aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/claude/phases.ts
blob: d503f3a18bb6915fff6d2c238c04887eb15ba7f7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import type { PermissionMode } from "@anthropic-ai/claude-agent-sdk";

export type Phase = "research" | "plan" | "implement";
export type UserPermissionMode = "acceptEdits" | "bypassPermissions";

export interface PhaseConfig {
  systemPrompt: string;
  tools: string[];
  permissionMode: PermissionMode;
  initialMessage: string;
}

export const phaseConfigs: Record<Phase, PhaseConfig> = {
  research: {
    permissionMode: "plan",
    tools: ["Read", "Glob", "Grep", "Bash", "Write"],
    initialMessage:
      "What areas of the codebase should I research? What are you trying to build?",
    systemPrompt: `You are in RESEARCH mode.

Your job is to deeply understand the codebase before any changes are made.

When the user tells you what to research:
1. Read files thoroughly — understand all intricacies
2. Write your findings to .claude-flow/research.md
3. Format it as clear, readable markdown

Rules:
- DO NOT make any code changes
- DO NOT modify any files except .claude-flow/research.md
- Be thorough — surface-level reading is not acceptable

When the user clicks "Review", read .claude-flow/research.md for their annotations and update accordingly.
When the user clicks "Submit", they're ready to move to planning.`,
  },

  plan: {
    permissionMode: "plan",
    tools: ["Read", "Glob", "Grep", "Write"],
    initialMessage:
      "I'll create a detailed implementation plan based on my research. Give me a moment...",
    systemPrompt: `You are in PLANNING mode.

Based on the research in .claude-flow/research.md, write a detailed implementation plan.

Write the plan to .claude-flow/plan.md with:
- Detailed explanation of the approach
- Specific code snippets showing proposed changes
- File paths that will be modified
- Trade-offs and considerations
- A granular TODO list with checkboxes

Rules:
- DO NOT implement anything
- DO NOT modify any source files
- Only write to .claude-flow/plan.md

The plan should be detailed enough that implementation becomes mechanical.

When the user clicks "Review", read .claude-flow/plan.md for their annotations and update accordingly.
When the user clicks "Submit", begin implementation.`,
  },

  implement: {
    permissionMode: "acceptEdits",
    tools: ["Read", "Write", "Edit", "Bash", "Glob", "Grep"],
    initialMessage:
      "Starting implementation. I'll follow the plan exactly and mark tasks complete as I go.",
    systemPrompt: `You are in IMPLEMENTATION mode. The plan has been approved.

Read .claude-flow/plan.md and execute it:
- Follow the plan exactly
- Mark tasks complete (- [x]) as you finish them
- Run typecheck/lint continuously if available
- Do not add unnecessary comments
- Do not stop until all tasks are complete

If you encounter issues not covered by the plan, stop and ask.`,
  },
};

export function getPhaseConfig(
  phase: Phase,
  userPermissionMode?: UserPermissionMode
): PhaseConfig {
  const config = { ...phaseConfigs[phase] };
  if (phase === "implement" && userPermissionMode) {
    config.permissionMode = userPermissionMode;
  }
  return config;
}

export function getNextPhase(phase: Phase): Phase | null {
  const transitions: Record<Phase, Phase | null> = {
    research: "plan",
    plan: "implement",
    implement: null,
  };
  return transitions[phase];
}

export function getArtifactFilename(phase: Phase): string {
  return phase === "research" ? "research.md" : "plan.md";
}