xonecas.io
64875
Mc

mini-coder / commit a551559

tools: tolerate trailing pipe in anchors

Sean2026-03-01 a5515594aabf3f1f4bb34286916d5cf0357db46f parent de20b0f

4 files changed

src/tools/insert.test.ts+12−0
@@ -175,4 +175,16 @@ describe("insertTool", () => {
175175 }),
176176 ).rejects.toThrow("Invalid anchor");
177177 });
178+ test("accepts anchor with trailing pipe separator", async () => {
179+ const name = await write("f.txt", "a\nb\nc\n");
180+ await insertTool.execute({
181+ path: name,
182+ cwd: dir,
183+ anchor: `${anchor(2, "b")}|`,
184+ position: "after",
185+ content: "X",
186+ });
187+
188+ expect(await read(name)).toBe("a\nb\nX\nc\n");
189+ });
178190 });
src/tools/insert.ts+4−1
@@ -79,7 +79,10 @@ interface ParsedAnchor {
7979 }
8080
8181 function parseAnchor(value: string): ParsedAnchor {
82- const match = /^\s*(\d+):([0-9a-fA-F]{2})\s*$/.exec(value);
82+ const normalized = value.trim().endsWith("|")
83+ ? value.trim().slice(0, -1)
84+ : value;
85+ const match = /^\s*(\d+):([0-9a-fA-F]{2})\s*$/.exec(normalized);
8386 if (!match) {
8487 throw new Error(
8588 `Invalid anchor. Expected format: "line:hh" (e.g. "11:a3").`,
src/tools/replace.test.ts+11−0
@@ -169,4 +169,15 @@ describe("replaceTool", () => {
169169 }),
170170 ).rejects.toThrow("Invalid startAnchor");
171171 });
172+ test("accepts anchors with trailing pipe separator", async () => {
173+ const name = await write("f.txt", "a\nb\nc\n");
174+ await replaceTool.execute({
175+ path: name,
176+ cwd: dir,
177+ startAnchor: `${anchor(2, "b")}|`,
178+ newContent: "B",
179+ });
180+
181+ expect(await read(name)).toBe("a\nB\nc\n");
182+ });
172183 });
src/tools/replace.ts+4−1
@@ -110,7 +110,10 @@ interface ParsedAnchor {
110110 }
111111
112112 function parseAnchor(value: string, name: string): ParsedAnchor {
113- const match = /^\s*(\d+):([0-9a-fA-F]{2})\s*$/.exec(value);
113+ const normalized = value.trim().endsWith("|")
114+ ? value.trim().slice(0, -1)
115+ : value;
116+ const match = /^\s*(\d+):([0-9a-fA-F]{2})\s*$/.exec(normalized);
114117 if (!match) {
115118 throw new Error(
116119 `Invalid ${name}. Expected format: "line:hh" (e.g. "11:a3").`,