@@ -1,15 +1,113 @@
11 import { homedir } from "node:os";
22 import * as c from "yoctocolors";
33 import { G, writeln } from "./output.ts";
4-import { buildToolCallLine } from "./tool-render-call.ts";
5-import { renderToolResult as renderResultImpl } from "./tool-render-result.ts";
4+import { renderToolResultByName } from "./tool-result-renderers.ts";
65
76 const HOME = homedir();
87
8+// ─── Tool call line rendering ─────────────────────────────────────────────────
9+
10+function toolGlyph(name: string): string {
11+ if (name === "read") return G.read;
12+ if (name === "create" || name === "replace" || name === "insert")
13+ return G.write;
14+ if (name === "shell") return G.run;
15+ if (name === "subagent") return G.agent;
16+ if (name.startsWith("mcp_")) return G.mcp;
17+ return G.info;
18+}
19+
20+export function buildToolCallLine(name: string, args: unknown): string {
21+ const a =
22+ args && typeof args === "object" ? (args as Record<string, unknown>) : {};
23+
24+ if (name === "subagent") {
25+ const prompt = typeof a.prompt === "string" ? a.prompt : "";
26+ const short = prompt.length > 60 ? `${prompt.slice(0, 57)}…` : prompt;
27+ const agentName =
28+ typeof a.agentName === "string" && a.agentName ? a.agentName : "";
29+ const label = agentName ? ` ${c.dim(c.cyan(`[@${agentName}]`))}` : "";
30+ return `${G.agent}${label} ${c.dim("—")} ${short}`;
31+ }
32+
33+ if (name === "read") {
34+ const line = Number.isFinite(a.line as number) ? Number(a.line) : null;
35+ const count = Number.isFinite(a.count as number) ? Number(a.count) : null;
36+ const range =
37+ line || count ? c.dim(`:${line ?? 1}${count ? `+${count}` : ""}`) : "";
38+ const path =
39+ typeof a.path === "string" && a.path.length > 0 ? a.path : null;
40+ return `${G.read} ${c.dim("read")}${path ? ` ${path}${range}` : ""}`;
41+ }
42+
43+ if (name === "create") {
44+ return `${G.write} ${c.dim("create")} ${c.bold(String(a.path ?? ""))}`;
45+ }
46+
47+ if (name === "replace") {
48+ const range = a.endAnchor
49+ ? c.dim(` ${a.startAnchor}–${a.endAnchor}`)
50+ : c.dim(` ${a.startAnchor}`);
51+ const verb =
52+ a.newContent === undefined || a.newContent === "" ? "delete" : "replace";
53+ return `${G.write} ${c.dim(verb)} ${c.bold(String(a.path ?? ""))}${range}`;
54+ }
55+
56+ if (name === "insert") {
57+ return `${G.write} ${c.dim(`insert ${a.position ?? ""}`)} ${c.bold(String(a.path ?? ""))}${c.dim(` @ ${a.anchor}`)}`;
58+ }
59+
60+ if (name === "shell") {
61+ const cmd = String(a.command ?? "").trim();
62+ if (!cmd) return `${G.run} ${c.dim("shell")}`;
63+ const shortCmd = cmd.length > 72 ? `${cmd.slice(0, 69)}…` : cmd;
64+ return `${G.run} ${shortCmd}`;
65+ }
66+
67+ if (name.startsWith("mcp_")) {
68+ return `${G.mcp} ${c.dim(name)}`;
69+ }
70+
71+ return `${toolGlyph(name)} ${c.dim(name)}`;
72+}
73+
974 export function renderToolCall(toolName: string, args: unknown): void {
1075 writeln(` ${buildToolCallLine(toolName, args)}`);
1176 }
1277
78+// ─── Tool result rendering ────────────────────────────────────────────────────
79+
80+function formatErrorBadge(result: unknown): string {
81+ const msg =
82+ typeof result === "string"
83+ ? result
84+ : result instanceof Error
85+ ? result.message
86+ : JSON.stringify(result);
87+ const oneLiner = msg.split("\n")[0] ?? msg;
88+ return `${G.err} ${c.red(oneLiner)}`;
89+}
90+
91+export function renderToolResult(
92+ toolName: string,
93+ result: unknown,
94+ isError: boolean,
95+): void {
96+ if (isError) {
97+ writeln(` ${formatErrorBadge(result)}`);
98+ return;
99+ }
100+
101+ if (renderToolResultByName(toolName, result)) {
102+ return;
103+ }
104+
105+ const text = JSON.stringify(result);
106+ writeln(` ${c.dim(text.length > 120 ? `${text.slice(0, 117)}…` : text)}`);
107+}
108+
109+// ─── Hook rendering ───────────────────────────────────────────────────────────
110+
13111 export function renderHook(
14112 toolName: string,
15113 scriptPath: string,
@@ -24,11 +122,3 @@ export function renderHook(
24122 ` ${G.err} ${c.red(`hook post-${toolName} failed`)} ${c.dim(short)}`,
25123 );
26124 }
27-
28-export function renderToolResult(
29- toolName: string,
30- result: unknown,
31- isError: boolean,
32-): void {
33- renderResultImpl(toolName, result, isError);
34-}