From 9b3decfad65eb852dc60aad24f8e854efaf04f4b Mon Sep 17 00:00:00 2001 From: Devin Foley Date: Fri, 15 May 2026 17:20:20 -0700 Subject: [PATCH] Improve grok transcript readability --- .../grok-local/src/ui/parse-stdout.test.ts | 4 ++-- .../adapters/grok-local/src/ui/parse-stdout.ts | 6 +++--- ui/src/adapters/transcript.test.ts | 17 +++++++++++++++++ 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/packages/adapters/grok-local/src/ui/parse-stdout.test.ts b/packages/adapters/grok-local/src/ui/parse-stdout.test.ts index 9cdc2f4a1fb..715afc8896a 100644 --- a/packages/adapters/grok-local/src/ui/parse-stdout.test.ts +++ b/packages/adapters/grok-local/src/ui/parse-stdout.test.ts @@ -6,10 +6,10 @@ describe("parseGrokStdoutLine", () => { it("maps thought/text/end events into transcript entries", () => { expect(parseGrokStdoutLine(JSON.stringify({ type: "thought", data: "Plan first." }), ts)).toEqual([ - { kind: "thinking", ts, text: "Plan first." }, + { kind: "thinking", ts, text: "Plan first.", delta: true }, ]); expect(parseGrokStdoutLine(JSON.stringify({ type: "text", data: "hello" }), ts)).toEqual([ - { kind: "assistant", ts, text: "hello" }, + { kind: "assistant", ts, text: "hello", delta: true }, ]); expect(parseGrokStdoutLine(JSON.stringify({ type: "end", stopReason: "EndTurn", sessionId: "sess-1" }), ts)).toEqual([ { kind: "system", ts, text: "stop_reason=EndTurn session=sess-1" }, diff --git a/packages/adapters/grok-local/src/ui/parse-stdout.ts b/packages/adapters/grok-local/src/ui/parse-stdout.ts index 1222aa1efd8..e75e0271b7b 100644 --- a/packages/adapters/grok-local/src/ui/parse-stdout.ts +++ b/packages/adapters/grok-local/src/ui/parse-stdout.ts @@ -26,13 +26,13 @@ export function parseGrokStdoutLine(line: string, ts: string): TranscriptEntry[] const type = asString(parsed.type).trim(); if (type === "thought") { - const text = asString(parsed.data).trim(); - return text ? [{ kind: "thinking", ts, text }] : []; + const text = asString(parsed.data); + return text ? [{ kind: "thinking", ts, text, delta: true }] : []; } if (type === "text") { const text = asString(parsed.data); - return text ? [{ kind: "assistant", ts, text }] : []; + return text ? [{ kind: "assistant", ts, text, delta: true }] : []; } if (type === "error") { diff --git a/ui/src/adapters/transcript.test.ts b/ui/src/adapters/transcript.test.ts index ddd164a54d2..56627f328ad 100644 --- a/ui/src/adapters/transcript.test.ts +++ b/ui/src/adapters/transcript.test.ts @@ -1,5 +1,6 @@ import { describe, expect, it } from "vitest"; import { buildTranscript, type RunLogChunk } from "./transcript"; +import { grokLocalUIAdapter } from "./grok-local"; import type { UIAdapterModule } from "./types"; describe("buildTranscript", () => { @@ -182,4 +183,20 @@ describe("buildTranscript", () => { }, ]); }); + + it("coalesces grok_local streaming text fragments into one assistant entry", () => { + const entries = buildTranscript( + [ + { ts, stream: "stdout", chunk: `${JSON.stringify({ type: "text", data: "Hello " })}\n` }, + { ts, stream: "stdout", chunk: `${JSON.stringify({ type: "text", data: "world" })}\n` }, + { ts, stream: "stdout", chunk: `${JSON.stringify({ type: "end", stopReason: "EndTurn", sessionId: "sess-1" })}\n` }, + ], + grokLocalUIAdapter, + ); + + expect(entries).toEqual([ + { kind: "assistant", ts, text: "Hello world", delta: true }, + { kind: "system", ts, text: "stop_reason=EndTurn session=sess-1" }, + ]); + }); });