aboutsummaryrefslogtreecommitdiffstats
path: root/dist/main/claude
diff options
context:
space:
mode:
Diffstat (limited to 'dist/main/claude')
-rw-r--r--dist/main/claude/index.js109
-rw-r--r--dist/main/claude/phases.js147
2 files changed, 0 insertions, 256 deletions
diff --git a/dist/main/claude/index.js b/dist/main/claude/index.js
deleted file mode 100644
index 42a9652..0000000
--- a/dist/main/claude/index.js
+++ /dev/null
@@ -1,109 +0,0 @@
1"use strict";
2var __importDefault = (this && this.__importDefault) || function (mod) {
3 return (mod && mod.__esModule) ? mod : { "default": mod };
4};
5Object.defineProperty(exports, "__esModule", { value: true });
6exports.sendMessage = sendMessage;
7exports.interruptSession = interruptSession;
8exports.triggerReview = triggerReview;
9exports.advancePhase = advancePhase;
10exports.readArtifact = readArtifact;
11exports.writeArtifact = writeArtifact;
12exports.getPhaseInitialMessage = getPhaseInitialMessage;
13const claude_agent_sdk_1 = require("@anthropic-ai/claude-agent-sdk");
14const phases_1 = require("./phases");
15const projects_1 = require("../db/projects");
16const sessions_1 = require("../db/sessions");
17const node_fs_1 = __importDefault(require("node:fs"));
18const node_path_1 = __importDefault(require("node:path"));
19// Track active queries by session ID
20const activeQueries = new Map();
21function ensureArtifactDir(projectPath) {
22 const dir = node_path_1.default.join(projectPath, ".claude-flow");
23 if (!node_fs_1.default.existsSync(dir)) {
24 node_fs_1.default.mkdirSync(dir, { recursive: true });
25 }
26}
27async function sendMessage({ session, message, onMessage, }) {
28 const project = (0, projects_1.getProject)(session.project_id);
29 if (!project)
30 throw new Error("Project not found");
31 ensureArtifactDir(project.path);
32 const phaseConfig = (0, phases_1.getPhaseConfig)(session.phase, session.permission_mode);
33 const q = (0, claude_agent_sdk_1.query)({
34 prompt: message,
35 options: {
36 cwd: project.path,
37 resume: session.claude_session_id ?? undefined,
38 tools: phaseConfig.tools,
39 permissionMode: phaseConfig.permissionMode,
40 systemPrompt: phaseConfig.systemPrompt,
41 },
42 });
43 activeQueries.set(session.id, q);
44 try {
45 for await (const msg of q) {
46 // Capture session ID from init message
47 if (msg.type === "system" && msg.subtype === "init") {
48 if (!session.claude_session_id) {
49 (0, sessions_1.updateSession)(session.id, { claude_session_id: msg.session_id });
50 }
51 }
52 onMessage(msg);
53 }
54 }
55 finally {
56 activeQueries.delete(session.id);
57 }
58}
59function interruptSession(sessionId) {
60 const q = activeQueries.get(sessionId);
61 if (q) {
62 q.close();
63 activeQueries.delete(sessionId);
64 }
65}
66/**
67 * Trigger a review: Claude reads the document and addresses user annotations
68 */
69async function triggerReview(session, onMessage) {
70 const docName = (0, phases_1.getArtifactFilename)(session.phase);
71 const message = `I've updated .claude-flow/${docName} with annotations. Read the file, find all my inline notes (marked with // REVIEW:, // NOTE:, TODO:, or similar), address each one, and update the document accordingly. Do not implement anything yet.`;
72 await sendMessage({ session, message, onMessage });
73}
74/**
75 * Advance to the next phase
76 */
77function advancePhase(session) {
78 const nextPhase = (0, phases_1.getNextPhase)(session.phase);
79 if (nextPhase) {
80 (0, sessions_1.updateSession)(session.id, { phase: nextPhase });
81 }
82 return nextPhase;
83}
84/**
85 * Read an artifact file from the project's .claude-flow directory
86 */
87function readArtifact(projectPath, filename) {
88 const filePath = node_path_1.default.join(projectPath, ".claude-flow", filename);
89 if (node_fs_1.default.existsSync(filePath)) {
90 return node_fs_1.default.readFileSync(filePath, "utf-8");
91 }
92 return null;
93}
94/**
95 * Write an artifact file to the project's .claude-flow directory
96 */
97function writeArtifact(projectPath, filename, content) {
98 const dir = node_path_1.default.join(projectPath, ".claude-flow");
99 if (!node_fs_1.default.existsSync(dir)) {
100 node_fs_1.default.mkdirSync(dir, { recursive: true });
101 }
102 node_fs_1.default.writeFileSync(node_path_1.default.join(dir, filename), content, "utf-8");
103}
104/**
105 * Get the initial message for a phase
106 */
107function getPhaseInitialMessage(phase) {
108 return (0, phases_1.getPhaseConfig)(phase).initialMessage;
109}
diff --git a/dist/main/claude/phases.js b/dist/main/claude/phases.js
deleted file mode 100644
index 65ea46d..0000000
--- a/dist/main/claude/phases.js
+++ /dev/null
@@ -1,147 +0,0 @@
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.phaseConfigs = void 0;
4exports.getPhaseConfig = getPhaseConfig;
5exports.getNextPhase = getNextPhase;
6exports.getArtifactFilename = getArtifactFilename;
7exports.phaseConfigs = {
8 research: {
9 permissionMode: "acceptEdits",
10 tools: ["Read", "Glob", "Grep", "Bash", "Write"],
11 initialMessage: "What areas of the codebase should I research? What are you trying to build?",
12 systemPrompt: `You are in RESEARCH mode. Your ONLY job is to understand the codebase.
13
14CRITICAL RULES:
151. You MUST write ALL findings to .claude-flow/research.md — this is your PRIMARY output
162. DO NOT just respond in chat. The document viewer shows research.md, so write there.
173. DO NOT suggest moving to planning or implementation
184. DO NOT ask "are you ready to implement?" or similar
195. DO NOT modify any source code files
206. The user controls phase transitions via UI buttons — never prompt them about it
21
22WORKFLOW:
231. Ask what to research (if unclear)
242. Read files thoroughly using Read, Glob, Grep
253. Write structured findings to .claude-flow/research.md
264. Keep updating research.md as you learn more
27
28FORMAT for research.md:
29\`\`\`markdown
30# Research Findings
31
32## Overview
33[High-level summary of what you found]
34
35## Architecture
36[Key components, patterns, structure]
37
38## Relevant Files
39[List of important files with descriptions]
40
41## Key Insights
42[Important discoveries, patterns, potential issues]
43
44## Questions/Unknowns
45[Things that need clarification]
46\`\`\`
47
48When the user adds annotations (// REVIEW:, // NOTE:, TODO:) to research.md and clicks Review, address each annotation and update the document.
49
50Remember: Your output goes in research.md, not chat. Chat is for clarifying questions only.`,
51 },
52 plan: {
53 permissionMode: "acceptEdits",
54 tools: ["Read", "Glob", "Grep", "Write"],
55 initialMessage: "I'll create a detailed implementation plan based on my research. Writing to plan.md...",
56 systemPrompt: `You are in PLANNING mode. Your ONLY job is to create an implementation plan.
57
58CRITICAL RULES:
591. You MUST write the plan to .claude-flow/plan.md — this is your PRIMARY output
602. DO NOT just respond in chat. The document viewer shows plan.md, so write there.
613. DO NOT implement anything — no code changes to source files
624. DO NOT ask "should I start implementing?" or similar
635. The user controls phase transitions via UI buttons — never prompt them about it
646. Base your plan on .claude-flow/research.md
65
66WORKFLOW:
671. Read .claude-flow/research.md to understand the codebase
682. Write a detailed plan to .claude-flow/plan.md
693. Include specific code snippets showing proposed changes
704. Make the plan detailed enough that implementation is mechanical
71
72FORMAT for plan.md:
73\`\`\`markdown
74# Implementation Plan
75
76## Goal
77[What we're building/changing]
78
79## Approach
80[High-level strategy]
81
82## Changes
83
84### 1. [First change]
85**File:** path/to/file.ts
86**What:** [Description]
87**Code:**
88\\\`\\\`\\\`typescript
89// Proposed code
90\\\`\\\`\\\`
91
92### 2. [Second change]
93...
94
95## TODO
96- [ ] Task 1
97- [ ] Task 2
98- [ ] Task 3
99
100## Risks/Considerations
101[Potential issues, edge cases]
102\`\`\`
103
104When the user adds annotations to plan.md and clicks Review, address each annotation and update the document.
105
106Remember: Your output goes in plan.md, not chat. Chat is for clarifying questions only.`,
107 },
108 implement: {
109 permissionMode: "acceptEdits",
110 tools: ["Read", "Write", "Edit", "Bash", "Glob", "Grep"],
111 initialMessage: "Starting implementation. I'll follow the plan exactly and mark tasks complete as I go.",
112 systemPrompt: `You are in IMPLEMENTATION mode. Execute the approved plan.
113
114CRITICAL RULES:
1151. Read .claude-flow/plan.md and follow it exactly
1162. Mark tasks complete in plan.md as you finish them: - [ ] → - [x]
1173. DO NOT deviate from the plan without asking
1184. Run tests/typecheck if available
1195. Stop and ask if you encounter issues not covered by the plan
120
121WORKFLOW:
1221. Read .claude-flow/plan.md
1232. Execute each task in order
1243. Update plan.md to mark tasks complete
1254. Continue until all tasks are done
126
127If something in the plan is unclear or problematic, ask before proceeding.`,
128 },
129};
130function getPhaseConfig(phase, userPermissionMode) {
131 const config = { ...exports.phaseConfigs[phase] };
132 if (phase === "implement" && userPermissionMode) {
133 config.permissionMode = userPermissionMode;
134 }
135 return config;
136}
137function getNextPhase(phase) {
138 const transitions = {
139 research: "plan",
140 plan: "implement",
141 implement: null,
142 };
143 return transitions[phase];
144}
145function getArtifactFilename(phase) {
146 return phase === "research" ? "research.md" : "plan.md";
147}