@criogaid/pi-hashline-edit 0.7.0 → 0.8.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 +74 -222
- package/README.zh-CN.md +162 -0
- package/package.json +2 -1
- package/src/core/AGENTS.md +1 -1
- package/src/core/apply.test.ts +172 -134
- package/src/core/apply.ts +28 -30
- 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 +41 -9
- package/src/core/ranges.ts +11 -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 +5 -7
- package/src/index.ts +2 -4
- package/src/integration/config-registration.test.ts +16 -8
- 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 +127 -87
- package/src/integration/grep-scan-budget.test.ts +27 -5
- package/src/integration/large-text.test.ts +3 -4
- package/src/integration/model-budget-lifecycle.test.ts +15 -6
- package/src/integration/mutation-file-types.test.ts +0 -1
- package/src/integration/mutation-file-types.testing.ts +1 -1
- package/src/integration/npm-package.testing.ts +6 -32
- package/src/integration/publication-read-changes.test.ts +58 -26
- 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 +2 -2
- package/src/integration/utf8-errors.test.ts +2 -2
- package/src/pi/AGENTS.md +12 -13
- package/src/pi/action-fusion.test.ts +71 -216
- 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 +1 -1
- package/src/pi/argument-error.testing.ts +7 -4
- package/src/pi/argument-error.ts +5 -7
- package/src/pi/argument-format.test.ts +5 -16
- package/src/pi/argument-validation.test.ts +59 -25
- 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 +9 -12
- package/src/pi/execute.test.ts +80 -149
- package/src/pi/failure-context.test.ts +61 -16
- package/src/pi/failure-context.ts +12 -9
- 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 +270 -169
- 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 +25 -16
- package/src/pi/path.ts +3 -1
- package/src/pi/pi.test.ts +4 -5
- 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 +54 -49
- package/src/pi/render.test.ts +196 -93
- package/src/pi/render.ts +32 -22
- package/src/pi/replace-regex.ts +3 -5
- package/src/pi/replace-tool.ts +27 -26
- 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 +55 -43
- package/src/pi/report.test.ts +138 -71
- package/src/pi/report.ts +40 -43
- package/src/pi/result-safety.test.ts +157 -117
- 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/config.test.ts
CHANGED
|
@@ -32,7 +32,6 @@ test("defaults come from the settings schema", () => {
|
|
|
32
32
|
assert.deepEqual(DEFAULT_CONFIG, {
|
|
33
33
|
enabled: true,
|
|
34
34
|
actionFusion: true,
|
|
35
|
-
forget: false,
|
|
36
35
|
hashLen: 4,
|
|
37
36
|
shiftRadius: 15,
|
|
38
37
|
read: { defaultLimit: 500, maxKiB: undefined },
|
|
@@ -56,7 +55,7 @@ test("actionFusion defaults on and honors explicit disabling", () =>
|
|
|
56
55
|
}
|
|
57
56
|
}));
|
|
58
57
|
|
|
59
|
-
test("
|
|
58
|
+
test("invalid or unknown settings → preserve valid leaves and default malformed values", () =>
|
|
60
59
|
withSettings(async (write, root) => {
|
|
61
60
|
for (const value of [3.5, -1, "4", null]) {
|
|
62
61
|
await write({ hashlineEdit: { hashLen: value, shiftRadius: value } });
|
|
@@ -73,9 +72,8 @@ test("config rejects fractional values and tolerates malformed settings shapes",
|
|
|
73
72
|
await write(rootValue);
|
|
74
73
|
assert.deepEqual(loadConfig(root), DEFAULT_CONFIG);
|
|
75
74
|
}
|
|
76
|
-
await write({ hashlineEdit: { hashLen: 8, shiftRadius: 0 } });
|
|
77
|
-
assert.
|
|
78
|
-
assert.equal(loadConfig(root).shiftRadius, 0);
|
|
75
|
+
await write({ hashlineEdit: { hashLen: 8, shiftRadius: 0, unexpected: true } });
|
|
76
|
+
assert.deepEqual(loadConfig(root), { ...DEFAULT_CONFIG, hashLen: 8, shiftRadius: 0 });
|
|
79
77
|
}));
|
|
80
78
|
|
|
81
79
|
test("tool groups resolve each setting independently", () =>
|
|
@@ -131,6 +129,18 @@ test("project settings replace global groups while absent project settings use g
|
|
|
131
129
|
assert.deepEqual(loadConfig(root), DEFAULT_CONFIG);
|
|
132
130
|
}));
|
|
133
131
|
|
|
132
|
+
test("project hashlineEdit is null → replaces global settings with defaults", () =>
|
|
133
|
+
withSettings(async (write, root, agentDir) => {
|
|
134
|
+
const globalConfig = { ...DEFAULT_CONFIG, enabled: false, hashLen: 8 };
|
|
135
|
+
await writeFile(
|
|
136
|
+
join(agentDir, "settings.json"),
|
|
137
|
+
JSON.stringify({ hashlineEdit: globalConfig }),
|
|
138
|
+
);
|
|
139
|
+
assert.deepEqual(loadConfig(root), globalConfig);
|
|
140
|
+
await write({ hashlineEdit: null });
|
|
141
|
+
assert.deepEqual(loadConfig(root), DEFAULT_CONFIG);
|
|
142
|
+
}));
|
|
143
|
+
|
|
134
144
|
test("invalid tool groups default independently without discarding valid sibling groups", () =>
|
|
135
145
|
withSettings(async (write, root) => {
|
|
136
146
|
const configured = {
|
package/src/pi/config.ts
CHANGED
|
@@ -32,7 +32,7 @@ const regexTimeoutSetting = integerSetting(
|
|
|
32
32
|
);
|
|
33
33
|
|
|
34
34
|
/** Settings schema: the single source of setting types, bounds, and defaults. */
|
|
35
|
-
|
|
35
|
+
const configSchema = Type.Object({
|
|
36
36
|
enabled: Type.Boolean({
|
|
37
37
|
default: true,
|
|
38
38
|
description:
|
|
@@ -42,10 +42,6 @@ export const configSchema = Type.Object({
|
|
|
42
42
|
default: true,
|
|
43
43
|
description: "Expose optional then_run commands after edit/replace/write.",
|
|
44
44
|
}),
|
|
45
|
-
forget: Type.Boolean({
|
|
46
|
-
default: false,
|
|
47
|
-
description: "Register forget and tag eligible read/grep results for context removal.",
|
|
48
|
-
}),
|
|
49
45
|
hashLen: integerSetting(
|
|
50
46
|
integerRange(HASH_LEN_MIN, HASH_LEN_MAX),
|
|
51
47
|
4,
|
|
@@ -131,5 +127,9 @@ function readSettings(filePath: string): Record<string, unknown> {
|
|
|
131
127
|
export function loadConfig(cwd?: string): HashlineEditConfig {
|
|
132
128
|
const globalSettings = readSettings(path.join(getAgentDir(), "settings.json"));
|
|
133
129
|
const projectSettings = cwd ? readSettings(path.join(cwd, ".pi", "settings.json")) : {};
|
|
134
|
-
|
|
130
|
+
// Any project value replaces the global one, even null or an invalid value, which yields defaults.
|
|
131
|
+
const settings = Object.hasOwn(projectSettings, "hashlineEdit")
|
|
132
|
+
? projectSettings
|
|
133
|
+
: globalSettings;
|
|
134
|
+
return resolveSetting(configSchema, settings.hashlineEdit);
|
|
135
135
|
}
|
|
@@ -46,10 +46,9 @@ test("diagnostics within the budget are unchanged", () => {
|
|
|
46
46
|
|
|
47
47
|
test("search warning aggregation retains the final cause and labels truncation", () => {
|
|
48
48
|
const { facts, payload } = assembleGrepOutput({
|
|
49
|
+
budget: DEFAULT_OUTPUT_BUDGETS,
|
|
49
50
|
formatted: {
|
|
50
|
-
blocks: ["confirmed match"],
|
|
51
|
-
linesTruncated: false,
|
|
52
|
-
invalidUtf8: [],
|
|
51
|
+
blocks: [{ lines: ["confirmed match"] }],
|
|
53
52
|
matches: 1,
|
|
54
53
|
files: 1,
|
|
55
54
|
},
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* model-facing search warnings. Retain the opening context and final cause;
|
|
4
4
|
* mark omitted text instead of silently dropping diagnostics.
|
|
5
5
|
*/
|
|
6
|
-
import {
|
|
6
|
+
import { formatByteSize } from "./budgets.ts";
|
|
7
7
|
|
|
8
8
|
/** Cut only at UTF-8 boundaries; diagnostics may contain a single oversized line. */
|
|
9
9
|
function byteSlice(text: string, maxBytes: number, tail: boolean): string {
|
|
@@ -25,7 +25,7 @@ export class DiagnosticBuffer {
|
|
|
25
25
|
|
|
26
26
|
constructor(maxBytes: number) {
|
|
27
27
|
this.maxBytes = maxBytes;
|
|
28
|
-
this.notice = `\n[Diagnostics truncated (${
|
|
28
|
+
this.notice = `\n[Diagnostics truncated (${formatByteSize(maxBytes)} limit); middle omitted.]\n`;
|
|
29
29
|
const contentBytes = maxBytes - Buffer.byteLength(this.notice);
|
|
30
30
|
this.headBytes = Math.floor(contentBytes / 2);
|
|
31
31
|
this.tailBytes = contentBytes - this.headBytes;
|
package/src/pi/edit-tool.ts
CHANGED
|
@@ -85,7 +85,7 @@ function buildEditSchema(hashLen: number) {
|
|
|
85
85
|
const transferFields = {
|
|
86
86
|
op: Type.Union([Type.Literal("copy"), Type.Literal("move")], {
|
|
87
87
|
description:
|
|
88
|
-
"
|
|
88
|
+
"Copy, or move (also removes the source), whole lines whose text and indentation stay unchanged; use a body edit when either changes.",
|
|
89
89
|
}),
|
|
90
90
|
anchor: requiredAnchor,
|
|
91
91
|
end: optionalEnd,
|
|
@@ -157,7 +157,7 @@ function buildEditSchema(hashLen: number) {
|
|
|
157
157
|
}),
|
|
158
158
|
edits: Type.Array(editOpSchema, {
|
|
159
159
|
minItems: 1,
|
|
160
|
-
description: `Operations on one snapshot. Anchors are LINE#HASH with exactly ${hashLen} hash characters. Copy each anchor from read, grep, or edit failure diagnostics; never write a hash you have not seen there. Shell output such as sed, head, or cat has no anchors, so read or grep those lines first.`,
|
|
160
|
+
description: `Operations on one snapshot; ranges must not overlap. Insertions at one position, or at the start of a replaced or deleted range, apply in array order before it. Anchors are LINE#HASH with exactly ${hashLen} hash characters. Copy each anchor from read, grep, or edit failure diagnostics; never write a hash you have not seen there. Shell output such as sed, head, or cat has no anchors, so read or grep those lines first.`,
|
|
161
161
|
}),
|
|
162
162
|
},
|
|
163
163
|
{ additionalProperties: false },
|
|
@@ -165,9 +165,6 @@ function buildEditSchema(hashLen: number) {
|
|
|
165
165
|
}
|
|
166
166
|
type EditSchema = ReturnType<typeof buildEditSchema>;
|
|
167
167
|
|
|
168
|
-
function createEditSchema(actionFusion: boolean, hashLen: number) {
|
|
169
|
-
return withThenRunSchema(buildEditSchema(hashLen), "edit", actionFusion);
|
|
170
|
-
}
|
|
171
168
|
type EditParams = Static<EditSchema> & { then_run?: ThenRunInput };
|
|
172
169
|
|
|
173
170
|
type EditOpInput = Static<EditSchema>["edits"][number];
|
|
@@ -230,15 +227,15 @@ function toCoreEdits(ops: readonly EditOpInput[]): Edit[] {
|
|
|
230
227
|
case "replace":
|
|
231
228
|
return {
|
|
232
229
|
op: "replace",
|
|
233
|
-
|
|
230
|
+
anchor: parseAnchor(op.anchor),
|
|
234
231
|
end: parseAnchor(op.end),
|
|
235
232
|
body: op.body,
|
|
236
233
|
};
|
|
237
234
|
case "delete":
|
|
238
|
-
return { op: "delete",
|
|
235
|
+
return { op: "delete", anchor: parseAnchor(op.anchor), end: parseAnchor(op.end) };
|
|
239
236
|
case "copy":
|
|
240
237
|
case "move": {
|
|
241
|
-
const source = { op: op.op,
|
|
238
|
+
const source = { op: op.op, anchor: parseAnchor(op.anchor), end: parseAnchor(op.end) };
|
|
242
239
|
return "before" in op
|
|
243
240
|
? { ...source, before: parseAnchor(op.before) }
|
|
244
241
|
: { ...source, after: parseAnchor(op.after) };
|
|
@@ -295,19 +292,19 @@ export function makeEditOverride(
|
|
|
295
292
|
) {
|
|
296
293
|
// Schema, verification, and recovery use the registered configuration.
|
|
297
294
|
const { hashLen, shiftRadius } = config;
|
|
298
|
-
const parameters =
|
|
295
|
+
const parameters = withThenRunSchema(buildEditSchema(hashLen), "edit", fusion !== undefined);
|
|
299
296
|
|
|
300
297
|
return {
|
|
301
298
|
name: "edit" as const,
|
|
302
299
|
label: "edit",
|
|
303
300
|
description: withThenRunDescription(
|
|
304
|
-
"Edit
|
|
301
|
+
"Edit whole lines using LINE#HASH anchors checked against the current file. Use replace instead when the same change repeats in several places, or when only a fragment of a long line changes.",
|
|
305
302
|
fusion !== undefined,
|
|
306
303
|
),
|
|
307
304
|
promptSnippet: "Edit file lines using verified anchors",
|
|
308
305
|
promptGuidelines: [
|
|
309
306
|
"Batch all edits to one file into a single edit call.",
|
|
310
|
-
"
|
|
307
|
+
"After edit or replace, get fresh anchors with read or grep before citing any line it changed. If it added or removed lines, also refresh anchors below the earliest affected line; anchors above it remain valid. If the affected positions are unknown, read or grep the lines you intend to cite.",
|
|
311
308
|
...(fusion ? ACTION_FUSION_GUIDELINES : []),
|
|
312
309
|
],
|
|
313
310
|
parameters,
|
|
@@ -329,7 +326,7 @@ export function makeEditOverride(
|
|
|
329
326
|
theme: Theme,
|
|
330
327
|
context: EditRenderContext,
|
|
331
328
|
) {
|
|
332
|
-
return renderMutationResult(result, options, theme, context, "Editing…", editHeader);
|
|
329
|
+
return renderMutationResult(result, options, theme, context, "Editing…", editHeader, "edit");
|
|
333
330
|
},
|
|
334
331
|
|
|
335
332
|
async execute(
|