xonecas.io
64875
Mc

mini-coder / commit 133dcd0

refactor: clean up stale hashline edit leftovers

xonecas2026-03-15 133dcd0b7dba7b9c2df827a8ec7ca2663d6a5351 parent 405219c

4 files changed

src/llm-api/turn-stream-events.test.ts+4−4
@@ -101,14 +101,14 @@ describe("mapStreamChunkToTurnEvent", () => {
101101 mapStreamChunkToTurnEvent({
102102 type: "tool-error",
103103 toolCallId: "id-3",
104- toolName: "replace",
105- error: "bad anchor",
104+ toolName: "shell",
105+ error: "command failed",
106106 }),
107107 ).toEqual({
108108 type: "tool-result",
109109 toolCallId: "id-3",
110- toolName: "replace",
111- result: "bad anchor",
110+ toolName: "shell",
111+ result: "command failed",
112112 isError: true,
113113 });
114114 });
src/llm-api/turn.test.ts+6−6
@@ -209,7 +209,7 @@ describe("sanitizeGeminiToolMessages", () => {
209209 {
210210 type: "tool-call",
211211 toolCallId,
212- toolName: "replace",
212+ toolName: "shell",
213213 input: {},
214214 },
215215 ],
@@ -220,7 +220,7 @@ describe("sanitizeGeminiToolMessages", () => {
220220 {
221221 type: "tool-result",
222222 toolCallId,
223- toolName: "replace",
223+ toolName: "shell",
224224 output: { type: "json", value: { ok: false } },
225225 },
226226 ],
@@ -265,7 +265,7 @@ describe("sanitizeGeminiToolMessages", () => {
265265 {
266266 type: "tool-call",
267267 toolCallId: "unsigned-followup",
268- toolName: "replace",
268+ toolName: "shell",
269269 input: {},
270270 },
271271 ],
@@ -366,7 +366,7 @@ describe("sanitizeGeminiToolMessages", () => {
366366 {
367367 type: "tool-call",
368368 toolCallId: "turn2-broken",
369- toolName: "replace",
369+ toolName: "shell",
370370 input: {},
371371 },
372372 ],
@@ -434,7 +434,7 @@ describe("sanitizeGeminiToolMessages", () => {
434434 {
435435 type: "tool-call",
436436 toolCallId: "older-broken",
437- toolName: "replace",
437+ toolName: "shell",
438438 input: {},
439439 },
440440 ],
@@ -445,7 +445,7 @@ describe("sanitizeGeminiToolMessages", () => {
445445 {
446446 type: "tool-result",
447447 toolCallId: "older-broken",
448- toolName: "replace",
448+ toolName: "shell",
449449 output: { type: "json", value: { stale: true } },
450450 },
451451 ],
src/tools/hashline.test.ts+6−38
@@ -1,45 +1,13 @@
11 import { describe, expect, test } from "bun:test";
2-import { findLineByHash, formatHashLine, hashLine } from "./hashline.ts";
3-
4-describe("hashLine", () => {
5- test("returns a stable two-character lowercase hex digest", () => {
6- const hash = hashLine("hello");
7- expect(hash).toHaveLength(2);
8- expect(hash).toMatch(/^[0-9a-f]{2}$/);
9- expect(hashLine("hello")).toBe(hash);
10- });
11-});
2+import { formatHashLine } from "./hashline.ts";
123
134 describe("formatHashLine", () => {
14- test("formats the line number, hash, and content", () => {
15- expect(formatHashLine(12, "alpha")).toBe(`12:${hashLine("alpha")}| alpha`);
16- });
17-});
18-
19-describe("findLineByHash", () => {
20- test("returns the hinted line when it matches exactly", () => {
21- const lines = ["alpha", "beta", "gamma", "beta"];
22- expect(findLineByHash(lines, hashLine("beta"), 2)).toBe(2);
23- });
24-
25- test("finds a unique nearby match within the scan range", () => {
26- const lines = ["alpha", "beta", "gamma", "delta"];
27- expect(findLineByHash(lines, hashLine("gamma"), 2)).toBe(3);
28- });
29-
30- test("treats anchor hashes case-insensitively", () => {
31- const lines = ["alpha", "beta"];
32- expect(findLineByHash(lines, hashLine("beta").toUpperCase(), 1)).toBe(2);
33- });
34-
35- test("returns null when nearby matches are ambiguous", () => {
36- const lines = ["alpha", "beta", "gamma", "beta"];
37- expect(findLineByHash(lines, hashLine("beta"), 3)).toBeNull();
5+ test("formats the line number, short hash, and content", () => {
6+ const formatted = formatHashLine(12, "alpha");
7+ expect(formatted).toMatch(/^12:[0-9a-f]{2}\| alpha$/);
388 });
399
40- test("returns null when the only match is outside the scan range", () => {
41- const lines = Array.from({ length: 25 }, (_, i) => `line ${i + 1}`);
42- lines[22] = "needle";
43- expect(findLineByHash(lines, hashLine("needle"), 1)).toBeNull();
10+ test("keeps the same hash for the same content", () => {
11+ expect(formatHashLine(1, "hello")).toBe(formatHashLine(1, "hello"));
4412 });
4513 });
src/tools/hashline.ts+2−37
@@ -1,50 +1,15 @@
11 const FNV_OFFSET_BASIS = 0x811c9dc5;
22 const FNV_PRIME = 0x01000193;
3-const HASH_SCAN_RANGE = 10;
43
5-export function hashLine(content: string): string {
4+function hashLine(content: string): string {
65 let hash = FNV_OFFSET_BASIS;
76 for (let i = 0; i < content.length; i++) {
87 hash ^= content.charCodeAt(i);
98 hash = (hash * FNV_PRIME) >>> 0;
109 }
11- const twoHex = (hash & 0xff).toString(16).padStart(2, "0");
12- return twoHex;
10+ return (hash & 0xff).toString(16).padStart(2, "0");
1311 }
1412
1513 export function formatHashLine(lineNum: number, content: string): string {
1614 return `${lineNum}:${hashLine(content)}| ${content}`;
1715 }
18-
19-export function findLineByHash(
20- lines: string[],
21- hash: string,
22- hintLine: number,
23-): number | null {
24- const normalized = hash.toLowerCase();
25- const hintIdx = hintLine - 1;
26- const foundMatches: number[] = [];
27-
28- const matches = (idx: number): boolean => {
29- const line = lines[idx] ?? "";
30- return hashLine(line) === normalized;
31- };
32-
33- if (hintIdx >= 0 && hintIdx < lines.length) {
34- if (matches(hintIdx)) return hintIdx + 1;
35- }
36-
37- for (let offset = 1; offset <= HASH_SCAN_RANGE; offset++) {
38- const lower = hintIdx - offset;
39- if (lower >= 0 && lower < lines.length && matches(lower)) {
40- foundMatches.push(lower + 1);
41- }
42- const higher = hintIdx + offset;
43- if (higher >= 0 && higher < lines.length && matches(higher)) {
44- foundMatches.push(higher + 1);
45- }
46- }
47-
48- if (foundMatches.length === 1) return foundMatches[0] ?? null;
49- return null;
50-}