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
10 changes: 7 additions & 3 deletions extensions/file-mutation-display/render.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ const fixtures: Array<{
patch: "@@ -1 +1,2 @@\n-old\n+new\n+second",
},
},
success: /Edited\s+README\.md\s+\+2\s+−1/,
success: /Edited\s+README\.md\s+\+2 -1/,
},
{
name: "grep",
Expand Down Expand Up @@ -236,7 +236,11 @@ test("all activity tools render pending and failure as one explicit row", () =>
const definition = withActivityRenderer(fixture.definition);
const pending = renderCollapsed(definition, fixture.args);
assert.equal(pending.length, 1, `${fixture.name} pending`);
assert.match(pending[0] ?? "", /^ {2}◌ /, `${fixture.name} pending`);
assert.match(
pending[0] ?? "",
/^ {2}[⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏] /,
`${fixture.name} pending`,
);
assert.ok(pending[0]?.endsWith(" "), `${fixture.name} pending`);

const failed = renderCollapsed(
Expand Down Expand Up @@ -274,7 +278,7 @@ test("long activity rows stay one line and fit narrow terminals", () => {
);
assert.equal(lines.length, 1);
assert.ok(visibleWidth(lines[0]!) <= 24);
assert.match(lines[0] ?? "", /^ {2} Running\s+bun/);
assert.match(lines[0] ?? "", /^ {2}[⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏] Running\s+bun/);
assert.ok(lines[0]?.endsWith(" "));
});

Expand Down
42 changes: 32 additions & 10 deletions extensions/file-mutation-display/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import type {
} from "@earendil-works/pi-coding-agent";
import { truncateToWidth, type Component } from "@earendil-works/pi-tui";
import type { TSchema } from "typebox";
import { spinnerFrame } from "../shared/spinner.ts";

type ActivityStatus = "pending" | "success" | "error";

Expand Down Expand Up @@ -91,13 +92,14 @@ function plural(count: number, singular: string) {

function editStats(details: unknown) {
const diff = string(record(details).diff);
if (!diff) return undefined;
let additions = 0;
let removals = 0;
for (const line of diff.split(/\r?\n/)) {
if (line.startsWith("+") && !line.startsWith("+++")) additions += 1;
if (line.startsWith("-") && !line.startsWith("---")) removals += 1;
}
return `+${additions} −${removals}`;
return { additions, removals };
}

function range(args: Record<string, unknown>) {
Expand Down Expand Up @@ -140,11 +142,7 @@ function activityRow(
return { verb: "Wrote", target: path, detail: plural(lines, "line") };
}
case "edit":
return {
verb: "Edited",
target: path,
detail: editStats(result?.details),
};
return { verb: "Edited", target: path };
case "grep":
return {
verb: "Searched",
Expand Down Expand Up @@ -242,17 +240,41 @@ function activityText(
) {
const row = activityRow(name, args, state.result, cwd);
const elapsed = duration(state);
const verbText = (
state.status === "pending"
? pendingVerb(name)
: state.status === "error"
? "Failed"
: row.verb
).padEnd(8);
const verb = theme.fg(
state.status === "error" ? "error" : "toolTitle",
verbText,
);
if (state.status === "pending") {
const detail = elapsed ? ` · ${elapsed}` : "";
return `${theme.fg("warning", "◌")} ${theme.fg("toolTitle", pendingVerb(name))} ${row.target}${theme.fg("dim", detail)}`;
return `${theme.fg("warning", spinnerFrame(Date.now()))} ${verb} ${row.target}${theme.fg("dim", detail)}`;
}
if (state.status === "error") {
const summary = errorSummary(state.result);
const detail = [elapsed, summary].filter(Boolean).join(" · ");
return `${theme.fg("error", "✕")} ${theme.fg("error", "Failed")} ${row.target}${detail ? theme.fg("dim", ` · ${detail}`) : ""}`;
return `${theme.fg("error", "✕")} ${verb} ${row.target}${detail ? theme.fg("dim", ` · ${detail}`) : ""}`;
}
const parts: string[] = [];
if (name === "edit") {
// Kimi-style diff stats: additions green, removals red.
const stats = editStats(state.result?.details);
if (stats) {
parts.push(
`${theme.fg("success", `+${stats.additions}`)} ${theme.fg("error", `-${stats.removals}`)}`,
);
}
} else if (row.detail) {
parts.push(theme.fg("dim", row.detail));
}
const detail = [row.detail, elapsed].filter(Boolean).join(" · ");
return `${theme.fg("dim", activityIcon(name))} ${theme.fg("toolTitle", row.verb.padEnd(8))} ${row.target}${detail ? theme.fg("dim", ` ${detail}`) : ""}`;
if (elapsed) parts.push(theme.fg("dim", elapsed));
const detail = parts.join(theme.fg("dim", " · "));
return `${theme.fg("dim", activityIcon(name))} ${verb} ${row.target}${detail ? ` ${detail}` : ""}`;
}

function activityComponent(
Expand Down
Loading