From 9d192d16b7a4026b35ad2bcaff9edb9f2670de2b Mon Sep 17 00:00:00 2001 From: bndw Date: Sat, 28 Feb 2026 20:07:05 -0800 Subject: feat: git branches --- src/main/claude/index.ts | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'src/main/claude/index.ts') 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"; import type { Phase, UserPermissionMode } from "./phases"; import { getProject } from "../db/projects"; import { updateSession } from "../db/sessions"; +import { autoCommitTurn } from "../git"; import fs from "node:fs"; import path from "node:path"; // Track active queries by session ID const activeQueries = new Map(); +// Snapshot of plan.md content per session, updated after each implement turn. +// Used to detect newly-completed tasks for commit messages. +const planSnapshots = new Map(); + function ensureDir(dirPath: string): void { if (!fs.existsSync(dirPath)) { fs.mkdirSync(dirPath, { recursive: true }); @@ -52,7 +57,14 @@ export async function sendMessage({ resume: session.claude_session_id ?? undefined, tools: phaseConfig.tools, permissionMode: phaseConfig.permissionMode, + // Required companion flag when bypassPermissions is active + allowDangerouslySkipPermissions: phaseConfig.permissionMode === "bypassPermissions", systemPrompt: phaseConfig.systemPrompt, + // Allow Claude to inspect git state during implementation without prompts. + // git add/commit intentionally omitted — the app handles those. + ...(session.phase === "implement" && { + allowedTools: ["Bash(git status*)", "Bash(git log*)", "Bash(git diff*)"], + }), }, }); @@ -71,6 +83,20 @@ export async function sendMessage({ } finally { activeQueries.delete(session.id); } + + // Auto-commit after a successful implement-phase turn. + // This runs only if for-await completed without throwing (successful turn). + // Interrupted / errored turns skip the commit. + if (session.phase === "implement") { + const previousPlan = planSnapshots.get(session.id) ?? ""; + const currentPlan = autoCommitTurn( + project.path, + session.git_branch, + previousPlan, + sessionDir + ); + planSnapshots.set(session.id, currentPlan); + } } export function interruptSession(sessionId: string): void { -- cgit v1.2.3