mirror of
https://github.com/anomalyco/opencode.git
synced 2026-06-01 19:05:38 +00:00
fix(run): restore non-interactive exit behavior (#27371)
This commit is contained in:
@@ -24,6 +24,7 @@ import { Filesystem } from "@/util/filesystem"
|
|||||||
import { createOpencodeClient, type OpencodeClient, type ToolPart } from "@opencode-ai/sdk/v2"
|
import { createOpencodeClient, type OpencodeClient, type ToolPart } from "@opencode-ai/sdk/v2"
|
||||||
import { Agent } from "@/agent/agent"
|
import { Agent } from "@/agent/agent"
|
||||||
import { Permission } from "@/permission"
|
import { Permission } from "@/permission"
|
||||||
|
import { FormatError, FormatUnknownError } from "../error"
|
||||||
import { INTERACTIVE_INPUT_ERROR, resolveInteractiveStdin } from "./run/runtime.stdin"
|
import { INTERACTIVE_INPUT_ERROR, resolveInteractiveStdin } from "./run/runtime.stdin"
|
||||||
|
|
||||||
const runtimeTask = import("./run/runtime")
|
const runtimeTask = import("./run/runtime")
|
||||||
@@ -82,6 +83,10 @@ function block(info: Inline, output?: string) {
|
|||||||
UI.empty()
|
UI.empty()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function formatRunError(error: unknown) {
|
||||||
|
return FormatError(error) ?? FormatUnknownError(error)
|
||||||
|
}
|
||||||
|
|
||||||
async function tool(part: ToolPart) {
|
async function tool(part: ToolPart) {
|
||||||
try {
|
try {
|
||||||
const { toolInlineInfo } = await import("./run/tool")
|
const { toolInlineInfo } = await import("./run/tool")
|
||||||
@@ -731,10 +736,13 @@ export const RunCommand = effectCmd({
|
|||||||
|
|
||||||
if (!args.interactive) {
|
if (!args.interactive) {
|
||||||
const events = await client.event.subscribe()
|
const events = await client.event.subscribe()
|
||||||
const completed = loop(client, events)
|
loop(client, events).catch((e) => {
|
||||||
|
console.error(e)
|
||||||
|
process.exit(1)
|
||||||
|
})
|
||||||
|
|
||||||
if (args.command) {
|
if (args.command) {
|
||||||
await client.session.command({
|
const result = await client.session.command({
|
||||||
sessionID,
|
sessionID,
|
||||||
agent,
|
agent,
|
||||||
model: args.model,
|
model: args.model,
|
||||||
@@ -742,21 +750,25 @@ export const RunCommand = effectCmd({
|
|||||||
arguments: message,
|
arguments: message,
|
||||||
variant: args.variant,
|
variant: args.variant,
|
||||||
})
|
})
|
||||||
const error = await completed
|
if (result.error) {
|
||||||
if (error) process.exitCode = 1
|
if (!emit("error", { error: result.error })) UI.error(formatRunError(result.error))
|
||||||
|
process.exitCode = 1
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const model = pick(args.model)
|
const model = pick(args.model)
|
||||||
await client.session.prompt({
|
const result = await client.session.prompt({
|
||||||
sessionID,
|
sessionID,
|
||||||
agent,
|
agent,
|
||||||
model,
|
model,
|
||||||
variant: args.variant,
|
variant: args.variant,
|
||||||
parts: [...files, { type: "text", text: message }],
|
parts: [...files, { type: "text", text: message }],
|
||||||
})
|
})
|
||||||
const error = await completed
|
if (result.error) {
|
||||||
if (error) process.exitCode = 1
|
if (!emit("error", { error: result.error })) UI.error(formatRunError(result.error))
|
||||||
|
process.exitCode = 1
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user