allow optional manual commit message in sandlot save, skip AI generation when provided

This commit is contained in:
Chris Wanstrath 2026-02-17 19:23:35 -08:00
parent ec697565ac
commit 9f250188ca

View File

@ -146,8 +146,9 @@ program
program program
.command("save") .command("save")
.argument("<branch>", "branch name") .argument("<branch>", "branch name")
.description("Stage all changes and commit with an AI-generated message") .argument("[message]", "commit message (AI-generated if omitted)")
.action(async (branch: string) => { .description("Stage all changes and commit")
.action(async (branch: string, message?: string) => {
const root = await git.repoRoot() const root = await git.repoRoot()
const session = await state.getSession(root, branch) const session = await state.getSession(root, branch)
if (!session) { if (!session) {
@ -169,27 +170,33 @@ program
process.exit(1) process.exit(1)
} }
spin.text = "Generating commit message" let msg: string
const gen = await vm.exec( if (message) {
worktreeAbs, msg = message
'set -a; source ~/.env 2>/dev/null; set +a; git diff --staged | claude -p "write a short commit message summarizing these changes. output only the message, no quotes or extra text" > /tmp/sandlot_commit_msg', } else {
) spin.text = "Generating commit message"
if (gen.exitCode !== 0) { const gen = await vm.exec(
spin.fail("Failed to generate commit message") worktreeAbs,
if (gen.stderr) console.error(gen.stderr) 'set -a; source ~/.env 2>/dev/null; set +a; git diff --staged | claude -p "write a short commit message summarizing these changes. output only the message, no quotes or extra text" > /tmp/sandlot_commit_msg',
process.exit(1) )
if (gen.exitCode !== 0) {
spin.fail("Failed to generate commit message")
if (gen.stderr) console.error(gen.stderr)
process.exit(1)
}
const { stdout } = await vm.exec(worktreeAbs, "cat /tmp/sandlot_commit_msg")
await vm.exec(worktreeAbs, "rm -f /tmp/sandlot_commit_msg")
msg = stdout
} }
spin.text = "Committing" spin.text = "Committing"
const commit = await vm.exec(worktreeAbs, "git commit -F /tmp/sandlot_commit_msg") const commit = await vm.exec(worktreeAbs, `git commit -m ${JSON.stringify(msg)}`)
if (commit.exitCode !== 0) { if (commit.exitCode !== 0) {
spin.fail("Commit failed") spin.fail("Commit failed")
if (commit.stderr) console.error(commit.stderr) if (commit.stderr) console.error(commit.stderr)
process.exit(1) process.exit(1)
} }
const { stdout: msg } = await vm.exec(worktreeAbs, "cat /tmp/sandlot_commit_msg")
await vm.exec(worktreeAbs, "rm -f /tmp/sandlot_commit_msg")
spin.succeed(`Saved: ${msg}`) spin.succeed(`Saved: ${msg}`)
}) })