From 5f42a6902a1cc1782dadc08d3c7e935fc3bd4bb5 Mon Sep 17 00:00:00 2001 From: Anthony Ettinger Date: Sat, 14 Nov 2026 14:51:59 +0000 Subject: [PATCH] fix(agents c0mpute): show each tool call once, not 2-3 times (v0.125.2) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit tool_start printed "● Bash(ping x)", then the permission prompt printed its own "● Bash(ping x)" header and the command again as its preview, so every call appeared two or three times. The prompt now skips the header when tool_start just printed it, and skips a one-line preview that only repeats the title. Co-Authored-By: Claude Opus 5.5 --- package.json | 2 +- src/c0agent-repl.mjs | 24 +++++++++++++++++++++--- test/c0agent-status.test.mjs | 8 ++++++++ 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 30ec12c4..e7f7639f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "moshcode", - "version": "0.125.1", + "version": "0.125.2", "type": "module", "description": "moshcode — a metal wrapper for coding engines and native UGig/CoinPay workflow CLIs, with OpenPRD and moshscript", "repository": { diff --git a/src/c0agent-repl.mjs b/src/c0agent-repl.mjs index c97eb4c2..17c7428e 100644 --- a/src/c0agent-repl.mjs +++ b/src/c0agent-repl.mjs @@ -128,6 +128,18 @@ export function fitSpinnerLabel(label, suffix, columns) { return chars.length <= room ? label : `${chars.slice(0, room - 1).join("")}…`; } +/** Whether the permission prompt needs its own "● " line. */ +export function permissionHeader(header, justPrinted) { + return header !== justPrinted; +} + +/** Preview lines for the permission prompt, minus a lone line that only repeats the title. */ +export function previewLines(preview, title) { + const lines = String(preview ?? "").split("\n").slice(0, 24); + if (lines.length === 1 && lines[0].trim() && String(title ?? "").includes(lines[0].trim())) return []; + return lines; +} + /** A spinner on one line of stderr that steps aside whenever real output prints. */ function createSpinner(stream = process.stderr) { const frames = ["✻", "✳", "✢", "·", "✢", "✳"]; @@ -211,12 +223,15 @@ export function statusLabel(status, job, { promptTokens = 0, agent = null, now = function createRenderer({ out, log, spinner, quiet = false }) { let atLineStart = true; let wroteText = false; + let lastToolTitle = null; const line = (s) => { spinner.stop(); if (!atLineStart) { out("\n"); atLineStart = true; } log(s); }; const jobs = new Map(); // agent@depth -> {node, writingSince} return { reset() { wroteText = false; }, get wroteText() { return wroteText; }, finish() { spinner.stop(); if (!atLineStart) { out("\n"); atLineStart = true; } }, + /** Title of the top-level tool call just printed (the permission prompt skips repeating it). */ + takeLastToolTitle() { const t = lastToolTitle; lastToolTitle = null; return t; }, event(e) { if (e.type === "waiting") { jobs.set(`${e.agent}@${e.depth}`, {}); @@ -256,6 +271,7 @@ function createRenderer({ out, log, spinner, quiet = false }) { if (e.type === "tool_start") { if (e.depth) line(` ${ash("⎿")} ${dim(`[${e.agent}]`)} ${dim(e.title)}`); else line(`${acid("●")} ${bone(e.title)}`); + lastToolTitle = e.depth ? null : e.title; return; } if (e.type === "tool_end") { @@ -440,9 +456,11 @@ async function repl({ cfg, opts, write }) { }; const promptPermission = async (req) => { spinner.stop(); - log(""); - log(`${amber("●")} ${bone(req.agent && req.agent !== "c0mpute" ? `[${req.agent}] ${req.title}` : req.title)}`); - for (const l of String(req.preview).split("\n").slice(0, 24)) { + const header = req.agent && req.agent !== "c0mpute" ? `[${req.agent}] ${req.title}` : req.title; + // tool_start already printed "● <title>" right above: saying it again + // (and the command again as its preview) showed every call 2-3 times. + if (permissionHeader(header, renderer.takeLastToolTitle())) { log(""); log(`${amber("●")} ${bone(header)}`); } + for (const l of previewLines(req.preview, req.title)) { log(` ${l.startsWith("+ ") ? acid(l) : l.startsWith("- ") ? danger(l) : dim(l)}`); } const a = (await question(` ${bone("Allow?")} ${ash("[y]es · [a]lways for this session · [n]o, or type what to do instead")} `)).trim(); diff --git a/test/c0agent-status.test.mjs b/test/c0agent-status.test.mjs index 65f09164..454fede6 100644 --- a/test/c0agent-status.test.mjs +++ b/test/c0agent-status.test.mjs @@ -56,3 +56,11 @@ test("statusLabel is honest about the one-piece c0mpute network path", () => { assert.match(statusLabel({ stage: "started" }, job, { promptTokens: 1000 }), /handed to another node/); assert.match(statusLabel({ stage: "started" }, { node: "provider@bonita", starts: 2 }, { promptTokens: 10 }), /^handed to bonita/); }); + +test("the permission prompt does not repeat the tool line it follows", async () => { + const { permissionHeader, previewLines } = await import("../src/c0agent-repl.mjs"); + assert.equal(permissionHeader("Bash(ping x)", "Bash(ping x)"), false); + assert.equal(permissionHeader("[explore] Bash(ls)", null), true); + assert.deepEqual(previewLines("ping compute-host", "Bash(ping compute-host)"), []); + assert.deepEqual(previewLines("+ added\n- removed", "Edit(a.js)"), ["+ added", "- removed"]); +});