@criogaid/pi-hashline-edit 0.10.0 → 0.11.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 (94) hide show
  1. package/README.md +4 -3
  2. package/README.zh-CN.md +4 -3
  3. package/package.json +1 -1
  4. package/src/core/apply.test.ts +2 -2
  5. package/src/core/apply.ts +2 -2
  6. package/src/core/character-set.test.ts +2 -3
  7. package/src/core/character-set.ts +1 -1
  8. package/src/core/ranges.test.ts +2 -1
  9. package/src/core/ranges.ts +1 -1
  10. package/src/core/types.ts +1 -1
  11. package/src/index.ts +8 -8
  12. package/src/integration/config-registration.test.ts +8 -10
  13. package/src/integration/fusion-dispatch.test.ts +2 -2
  14. package/src/integration/grep-errors.test.ts +3 -3
  15. package/src/integration/grep-flags.test.ts +5 -5
  16. package/src/integration/grep-js-completeness.test.ts +12 -11
  17. package/src/integration/grep-line-candidates.test.ts +3 -2
  18. package/src/integration/grep-matrix.test.ts +5 -4
  19. package/src/integration/grep-order.test.ts +4 -4
  20. package/src/integration/grep-path-matrix.test.ts +5 -4
  21. package/src/integration/grep-prefilter-coverage.test.ts +4 -3
  22. package/src/integration/grep-process-limits.test.ts +2 -4
  23. package/src/integration/grep-regex.test.ts +10 -10
  24. package/src/integration/grep-rg.test.ts +50 -48
  25. package/src/integration/grep-scan-budget.test.ts +8 -8
  26. package/src/integration/grep-translation.test.ts +8 -7
  27. package/src/integration/large-text.test.ts +5 -5
  28. package/src/integration/model-budget-lifecycle.test.ts +9 -9
  29. package/src/integration/mutation-file-types.testing.ts +4 -4
  30. package/src/integration/npm-package.testing.ts +3 -3
  31. package/src/integration/publication-read-changes.test.ts +54 -54
  32. package/src/integration/read-changes.test.ts +4 -4
  33. package/src/integration/replace-worker-boundary.test.ts +1 -1
  34. package/src/integration/report-replay.test.ts +5 -6
  35. package/src/integration/utf8-errors.test.ts +4 -4
  36. package/src/pi/AGENTS.md +6 -5
  37. package/src/pi/action-fusion.test.ts +125 -105
  38. package/src/pi/action-fusion.testing.ts +38 -0
  39. package/src/pi/action-fusion.ts +9 -21
  40. package/src/pi/argument-diagnostics.ts +4 -3
  41. package/src/pi/argument-format.test.ts +19 -18
  42. package/src/pi/argument-validation.test.ts +218 -139
  43. package/src/pi/budgets.ts +1 -4
  44. package/src/pi/codemode.test.ts +7 -2
  45. package/src/pi/config.test.ts +2 -1
  46. package/src/pi/config.ts +8 -3
  47. package/src/pi/diagnostic-buffer.test.ts +23 -13
  48. package/src/pi/edit-tool.ts +47 -62
  49. package/src/pi/error-text.ts +7 -2
  50. package/src/pi/execute.test.ts +174 -157
  51. package/src/pi/failure-context.test.ts +4 -3
  52. package/src/pi/failure-context.ts +1 -1
  53. package/src/pi/failure-path.test.ts +37 -37
  54. package/src/pi/file-commit.test.ts +47 -19
  55. package/src/pi/file-commit.ts +36 -9
  56. package/src/pi/fusion-card.test.ts +22 -21
  57. package/src/pi/grep-candidates.test.ts +18 -20
  58. package/src/pi/grep-candidates.ts +8 -13
  59. package/src/pi/grep-matrix.test.ts +3 -3
  60. package/src/pi/grep-order.test.ts +12 -11
  61. package/src/pi/grep-output.ts +36 -15
  62. package/src/pi/grep-reread.ts +7 -2
  63. package/src/pi/grep-rg.testing.ts +70 -0
  64. package/src/pi/grep-scope.ts +4 -4
  65. package/src/pi/grep-search.ts +8 -11
  66. package/src/pi/grep-tool.ts +23 -39
  67. package/src/pi/grep.test.ts +102 -116
  68. package/src/pi/model-budgets.test.ts +2 -1
  69. package/src/pi/mutation-outcome.testing.ts +0 -1
  70. package/src/pi/mutation-result.test.ts +8 -8
  71. package/src/pi/mutation-result.ts +1 -1
  72. package/src/pi/mutation-runner.ts +9 -5
  73. package/src/pi/output-budgets.test.ts +53 -31
  74. package/src/pi/pi.test.ts +18 -13
  75. package/src/pi/read-tool.ts +13 -18
  76. package/src/pi/read.test.ts +22 -41
  77. package/src/pi/registration.test.ts +25 -19
  78. package/src/pi/render.test.ts +51 -32
  79. package/src/pi/render.ts +7 -4
  80. package/src/pi/replace-regex.ts +1 -1
  81. package/src/pi/replace-tool.ts +6 -16
  82. package/src/pi/replace.test.ts +45 -34
  83. package/src/pi/report-failure.testing.ts +9 -1
  84. package/src/pi/report-schema.ts +205 -83
  85. package/src/pi/report.test.ts +66 -64
  86. package/src/pi/report.ts +23 -17
  87. package/src/pi/result-safety.test.ts +121 -100
  88. package/src/pi/rg-process.test.ts +2 -2
  89. package/src/pi/rg-process.ts +9 -15
  90. package/src/pi/schema.ts +23 -0
  91. package/src/pi/tool-factories.testing.ts +59 -0
  92. package/src/pi/write-tool.ts +9 -15
  93. package/src/pi/write.test.ts +30 -31
  94. package/src/testing/run-tests.ts +1 -1
@@ -4,10 +4,10 @@ import { tmpdir } from "node:os";
4
4
  import { join } from "node:path";
5
5
  import { test } from "node:test";
6
6
  import { rejectsArgument } from "../pi/argument-error.testing.ts";
7
- import { DEFAULT_CONFIG } from "../pi/config.ts";
8
- import { makeGrepOverrideWithBackend } from "../pi/grep-tool.ts";
7
+ const { DEFAULT_CONFIG, makeGrepOverride } = await import("../pi/tool-factories.testing.ts");
8
+
9
9
  import { reportOf } from "../pi/report.ts";
10
- import { grepCounts } from "../pi/grep-output.testing.ts";
10
+ const { grepCounts } = await import("../pi/grep-output.testing.ts");
11
11
  import { callTool } from "../pi/tool-call.testing.ts";
12
12
  import { unsupportedByHost } from "../testing/regex-host.testing.ts";
13
13
 
@@ -207,7 +207,7 @@ test("regex and case modes across line endings → real grep agrees with native
207
207
  const directory = await mkdtemp(join(tmpdir(), "hl-grep-js-equivalence-"));
208
208
  t.after(() => rm(directory, { recursive: true, force: true }));
209
209
  const path = join(directory, "fixture.txt");
210
- const tool = makeGrepOverrideWithBackend(directory, DEFAULT_CONFIG, {});
210
+ const tool = makeGrepOverride(directory, DEFAULT_CONFIG);
211
211
  for (const scenario of cases) {
212
212
  for (const separator of ["\n", "\r\n"]) {
213
213
  for (const multiline of scenario.multilineOnly ? [true] : [false, true]) {
@@ -249,7 +249,7 @@ test("malformed UTF-8 → character classes match replacement characters in the
249
249
  const directory = await mkdtemp(join(tmpdir(), "hl-grep-js-invalid-"));
250
250
  t.after(() => rm(directory, { recursive: true, force: true }));
251
251
  const path = join(directory, "invalid.txt");
252
- const tool = makeGrepOverrideWithBackend(directory, DEFAULT_CONFIG, {});
252
+ const tool = makeGrepOverride(directory, DEFAULT_CONFIG);
253
253
  await writeFile(
254
254
  path,
255
255
  Buffer.concat([Buffer.from("a"), Buffer.from([0xff]), Buffer.from("b\naxb\n")]),
@@ -274,7 +274,7 @@ test("backreference regression: a capture spanning mixed line endings → matche
274
274
  try {
275
275
  const path = join(dir, "mixed.txt");
276
276
  await writeFile(path, "a\r\na\n");
277
- const tool = makeGrepOverrideWithBackend(dir, DEFAULT_CONFIG, {});
277
+ const tool = makeGrepOverride(dir, DEFAULT_CONFIG);
278
278
  const result = await callTool(tool, {
279
279
  path,
280
280
  pattern: "(a\\n)\\1",
@@ -294,7 +294,7 @@ test("backreference regression: ignoreCase with an ASCII capture → does not ma
294
294
  try {
295
295
  const path = join(dir, "casefold.txt");
296
296
  await writeFile(path, "kK\n");
297
- const tool = makeGrepOverrideWithBackend(dir, DEFAULT_CONFIG, {});
297
+ const tool = makeGrepOverride(dir, DEFAULT_CONFIG);
298
298
  const result = await callTool(tool, {
299
299
  path,
300
300
  pattern: "(k)\\1",
@@ -331,7 +331,7 @@ test("zero-maximum quantifiers → real grep matches the active capture", async
331
331
  try {
332
332
  const path = join(dir, "input.txt");
333
333
  await writeFile(path, source);
334
- const tool = makeGrepOverrideWithBackend(dir, DEFAULT_CONFIG, {});
334
+ const tool = makeGrepOverride(dir, DEFAULT_CONFIG);
335
335
  const result = await callTool(tool, {
336
336
  path,
337
337
  pattern,
@@ -353,7 +353,7 @@ test("JS syntax boundary → executes constructs requiring JS", async (t) => {
353
353
  t.after(() => rm(dir, { recursive: true, force: true }));
354
354
  const path = join(dir, "input.txt");
355
355
  await writeFile(path, "😀\naba\nab\n");
356
- const tool = makeGrepOverrideWithBackend(dir, DEFAULT_CONFIG, {});
356
+ const tool = makeGrepOverride(dir, DEFAULT_CONFIG);
357
357
  for (const pattern of [
358
358
  "^..$",
359
359
  "^[^a]{2}$",
@@ -378,7 +378,7 @@ test("zero-width assertions at LF and CRLF boundaries → match only empty physi
378
378
  t.after(() => rm(directory, { recursive: true, force: true }));
379
379
  const path = join(directory, "fixture.txt");
380
380
  await writeFile(path, "a\nb\r\nc\n\nd\r\n\r\nx y\n");
381
- const tool = makeGrepOverrideWithBackend(directory, DEFAULT_CONFIG, {});
381
+ const tool = makeGrepOverride(directory, DEFAULT_CONFIG);
382
382
  for (const [pattern, multiline] of [
383
383
  ["^$", false],
384
384
  ["^ *$", false],
@@ -1,3 +1,4 @@
1
+ import { makeMockGrep } from "../pi/grep-rg.testing.ts";
1
2
  /**
2
3
  * Explicit integration coverage for the platform rg bundled by @vscode/ripgrep.
3
4
  * This suite is excluded from the default test script.
@@ -21,19 +22,20 @@ import { tmpdir } from "node:os";
21
22
  import { dirname, join } from "node:path";
22
23
  import { fileURLToPath, pathToFileURL } from "node:url";
23
24
  import type { ExtensionContext } from "@earendil-works/pi-coding-agent";
24
- import { makeGrepOverrideWithBackend } from "../pi/grep-tool.ts";
25
- import { makeEditOverride } from "../pi/edit-tool.ts";
26
- import { makeReadOverride } from "../pi/read-tool.ts";
27
- import { makeWriteOverride } from "../pi/write-tool.ts";
28
- import { makeReplaceTool } from "../pi/replace-tool.ts";
29
- import { COMMON_RG_ARGS, MAX_RG_RECORD_BYTES, runRgPaths } from "../pi/rg-process.ts";
30
- import { DEFAULT_OUTPUT_BUDGETS } from "../pi/budgets.ts";
25
+
26
+ const { makeEditOverride } = await import("../pi/tool-factories.testing.ts");
27
+ const { makeReadOverride } = await import("../pi/tool-factories.testing.ts");
28
+ const { makeWriteOverride } = await import("../pi/tool-factories.testing.ts");
29
+ const { makeReplaceTool } = await import("../pi/tool-factories.testing.ts");
30
+ import { COMMON_RG_ARGS, runRgPaths } from "../pi/rg-process.ts";
31
+ const { DEFAULT_OUTPUT_BUDGETS } = await import("../pi/tool-factories.testing.ts");
32
+ const MAX_RG_RECORD_BYTES = 16 * 1024 * 1024;
31
33
  import { computeLineHash } from "../core/hash.ts";
32
34
  import { callTool } from "../pi/tool-call.testing.ts";
33
- import { DEFAULT_CONFIG } from "../pi/config.ts";
35
+ const { DEFAULT_CONFIG, makeGrepOverride } = await import("../pi/tool-factories.testing.ts");
34
36
  import { canonicalPath } from "../pi/path.ts";
35
37
  import { reportOf } from "../pi/report.ts";
36
- import { grepCounts } from "../pi/grep-output.testing.ts";
38
+ const { grepCounts } = await import("../pi/grep-output.testing.ts");
37
39
  import { hostCompiles, unsupportedByHost } from "../testing/regex-host.testing.ts";
38
40
 
39
41
  const invoke = (
@@ -50,7 +52,7 @@ test("real rg emits anchored matches from a temporary directory", async () => {
50
52
  try {
51
53
  const file = join(directory, "fixture.ts");
52
54
  await writeFile(file, "needle\nother\n");
53
- const tool = makeGrepOverrideWithBackend(directory, DEFAULT_CONFIG, {});
55
+ const tool = makeGrepOverride(directory, DEFAULT_CONFIG);
54
56
 
55
57
  for (const pattern of ["needle", ["needle"]]) {
56
58
  const result: any = await invoke(tool, "0", { pattern, literal: true }, undefined, undefined);
@@ -67,7 +69,7 @@ test("real rg finds whitespace-only literal queries and OR alternatives", async
67
69
  try {
68
70
  const file = join(directory, "fixture.txt");
69
71
  await writeFile(file, "plain word\nfirst\tsecond\nboth \tforms\n");
70
- const tool = makeGrepOverrideWithBackend(directory, DEFAULT_CONFIG, {});
72
+ const tool = makeGrepOverride(directory, DEFAULT_CONFIG);
71
73
  for (const { pattern, expected } of [
72
74
  { pattern: " ", expected: 2 },
73
75
  { pattern: "\t", expected: 2 },
@@ -101,7 +103,7 @@ test("real rg uses smart-case across OR patterns and Unicode matches", async ()
101
103
  const directory = await mkdtemp(join(tmpdir(), "hl-grep-case-"));
102
104
  try {
103
105
  await writeFile(join(directory, "fixture.ts"), "FOO abc\nfoo BAR\nfoo bar\nK zip\nk zip\n");
104
- const tool = makeGrepOverrideWithBackend(directory, DEFAULT_CONFIG, {});
106
+ const tool = makeGrepOverride(directory, DEFAULT_CONFIG);
105
107
  const lower = await invoke(
106
108
  tool,
107
109
  "0",
@@ -134,7 +136,7 @@ test("explicit ignoreCase overrides smart-case for regex and literal queries", a
134
136
  try {
135
137
  const file = join(directory, "fixture.txt");
136
138
  await writeFile(file, "FOO\nfoo\n");
137
- const tool = makeGrepOverrideWithBackend(directory, DEFAULT_CONFIG, {});
139
+ const tool = makeGrepOverride(directory, DEFAULT_CONFIG);
138
140
  const sensitive = await invoke(
139
141
  tool,
140
142
  "0",
@@ -193,7 +195,7 @@ test("owned rg processes ignore RIPGREP_CONFIG_PATH", async () => {
193
195
  );
194
196
  await writeFile(join(directory, "fixture.ts"), "FOO\nfoo\nbar\n");
195
197
  process.env.RIPGREP_CONFIG_PATH = config;
196
- const tool = makeGrepOverrideWithBackend(directory, DEFAULT_CONFIG, {});
198
+ const tool = makeGrepOverride(directory, DEFAULT_CONFIG);
197
199
  const result: any = await invoke(
198
200
  tool,
199
201
  "0",
@@ -230,7 +232,7 @@ test("real rg separates exact text from regex", async () => {
230
232
  join(directory, "fixture.ts"),
231
233
  "FOO\nfoo\nfoo0\nfoo(0)\nqueueTool(\nfoo(?=bar)\n",
232
234
  );
233
- const tool = makeGrepOverrideWithBackend(directory, DEFAULT_CONFIG, {});
235
+ const tool = makeGrepOverride(directory, DEFAULT_CONFIG);
234
236
  for (const pattern of ["(?i:^foo$)", "(?<name>foo)$"].filter((source) =>
235
237
  hostCompiles(source),
236
238
  )) {
@@ -256,7 +258,7 @@ test("real rg keeps CRLF line-end anchors with regex OR matching", async () => {
256
258
  const directory = await mkdtemp(join(tmpdir(), "hl-grep-crlf-"));
257
259
  try {
258
260
  await writeFile(join(directory, "fixture.ts"), "alpha beta drop\r\nalpha beta\r\nalpha only");
259
- const tool = makeGrepOverrideWithBackend(directory, DEFAULT_CONFIG, {});
261
+ const tool = makeGrepOverride(directory, DEFAULT_CONFIG);
260
262
  const ending = await invoke(
261
263
  tool,
262
264
  "0",
@@ -287,7 +289,7 @@ test("real rg finds a late OR match and respects the line limit", async () => {
287
289
  join(directory, "fixture.ts"),
288
290
  "foo skip\n".repeat(4096) + "foo keep\nfoo keep later\n",
289
291
  );
290
- const tool = makeGrepOverrideWithBackend(directory, DEFAULT_CONFIG, {});
292
+ const tool = makeGrepOverride(directory, DEFAULT_CONFIG);
291
293
  const result = await invoke(
292
294
  tool,
293
295
  "0",
@@ -375,7 +377,7 @@ test("directory searches respect ignores but explicit files and hidden files rem
375
377
  await writeFile(join(directory, ".ignore"), "ignored.txt\n");
376
378
  const ignored = join(directory, "ignored.txt");
377
379
  await writeFile(ignored, "needle\n");
378
- const tool = makeGrepOverrideWithBackend(directory, DEFAULT_CONFIG, {});
380
+ const tool = makeGrepOverride(directory, DEFAULT_CONFIG);
379
381
  const normal = await invoke(
380
382
  tool,
381
383
  "0",
@@ -424,7 +426,7 @@ test("gitignored directory → root traversal skips it and an explicit directory
424
426
  await writeFile(join(directory, ".gitignore"), "ignored/\n");
425
427
  await writeFile(join(ignored, "x.txt"), "needle\n");
426
428
  await writeFile(join(directory, "a.txt"), "needle\n");
427
- const tool = makeGrepOverrideWithBackend(directory, DEFAULT_CONFIG, {});
429
+ const tool = makeGrepOverride(directory, DEFAULT_CONFIG);
428
430
  for (const [path, expected] of [
429
431
  [directory, "a.txt"],
430
432
  [ignored, "ignored/x.txt"],
@@ -458,7 +460,7 @@ test("named directory → nested ignores, .git and links still limit traversal",
458
460
  await mkdir(dirname(join(directory, file)), { recursive: true });
459
461
  await writeFile(join(directory, file), "needle\n");
460
462
  }
461
- const tool = makeGrepOverrideWithBackend(directory, DEFAULT_CONFIG, {});
463
+ const tool = makeGrepOverride(directory, DEFAULT_CONFIG);
462
464
  for (const { path, expected, linked } of [
463
465
  { path: "node_modules/foo", expected: "node_modules/foo/index.js" },
464
466
  { path: "node_modules/foo/dist", expected: "node_modules/foo/dist/bundle.js" },
@@ -507,7 +509,7 @@ test("directory traversal with caller globs → excludes .git while an explicit
507
509
  await mkdir(git);
508
510
  await writeFile(join(git, "x.txt"), "needle\n");
509
511
  await writeFile(join(directory, "a.txt"), "needle\n");
510
- const tool = makeGrepOverrideWithBackend(directory, DEFAULT_CONFIG, {});
512
+ const tool = makeGrepOverride(directory, DEFAULT_CONFIG);
511
513
  for (const multiline of [false, true]) {
512
514
  for (const glob of [undefined, "*"]) {
513
515
  for (const [path, expected] of [
@@ -548,7 +550,7 @@ test("explicit file with different case and a glob → admits the same file on a
548
550
  const original = await stat(file, { bigint: true });
549
551
  assert.equal(alias.dev, original.dev);
550
552
  assert.equal(alias.ino, original.ino);
551
- const tool = makeGrepOverrideWithBackend(directory, DEFAULT_CONFIG, {});
553
+ const tool = makeGrepOverride(directory, DEFAULT_CONFIG);
552
554
  const result = await callTool(tool, {
553
555
  path: requested,
554
556
  glob: "*.txt",
@@ -587,7 +589,7 @@ test("explicit file with a dangling sibling link and a glob → returns complete
587
589
  }
588
590
  await assert.rejects(stat(link), { code: "ENOENT" });
589
591
  let listingDiagnostics = "";
590
- const tool = makeGrepOverrideWithBackend(directory, DEFAULT_CONFIG, {
592
+ const tool = makeMockGrep(directory, DEFAULT_CONFIG, {
591
593
  runRgPaths: async (...args) => {
592
594
  const listed = await runRgPaths(...args);
593
595
  listingDiagnostics = listed.stderr;
@@ -614,7 +616,7 @@ test("explicit file paths obey ordered glob filters without inheriting ignore ru
614
616
  const ignored = join(directory, "ignored.ts");
615
617
  await writeFile(join(directory, ".ignore"), "ignored.ts\n");
616
618
  await Promise.all([kept, excluded, ignored].map((path) => writeFile(path, "needle\n")));
617
- const tool = makeGrepOverrideWithBackend(directory, DEFAULT_CONFIG, {});
619
+ const tool = makeGrepOverride(directory, DEFAULT_CONFIG);
618
620
  const result: any = await invoke(
619
621
  tool,
620
622
  "0",
@@ -663,7 +665,7 @@ test("directory traversal skips symlinks but explicit linked directories and fil
663
665
  return t.skip("symbolic link creation unavailable");
664
666
  throw error;
665
667
  }
666
- const grep = makeGrepOverrideWithBackend(root, DEFAULT_CONFIG, {});
668
+ const grep = makeGrepOverride(root, DEFAULT_CONFIG);
667
669
  const hidden: any = await invoke(
668
670
  grep,
669
671
  "0",
@@ -702,7 +704,7 @@ test("directory traversal skips symlinks but explicit linked directories and fil
702
704
  await invoke(
703
705
  edit,
704
706
  "0",
705
- { path: resultPath, edits: [{ action: "replace", anchor, body: ["updated"] }] },
707
+ { path: resultPath, steps: [{ action: "replace", anchor, lines: ["updated"] }] },
706
708
  undefined,
707
709
  undefined,
708
710
  );
@@ -719,7 +721,7 @@ test("unbounded lookbehind → native JS matches after rg discovery", async (t)
719
721
  const directory = await mkdtemp(join(tmpdir(), "hl-grep-lookbehind-"));
720
722
  t.after(() => rm(directory, { recursive: true, force: true }));
721
723
  await writeFile(join(directory, "fixture.txt"), "aaab\n");
722
- const tool = makeGrepOverrideWithBackend(directory, DEFAULT_CONFIG, {});
724
+ const tool = makeGrepOverride(directory, DEFAULT_CONFIG);
723
725
  const result = await invoke(tool, "0", { pattern: "(?<=a+)b", literal: false });
724
726
  assert.equal(result.isError, undefined, JSON.stringify(reportOf(result, "grep")));
725
727
  assert.equal(grepCounts(result).matches, 1);
@@ -729,7 +731,7 @@ test("line-based grep uses context for display but never matches across CRLF", a
729
731
  const directory = await mkdtemp(join(tmpdir(), "hl-grep-lines-"));
730
732
  try {
731
733
  await writeFile(join(directory, "fixture.txt"), "alpha\r\nbeta\r\ngamma\r\n");
732
- const tool = makeGrepOverrideWithBackend(directory, DEFAULT_CONFIG, {});
734
+ const tool = makeGrepOverride(directory, DEFAULT_CONFIG);
733
735
  const context = await invoke(
734
736
  tool,
735
737
  "0",
@@ -768,7 +770,7 @@ test("multiline grep anchors CRLF spans and counts overlapping physical lines on
768
770
  try {
769
771
  const file = join(directory, "fixture.txt");
770
772
  await writeFile(file, "alpha\r\nbeta\r\ngamma\r\n");
771
- const tool = makeGrepOverrideWithBackend(directory, DEFAULT_CONFIG, {});
773
+ const tool = makeGrepOverride(directory, DEFAULT_CONFIG);
772
774
  const regex = await invoke(
773
775
  tool,
774
776
  "0",
@@ -843,7 +845,7 @@ test("multiline grep anchors CRLF spans and counts overlapping physical lines on
843
845
  await invoke(
844
846
  edit,
845
847
  "0",
846
- { path: file, edits: [{ action: "replace", anchor, body: ["updated"] }] },
848
+ { path: file, steps: [{ action: "replace", anchor, lines: ["updated"] }] },
847
849
  undefined,
848
850
  undefined,
849
851
  );
@@ -858,7 +860,7 @@ test("multiline grep preserves BOM and standalone CR while normalizing CRLF", as
858
860
  try {
859
861
  const file = join(directory, "fixture.txt");
860
862
  await writeFile(file, "\uFEFFalpha\rsolo\r\nbeta\r\n");
861
- const tool = makeGrepOverrideWithBackend(directory, DEFAULT_CONFIG, {});
863
+ const tool = makeGrepOverride(directory, DEFAULT_CONFIG);
862
864
  const result = await invoke(
863
865
  tool,
864
866
  "0",
@@ -887,7 +889,7 @@ test("multiline grep anchors empty lines and line-start zero-width matches", asy
887
889
  try {
888
890
  const file = join(directory, "fixture.txt");
889
891
  await writeFile(file, "alpha\r\n\r\nbeta\r\n");
890
- const tool = makeGrepOverrideWithBackend(directory, DEFAULT_CONFIG, {});
892
+ const tool = makeGrepOverride(directory, DEFAULT_CONFIG);
891
893
  const span = await invoke(
892
894
  tool,
893
895
  "0",
@@ -918,7 +920,7 @@ test("multiline zero-width EOF stays on the last existing physical line", {
918
920
  const directory = await mkdtemp(join(tmpdir(), "hl-grep-multiline-eof-"));
919
921
  try {
920
922
  const file = join(directory, "fixture.txt");
921
- const tool = makeGrepOverrideWithBackend(directory, DEFAULT_CONFIG, {});
923
+ const tool = makeGrepOverride(directory, DEFAULT_CONFIG);
922
924
  for (const content of ["last line", "last line\n"]) {
923
925
  await writeFile(file, content);
924
926
  const result = await invoke(
@@ -947,7 +949,7 @@ test("files and count modes aggregate only matching lines inside the limit", asy
947
949
  const second = join(directory, "b.txt");
948
950
  await writeFile(first, "needle needle\nneedle\n");
949
951
  await writeFile(second, "needle\n");
950
- const tool = makeGrepOverrideWithBackend(directory, DEFAULT_CONFIG, {});
952
+ const tool = makeGrepOverride(directory, DEFAULT_CONFIG);
951
953
  const query = { literal: true, pattern: "needle", path: [first, second], limit: 1 };
952
954
  const files = await invoke(
953
955
  tool,
@@ -994,7 +996,7 @@ test("real rg accepts wildcard-only regexes and preserves limits and literal mod
994
996
  const directory = await mkdtemp(join(tmpdir(), "hl-grep-wildcard-"));
995
997
  try {
996
998
  await writeFile(join(directory, "fixture.txt"), "first\n\n.*\n");
997
- const tool = makeGrepOverrideWithBackend(directory, DEFAULT_CONFIG, {});
999
+ const tool = makeGrepOverride(directory, DEFAULT_CONFIG);
998
1000
  for (const [pattern, expected] of [
999
1001
  ["[\\w.*]*", 3],
1000
1002
  ["^[\\w.*]+$", 2],
@@ -1053,7 +1055,7 @@ test("tools share physical lines and anchors across text representations", async
1053
1055
  });
1054
1056
  assert.equal(await readFile(file, "utf8"), before);
1055
1057
  const read = await call(makeReadOverride(directory, DEFAULT_CONFIG), { path: file });
1056
- const grep = await call(makeGrepOverrideWithBackend(directory, DEFAULT_CONFIG, {}), {
1058
+ const grep = await call(makeGrepOverride(directory, DEFAULT_CONFIG), {
1057
1059
  literal: true,
1058
1060
  path: file,
1059
1061
  pattern: "old",
@@ -1064,7 +1066,7 @@ test("tools share physical lines and anchors across text representations", async
1064
1066
  const anchor = rows(grep)[1].split("│")[0];
1065
1067
  const edit = await call(makeEditOverride(directory, DEFAULT_CONFIG), {
1066
1068
  path: file,
1067
- edits: [{ action: "replace", anchor, body: ["new"] }],
1069
+ steps: [{ action: "replace", anchor, lines: ["new"] }],
1068
1070
  });
1069
1071
  assert.equal(await readFile(file, "utf8"), before.replace("old", "new"));
1070
1072
  assert.match(edit.details.diff, /^-2 old/m);
@@ -1087,7 +1089,7 @@ test("long-line previews preserve full-line anchors across literal and JavaScrip
1087
1089
  const long = "😀界".repeat(220) + "NEEDLE" + "tail".repeat(200);
1088
1090
  const context = "x" + "😀".repeat(400);
1089
1091
  await writeFile(join(directory, "long.txt"), `${long}\r\nfollow\r\n${context}\r\n`);
1090
- const tool = makeGrepOverrideWithBackend(directory, DEFAULT_CONFIG, {});
1092
+ const tool = makeGrepOverride(directory, DEFAULT_CONFIG);
1091
1093
  for (const params of [
1092
1094
  { literal: true, pattern: "NEEDLE" },
1093
1095
  { pattern: ["NEEDLE", "tail"], literal: true },
@@ -1127,7 +1129,7 @@ test("all text tools share logical CRLF matching, anchors, and mutation separato
1127
1129
  const before = "\uFEFFhead\r\nalpha\r\nbeta\nstand\rCR\r\r\nlast";
1128
1130
  const write = makeWriteOverride(directory);
1129
1131
  const read = makeReadOverride(directory, DEFAULT_CONFIG);
1130
- const grep = makeGrepOverrideWithBackend(directory, DEFAULT_CONFIG, {});
1132
+ const grep = makeGrepOverride(directory, DEFAULT_CONFIG);
1131
1133
  await invoke(write, "write", { path, content: before, mode: "create" }, undefined, undefined, {
1132
1134
  cwd: directory,
1133
1135
  } as ExtensionContext);
@@ -1193,12 +1195,12 @@ test("all text tools share logical CRLF matching, anchors, and mutation separato
1193
1195
  "edit",
1194
1196
  {
1195
1197
  path,
1196
- edits: [
1198
+ steps: [
1197
1199
  {
1198
1200
  action: "replace",
1199
1201
  anchor: rows[1].split("│")[0],
1200
1202
  end: rows[2].split("│")[0],
1201
- body: ["A", "B", "C"],
1203
+ lines: ["A", "B", "C"],
1202
1204
  },
1203
1205
  ],
1204
1206
  },
@@ -1269,7 +1271,7 @@ test("visible source escapes remain readable and searchable while real CRLF stay
1269
1271
  );
1270
1272
  assert.ok(read.content[0].type === "text");
1271
1273
  assert.ok(read.content[0].text.includes(String.raw`const eol = "\r\n";`));
1272
- const grep = makeGrepOverrideWithBackend(directory, DEFAULT_CONFIG, {});
1274
+ const grep = makeGrepOverride(directory, DEFAULT_CONFIG);
1273
1275
  for (const query of [
1274
1276
  { pattern: String.raw`\r\n`, literal: true },
1275
1277
  { pattern: String.raw`\\r\\n`, literal: false },
@@ -1311,7 +1313,7 @@ test("grep retains original paths and ignores unmatched invalid UTF-8 across man
1311
1313
  Array.from({ length: 70 }, (_, i) => writeFile(join(directory, `file ${i}.txt`), "--\r\n")),
1312
1314
  );
1313
1315
  await writeFile(join(directory, "invalid.txt"), Buffer.from([0xc3, 0x28]));
1314
- const grep = makeGrepOverrideWithBackend(directory, DEFAULT_CONFIG, {});
1316
+ const grep = makeGrepOverride(directory, DEFAULT_CONFIG);
1315
1317
  const result = await invoke(
1316
1318
  grep,
1317
1319
  "grep",
@@ -1340,7 +1342,7 @@ test("NUL files are silently skipped across search scopes and output modes", asy
1340
1342
  ]);
1341
1343
  await writeFile(binary, source);
1342
1344
  await writeFile(join(directory, "valid.txt"), "needle\n");
1343
- const grep = makeGrepOverrideWithBackend(directory, DEFAULT_CONFIG, {});
1345
+ const grep = makeGrepOverride(directory, DEFAULT_CONFIG);
1344
1346
  for (const outputMode of ["content", "files", "count"] as const) {
1345
1347
  for (const multiline of [false, true]) {
1346
1348
  const skipped = await invoke(
@@ -1374,7 +1376,7 @@ test("NUL files are silently skipped across search scopes and output modes", asy
1374
1376
  test("invalid UTF-8 matches use plain previews while valid files retain edit anchors", async () => {
1375
1377
  const directory = await mkdtemp(join(tmpdir(), "hl-grep-preview-"));
1376
1378
  try {
1377
- const grep = makeGrepOverrideWithBackend(directory, DEFAULT_CONFIG, {});
1379
+ const grep = makeGrepOverride(directory, DEFAULT_CONFIG);
1378
1380
  const invalid = join(directory, "invalid.txt");
1379
1381
  for (const separator of ["\n", "\r\n"]) {
1380
1382
  const source = Buffer.concat([
@@ -1451,7 +1453,7 @@ test("grep paths with input shorthand or literal separators still edit the searc
1451
1453
  await mkdir(dirname(otherFile), { recursive: true });
1452
1454
  await writeFile(file, "needle\n");
1453
1455
  await writeFile(otherFile, "needle\n");
1454
- const grep = makeGrepOverrideWithBackend(directory, DEFAULT_CONFIG, {});
1456
+ const grep = makeGrepOverride(directory, DEFAULT_CONFIG);
1455
1457
  let content = "";
1456
1458
  let returnedPath = "";
1457
1459
  for (const outputMode of ["content", "files", "count"] as const) {
@@ -1476,7 +1478,7 @@ test("grep paths with input shorthand or literal separators still edit the searc
1476
1478
  assert.ok(anchor);
1477
1479
  await invoke(makeEditOverride(directory, DEFAULT_CONFIG), "edit", {
1478
1480
  path: returnedPath,
1479
- edits: [{ action: "replace", anchor, body: ["updated"] }],
1481
+ steps: [{ action: "replace", anchor, lines: ["updated"] }],
1480
1482
  });
1481
1483
  assert.equal(await readFile(file, "utf8"), "updated\n");
1482
1484
  assert.equal(await readFile(otherFile, "utf8"), "needle\n");
@@ -1495,7 +1497,7 @@ test("literal LF and CRLF queries match original valid and invalid UTF-8 files a
1495
1497
  join(directory, "invalid.txt"),
1496
1498
  Buffer.concat([Buffer.from("alpha\r\nbeta\r\n"), Buffer.from([0xff])]),
1497
1499
  );
1498
- const grep = makeGrepOverrideWithBackend(directory, DEFAULT_CONFIG, {});
1500
+ const grep = makeGrepOverride(directory, DEFAULT_CONFIG);
1499
1501
  for (const outputMode of ["content", "files", "count"] as const) {
1500
1502
  await t.test(outputMode, async () => {
1501
1503
  const result = await invoke(grep, "crlf", {
@@ -1,16 +1,17 @@
1
+ import { makeMockGrep } from "../pi/grep-rg.testing.ts";
1
2
  import assert from "node:assert/strict";
2
3
  import { mkdtemp, rm, truncate, writeFile } from "node:fs/promises";
3
4
  import { tmpdir } from "node:os";
4
5
  import { join } from "node:path";
5
6
  import { test } from "node:test";
6
7
  import { formatByteSize } from "../pi/budgets.ts";
7
- import { DEFAULT_CONFIG } from "../pi/config.ts";
8
- import { MAX_MULTILINE_SEARCH_BYTES } from "../pi/grep-search.ts";
9
- import { MAX_UNNARROWED_SCAN_BYTES } from "../pi/grep-candidates.ts";
10
- import { makeGrepOverrideWithBackend } from "../pi/grep-tool.ts";
8
+ const { DEFAULT_CONFIG, makeGrepOverride } = await import("../pi/tool-factories.testing.ts");
9
+ const MAX_MULTILINE_SEARCH_BYTES = 64 * 1024 * 1024;
10
+ const { MAX_UNNARROWED_SCAN_BYTES } = await import("../pi/grep-candidates.ts");
11
+
11
12
  import { OUTCOME_NEXT } from "../pi/report-schema.ts";
12
13
  import { reportOf } from "../pi/report.ts";
13
- import { grepCounts } from "../pi/grep-output.testing.ts";
14
+ const { grepCounts } = await import("../pi/grep-output.testing.ts");
14
15
  import { callTool } from "../pi/tool-call.testing.ts";
15
16
 
16
17
  test("repeated all-file candidates → count each file once toward the scan budget", async (t) => {
@@ -22,7 +23,7 @@ test("repeated all-file candidates → count each file once toward the scan budg
22
23
  await truncate(padding, MAX_MULTILINE_SEARCH_BYTES);
23
24
  await writeFile(fixture, "ab\n");
24
25
  const repeats = Math.ceil(MAX_UNNARROWED_SCAN_BYTES / MAX_MULTILINE_SEARCH_BYTES);
25
- const result = await callTool(makeGrepOverrideWithBackend(directory, DEFAULT_CONFIG, {}), {
26
+ const result = await callTool(makeGrepOverride(directory, DEFAULT_CONFIG), {
26
27
  path: [...Array<string>(repeats).fill(padding), fixture],
27
28
  pattern: ".",
28
29
  literal: false,
@@ -69,7 +70,7 @@ test("all-file candidates exceed the scan budget → stop listing and retain sca
69
70
  await writeFile(fixture, scenario.source);
70
71
  const offered: string[] = [];
71
72
  let stopped = false;
72
- const tool = makeGrepOverrideWithBackend(directory, DEFAULT_CONFIG, {
73
+ const tool = makeMockGrep(directory, DEFAULT_CONFIG, {
73
74
  runRgLines: async () => assert.fail("multiline candidates must use file listing"),
74
75
  runRgPaths: async (_args, _signal, onFile) => {
75
76
  for (const path of paths) {
@@ -92,7 +93,6 @@ test("all-file candidates exceed the scan budget → stop listing and retain sca
92
93
  assert.deepEqual(offered, [fixture, ...padding, blocked]);
93
94
  const report = reportOf(result, "grep");
94
95
  assert.ok(report);
95
- assert.equal(report.scanned, "all");
96
96
  assert.equal(report.scanLimit, formatByteSize(MAX_UNNARROWED_SCAN_BYTES));
97
97
  if (scenario.stderr) {
98
98
  assert.equal(result.isError, true);
@@ -1,14 +1,15 @@
1
+ import { searchWithMockRg } from "../pi/grep-rg.testing.ts";
1
2
  import assert from "node:assert/strict";
2
3
  import { mkdtemp, rm, writeFile } from "node:fs/promises";
3
4
  import { tmpdir } from "node:os";
4
5
  import { join, resolve } from "node:path";
5
6
  import { test } from "node:test";
6
7
  import { searchText, type GrepQuery } from "../core/search.ts";
7
- import { searchFiles, type GrepFileMatch } from "../pi/grep-search.ts";
8
+ import type { GrepFileMatch } from "../pi/grep-search.ts";
8
9
  import { runRgLines, runRgPaths } from "../pi/rg-process.ts";
9
- import { candidateArgs } from "../pi/grep-candidates.ts";
10
+ import { fileCandidateArgs } from "../pi/grep-rg.testing.ts";
10
11
  import { lineCandidatePatterns } from "../pi/rg-regex.ts";
11
- import { extractPrefilter } from "../core/search-analysis.ts";
12
+
12
13
  import { REGEX_TRANSLATION_CORPUS } from "../testing/regex-translation-corpus.ts";
13
14
  import { unsupportedByHost } from "../testing/regex-host.testing.ts";
14
15
 
@@ -70,7 +71,7 @@ test("upstream regex witnesses × LF/CRLF/malformed bytes → sound candidates,
70
71
  inputs.push({ bytes, filePath });
71
72
  }
72
73
  const candidates = new Map<string, readonly number[] | undefined>();
73
- const result = await searchFiles({
74
+ const result = await searchWithMockRg({
74
75
  backend: {
75
76
  runRgPaths: async () => assert.fail("unexpected file fallback"),
76
77
  runRgLines: (args, signal, maxLines, onFile) =>
@@ -131,7 +132,7 @@ test("real rg AND/OR file prefilter → broad candidates retain exact JS results
131
132
  };
132
133
  const candidates: string[] = [];
133
134
  const listing = await runRgPaths(
134
- [...candidateArgs(extractPrefilter(query)), "--null", "--", directory],
135
+ [...(await fileCandidateArgs(query)), "--null", "--", directory],
135
136
  AbortSignal.timeout(timeoutMs),
136
137
  (path) => {
137
138
  candidates.push(resolve(path));
@@ -141,7 +142,7 @@ test("real rg AND/OR file prefilter → broad candidates retain exact JS results
141
142
  assert.equal(listing.code, 0);
142
143
  assert.equal(listing.stderr, "");
143
144
  assert.deepEqual(candidates.sort(), [paths[0], paths[1], paths[2], paths[3], paths[4]].sort());
144
- const result = await searchFiles({
145
+ const result = await searchWithMockRg({
145
146
  backend: { runRgPaths, runRgLines },
146
147
  scope: { globs: [], searchPaths: [directory] },
147
148
  query,
@@ -169,7 +170,7 @@ test("oversized line translation → file prefilter fallback preserves JS result
169
170
  const path = join(directory, "long.txt");
170
171
  await writeFile(path, pattern);
171
172
  let filePasses = 0;
172
- const result = await searchFiles({
173
+ const result = await searchWithMockRg({
173
174
  backend: {
174
175
  runRgPaths: (...args) => {
175
176
  filePasses++;
@@ -3,11 +3,11 @@ import assert from "node:assert/strict";
3
3
  import { mkdtemp, open, rm, writeFile } from "node:fs/promises";
4
4
  import { tmpdir } from "node:os";
5
5
  import { join } from "node:path";
6
- import { makeReadOverride } from "../pi/read-tool.ts";
7
- import { makeGrepOverrideWithBackend } from "../pi/grep-tool.ts";
6
+ import { makeReadOverride } from "../pi/tool-factories.testing.ts";
7
+ import { makeGrepOverride } from "../pi/tool-factories.testing.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
+ import { DEFAULT_CONFIG } from "../pi/tool-factories.testing.ts";
11
11
 
12
12
  const call = (tool: any, params: any) => callTool(tool, params, { toolCallId: "large-text" });
13
13
 
@@ -15,7 +15,7 @@ test("read and line-based grep retain anchors on LF and CRLF files over 100 MiB"
15
15
  const directory = await mkdtemp(join(tmpdir(), "hashline-large-text-"));
16
16
  try {
17
17
  const read = makeReadOverride(directory, DEFAULT_CONFIG);
18
- const grep = makeGrepOverrideWithBackend(directory, DEFAULT_CONFIG, {});
18
+ const grep = makeGrepOverride(directory, DEFAULT_CONFIG);
19
19
  for (const ending of ["\n", "\r\n"]) {
20
20
  const path = join(directory, "large.txt");
21
21
  const handle = await open(path, "w");
@@ -56,7 +56,7 @@ test("CRLF snapshots normalize terminators split across read chunks and preserve
56
56
  try {
57
57
  const path = join(directory, "boundary.txt");
58
58
  await writeFile(path, "x".repeat(65535) + "\r\nneedle\r\nstandalone\r");
59
- const grep = makeGrepOverrideWithBackend(directory, DEFAULT_CONFIG, {});
59
+ const grep = makeGrepOverride(directory, DEFAULT_CONFIG);
60
60
  const result: any = await call(grep, {
61
61
  path,
62
62
  pattern: ["needle", "standalone\r"],
@@ -5,7 +5,7 @@ import { join } from "node:path";
5
5
  import hashlineEdit from "../index.ts";
6
6
  import { callTool } from "../pi/tool-call.testing.ts";
7
7
  import { outputBudgetsFor } from "../pi/budgets.ts";
8
- import { decodeReport, reportOf } from "../pi/report.ts";
8
+ import { reportOf } from "../pi/report.ts";
9
9
  import type { Report } from "../pi/report-schema.ts";
10
10
  import { openTestSession } from "../testing/session.testing.ts";
11
11
 
@@ -81,7 +81,7 @@ test("model capacity changes → read and grep grow and shrink without re-regist
81
81
  assert.ok(large.content[0].text.includes(text));
82
82
  await session.setModel({ ...model, id: "small", contextWindow: 65_536 });
83
83
  const smallAgain = await callTool(tool, { path }, { ctx });
84
- assert.deepEqual(reportOf(smallAgain, "read")?.lineTooLong, smallReport.lineTooLong);
84
+ assert.equal(reportOf(smallAgain, "read")?.lineTooLong, smallReport?.lineTooLong);
85
85
  const grep = session.getToolDefinition("grep");
86
86
  assert.ok(grep);
87
87
  const smallSearch = await callTool(grep, { path, pattern: "中文", literal: true }, { ctx });
@@ -111,15 +111,15 @@ test("model switches before argument preparation → rejection uses the new budg
111
111
  assert.ok(prepare);
112
112
  const properties: unknown = Reflect.get(tool.parameters, "properties");
113
113
  assert.ok(properties && typeof properties === "object");
114
- const edits: unknown = Reflect.get(properties, "edits");
115
- assert.ok(edits && typeof edits === "object");
116
- const maxEdits: unknown = Reflect.get(edits, "maxItems");
114
+ const steps: unknown = Reflect.get(properties, "steps");
115
+ assert.ok(steps && typeof steps === "object");
116
+ const maxEdits: unknown = Reflect.get(steps, "maxItems");
117
117
  assert.ok(typeof maxEdits === "number");
118
118
  const args = {
119
119
  path: "never-opened.txt",
120
- edits: Array.from({ length: maxEdits }, () => ({
120
+ steps: Array.from({ length: maxEdits }, () => ({
121
121
  action: "append",
122
- body: Array(4).fill("\ud800"),
122
+ lines: Array(4).fill("\ud800"),
123
123
  })),
124
124
  };
125
125
  const reports: Report[] = [];
@@ -134,9 +134,9 @@ test("model switches before argument preparation → rejection uses the new budg
134
134
  assert.ok(error instanceof Error);
135
135
  const budget = outputBudgetsFor(contextWindow);
136
136
  assert.ok(Buffer.byteLength(error.message) <= budget.blockBytes);
137
- const report = decodeReport(error.message, "edit");
137
+ const report = reportOf({ content: [{ type: "text", text: error.message }] }, "edit");
138
138
  assert.ok(report?.issues);
139
- assert.equal(report.issues.length + (report.omittedIssues ?? 0), args.edits.length * 4);
139
+ assert.equal(report.issues.length + (report.omittedIssues ?? 0), args.steps.length * 4);
140
140
  reports.push(report);
141
141
  return true;
142
142
  },