Parse JSONL events in ui-parser for cleaner output
Skip step_start/step_finish/tool_use events in UI display, extract text from type:text events. Provides cleaner real-time output. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
+22
-1
@@ -9,5 +9,26 @@ type TranscriptEntry =
|
||||
| { kind: "system"; ts: string; text: string };
|
||||
|
||||
export function parseStdoutLine(line: string, ts: string): TranscriptEntry[] {
|
||||
return [{ kind: "stdout", ts, text: line }];
|
||||
const trimmed = line.trim();
|
||||
if (!trimmed) return [];
|
||||
|
||||
// Try to parse as JSONL event from opencode run --format json
|
||||
try {
|
||||
const event = JSON.parse(trimmed);
|
||||
const type = typeof event.type === "string" ? event.type : "";
|
||||
const part = typeof event.part === "object" && event.part !== null ? event.part : {};
|
||||
|
||||
if (type === "text" && typeof part.text === "string" && part.text.trim()) {
|
||||
return [{ kind: "stdout", ts, text: part.text.trim() }];
|
||||
}
|
||||
|
||||
// Skip non-display event types
|
||||
if (type === "step_start" || type === "step_finish" || type === "tool_use") {
|
||||
return [];
|
||||
}
|
||||
} catch {
|
||||
// Not JSON — treat as raw stdout
|
||||
}
|
||||
|
||||
return [{ kind: "stdout", ts, text: trimmed }];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user