diff options
Diffstat (limited to 'src/main/claude/phases.ts')
| -rw-r--r-- | src/main/claude/phases.ts | 104 |
1 files changed, 104 insertions, 0 deletions
diff --git a/src/main/claude/phases.ts b/src/main/claude/phases.ts new file mode 100644 index 0000000..d503f3a --- /dev/null +++ b/src/main/claude/phases.ts | |||
| @@ -0,0 +1,104 @@ | |||
| 1 | import type { PermissionMode } from "@anthropic-ai/claude-agent-sdk"; | ||
| 2 | |||
| 3 | export type Phase = "research" | "plan" | "implement"; | ||
| 4 | export type UserPermissionMode = "acceptEdits" | "bypassPermissions"; | ||
| 5 | |||
| 6 | export interface PhaseConfig { | ||
| 7 | systemPrompt: string; | ||
| 8 | tools: string[]; | ||
| 9 | permissionMode: PermissionMode; | ||
| 10 | initialMessage: string; | ||
| 11 | } | ||
| 12 | |||
| 13 | export const phaseConfigs: Record<Phase, PhaseConfig> = { | ||
| 14 | research: { | ||
| 15 | permissionMode: "plan", | ||
| 16 | tools: ["Read", "Glob", "Grep", "Bash", "Write"], | ||
| 17 | initialMessage: | ||
| 18 | "What areas of the codebase should I research? What are you trying to build?", | ||
| 19 | systemPrompt: `You are in RESEARCH mode. | ||
| 20 | |||
| 21 | Your job is to deeply understand the codebase before any changes are made. | ||
| 22 | |||
| 23 | When the user tells you what to research: | ||
| 24 | 1. Read files thoroughly — understand all intricacies | ||
| 25 | 2. Write your findings to .claude-flow/research.md | ||
| 26 | 3. Format it as clear, readable markdown | ||
| 27 | |||
| 28 | Rules: | ||
| 29 | - DO NOT make any code changes | ||
| 30 | - DO NOT modify any files except .claude-flow/research.md | ||
| 31 | - Be thorough — surface-level reading is not acceptable | ||
| 32 | |||
| 33 | When the user clicks "Review", read .claude-flow/research.md for their annotations and update accordingly. | ||
| 34 | When the user clicks "Submit", they're ready to move to planning.`, | ||
| 35 | }, | ||
| 36 | |||
| 37 | plan: { | ||
| 38 | permissionMode: "plan", | ||
| 39 | tools: ["Read", "Glob", "Grep", "Write"], | ||
| 40 | initialMessage: | ||
| 41 | "I'll create a detailed implementation plan based on my research. Give me a moment...", | ||
| 42 | systemPrompt: `You are in PLANNING mode. | ||
| 43 | |||
| 44 | Based on the research in .claude-flow/research.md, write a detailed implementation plan. | ||
| 45 | |||
| 46 | Write the plan to .claude-flow/plan.md with: | ||
| 47 | - Detailed explanation of the approach | ||
| 48 | - Specific code snippets showing proposed changes | ||
| 49 | - File paths that will be modified | ||
| 50 | - Trade-offs and considerations | ||
| 51 | - A granular TODO list with checkboxes | ||
| 52 | |||
| 53 | Rules: | ||
| 54 | - DO NOT implement anything | ||
| 55 | - DO NOT modify any source files | ||
| 56 | - Only write to .claude-flow/plan.md | ||
| 57 | |||
| 58 | The plan should be detailed enough that implementation becomes mechanical. | ||
| 59 | |||
| 60 | When the user clicks "Review", read .claude-flow/plan.md for their annotations and update accordingly. | ||
| 61 | When the user clicks "Submit", begin implementation.`, | ||
| 62 | }, | ||
| 63 | |||
| 64 | implement: { | ||
| 65 | permissionMode: "acceptEdits", | ||
| 66 | tools: ["Read", "Write", "Edit", "Bash", "Glob", "Grep"], | ||
| 67 | initialMessage: | ||
| 68 | "Starting implementation. I'll follow the plan exactly and mark tasks complete as I go.", | ||
| 69 | systemPrompt: `You are in IMPLEMENTATION mode. The plan has been approved. | ||
| 70 | |||
| 71 | Read .claude-flow/plan.md and execute it: | ||
| 72 | - Follow the plan exactly | ||
| 73 | - Mark tasks complete (- [x]) as you finish them | ||
| 74 | - Run typecheck/lint continuously if available | ||
| 75 | - Do not add unnecessary comments | ||
| 76 | - Do not stop until all tasks are complete | ||
| 77 | |||
| 78 | If you encounter issues not covered by the plan, stop and ask.`, | ||
| 79 | }, | ||
| 80 | }; | ||
| 81 | |||
| 82 | export function getPhaseConfig( | ||
| 83 | phase: Phase, | ||
| 84 | userPermissionMode?: UserPermissionMode | ||
| 85 | ): PhaseConfig { | ||
| 86 | const config = { ...phaseConfigs[phase] }; | ||
| 87 | if (phase === "implement" && userPermissionMode) { | ||
| 88 | config.permissionMode = userPermissionMode; | ||
| 89 | } | ||
| 90 | return config; | ||
| 91 | } | ||
| 92 | |||
| 93 | export function getNextPhase(phase: Phase): Phase | null { | ||
| 94 | const transitions: Record<Phase, Phase | null> = { | ||
| 95 | research: "plan", | ||
| 96 | plan: "implement", | ||
| 97 | implement: null, | ||
| 98 | }; | ||
| 99 | return transitions[phase]; | ||
| 100 | } | ||
| 101 | |||
| 102 | export function getArtifactFilename(phase: Phase): string { | ||
| 103 | return phase === "research" ? "research.md" : "plan.md"; | ||
| 104 | } | ||
