@@ -4,26 +4,7 @@ import { G, writeln } from "./output.ts";
44
55 const HOME = homedir();
66
7-/** Strip the `linenum:hash| ` prefix that hashline-formatted tool outputs include. */
8-function stripHashlinePrefix(text: string): string {
9- return text.replace(/^\d+:[0-9a-f]{2}\| /, "");
10-}
11-
12-function commonPrefix(paths: string[]): string {
13- const first = paths[0];
14- if (!first) return "";
15- const parts = first.split("/");
16- let prefix = "";
17- for (let i = 0; i < parts.length - 1; i++) {
18- const candidate = `${parts.slice(0, i + 1).join("/")}/`;
19- if (paths.every((p) => p.startsWith(candidate))) prefix = candidate;
20- else break;
21- }
22- return prefix;
23-}
24-
257 function toolGlyph(name: string): string {
26- if (name === "glob" || name === "grep") return G.search;
278 if (name === "read") return G.read;
289 if (name === "create" || name === "replace" || name === "insert")
2910 return G.write;
@@ -49,21 +30,6 @@ function toolCallLine(
4930 const label = agentName ? ` ${c.dim(c.cyan(`[@${agentName}]`))}` : "";
5031 return `${G.agent}${label} ${c.dim("—")} ${short}`;
5132 }
52- if (name === "glob") {
53- const pattern = String(a.pattern ?? "");
54- const cwd = a.cwd ? String(a.cwd) : "";
55- return `${G.search} ${c.dim("glob")} ${c.bold(pattern)}${cwd ? c.dim(` in ${cwd}`) : ""}`;
56- }
57- if (name === "grep") {
58- const flags = [
59- a.include ? String(a.include) : null,
60- a.caseSensitive === false ? "i" : null,
61- ]
62- .filter(Boolean)
63- .join(" ");
64- const pattern = String(a.pattern ?? "");
65- return `${G.search} ${c.dim("grep")} ${c.bold(pattern)}${flags ? c.dim(` ${flags}`) : ""}`;
66- }
6733 if (name === "read") {
6834 const line = Number.isFinite(a.line as number) ? Number(a.line) : null;
6935 const count = Number.isFinite(a.count as number) ? Number(a.count) : null;
@@ -170,72 +136,6 @@ export function renderToolResult(
170136 return;
171137 }
172138
173- if (toolName === "glob") {
174- const r = result as { files?: string[]; truncated?: boolean };
175- if (Array.isArray(r?.files)) {
176- const files = r.files;
177- if (files.length === 0) {
178- writeln(` ${G.info} ${c.dim("no matches")}`);
179- return;
180- }
181-
182- // Show up to 12 files, grouped by top-level directory for readability
183- const show = files.slice(0, 12);
184- const rest = files.length - show.length;
185-
186- // Find common prefix to strip for cleaner display
187- const prefix = commonPrefix(show);
188- for (const f of show) {
189- const rel =
190- prefix && f.startsWith(prefix)
191- ? c.dim(prefix) + f.slice(prefix.length)
192- : f;
193- writeln(` ${c.dim("·")} ${rel}`);
194- }
195- if (rest > 0) writeln(` ${c.dim(` +${rest} more`)}`);
196- if (r.truncated) writeln(` ${c.dim(" (results capped)")}`);
197- return;
198- }
199- }
200-
201- if (toolName === "grep") {
202- const r = result as {
203- matches?: Array<{
204- file: string;
205- line: number;
206- text: string;
207- context?: Array<{ line: number; text: string; isMatch: boolean }>;
208- }>;
209- truncated?: boolean;
210- };
211- if (Array.isArray(r?.matches)) {
212- if (r.matches.length === 0) {
213- writeln(` ${G.info} ${c.dim("no matches")}`);
214- return;
215- }
216-
217- // Deduplicate by file, show file:line and match text
218- const seen = new Set<string>();
219- let shown = 0;
220- for (const m of r.matches) {
221- if (shown >= 10) break;
222- const key = m.file;
223- const fileLabel = seen.has(key)
224- ? c.dim(" ".repeat(m.file.length + 1))
225- : c.dim(`${m.file}:`);
226- seen.add(key);
227- writeln(
228- ` ${fileLabel}${c.dim(String(m.line))} ${stripHashlinePrefix(m.text).trim()}`,
229- );
230- shown++;
231- }
232- const rest = r.matches.length - shown;
233- if (rest > 0) writeln(` ${c.dim(` +${rest} more`)}`);
234- if (r.truncated) writeln(` ${c.dim(" (results capped)")}`);
235- return;
236- }
237- }
238-
239139 if (toolName === "read") {
240140 const r = result as {
241141 path: string;