@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
@@ -23,9 +23,11 @@ import { makeEditOverride } from "../pi/edit-tool.ts";
23
23
  import { makeReadOverride } from "../pi/read-tool.ts";
24
24
  import { makeWriteOverride } from "../pi/write-tool.ts";
25
25
  import { makeReplaceTool } from "../pi/replace-tool.ts";
26
- import { COMMON_RG_ARGS, resolveIgnoreCase, runRg } from "../pi/rg-line-filter.ts";
26
+ import { COMMON_RG_ARGS, probeRegex, resolveIgnoreCase, runRg } from "../pi/rg-process.ts";
27
+ import { runRgTextView } from "../pi/rg-text-view.ts";
27
28
  import { computeLineHash } from "../core/hash.ts";
28
29
  import { callTool } from "../pi/tool-call.testing.ts";
30
+ import { DEFAULT_CONFIG } from "../pi/config.ts";
29
31
 
30
32
  const invoke = (
31
33
  tool: any,
@@ -41,7 +43,7 @@ test("real rg emits anchored matches from a temporary directory", async () => {
41
43
  try {
42
44
  const file = join(directory, "fixture.ts");
43
45
  await writeFile(file, "needle\nother\n");
44
- const tool = makeGrepOverrideWithBackend(directory, {});
46
+ const tool = makeGrepOverrideWithBackend(directory, DEFAULT_CONFIG, {});
45
47
 
46
48
  for (const pattern of ["needle", ["needle"]]) {
47
49
  const result: any = await invoke(tool, "0", { pattern }, undefined, undefined);
@@ -58,7 +60,7 @@ test("real rg finds whitespace-only literal queries and OR alternatives", async
58
60
  try {
59
61
  const file = join(directory, "fixture.txt");
60
62
  await writeFile(file, "plain word\nfirst\tsecond\nboth \tforms\n");
61
- const tool = makeGrepOverrideWithBackend(directory, {});
63
+ const tool = makeGrepOverrideWithBackend(directory, DEFAULT_CONFIG, {});
62
64
  for (const { pattern, expected } of [
63
65
  { pattern: " ", expected: 2 },
64
66
  { pattern: "\t", expected: 2 },
@@ -90,7 +92,7 @@ test("real rg uses smart-case across OR patterns and Unicode matches", async ()
90
92
  const directory = await mkdtemp(join(tmpdir(), "hl-grep-case-"));
91
93
  try {
92
94
  await writeFile(join(directory, "fixture.ts"), "FOO abc\nfoo BAR\nfoo bar\nK zip\nk zip\n");
93
- const tool = makeGrepOverrideWithBackend(directory, {});
95
+ const tool = makeGrepOverrideWithBackend(directory, DEFAULT_CONFIG, {});
94
96
  const lower = await invoke(tool, "0", { pattern: ["foo", "bar"] }, undefined, undefined);
95
97
  assert.match(lower.content[0].text, /fixture\.ts · 3 matches/);
96
98
  assert.match(lower.content[0].text, /│FOO abc/);
@@ -110,7 +112,7 @@ test("explicit ignoreCase overrides smart-case for regex and literal queries", a
110
112
  try {
111
113
  const file = join(directory, "fixture.txt");
112
114
  await writeFile(file, "FOO\nfoo\n");
113
- const tool = makeGrepOverrideWithBackend(directory, {});
115
+ const tool = makeGrepOverrideWithBackend(directory, DEFAULT_CONFIG, {});
114
116
  const sensitive = await invoke(
115
117
  tool,
116
118
  "0",
@@ -202,7 +204,7 @@ test("real rg accepts Rust regex syntax and rejects unsupported lookarounds", as
202
204
  const directory = await mkdtemp(join(tmpdir(), "hl-grep-regex-engine-"));
203
205
  try {
204
206
  await writeFile(join(directory, "fixture.ts"), "FOO abc\nfoo BAR\nfoo bar\n");
205
- const tool = makeGrepOverrideWithBackend(directory, {});
207
+ const tool = makeGrepOverrideWithBackend(directory, DEFAULT_CONFIG, {});
206
208
  const result = await invoke(
207
209
  tool,
208
210
  "0",
@@ -231,7 +233,7 @@ test("owned rg processes ignore RIPGREP_CONFIG_PATH", async () => {
231
233
  );
232
234
  await writeFile(join(directory, "fixture.ts"), "FOO\nfoo\nbar\n");
233
235
  process.env.RIPGREP_CONFIG_PATH = config;
234
- const tool = makeGrepOverrideWithBackend(directory, {});
236
+ const tool = makeGrepOverrideWithBackend(directory, DEFAULT_CONFIG, {});
235
237
  const result: any = await invoke(
236
238
  tool,
237
239
  "0",
@@ -268,7 +270,7 @@ test("real rg validates its own regex syntax and limits automatic literal fallba
268
270
  const directory = await mkdtemp(join(tmpdir(), "hl-grep-regex-"));
269
271
  try {
270
272
  await writeFile(join(directory, "fixture.ts"), "FOO\nfoo\nqueueTool(\nfoo(?=bar)\n");
271
- const tool = makeGrepOverrideWithBackend(directory, {});
273
+ const tool = makeGrepOverrideWithBackend(directory, DEFAULT_CONFIG, {});
272
274
  for (const pattern of ["(?i)^foo$", "(?P<name>foo)$"]) {
273
275
  const result: any = await invoke(tool, "0", { pattern }, undefined, undefined);
274
276
  assert.match(result.content[0].text, /│foo/);
@@ -307,7 +309,7 @@ test("real rg keeps CRLF line-end anchors with fixed OR matching", async () => {
307
309
  const directory = await mkdtemp(join(tmpdir(), "hl-grep-crlf-"));
308
310
  try {
309
311
  await writeFile(join(directory, "fixture.ts"), "alpha beta drop\r\nalpha beta\r\nalpha only");
310
- const tool = makeGrepOverrideWithBackend(directory, {});
312
+ const tool = makeGrepOverrideWithBackend(directory, DEFAULT_CONFIG, {});
311
313
  const ending = await invoke(tool, "0", { pattern: "beta$" }, undefined, undefined);
312
314
  assert.match(ending.content[0].text, /fixture\.ts · 1 match/);
313
315
  assert.match(ending.content[0].text, /2#[0-9A-Z]+│alpha beta$/);
@@ -329,7 +331,7 @@ test("real rg finds a late OR match and respects the line limit", async () => {
329
331
  const directory = await mkdtemp(join(tmpdir(), "hl-grep-limit-"));
330
332
  try {
331
333
  await writeFile(join(directory, "fixture.ts"), "foo skip\n".repeat(4096) + "foo keep\n");
332
- const tool = makeGrepOverrideWithBackend(directory, {});
334
+ const tool = makeGrepOverrideWithBackend(directory, DEFAULT_CONFIG, {});
333
335
  const result = await invoke(
334
336
  tool,
335
337
  "0",
@@ -379,6 +381,10 @@ test("shared rg runner stops and cleans up after limits, callback failures, and
379
381
  runRg(join(directory, "missing-rg"), [], undefined, () => true),
380
382
  /Failed to run ripgrep/,
381
383
  );
384
+ await assert.rejects(
385
+ probeRegex(join(directory, "missing-rg"), ["needle"], false),
386
+ /^Error: Failed to run ripgrep: /,
387
+ );
382
388
  } finally {
383
389
  await rm(directory, { recursive: true, force: true });
384
390
  }
@@ -390,7 +396,7 @@ test("directory searches respect ignores but explicit files and hidden files rem
390
396
  await writeFile(join(directory, ".ignore"), "ignored.txt\n");
391
397
  const ignored = join(directory, "ignored.txt");
392
398
  await writeFile(ignored, "needle\n");
393
- const tool = makeGrepOverrideWithBackend(directory, {});
399
+ const tool = makeGrepOverrideWithBackend(directory, DEFAULT_CONFIG, {});
394
400
  const normal = await invoke(tool, "0", { pattern: "needle" }, undefined, undefined);
395
401
  assert.equal(normal.content[0].text, "No matches found");
396
402
  const explicit = await invoke(
@@ -426,7 +432,7 @@ test("explicit file paths obey ordered glob filters without inheriting ignore ru
426
432
  const ignored = join(directory, "ignored.ts");
427
433
  await writeFile(join(directory, ".ignore"), "ignored.ts\n");
428
434
  await Promise.all([kept, excluded, ignored].map((path) => writeFile(path, "needle\n")));
429
- const tool = makeGrepOverrideWithBackend(directory, {});
435
+ const tool = makeGrepOverrideWithBackend(directory, DEFAULT_CONFIG, {});
430
436
  const result: any = await invoke(
431
437
  tool,
432
438
  "0",
@@ -478,7 +484,7 @@ test("directory traversal skips symlinks but explicitly named linked files remai
478
484
  return t.skip("symbolic link creation unavailable");
479
485
  throw error;
480
486
  }
481
- const grep = makeGrepOverrideWithBackend(root, {});
487
+ const grep = makeGrepOverrideWithBackend(root, DEFAULT_CONFIG, {});
482
488
  const hidden: any = await invoke(grep, "0", { pattern: "needle" }, undefined, undefined);
483
489
  assert.equal(hidden.content[0].text, "No matches found");
484
490
  const found: any = await invoke(
@@ -493,7 +499,7 @@ test("directory traversal skips symlinks but explicitly named linked files remai
493
499
  assert.equal(resultPath.replace(/\\/g, "/"), "link/linked.txt");
494
500
  assert.equal(found.content[0].text.match(/ · 1 match/g)?.length, 1);
495
501
  const anchor = anchored.slice(0, anchored.indexOf("│"));
496
- const edit: any = makeEditOverride(root);
502
+ const edit: any = makeEditOverride(root, DEFAULT_CONFIG);
497
503
  await invoke(
498
504
  edit,
499
505
  "0",
@@ -514,7 +520,7 @@ test("real rg reports unsupported lookarounds and backreferences under Rust rege
514
520
  const directory = await mkdtemp(join(tmpdir(), "hl-grep-rust-boundary-"));
515
521
  try {
516
522
  await writeFile(join(directory, "fixture.txt"), "foobar\nfoofoo\n");
517
- const tool = makeGrepOverrideWithBackend(directory, {});
523
+ const tool = makeGrepOverrideWithBackend(directory, DEFAULT_CONFIG, {});
518
524
  const valid = await invoke(
519
525
  tool,
520
526
  "0",
@@ -549,7 +555,7 @@ test("line-based grep uses context for display but never matches across CRLF", a
549
555
  const directory = await mkdtemp(join(tmpdir(), "hl-grep-lines-"));
550
556
  try {
551
557
  await writeFile(join(directory, "fixture.txt"), "alpha\r\nbeta\r\ngamma\r\n");
552
- const tool = makeGrepOverrideWithBackend(directory, {});
558
+ const tool = makeGrepOverrideWithBackend(directory, DEFAULT_CONFIG, {});
553
559
  const context = await invoke(tool, "0", { pattern: "alpha", context: 1 }, undefined, undefined);
554
560
  assert.match(context.content[0].text, /fixture\.txt · 1 match/);
555
561
  assert.match(context.content[0].text, /1#[0-9A-Z]+│alpha/);
@@ -582,7 +588,7 @@ test("multiline grep anchors CRLF spans and counts overlapping physical lines on
582
588
  try {
583
589
  const file = join(directory, "fixture.txt");
584
590
  await writeFile(file, "alpha\r\nbeta\r\ngamma\r\n");
585
- const tool = makeGrepOverrideWithBackend(directory, {});
591
+ const tool = makeGrepOverrideWithBackend(directory, DEFAULT_CONFIG, {});
586
592
  const regex = await invoke(
587
593
  tool,
588
594
  "0",
@@ -635,7 +641,7 @@ test("multiline grep anchors CRLF spans and counts overlapping physical lines on
635
641
  undefined,
636
642
  );
637
643
  assert.match(boundary.content[0].text, /fixture\.txt · 1 match/);
638
- const edit: any = makeEditOverride(directory);
644
+ const edit: any = makeEditOverride(directory, DEFAULT_CONFIG);
639
645
  const anchor = regex.content[0].text.match(/(2#[0-9A-Z]+)│beta/)?.[1];
640
646
  assert.ok(anchor);
641
647
  await invoke(
@@ -656,7 +662,7 @@ test("multiline grep preserves BOM and standalone CR while normalizing CRLF", as
656
662
  try {
657
663
  const file = join(directory, "fixture.txt");
658
664
  await writeFile(file, "\uFEFFalpha\rsolo\r\nbeta\r\n");
659
- const tool = makeGrepOverrideWithBackend(directory, {});
665
+ const tool = makeGrepOverrideWithBackend(directory, DEFAULT_CONFIG, {});
660
666
  const result = await invoke(
661
667
  tool,
662
668
  "0",
@@ -685,7 +691,7 @@ test("multiline grep anchors empty lines and line-start zero-width matches", asy
685
691
  try {
686
692
  const file = join(directory, "fixture.txt");
687
693
  await writeFile(file, "alpha\r\n\r\nbeta\r\n");
688
- const tool = makeGrepOverrideWithBackend(directory, {});
694
+ const tool = makeGrepOverrideWithBackend(directory, DEFAULT_CONFIG, {});
689
695
  const span = await invoke(
690
696
  tool,
691
697
  "0",
@@ -714,7 +720,7 @@ test("multiline zero-width EOF stays on the last existing physical line", async
714
720
  const directory = await mkdtemp(join(tmpdir(), "hl-grep-multiline-eof-"));
715
721
  try {
716
722
  const file = join(directory, "fixture.txt");
717
- const tool = makeGrepOverrideWithBackend(directory, {});
723
+ const tool = makeGrepOverrideWithBackend(directory, DEFAULT_CONFIG, {});
718
724
  for (const content of ["last line", "last line\n"]) {
719
725
  await writeFile(file, content);
720
726
  const result = await invoke(
@@ -741,10 +747,10 @@ test("multiline grep detects changed files and propagates cancellation", async (
741
747
  try {
742
748
  const file = join(directory, "fixture.txt");
743
749
  await writeFile(file, "alpha\nbeta\n");
744
- const changing = makeGrepOverrideWithBackend(directory, {
745
- async runRg(path, args, signal, onLine) {
746
- const result = await runRg(path, args, signal, onLine);
747
- if (args.includes("--json")) await writeFile(file, "alpha\nchanged\n");
750
+ const changing = makeGrepOverrideWithBackend(directory, DEFAULT_CONFIG, {
751
+ async search(path, request, signal, onLine) {
752
+ const result = await runRgTextView(path, request, signal, onLine);
753
+ await writeFile(file, "alpha\nchanged\n");
748
754
  return result;
749
755
  },
750
756
  });
@@ -760,10 +766,10 @@ test("multiline grep detects changed files and propagates cancellation", async (
760
766
  );
761
767
  await writeFile(file, "alpha\nbeta\n");
762
768
  const controller = new AbortController();
763
- const cancelling = makeGrepOverrideWithBackend(directory, {
764
- runRg(path, args, signal, onLine) {
765
- if (args.includes("--json")) controller.abort();
766
- return runRg(path, args, signal, onLine);
769
+ const cancelling = makeGrepOverrideWithBackend(directory, DEFAULT_CONFIG, {
770
+ search(path, request, signal, onLine) {
771
+ controller.abort();
772
+ return runRgTextView(path, request, signal, onLine);
767
773
  },
768
774
  });
769
775
  await assert.rejects(
@@ -788,7 +794,7 @@ test("files and count modes aggregate only matching lines inside the limit", asy
788
794
  const second = join(directory, "b.txt");
789
795
  await writeFile(first, "needle needle\nneedle\n");
790
796
  await writeFile(second, "needle\n");
791
- const tool = makeGrepOverrideWithBackend(directory, {});
797
+ const tool = makeGrepOverrideWithBackend(directory, DEFAULT_CONFIG, {});
792
798
  const query = { pattern: "needle", path: [first, second], limit: 1 };
793
799
  const files = await invoke(
794
800
  tool,
@@ -833,10 +839,10 @@ test("default grep rejects file changes and propagates cancellation", async () =
833
839
  try {
834
840
  const file = join(directory, "fixture.txt");
835
841
  await writeFile(file, "foo bar\n");
836
- const changing = makeGrepOverrideWithBackend(directory, {
837
- async runRg(path, args, signal, onLine) {
838
- const result = await runRg(path, args, signal, onLine);
839
- if (args.includes("--json")) await writeFile(file, "changed content\n");
842
+ const changing = makeGrepOverrideWithBackend(directory, DEFAULT_CONFIG, {
843
+ async search(path, request, signal, onLine) {
844
+ const result = await runRgTextView(path, request, signal, onLine);
845
+ await writeFile(file, "changed content\n");
840
846
  return result;
841
847
  },
842
848
  });
@@ -847,10 +853,10 @@ test("default grep rejects file changes and propagates cancellation", async () =
847
853
 
848
854
  await writeFile(file, "foo bar\n");
849
855
  const controller = new AbortController();
850
- const cancelling = makeGrepOverrideWithBackend(directory, {
851
- runRg(path, args, signal, onLine) {
852
- if (args.includes("--json")) controller.abort();
853
- return runRg(path, args, signal, onLine);
856
+ const cancelling = makeGrepOverrideWithBackend(directory, DEFAULT_CONFIG, {
857
+ search(path, request, signal, onLine) {
858
+ controller.abort();
859
+ return runRgTextView(path, request, signal, onLine);
854
860
  },
855
861
  });
856
862
  await assert.rejects(
@@ -866,7 +872,7 @@ test("owned rg rejects an oversized JSONL record", async () => {
866
872
  const directory = await mkdtemp(join(tmpdir(), "hl-grep-record-limit-"));
867
873
  try {
868
874
  await writeFile(join(directory, "large.txt"), `needle${"x".repeat(17 * 1024 * 1024)}\n`);
869
- const tool = makeGrepOverrideWithBackend(directory, {});
875
+ const tool = makeGrepOverrideWithBackend(directory, DEFAULT_CONFIG, {});
870
876
  await assert.rejects(
871
877
  invoke(tool, "0", { pattern: "needle", literal: true }, undefined, undefined),
872
878
  /record exceeds 16 MiB/,
@@ -880,7 +886,7 @@ test("real rg accepts wildcard-only regexes and preserves limits and literal mod
880
886
  const directory = await mkdtemp(join(tmpdir(), "hl-grep-wildcard-"));
881
887
  try {
882
888
  await writeFile(join(directory, "fixture.txt"), "first\n\n.*\n");
883
- const tool = makeGrepOverrideWithBackend(directory, {});
889
+ const tool = makeGrepOverrideWithBackend(directory, DEFAULT_CONFIG, {});
884
890
  for (const [pattern, expected] of [
885
891
  [".*", 3],
886
892
  ["^.+$", 2],
@@ -937,8 +943,8 @@ test("tools share physical lines and anchors across text representations", async
937
943
  ]) {
938
944
  await call(makeWriteOverride(directory), { path: file, content: before });
939
945
  assert.equal(await readFile(file, "utf8"), before);
940
- const read = await call(makeReadOverride(directory), { path: file });
941
- const grep = await call(makeGrepOverrideWithBackend(directory, {}), {
946
+ const read = await call(makeReadOverride(directory, DEFAULT_CONFIG), { path: file });
947
+ const grep = await call(makeGrepOverrideWithBackend(directory, DEFAULT_CONFIG, {}), {
942
948
  path: file,
943
949
  pattern: "old",
944
950
  context: 2,
@@ -946,7 +952,7 @@ test("tools share physical lines and anchors across text representations", async
946
952
  assert.deepEqual(rows(grep), rows(read));
947
953
  if (before.includes("a\rb")) assert.match(rows(read)[0], /│a␍b$/);
948
954
  const anchor = rows(grep)[1].split("│")[0];
949
- const edit = await call(makeEditOverride(directory), {
955
+ const edit = await call(makeEditOverride(directory, DEFAULT_CONFIG), {
950
956
  path: file,
951
957
  edits: [{ op: "replace", anchor, body: ["new"] }],
952
958
  });
@@ -956,15 +962,15 @@ test("tools share physical lines and anchors across text representations", async
956
962
  assert.match(edit.details.diff, /^\+2 new/m);
957
963
  assert.ok(!edit.details.diff.includes("\r"));
958
964
  if (before.includes("a\rb")) assert.ok(edit.details.patch.includes(" a\rb\n"));
959
- const editedRead = await call(makeReadOverride(directory), { path: file });
965
+ const editedRead = await call(makeReadOverride(directory, DEFAULT_CONFIG), { path: file });
960
966
  assert.equal(rows(edit)[0], rows(editedRead)[1].split("│")[0]);
961
- const replaced = await call(makeReplaceTool(directory), {
967
+ const replaced = await call(makeReplaceTool(directory, DEFAULT_CONFIG), {
962
968
  path: file,
963
969
  replacements: [{ find: "new", replace: "next" }],
964
970
  });
965
971
  assert.equal(await readFile(file, "utf8"), before.replace("old", "next"));
966
972
  assert.equal(replaced.details.firstChangedLine, 2);
967
- const replacedRead = await call(makeReadOverride(directory), { path: file });
973
+ const replacedRead = await call(makeReadOverride(directory, DEFAULT_CONFIG), { path: file });
968
974
  assert.equal(rows(replaced)[0], rows(replacedRead)[1].split("│")[0]);
969
975
  }
970
976
  } finally {
@@ -978,7 +984,7 @@ test("long-line previews preserve full-line anchors across literal and Rust rege
978
984
  const long = "😀界".repeat(220) + "NEEDLE" + "tail".repeat(200);
979
985
  const context = "x" + "😀".repeat(400);
980
986
  await writeFile(join(directory, "long.txt"), `${long}\r\nfollow\r\n${context}\r\n`);
981
- const tool = makeGrepOverrideWithBackend(directory, {});
987
+ const tool = makeGrepOverrideWithBackend(directory, DEFAULT_CONFIG, {});
982
988
  for (const params of [
983
989
  { pattern: "NEEDLE" },
984
990
  { pattern: ["NEEDLE", "tail"], literal: true },
@@ -993,10 +999,10 @@ test("long-line previews preserve full-line anchors across literal and Rust rege
993
999
  );
994
1000
  const output = result.content[0].text;
995
1001
  const row = output.split("\n").find((line: string) => line.startsWith("1#"));
996
- assert.ok(row.startsWith(`1#${computeLineHash(1, long)}│[partial, columns `));
1002
+ assert.ok(row.startsWith(`1#${computeLineHash(1, long, 4)}│[partial, columns `));
997
1003
  assert.ok(row.includes("NEEDLE"));
998
1004
  assert.equal(Buffer.from(row).toString("utf8"), row);
999
- assert.ok(output.includes(`3#${computeLineHash(3, context)}│[partial, columns 1-499]`));
1005
+ assert.ok(output.includes(`3#${computeLineHash(3, context, 4)}│[partial, columns 1-499]`));
1000
1006
  assert.match(output, /anchors hash full lines/);
1001
1007
  }
1002
1008
  } finally {
@@ -1010,8 +1016,8 @@ test("all text tools share logical CRLF matching, anchors, and mutation separato
1010
1016
  const path = join(directory, "mixed.txt");
1011
1017
  const before = "\uFEFFhead\r\nalpha\r\nbeta\nstand\rCR\r\r\nlast";
1012
1018
  const write = makeWriteOverride(directory);
1013
- const read = makeReadOverride(directory);
1014
- const grep = makeGrepOverrideWithBackend(directory, {});
1019
+ const read = makeReadOverride(directory, DEFAULT_CONFIG);
1020
+ const grep = makeGrepOverrideWithBackend(directory, DEFAULT_CONFIG, {});
1015
1021
  await invoke(write, "write", { path, content: before }, undefined, undefined, {
1016
1022
  cwd: directory,
1017
1023
  } as ExtensionContext);
@@ -1066,7 +1072,7 @@ test("all text tools share logical CRLF matching, anchors, and mutation separato
1066
1072
  } as ExtensionContext);
1067
1073
  if (mode === "edit") {
1068
1074
  await invoke(
1069
- makeEditOverride(directory),
1075
+ makeEditOverride(directory, DEFAULT_CONFIG),
1070
1076
  "edit",
1071
1077
  {
1072
1078
  path,
@@ -1085,7 +1091,7 @@ test("all text tools share logical CRLF matching, anchors, and mutation separato
1085
1091
  );
1086
1092
  } else {
1087
1093
  await invoke(
1088
- makeReplaceTool(directory),
1094
+ makeReplaceTool(directory, DEFAULT_CONFIG),
1089
1095
  "replace",
1090
1096
  {
1091
1097
  path,
@@ -1127,12 +1133,19 @@ test("visible source escapes remain readable and searchable while real CRLF stay
1127
1133
  undefined,
1128
1134
  { cwd: directory } as ExtensionContext,
1129
1135
  );
1130
- const read = await invoke(makeReadOverride(directory), "read", { path }, undefined, undefined, {
1131
- cwd: directory,
1132
- } as ExtensionContext);
1136
+ const read = await invoke(
1137
+ makeReadOverride(directory, DEFAULT_CONFIG),
1138
+ "read",
1139
+ { path },
1140
+ undefined,
1141
+ undefined,
1142
+ {
1143
+ cwd: directory,
1144
+ } as ExtensionContext,
1145
+ );
1133
1146
  assert.ok(read.content[0].type === "text");
1134
1147
  assert.ok(read.content[0].text.includes(String.raw`const eol = "\r\n";`));
1135
- const grep = makeGrepOverrideWithBackend(directory, {});
1148
+ const grep = makeGrepOverrideWithBackend(directory, DEFAULT_CONFIG, {});
1136
1149
  for (const query of [
1137
1150
  { pattern: String.raw`\r\n`, literal: true },
1138
1151
  { pattern: String.raw`\\r\\n`, literal: false },
@@ -1140,7 +1153,7 @@ test("visible source escapes remain readable and searchable while real CRLF stay
1140
1153
  const result = await invoke(grep, "grep", { path, ...query }, undefined, undefined);
1141
1154
  assert.ok(result.content[0].text.includes(String.raw`const eol = "\r\n";`));
1142
1155
  }
1143
- const replace = makeReplaceTool(directory);
1156
+ const replace = makeReplaceTool(directory, DEFAULT_CONFIG);
1144
1157
  await invoke(
1145
1158
  replace,
1146
1159
  "literal",
@@ -1171,7 +1184,7 @@ test("normalized grep batches retain original paths, literal option markers, and
1171
1184
  Array.from({ length: 70 }, (_, i) => writeFile(join(directory, `file ${i}.txt`), "--\r\n")),
1172
1185
  );
1173
1186
  await writeFile(join(directory, "invalid.txt"), Buffer.from([0xc3, 0x28]));
1174
- const grep = makeGrepOverrideWithBackend(directory, {});
1187
+ const grep = makeGrepOverrideWithBackend(directory, DEFAULT_CONFIG, {});
1175
1188
  const result = await invoke(
1176
1189
  grep,
1177
1190
  "grep",
@@ -1194,7 +1207,7 @@ test("NUL files are rejected on a confirmed hit, not reported as no match", asyn
1194
1207
  try {
1195
1208
  const binary = join(directory, "binary.txt");
1196
1209
  await writeFile(binary, Buffer.from("needle\r\nother\0needle\n"));
1197
- const grep = makeGrepOverrideWithBackend(directory, {});
1210
+ const grep = makeGrepOverrideWithBackend(directory, DEFAULT_CONFIG, {});
1198
1211
  await assert.rejects(
1199
1212
  invoke(
1200
1213
  grep,
@@ -7,14 +7,15 @@ import { makeReadOverride } from "../pi/read-tool.ts";
7
7
  import { makeGrepOverrideWithBackend } from "../pi/grep-tool.ts";
8
8
  import { computeLineHash } from "../core/hash.ts";
9
9
  import { callTool } from "../pi/tool-call.testing.ts";
10
+ import { DEFAULT_CONFIG } from "../pi/config.ts";
10
11
 
11
12
  const call = (tool: any, params: any) => callTool(tool, params, { toolCallId: "large-text" });
12
13
 
13
14
  test("read and line-based grep retain anchors on LF and CRLF files over 100 MiB", async () => {
14
15
  const directory = await mkdtemp(join(tmpdir(), "hashline-large-text-"));
15
16
  try {
16
- const read = makeReadOverride(directory);
17
- const grep = makeGrepOverrideWithBackend(directory, {});
17
+ const read = makeReadOverride(directory, DEFAULT_CONFIG);
18
+ const grep = makeGrepOverrideWithBackend(directory, DEFAULT_CONFIG, {});
18
19
  for (const ending of ["\n", "\r\n"]) {
19
20
  const path = join(directory, "large.txt");
20
21
  const handle = await open(path, "w");
@@ -29,12 +30,12 @@ test("read and line-based grep retain anchors on LF and CRLF files over 100 MiB"
29
30
  }
30
31
  const first: any = await call(read, { path, limit: 1 });
31
32
  assert.match(first.content[0].text, /103426 lines/);
32
- assert.ok(first.content[0].text.includes(`1#${computeLineHash(1, "needle")}│needle`));
33
+ assert.ok(first.content[0].text.includes(`1#${computeLineHash(1, "needle", 4)}│needle`));
33
34
  const last: any = await call(read, { path, offset: 103426, limit: 1 });
34
- assert.ok(last.content[0].text.includes(`103426#${computeLineHash(103426, "tail")}│tail`));
35
+ assert.ok(last.content[0].text.includes(`103426#${computeLineHash(103426, "tail", 4)}│tail`));
35
36
  for (const modes of [{}, { literal: true }]) {
36
37
  const result: any = await call(grep, { path, pattern: "needle", ...modes });
37
- assert.ok(result.content[0].text.includes(`1#${computeLineHash(1, "needle")}│needle`));
38
+ assert.ok(result.content[0].text.includes(`1#${computeLineHash(1, "needle", 4)}│needle`));
38
39
  assert.doesNotMatch(result.content[0].text, /Search incomplete/);
39
40
  }
40
41
  }
@@ -48,14 +49,14 @@ test("CRLF snapshots normalize terminators split across read chunks and preserve
48
49
  try {
49
50
  const path = join(directory, "boundary.txt");
50
51
  await writeFile(path, "x".repeat(65535) + "\r\nneedle\r\nstandalone\r");
51
- const grep = makeGrepOverrideWithBackend(directory, {});
52
+ const grep = makeGrepOverrideWithBackend(directory, DEFAULT_CONFIG, {});
52
53
  const result: any = await call(grep, {
53
54
  path,
54
55
  pattern: ["needle", "standalone\r"],
55
56
  literal: true,
56
57
  });
57
- assert.ok(result.content[0].text.includes(`2#${computeLineHash(2, "needle")}│needle`));
58
- assert.ok(result.content[0].text.includes(`3#${computeLineHash(3, "standalone\r")}│`));
58
+ assert.ok(result.content[0].text.includes(`2#${computeLineHash(2, "needle", 4)}│needle`));
59
+ assert.ok(result.content[0].text.includes(`3#${computeLineHash(3, "standalone\r", 4)}│`));
59
60
  } finally {
60
61
  await rm(directory, { recursive: true, force: true });
61
62
  }
@@ -10,14 +10,18 @@ test("regex worker starts from an installed-package path", async () => {
10
10
  try {
11
11
  const src = join(root, "src");
12
12
  await mkdir(join(src, "pi"), { recursive: true });
13
- await cp(new URL("../core/", import.meta.url), join(src, "core"), { recursive: true });
14
- for (const name of [
15
- "replace-worker.mjs",
16
- "replace-worker.ts",
17
- "replace-apply.ts",
18
- "error-text.ts",
13
+ await mkdir(join(src, "core"), { recursive: true });
14
+ for (const path of [
15
+ "pi/replace-worker.mjs",
16
+ "pi/replace-worker.ts",
17
+ "core/replace.ts",
18
+ "core/errors.ts",
19
+ "core/text.ts",
20
+ "core/lines.ts",
21
+ "core/ranges.ts",
22
+ "core/types.ts",
19
23
  ]) {
20
- await cp(new URL(`../pi/${name}`, import.meta.url), join(src, "pi", name));
24
+ await cp(new URL(`../${path}`, import.meta.url), join(src, path));
21
25
  }
22
26
  const worker = new Worker(join(src, "pi", "replace-worker.mjs"), {
23
27
  workerData: {