@criogaid/pi-hashline-edit 0.4.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. package/README.md +116 -20
  2. package/package.json +3 -3
  3. package/src/core/apply.test.ts +194 -104
  4. package/src/core/apply.ts +6 -37
  5. package/src/core/errors.ts +9 -0
  6. package/src/core/hash.test.ts +8 -8
  7. package/src/core/hash.ts +5 -5
  8. package/src/{pi/replace-apply.ts → core/replace.ts} +4 -4
  9. package/src/core/text.ts +1 -3
  10. package/src/core/types.ts +4 -7
  11. package/src/index.ts +9 -11
  12. package/src/integration/config-registration.test.ts +206 -0
  13. package/src/integration/grep-rg.test.ts +73 -60
  14. package/src/integration/large-text.test.ts +9 -8
  15. package/src/integration/replace-package.test.ts +11 -7
  16. package/src/pi/action-fusion.test.ts +110 -34
  17. package/src/pi/action-fusion.ts +77 -114
  18. package/src/pi/anchor-format.test.ts +43 -22
  19. package/src/pi/anchor-format.ts +23 -8
  20. package/src/pi/budgets.ts +7 -2
  21. package/src/pi/config.test.ts +153 -40
  22. package/src/pi/config.ts +87 -41
  23. package/src/pi/e2e-scenarios.test.ts +12 -11
  24. package/src/pi/edit-tool.ts +20 -156
  25. package/src/pi/error-text.ts +10 -5
  26. package/src/pi/execute.test.ts +299 -175
  27. package/src/pi/failure-context.test.ts +7 -2
  28. package/src/pi/failure-context.ts +155 -8
  29. package/src/pi/failure-path.test.ts +33 -26
  30. package/src/pi/file-commit.ts +2 -1
  31. package/src/pi/fusion-card.ts +83 -2
  32. package/src/pi/grep-output.ts +26 -9
  33. package/src/pi/grep-render.ts +6 -5
  34. package/src/pi/grep-scope.ts +2 -15
  35. package/src/pi/grep-search.ts +29 -15
  36. package/src/pi/grep-tool.ts +94 -78
  37. package/src/pi/grep.test.ts +357 -320
  38. package/src/pi/mutation-outcome.testing.ts +22 -0
  39. package/src/pi/mutation-result.test.ts +51 -2
  40. package/src/pi/mutation-result.ts +62 -55
  41. package/src/pi/mutation-runner.ts +16 -33
  42. package/src/pi/pi.test.ts +10 -5
  43. package/src/pi/read-tool.ts +61 -33
  44. package/src/pi/registration.test.ts +1 -5
  45. package/src/pi/render.test.ts +16 -8
  46. package/src/pi/render.ts +4 -91
  47. package/src/pi/replace-regex.ts +54 -0
  48. package/src/pi/replace-tool.ts +24 -58
  49. package/src/pi/replace-worker.ts +2 -2
  50. package/src/pi/replace.test.ts +62 -58
  51. package/src/pi/result-safety.test.ts +124 -84
  52. package/src/pi/rg-line-ranges.ts +3 -2
  53. package/src/pi/{rg-line-filter.test.ts → rg-process.test.ts} +1 -1
  54. package/src/pi/{rg-line-filter.ts → rg-process.ts} +35 -4
  55. package/src/pi/rg-text-view.ts +17 -33
  56. package/src/pi/schema.ts +2 -10
  57. package/src/pi/write-tool.ts +1 -2
  58. package/src/pi/write.test.ts +10 -9
  59. package/src/core/index.ts +0 -14
  60. package/src/pi/state.ts +0 -26
@@ -18,6 +18,7 @@ import { validateToolArguments } from "@earendil-works/pi-ai";
18
18
  import { callTool } from "./tool-call.testing.ts";
19
19
  import { createActionFusionExecutor } from "./action-fusion.ts";
20
20
  import { generateMutationDetails } from "./mutation-result.ts";
21
+ import { DEFAULT_CONFIG } from "./config.ts";
21
22
 
22
23
  async function withDir<T>(fn: (dir: string) => Promise<T>): Promise<T> {
23
24
  const dir = await mkdtemp(join(tmpdir(), "hl-replace-"));
@@ -28,7 +29,7 @@ async function withDir<T>(fn: (dir: string) => Promise<T>): Promise<T> {
28
29
  }
29
30
  }
30
31
 
31
- const call = (tool: any, params: any) => tool.execute("0", params, undefined, undefined);
32
+ const call = (tool: any, params: any) => callTool(tool, params, { toolCallId: "0" });
32
33
 
33
34
  /** Extract a `LINE#HASH` anchor for `line` from a result text block. */
34
35
  function anchorLine(block: string, line: number) {
@@ -44,7 +45,7 @@ const stubTheme = { fg: (_k: string, s: string) => s, bold: (s: string) => s } a
44
45
  initTheme();
45
46
 
46
47
  test("replace find guidance distinguishes literal escapes and regex line anchors", () => {
47
- const tool = makeReplaceTool(process.cwd());
48
+ const tool = makeReplaceTool(process.cwd(), DEFAULT_CONFIG);
48
49
  const description: unknown = Reflect.get(
49
50
  tool.parameters.properties.replacements.items.properties.find,
50
51
  "description",
@@ -57,9 +58,9 @@ test("replace find guidance distinguishes literal escapes and regex line anchors
57
58
  assert.match(description, /regex mode.*\^ and \$.*m flag.*per line/);
58
59
  });
59
60
 
60
- test("replace schema requires a non-empty replacements array", () => {
61
+ test("replace schema requires a non-empty replacements array", async () => {
61
62
  for (const fusion of [undefined, createActionFusionExecutor()]) {
62
- const tool = makeReplaceTool(process.cwd(), fusion);
63
+ const tool = makeReplaceTool(process.cwd(), DEFAULT_CONFIG, fusion);
63
64
  assert.equal(Object.hasOwn(tool.parameters.properties, "find"), false);
64
65
  const check = (args: Parameters<typeof validateToolArguments>[1]["arguments"]) =>
65
66
  validateToolArguments(tool, { type: "toolCall", id: "0", name: "replace", arguments: args });
@@ -77,27 +78,21 @@ test("replace schema requires a non-empty replacements array", () => {
77
78
  })),
78
79
  ];
79
80
  for (const args of invalidArgs) {
80
- assert.throws(() => check(args));
81
+ await assert.rejects(call(tool, args), /Validation failed for tool "replace"/);
81
82
  }
82
83
  }
83
84
  });
84
85
 
85
- test("replace schema rejects empty paths, empty find, and unsupported flags", () => {
86
- const tool = makeReplaceTool(process.cwd());
86
+ test("replace schema rejects empty paths, empty find, and unsupported flags", async () => {
87
+ const tool = makeReplaceTool(process.cwd(), DEFAULT_CONFIG);
87
88
  for (const args of [
88
89
  { path: "", replacements: [{ find: "old", replace: "new" }] },
89
90
  { path: "f.txt", replacements: [{ find: "", replace: "new" }] },
90
91
  { path: "f.txt", replacements: [{ find: "old", replace: "new", flags: "x" }] },
91
92
  ]) {
92
- assert.throws(
93
- () =>
94
- validateToolArguments(tool, {
95
- type: "toolCall",
96
- id: "invalid",
97
- name: "replace",
98
- arguments: args,
99
- }),
100
- /Validation failed/,
93
+ await assert.rejects(
94
+ call(tool, args),
95
+ /Validation failed for tool "replace"/,
101
96
  JSON.stringify(args),
102
97
  );
103
98
  }
@@ -108,7 +103,7 @@ test("replace rejects top-level rules without publishing", async () =>
108
103
  const file = join(dir, "f.txt");
109
104
  await writeFile(file, "old\n");
110
105
  await assert.rejects(
111
- callTool(makeReplaceTool(dir), {
106
+ callTool(makeReplaceTool(dir, DEFAULT_CONFIG), {
112
107
  path: file,
113
108
  find: "old",
114
109
  replace: "new",
@@ -123,7 +118,7 @@ test("replace rejects unsupported per-rule fields before publishing", async () =
123
118
  const file = join(dir, "f.txt");
124
119
  const before = "foo foo foo\n";
125
120
  await writeFile(file, before);
126
- const tool = makeReplaceTool(dir);
121
+ const tool = makeReplaceTool(dir, DEFAULT_CONFIG);
127
122
  for (const maxMatches of [1, null, false]) {
128
123
  await assert.rejects(
129
124
  callTool(tool, { path: file, replacements: [{ find: "foo", replace: "bar", maxMatches }] }),
@@ -136,7 +131,7 @@ test("replace rejects unsupported per-rule fields before publishing", async () =
136
131
  test("replace rejects unwritable text and invalid regex before reading a missing target", async () =>
137
132
  withDir(async (dir) => {
138
133
  const file = join(dir, "missing.txt");
139
- const tool = makeReplaceTool(dir);
134
+ const tool = makeReplaceTool(dir, DEFAULT_CONFIG);
140
135
  const valid = { path: file, replacements: [{ find: "x", replace: "y", regex: true }] };
141
136
  assert.equal(tool.prepareArguments(valid), valid);
142
137
  for (const [rule, expected] of [
@@ -170,7 +165,7 @@ test("replace literal: replaces all occurrences", async () => {
170
165
  await withDir(async (dir) => {
171
166
  const f = join(dir, "f.txt");
172
167
  await writeFile(f, "foo bar foo baz foo\n");
173
- const r: any = await call(makeReplaceTool(dir), {
168
+ const r: any = await call(makeReplaceTool(dir, DEFAULT_CONFIG), {
174
169
  path: "f.txt",
175
170
  replacements: [{ find: "foo", replace: "qux" }],
176
171
  });
@@ -184,13 +179,13 @@ test("literal multiline replace matches LF and CRLF while retaining local separa
184
179
  withDir(async (dir) => {
185
180
  const file = join(dir, "mixed.txt");
186
181
  await writeFile(file, "\uFEFFhead\r\nold\r\none\r\nmid\nold\none\nend\r\n");
187
- const result: any = await call(makeReplaceTool(dir), {
182
+ const result: any = await call(makeReplaceTool(dir, DEFAULT_CONFIG), {
188
183
  path: "mixed.txt",
189
184
  replacements: [{ find: "old\none", replace: "NEW\nX" }],
190
185
  });
191
186
  assert.match(result.content[0].text, /2 matches/);
192
187
  assert.equal(await readFile(file, "utf8"), "\uFEFFhead\r\nNEW\r\nX\r\nmid\nNEW\nX\nend\r\n");
193
- await call(makeReplaceTool(dir), {
188
+ await call(makeReplaceTool(dir, DEFAULT_CONFIG), {
194
189
  path: "mixed.txt",
195
190
  replacements: [{ find: "NEW\r\nX", replace: "done" }],
196
191
  });
@@ -202,7 +197,7 @@ test("both replacement modes preserve each matched separator", async () =>
202
197
  const file = join(dir, "mixed.txt");
203
198
  for (const regex of [false, true]) {
204
199
  await writeFile(file, "a\r\nb\nc\r\ntail\n");
205
- await call(makeReplaceTool(dir), {
200
+ await call(makeReplaceTool(dir, DEFAULT_CONFIG), {
206
201
  path: "mixed.txt",
207
202
  replacements: [{ find: "a\nb\nc", replace: "x\ny\nz\nextra", regex }],
208
203
  });
@@ -216,7 +211,7 @@ test("literal replacement uses one LF view and preserves raw bytes across query
216
211
  for (const find of ["a\nb\nc", "a\r\nb\r\nc", "a\r\nb\nc"]) {
217
212
  const before = "\uFEFFhead\r\na\r\nb\nc\rtail";
218
213
  await writeFile(file, before);
219
- const result = await call(makeReplaceTool(dir), {
214
+ const result = await call(makeReplaceTool(dir, DEFAULT_CONFIG), {
220
215
  path: file,
221
216
  replacements: [{ find, replace: find }],
222
217
  });
@@ -231,7 +226,7 @@ test("literal replacement uses one LF view and preserves raw bytes across query
231
226
  ["a\rb\r\r\nc", "a\rb\r\r\nc", "x\ry\r\r\nz", "x\ry\r\r\nz"],
232
227
  ]) {
233
228
  await writeFile(file, before);
234
- await call(makeReplaceTool(dir), {
229
+ await call(makeReplaceTool(dir, DEFAULT_CONFIG), {
235
230
  path: file,
236
231
  replacements: [{ find, replace: replacement }],
237
232
  });
@@ -243,7 +238,7 @@ test("mixed literal and regex batches share raw offsets after CRLF normalization
243
238
  withDir(async (dir) => {
244
239
  const file = join(dir, "f.txt");
245
240
  await writeFile(file, "😀\r\na\r\nb\r\nc");
246
- await call(makeReplaceTool(dir), {
241
+ await call(makeReplaceTool(dir, DEFAULT_CONFIG), {
247
242
  path: file,
248
243
  replacements: [
249
244
  { find: "a\nb", replace: "A\nB" },
@@ -253,7 +248,7 @@ test("mixed literal and regex batches share raw offsets after CRLF normalization
253
248
  assert.equal(await readFile(file, "utf8"), "😀\r\nA\r\nB\r\nc!");
254
249
  const before = await readFile(file, "utf8");
255
250
  await assert.rejects(
256
- call(makeReplaceTool(dir), {
251
+ call(makeReplaceTool(dir, DEFAULT_CONFIG), {
257
252
  path: file,
258
253
  replacements: [
259
254
  { find: "A\nB", replace: "x" },
@@ -269,7 +264,7 @@ test("replace literal: $ in replacement stays literal (no expansion)", async ()
269
264
  await withDir(async (dir) => {
270
265
  const f = join(dir, "f.txt");
271
266
  await writeFile(f, "cost: $5 here\n");
272
- const r: any = await call(makeReplaceTool(dir), {
267
+ const r: any = await call(makeReplaceTool(dir, DEFAULT_CONFIG), {
273
268
  path: "f.txt",
274
269
  replacements: [{ find: "$5", replace: "$10" }],
275
270
  });
@@ -283,7 +278,7 @@ test("replace literal: case-insensitive via flags", async () => {
283
278
  await withDir(async (dir) => {
284
279
  const f = join(dir, "f.txt");
285
280
  await writeFile(f, "Foo fOo FOO\n");
286
- await call(makeReplaceTool(dir), {
281
+ await call(makeReplaceTool(dir, DEFAULT_CONFIG), {
287
282
  path: "f.txt",
288
283
  replacements: [{ find: "foo", replace: "x", flags: "i" }],
289
284
  });
@@ -301,7 +296,7 @@ test("replace aborts catastrophic regex without blocking the event loop or publi
301
296
  const start = performance.now();
302
297
  try {
303
298
  await assert.rejects(
304
- makeReplaceTool(dir).execute(
299
+ makeReplaceTool(dir, DEFAULT_CONFIG).execute(
305
300
  "abort",
306
301
  { path: file, replacements: [{ find: "^(a+)+$", replace: "x", regex: true }] },
307
302
  controller.signal,
@@ -319,19 +314,20 @@ test("replace aborts catastrophic regex without blocking the event loop or publi
319
314
  }
320
315
  });
321
316
  });
322
- test("replace times out catastrophic regex without publishing", async () => {
317
+ test("replace times out catastrophic regex at the configured limit without publishing", async () => {
323
318
  await withDir(async (dir) => {
324
319
  const file = join(dir, "f.txt");
325
320
  const before = `${"a".repeat(35)}!`;
326
321
  await writeFile(file, before);
322
+ const config = { ...DEFAULT_CONFIG, replace: { regexTimeoutMs: 1_000 } };
327
323
  await assert.rejects(
328
- call(makeReplaceTool(dir), {
324
+ call(makeReplaceTool(dir, config), {
329
325
  path: file,
330
326
  replacements: [{ find: "^(a+)+$", replace: "x", regex: true }],
331
327
  }),
332
328
  (error: unknown) =>
333
329
  error instanceof Error &&
334
- error.message === `Replace ${file}: regex evaluation timed out after 5000ms`,
330
+ error.message === `Replace ${file}: regex evaluation timed out after 1000ms`,
335
331
  );
336
332
  assert.equal(await readFile(file, "utf8"), before);
337
333
  });
@@ -341,7 +337,7 @@ test("replace regex: capture groups in replacement", async () => {
341
337
  await withDir(async (dir) => {
342
338
  const f = join(dir, "f.txt");
343
339
  await writeFile(f, "name: alice\nname: bob\n");
344
- await call(makeReplaceTool(dir), {
340
+ await call(makeReplaceTool(dir, DEFAULT_CONFIG), {
345
341
  path: "f.txt",
346
342
  replacements: [{ find: "name: (\\w+)", replace: "user: $1", regex: true }],
347
343
  });
@@ -354,7 +350,7 @@ test("replace regex: multiline flag matches line-anchored pattern", async () =>
354
350
  const f = join(dir, "f.txt");
355
351
  await writeFile(f, "a\nb\nc\n");
356
352
  // without `m`, ^a$ wouldn't match (a isn't at end of string); with `m` it does
357
- await call(makeReplaceTool(dir), {
353
+ await call(makeReplaceTool(dir, DEFAULT_CONFIG), {
358
354
  path: "f.txt",
359
355
  replacements: [{ find: "^a$", replace: "A", regex: true, flags: "m" }],
360
356
  });
@@ -367,7 +363,7 @@ test("replace regex: dotall flag makes . match newlines", async () => {
367
363
  const f = join(dir, "f.txt");
368
364
  await writeFile(f, "a\nb\n");
369
365
  // a.b only matches across the newline with the `s` (dotall) flag
370
- await call(makeReplaceTool(dir), {
366
+ await call(makeReplaceTool(dir, DEFAULT_CONFIG), {
371
367
  path: "f.txt",
372
368
  replacements: [{ find: "a.b", replace: "X", regex: true, flags: "s" }],
373
369
  });
@@ -380,7 +376,10 @@ test("replace: 0 matches throws", async () => {
380
376
  const f = join(dir, "f.txt");
381
377
  await writeFile(f, "a\nb\n");
382
378
  await assert.rejects(
383
- call(makeReplaceTool(dir), { path: "f.txt", replacements: [{ find: "zzz", replace: "y" }] }),
379
+ call(makeReplaceTool(dir, DEFAULT_CONFIG), {
380
+ path: "f.txt",
381
+ replacements: [{ find: "zzz", replace: "y" }],
382
+ }),
384
383
  /no matches/,
385
384
  );
386
385
  assert.equal(await readFile(f, "utf-8"), "a\nb\n", "file untouched on 0-match failure");
@@ -391,7 +390,10 @@ test("replace: empty find throws", async () => {
391
390
  await withDir(async (dir) => {
392
391
  await writeFile(join(dir, "f.txt"), "a\n");
393
392
  await assert.rejects(
394
- callTool(makeReplaceTool(dir), { path: "f.txt", replacements: [{ find: "", replace: "x" }] }),
393
+ callTool(makeReplaceTool(dir, DEFAULT_CONFIG), {
394
+ path: "f.txt",
395
+ replacements: [{ find: "", replace: "x" }],
396
+ }),
395
397
  /Validation failed for tool "replace"[\s\S]*find/,
396
398
  );
397
399
  });
@@ -401,7 +403,7 @@ test("replace: handles large match counts without an arbitrary cap", async () =>
401
403
  await withDir(async (dir) => {
402
404
  const f = join(dir, "f.txt");
403
405
  await writeFile(f, "a\n".repeat(2500));
404
- const result: any = await call(makeReplaceTool(dir), {
406
+ const result: any = await call(makeReplaceTool(dir, DEFAULT_CONFIG), {
405
407
  path: "f.txt",
406
408
  replacements: [{ find: "a", replace: "b" }],
407
409
  });
@@ -414,7 +416,7 @@ test("replace: invalid regex throws a friendly message", async () => {
414
416
  await withDir(async (dir) => {
415
417
  await writeFile(join(dir, "f.txt"), "a\n");
416
418
  await assert.rejects(
417
- call(makeReplaceTool(dir), {
419
+ call(makeReplaceTool(dir, DEFAULT_CONFIG), {
418
420
  path: "f.txt",
419
421
  replacements: [{ find: "(unclosed", replace: "x", regex: true }],
420
422
  }),
@@ -427,7 +429,7 @@ test("replace: invalid flag char throws", async () => {
427
429
  await withDir(async (dir) => {
428
430
  await writeFile(join(dir, "f.txt"), "a\n");
429
431
  await assert.rejects(
430
- callTool(makeReplaceTool(dir), {
432
+ callTool(makeReplaceTool(dir, DEFAULT_CONFIG), {
431
433
  path: "f.txt",
432
434
  replacements: [{ find: "a", replace: "x", flags: "z" }],
433
435
  }),
@@ -441,7 +443,7 @@ test("replace: count-but-no-net-change does not rewrite and reports it", async (
441
443
  const f = join(dir, "f.txt");
442
444
  await writeFile(f, "xx\n");
443
445
  // $& = whole match = "x", so the text is unchanged despite 2 matches
444
- const r: any = await call(makeReplaceTool(dir), {
446
+ const r: any = await call(makeReplaceTool(dir, DEFAULT_CONFIG), {
445
447
  path: "f.txt",
446
448
  replacements: [{ find: "x", replace: "$&", regex: true }],
447
449
  });
@@ -455,7 +457,7 @@ test("replace: returns details.diff (string) + patch + firstChangedLine", async
455
457
  await withDir(async (dir) => {
456
458
  const f = join(dir, "f.txt");
457
459
  await writeFile(f, "a\nb\nc\n");
458
- const r: any = await call(makeReplaceTool(dir), {
460
+ const r: any = await call(makeReplaceTool(dir, DEFAULT_CONFIG), {
459
461
  path: "f.txt",
460
462
  replacements: [{ find: "b", replace: "B" }],
461
463
  });
@@ -469,7 +471,7 @@ test("replace: returns fresh anchors for the changed region", async () => {
469
471
  await withDir(async (dir) => {
470
472
  const f = join(dir, "f.txt");
471
473
  await writeFile(f, "a\nb\nc\n");
472
- const r: any = await call(makeReplaceTool(dir), {
474
+ const r: any = await call(makeReplaceTool(dir, DEFAULT_CONFIG), {
473
475
  path: "f.txt",
474
476
  replacements: [{ find: "b", replace: "B" }],
475
477
  });
@@ -487,7 +489,7 @@ test("replace: changed-region anchor chains a subsequent hashline edit without a
487
489
  await withDir(async (dir) => {
488
490
  const f = join(dir, "f.txt");
489
491
  await writeFile(f, "old old old\n");
490
- const replace = makeReplaceTool(dir);
492
+ const replace = makeReplaceTool(dir, DEFAULT_CONFIG);
491
493
  const r1: any = await call(replace, {
492
494
  path: "f.txt",
493
495
  replacements: [{ find: "old", replace: "new" }],
@@ -495,7 +497,7 @@ test("replace: changed-region anchor chains a subsequent hashline edit without a
495
497
  const out: string = r1.content[0].text;
496
498
  // line 1 is the changed line; chain an edit on its returned anchor
497
499
  const a1 = anchorLine(out, 1);
498
- const edit = makeEditOverride(dir);
500
+ const edit = makeEditOverride(dir, DEFAULT_CONFIG);
499
501
  const r2: any = await call(edit, {
500
502
  path: "f.txt",
501
503
  edits: [{ op: "replace", anchor: a1, body: ["NEW NEW NEW"] }],
@@ -510,7 +512,7 @@ test("replace: multiline replacement (changes line count) still reports a correc
510
512
  const f = join(dir, "f.txt");
511
513
  await writeFile(f, "a\nb\nc\n");
512
514
  // replace "b" with two lines → line count grows; changed region must cover the insertion
513
- const r: any = await call(makeReplaceTool(dir), {
515
+ const r: any = await call(makeReplaceTool(dir, DEFAULT_CONFIG), {
514
516
  path: "f.txt",
515
517
  replacements: [{ find: "b", replace: "B1\nB2" }],
516
518
  });
@@ -526,7 +528,7 @@ test("replace renderResult: renders the diff without throwing", async () => {
526
528
  await withDir(async (dir) => {
527
529
  const f = join(dir, "f.txt");
528
530
  await writeFile(f, "a\nb\nc\n");
529
- const tool = makeReplaceTool(dir);
531
+ const tool = makeReplaceTool(dir, DEFAULT_CONFIG);
530
532
  const r: any = await call(tool, { path: "f.txt", replacements: [{ find: "b", replace: "B" }] });
531
533
  const comp = tool.renderResult(
532
534
  { content: r.content, details: r.details },
@@ -547,7 +549,7 @@ test("replace renderResult: renders the error line without throwing", async () =
547
549
  await withDir(async (dir) => {
548
550
  const f = join(dir, "f.txt");
549
551
  await writeFile(f, "a\n");
550
- const tool = makeReplaceTool(dir);
552
+ const tool = makeReplaceTool(dir, DEFAULT_CONFIG);
551
553
  let thrown: any;
552
554
  const r: any = await call(tool, {
553
555
  path: "f.txt",
@@ -583,7 +585,7 @@ test("replace header: renderResult refreshes the call header in place — no inv
583
585
  await withDir(async (dir) => {
584
586
  const f = join(dir, "f.txt");
585
587
  await writeFile(f, "a\nb\nc\n");
586
- const tool = makeReplaceTool(dir);
588
+ const tool = makeReplaceTool(dir, DEFAULT_CONFIG);
587
589
  const args = { path: "f.txt", replacements: [{ find: "b", replace: "B1\nB2" }] };
588
590
  const r: any = await call(tool, args);
589
591
  let invalidated = false;
@@ -612,7 +614,7 @@ test("replace header: renderResult refreshes the call header in place — no inv
612
614
  });
613
615
 
614
616
  test("replace header retains the rule count when a long path wraps", () => {
615
- const tool = makeReplaceTool(process.cwd());
617
+ const tool = makeReplaceTool(process.cwd(), DEFAULT_CONFIG);
616
618
  const args = {
617
619
  path: "x".repeat(68),
618
620
  replacements: [
@@ -628,7 +630,7 @@ test("replace header retains the rule count when a long path wraps", () => {
628
630
  test("replacement batches use one snapshot and return anchors for the final content", async () =>
629
631
  withDir(async (dir) => {
630
632
  const file = join(dir, "batch.txt");
631
- const tool = makeReplaceTool(dir);
633
+ const tool = makeReplaceTool(dir, DEFAULT_CONFIG);
632
634
  const args = {
633
635
  path: file,
634
636
  replacements: [
@@ -642,7 +644,7 @@ test("replacement batches use one snapshot and return anchors for the final cont
642
644
  assert.equal(await readFile(file, "utf8"), "\uFEFFbar\r\nbaz\nbar");
643
645
  assert.match(result.content[0].text, /3 matches/);
644
646
  assert.match(result.details.diff, /^\+2 baz/m);
645
- await call(makeEditOverride(dir), {
647
+ await call(makeEditOverride(dir, DEFAULT_CONFIG), {
646
648
  path: file,
647
649
  edits: [{ op: "replace", anchor: anchorLine(result.content[0].text, 2), body: ["chained"] }],
648
650
  });
@@ -657,6 +659,7 @@ test("invalid batches reject every change and never run a fused command", async
657
659
  let commands = 0;
658
660
  const tool = makeReplaceTool(
659
661
  dir,
662
+ DEFAULT_CONFIG,
660
663
  createActionFusionExecutor(async () => {
661
664
  commands++;
662
665
  return "done";
@@ -717,7 +720,7 @@ test("invalid batches reject every change and never run a fused command", async
717
720
  test("adjacent matches and zero-width boundaries have deterministic batch semantics", async () =>
718
721
  withDir(async (dir) => {
719
722
  const file = join(dir, "batch.txt");
720
- const tool = makeReplaceTool(dir);
723
+ const tool = makeReplaceTool(dir, DEFAULT_CONFIG);
721
724
  for (const rules of [
722
725
  [
723
726
  { find: "a", replace: "b" },
@@ -765,7 +768,7 @@ test("adjacent matches and zero-width boundaries have deterministic batch semant
765
768
  test("regex templates agree with native replacement in single and snapshot batch modes", async () =>
766
769
  withDir(async (dir) => {
767
770
  const file = join(dir, "regex.txt");
768
- const tool = makeReplaceTool(dir);
771
+ const tool = makeReplaceTool(dir, DEFAULT_CONFIG);
769
772
  const template =
770
773
  "$$|$&|$`|$'|$0|$00|$01|$1|$2|$10|$12|$99|$<x>|$<missing>|$<>|$<$&>|$<unclosed$1|$";
771
774
  for (const [source, find, flags] of [
@@ -803,6 +806,7 @@ test("successful batches run one command against the complete result", async ()
803
806
  let commands = 0;
804
807
  const tool = makeReplaceTool(
805
808
  dir,
809
+ DEFAULT_CONFIG,
806
810
  createActionFusionExecutor(async () => {
807
811
  commands++;
808
812
  assert.equal(await readFile(file, "utf8"), "bar baz");
@@ -835,12 +839,12 @@ test("regex captures and zero-width insertions use logical offsets without consu
835
839
  const path = join(dir, "f.txt");
836
840
  const before = "a\r\nb\rc\r\r\n";
837
841
  await writeFile(path, before);
838
- await call(makeReplaceTool(dir), {
842
+ await call(makeReplaceTool(dir, DEFAULT_CONFIG), {
839
843
  path,
840
844
  replacements: [{ find: "(b\rc\r)\\n", replace: "$1\n", regex: true }],
841
845
  });
842
846
  assert.equal(await readFile(path, "utf8"), before);
843
- await call(makeReplaceTool(dir), {
847
+ await call(makeReplaceTool(dir, DEFAULT_CONFIG), {
844
848
  path,
845
849
  replacements: [{ find: "(?=\\n)", replace: "!", regex: true }],
846
850
  });
@@ -851,7 +855,7 @@ test("replace rejects JSON-string rules without publishing", async () =>
851
855
  withDir(async (dir) => {
852
856
  const file = join(dir, "f.txt");
853
857
  await writeFile(file, "hello foo world");
854
- const tool = makeReplaceTool(dir);
858
+ const tool = makeReplaceTool(dir, DEFAULT_CONFIG);
855
859
  await assert.rejects(
856
860
  callTool(tool, {
857
861
  path: "f.txt",