aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/claude
diff options
context:
space:
mode:
authorbndw <ben@bdw.to>2026-02-28 20:07:05 -0800
committerbndw <ben@bdw.to>2026-02-28 20:07:05 -0800
commit9d192d16b7a4026b35ad2bcaff9edb9f2670de2b (patch)
tree2603dd04c3567074e84be271c448ede02ee7097d /src/main/claude
parent283013c09d4855529e846951a1e090f0f16030a8 (diff)
feat: git branches
Diffstat (limited to 'src/main/claude')
-rw-r--r--src/main/claude/index.ts26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/main/claude/index.ts b/src/main/claude/index.ts
index 4dd49f2..8971844 100644
--- a/src/main/claude/index.ts
+++ b/src/main/claude/index.ts
@@ -4,12 +4,17 @@ import { getPhaseConfig, getNextPhase, getArtifactFilename } from "./phases";
4import type { Phase, UserPermissionMode } from "./phases"; 4import type { Phase, UserPermissionMode } from "./phases";
5import { getProject } from "../db/projects"; 5import { getProject } from "../db/projects";
6import { updateSession } from "../db/sessions"; 6import { updateSession } from "../db/sessions";
7import { autoCommitTurn } from "../git";
7import fs from "node:fs"; 8import fs from "node:fs";
8import path from "node:path"; 9import path from "node:path";
9 10
10// Track active queries by session ID 11// Track active queries by session ID
11const activeQueries = new Map<string, Query>(); 12const activeQueries = new Map<string, Query>();
12 13
14// Snapshot of plan.md content per session, updated after each implement turn.
15// Used to detect newly-completed tasks for commit messages.
16const planSnapshots = new Map<string, string>();
17
13function ensureDir(dirPath: string): void { 18function ensureDir(dirPath: string): void {
14 if (!fs.existsSync(dirPath)) { 19 if (!fs.existsSync(dirPath)) {
15 fs.mkdirSync(dirPath, { recursive: true }); 20 fs.mkdirSync(dirPath, { recursive: true });
@@ -52,7 +57,14 @@ export async function sendMessage({
52 resume: session.claude_session_id ?? undefined, 57 resume: session.claude_session_id ?? undefined,
53 tools: phaseConfig.tools, 58 tools: phaseConfig.tools,
54 permissionMode: phaseConfig.permissionMode, 59 permissionMode: phaseConfig.permissionMode,
60 // Required companion flag when bypassPermissions is active
61 allowDangerouslySkipPermissions: phaseConfig.permissionMode === "bypassPermissions",
55 systemPrompt: phaseConfig.systemPrompt, 62 systemPrompt: phaseConfig.systemPrompt,
63 // Allow Claude to inspect git state during implementation without prompts.
64 // git add/commit intentionally omitted — the app handles those.
65 ...(session.phase === "implement" && {
66 allowedTools: ["Bash(git status*)", "Bash(git log*)", "Bash(git diff*)"],
67 }),
56 }, 68 },
57 }); 69 });
58 70
@@ -71,6 +83,20 @@ export async function sendMessage({
71 } finally { 83 } finally {
72 activeQueries.delete(session.id); 84 activeQueries.delete(session.id);
73 } 85 }
86
87 // Auto-commit after a successful implement-phase turn.
88 // This runs only if for-await completed without throwing (successful turn).
89 // Interrupted / errored turns skip the commit.
90 if (session.phase === "implement") {
91 const previousPlan = planSnapshots.get(session.id) ?? "";
92 const currentPlan = autoCommitTurn(
93 project.path,
94 session.git_branch,
95 previousPlan,
96 sessionDir
97 );
98 planSnapshots.set(session.id, currentPlan);
99 }
74} 100}
75 101
76export function interruptSession(sessionId: string): void { 102export function interruptSession(sessionId: string): void {