Return exit code and output from claude() and retry without --continue on failure
This commit is contained in:
parent
6ec203e67f
commit
6114540764
|
|
@ -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")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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 })
|
||||
|
|
|
|||
|
|
@ -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<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 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. */
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user