@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.
- package/README.md +76 -220
- package/README.zh-CN.md +166 -0
- package/package.json +2 -1
- package/src/core/AGENTS.md +1 -1
- package/src/core/apply.test.ts +171 -133
- package/src/core/apply.ts +34 -31
- package/src/core/case-fold.test.ts +11 -7
- package/src/core/case-fold.ts +2 -6
- package/src/core/character-set.ts +14 -0
- package/src/core/hash.test.ts +1 -25
- package/src/core/hash.ts +0 -5
- package/src/core/lines.ts +25 -7
- package/src/core/ranges.test.ts +49 -9
- package/src/core/ranges.ts +15 -4
- package/src/core/regex.ts +36 -6
- package/src/core/replace-schema.ts +18 -11
- package/src/core/replace.test.ts +90 -0
- package/src/core/replace.ts +6 -5
- package/src/core/search-analysis.test.ts +9 -0
- package/src/core/search-analysis.ts +35 -31
- package/src/core/search.ts +1 -1
- package/src/core/types.ts +6 -8
- package/src/index.ts +2 -4
- package/src/integration/config-registration.test.ts +18 -10
- package/src/integration/fusion-dispatch.test.ts +41 -22
- package/src/integration/grep-flags.test.ts +6 -13
- package/src/integration/grep-js-completeness.test.ts +41 -31
- package/src/integration/grep-order.test.ts +78 -0
- package/src/integration/grep-path-matrix.test.ts +4 -3
- package/src/integration/grep-regex.test.ts +13 -16
- package/src/integration/grep-rg.test.ts +132 -92
- package/src/integration/grep-scan-budget.test.ts +27 -5
- package/src/integration/large-text.test.ts +4 -5
- package/src/integration/model-budget-lifecycle.test.ts +26 -8
- package/src/integration/mutation-file-types.test.ts +0 -1
- package/src/integration/mutation-file-types.testing.ts +2 -2
- package/src/integration/npm-package.testing.ts +7 -33
- package/src/integration/publication-read-changes.test.ts +60 -28
- package/src/integration/replace-package.testing.ts +4 -1
- package/src/integration/replace-worker-boundary.test.ts +34 -24
- package/src/integration/report-replay.test.ts +3 -3
- package/src/integration/utf8-errors.test.ts +3 -3
- package/src/pi/AGENTS.md +13 -14
- package/src/pi/action-fusion.test.ts +75 -220
- package/src/pi/action-fusion.ts +37 -74
- package/src/pi/anchor-format.test.ts +16 -0
- package/src/pi/anchor-format.ts +7 -3
- package/src/pi/argument-diagnostics.ts +35 -186
- package/src/pi/argument-error.testing.ts +7 -4
- package/src/pi/argument-error.ts +5 -7
- package/src/pi/argument-format.test.ts +25 -38
- package/src/pi/argument-validation.test.ts +446 -420
- package/src/pi/argument-validation.ts +4 -5
- package/src/pi/budgets.ts +5 -7
- package/src/pi/config.test.ts +15 -5
- package/src/pi/config.ts +6 -6
- package/src/pi/diagnostic-buffer.test.ts +2 -3
- package/src/pi/diagnostic-buffer.ts +2 -2
- package/src/pi/edit-tool.ts +175 -121
- package/src/pi/execute.test.ts +170 -227
- package/src/pi/failure-context.test.ts +61 -16
- package/src/pi/failure-context.ts +13 -10
- package/src/pi/failure-path.test.ts +115 -50
- package/src/pi/file-commit.test.ts +30 -46
- package/src/pi/file-commit.ts +11 -40
- package/src/pi/file-revision.ts +25 -0
- package/src/pi/fusion-card-interaction.test.ts +143 -0
- package/src/pi/fusion-card.test.ts +193 -37
- package/src/pi/fusion-card.ts +186 -116
- package/src/pi/grep-candidates.ts +25 -27
- package/src/pi/grep-matrix.test.ts +1 -1
- package/src/pi/grep-order.test.ts +323 -0
- package/src/pi/grep-output.testing.ts +24 -0
- package/src/pi/grep-output.ts +62 -69
- package/src/pi/grep-render.ts +4 -1
- package/src/pi/grep-scope.ts +1 -1
- package/src/pi/grep-search.ts +85 -56
- package/src/pi/grep-tool.ts +17 -48
- package/src/pi/grep.test.ts +271 -170
- package/src/pi/mutation-outcome.testing.ts +2 -3
- package/src/pi/mutation-result.test.ts +26 -19
- package/src/pi/mutation-result.ts +25 -40
- package/src/pi/mutation-runner.ts +9 -17
- package/src/pi/output-budgets.test.ts +27 -18
- package/src/pi/path.ts +3 -1
- package/src/pi/pi.test.ts +7 -6
- package/src/pi/read-tool.ts +32 -80
- package/src/pi/read.test.ts +145 -92
- package/src/pi/regex-worker-contract.ts +5 -23
- package/src/pi/regex-worker.ts +4 -10
- package/src/pi/registration.test.ts +106 -67
- package/src/pi/render.test.ts +239 -109
- package/src/pi/render.ts +42 -22
- package/src/pi/replace-regex.ts +3 -5
- package/src/pi/replace-tool.ts +29 -27
- package/src/pi/replace-worker-contract.ts +3 -12
- package/src/pi/replace.test.ts +144 -226
- package/src/pi/report-cause.ts +23 -19
- package/src/pi/report-failure.testing.ts +2 -2
- package/src/pi/report-schema.ts +60 -45
- package/src/pi/report.test.ts +138 -71
- package/src/pi/report.ts +40 -43
- package/src/pi/result-safety.test.ts +186 -131
- package/src/pi/rg-process.test.ts +36 -10
- package/src/pi/rg-process.ts +9 -3
- package/src/pi/rg-regex.test.ts +17 -0
- package/src/pi/rg-regex.ts +28 -22
- package/src/pi/text-stream.test.ts +35 -36
- package/src/pi/text-stream.ts +14 -14
- package/src/pi/tool-call.testing.ts +17 -7
- package/src/pi/write-tool.ts +9 -11
- package/src/pi/write.test.ts +43 -75
- package/src/testing/regex-translation-corpus.ts +16 -0
- package/src/testing/rg-line-listing.fixture.mjs +1 -1
- package/src/integration/forget-grep.test.ts +0 -148
- package/src/pi/forget-tool.ts +0 -367
- package/src/pi/forget.test.ts +0 -630
- package/src/pi/forget.testing.ts +0 -201
package/src/pi/argument-error.ts
CHANGED
|
@@ -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 {
|
|
7
|
-
import { boundedText, renderReport } from "./report.ts";
|
|
8
|
-
import type { ArgumentIssue, FailureReport
|
|
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
|
|
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
|
|
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: [{
|
|
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: {
|
|
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].
|
|
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
|
-
|
|
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
|
|
93
|
-
|
|
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
|
-
|
|
98
|
-
(error
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
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: [{
|
|
105
|
+
edits: [{ action: "delete", anchor }],
|
|
119
106
|
}),
|
|
120
107
|
(error: unknown) => {
|
|
121
108
|
const result = argumentError(error);
|