Return exit code and output from claude() and retry without --continue on failure

This commit is contained in:
Chris Wanstrath 2026-02-23 07:32:42 -08:00
parent 6ec203e67f
commit 6114540764
4 changed files with 20 additions and 13 deletions

View File

@ -105,10 +105,10 @@ export async function action(
if (opts.print) { if (opts.print) {
spin.text = "Running prompt…" spin.text = "Running prompt…"
const output = await vm.claude(worktreeAbs, { prompt, print: opts.print }) const result = await vm.claude(worktreeAbs, { prompt, print: opts.print })
if (output) { if (result.output) {
spin.stop() spin.stop()
process.stdout.write(renderMarkdown(output) + "\n") process.stdout.write(renderMarkdown(result.output) + "\n")
} else { } else {
spin.succeed("Done") spin.succeed("Done")
} }

View File

@ -21,16 +21,22 @@ export async function action(
if (opts.print) { if (opts.print) {
spin.text = "Running prompt…" spin.text = "Running prompt…"
const output = await vm.claude(session.worktree, { prompt, print: opts.print, continue: true }) let result = await vm.claude(session.worktree, { prompt, print: opts.print, continue: true })
if (output) { if (result.exitCode !== 0) {
result = await vm.claude(session.worktree, { prompt, print: opts.print })
}
if (result.output) {
spin.stop() spin.stop()
process.stdout.write(renderMarkdown(output) + "\n") process.stdout.write(renderMarkdown(result.output) + "\n")
} else { } else {
spin.succeed("Done") spin.succeed("Done")
} }
} else { } else {
spin.succeed("Session ready") spin.succeed("Session ready")
await vm.claude(session.worktree, { prompt, print: opts.print, continue: true }) const result = await vm.claude(session.worktree, { prompt, print: opts.print, continue: true })
if (result.exitCode !== 0) {
await vm.claude(session.worktree, { prompt, print: opts.print })
}
} }
if (opts.save !== false) await saveChanges(session.worktree, branch) if (opts.save !== false) await saveChanges(session.worktree, branch)

View File

@ -12,9 +12,9 @@ export async function action(branch: string, opts: { print?: boolean }) {
if (opts.print) { if (opts.print) {
spin.text = "Running review…" spin.text = "Running review…"
const output = await vm.claude(session.worktree, { print: prompt }) const result = await vm.claude(session.worktree, { print: prompt })
spin.stop() spin.stop()
if (output) process.stdout.write(output + "\n") if (result.output) process.stdout.write(result.output + "\n")
} else { } else {
spin.succeed("Session ready") spin.succeed("Session ready")
await vm.claude(session.worktree, { prompt }) await vm.claude(session.worktree, { prompt })

View File

@ -237,7 +237,7 @@ export async function status(): Promise<"running" | "stopped" | "missing"> {
} }
/** Launch claude in the container at the given workdir. */ /** Launch claude in the container at the given workdir. */
export async function claude(workdir: string, opts?: { prompt?: string; print?: string; continue?: boolean }): Promise<string | void> { export async function claude(workdir: string, opts?: { prompt?: string; print?: string; continue?: boolean }): Promise<{ exitCode: number; output?: string }> {
const cwd = containerPath(workdir) const cwd = containerPath(workdir)
const systemPromptLines = [ const systemPromptLines = [
"You are running inside a sandlot container (Apple Container, ubuntu:24.04).", "You are running inside a sandlot container (Apple Container, ubuntu:24.04).",
@ -260,12 +260,13 @@ export async function claude(workdir: string, opts?: { prompt?: string; print?:
if (opts?.print) { if (opts?.print) {
const proc = Bun.spawn(args, { stdin: "inherit", stdout: "pipe", stderr: "inherit" }) const proc = Bun.spawn(args, { stdin: "inherit", stdout: "pipe", stderr: "inherit" })
const output = await new Response(proc.stdout).text() const output = await new Response(proc.stdout).text()
await proc.exited const exitCode = await proc.exited
return output return { exitCode, output }
} }
const proc = Bun.spawn(args, { stdin: "inherit", stdout: "inherit", stderr: "inherit" }) const proc = Bun.spawn(args, { stdin: "inherit", stdout: "inherit", stderr: "inherit" })
await proc.exited const exitCode = await proc.exited
return { exitCode }
} }
/** Open an interactive fish shell in the container, optionally in a specific directory. */ /** Open an interactive fish shell in the container, optionally in a specific directory. */