Skip to content

Commit 6b6f41e

Browse files
fix(opencode): fall back for legacy compacted tool evidence
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <[email protected]>
1 parent 011092a commit 6b6f41e

3 files changed

Lines changed: 53 additions & 9 deletions

File tree

packages/opencode/src/session/evidence.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ export namespace Evidence {
3232
return [...list.slice(0, FILE_MAX), `+${list.length - FILE_MAX} more`]
3333
}
3434

35-
function path(input: MessageV2.ToolStateCompleted["metadata"]) {
36-
return typeof input.outputPath === "string" ? input.outputPath : undefined
35+
function path(input?: MessageV2.ToolStateCompleted["metadata"]) {
36+
return typeof input?.outputPath === "string" ? input.outputPath : undefined
3737
}
3838

3939
export function tool(input: {

packages/opencode/src/session/message-v2.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -718,13 +718,10 @@ export namespace MessageV2 {
718718
toolNames.add(part.tool)
719719
if (part.state.status === "completed") {
720720
const state = part.state
721-
const outputText = state.time.compacted
722-
? Evidence.text(
723-
Evidence.isTool(state.metadata.evidence)
724-
? state.metadata.evidence
725-
: Evidence.tool({ tool: part.tool, state }),
726-
)
727-
: state.output
721+
const proof = Evidence.isTool(state.metadata?.evidence)
722+
? state.metadata.evidence
723+
: Evidence.tool({ tool: part.tool, state })
724+
const outputText = state.time.compacted ? Evidence.text(proof) : state.output
728725
const attachments = state.time.compacted || options?.stripMedia ? [] : (state.attachments ?? [])
729726

730727
// For providers that don't support media in tool results, extract media files

packages/opencode/test/session/message-v2.test.ts

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,53 @@ describe("session.message-v2.toModelMessage", () => {
519519
expect(text).not.toContain("[Old tool result content cleared]")
520520
})
521521

522+
test("replaces compacted tool output when legacy evidence metadata is missing", async () => {
523+
const userID = "m-user-legacy"
524+
const assistantID = "m-assistant-legacy"
525+
526+
const input = [
527+
{
528+
info: userInfo(userID),
529+
parts: [
530+
{
531+
...basePart(userID, "u1"),
532+
type: "text",
533+
text: "run tool",
534+
},
535+
] as MessageV2.Part[],
536+
},
537+
{
538+
info: assistantInfo(assistantID, userID),
539+
parts: [
540+
{
541+
...basePart(assistantID, "a1"),
542+
type: "tool",
543+
callID: "call-legacy",
544+
tool: "bash",
545+
state: {
546+
status: "completed",
547+
input: { cmd: "pwd" },
548+
output: "legacy compacted output",
549+
title: "Bash",
550+
metadata: undefined,
551+
time: { start: 0, end: 1, compacted: 1 },
552+
},
553+
},
554+
] as unknown as MessageV2.Part[],
555+
},
556+
] satisfies MessageV2.WithParts[]
557+
558+
const result = await MessageV2.toModelMessages(input, model)
559+
const tool = result[2] as {
560+
content: Array<{
561+
output: { value: string }
562+
}>
563+
}
564+
565+
expect(tool.content[0]?.output.value).toContain("tool: bash")
566+
expect(tool.content[0]?.output.value).toContain("excerpt:\nlegacy compacted output")
567+
})
568+
522569
test("converts assistant tool error into error-text tool result", async () => {
523570
const userID = "m-user"
524571
const assistantID = "m-assistant"

0 commit comments

Comments
 (0)