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) {
|
if (opts.print) {
|
||||||
spin.text = "Running prompt…"
|
spin.text = "Running prompt…"
|
||||||
let result = 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) {
|
|
||||||
result = await vm.claude(session.worktree, { prompt, print: opts.print })
|
|
||||||
}
|
|
||||||
if (result.output) {
|
if (result.output) {
|
||||||
spin.stop()
|
spin.stop()
|
||||||
process.stdout.write(renderMarkdown(result.output) + "\n")
|
process.stdout.write(renderMarkdown(result.output) + "\n")
|
||||||
|
|
@ -33,10 +30,7 @@ export async function action(
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
spin.succeed("Session ready")
|
spin.succeed("Session ready")
|
||||||
const result = await vm.claude(session.worktree, { prompt, print: opts.print, continue: true })
|
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)
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ import { $ } from "bun"
|
||||||
import { homedir } from "os"
|
import { homedir } from "os"
|
||||||
import { dirname, join } from "path"
|
import { dirname, join } from "path"
|
||||||
import { getApiKey } from "./env.ts"
|
import { getApiKey } from "./env.ts"
|
||||||
|
import { info } from "./fmt.ts"
|
||||||
|
|
||||||
const CONTAINER_NAME = "sandlot"
|
const CONTAINER_NAME = "sandlot"
|
||||||
const USER = "ubuntu"
|
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 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()
|
||||||
const exitCode = await proc.exited
|
const exitCode = await proc.exited
|
||||||
|
if (exitCode !== 0 && opts?.continue) {
|
||||||
|
info("Retrying without --continue")
|
||||||
|
return claude(workdir, { ...opts, continue: false })
|
||||||
|
}
|
||||||
return { exitCode, 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" })
|
||||||
const exitCode = await proc.exited
|
const exitCode = await proc.exited
|
||||||
|
if (exitCode !== 0 && opts?.continue) {
|
||||||
|
info("Retrying without --continue")
|
||||||
|
return claude(workdir, { ...opts, continue: false })
|
||||||
|
}
|
||||||
return { exitCode }
|
return { exitCode }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user