diff --git a/src/commands/new.ts b/src/commands/new.ts index 06faba1..b297d1b 100644 --- a/src/commands/new.ts +++ b/src/commands/new.ts @@ -105,10 +105,10 @@ export async function action( if (opts.print) { spin.text = "Running prompt…" - const output = await vm.claude(worktreeAbs, { prompt, print: opts.print }) - if (output) { + const result = await vm.claude(worktreeAbs, { prompt, print: opts.print }) + if (result.output) { spin.stop() - process.stdout.write(renderMarkdown(output) + "\n") + process.stdout.write(renderMarkdown(result.output) + "\n") } else { spin.succeed("Done") } diff --git a/src/commands/open.ts b/src/commands/open.ts index da5b6e8..a7e9ab3 100644 --- a/src/commands/open.ts +++ b/src/commands/open.ts @@ -21,16 +21,22 @@ export async function action( if (opts.print) { spin.text = "Running prompt…" - const output = await vm.claude(session.worktree, { prompt, print: opts.print, continue: true }) - if (output) { + let result = await vm.claude(session.worktree, { prompt, print: opts.print, continue: true }) + if (result.exitCode !== 0) { + result = await vm.claude(session.worktree, { prompt, print: opts.print }) + } + if (result.output) { spin.stop() - process.stdout.write(renderMarkdown(output) + "\n") + process.stdout.write(renderMarkdown(result.output) + "\n") } else { spin.succeed("Done") } } else { 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) diff --git a/src/commands/review.ts b/src/commands/review.ts index 68ab166..df9e860 100644 --- a/src/commands/review.ts +++ b/src/commands/review.ts @@ -12,9 +12,9 @@ export async function action(branch: string, opts: { print?: boolean }) { if (opts.print) { spin.text = "Running review…" - const output = await vm.claude(session.worktree, { print: prompt }) + const result = await vm.claude(session.worktree, { print: prompt }) spin.stop() - if (output) process.stdout.write(output + "\n") + if (result.output) process.stdout.write(result.output + "\n") } else { spin.succeed("Session ready") await vm.claude(session.worktree, { prompt }) diff --git a/src/vm.ts b/src/vm.ts index 29d267b..ab383a1 100644 --- a/src/vm.ts +++ b/src/vm.ts @@ -237,7 +237,7 @@ export async function status(): Promise<"running" | "stopped" | "missing"> { } /** Launch claude in the container at the given workdir. */ -export async function claude(workdir: string, opts?: { prompt?: string; print?: string; continue?: boolean }): Promise { +export async function claude(workdir: string, opts?: { prompt?: string; print?: string; continue?: boolean }): Promise<{ exitCode: number; output?: string }> { const cwd = containerPath(workdir) const systemPromptLines = [ "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) { const proc = Bun.spawn(args, { stdin: "inherit", stdout: "pipe", stderr: "inherit" }) const output = await new Response(proc.stdout).text() - await proc.exited - return output + const exitCode = await proc.exited + return { exitCode, output } } 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. */