@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.
- package/README.md +18 -12
- package/README.zh-CN.md +18 -12
- package/package.json +8 -1
- package/src/core/AGENTS.md +3 -1
- package/src/core/apply.ts +110 -117
- package/src/core/character-set.ts +2 -3
- package/src/core/copy-span.ts +15 -0
- package/src/core/errors.ts +24 -9
- package/src/core/lines.ts +71 -17
- package/src/core/ranges.ts +5 -4
- package/src/core/replace-schema.ts +3 -1
- package/src/core/replace.ts +50 -29
- package/src/core/search-analysis.ts +21 -22
- package/src/core/search.ts +15 -32
- package/src/core/types.ts +3 -0
- package/src/index.ts +47 -39
- package/src/pi/AGENTS.md +30 -19
- package/src/pi/action-fusion.ts +284 -211
- package/src/pi/argument-diagnostics.ts +50 -37
- package/src/pi/argument-error.ts +2 -2
- package/src/pi/argument-validation.ts +163 -66
- package/src/pi/budgets.ts +12 -0
- package/src/pi/diagnostic-buffer.ts +12 -11
- package/src/pi/edit-tool.ts +138 -115
- package/src/pi/error-text.ts +10 -2
- package/src/pi/failure-context.ts +24 -37
- package/src/pi/file-commit.ts +131 -164
- package/src/pi/file-read.ts +122 -31
- package/src/pi/fusion-arguments.ts +214 -0
- package/src/pi/fusion-card.ts +102 -60
- package/src/pi/grep-candidates.ts +35 -22
- package/src/pi/grep-output.ts +197 -190
- package/src/pi/grep-render.ts +22 -13
- package/src/pi/grep-reread.ts +7 -6
- package/src/pi/grep-scope.ts +31 -16
- package/src/pi/grep-search.ts +56 -47
- package/src/pi/grep-tool.ts +35 -33
- package/src/pi/grep-worker.ts +3 -4
- package/src/pi/mutation-diff.ts +238 -0
- package/src/pi/mutation-result.ts +102 -79
- package/src/pi/mutation-runner.ts +107 -84
- package/src/pi/native-bash.ts +41 -0
- package/src/pi/path.ts +59 -6
- package/src/pi/read-tool.ts +173 -138
- package/src/pi/regex-worker.ts +14 -8
- package/src/pi/render.ts +101 -54
- package/src/pi/replace-regex.ts +1 -1
- package/src/pi/replace-tool.ts +14 -7
- package/src/pi/report-cause.ts +34 -17
- package/src/pi/report-schema.ts +184 -85
- package/src/pi/report.ts +133 -64
- package/src/pi/rg-process.ts +68 -48
- package/src/pi/schema.ts +4 -0
- package/src/pi/text-stream.ts +81 -87
- package/src/pi/workspace-cwd.js +2 -0
- package/src/pi/workspace.ts +46 -0
- package/src/pi/write-tool.ts +19 -13
- package/src/core/apply.test.ts +0 -644
- package/src/core/case-fold.test.ts +0 -35
- package/src/core/character-set.test.ts +0 -97
- package/src/core/errors.test.ts +0 -39
- package/src/core/hash.test.ts +0 -64
- package/src/core/lines.test.ts +0 -63
- package/src/core/ranges.test.ts +0 -123
- package/src/core/replace.test.ts +0 -187
- package/src/core/search-analysis.test.ts +0 -210
- package/src/core/search-matrix.test.ts +0 -64
- package/src/core/search-matrix.testing.ts +0 -171
- package/src/core/search.test.ts +0 -132
- package/src/core/text.test.ts +0 -52
- package/src/integration/config-registration.test.ts +0 -291
- package/src/integration/fusion-dispatch.test.ts +0 -320
- package/src/integration/grep-errors.test.ts +0 -81
- package/src/integration/grep-flags.test.ts +0 -76
- package/src/integration/grep-js-completeness.test.ts +0 -278
- package/src/integration/grep-line-candidates.test.ts +0 -201
- package/src/integration/grep-matrix.test.ts +0 -118
- package/src/integration/grep-order.test.ts +0 -78
- package/src/integration/grep-path-matrix.test.ts +0 -128
- package/src/integration/grep-prefilter-coverage.test.ts +0 -204
- package/src/integration/grep-process-limits.test.ts +0 -122
- package/src/integration/grep-regex.test.ts +0 -412
- package/src/integration/grep-rg.test.ts +0 -1659
- package/src/integration/grep-scan-budget.test.ts +0 -111
- package/src/integration/grep-translation.test.ts +0 -199
- package/src/integration/large-text.test.ts +0 -70
- package/src/integration/model-budget-lifecycle.test.ts +0 -186
- package/src/integration/mutation-file-types.test.ts +0 -30
- package/src/integration/mutation-file-types.testing.ts +0 -33
- package/src/integration/npm-package.test.ts +0 -19
- package/src/integration/npm-package.testing.ts +0 -243
- package/src/integration/publication-read-changes.test.ts +0 -454
- package/src/integration/read-changes.test.ts +0 -98
- package/src/integration/replace-package.test.ts +0 -22
- package/src/integration/replace-package.testing.ts +0 -36
- package/src/integration/replace-worker-boundary.test.ts +0 -127
- package/src/integration/report-replay.test.ts +0 -91
- package/src/integration/utf8-errors.test.ts +0 -46
- package/src/pi/action-fusion.test.ts +0 -659
- package/src/pi/action-fusion.testing.ts +0 -38
- package/src/pi/anchor-format.test.ts +0 -124
- package/src/pi/argument-error.testing.ts +0 -46
- package/src/pi/argument-format.test.ts +0 -196
- package/src/pi/argument-validation.test.ts +0 -1007
- package/src/pi/codemode.test.ts +0 -101
- package/src/pi/config.test.ts +0 -204
- package/src/pi/diagnostic-buffer.test.ts +0 -115
- package/src/pi/directory-sync.test.ts +0 -57
- package/src/pi/execute.test.ts +0 -1257
- package/src/pi/extension-loading.test.ts +0 -14
- package/src/pi/extension-loading.testing.ts +0 -3
- package/src/pi/failure-context.test.ts +0 -370
- package/src/pi/failure-path.test.ts +0 -289
- package/src/pi/file-commit.test.ts +0 -628
- package/src/pi/file-read.test.ts +0 -29
- package/src/pi/file-snapshot.test.ts +0 -22
- package/src/pi/fusion-card-interaction.test.ts +0 -143
- package/src/pi/fusion-card.test.ts +0 -353
- package/src/pi/grep-candidates.test.ts +0 -26
- package/src/pi/grep-matrix.test.ts +0 -68
- package/src/pi/grep-order.test.ts +0 -447
- package/src/pi/grep-output.testing.ts +0 -24
- package/src/pi/grep-rg.testing.ts +0 -73
- package/src/pi/grep.test.ts +0 -1670
- package/src/pi/model-budgets.test.ts +0 -96
- package/src/pi/mutation-outcome.testing.ts +0 -20
- package/src/pi/mutation-result.test.ts +0 -96
- package/src/pi/output-budgets.test.ts +0 -221
- package/src/pi/pi.test.ts +0 -158
- package/src/pi/read-delegation.test.ts +0 -119
- package/src/pi/read.test.ts +0 -735
- package/src/pi/regex-worker.test.ts +0 -42
- package/src/pi/registration.test.ts +0 -549
- package/src/pi/render.test.ts +0 -841
- package/src/pi/replace.test.ts +0 -634
- package/src/pi/report-failure.testing.ts +0 -27
- package/src/pi/report.test.ts +0 -533
- package/src/pi/result-safety.test.ts +0 -597
- package/src/pi/rg-process.test.ts +0 -133
- package/src/pi/rg-regex.test.ts +0 -40
- package/src/pi/text-stream.test.ts +0 -281
- package/src/pi/tool-call.testing.ts +0 -61
- package/src/pi/tool-factories.testing.ts +0 -59
- package/src/pi/write.test.ts +0 -256
- package/src/testing/extension-loader.testing.ts +0 -24
- package/src/testing/installation.testing.ts +0 -77
- package/src/testing/process.testing.ts +0 -33
- package/src/testing/regex-host.testing.ts +0 -20
- package/src/testing/regex-translation-corpus.ts +0 -267
- package/src/testing/rg-line-listing.fixture.mjs +0 -7
- package/src/testing/run-tests.ts +0 -47
- 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
|
-
});
|