@criogaid/pi-hashline-edit 0.9.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 (131) hide show
  1. package/README.md +12 -12
  2. package/README.zh-CN.md +12 -12
  3. package/THIRD_PARTY_NOTICES.md +0 -6
  4. package/package.json +1 -1
  5. package/src/core/AGENTS.md +4 -5
  6. package/src/core/apply.test.ts +96 -271
  7. package/src/core/apply.ts +62 -169
  8. package/src/core/case-fold.ts +8 -67
  9. package/src/core/character-set.test.ts +2 -3
  10. package/src/core/character-set.ts +5 -5
  11. package/src/core/errors.test.ts +23 -7
  12. package/src/core/errors.ts +32 -5
  13. package/src/core/hash.test.ts +8 -16
  14. package/src/core/hash.ts +3 -23
  15. package/src/core/lines.ts +2 -4
  16. package/src/core/ranges.test.ts +2 -1
  17. package/src/core/ranges.ts +1 -1
  18. package/src/core/regex.ts +3 -4
  19. package/src/core/replace.test.ts +47 -1
  20. package/src/core/replace.ts +19 -13
  21. package/src/core/search-analysis.test.ts +24 -27
  22. package/src/core/search-analysis.ts +34 -65
  23. package/src/core/search-matrix.testing.ts +0 -2
  24. package/src/core/search.ts +1 -1
  25. package/src/core/text.test.ts +5 -5
  26. package/src/core/text.ts +5 -12
  27. package/src/core/types.ts +8 -44
  28. package/src/index.ts +8 -8
  29. package/src/integration/config-registration.test.ts +8 -10
  30. package/src/integration/fusion-dispatch.test.ts +4 -7
  31. package/src/integration/grep-errors.test.ts +3 -3
  32. package/src/integration/grep-flags.test.ts +5 -19
  33. package/src/integration/grep-js-completeness.test.ts +45 -18
  34. package/src/integration/grep-line-candidates.test.ts +7 -10
  35. package/src/integration/grep-matrix.test.ts +6 -9
  36. package/src/integration/grep-order.test.ts +4 -4
  37. package/src/integration/grep-path-matrix.test.ts +10 -9
  38. package/src/integration/grep-prefilter-coverage.test.ts +5 -8
  39. package/src/integration/grep-process-limits.test.ts +76 -0
  40. package/src/integration/grep-regex.test.ts +10 -10
  41. package/src/integration/grep-rg.test.ts +166 -66
  42. package/src/integration/grep-scan-budget.test.ts +9 -9
  43. package/src/integration/grep-translation.test.ts +18 -32
  44. package/src/integration/large-text.test.ts +6 -52
  45. package/src/integration/model-budget-lifecycle.test.ts +10 -9
  46. package/src/integration/mutation-file-types.testing.ts +4 -4
  47. package/src/integration/npm-package.testing.ts +3 -3
  48. package/src/integration/publication-read-changes.test.ts +161 -83
  49. package/src/integration/read-changes.test.ts +4 -4
  50. package/src/integration/replace-worker-boundary.test.ts +22 -12
  51. package/src/integration/report-replay.test.ts +23 -26
  52. package/src/integration/utf8-errors.test.ts +4 -4
  53. package/src/pi/AGENTS.md +18 -17
  54. package/src/pi/action-fusion.test.ts +241 -353
  55. package/src/pi/action-fusion.testing.ts +38 -0
  56. package/src/pi/action-fusion.ts +150 -125
  57. package/src/pi/anchor-format.test.ts +9 -9
  58. package/src/pi/anchor-format.ts +6 -8
  59. package/src/pi/argument-diagnostics.ts +25 -28
  60. package/src/pi/argument-error.ts +2 -1
  61. package/src/pi/argument-format.test.ts +19 -18
  62. package/src/pi/argument-validation.test.ts +334 -283
  63. package/src/pi/argument-validation.ts +5 -8
  64. package/src/pi/budgets.ts +6 -8
  65. package/src/pi/codemode.test.ts +7 -2
  66. package/src/pi/config.test.ts +7 -3
  67. package/src/pi/config.ts +12 -9
  68. package/src/pi/diagnostic-buffer.test.ts +34 -13
  69. package/src/pi/diagnostic-buffer.ts +1 -2
  70. package/src/pi/directory-sync.test.ts +0 -1
  71. package/src/pi/edit-tool.ts +86 -211
  72. package/src/pi/error-text.ts +10 -9
  73. package/src/pi/execute.test.ts +249 -345
  74. package/src/pi/failure-context.test.ts +146 -127
  75. package/src/pi/failure-context.ts +45 -94
  76. package/src/pi/failure-path.test.ts +182 -155
  77. package/src/pi/file-commit.test.ts +156 -71
  78. package/src/pi/file-commit.ts +126 -146
  79. package/src/pi/file-snapshot.test.ts +3 -5
  80. package/src/pi/fusion-card.test.ts +26 -22
  81. package/src/pi/fusion-card.ts +16 -24
  82. package/src/pi/grep-candidates.test.ts +19 -120
  83. package/src/pi/grep-candidates.ts +25 -76
  84. package/src/pi/grep-matrix.test.ts +5 -5
  85. package/src/pi/grep-order.test.ts +16 -15
  86. package/src/pi/grep-output.ts +94 -107
  87. package/src/pi/grep-render.ts +1 -1
  88. package/src/pi/grep-reread.ts +97 -0
  89. package/src/pi/grep-rg.testing.ts +70 -0
  90. package/src/pi/grep-scope.ts +41 -43
  91. package/src/pi/grep-search.ts +27 -39
  92. package/src/pi/grep-tool.ts +63 -106
  93. package/src/pi/grep.test.ts +177 -156
  94. package/src/pi/model-budgets.test.ts +27 -24
  95. package/src/pi/model-budgets.ts +6 -38
  96. package/src/pi/mutation-outcome.testing.ts +0 -1
  97. package/src/pi/mutation-result.test.ts +44 -35
  98. package/src/pi/mutation-result.ts +52 -21
  99. package/src/pi/mutation-runner.ts +134 -74
  100. package/src/pi/output-budgets.test.ts +86 -42
  101. package/src/pi/path.ts +1 -1
  102. package/src/pi/pi.test.ts +18 -13
  103. package/src/pi/read-tool.ts +18 -23
  104. package/src/pi/read.test.ts +22 -41
  105. package/src/pi/regex-worker-contract.ts +3 -13
  106. package/src/pi/regex-worker.ts +1 -10
  107. package/src/pi/registration.test.ts +85 -51
  108. package/src/pi/render.test.ts +88 -59
  109. package/src/pi/render.ts +64 -65
  110. package/src/pi/replace-regex.ts +14 -2
  111. package/src/pi/replace-tool.ts +22 -94
  112. package/src/pi/replace-worker.ts +1 -1
  113. package/src/pi/replace.test.ts +53 -38
  114. package/src/pi/report-cause.ts +3 -8
  115. package/src/pi/report-failure.testing.ts +10 -3
  116. package/src/pi/report-schema.ts +251 -148
  117. package/src/pi/report.test.ts +215 -67
  118. package/src/pi/report.ts +50 -98
  119. package/src/pi/result-safety.test.ts +241 -247
  120. package/src/pi/rg-process.test.ts +77 -63
  121. package/src/pi/rg-process.ts +53 -75
  122. package/src/pi/rg-regex.ts +40 -400
  123. package/src/pi/schema.ts +35 -0
  124. package/src/pi/text-stream.test.ts +0 -21
  125. package/src/pi/text-stream.ts +14 -21
  126. package/src/pi/tool-factories.testing.ts +59 -0
  127. package/src/pi/write-tool.ts +36 -71
  128. package/src/pi/write.test.ts +31 -34
  129. package/src/testing/regex-translation-corpus.ts +12 -12
  130. package/src/testing/run-tests.ts +1 -1
  131. package/src/pi/replace-worker-contract.ts +0 -10
@@ -3,7 +3,6 @@ import { mkdtemp, rm, writeFile } from "node:fs/promises";
3
3
  import { tmpdir } from "node:os";
4
4
  import { basename, join } from "node:path";
5
5
  import { test } from "node:test";
6
- import { rgPath } from "@vscode/ripgrep";
7
6
  import { extractPrefilter, type Prefilter } from "../core/search-analysis.ts";
8
7
  import {
9
8
  acceptsNative,
@@ -13,7 +12,7 @@ import {
13
12
  } from "../core/search-matrix.testing.ts";
14
13
  import { searchText, type GrepQuery } from "../core/search.ts";
15
14
  import { runRgPaths } from "../pi/rg-process.ts";
16
- import { runCandidatePaths } from "../pi/grep-candidates.ts";
15
+ import { fileCandidateArgs } from "../pi/grep-rg.testing.ts";
17
16
 
18
17
  const syntaxCases = [
19
18
  ...MATRIX_SYNTAX,
@@ -54,6 +53,7 @@ function emptyCoverage(): Coverage {
54
53
 
55
54
  interface CandidateCase {
56
55
  readonly prefilter: Prefilter;
56
+ readonly query: GrepQuery;
57
57
  readonly required: Map<string, GrepQuery>;
58
58
  readonly contributions: Map<Coverage, number>;
59
59
  }
@@ -110,7 +110,7 @@ test("Cartesian prefilter coverage × composition × flags × bytes → real rg
110
110
  const key = JSON.stringify(prefilter);
111
111
  let group = groups.get(key);
112
112
  if (!group) {
113
- group = { prefilter, required: new Map(), contributions: new Map() };
113
+ group = { prefilter, query, required: new Map(), contributions: new Map() };
114
114
  groups.set(key, group);
115
115
  }
116
116
  let hits = 0;
@@ -140,11 +140,8 @@ test("Cartesian prefilter coverage × composition × flags × bytes → real rg
140
140
  while (next < cases.length) {
141
141
  const group = cases[next++];
142
142
  const actual = new Set<string>();
143
- const result = await runCandidatePaths(
144
- runRgPaths,
145
- rgPath,
146
- group.prefilter,
147
- ["--null", "--", directory],
143
+ const result = await runRgPaths(
144
+ [...(await fileCandidateArgs(group.query)), "--null", "--", directory],
148
145
  AbortSignal.timeout(processTimeoutMs),
149
146
  (path) => {
150
147
  actual.add(basename(path));
@@ -0,0 +1,76 @@
1
+ import assert from "node:assert/strict";
2
+ import { mkdtemp, rm, writeFile } from "node:fs/promises";
3
+ import { tmpdir } from "node:os";
4
+ import { join } from "node:path";
5
+ import { test } from "node:test";
6
+ import { DEFAULT_CONFIG } from "../pi/tool-factories.testing.ts";
7
+ import { grepCounts } from "../pi/grep-output.testing.ts";
8
+ import { makeGrepOverride } from "../pi/tool-factories.testing.ts";
9
+ import { expectToolFailure } from "../pi/report-failure.testing.ts";
10
+ import { reportOf } from "../pi/report.ts";
11
+ import { callTool } from "../pi/tool-call.testing.ts";
12
+
13
+ for (const input of ["explicit paths", "globs"] as const) {
14
+ test(`2000 ${input} exceed the Windows command line → report RIPGREP_FAILED with ENAMETOOLONG`, {
15
+ skip: process.platform !== "win32" ? "Requires the Windows command-line length limit" : false,
16
+ }, async (t) => {
17
+ const directory = await mkdtemp(join(tmpdir(), "hl-rg-launch-"));
18
+ t.after(() => rm(directory, { recursive: true, force: true }));
19
+ const file = join(directory, "needle.txt");
20
+ await writeFile(file, "needle\n");
21
+ const args =
22
+ input === "explicit paths"
23
+ ? { path: Array.from({ length: 2000 }, () => file) }
24
+ : {
25
+ path: [file],
26
+ glob: Array.from({ length: 2000 }, (_, index) => `**/needle-${index}-*.txt`),
27
+ };
28
+ await expectToolFailure(
29
+ callTool(makeGrepOverride(directory, DEFAULT_CONFIG), {
30
+ ...args,
31
+ pattern: ["needle"],
32
+ literal: true,
33
+ }),
34
+ "RIPGREP_FAILED",
35
+ (report) => assert.equal(report.cause?.code, "ENAMETOOLONG"),
36
+ );
37
+ });
38
+ }
39
+
40
+ test("multiline prefilter exceeds the rg pattern budget → scan all files and retain native matches", async (t) => {
41
+ const directory = await mkdtemp(join(tmpdir(), "hl-rg-prefilter-budget-"));
42
+ t.after(() => rm(directory, { recursive: true, force: true }));
43
+ const starts = [0x100, 0x140, 0x180, 0x1c0];
44
+ for (const start of starts)
45
+ await writeFile(join(directory, `${start}.txt`), String.fromCodePoint(start).repeat(64));
46
+ await writeFile(join(directory, "literal.txt"), "needle\n");
47
+ const tool = makeGrepOverride(directory, DEFAULT_CONFIG);
48
+ for (const count of [2, 3, 4]) {
49
+ await t.test(
50
+ `${count} large character classes → full scan finds every matching file`,
51
+ async () => {
52
+ const result = await callTool(tool, {
53
+ path: [directory],
54
+ pattern: starts
55
+ .slice(0, count)
56
+ .map(
57
+ (start) => `[${String.fromCodePoint(start)}-${String.fromCodePoint(start + 63)}]{64}`,
58
+ ),
59
+ literal: false,
60
+ multiline: true,
61
+ ignoreCase: false,
62
+ });
63
+ assert.equal(result.isError, undefined, JSON.stringify(reportOf(result, "grep")));
64
+ assert.deepEqual(grepCounts(result), { matches: count, files: count });
65
+ },
66
+ );
67
+ }
68
+ const literal = await callTool(tool, {
69
+ path: [directory],
70
+ pattern: ["needle"],
71
+ literal: true,
72
+ multiline: true,
73
+ });
74
+ assert.equal(literal.isError, undefined);
75
+ assert.deepEqual(grepCounts(literal), { matches: 1, files: 1 });
76
+ });
@@ -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],