Add CLIAdapterModule with pretty JSONL formatting
New src/cli/format-event.ts handles formatting OpenCode JSONL events: - step_start: skip in normal mode, show in debug - text: display as-is - tool_use: show errors, skip in normal mode - step_finish: show message + tokens/cost in debug - error: display error message Exports cliAdapter.formatStdoutEvent for Paperclip UI to call. Also fixes ui-parser.ts to re-export from format-event.ts. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
+3
-28
@@ -3,32 +3,7 @@
|
||||
* Zero external imports — required by the Paperclip adapter plugin UI parser contract.
|
||||
*/
|
||||
|
||||
type TranscriptEntry =
|
||||
| { kind: "stdout"; ts: string; text: string }
|
||||
| { kind: "stderr"; ts: string; text: string }
|
||||
| { kind: "system"; ts: string; text: string };
|
||||
import type { TranscriptEntry } from "@paperclipai/adapter-utils";
|
||||
import { parseStdoutLine } from "./cli/format-event.js";
|
||||
|
||||
export function parseStdoutLine(line: string, ts: string): TranscriptEntry[] {
|
||||
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 }];
|
||||
}
|
||||
export { parseStdoutLine };
|
||||
|
||||
Reference in New Issue
Block a user