@criogaid/pi-hashline-edit 0.7.0 → 0.9.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 (118) hide show
  1. package/README.md +76 -220
  2. package/README.zh-CN.md +166 -0
  3. package/package.json +2 -1
  4. package/src/core/AGENTS.md +1 -1
  5. package/src/core/apply.test.ts +171 -133
  6. package/src/core/apply.ts +34 -31
  7. package/src/core/case-fold.test.ts +11 -7
  8. package/src/core/case-fold.ts +2 -6
  9. package/src/core/character-set.ts +14 -0
  10. package/src/core/hash.test.ts +1 -25
  11. package/src/core/hash.ts +0 -5
  12. package/src/core/lines.ts +25 -7
  13. package/src/core/ranges.test.ts +49 -9
  14. package/src/core/ranges.ts +15 -4
  15. package/src/core/regex.ts +36 -6
  16. package/src/core/replace-schema.ts +18 -11
  17. package/src/core/replace.test.ts +90 -0
  18. package/src/core/replace.ts +6 -5
  19. package/src/core/search-analysis.test.ts +9 -0
  20. package/src/core/search-analysis.ts +35 -31
  21. package/src/core/search.ts +1 -1
  22. package/src/core/types.ts +6 -8
  23. package/src/index.ts +2 -4
  24. package/src/integration/config-registration.test.ts +18 -10
  25. package/src/integration/fusion-dispatch.test.ts +41 -22
  26. package/src/integration/grep-flags.test.ts +6 -13
  27. package/src/integration/grep-js-completeness.test.ts +41 -31
  28. package/src/integration/grep-order.test.ts +78 -0
  29. package/src/integration/grep-path-matrix.test.ts +4 -3
  30. package/src/integration/grep-regex.test.ts +13 -16
  31. package/src/integration/grep-rg.test.ts +132 -92
  32. package/src/integration/grep-scan-budget.test.ts +27 -5
  33. package/src/integration/large-text.test.ts +4 -5
  34. package/src/integration/model-budget-lifecycle.test.ts +26 -8
  35. package/src/integration/mutation-file-types.test.ts +0 -1
  36. package/src/integration/mutation-file-types.testing.ts +2 -2
  37. package/src/integration/npm-package.testing.ts +7 -33
  38. package/src/integration/publication-read-changes.test.ts +60 -28
  39. package/src/integration/replace-package.testing.ts +4 -1
  40. package/src/integration/replace-worker-boundary.test.ts +34 -24
  41. package/src/integration/report-replay.test.ts +3 -3
  42. package/src/integration/utf8-errors.test.ts +3 -3
  43. package/src/pi/AGENTS.md +13 -14
  44. package/src/pi/action-fusion.test.ts +75 -220
  45. package/src/pi/action-fusion.ts +37 -74
  46. package/src/pi/anchor-format.test.ts +16 -0
  47. package/src/pi/anchor-format.ts +7 -3
  48. package/src/pi/argument-diagnostics.ts +35 -186
  49. package/src/pi/argument-error.testing.ts +7 -4
  50. package/src/pi/argument-error.ts +5 -7
  51. package/src/pi/argument-format.test.ts +25 -38
  52. package/src/pi/argument-validation.test.ts +446 -420
  53. package/src/pi/argument-validation.ts +4 -5
  54. package/src/pi/budgets.ts +5 -7
  55. package/src/pi/config.test.ts +15 -5
  56. package/src/pi/config.ts +6 -6
  57. package/src/pi/diagnostic-buffer.test.ts +2 -3
  58. package/src/pi/diagnostic-buffer.ts +2 -2
  59. package/src/pi/edit-tool.ts +175 -121
  60. package/src/pi/execute.test.ts +170 -227
  61. package/src/pi/failure-context.test.ts +61 -16
  62. package/src/pi/failure-context.ts +13 -10
  63. package/src/pi/failure-path.test.ts +115 -50
  64. package/src/pi/file-commit.test.ts +30 -46
  65. package/src/pi/file-commit.ts +11 -40
  66. package/src/pi/file-revision.ts +25 -0
  67. package/src/pi/fusion-card-interaction.test.ts +143 -0
  68. package/src/pi/fusion-card.test.ts +193 -37
  69. package/src/pi/fusion-card.ts +186 -116
  70. package/src/pi/grep-candidates.ts +25 -27
  71. package/src/pi/grep-matrix.test.ts +1 -1
  72. package/src/pi/grep-order.test.ts +323 -0
  73. package/src/pi/grep-output.testing.ts +24 -0
  74. package/src/pi/grep-output.ts +62 -69
  75. package/src/pi/grep-render.ts +4 -1
  76. package/src/pi/grep-scope.ts +1 -1
  77. package/src/pi/grep-search.ts +85 -56
  78. package/src/pi/grep-tool.ts +17 -48
  79. package/src/pi/grep.test.ts +271 -170
  80. package/src/pi/mutation-outcome.testing.ts +2 -3
  81. package/src/pi/mutation-result.test.ts +26 -19
  82. package/src/pi/mutation-result.ts +25 -40
  83. package/src/pi/mutation-runner.ts +9 -17
  84. package/src/pi/output-budgets.test.ts +27 -18
  85. package/src/pi/path.ts +3 -1
  86. package/src/pi/pi.test.ts +7 -6
  87. package/src/pi/read-tool.ts +32 -80
  88. package/src/pi/read.test.ts +145 -92
  89. package/src/pi/regex-worker-contract.ts +5 -23
  90. package/src/pi/regex-worker.ts +4 -10
  91. package/src/pi/registration.test.ts +106 -67
  92. package/src/pi/render.test.ts +239 -109
  93. package/src/pi/render.ts +42 -22
  94. package/src/pi/replace-regex.ts +3 -5
  95. package/src/pi/replace-tool.ts +29 -27
  96. package/src/pi/replace-worker-contract.ts +3 -12
  97. package/src/pi/replace.test.ts +144 -226
  98. package/src/pi/report-cause.ts +23 -19
  99. package/src/pi/report-failure.testing.ts +2 -2
  100. package/src/pi/report-schema.ts +60 -45
  101. package/src/pi/report.test.ts +138 -71
  102. package/src/pi/report.ts +40 -43
  103. package/src/pi/result-safety.test.ts +186 -131
  104. package/src/pi/rg-process.test.ts +36 -10
  105. package/src/pi/rg-process.ts +9 -3
  106. package/src/pi/rg-regex.test.ts +17 -0
  107. package/src/pi/rg-regex.ts +28 -22
  108. package/src/pi/text-stream.test.ts +35 -36
  109. package/src/pi/text-stream.ts +14 -14
  110. package/src/pi/tool-call.testing.ts +17 -7
  111. package/src/pi/write-tool.ts +9 -11
  112. package/src/pi/write.test.ts +43 -75
  113. package/src/testing/regex-translation-corpus.ts +16 -0
  114. package/src/testing/rg-line-listing.fixture.mjs +1 -1
  115. package/src/integration/forget-grep.test.ts +0 -148
  116. package/src/pi/forget-tool.ts +0 -367
  117. package/src/pi/forget.test.ts +0 -630
  118. package/src/pi/forget.testing.ts +0 -201
@@ -3,11 +3,11 @@
3
3
  * with field issues within one byte budget. Pi raises it before execution,
4
4
  * so it travels as the thrown message only. Oversized issues are omitted whole.
5
5
  */
6
- import { DEFAULT_OUTPUT_BUDGETS, type OutputBudgets } from "./budgets.ts";
7
- import { boundedText, renderReport } from "./report.ts";
8
- import type { ArgumentIssue, FailureReport, ReportTool } from "./report-schema.ts";
6
+ import type { OutputBudgets } from "./budgets.ts";
7
+ import { boundedText, renderReport, type ReportText } from "./report.ts";
8
+ import type { ArgumentIssue, FailureReport } from "./report-schema.ts";
9
9
 
10
- type ArgumentRejection = Extract<FailureReport, { error: "INVALID_ARGUMENTS" }>;
10
+ type ArgumentRejection = ReportText<Extract<FailureReport, { error: "INVALID_ARGUMENTS" }>>;
11
11
 
12
12
  /**
13
13
  * State each distinct fix once, on the first reported issue that needs it:
@@ -29,10 +29,9 @@ function encode(report: ArgumentRejection): string {
29
29
 
30
30
  /** Encode actionable field diagnostics without repeating the call's arguments. */
31
31
  export function formatArgumentError(
32
- tool: ReportTool,
33
32
  issues: readonly ArgumentIssue[],
34
33
  schemaLimited: boolean,
35
- budget: OutputBudgets = DEFAULT_OUTPUT_BUDGETS,
34
+ budget: OutputBudgets,
36
35
  ): string {
37
36
  const boundedIssues = issues.map(({ field, reason, fix }) => ({
38
37
  field,
@@ -41,7 +40,6 @@ export function formatArgumentError(
41
40
  }));
42
41
  const base = {
43
42
  error: "INVALID_ARGUMENTS" as const,
44
- tool,
45
43
  ...(schemaLimited ? { schemaLimited: true as const } : {}),
46
44
  };
47
45
  const fits = (text: string) => Buffer.byteLength(text) <= budget.blockBytes;
@@ -1,41 +1,30 @@
1
1
  import assert from "node:assert/strict";
2
2
  import { test } from "node:test";
3
- import { openTestSession } from "../testing/session.testing.ts";
4
- import { registerForgetTool } from "./forget-tool.ts";
5
3
  import { makeEditOverride } from "./edit-tool.ts";
6
4
  import { makeReadOverride } from "./read-tool.ts";
7
5
  import { makeGrepOverride } from "./grep-tool.ts";
8
6
  import { makeWriteOverride } from "./write-tool.ts";
9
7
  import { makeReplaceTool } from "./replace-tool.ts";
10
8
  import { DEFAULT_CONFIG } from "./config.ts";
11
- import { DEFAULT_OUTPUT_BUDGETS } from "./budgets.ts";
9
+ import { DEFAULT_OUTPUT_BUDGETS, outputBudgetsFor } from "./budgets.ts";
12
10
  import { callTool } from "./tool-call.testing.ts";
13
11
  import { argumentError } from "./argument-error.testing.ts";
14
12
 
15
13
  const cwd = process.cwd();
16
14
 
17
- test("all six tools receive invalid arguments → return field diagnostics without an argument copy or execution", async (t) => {
18
- const { session } = await openTestSession(t, {
19
- tools: ["forget"],
20
- configure(pi) {
21
- registerForgetTool(pi);
22
- },
23
- });
24
- const forget = session.getToolDefinition("forget");
25
- assert.ok(forget);
15
+ test("all tools receive invalid arguments → return field diagnostics without an argument copy or execution", async () => {
26
16
  const cases = [
27
17
  {
28
18
  tool: makeEditOverride(cwd, DEFAULT_CONFIG),
29
- args: { path: "unused", edits: [{ op: "append", body: [] }] },
19
+ args: { path: "unused", edits: [{ action: "append", body: [] }] },
30
20
  },
31
21
  { tool: makeReadOverride(cwd, DEFAULT_CONFIG), args: { path: "unused", limit: 0 } },
32
22
  { tool: makeGrepOverride(cwd, DEFAULT_CONFIG), args: { pattern: "", literal: true } },
33
23
  { tool: makeWriteOverride(cwd), args: { path: "unused", content: "bad\0", mode: "create" } },
34
24
  {
35
25
  tool: makeReplaceTool(cwd, DEFAULT_CONFIG),
36
- args: { path: "unused", replacements: [{ find: "a", replace: "bad\0" }] },
26
+ args: { path: "unused", replacements: [{ literal: true, find: "a", replace: "bad\0" }] },
37
27
  },
38
- { tool: forget, args: { ids: [] } },
39
28
  ];
40
29
  for (const { tool, args } of cases) {
41
30
  let executed = false;
@@ -52,10 +41,8 @@ test("all six tools receive invalid arguments → return field diagnostics witho
52
41
  ),
53
42
  (error: unknown) => {
54
43
  const result = argumentError(error);
55
- assert.equal(result.tool, tool.name);
56
44
  assert.ok(result.issues.length > 0);
57
45
  assert.equal(Object.hasOwn(result, "arguments"), false);
58
- assert.equal(Object.hasOwn(result, "argumentsOmitted"), false);
59
46
  return true;
60
47
  },
61
48
  );
@@ -66,12 +53,12 @@ test("all six tools receive invalid arguments → return field diagnostics witho
66
53
  test("Pi prepares a singleton operation → semantic and schema paths resolve to the prepared array", async () => {
67
54
  const tool = makeEditOverride(cwd, DEFAULT_CONFIG);
68
55
  await assert.rejects(
69
- callTool(tool, { path: "unused", edits: { op: "insert_after", body: [] } }),
56
+ callTool(tool, { path: "unused", edits: { action: "insert_after", body: [] } }),
70
57
  (error: unknown) => {
71
58
  const result = argumentError(error);
72
59
  assert.deepEqual(
73
60
  result.issues.map((issue) => issue.field),
74
- ["edits[0].body", "edits[0].anchor"],
61
+ ["edits[0].anchor", "edits[0].body"],
75
62
  );
76
63
  return true;
77
64
  },
@@ -79,35 +66,35 @@ test("Pi prepares a singleton operation → semantic and schema paths resolve to
79
66
  await assert.rejects(
80
67
  callTool(makeReadOverride(cwd, DEFAULT_CONFIG), { path: "unused", offset: "1", limit: 0 }),
81
68
  (error: unknown) => {
69
+ const result = argumentError(error);
82
70
  assert.deepEqual(
83
- argumentError(error).issues.map((issue) => issue.field),
71
+ result.issues.map((issue) => issue.field),
84
72
  ["limit"],
85
73
  );
74
+ assert.equal(result.schemaLimited, undefined);
86
75
  return true;
87
76
  },
88
77
  );
89
78
  });
90
79
 
91
80
  test("JSON diagnostics exceed the budget → retain whole opening and closing issues and label omissions", async () => {
92
- const edits = Array.from({ length: DEFAULT_OUTPUT_BUDGETS.blockBytes }, () => ({
93
- op: "append",
81
+ const budget = outputBudgetsFor(4096);
82
+ const tool = makeEditOverride(cwd, DEFAULT_CONFIG, undefined, () => budget);
83
+ const maxItems: unknown = Reflect.get(tool.parameters.properties.edits, "maxItems");
84
+ assert.ok(typeof maxItems === "number");
85
+ const edits = Array.from({ length: maxItems }, () => ({
86
+ action: "append",
94
87
  body: [],
95
88
  }));
96
- await assert.rejects(
97
- callTool(makeEditOverride(cwd, DEFAULT_CONFIG), { path: "", edits }),
98
- (error: unknown) => {
99
- const result = argumentError(error);
100
- assert.ok(
101
- error instanceof Error &&
102
- Buffer.byteLength(error.message) <= DEFAULT_OUTPUT_BUDGETS.blockBytes,
103
- );
104
- assert.equal(result.issues[0].field, "edits[0].body");
105
- assert.equal(result.issues.at(-1)?.field, "path");
106
- assert.ok((result.omittedIssues ?? 0) > 0);
107
- assert.equal(result.issues.length + (result.omittedIssues ?? 0), edits.length + 1);
108
- return true;
109
- },
110
- );
89
+ await assert.rejects(callTool(tool, { path: "", edits }), (error: unknown) => {
90
+ const result = argumentError(error);
91
+ 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.at(-1)?.field, "path");
94
+ assert.ok((result.omittedIssues ?? 0) > 0);
95
+ assert.equal(result.issues.length + (result.omittedIssues ?? 0), edits.length + 1);
96
+ return true;
97
+ });
111
98
  });
112
99
 
113
100
  test("a reason contains an oversized anchor → keep its cause and recovery instruction inside valid JSON", async () => {
@@ -115,7 +102,7 @@ test("a reason contains an oversized anchor → keep its cause and recovery inst
115
102
  await assert.rejects(
116
103
  callTool(makeEditOverride(cwd, DEFAULT_CONFIG), {
117
104
  path: "unused",
118
- edits: [{ op: "delete", anchor }],
105
+ edits: [{ action: "delete", anchor }],
119
106
  }),
120
107
  (error: unknown) => {
121
108
  const result = argumentError(error);