Move retry logic into vm.ts and simplify open.ts command flow
This commit is contained in:
parent
6114540764
commit
33e47a802c
|
|
@ -21,10 +21,7 @@ export async function action(
|
|||
|
||||
if (opts.print) {
|
||||
spin.text = "Running prompt…"
|
||||
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 })
|
||||
}
|
||||
const result = await vm.claude(session.worktree, { prompt, print: opts.print, continue: true })
|
||||
if (result.output) {
|
||||
spin.stop()
|
||||
process.stdout.write(renderMarkdown(result.output) + "\n")
|
||||
|
|
@ -33,10 +30,7 @@ export async function action(
|
|||
}
|
||||
} else {
|
||||
spin.succeed("Session ready")
|
||||
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 })
|
||||
}
|
||||
await vm.claude(session.worktree, { prompt, print: opts.print, continue: true })
|
||||
}
|
||||
|
||||
if (opts.save !== false) await saveChanges(session.worktree, branch)
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ import { $ } from "bun"
|
|||
import { homedir } from "os"
|
||||
import { dirname, join } from "path"
|
||||
import { getApiKey } from "./env.ts"
|
||||
import { info } from "./fmt.ts"
|
||||
|
||||
const CONTAINER_NAME = "sandlot"
|
||||
const USER = "ubuntu"
|
||||
|
|
@ -261,11 +262,19 @@ export async function claude(workdir: string, opts?: { prompt?: string; print?:
|
|||
const proc = Bun.spawn(args, { stdin: "inherit", stdout: "pipe", stderr: "inherit" })
|
||||
const output = await new Response(proc.stdout).text()
|
||||
const exitCode = await proc.exited
|
||||
if (exitCode !== 0 && opts?.continue) {
|
||||
info("Retrying without --continue")
|
||||
return claude(workdir, { ...opts, continue: false })
|
||||
}
|
||||
return { exitCode, output }
|
||||
}
|
||||
|
||||
const proc = Bun.spawn(args, { stdin: "inherit", stdout: "inherit", stderr: "inherit" })
|
||||
const exitCode = await proc.exited
|
||||
if (exitCode !== 0 && opts?.continue) {
|
||||
info("Retrying without --continue")
|
||||
return claude(workdir, { ...opts, continue: false })
|
||||
}
|
||||
return { exitCode }
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user