mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-17 05:26:47 +03:00
fix(cli): report usage for steps that end after run goes idle (#60475)
This commit is contained in:
committed by
GitHub
Unverified
parent
2d96b0f69f
commit
dbd7202f52
@@ -85,6 +85,9 @@ export async function runNonInteractivePrompt(input: Input) {
|
||||
const renderedText = new Map<string, string>()
|
||||
const renderedReasoning = new Map<string, string>()
|
||||
const renderedTools = new Set<string>()
|
||||
// Live step events stop being read once the session goes idle, and the last step usually ends after
|
||||
// that. Reconcile uses this to emit only the step_start/step_finish lines the live stream missed.
|
||||
const steps = new Map<string, "started" | "ended">()
|
||||
let submitted = false
|
||||
let promoted = false
|
||||
let emittedError = false
|
||||
@@ -280,6 +283,7 @@ export async function runNonInteractivePrompt(input: Input) {
|
||||
}
|
||||
continue
|
||||
}
|
||||
steps.set(event.data.assistantMessageID, "started")
|
||||
if (!emit("step_start", time, { part }) && input.format !== "json") {
|
||||
UI.empty()
|
||||
UI.println(`> ${event.data.agent} · ${event.data.model.id}`)
|
||||
@@ -493,6 +497,7 @@ export async function runNonInteractivePrompt(input: Input) {
|
||||
|
||||
if (event.type === "session.step.ended") {
|
||||
flushStep()
|
||||
steps.set(event.data.assistantMessageID, "ended")
|
||||
const part = {
|
||||
id: partID(event.id),
|
||||
sessionID: input.sessionID,
|
||||
@@ -568,6 +573,18 @@ export async function runNonInteractivePrompt(input: Input) {
|
||||
for (const message of projected.messages) {
|
||||
if (message.type !== "assistant") continue
|
||||
const timestamp = message.time.completed ?? message.time.created
|
||||
const step = steps.get(message.id)
|
||||
if (!step) {
|
||||
emit("step_start", message.time.created, {
|
||||
part: {
|
||||
id: projectedPartID(message.id, "step-start"),
|
||||
sessionID: input.sessionID,
|
||||
messageID: message.id,
|
||||
type: "step-start",
|
||||
snapshot: message.snapshot?.start,
|
||||
},
|
||||
})
|
||||
}
|
||||
let textOrdinal = 0
|
||||
let reasoningOrdinal = 0
|
||||
for (const item of message.content) {
|
||||
@@ -660,6 +677,21 @@ export async function runNonInteractivePrompt(input: Input) {
|
||||
UI.error(item.state.error.message)
|
||||
}
|
||||
|
||||
if (step !== "ended" && message.finish && message.tokens) {
|
||||
emit("step_finish", timestamp, {
|
||||
part: {
|
||||
id: projectedPartID(message.id, "step-finish"),
|
||||
sessionID: input.sessionID,
|
||||
messageID: message.id,
|
||||
type: "step-finish",
|
||||
reason: message.finish,
|
||||
snapshot: message.snapshot?.end,
|
||||
cost: message.cost ?? 0,
|
||||
tokens: message.tokens,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
// A declined tool call ends its step with an interrupted-step error that is
|
||||
// only a consequence of our own rejection; it was already reported above.
|
||||
if (message.error && !emittedError && !permissionRejected && !formCancelled) {
|
||||
|
||||
Reference in New Issue
Block a user