xonecas.io
64875
Mc

mini-coder / commit b3b36b7

fix(output): update tool rendering for create/replace/insert and hashline

- toolGlyph: replace 'edit' with create/replace/insert → G.write
- toolCallLine: dedicated branches for create (path), replace (verb +
  anchor range, 'delete' when no newContent), insert (position + anchor)
- renderToolResult: replace stale 'edit' branch with create (created/
  overwritten), replace (replaced/deleted via ReplaceOutput.deleted),
  insert (inserted)
- grep display: strip linenum:hash| prefix from match text before render
- add stripHashlinePrefix() helper
- ReplaceOutput: add deleted boolean propagated from execute

xonecas2026-02-20 b3b36b7befa2d37b58a19f861fa62c678f62aa7b parent 9caf27f

2 files changed

src/cli/output.ts+34−11
@@ -86,6 +86,11 @@ export function write(text: string): void {
8686 process.stdout.write(text);
8787 }
8888
89+/** Strip the `linenum:hash| ` prefix that hashline-formatted tool outputs include. */
90+function stripHashlinePrefix(text: string): string {
91+ return text.replace(/^\d+:[0-9a-f]{2}\| /, "");
92+}
93+
8994 // ─── Glyph vocabulary ─────────────────────────────────────────────────────────
9095 // All from the 16-color ANSI palette — inherits terminal theme.
9196
@@ -117,7 +122,8 @@ export const G = {
117122 function toolGlyph(name: string): string {
118123 if (name === "glob" || name === "grep") return G.search;
119124 if (name === "read") return G.read;
120- if (name === "edit") return G.write;
125+ if (name === "create" || name === "replace" || name === "insert")
126+ return G.write;
121127 if (name === "shell") return G.run;
122128 if (name === "subagent") return G.agent;
123129 if (name.startsWith("mcp_")) return G.mcp;
@@ -151,13 +157,19 @@ function toolCallLine(name: string, args: unknown): string {
151157 line || count ? c.dim(`:${line ?? 1}${count ? `+${count}` : ""}`) : "";
152158 return `${G.read} ${c.dim("read")} ${String(a.path ?? "")}${range}`;
153159 }
154- if (name === "edit") {
155- const verb = !a.startAnchor
156- ? "create"
157- : a.insertPosition
158- ? "insert"
159- : "edit";
160- return `${G.write} ${c.dim(verb)} ${c.bold(String(a.path ?? ""))}`;
160+ if (name === "create") {
161+ return `${G.write} ${c.dim("create")} ${c.bold(String(a.path ?? ""))}`;
162+ }
163+ if (name === "replace") {
164+ const range = a.endAnchor
165+ ? c.dim(` ${a.startAnchor}–${a.endAnchor}`)
166+ : c.dim(` ${a.startAnchor}`);
167+ const verb =
168+ a.newContent === undefined || a.newContent === "" ? "delete" : "replace";
169+ return `${G.write} ${c.dim(verb)} ${c.bold(String(a.path ?? ""))}${range}`;
170+ }
171+ if (name === "insert") {
172+ return `${G.write} ${c.dim(`insert ${a.position ?? ""}`)} ${c.bold(String(a.path ?? ""))}${c.dim(` @ ${a.anchor}`)}`;
161173 }
162174 if (name === "shell") {
163175 const cmd = String(a.command ?? "");
@@ -250,7 +262,9 @@ export function renderToolResult(
250262 ? c.dim(" ".repeat(m.file.length + 1))
251263 : c.dim(`${m.file}:`);
252264 seen.add(key);
253- writeln(` ${fileLabel}${c.dim(String(m.line))} ${m.text.trim()}`);
265+ writeln(
266+ ` ${fileLabel}${c.dim(String(m.line))} ${stripHashlinePrefix(m.text).trim()}`,
267+ );
254268 shown++;
255269 }
256270 const rest = r.matches.length - shown;
@@ -279,14 +293,23 @@ export function renderToolResult(
279293 return;
280294 }
281295
282- if (toolName === "edit") {
296+ if (toolName === "create") {
283297 const r = result as { path: string; diff: string; created: boolean };
284- const verb = r.created ? c.green("created") : c.dim("edited");
298+ const verb = r.created ? c.green("created") : c.dim("overwritten");
285299 writeln(` ${G.ok} ${verb} ${r.path}`);
286300 renderDiff(r.diff);
287301 return;
288302 }
289303
304+ if (toolName === "replace" || toolName === "insert") {
305+ const r = result as { path: string; diff: string; deleted?: boolean };
306+ const verb =
307+ toolName === "insert" ? "inserted" : r.deleted ? "deleted" : "replaced";
308+ writeln(` ${G.ok} ${c.dim(verb)} ${r.path}`);
309+ renderDiff(r.diff);
310+ return;
311+ }
312+
290313 if (toolName === "shell") {
291314 const r = result as {
292315 stdout: string;
src/tools/replace.ts+2−1
@@ -28,6 +28,7 @@ type ReplaceInput = z.infer<typeof ReplaceSchema> & { cwd?: string };
2828 export interface ReplaceOutput {
2929 path: string;
3030 diff: string;
31+ deleted: boolean;
3132 }
3233
3334 const HASH_NOT_FOUND_ERROR =
@@ -99,7 +100,7 @@ export const replaceTool: ToolDef<ReplaceInput, ReplaceOutput> = {
99100 await Bun.write(filePath, updated);
100101
101102 const diff = generateDiff(relPath, original, updated);
102- return { path: relPath, diff };
103+ return { path: relPath, diff, deleted: replacement.length === 0 };
103104 },
104105 };