xonecas.io
64875
Mc

mini-coder / commit f48a636

refactor: keep successful shell tool rendering compact

xonecas2026-03-14 f48a636a0115da8fb75c3c74cd2572f0d39ef9fc parent ed11b2b

2 files changed

src/cli/tool-render-result.test.ts+5−5
@@ -35,11 +35,11 @@ describe("renderToolResult", () => {
3535
3636 const plain = stripAnsi(stdout);
3737 expect(plain).toContain("exit 0 · stdout 2L · stderr 1L");
38- expect(plain).toContain("stdout (2 lines)");
39- expect(plain).toContain("stderr (1 lines)");
38+ expect(plain).not.toContain("stdout (2 lines)");
39+ expect(plain).not.toContain("stderr (1 lines)");
4040 });
4141
42- test("omits long stdout previews for successful shell calls", () => {
42+ test("keeps successful multi-line shell output compact", () => {
4343 terminal.stdoutWrite = (chunk: string) => {
4444 stdout += chunk;
4545 };
@@ -58,7 +58,7 @@ describe("renderToolResult", () => {
5858
5959 const plain = stripAnsi(stdout);
6060 expect(plain).toContain("exit 0 · stdout 5L · stderr 0L");
61- expect(plain).toContain("stdout omitted (5 lines)");
61+ expect(plain).not.toContain("stdout omitted");
6262 expect(plain).not.toContain("stdout (5 lines)");
6363 });
6464
@@ -81,7 +81,7 @@ describe("renderToolResult", () => {
8181
8282 const plain = stripAnsi(stdout);
8383 expect(plain).toContain("exit 0 · stdout 1L · stderr 0L");
84- expect(plain).toContain("stdout: /home/xonecas/src/mini-coder");
84+ expect(plain).toContain("out: /home/xonecas/src/mini-coder");
8585 expect(plain).not.toContain("stdout (1 lines)");
8686 });
8787
src/cli/tool-results/shell.ts+27−44
@@ -2,6 +2,10 @@ import * as c from "yoctocolors";
22 import { writeln } from "../output.ts";
33 import { writePreviewLines } from "../tool-result-shared.ts";
44
5+function truncateOneLine(value: string, max = 100): string {
6+ return value.length > max ? `${value.slice(0, max - 1)}…` : value;
7+}
8+
59 export function renderShellResult(result: unknown): boolean {
610 const r = result as {
711 stdout: string;
@@ -31,61 +35,40 @@ export function renderShellResult(result: unknown): boolean {
3135 const stdoutSingleLine =
3236 stdoutLines === 1 ? (stdoutNormalized.split(/\r?\n/)[0] ?? "") : null;
3337
34- writeln(
35- ` ${badge} ${c.dim(`exit ${r.exitCode} · stdout ${stdoutLines}L · stderr ${stderrLines}L`)}`,
36- );
38+ const parts = [
39+ `exit ${r.exitCode}`,
40+ `stdout ${stdoutLines}L`,
41+ `stderr ${stderrLines}L`,
42+ ];
3743
3844 if (
3945 r.success &&
4046 !r.timedOut &&
4147 stderrLines === 0 &&
42- stdoutSingleLine !== null
48+ stdoutSingleLine !== null &&
49+ stdoutSingleLine.length > 0
4350 ) {
44- const compact =
45- stdoutSingleLine.length > 100
46- ? `${stdoutSingleLine.slice(0, 97)}…`
47- : stdoutSingleLine;
48- if (compact.length > 0) {
49- writeln(` ${c.dim(`stdout: ${compact}`)}`);
50- }
51- return true;
51+ parts.push(`out: ${truncateOneLine(stdoutSingleLine)}`);
5252 }
5353
54- if (!r.success || r.timedOut) {
55- writePreviewLines({
56- label: "stderr",
57- value: r.stderr,
58- lineColor: c.red,
59- maxLines: 6,
60- });
61- writePreviewLines({
62- label: "stdout",
63- value: r.stdout,
64- lineColor: c.dim,
65- maxLines: 4,
66- });
67- return true;
68- }
54+ writeln(` ${badge} ${c.dim(parts.join(" · "))}`);
6955
70- if (stderrLines > 0) {
71- writePreviewLines({
72- label: "stderr",
73- value: r.stderr,
74- lineColor: c.red,
75- maxLines: 4,
76- });
56+ if (r.success && !r.timedOut) {
57+ return true;
7758 }
7859
79- if (stdoutLines > 0 && stdoutLines <= 3) {
80- writePreviewLines({
81- label: "stdout",
82- value: r.stdout,
83- lineColor: c.dim,
84- maxLines: 3,
85- });
86- } else if (stdoutLines > 3) {
87- writeln(` ${c.dim(`stdout omitted (${stdoutLines} lines)`)}`);
88- }
60+ writePreviewLines({
61+ label: "stderr",
62+ value: r.stderr,
63+ lineColor: c.red,
64+ maxLines: 6,
65+ });
66+ writePreviewLines({
67+ label: "stdout",
68+ value: r.stdout,
69+ lineColor: c.dim,
70+ maxLines: 4,
71+ });
8972
9073 return true;
9174 }