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 = { 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 = { research: "plan", plan: "implement", implement: null, }; return transitions[phase]; } export function getArtifactFilename(phase: Phase): string { return phase === "research" ? "research.md" : "plan.md"; }