xonecas.io
64875
Mc

mini-coder / commit 6b1b19d

feat(ui): align verbose tool rendering with spec

xonecas2026-04-09 6b1b19d89f15a3e21c352899c1fb5dc92d15453a parent 7c721f8

3 files changed

spec.md+26−15
@@ -504,13 +504,24 @@ Message types and their rendering:
504504
505505 - **User messages**: displayed as plain text with a subtle background color to distinguish them from agent responses. No prefix or role indicator.
506506 - **Assistant messages**: streamed markdown rendered via cel-tui's `Markdown` component on the default background. Thinking/reasoning content is collapsible (shown or hidden according to the user's persisted `/reasoning` preference; defaults to shown when no setting exists).
507-- **Tool calls — shell**: rendered with a left border (`│`) and dimmed foreground. The assistant tool call streams the arguments as they arrive. The shell tool result is rendered as the tool output (not the raw json, the content), with no extra header or placeholder lines. When `/verbose` is off, shell output is previewed as the first 20 lines followed by `And X lines more` when additional lines exist. When `/verbose` is on, the shell block expands to the full stored tool result. This is a U …
508-- **Tool calls — edit**: rendered with a left border (`│`) and dimmed foreground. Shows the arguments streamed in, preserving whitespace (the content of the arguments, not JSON). Then shows a unified diff of the change (added lines in green, removed in red). When `/verbose` is off, the diff preview shows the first 20 diff lines followed by `And X lines more` when additional lines exist. When `/verbose` is on, the diff expands to the full stored tool result. This is a UI-only display choice. …
507+- **Tool calls — shell**: rendered with a left border (`│`) and dimmed foreground. The assistant tool call streams the arguments as they arrive. The command preview and shell tool result body use [verbose tool rendering](#verbose-tool-rendering). The shell tool result is rendered as the tool output (not the raw json, the content), with no extra header or placeholder lines.
508+- **Tool calls — edit**: rendered with a left border (`│`) and dimmed foreground. Shows the arguments streamed in, preserving whitespace (the content of the arguments, not JSON). The in-progress tool-call preview uses [verbose tool rendering](#verbose-tool-rendering). Successful results then show a unified diff of the change (added lines in green, removed in red) in full. Uses the `diff` package (`structuredPatch`) for line-level unified diffs.
509509 - **Tool calls — readImage**: rendered with a left border (`│`) and dimmed foreground. The assistant tool call streams the arguments as they arrive (the path, not the JSON). Successful tool results display the text `Read image.` instead of rendering the image itself.
510510 - **Tool calls — plugin tools**: rendered with a left border, prefixed with plugin/tool name.
511511 - **UI messages**: internal app messages such as `/help` output, OAuth progress, and other session-local notices. They are rendered in the conversation log, persisted with the session, excluded from model context, and do not participate in conversational turn numbering.
512512 - **Errors**: one-line summary, styled distinctly.
513513
514+#### Verbose tool rendering
515+
516+`/verbose` controls a single persisted UI preference for how tool-call previews and selected tool-result bodies are displayed in the conversation log.
517+
518+- Scope: shell tool-call bodies, shell tool-result bodies, edit tool-call preview bodies, and edit error results only. Successful edit results render as a unified diff, and that diff is always shown in full.
519+- Default: off when no saved setting exists.
520+- Off: show the last 8 lines followed by `And X lines more` when additional lines exist.
521+- On: show the full stored tool result or preview body.
522+- Persistence: the new on/off state is saved immediately and restored on launch.
523+- This is a UI-only display choice over streamed tool-call previews and stored tool results; it does not affect tool execution or the shell tool's own safety truncation for pathological output.
524+
514525 While the agent is working, the top divider (above the input area) animates with a scanning pulse — a bright and colored (be creative) segment sweeping across the dimmed divider line. The animation starts when a turn begins and stops when the turn ends (done, error, or aborted). No per-activity state tracking.
515526
516527 ### Input area
@@ -541,19 +552,19 @@ Supports:
541552
542553 ### Commands
543554
544-| Command | Description |
545-| ------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
546-| `/model` | Interactive model selector. Switching models mid-session is allowed — pi-ai's context is model-agnostic. The `readImage` tool is re-evaluated (added/removed based on the new model's capabilities). The status bar updates immediately, and the selected model is persisted immediately as the user's global default. The session record's `model` field is not updated (it reflects the initial choice). |
547-| `/session` | Interactive session manager (list, resume). Sessions scoped to CWD. |
548-| `/new` | Start a new session. Clears conversation, resets cost/token counters. |
549-| `/fork` | Fork the current conversation into a new session. Copies the full message history, continues from here independently. The original session is preserved. |
550-| `/undo` | Remove the last conversational turn from history: the most recent user message and all assistant/tool messages that followed in that turn. Persisted UI messages are not part of turns and are not removed by `/undo`. Context-only — does not revert filesystem changes. |
551-| `/reasoning` | Toggle display of model thinking/reasoning content in the log. The new on/off state is persisted immediately and restored on launch. When no setting exists yet, reasoning defaults to shown. |
552-| `/verbose` | Toggle full shell-output and edit-diff display in the UI. When off, those tool blocks show a concise preview (first 20 lines plus `And X lines more` when applicable). When on, they expand to the full stored tool result. This setting only affects UI rendering; it does not control tool-level safety truncation. The new on/off state is persisted immediately and restored on launch. When no setting exists yet, verbose mode defaults to off. |
553-| `/login` | Interactive OAuth login. Shows a selector with available OAuth providers and their login status (logged in / not logged in). Selecting a provider starts the browser-based OAuth flow. Uses pi-ai's OAuth registry. Credentials are persisted to the app data directory and used for provider discovery on subsequent launches. |
554-| `/logout` | Interactive OAuth logout. Shows a selector with logged-in OAuth providers. Selecting one clears its saved credentials. |
555-| `/effort` | Interactive effort selector. Shows the four reasoning levels (`low`, `med`, `high`, `xhigh`) with the current level highlighted. Updates the status bar immediately, and the selected effort is persisted immediately as the user's global default. The session record's `effort` field is not updated (it reflects the initial choice, like `/model`). |
556-| `/help` | List available commands, including the current on/off state of `/reasoning` and `/verbose`, plus loaded AGENTS.md files, discovered skills, and active plugins. |
555+| Command | Description |
556+| ------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
557+| `/model` | Interactive model selector. Switching models mid-session is allowed — pi-ai's context is model-agnostic. The `readImage` tool is re-evaluated (added/removed based on the new model's capabilities). The status bar updates immediately, and the selected model is persisted immediately as the user's global default. The session record's `model` field is not updated (it reflects the initial choice). |
558+| `/session` | Interactive session manager (list, resume). Sessions scoped to CWD. |
559+| `/new` | Start a new session. Clears conversation, resets cost/token counters. |
560+| `/fork` | Fork the current conversation into a new session. Copies the full message history, continues from here independently. The original session is preserved. |
561+| `/undo` | Remove the last conversational turn from history: the most recent user message and all assistant/tool messages that followed in that turn. Persisted UI messages are not part of turns and are not removed by `/undo`. Context-only — does not revert filesystem changes. |
562+| `/reasoning` | Toggle display of model thinking/reasoning content in the log. The new on/off state is persisted immediately and restored on launch. When no setting exists yet, reasoning defaults to shown. |
563+| `/verbose` | Toggle [verbose tool rendering](#verbose-tool-rendering) for shell previews/results, edit previews, and edit errors. Successful edit diffs always render in full. |
564+| `/login` | Interactive OAuth login. Shows a selector with available OAuth providers and their login status (logged in / not logged in). Selecting a provider starts the browser-based OAuth flow. Uses pi-ai's OAuth registry. Credentials are persisted to the app data directory and used for provider discovery on subsequent launches. |
565+| `/logout` | Interactive OAuth logout. Shows a selector with logged-in OAuth providers. Selecting one clears its saved credentials. |
566+| `/effort` | Interactive effort selector. Shows the four reasoning levels (`low`, `med`, `high`, `xhigh`) with the current level highlighted. Updates the status bar immediately, and the selected effort is persisted immediately as the user's global default. The session record's `effort` field is not updated (it reflects the initial choice, like `/model`). |
567+| `/help` | List available commands, including the current on/off state of `/reasoning` and `/verbose`, plus loaded AGENTS.md files, discovered skills, and active plugins. |
557568
558569 Commands are discoverable when the input starts with `/`: pressing `Tab` in that state switches from file-path autocomplete to interactive command select/filter.
559570
src/ui/conversation.test.ts+85−16
@@ -270,7 +270,11 @@ describe("ui/conversation", () => {
270270 });
271271
272272 expect(previewNodes).not.toBe(verboseNodes);
273- expect(previewText).toContain("And 5 lines more");
273+ expect(previewText).toContain("line 18");
274+ expect(previewText).toContain("line 25");
275+ expect(previewText).toContain("And 17 lines more");
276+ expect(previewText).not.toContain("line 17");
277+ expect(verboseText).toContain("line 17");
274278 expect(verboseText).toContain("line 25");
275279 });
276280
@@ -320,6 +324,26 @@ describe("ui/conversation", () => {
320324 expect(text).not.toContain("Preparing...");
321325 });
322326
327+ test("renderAssistantMessage shows the last 8 lines of multi-line shell commands when verbose mode is off", () => {
328+ const command = Array.from({ length: 10 }, (_, i) => `echo ${i + 1}`).join(
329+ "\n",
330+ );
331+
332+ const node = renderAssistantMessage(
333+ {
334+ content: [fauxToolCall("shell", { command }, { id: "tool-1" })],
335+ },
336+ RENDER_OPTS,
337+ );
338+ const text = collectText(node);
339+
340+ expect(text.some((line) => /(^|\s)echo 3$/.test(line))).toBe(true);
341+ expect(text.some((line) => /(^|\s)echo 10$/.test(line))).toBe(true);
342+ expect(text).toContain("And 2 lines more");
343+ expect(text.some((line) => /(^|\s)echo 1$/.test(line))).toBe(false);
344+ expect(text.some((line) => /(^|\s)echo 2$/.test(line))).toBe(false);
345+ });
346+
323347 test("renderAssistantMessage shows streamed readImage arguments semantically", () => {
324348 const node = renderAssistantMessage(
325349 {
@@ -374,24 +398,24 @@ describe("ui/conversation", () => {
374398 expect(preview).toEqual(lines);
375399 });
376400
377- test("previewToolRenderLines shows first 20 lines plus a summary when verbose mode is off", () => {
401+ test("previewToolRenderLines shows the last 8 lines plus a summary when verbose mode is off", () => {
378402 const lines: ToolRenderLine[] = Array.from({ length: 25 }, (_, i) => ({
379403 kind: "text",
380404 text: `line ${i + 1}`,
381405 }));
382406
383- const preview = previewToolRenderLines(lines, false, 20);
407+ const preview = previewToolRenderLines(lines, false);
384408
385- expect(preview).toHaveLength(21);
386- expect(preview.at(0)?.text).toBe("line 1");
387- expect(preview.at(19)?.text).toBe("line 20");
388- expect(preview.at(20)).toEqual({
409+ expect(preview).toHaveLength(9);
410+ expect(preview.at(0)?.text).toBe("line 18");
411+ expect(preview.at(7)?.text).toBe("line 25");
412+ expect(preview.at(8)).toEqual({
389413 kind: "summary",
390- text: "And 5 lines more",
414+ text: "And 17 lines more",
391415 });
392416 });
393417
394- test("renderToolResult truncates shell output in non-verbose mode", () => {
418+ test("renderToolResult shows the last 8 shell-output lines in non-verbose mode", () => {
395419 const output = Array.from({ length: 25 }, (_, i) => `line ${i + 1}`).join(
396420 "\n",
397421 );
@@ -405,10 +429,10 @@ describe("ui/conversation", () => {
405429 );
406430 const text = collectText(node);
407431
408- expect(text).toContain("line 1");
409- expect(text).toContain("line 20");
410- expect(text).toContain("And 5 lines more");
411- expect(text).not.toContain("line 21");
432+ expect(text).toContain("line 18");
433+ expect(text).toContain("line 25");
434+ expect(text).toContain("And 17 lines more");
435+ expect(text).not.toContain("line 17");
412436 expect(text).not.toContain("$ seq 1 25");
413437 });
414438
@@ -460,6 +484,26 @@ describe("ui/conversation", () => {
460484 expect(text).not.toContain("~ diagram.png");
461485 });
462486
487+ test("renderToolResult shows full readImage errors even in non-verbose mode", () => {
488+ const errorText = Array.from(
489+ { length: 25 },
490+ (_, i) => `error ${i + 1}`,
491+ ).join("\n");
492+
493+ const node = renderToolResult(
494+ "readImage",
495+ { path: "diagram.png" },
496+ errorText,
497+ true,
498+ RENDER_OPTS,
499+ );
500+ const text = collectText(node);
501+
502+ expect(text).toContain("error 1");
503+ expect(text).toContain("error 25");
504+ expect(text.some((line) => /^And \d+ lines more$/.test(line))).toBe(false);
505+ });
506+
463507 test("renderToolResult shows a diff for newly created files", () => {
464508 const node = renderToolResult(
465509 "edit",
@@ -475,7 +519,7 @@ describe("ui/conversation", () => {
475519 expect(text).not.toContain("(new file)");
476520 });
477521
478- test("renderToolResult truncates edit diffs in non-verbose mode", () => {
522+ test("renderToolResult shows full edit diffs even in non-verbose mode", () => {
479523 const oldText = Array.from({ length: 25 }, (_, i) => `old ${i + 1}`).join(
480524 "\n",
481525 );
@@ -493,8 +537,8 @@ describe("ui/conversation", () => {
493537 const text = collectText(node);
494538
495539 expect(text).not.toContain("~ src/file.ts");
496- expect(text.at(-1)).toMatch(/^And \d+ lines more$/);
497- expect(text).not.toContain("+new 11");
540+ expect(text).toContain("+new 25");
541+ expect(text.some((line) => /^And \d+ lines more$/.test(line))).toBe(false);
498542 });
499543
500544 test("renderToolResult shows full edit diffs in verbose mode", () => {
@@ -517,4 +561,29 @@ describe("ui/conversation", () => {
517561 expect(text).toContain("+new 25");
518562 expect(text.some((line) => /^And \d+ lines more$/.test(line))).toBe(false);
519563 });
564+
565+ test("renderToolResult previews edit errors in non-verbose mode", () => {
566+ const errorText = Array.from(
567+ { length: 25 },
568+ (_, i) => `error ${i + 1}`,
569+ ).join("\n");
570+
571+ const node = renderToolResult(
572+ "edit",
573+ {
574+ path: "src/file.ts",
575+ oldText: "before",
576+ newText: "after",
577+ },
578+ errorText,
579+ true,
580+ RENDER_OPTS,
581+ );
582+ const text = collectText(node);
583+
584+ expect(text).toContain("error 18");
585+ expect(text).toContain("error 25");
586+ expect(text).toContain("And 17 lines more");
587+ expect(text).not.toContain("error 17");
588+ });
520589 });
src/ui/conversation.ts+46−27
@@ -22,8 +22,8 @@ import type { AppState } from "../index.ts";
2222 import type { UiMessage } from "../session.ts";
2323 import type { Theme } from "../theme.ts";
2424
25-/** Max body lines shown for tool results when verbose mode is off. */
26-const UI_TOOL_PREVIEW_LINES = 20;
25+/** Max body lines shown for tool previews/results when verbose mode is off. */
26+const UI_TOOL_PREVIEW_LINES = 8;
2727
2828 /** A pending tool result shown in the streaming tail. */
2929 export interface PendingToolResult {
@@ -261,10 +261,7 @@ export function renderAssistantMessage(
261261 /** Split multi-line tool text into logical render lines. */
262262 function splitToolTextLines(
263263 text: string,
264- kind: Exclude<
265- ToolRenderLineKind,
266- "command" | "path" | "toolName" | "summary"
267- >,
264+ kind: Exclude<ToolRenderLineKind, "path" | "toolName" | "summary">,
268265 ): ToolRenderLine[] {
269266 if (text === "") {
270267 return [];
@@ -281,8 +278,8 @@ function getToolArgString(args: Record<string, unknown>, key: string): string {
281278 /**
282279 * Apply the UI preview policy to tool body lines.
283280 *
284- * When verbose mode is off, only the first `maxLines` body lines are shown,
285- * followed by a summary line reporting how many lines remain hidden.
281+ * When verbose mode is off, only the last `maxLines` body lines are shown,
282+ * followed by a summary line reporting how many earlier lines were hidden.
286283 *
287284 * @param lines - Full body lines for the tool output.
288285 * @param verbose - Whether verbose mode is enabled.
@@ -299,7 +296,7 @@ export function previewToolRenderLines(
299296 }
300297
301298 return [
302- ...lines.slice(0, maxLines),
299+ ...lines.slice(-maxLines),
303300 {
304301 kind: "summary",
305302 text: `And ${lines.length - maxLines} lines more`,
@@ -532,13 +529,9 @@ function buildEditToolLines(
532529 }
533530
534531 const diffLines = getCachedEditToolDiffLines(args);
535-
536- return previewToolRenderLines(
537- diffLines.length > 0
538- ? diffLines
539- : [{ kind: "summary", text: "(empty file)" }],
540- verbose,
541- );
532+ return diffLines.length > 0
533+ ? diffLines
534+ : [{ kind: "summary", text: "(empty file)" }];
542535 }
543536
544537 /** Render a single styled text node for a tool line. */
@@ -601,11 +594,6 @@ function buildToolHeaderLine(
601594 toolName: string,
602595 args: Record<string, unknown>,
603596 ): ToolRenderLine | null {
604- if (toolName === "shell") {
605- const command = getToolArgString(args, "command");
606- return command ? { kind: "command", text: `$ ${command}` } : null;
607- }
608-
609597 if (toolName === "edit" || toolName === "readImage") {
610598 const filePath = getToolArgString(args, "path");
611599 return filePath ? { kind: "path", text: `~ ${filePath}` } : null;
@@ -614,6 +602,36 @@ function buildToolHeaderLine(
614602 return { kind: "toolName", text: toolName };
615603 }
616604
605+function prefixFirstLine(
606+ lines: readonly ToolRenderLine[],
607+ prefix: string,
608+): ToolRenderLine[] {
609+ if (lines.length === 0) {
610+ return [];
611+ }
612+
613+ return lines.map((line, index) => {
614+ if (index !== 0 || line.kind === "summary") {
615+ return line;
616+ }
617+
618+ return {
619+ ...line,
620+ text: `${prefix}${line.text}`,
621+ };
622+ });
623+}
624+
625+function buildShellToolCallLines(
626+ command: string,
627+ verbose: boolean,
628+): ToolRenderLine[] {
629+ return prefixFirstLine(
630+ previewToolRenderLines(splitToolTextLines(command, "command"), verbose),
631+ "$ ",
632+ );
633+}
634+
617635 function buildEditToolCallLines(
618636 filePath: string,
619637 oldText: string,
@@ -641,7 +659,11 @@ function buildToolCallLines(
641659 args: Record<string, unknown>,
642660 verbose: boolean,
643661 ): ToolRenderLine[] {
644- if (toolName === "shell" || toolName === "readImage") {
662+ if (toolName === "shell") {
663+ return buildShellToolCallLines(getToolArgString(args, "command"), verbose);
664+ }
665+
666+ if (toolName === "readImage") {
645667 const header = buildToolHeaderLine(toolName, args);
646668 return header ? [header] : [];
647669 }
@@ -682,13 +704,10 @@ function renderToolCall(
682704 function buildReadImageToolLines(
683705 content: ToolResultMessage["content"],
684706 isError: boolean,
685- verbose: boolean,
707+ _verbose: boolean,
686708 ): ToolRenderLine[] {
687709 if (isError) {
688- return previewToolRenderLines(
689- splitToolTextLines(getToolContentText(content), "error"),
690- verbose,
691- );
710+ return splitToolTextLines(getToolContentText(content), "error");
692711 }
693712
694713 return [{ kind: "text", text: "Read image." }];