aboutsummaryrefslogtreecommitdiffstats
path: root/src/main
diff options
context:
space:
mode:
authorClawd <ai@clawd.bot>2026-02-28 07:53:12 -0800
committerClawd <ai@clawd.bot>2026-02-28 07:53:12 -0800
commit95a141f79104a350f09ce0fc1ba5dac015e3be16 (patch)
treed1f6618a88abe7a6fe972484460ee4b30b96bf22 /src/main
parent35a38d909f1777e3b384ba26d68b88f641ec6a1a (diff)
Fix: system prompt passing and strengthen phase enforcement
- Fix systemPrompt option (was incorrectly using extraArgs) - Rewrite research phase prompt: - Emphasize writing to research.md as PRIMARY output - Explicitly forbid asking about phase transitions - Add document format template - Clarify that chat is for questions only - Rewrite plan phase prompt: - Same emphasis on plan.md as primary output - Include code snippet format examples - Forbid implementation attempts - Change research/plan permissionMode to acceptEdits (was 'plan') - 'plan' mode may have been blocking file writes
Diffstat (limited to 'src/main')
-rw-r--r--src/main/claude/index.ts5
-rw-r--r--src/main/claude/phases.ts148
2 files changed, 105 insertions, 48 deletions
diff --git a/src/main/claude/index.ts b/src/main/claude/index.ts
index 34a914e..8bdcccd 100644
--- a/src/main/claude/index.ts
+++ b/src/main/claude/index.ts
@@ -45,10 +45,7 @@ export async function sendMessage({
45 resume: session.claude_session_id ?? undefined, 45 resume: session.claude_session_id ?? undefined,
46 tools: phaseConfig.tools, 46 tools: phaseConfig.tools,
47 permissionMode: phaseConfig.permissionMode, 47 permissionMode: phaseConfig.permissionMode,
48 // Add system prompt via extraArgs since there's no direct option 48 systemPrompt: phaseConfig.systemPrompt,
49 extraArgs: {
50 "system-prompt": phaseConfig.systemPrompt,
51 },
52 }, 49 },
53 }); 50 });
54 51
diff --git a/src/main/claude/phases.ts b/src/main/claude/phases.ts
index d503f3a..2ea1ea8 100644
--- a/src/main/claude/phases.ts
+++ b/src/main/claude/phases.ts
@@ -12,53 +12,107 @@ export interface PhaseConfig {
12 12
13export const phaseConfigs: Record<Phase, PhaseConfig> = { 13export const phaseConfigs: Record<Phase, PhaseConfig> = {
14 research: { 14 research: {
15 permissionMode: "plan", 15 permissionMode: "acceptEdits",
16 tools: ["Read", "Glob", "Grep", "Bash", "Write"], 16 tools: ["Read", "Glob", "Grep", "Bash", "Write"],
17 initialMessage: 17 initialMessage:
18 "What areas of the codebase should I research? What are you trying to build?", 18 "What areas of the codebase should I research? What are you trying to build?",
19 systemPrompt: `You are in RESEARCH mode. 19 systemPrompt: `You are in RESEARCH mode. Your ONLY job is to understand the codebase.
20 20
21Your job is to deeply understand the codebase before any changes are made. 21CRITICAL RULES:
221. You MUST write ALL findings to .claude-flow/research.md — this is your PRIMARY output
232. DO NOT just respond in chat. The document viewer shows research.md, so write there.
243. DO NOT suggest moving to planning or implementation
254. DO NOT ask "are you ready to implement?" or similar
265. DO NOT modify any source code files
276. The user controls phase transitions via UI buttons — never prompt them about it
22 28
23When the user tells you what to research: 29WORKFLOW:
241. Read files thoroughly — understand all intricacies 301. Ask what to research (if unclear)
252. Write your findings to .claude-flow/research.md 312. Read files thoroughly using Read, Glob, Grep
263. Format it as clear, readable markdown 323. Write structured findings to .claude-flow/research.md
334. Keep updating research.md as you learn more
27 34
28Rules: 35FORMAT for research.md:
29- DO NOT make any code changes 36\`\`\`markdown
30- DO NOT modify any files except .claude-flow/research.md 37# Research Findings
31- Be thorough — surface-level reading is not acceptable
32 38
33When the user clicks "Review", read .claude-flow/research.md for their annotations and update accordingly. 39## Overview
34When the user clicks "Submit", they're ready to move to planning.`, 40[High-level summary of what you found]
35 },
36 41
37 plan: { 42## Architecture
38 permissionMode: "plan", 43[Key components, patterns, structure]
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
44Based on the research in .claude-flow/research.md, write a detailed implementation plan. 45## Relevant Files
46[List of important files with descriptions]
45 47
46Write the plan to .claude-flow/plan.md with: 48## Key Insights
47- Detailed explanation of the approach 49[Important discoveries, patterns, potential issues]
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 50
53Rules: 51## Questions/Unknowns
54- DO NOT implement anything 52[Things that need clarification]
55- DO NOT modify any source files 53\`\`\`
56- Only write to .claude-flow/plan.md
57 54
58The plan should be detailed enough that implementation becomes mechanical. 55When the user adds annotations (// REVIEW:, // NOTE:, TODO:) to research.md and clicks Review, address each annotation and update the document.
59 56
60When the user clicks "Review", read .claude-flow/plan.md for their annotations and update accordingly. 57Remember: Your output goes in research.md, not chat. Chat is for clarifying questions only.`,
61When the user clicks "Submit", begin implementation.`, 58 },
59
60 plan: {
61 permissionMode: "acceptEdits",
62 tools: ["Read", "Glob", "Grep", "Write"],
63 initialMessage:
64 "I'll create a detailed implementation plan based on my research. Writing to plan.md...",
65 systemPrompt: `You are in PLANNING mode. Your ONLY job is to create an implementation plan.
66
67CRITICAL RULES:
681. You MUST write the plan to .claude-flow/plan.md — this is your PRIMARY output
692. DO NOT just respond in chat. The document viewer shows plan.md, so write there.
703. DO NOT implement anything — no code changes to source files
714. DO NOT ask "should I start implementing?" or similar
725. The user controls phase transitions via UI buttons — never prompt them about it
736. Base your plan on .claude-flow/research.md
74
75WORKFLOW:
761. Read .claude-flow/research.md to understand the codebase
772. Write a detailed plan to .claude-flow/plan.md
783. Include specific code snippets showing proposed changes
794. Make the plan detailed enough that implementation is mechanical
80
81FORMAT for plan.md:
82\`\`\`markdown
83# Implementation Plan
84
85## Goal
86[What we're building/changing]
87
88## Approach
89[High-level strategy]
90
91## Changes
92
93### 1. [First change]
94**File:** path/to/file.ts
95**What:** [Description]
96**Code:**
97\\\`\\\`\\\`typescript
98// Proposed code
99\\\`\\\`\\\`
100
101### 2. [Second change]
102...
103
104## TODO
105- [ ] Task 1
106- [ ] Task 2
107- [ ] Task 3
108
109## Risks/Considerations
110[Potential issues, edge cases]
111\`\`\`
112
113When the user adds annotations to plan.md and clicks Review, address each annotation and update the document.
114
115Remember: Your output goes in plan.md, not chat. Chat is for clarifying questions only.`,
62 }, 116 },
63 117
64 implement: { 118 implement: {
@@ -66,16 +120,22 @@ When the user clicks "Submit", begin implementation.`,
66 tools: ["Read", "Write", "Edit", "Bash", "Glob", "Grep"], 120 tools: ["Read", "Write", "Edit", "Bash", "Glob", "Grep"],
67 initialMessage: 121 initialMessage:
68 "Starting implementation. I'll follow the plan exactly and mark tasks complete as I go.", 122 "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. 123 systemPrompt: `You are in IMPLEMENTATION mode. Execute the approved plan.
70 124
71Read .claude-flow/plan.md and execute it: 125CRITICAL RULES:
72- Follow the plan exactly 1261. Read .claude-flow/plan.md and follow it exactly
73- Mark tasks complete (- [x]) as you finish them 1272. Mark tasks complete in plan.md as you finish them: - [ ] → - [x]
74- Run typecheck/lint continuously if available 1283. DO NOT deviate from the plan without asking
75- Do not add unnecessary comments 1294. Run tests/typecheck if available
76- Do not stop until all tasks are complete 1305. Stop and ask if you encounter issues not covered by the plan
77 131
78If you encounter issues not covered by the plan, stop and ask.`, 132WORKFLOW:
1331. Read .claude-flow/plan.md
1342. Execute each task in order
1353. Update plan.md to mark tasks complete
1364. Continue until all tasks are done
137
138If something in the plan is unclear or problematic, ask before proceeding.`,
79 }, 139 },
80}; 140};
81 141