xonecas.io
64875
Mc

mini-coder / commit 501746f

refactor(cli): compact successful shell tool output

xonecas2026-03-14 501746f26dd982b127faf1b45690e6167f9045e0 parent 8c81d62

2 files changed

src/cli/tool-render-result.test.ts+23−0
@@ -62,6 +62,29 @@ describe("renderToolResult", () => {
6262 expect(plain).not.toContain("stdout (5 lines)");
6363 });
6464
65+ test("renders compact one-line stdout for successful shell calls", () => {
66+ terminal.stdoutWrite = (chunk: string) => {
67+ stdout += chunk;
68+ };
69+
70+ renderToolResult(
71+ "shell",
72+ {
73+ stdout: "/home/xonecas/src/mini-coder\n",
74+ stderr: "",
75+ exitCode: 0,
76+ success: true,
77+ timedOut: false,
78+ },
79+ false,
80+ );
81+
82+ const plain = stripAnsi(stdout);
83+ expect(plain).toContain("exit 0 · stdout 1L · stderr 0L");
84+ expect(plain).toContain("stdout: /home/xonecas/src/mini-coder");
85+ expect(plain).not.toContain("stdout (1 lines)");
86+ });
87+
6588 test("renders file edit diff for create", () => {
6689 terminal.stdoutWrite = (chunk: string) => {
6790 stdout += chunk;
src/cli/tool-result-handlers.ts+26−2
@@ -64,13 +64,37 @@ function renderShellResult(result: unknown): boolean {
6464 ? c.green("success")
6565 : c.red("error");
6666
67- const stdoutLines = r.stdout.trim() ? r.stdout.split("\n").length : 0;
68- const stderrLines = r.stderr.trim() ? r.stderr.split("\n").length : 0;
67+ const stdoutNormalized = r.stdout.replace(/[\r\n]+$/, "");
68+ const stderrNormalized = r.stderr.replace(/[\r\n]+$/, "");
69+ const stdoutLines = stdoutNormalized
70+ ? stdoutNormalized.split(/\r?\n/).length
71+ : 0;
72+ const stderrLines = stderrNormalized
73+ ? stderrNormalized.split(/\r?\n/).length
74+ : 0;
75+ const stdoutSingleLine =
76+ stdoutLines === 1 ? (stdoutNormalized.split(/\r?\n/)[0] ?? "") : null;
6977
7078 writeln(
7179 ` ${badge} ${c.dim(`exit ${r.exitCode} · stdout ${stdoutLines}L · stderr ${stderrLines}L`)}`,
7280 );
7381
82+ if (
83+ r.success &&
84+ !r.timedOut &&
85+ stderrLines === 0 &&
86+ stdoutSingleLine !== null
87+ ) {
88+ const compact =
89+ stdoutSingleLine.length > 100
90+ ? `${stdoutSingleLine.slice(0, 97)}…`
91+ : stdoutSingleLine;
92+ if (compact.length > 0) {
93+ writeln(` ${c.dim(`stdout: ${compact}`)}`);
94+ }
95+ return true;
96+ }
97+
7498 if (!r.success || r.timedOut) {
7599 writePreviewLines({
76100 label: "stderr",