A desktop coding agent with free access to frontier models.
TypeScript
feat: show command output
ogsamrat134c596e1bfc
diff --git a/apps/app/src/components/chat/command-output.tsx b/apps/app/src/components/chat/command-output.tsxnew file mode 100644index 00000000..6164bc47--- /dev/null+++ b/apps/app/src/components/chat/command-output.tsx@@ -0,0 +1,101 @@+"use client"++import { useState } from "react"++import { displayRuntimeBrand } from "@/lib/display-runtime-brand"+import {+ boundedCommandOutput,+ previewCommandOutput,+ type CommandOutputView,+} from "@/lib/command-output"+import { cn } from "@/lib/utils"++type CommandOutputProps = {+ /** `partial`: output captured so far from a call that has not finished. */+ output: CommandOutputView & { partial?: boolean }+}++function exitLabel(output: CommandOutputProps["output"]): string | null {+ if (output.running || output.partial || output.exitCode === null) return null+ return `Exit ${output.exitCode}`+}++/**+ * A terminal command's output under its command box: the last lines in a+ * monospace block, expandable to the whole (bounded) output, with the live+ * text while the command runs and its exit code once it ends.+ */+export function CommandOutput({ output }: CommandOutputProps) {+ const [expanded, setExpanded] = useState(false)+ const preview = previewCommandOutput(output.text)+ const full = boundedCommandOutput(output.text)+ const shown = expanded ? full.text : preview.text+ const exit = exitLabel(output)+ const failed = output.exitCode !== null && output.exitCode !== 0+ const empty = output.text.length === 0++ return (+ <div+ data-command-output=""+ data-command-output-state={output.running ? "running" : "done"}+ className="flex min-w-0 max-w-full flex-col rounded-xl border border-border/70 bg-gray-2/40"+ >+ <div className="flex min-w-0 items-center gap-2 px-3 pt-1.5 text-xs text-muted-foreground">+ <span className={cn("shrink-0", output.running && "text-foreground ow-text-shimmer")}>+ {output.running ? "Running…" : output.partial ? "Output so far" : "Output"}+ </span>+ {exit ? (+ <span+ data-command-exit={output.exitCode ?? undefined}+ className={cn("shrink-0 tabular-nums", failed ? "text-destructive" : "text-muted-foreground/70")}+ >+ {exit}+ </span>+ ) : null}+ <span className="min-w-0 flex-1" />+ {preview.clipped ? (+ <button+ type="button"+ data-command-output-toggle=""+ aria-expanded={expanded}+ onClick={() => setExpanded(!expanded)}+ className="shrink-0 cursor-pointer underline-offset-2 hover:text-foreground hover:underline"+ >+ {expanded+ ? "Show less"+ : preview.totalLines > 1+ ? `Show all ${preview.totalLines} lines`+ : "Show all"}+ </button>+ ) : null}+ </div>+ {empty ? (+ <div className="px-3 pt-1 pb-2 text-xs text-muted-foreground/70">+ {output.running ? "Waiting for output…" : "No output"}+ </div>+ ) : (+ <pre+ data-command-output-text=""+ className={cn(+ "min-w-0 px-3 pt-1 pb-2 font-mono text-xs leading-relaxed whitespace-pre-wrap break-words [overflow-wrap:anywhere] text-foreground/85",+ expanded && "max-h-80 overflow-y-auto",+ )}+ >+ {expanded && full.omittedChars > 0 ? (+ <span className="text-muted-foreground/70">{`… ${full.omittedChars.toLocaleString()} earlier characters not shown\n`}</span>+ ) : !expanded && preview.hiddenLines > 0 ? (+ <span className="text-muted-foreground/70">{`… ${preview.hiddenLines} earlier ${preview.hiddenLines === 1 ? "line" : "lines"}\n`}</span>+ ) : null}+ {displayRuntimeBrand(shown)}+ </pre>+ )}+ {output.notes.length > 0 ? (+ <div className="px-3 pb-2 text-xs text-muted-foreground">+ {output.notes.map((note) => (+ <div key={note}>{note}</div>+ ))}+ </div>+ ) : null}+ </div>+ )+}diff --git a/apps/app/src/components/chat/tool-aggregate-group.tsx b/apps/app/src/components/chat/tool-aggregate-group.tsxindex 59f892a2..b6af1511 100644--- a/apps/app/src/components/chat/tool-aggregate-group.tsx+++ b/apps/app/src/components/chat/tool-aggregate-group.tsx@@ -3,6 +3,7 @@import { Fragment, useState } from "react"import { AlertTriangle, Check, ChevronUp, CircleHelp, CirclePause, Copy, MoreHorizontal } from "lucide-react"+import { CommandOutput } from "@/components/chat/command-output"import { FileChip } from "@/components/chat/file-chip"import { ShellCommandText } from "@/components/chat/shell-command-text"import { ReasoningBlock } from "@/components/chat/reasoning-block"@@ -22,6 +23,7 @@ import {} from "@/lib/tool-aggregate"import { isToolPartInFlight } from "@/lib/tool-activity"import { isBashToolPart } from "@/lib/build-in-tools"+import { getCommandOutput } from "@/lib/command-output"import { displayRuntimeBrand } from "@/lib/display-runtime-brand"import { trackToolCallDuration } from "@/lib/tool-call-duration"import { cn } from "@/lib/utils"@@ -405,6 +407,12 @@ export function ToolAggregateGroup({ parts, thoughts = [], className }: ToolAggrconst commandDescription = bash? part.input?.description?.trim() || "command": ""+ // Live output only reads as running while the call is observed+ // running; an unobserved or waiting call shows what arrived so far.+ const rawCommandOutput = bash ? getCommandOutput(part) : null+ const commandOutput = rawCommandOutput?.running && status !== "running"+ ? (rawCommandOutput.text ? { ...rawCommandOutput, running: false, partial: true } : null)+ : rawCommandOutputconst search = bash ? null : getAggregateRowSearch(part)return (<Fragment key={part.toolCallId}>@@ -476,6 +484,7 @@ export function ToolAggregateGroup({ parts, thoughts = [], className }: ToolAggr</div>) : null}{bash && command ? detailBox("command", part.toolCallId, command) : null}+ {commandOutput ? <CommandOutput output={commandOutput} /> : null}{search ? detailBox("pattern", part.toolCallId, search.pattern) : null}{failure ? detailBox("error", part.toolCallId, failure) : null}</div>diff --git a/apps/app/src/lib/command-output.ts b/apps/app/src/lib/command-output.tsnew file mode 100644index 00000000..aaf88ed3--- /dev/null+++ b/apps/app/src/lib/command-output.ts@@ -0,0 +1,143 @@+import type { DynamicToolUIPart, ToolUIPart } from "ai"++import { isBashToolPart } from "./build-in-tools"++type AnyToolPart = ToolUIPart | DynamicToolUIPart++/** Lines a collapsed output box shows: the end, where results and errors land. */+export const COMMAND_OUTPUT_PREVIEW_LINES = 8+/** Characters a collapsed output box shows at most (one very long line). */+export const COMMAND_OUTPUT_PREVIEW_CHARS = 1_200+/** Characters the expanded box renders; the engine already keeps a bounded tail. */+export const COMMAND_OUTPUT_RENDER_CHARS = 100_000+/** Characters of live output forwarded from a running command's metadata. */+export const COMMAND_OUTPUT_METADATA_CHARS = 32_000++export type CommandOutputView = {+ /** Output text with terminal escapes removed; empty when the command printed nothing. */+ text: string+ /** The command is still running; `text` is its latest output so far. */+ running: boolean+ /** Process exit code when the engine reported one. */+ exitCode: number | null+ /** Engine notes (timeout, user abort) appended to the output. */+ notes: string[]+}++export type CommandOutputPreview = {+ text: string+ /** Lines before the preview that are not shown. */+ hiddenLines: number+ /** Whether the preview omits anything. */+ clipped: boolean+ totalLines: number+}++// CSI (colors, cursor moves), OSC (titles, links) and other two-byte escapes.+const CSI = /\u001b\[[0-?]*[ -/]*[@-~]|\u009b[0-?]*[ -/]*[@-~]/g+const OSC = /\u001b\][^\u0007\u001b]*(?:\u0007|\u001b\\)?/g+const ESC = /\u001b[@-Z\\^_]|\u001b[ -/]+[0-~]/g+// Control characters other than tab and newline (\r is handled first).+const CONTROL = /[\u0000-\u0008\u000b-\u001f\u007f]/g++/**+ * Remove terminal escape sequences and resolve carriage returns the way a+ * terminal shows them: a progress bar redrawn with `\r` keeps its last state.+ */+export function stripAnsi(text: string): string {+ const withoutEscapes = text.replace(OSC, "").replace(CSI, "").replace(ESC, "")+ const lines = withoutEscapes.replace(/\r\n/g, "\n").split("\n").map((line) => {+ if (!line.includes("\r")) return line+ const frames = line.split("\r")+ let shown = ""+ for (const frame of frames) {+ // A redraw overwrites from the start of the line.+ shown = frame + shown.slice(frame.length)+ }+ return shown+ })+ return lines.join("\n").replace(CONTROL, "")+}++const NOTE_BLOCK = /\n*<(shell|bash)_metadata>\n?([\s\S]*?)\n?<\/\1_metadata>\s*$/++/** Split the engine's trailing `<shell_metadata>` block from the output. */+export function splitEngineNotes(text: string): { text: string; notes: string[] } {+ const match = text.match(NOTE_BLOCK)+ if (!match) return { text, notes: [] }+ const notes = (match[2] ?? "").split("\n").map((line) => line.trim()).filter(Boolean)+ return { text: text.slice(0, match.index), notes }+}++function isRecord(value: unknown): value is Record<string, unknown> {+ return typeof value === "object" && value !== null && !Array.isArray(value)+}++/** The `omnirush.command` block session sync forwards for bash calls. */+function commandMetadata(part: AnyToolPart): { output?: string; exit?: number | null } {+ const omnirush = (part as DynamicToolUIPart).callProviderMetadata?.omnirush+ const command = isRecord(omnirush) ? omnirush.command : undefined+ if (!isRecord(command)) return {}+ return {+ ...(typeof command.output === "string" ? { output: command.output } : {}),+ ...(typeof command.exit === "number" && Number.isFinite(command.exit) ? { exit: command.exit } : {}),+ }+}++function cleanOutput(raw: string): { text: string; notes: string[] } {+ const split = splitEngineNotes(raw)+ const text = stripAnsi(split.text).replace(/\s+$/, "")+ // The engine reports an empty run as this placeholder.+ return { text: text.trim() === "(no output)" ? "" : text, notes: split.notes }+}++/**+ * What a terminal command card shows: the final output when the call+ * finished, the live output while it runs, whatever was captured when it+ * failed. Null for other tools, or when there is nothing to show yet.+ */+export function getCommandOutput(part: AnyToolPart): CommandOutputView | null {+ if (!isBashToolPart(part)) return null+ const metadata = commandMetadata(part)+ const exitCode = metadata.exit ?? null+ if (part.state === "input-streaming" || part.state === "input-available") {+ const { text, notes } = cleanOutput(metadata.output ?? "")+ return { text, running: true, exitCode: null, notes }+ }+ if (part.state === "output-available") {+ const raw = typeof part.output === "string" ? part.output : metadata.output ?? ""+ const { text, notes } = cleanOutput(raw)+ return { text, running: false, exitCode, notes }+ }+ if (part.state === "output-error") {+ if (metadata.output === undefined) return null+ const { text, notes } = cleanOutput(metadata.output)+ if (!text && notes.length === 0) return null+ return { text, running: false, exitCode, notes }+ }+ return null+}++/** The end of the output that fits the collapsed box. */+export function previewCommandOutput(+ text: string,+ maxLines = COMMAND_OUTPUT_PREVIEW_LINES,+ maxChars = COMMAND_OUTPUT_PREVIEW_CHARS,+): CommandOutputPreview {+ const lines = text.split("\n")+ const kept = lines.slice(-maxLines)+ let preview = kept.join("\n")+ let clipped = kept.length < lines.length+ if (preview.length > maxChars) {+ preview = `…${preview.slice(preview.length - maxChars + 1)}`+ clipped = true+ }+ const shownLines = preview.split("\n").length+ return { text: preview, hiddenLines: Math.max(0, lines.length - shownLines), clipped, totalLines: lines.length }+}++/** The expanded text, bounded so a huge log cannot freeze the chat. */+export function boundedCommandOutput(text: string, maxChars = COMMAND_OUTPUT_RENDER_CHARS): { text: string; omittedChars: number } {+ if (text.length <= maxChars) return { text, omittedChars: 0 }+ return { text: text.slice(text.length - maxChars), omittedChars: text.length - maxChars }+}diff --git a/apps/app/src/react-app/domains/session/sync/parse-tool-parts.ts b/apps/app/src/react-app/domains/session/sync/parse-tool-parts.tsindex 069058ae..343ed883 100644--- a/apps/app/src/react-app/domains/session/sync/parse-tool-parts.ts+++ b/apps/app/src/react-app/domains/session/sync/parse-tool-parts.ts@@ -7,6 +7,7 @@ import {import { safeStringify } from "@/app/utils";import { normalizeErrorText } from "@/lib/error-text";+import { COMMAND_OUTPUT_METADATA_CHARS } from "@/lib/command-output";export const STRUCTURED_OUTPUT_TOOL = "StructuredOutput";@@ -80,7 +81,9 @@ function toolCallProviderMetadata(part: ToolPart): ProviderMetadata {const subagentModelFallback = fallback && typeof fallback.requested === "string" && typeof fallback.used === "string"? { requested: fallback.requested.slice(0, 128), used: fallback.used.slice(0, 128), reason: typeof fallback.reason === "string" ? fallback.reason.slice(0, 64) : "unavailable" }: null;+ const command = part.tool === "bash" ? commandMetadata(part, stateMetadata) : null;const omnirush = {+ ...(command ? { command } : {}),...(mcpResult ? { mcpResult } : {}),...(childSessionId ? { childSessionId } : {}),...(subagentModel ? { subagentModel } : {}),@@ -97,6 +100,24 @@ function toolCallProviderMetadata(part: ToolPart): ProviderMetadata {};}+/**+ * A terminal command's live output (state metadata, updated while it runs)+ * and exit code. A finished call's full output is `state.output`, so only+ * running and failed calls carry the text here.+ */+function commandMetadata(part: ToolPart, stateMetadata: Record<string, unknown>) {+ const exit = typeof stateMetadata.exit === "number" && Number.isFinite(stateMetadata.exit) ? stateMetadata.exit : null;+ const rawOutput = part.state.status !== "completed" && typeof stateMetadata.output === "string" ? stateMetadata.output : null;+ const output = rawOutput !== null && rawOutput.length > COMMAND_OUTPUT_METADATA_CHARS+ ? rawOutput.slice(rawOutput.length - COMMAND_OUTPUT_METADATA_CHARS)+ : rawOutput;+ if (exit === null && output === null) return null;+ return {+ ...(output !== null ? { output } : {}),+ ...(exit !== null ? { exit } : {}),+ };+}+function shouldDeferInProgressTool(part: ToolPart) {if (part.state.status === "completed" || part.state.status === "error") {return false;diff --git a/apps/app/tests/command-output.test.tsx b/apps/app/tests/command-output.test.tsxnew file mode 100644index 00000000..4413eea8--- /dev/null+++ b/apps/app/tests/command-output.test.tsx@@ -0,0 +1,212 @@+/** @jsxImportSource react */+import { describe, expect, test } from "bun:test";+import { renderToStaticMarkup } from "react-dom/server";+import { act } from "react";+import type React from "react";+import { createRoot } from "react-dom/client";+import { GlobalRegistrator } from "@happy-dom/global-registrator";+import type { DynamicToolUIPart } from "ai";+import type { ToolPart } from "@opencode-ai/sdk/v2/client";++import {+ boundedCommandOutput,+ getCommandOutput,+ previewCommandOutput,+ splitEngineNotes,+ stripAnsi,+} from "../src/lib/command-output";+import { CommandOutput } from "../src/components/chat/command-output";+import { ToolAggregateGroup } from "../src/components/chat/tool-aggregate-group";+import { CurrentToolLifecycleProvider } from "../src/components/chat/current-tool-lifecycle-context";+import { parseDynamicToolUIPart } from "../src/react-app/domains/session/sync/parse-tool-parts";++const input = { command: "npm test", description: "Run tests" };++function bash(part: Partial<DynamicToolUIPart> & Pick<DynamicToolUIPart, "state">): DynamicToolUIPart {+ return { type: "dynamic-tool", toolName: "bash", toolCallId: "call-1", input, ...part } as DynamicToolUIPart;+}++function withCommand(command: Record<string, unknown>) {+ return { callProviderMetadata: { opencode: { partId: "p1" }, omnirush: { command } } } as Partial<DynamicToolUIPart>;+}++describe("stripAnsi", () => {+ test("removes colors, cursor moves, titles and links", () => {+ expect(stripAnsi("\u001b[31mred\u001b[0m \u001b[1;32mbold\u001b[m")).toBe("red bold");+ expect(stripAnsi("\u001b]0;title\u0007after")).toBe("after");+ expect(stripAnsi("\u001b]8;;https://x.test\u001b\\link\u001b]8;;\u001b\\")).toBe("link");+ expect(stripAnsi("a\u001b[2Kb\u001b[1Ac")).toBe("abc");+ });++ test("keeps the last redraw of a carriage-return progress line", () => {+ expect(stripAnsi("10%\r50%\r100%\ndone")).toBe("100%\ndone");+ expect(stripAnsi("windows\r\nline")).toBe("windows\nline");+ expect(stripAnsi("long text\rX")).toBe("Xong text");+ });++ test("keeps tabs and newlines, drops other control characters", () => {+ expect(stripAnsi("a\tb\nc\u0007\u0008d")).toBe("a\tb\ncd");+ });+});++describe("engine notes", () => {+ test("splits a trailing shell_metadata block into notes", () => {+ expect(splitEngineNotes("out\n\n<shell_metadata>\nUser aborted the command\n</shell_metadata>")).toEqual({ text: "out", notes: ["User aborted the command"] });+ expect(splitEngineNotes("plain <shell_metadata> mention")).toEqual({ text: "plain <shell_metadata> mention", notes: [] });+ });+});++describe("getCommandOutput", () => {+ test("ignores other tools", () => {+ expect(getCommandOutput({ ...bash({ state: "output-available", output: "x" }), toolName: "read" } as DynamicToolUIPart)).toBeNull();+ });++ test("a finished command shows its output and exit code", () => {+ const view = getCommandOutput(bash({ state: "output-available", output: "\u001b[32mok\u001b[0m 3 passed\n", ...withCommand({ exit: 0 }) }));+ expect(view).toEqual({ text: "ok 3 passed", running: false, exitCode: 0, notes: [] });+ });++ test("an empty run is reported as no output", () => {+ expect(getCommandOutput(bash({ state: "output-available", output: "(no output)" }))?.text).toBe("");+ });++ test("a running command shows its live metadata output", () => {+ const view = getCommandOutput(bash({ state: "input-available", ...withCommand({ output: "line 1\nline 2" }) }));+ expect(view).toEqual({ text: "line 1\nline 2", running: true, exitCode: null, notes: [] });+ expect(getCommandOutput(bash({ state: "input-available" }))).toEqual({ text: "", running: true, exitCode: null, notes: [] });+ });++ test("a failed call shows output captured before the failure, if any", () => {+ expect(getCommandOutput(bash({ state: "output-error", errorText: "aborted" }))).toBeNull();+ expect(getCommandOutput(bash({ state: "output-error", errorText: "aborted", ...withCommand({ output: "partial" }) }))?.text).toBe("partial");+ });+});++describe("previews", () => {+ test("a short output is shown whole", () => {+ expect(previewCommandOutput("a\nb")).toEqual({ text: "a\nb", hiddenLines: 0, clipped: false, totalLines: 2 });+ });++ test("a long output keeps its last lines", () => {+ const text = Array.from({ length: 20 }, (_, index) => `line ${index + 1}`).join("\n");+ const preview = previewCommandOutput(text, 8);+ expect(preview.text.split("\n")).toEqual(Array.from({ length: 8 }, (_, index) => `line ${index + 13}`));+ expect(preview).toMatchObject({ hiddenLines: 12, clipped: true, totalLines: 20 });+ });++ test("one huge line is clipped by characters", () => {+ const preview = previewCommandOutput("x".repeat(5000), 8, 100);+ expect(preview.text.length).toBe(100);+ expect(preview.text.startsWith("…")).toBe(true);+ expect(preview.clipped).toBe(true);+ });++ test("the expanded text is bounded from the end", () => {+ expect(boundedCommandOutput("abcdef", 4)).toEqual({ text: "cdef", omittedChars: 2 });+ expect(boundedCommandOutput("abc", 4)).toEqual({ text: "abc", omittedChars: 0 });+ });+});++describe("CommandOutput card", () => {+ test("renders monospace, newline-preserving output with a failing exit code", () => {+ const markup = renderToStaticMarkup(<CommandOutput output={{ text: "error: boom\nat x", running: false, exitCode: 2, notes: [] }} />);+ expect(markup).toContain("font-mono");+ expect(markup).toContain("whitespace-pre-wrap");+ expect(markup).toContain("error: boom\nat x");+ expect(markup).toContain('data-command-exit="2"');+ expect(markup).toContain("text-destructive");+ expect(markup).not.toContain("data-command-output-toggle");+ });++ test("long output offers to show every line", () => {+ const text = Array.from({ length: 30 }, (_, index) => `l${index}`).join("\n");+ const markup = renderToStaticMarkup(<CommandOutput output={{ text, running: false, exitCode: 0, notes: [] }} />);+ expect(markup).toContain("Show all 30 lines");+ expect(markup).toContain("22 earlier lines");+ expect(markup).not.toContain("l21\n");+ expect(markup).toContain("l29");+ });++ test("a running command says so instead of an exit code", () => {+ const markup = renderToStaticMarkup(<CommandOutput output={{ text: "", running: true, exitCode: null, notes: [] }} />);+ expect(markup).toContain("Running…");+ expect(markup).toContain("Waiting for output…");+ expect(markup).not.toContain("Exit");+ });+});++describe("tool aggregate shows command output", () => {+ test("a collapsed group keeps the output hidden", () => {+ const part = bash({ toolCallId: "agg-collapsed", state: "output-available", output: "secret-ish log" });+ expect(renderToStaticMarkup(<ToolAggregateGroup parts={[part]} />)).not.toContain("data-command-output");+ });++ test("an expanded finished command shows its output under the command", async () => {+ const part = bash({ toolCallId: "agg-done", state: "output-available", output: "hello\nworld", ...withCommand({ exit: 0 }) });+ const markup = await renderExpanded(<ToolAggregateGroup parts={[part]} />);+ expect(markup).toContain("data-command-output");+ expect(markup).toContain("hello\nworld");+ expect(markup).toContain("Exit 0");+ });++ test("a call that is not observed running shows output so far, not a running state", async () => {+ const part = bash({ toolCallId: "agg-unknown", state: "input-available", ...withCommand({ output: "half" }) });+ const markup = await renderExpanded(<ToolAggregateGroup parts={[part]} />);+ expect(markup).toContain("Output so far");+ expect(markup).not.toContain("Running…");+ });++ test("a running observed command streams its output", async () => {+ const part = bash({ toolCallId: "agg-running", state: "input-available", ...withCommand({ output: "step 1" }) });+ const markup = await renderExpanded(+ <CurrentToolLifecycleProvider activityStatus="responding" currentToolCallIds={new Set([part.toolCallId])}>+ <ToolAggregateGroup parts={[part]} />+ </CurrentToolLifecycleProvider>,+ );+ expect(markup).toContain("Running…");+ expect(markup).toContain("step 1");+ });+});++// Groups start collapsed; open one the way a person does, by clicking its summary.+async function renderExpanded(node: React.ReactNode): Promise<string> {+ if (typeof globalThis.document === "undefined") GlobalRegistrator.register();+ Object.defineProperty(globalThis, "IS_REACT_ACT_ENVIRONMENT", { configurable: true, value: true });+ const container = document.createElement("div");+ document.body.append(container);+ const root = createRoot(container);+ await act(async () => { root.render(node); });+ const toggle = container.querySelector<HTMLButtonElement>("button[aria-expanded]");+ await act(async () => { toggle?.click(); });+ const html = container.innerHTML;+ await act(async () => { root.unmount(); });+ container.remove();+ return html;+}++describe("session sync forwards command metadata", () => {+ const base = { id: "prt_1", sessionID: "s", messageID: "m", type: "tool", callID: "c1", tool: "bash" } as const;++ test("running output and exit codes reach the card", () => {+ const running = parseDynamicToolUIPart({ ...base, state: { status: "running", input, title: "", metadata: { output: "live" }, time: { start: 1 } } } as unknown as ToolPart);+ expect(running?.callProviderMetadata?.omnirush).toEqual({ command: { output: "live" } });+ const done = parseDynamicToolUIPart({ ...base, state: { status: "completed", input, output: "final", title: "", metadata: { output: "preview", exit: 1 }, time: { start: 1, end: 2 } } } as unknown as ToolPart);+ expect(done?.callProviderMetadata?.omnirush).toEqual({ command: { exit: 1 } });+ expect(getCommandOutput(done!)).toEqual({ text: "final", running: false, exitCode: 1, notes: [] });+ });++ test("other tools and empty metadata add nothing", () => {+ const read = parseDynamicToolUIPart({ ...base, tool: "read", state: { status: "running", input: { filePath: "a" }, title: "", metadata: { output: "x" }, time: { start: 1 } } } as unknown as ToolPart);+ expect(read?.callProviderMetadata?.omnirush).toBeUndefined();+ const quiet = parseDynamicToolUIPart({ ...base, state: { status: "running", input, title: "", metadata: {}, time: { start: 1 } } } as unknown as ToolPart);+ expect(quiet?.callProviderMetadata?.omnirush).toBeUndefined();+ });++ test("very long live output keeps its end", () => {+ const long = "a".repeat(40_000) + "END";+ const running = parseDynamicToolUIPart({ ...base, state: { status: "running", input, title: "", metadata: { output: long }, time: { start: 1 } } } as unknown as ToolPart);+ const output = (running?.callProviderMetadata?.omnirush as { command: { output: string } }).command.output;+ expect(output.length).toBe(32_000);+ expect(output.endsWith("END")).toBe(true);+ });+});