@criogaid/pi-hashline-edit 0.13.0 → 0.15.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 (152) hide show
  1. package/README.md +18 -12
  2. package/README.zh-CN.md +18 -12
  3. package/package.json +8 -1
  4. package/src/core/AGENTS.md +3 -1
  5. package/src/core/apply.ts +110 -117
  6. package/src/core/character-set.ts +2 -3
  7. package/src/core/copy-span.ts +15 -0
  8. package/src/core/errors.ts +24 -9
  9. package/src/core/lines.ts +71 -17
  10. package/src/core/ranges.ts +5 -4
  11. package/src/core/replace-schema.ts +3 -1
  12. package/src/core/replace.ts +50 -29
  13. package/src/core/search-analysis.ts +21 -22
  14. package/src/core/search.ts +15 -32
  15. package/src/core/types.ts +3 -0
  16. package/src/index.ts +47 -39
  17. package/src/pi/AGENTS.md +30 -19
  18. package/src/pi/action-fusion.ts +284 -211
  19. package/src/pi/argument-diagnostics.ts +50 -37
  20. package/src/pi/argument-error.ts +2 -2
  21. package/src/pi/argument-validation.ts +163 -66
  22. package/src/pi/budgets.ts +12 -0
  23. package/src/pi/diagnostic-buffer.ts +12 -11
  24. package/src/pi/edit-tool.ts +138 -115
  25. package/src/pi/error-text.ts +10 -2
  26. package/src/pi/failure-context.ts +24 -37
  27. package/src/pi/file-commit.ts +131 -164
  28. package/src/pi/file-read.ts +122 -31
  29. package/src/pi/fusion-arguments.ts +214 -0
  30. package/src/pi/fusion-card.ts +102 -60
  31. package/src/pi/grep-candidates.ts +35 -22
  32. package/src/pi/grep-output.ts +197 -190
  33. package/src/pi/grep-render.ts +22 -13
  34. package/src/pi/grep-reread.ts +7 -6
  35. package/src/pi/grep-scope.ts +31 -16
  36. package/src/pi/grep-search.ts +56 -47
  37. package/src/pi/grep-tool.ts +35 -33
  38. package/src/pi/grep-worker.ts +3 -4
  39. package/src/pi/mutation-diff.ts +238 -0
  40. package/src/pi/mutation-result.ts +102 -79
  41. package/src/pi/mutation-runner.ts +107 -84
  42. package/src/pi/native-bash.ts +41 -0
  43. package/src/pi/path.ts +59 -6
  44. package/src/pi/read-tool.ts +173 -138
  45. package/src/pi/regex-worker.ts +14 -8
  46. package/src/pi/render.ts +101 -54
  47. package/src/pi/replace-regex.ts +1 -1
  48. package/src/pi/replace-tool.ts +14 -7
  49. package/src/pi/report-cause.ts +34 -17
  50. package/src/pi/report-schema.ts +184 -85
  51. package/src/pi/report.ts +133 -64
  52. package/src/pi/rg-process.ts +68 -48
  53. package/src/pi/schema.ts +4 -0
  54. package/src/pi/text-stream.ts +81 -87
  55. package/src/pi/workspace-cwd.js +2 -0
  56. package/src/pi/workspace.ts +46 -0
  57. package/src/pi/write-tool.ts +19 -13
  58. package/src/core/apply.test.ts +0 -644
  59. package/src/core/case-fold.test.ts +0 -35
  60. package/src/core/character-set.test.ts +0 -97
  61. package/src/core/errors.test.ts +0 -39
  62. package/src/core/hash.test.ts +0 -64
  63. package/src/core/lines.test.ts +0 -63
  64. package/src/core/ranges.test.ts +0 -123
  65. package/src/core/replace.test.ts +0 -187
  66. package/src/core/search-analysis.test.ts +0 -210
  67. package/src/core/search-matrix.test.ts +0 -64
  68. package/src/core/search-matrix.testing.ts +0 -171
  69. package/src/core/search.test.ts +0 -132
  70. package/src/core/text.test.ts +0 -52
  71. package/src/integration/config-registration.test.ts +0 -291
  72. package/src/integration/fusion-dispatch.test.ts +0 -320
  73. package/src/integration/grep-errors.test.ts +0 -81
  74. package/src/integration/grep-flags.test.ts +0 -76
  75. package/src/integration/grep-js-completeness.test.ts +0 -278
  76. package/src/integration/grep-line-candidates.test.ts +0 -201
  77. package/src/integration/grep-matrix.test.ts +0 -118
  78. package/src/integration/grep-order.test.ts +0 -78
  79. package/src/integration/grep-path-matrix.test.ts +0 -128
  80. package/src/integration/grep-prefilter-coverage.test.ts +0 -204
  81. package/src/integration/grep-process-limits.test.ts +0 -122
  82. package/src/integration/grep-regex.test.ts +0 -412
  83. package/src/integration/grep-rg.test.ts +0 -1659
  84. package/src/integration/grep-scan-budget.test.ts +0 -111
  85. package/src/integration/grep-translation.test.ts +0 -199
  86. package/src/integration/large-text.test.ts +0 -70
  87. package/src/integration/model-budget-lifecycle.test.ts +0 -186
  88. package/src/integration/mutation-file-types.test.ts +0 -30
  89. package/src/integration/mutation-file-types.testing.ts +0 -33
  90. package/src/integration/npm-package.test.ts +0 -19
  91. package/src/integration/npm-package.testing.ts +0 -243
  92. package/src/integration/publication-read-changes.test.ts +0 -454
  93. package/src/integration/read-changes.test.ts +0 -98
  94. package/src/integration/replace-package.test.ts +0 -22
  95. package/src/integration/replace-package.testing.ts +0 -36
  96. package/src/integration/replace-worker-boundary.test.ts +0 -127
  97. package/src/integration/report-replay.test.ts +0 -91
  98. package/src/integration/utf8-errors.test.ts +0 -46
  99. package/src/pi/action-fusion.test.ts +0 -659
  100. package/src/pi/action-fusion.testing.ts +0 -38
  101. package/src/pi/anchor-format.test.ts +0 -124
  102. package/src/pi/argument-error.testing.ts +0 -46
  103. package/src/pi/argument-format.test.ts +0 -196
  104. package/src/pi/argument-validation.test.ts +0 -1007
  105. package/src/pi/codemode.test.ts +0 -101
  106. package/src/pi/config.test.ts +0 -204
  107. package/src/pi/diagnostic-buffer.test.ts +0 -115
  108. package/src/pi/directory-sync.test.ts +0 -57
  109. package/src/pi/execute.test.ts +0 -1257
  110. package/src/pi/extension-loading.test.ts +0 -14
  111. package/src/pi/extension-loading.testing.ts +0 -3
  112. package/src/pi/failure-context.test.ts +0 -370
  113. package/src/pi/failure-path.test.ts +0 -289
  114. package/src/pi/file-commit.test.ts +0 -628
  115. package/src/pi/file-read.test.ts +0 -29
  116. package/src/pi/file-snapshot.test.ts +0 -22
  117. package/src/pi/fusion-card-interaction.test.ts +0 -143
  118. package/src/pi/fusion-card.test.ts +0 -353
  119. package/src/pi/grep-candidates.test.ts +0 -26
  120. package/src/pi/grep-matrix.test.ts +0 -68
  121. package/src/pi/grep-order.test.ts +0 -447
  122. package/src/pi/grep-output.testing.ts +0 -24
  123. package/src/pi/grep-rg.testing.ts +0 -73
  124. package/src/pi/grep.test.ts +0 -1670
  125. package/src/pi/model-budgets.test.ts +0 -96
  126. package/src/pi/mutation-outcome.testing.ts +0 -20
  127. package/src/pi/mutation-result.test.ts +0 -96
  128. package/src/pi/output-budgets.test.ts +0 -221
  129. package/src/pi/pi.test.ts +0 -158
  130. package/src/pi/read-delegation.test.ts +0 -119
  131. package/src/pi/read.test.ts +0 -735
  132. package/src/pi/regex-worker.test.ts +0 -42
  133. package/src/pi/registration.test.ts +0 -549
  134. package/src/pi/render.test.ts +0 -841
  135. package/src/pi/replace.test.ts +0 -634
  136. package/src/pi/report-failure.testing.ts +0 -27
  137. package/src/pi/report.test.ts +0 -533
  138. package/src/pi/result-safety.test.ts +0 -597
  139. package/src/pi/rg-process.test.ts +0 -133
  140. package/src/pi/rg-regex.test.ts +0 -40
  141. package/src/pi/text-stream.test.ts +0 -281
  142. package/src/pi/tool-call.testing.ts +0 -61
  143. package/src/pi/tool-factories.testing.ts +0 -59
  144. package/src/pi/write.test.ts +0 -256
  145. package/src/testing/extension-loader.testing.ts +0 -24
  146. package/src/testing/installation.testing.ts +0 -77
  147. package/src/testing/process.testing.ts +0 -33
  148. package/src/testing/regex-host.testing.ts +0 -20
  149. package/src/testing/regex-translation-corpus.ts +0 -267
  150. package/src/testing/rg-line-listing.fixture.mjs +0 -7
  151. package/src/testing/run-tests.ts +0 -47
  152. package/src/testing/session.testing.ts +0 -127
@@ -1,119 +0,0 @@
1
- import assert from "node:assert/strict";
2
- import { mkdir, mkdtemp, rm, writeFile } from "node:fs/promises";
3
- import { tmpdir } from "node:os";
4
- import { join } from "node:path";
5
- import { pathToFileURL } from "node:url";
6
- import { test } from "node:test";
7
- import * as pi from "@earendil-works/pi-coding-agent";
8
- import { callTool } from "./tool-call.testing.ts";
9
- import { loadConfig } from "./config.ts";
10
- import { outputBudgetsFor } from "./budgets.ts";
11
- import { reportOf } from "./report.ts";
12
-
13
- test("read delegation → only images and NUL use native read on the canonical target", async (t) => {
14
- const dir = await mkdtemp(join(tmpdir(), "hashline-read-delegation-"));
15
- t.after(() => rm(dir, { recursive: true, force: true }));
16
- type Native = ReturnType<typeof pi.createReadToolDefinition>;
17
- let beforeNative: (() => Promise<void>) | undefined;
18
- const execute = t.mock.fn(async (native: Native, ...args: Parameters<Native["execute"]>) => {
19
- await beforeNative?.();
20
- return native.execute(...args);
21
- });
22
- t.mock.module("@earendil-works/pi-coding-agent", {
23
- namedExports: {
24
- ...pi,
25
- createReadToolDefinition: (...args: Parameters<typeof pi.createReadToolDefinition>) => {
26
- const native = pi.createReadToolDefinition(...args);
27
- return {
28
- ...native,
29
- execute: (...args: Parameters<Native["execute"]>) => execute(native, ...args),
30
- };
31
- },
32
- },
33
- });
34
- const { makeReadOverride } = await import("./read-tool.ts");
35
- const tool = makeReadOverride({
36
- cwd: dir,
37
- config: loadConfig(dir),
38
- budgets: () => outputBudgetsFor(undefined),
39
- });
40
- const image = Buffer.from("R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7", "base64");
41
- await writeFile(join(dir, "image.gif"), image);
42
- await writeFile(join(dir, "nul.txt"), "first\0\nsecond\n");
43
- await writeFile(join(dir, "invalid.txt"), Buffer.from([0xff]));
44
- await mkdir(join(dir, "directory"));
45
- for (const [path, error, native] of [
46
- ["image.gif", undefined, true],
47
- ["nul.txt", undefined, true],
48
- ["missing.txt", "PATH_NOT_FOUND", false],
49
- ["directory", "NOT_REGULAR_FILE", false],
50
- ["nul.txt/child", process.platform === "win32" ? "PATH_NOT_FOUND" : "FILESYSTEM_ERROR", false],
51
- ["invalid.txt", "UNSUPPORTED_ENCODING", false],
52
- ] as const) {
53
- await t.test(path, async () => {
54
- const before = execute.mock.callCount();
55
- const params = { path, offset: 1, limit: 1 };
56
- const result = await callTool(tool, { ...params, anchors: false });
57
- assert.equal(execute.mock.callCount(), before + Number(native));
58
- assert.equal(result.isError === true, error !== undefined);
59
- assert.equal(reportOf(result, "read")?.error, error);
60
- if (native) {
61
- assert.deepEqual(execute.mock.calls.at(-1)?.arguments[2], {
62
- ...params,
63
- path: join(dir, path),
64
- });
65
- assert.equal(result.details?.nativeRead, true);
66
- }
67
- });
68
- }
69
-
70
- await t.test(
71
- "encoded Unicode path and different context cwd → delegates the exact file",
72
- async () => {
73
- const other = join(dir, "other");
74
- await mkdir(other);
75
- for (const [name, bytes] of [
76
- ["image\u202f.gif", image],
77
- ["nul\u202f.txt", Buffer.from("exact\0target")],
78
- ] as const) {
79
- await writeFile(join(dir, name), bytes);
80
- await writeFile(join(dir, name.replace("\u202f", " ")), "wrong normalized target");
81
- const result = await callTool(
82
- tool,
83
- { path: pathToFileURL(join(dir, name)).href },
84
- { ctx: { cwd: other } },
85
- );
86
- assert.equal(result.isError, undefined);
87
- assert.equal(result.details?.nativeRead, true);
88
- if (name.endsWith(".gif"))
89
- assert.ok(result.content.some((block) => block.type === "image"));
90
- else
91
- assert.equal(
92
- result.content[0]?.type === "text" && result.content[0].text,
93
- bytes.toString(),
94
- );
95
- }
96
- const result = await callTool(tool, { path: "@nul.txt" }, { ctx: { cwd: other } });
97
- assert.equal(result.isError, undefined);
98
- assert.equal(
99
- result.content[0]?.type === "text" && result.content[0].text,
100
- "first\0\nsecond\n",
101
- );
102
- },
103
- );
104
-
105
- await t.test(
106
- "canonical target disappears before native read → does not open a filename variant",
107
- async () => {
108
- const target = join(dir, "shot 9 AM.txt");
109
- await writeFile(target, "original\0target");
110
- await writeFile(join(dir, "shot 9\u202fAM.txt"), "wrong variant");
111
- beforeNative = () => rm(target);
112
- const result = await callTool(tool, { path: "shot 9 AM.txt" });
113
- beforeNative = undefined;
114
- assert.equal(result.isError, true);
115
- assert.equal(reportOf(result, "read")?.error, "PATH_NOT_FOUND");
116
- assert.deepEqual(reportOf(result, "read")?.missing, [target]);
117
- },
118
- );
119
- });