Capture text from step_finish message field in parse

OpenCode outputs the final response in step_finish.part.message, not
just as type:text events. Added parsing of part.message to ensure
the summary is captured when the agent responds.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-04-12 08:57:51 -04:00
parent 66893dc286
commit a327255834
2 changed files with 15 additions and 0 deletions
+13
View File
@@ -31,6 +31,19 @@ describe("parseOpenCodeJsonl", () => {
expect(result.costUsd).toBeCloseTo(0.001);
});
it("captures text from step_finish message field", () => {
const stdout = [
JSON.stringify({
type: "step_finish",
part: { message: "Final response text", tokens: { input: 10, output: 5 } },
}),
].join("\n");
const result = parseOpenCodeJsonl(stdout);
expect(result.summary).toBe("Final response text");
});
it("captures errors from error type events", () => {
const stdout = [
JSON.stringify({ type: "error", error: { message: "Something went wrong" } }),
+2
View File
@@ -51,6 +51,8 @@ export function parseOpenCodeJsonl(stdout: string) {
if (type === "step_finish") {
const part = parseObject(event.part);
const text = asString(part.message, "").trim();
if (text) messages.push(text);
const tokens = parseObject(part.tokens);
const cache = parseObject(tokens.cache);
usage.inputTokens += asNumber(tokens.input, 0);