@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
@@ -4,7 +4,8 @@
4
4
  * so it travels as the thrown message only. Oversized issues are omitted whole.
5
5
  */
6
6
  import type { OutputBudgets } from "./budgets.ts";
7
- import { boundedText, renderReport, type ReportText } from "./report.ts";
7
+ import { renderReport, type ReportText } from "./report.ts";
8
+ import { boundedText } from "./report-cause.ts";
8
9
  import type { ArgumentIssue, FailureReport } from "./report-schema.ts";
9
10
 
10
11
  type ArgumentRejection = ReportText<Extract<FailureReport, { error: "INVALID_ARGUMENTS" }>>;
@@ -1,12 +1,13 @@
1
1
  import assert from "node:assert/strict";
2
2
  import { test } from "node:test";
3
- import { makeEditOverride } from "./edit-tool.ts";
4
- import { makeReadOverride } from "./read-tool.ts";
5
- import { makeGrepOverride } from "./grep-tool.ts";
6
- import { makeWriteOverride } from "./write-tool.ts";
7
- import { makeReplaceTool } from "./replace-tool.ts";
8
- import { DEFAULT_CONFIG } from "./config.ts";
9
- import { DEFAULT_OUTPUT_BUDGETS, outputBudgetsFor } from "./budgets.ts";
3
+ import { makeEditOverride } from "./tool-factories.testing.ts";
4
+ import { makeReadOverride } from "./tool-factories.testing.ts";
5
+ import { makeGrepOverride } from "./tool-factories.testing.ts";
6
+ import { makeWriteOverride } from "./tool-factories.testing.ts";
7
+ import { makeReplaceTool } from "./tool-factories.testing.ts";
8
+ import { DEFAULT_CONFIG } from "./tool-factories.testing.ts";
9
+ import { outputBudgetsFor } from "./budgets.ts";
10
+ import { DEFAULT_OUTPUT_BUDGETS } from "./tool-factories.testing.ts";
10
11
  import { callTool } from "./tool-call.testing.ts";
11
12
  import { argumentError } from "./argument-error.testing.ts";
12
13
 
@@ -16,7 +17,7 @@ test("all tools receive invalid arguments → return field diagnostics without a
16
17
  const cases = [
17
18
  {
18
19
  tool: makeEditOverride(cwd, DEFAULT_CONFIG),
19
- args: { path: "unused", edits: [{ action: "append", body: [] }] },
20
+ args: { path: "unused", steps: [{ action: "append", lines: [] }] },
20
21
  },
21
22
  { tool: makeReadOverride(cwd, DEFAULT_CONFIG), args: { path: "unused", limit: 0 } },
22
23
  { tool: makeGrepOverride(cwd, DEFAULT_CONFIG), args: { pattern: "", literal: true } },
@@ -53,12 +54,12 @@ test("all tools receive invalid arguments → return field diagnostics without a
53
54
  test("Pi prepares a singleton operation → semantic and schema paths resolve to the prepared array", async () => {
54
55
  const tool = makeEditOverride(cwd, DEFAULT_CONFIG);
55
56
  await assert.rejects(
56
- callTool(tool, { path: "unused", edits: { action: "insert_after", body: [] } }),
57
+ callTool(tool, { path: "unused", steps: { action: "insert_after", lines: [] } }),
57
58
  (error: unknown) => {
58
59
  const result = argumentError(error);
59
60
  assert.deepEqual(
60
61
  result.issues.map((issue) => issue.field),
61
- ["edits[0].anchor", "edits[0].body"],
62
+ ["steps[0].anchor", "steps[0].lines"],
62
63
  );
63
64
  return true;
64
65
  },
@@ -80,19 +81,19 @@ test("Pi prepares a singleton operation → semantic and schema paths resolve to
80
81
  test("JSON diagnostics exceed the budget → retain whole opening and closing issues and label omissions", async () => {
81
82
  const budget = outputBudgetsFor(4096);
82
83
  const tool = makeEditOverride(cwd, DEFAULT_CONFIG, undefined, () => budget);
83
- const maxItems: unknown = Reflect.get(tool.parameters.properties.edits, "maxItems");
84
+ const maxItems: unknown = Reflect.get(tool.parameters.properties.steps, "maxItems");
84
85
  assert.ok(typeof maxItems === "number");
85
- const edits = Array.from({ length: maxItems }, () => ({
86
+ const steps = Array.from({ length: maxItems }, () => ({
86
87
  action: "append",
87
- body: [],
88
+ lines: [],
88
89
  }));
89
- await assert.rejects(callTool(tool, { path: "", edits }), (error: unknown) => {
90
+ await assert.rejects(callTool(tool, { path: "", steps }), (error: unknown) => {
90
91
  const result = argumentError(error);
91
92
  assert.ok(error instanceof Error && Buffer.byteLength(error.message) <= budget.blockBytes);
92
- assert.equal(result.issues[0].field, "edits[0].body");
93
+ assert.equal(result.issues[0].field, "steps[0].lines");
93
94
  assert.equal(result.issues.at(-1)?.field, "path");
94
95
  assert.ok((result.omittedIssues ?? 0) > 0);
95
- assert.equal(result.issues.length + (result.omittedIssues ?? 0), edits.length + 1);
96
+ assert.equal(result.issues.length + (result.omittedIssues ?? 0), steps.length + 1);
96
97
  return true;
97
98
  });
98
99
  });
@@ -102,7 +103,7 @@ test("a reason contains an oversized anchor → keep its cause and recovery inst
102
103
  await assert.rejects(
103
104
  callTool(makeEditOverride(cwd, DEFAULT_CONFIG), {
104
105
  path: "unused",
105
- edits: [{ action: "delete", anchor }],
106
+ steps: [{ action: "delete", anchor }],
106
107
  }),
107
108
  (error: unknown) => {
108
109
  const result = argumentError(error);
@@ -111,7 +112,7 @@ test("a reason contains an oversized anchor → keep its cause and recovery inst
111
112
  Buffer.byteLength(error.message) <= DEFAULT_OUTPUT_BUDGETS.blockBytes,
112
113
  );
113
114
  assert.equal(result.issues.length, 1);
114
- assert.equal(result.issues[0].field, "edits[0].anchor");
115
+ assert.equal(result.issues[0].field, "steps[0].anchor");
115
116
  assert.match(result.issues[0].reason, /^line number/);
116
117
  assert.match(result.issues[0].fix ?? "", /Copy a complete.*latest tool result/);
117
118
  assert.doesNotMatch(result.issues[0].reason, /Read|grep|Copy/);