Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
24 changes: 21 additions & 3 deletions src/c0agent-repl.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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 "● <title>" 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 = ["✻", "✳", "✢", "·", "✢", "✳"];
Expand Down Expand Up @@ -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}`, {});
Expand Down Expand Up @@ -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") {
Expand Down Expand Up @@ -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();
Expand Down
8 changes: 8 additions & 0 deletions test/c0agent-status.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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"]);
});
Loading