@criogaid/pi-hashline-edit 0.9.0 → 0.10.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 +9 -10
- package/README.zh-CN.md +8 -9
- package/THIRD_PARTY_NOTICES.md +0 -6
- package/package.json +1 -1
- package/src/core/AGENTS.md +4 -5
- package/src/core/apply.test.ts +96 -271
- package/src/core/apply.ts +62 -169
- package/src/core/case-fold.ts +8 -67
- package/src/core/character-set.ts +4 -4
- package/src/core/errors.test.ts +23 -7
- package/src/core/errors.ts +32 -5
- package/src/core/hash.test.ts +8 -16
- package/src/core/hash.ts +3 -23
- package/src/core/lines.ts +2 -4
- package/src/core/regex.ts +3 -4
- package/src/core/replace.test.ts +47 -1
- package/src/core/replace.ts +19 -13
- package/src/core/search-analysis.test.ts +24 -27
- package/src/core/search-analysis.ts +34 -65
- package/src/core/search-matrix.testing.ts +0 -2
- package/src/core/search.ts +1 -1
- package/src/core/text.test.ts +5 -5
- package/src/core/text.ts +5 -12
- package/src/core/types.ts +7 -43
- package/src/integration/fusion-dispatch.test.ts +2 -5
- package/src/integration/grep-flags.test.ts +0 -14
- package/src/integration/grep-js-completeness.test.ts +34 -8
- package/src/integration/grep-line-candidates.test.ts +4 -8
- package/src/integration/grep-matrix.test.ts +3 -7
- package/src/integration/grep-path-matrix.test.ts +5 -5
- package/src/integration/grep-prefilter-coverage.test.ts +3 -7
- package/src/integration/grep-process-limits.test.ts +78 -0
- package/src/integration/grep-rg.test.ts +118 -20
- package/src/integration/grep-scan-budget.test.ts +2 -2
- package/src/integration/grep-translation.test.ts +12 -27
- package/src/integration/large-text.test.ts +1 -47
- package/src/integration/model-budget-lifecycle.test.ts +2 -1
- package/src/integration/publication-read-changes.test.ts +123 -45
- package/src/integration/replace-worker-boundary.test.ts +21 -11
- package/src/integration/report-replay.test.ts +20 -22
- package/src/pi/AGENTS.md +15 -15
- package/src/pi/action-fusion.test.ts +164 -296
- package/src/pi/action-fusion.ts +148 -111
- package/src/pi/anchor-format.test.ts +9 -9
- package/src/pi/anchor-format.ts +6 -8
- package/src/pi/argument-diagnostics.ts +21 -25
- package/src/pi/argument-error.ts +2 -1
- package/src/pi/argument-validation.test.ts +129 -157
- package/src/pi/argument-validation.ts +5 -8
- package/src/pi/budgets.ts +5 -4
- package/src/pi/config.test.ts +5 -2
- package/src/pi/config.ts +4 -6
- package/src/pi/diagnostic-buffer.test.ts +12 -1
- package/src/pi/diagnostic-buffer.ts +1 -2
- package/src/pi/directory-sync.test.ts +0 -1
- package/src/pi/edit-tool.ts +46 -156
- package/src/pi/error-text.ts +4 -8
- package/src/pi/execute.test.ts +83 -196
- package/src/pi/failure-context.test.ts +144 -126
- package/src/pi/failure-context.ts +44 -93
- package/src/pi/failure-path.test.ts +168 -141
- package/src/pi/file-commit.test.ts +110 -53
- package/src/pi/file-commit.ts +90 -137
- package/src/pi/file-snapshot.test.ts +3 -5
- package/src/pi/fusion-card.test.ts +4 -1
- package/src/pi/fusion-card.ts +16 -24
- package/src/pi/grep-candidates.test.ts +2 -101
- package/src/pi/grep-candidates.ts +23 -69
- package/src/pi/grep-matrix.test.ts +2 -2
- package/src/pi/grep-order.test.ts +4 -4
- package/src/pi/grep-output.ts +62 -96
- package/src/pi/grep-render.ts +1 -1
- package/src/pi/grep-reread.ts +92 -0
- package/src/pi/grep-scope.ts +40 -42
- package/src/pi/grep-search.ts +22 -31
- package/src/pi/grep-tool.ts +55 -82
- package/src/pi/grep.test.ts +80 -45
- package/src/pi/model-budgets.test.ts +25 -23
- package/src/pi/model-budgets.ts +6 -38
- package/src/pi/mutation-result.test.ts +44 -35
- package/src/pi/mutation-result.ts +51 -20
- package/src/pi/mutation-runner.ts +126 -70
- package/src/pi/output-budgets.test.ts +36 -14
- package/src/pi/path.ts +1 -1
- package/src/pi/read-tool.ts +5 -5
- package/src/pi/regex-worker-contract.ts +3 -13
- package/src/pi/regex-worker.ts +1 -10
- package/src/pi/registration.test.ts +64 -36
- package/src/pi/render.test.ts +38 -28
- package/src/pi/render.ts +59 -63
- package/src/pi/replace-regex.ts +14 -2
- package/src/pi/replace-tool.ts +20 -82
- package/src/pi/replace-worker.ts +1 -1
- package/src/pi/replace.test.ts +9 -5
- package/src/pi/report-cause.ts +3 -8
- package/src/pi/report-failure.testing.ts +1 -2
- package/src/pi/report-schema.ts +62 -81
- package/src/pi/report.test.ts +171 -25
- package/src/pi/report.ts +33 -87
- package/src/pi/result-safety.test.ts +149 -176
- package/src/pi/rg-process.test.ts +77 -63
- package/src/pi/rg-process.ts +48 -64
- package/src/pi/rg-regex.ts +40 -400
- package/src/pi/schema.ts +12 -0
- package/src/pi/text-stream.test.ts +0 -21
- package/src/pi/text-stream.ts +14 -21
- package/src/pi/write-tool.ts +33 -62
- package/src/pi/write.test.ts +1 -3
- package/src/testing/regex-translation-corpus.ts +12 -12
- package/src/pi/replace-worker-contract.ts +0 -10
package/src/pi/edit-tool.ts
CHANGED
|
@@ -5,9 +5,7 @@
|
|
|
5
5
|
* The core verifies each anchor live against
|
|
6
6
|
* the current file content — no prior-read revision guard: a cited line
|
|
7
7
|
* that changed (or was misremembered) fails its own anchor; unchanged lines
|
|
8
|
-
* elsewhere never block the edit.
|
|
9
|
-
* at execution; Pi may coerce a single object before validation. Legacy
|
|
10
|
-
* oldText/newText inputs fail schema validation before mutation.
|
|
8
|
+
* elsewhere never block the edit.
|
|
11
9
|
*
|
|
12
10
|
* Concurrency safety: read-modify-write is wrapped in withFileMutationQueue.
|
|
13
11
|
* AbortSignal is honored — checked after read / before write.
|
|
@@ -15,49 +13,28 @@
|
|
|
15
13
|
* @module pi-hashline-edit/pi
|
|
16
14
|
*/
|
|
17
15
|
|
|
18
|
-
import {
|
|
19
|
-
type ExtensionToolContext,
|
|
20
|
-
type Theme,
|
|
21
|
-
type ToolDefinition,
|
|
22
|
-
type ToolRenderResultOptions,
|
|
23
|
-
} from "@earendil-works/pi-coding-agent";
|
|
24
|
-
import type { AgentToolUpdateCallback } from "@earendil-works/pi-agent-core";
|
|
16
|
+
import type { Theme } from "@earendil-works/pi-coding-agent";
|
|
25
17
|
import { Type, type Static, type TLiteral } from "typebox";
|
|
26
|
-
import {
|
|
27
|
-
ACTION_FUSION_GUIDELINES,
|
|
28
|
-
withThenRunDescription,
|
|
29
|
-
withThenRunSchema,
|
|
30
|
-
type ThenRunInput,
|
|
31
|
-
} from "./action-fusion.ts";
|
|
32
18
|
import { applyEdits } from "../core/apply.ts";
|
|
33
19
|
import { unwritableTextError } from "../core/text.ts";
|
|
34
20
|
import { EDIT_ANCHOR_FIELDS, type Anchor, type Edit } from "../core/types.ts";
|
|
35
21
|
import type { HashlineEditConfig } from "./config.ts";
|
|
36
22
|
import { anchorPattern, createAnchorFormatter, parseAnchorToken } from "./anchor-format.ts";
|
|
37
23
|
import {
|
|
24
|
+
diffCardRenderers,
|
|
38
25
|
formatDiffCounts,
|
|
39
26
|
formatHeaderPath,
|
|
40
|
-
renderMutationCall,
|
|
41
|
-
renderMutationResult,
|
|
42
27
|
type DiffCounts,
|
|
43
28
|
} from "./render.ts";
|
|
44
29
|
import { describeEditFailure } from "./failure-context.ts";
|
|
45
30
|
import { defaultOutputBudgets, type OutputBudgetProvider } from "./budgets.ts";
|
|
46
31
|
import {
|
|
47
|
-
|
|
32
|
+
mutationToolBase,
|
|
48
33
|
runTextMutation,
|
|
49
34
|
type ActionFusionExecutor,
|
|
50
35
|
type MutationTarget,
|
|
51
|
-
type TextMutationDetails,
|
|
52
36
|
} from "./mutation-runner.ts";
|
|
53
|
-
import type
|
|
54
|
-
import {
|
|
55
|
-
argumentItems,
|
|
56
|
-
createArgumentPreparer,
|
|
57
|
-
type ReportArgumentIssue,
|
|
58
|
-
} from "./argument-validation.ts";
|
|
59
|
-
type EditDetails = MutationResultDetails<TextMutationDetails>;
|
|
60
|
-
type EditRenderContext = Parameters<NonNullable<ToolDefinition<EditSchema>["renderCall"]>>[2];
|
|
37
|
+
import { argumentItems, type ReportArgumentIssue } from "./argument-validation.ts";
|
|
61
38
|
|
|
62
39
|
/** Split a validated anchor token; prepareArguments and the schema already checked it. */
|
|
63
40
|
function parseAnchor(value: string): Anchor;
|
|
@@ -74,12 +51,8 @@ interface EditOpSpec {
|
|
|
74
51
|
readonly meaning: string;
|
|
75
52
|
readonly required: readonly EditItemField[];
|
|
76
53
|
readonly optional?: readonly EditItemField[];
|
|
77
|
-
/** Destinations, of which exactly one is required. */
|
|
78
|
-
readonly destination?: readonly EditItemField[];
|
|
79
54
|
}
|
|
80
55
|
|
|
81
|
-
const TRANSFER_DESTINATION = ["before", "after"] as const;
|
|
82
|
-
|
|
83
56
|
/** Every op and its fields; the schema states them, and argument checks enforce them. */
|
|
84
57
|
const EDIT_OPS = {
|
|
85
58
|
replace: {
|
|
@@ -96,20 +69,6 @@ const EDIT_OPS = {
|
|
|
96
69
|
meaning: "Insert body before the anchor line, which is kept; do not repeat it in body.",
|
|
97
70
|
required: ["anchor", "body"],
|
|
98
71
|
},
|
|
99
|
-
copy: {
|
|
100
|
-
meaning:
|
|
101
|
-
"Copy the cited line(s), text and indentation unchanged, before or after another original line; use a body edit when either changes.",
|
|
102
|
-
required: ["anchor"],
|
|
103
|
-
optional: ["end"],
|
|
104
|
-
destination: TRANSFER_DESTINATION,
|
|
105
|
-
},
|
|
106
|
-
move: {
|
|
107
|
-
meaning:
|
|
108
|
-
"Move the cited line(s), text and indentation unchanged, before or after another original line, removing the source; use a body edit when either changes.",
|
|
109
|
-
required: ["anchor"],
|
|
110
|
-
optional: ["end"],
|
|
111
|
-
destination: TRANSFER_DESTINATION,
|
|
112
|
-
},
|
|
113
72
|
append: { meaning: "Add body at the end of the file.", required: ["body"] },
|
|
114
73
|
prepend: { meaning: "Add body at the start of the file.", required: ["body"] },
|
|
115
74
|
} as const satisfies Record<string, EditOpSpec>;
|
|
@@ -120,12 +79,8 @@ const EDIT_OP_NAMES = Object.keys(EDIT_OPS) as EditOpName[];
|
|
|
120
79
|
const MAX_EDIT_OPS = 64;
|
|
121
80
|
|
|
122
81
|
/** An op's meaning followed by the fields it takes. */
|
|
123
|
-
function describeEditOp({ meaning, required, optional = []
|
|
124
|
-
|
|
125
|
-
...required,
|
|
126
|
-
...(destination ? [`exactly one of ${destination.join(" or ")}`] : []),
|
|
127
|
-
].join(" and ");
|
|
128
|
-
return `${meaning} Takes ${takes}${optional.length ? `; ${optional.join(", ")} is optional` : ""}.`;
|
|
82
|
+
function describeEditOp({ meaning, required, optional = [] }: EditOpSpec): string {
|
|
83
|
+
return `${meaning} Takes ${required.join(" and ")}${optional.length ? `; ${optional.join(", ")} is optional` : ""}.`;
|
|
129
84
|
}
|
|
130
85
|
|
|
131
86
|
/**
|
|
@@ -155,8 +110,6 @@ function buildEditSchema(hashLen: number) {
|
|
|
155
110
|
'New lines, one per element, without CR/LF. At least one; [""] is one blank line.',
|
|
156
111
|
}),
|
|
157
112
|
),
|
|
158
|
-
before: anchorField("Insert captured lines before this original line."),
|
|
159
|
-
after: anchorField("Insert captured lines after this original line."),
|
|
160
113
|
},
|
|
161
114
|
{
|
|
162
115
|
additionalProperties: false,
|
|
@@ -172,7 +125,7 @@ function buildEditSchema(hashLen: number) {
|
|
|
172
125
|
edits: Type.Array(editOpSchema, {
|
|
173
126
|
minItems: 1,
|
|
174
127
|
maxItems: MAX_EDIT_OPS,
|
|
175
|
-
description: `Operations on one snapshot; ranges must not overlap. Each gap between lines takes at most one insertion
|
|
128
|
+
description: `Operations on one snapshot; ranges must not overlap. Each gap between lines takes at most one insertion; insert_after N and insert_before N+1 target the same gap, so put all new lines for a gap in one body. An insertion at the start of a replaced or deleted range goes 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.`,
|
|
176
129
|
}),
|
|
177
130
|
},
|
|
178
131
|
{ additionalProperties: false },
|
|
@@ -180,9 +133,9 @@ function buildEditSchema(hashLen: number) {
|
|
|
180
133
|
}
|
|
181
134
|
type EditSchema = ReturnType<typeof buildEditSchema>;
|
|
182
135
|
|
|
183
|
-
type EditParams = Static<EditSchema
|
|
136
|
+
type EditParams = Static<EditSchema>;
|
|
184
137
|
|
|
185
|
-
type EditOpInput =
|
|
138
|
+
type EditOpInput = EditParams["edits"][number];
|
|
186
139
|
type EditOpSchema = EditSchema["properties"]["edits"]["items"];
|
|
187
140
|
|
|
188
141
|
/** How to correct edit argument issues; each reason states only what is wrong. */
|
|
@@ -212,11 +165,7 @@ function checkEditArguments(
|
|
|
212
165
|
const name = edit.action as EditOpName;
|
|
213
166
|
const spec: EditOpSpec = EDIT_OPS[name];
|
|
214
167
|
const path = `edits[${index}]`;
|
|
215
|
-
const accepted = new Set([
|
|
216
|
-
...spec.required,
|
|
217
|
-
...(spec.optional ?? []),
|
|
218
|
-
...(spec.destination ?? []),
|
|
219
|
-
]);
|
|
168
|
+
const accepted = new Set([...spec.required, ...(spec.optional ?? [])]);
|
|
220
169
|
for (const [field, declaration] of Object.entries(item.properties)) {
|
|
221
170
|
if (field === "action") continue;
|
|
222
171
|
const given = edit[field] !== undefined;
|
|
@@ -229,11 +178,6 @@ function checkEditArguments(
|
|
|
229
178
|
Reflect.get(declaration, "description"),
|
|
230
179
|
);
|
|
231
180
|
}
|
|
232
|
-
if (
|
|
233
|
-
spec.destination &&
|
|
234
|
-
spec.destination.filter((field) => edit[field] !== undefined).length !== 1
|
|
235
|
-
)
|
|
236
|
-
report(path, `expected exactly one of: ${spec.destination.join(", ")}`);
|
|
237
181
|
|
|
238
182
|
const body = edit.body;
|
|
239
183
|
if (accepted.has("body") && Array.isArray(body)) {
|
|
@@ -249,18 +193,22 @@ function checkEditArguments(
|
|
|
249
193
|
if (unwritable) report(`${path}.body[${lineIndex}]`, unwritable.message);
|
|
250
194
|
});
|
|
251
195
|
}
|
|
196
|
+
const cited: { anchor?: number; end?: number } = {};
|
|
252
197
|
for (const field of EDIT_ANCHOR_FIELDS) {
|
|
253
198
|
const anchor = edit[field];
|
|
254
199
|
if (!accepted.has(field) || typeof anchor !== "string") continue;
|
|
255
200
|
const token = parseAnchorToken(anchor);
|
|
256
|
-
if (
|
|
201
|
+
if (!token) continue;
|
|
202
|
+
if (Number.isSafeInteger(token.line)) {
|
|
203
|
+
cited[field] = token.line;
|
|
204
|
+
} else {
|
|
257
205
|
report(
|
|
258
206
|
`${path}.${field}`,
|
|
259
207
|
"line number exceeds the safe integer range",
|
|
260
208
|
EDIT_ISSUE_FIX.unsafeLine,
|
|
261
209
|
);
|
|
262
210
|
}
|
|
263
|
-
if (token
|
|
211
|
+
if (token.hash.length !== hashLen) {
|
|
264
212
|
report(
|
|
265
213
|
`${path}.${field}`,
|
|
266
214
|
`has ${token.hash.length} hash characters; hashLen is ${hashLen}`,
|
|
@@ -268,6 +216,12 @@ function checkEditArguments(
|
|
|
268
216
|
);
|
|
269
217
|
}
|
|
270
218
|
}
|
|
219
|
+
|
|
220
|
+
// The cited line numbers alone decide this, whatever the file holds. An
|
|
221
|
+
// unsafe line number was reported above, and comparing it would add a false issue.
|
|
222
|
+
if (cited.anchor !== undefined && cited.end !== undefined && cited.end < cited.anchor) {
|
|
223
|
+
report(`${path}.end`, `line ${cited.end} is before anchor line ${cited.anchor}`);
|
|
224
|
+
}
|
|
271
225
|
});
|
|
272
226
|
}
|
|
273
227
|
|
|
@@ -287,13 +241,6 @@ function toCoreEdits(ops: readonly EditOpInput[]): Edit[] {
|
|
|
287
241
|
};
|
|
288
242
|
case "delete":
|
|
289
243
|
return { op: "delete", anchor: parseAnchor(op.anchor!), end: parseAnchor(op.end) };
|
|
290
|
-
case "copy":
|
|
291
|
-
case "move": {
|
|
292
|
-
const source = { op: op.action, anchor: parseAnchor(op.anchor!), end: parseAnchor(op.end) };
|
|
293
|
-
return op.before !== undefined
|
|
294
|
-
? { ...source, before: parseAnchor(op.before) }
|
|
295
|
-
: { ...source, after: parseAnchor(op.after!) };
|
|
296
|
-
}
|
|
297
244
|
case "insert_after":
|
|
298
245
|
case "insert_before":
|
|
299
246
|
return { op: op.action, anchor: parseAnchor(op.anchor!), body: op.body! };
|
|
@@ -311,17 +258,9 @@ function editHeader(args: EditParams, theme: Theme, counts?: DiffCounts): string
|
|
|
311
258
|
const edits = Array.isArray(args.edits) ? args.edits : [];
|
|
312
259
|
const n = edits.length;
|
|
313
260
|
if (n) {
|
|
314
|
-
const opCounts: Record<
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
copy: 0,
|
|
318
|
-
move: 0,
|
|
319
|
-
insert_before: 0,
|
|
320
|
-
insert_after: 0,
|
|
321
|
-
append: 0,
|
|
322
|
-
prepend: 0,
|
|
323
|
-
unknown: 0,
|
|
324
|
-
};
|
|
261
|
+
const opCounts: Record<string, number> = Object.fromEntries(
|
|
262
|
+
[...EDIT_OP_NAMES, "unknown"].map((kind) => [kind, 0]),
|
|
263
|
+
);
|
|
325
264
|
// Renderers receive partial arguments; fixed buckets keep one-pass counting O(1) in space.
|
|
326
265
|
for (const edit of edits) {
|
|
327
266
|
const kind = edit?.action;
|
|
@@ -347,64 +286,26 @@ export function makeEditOverride(
|
|
|
347
286
|
// Schema, verification, and recovery use the registered configuration.
|
|
348
287
|
const { hashLen, shiftRadius } = config;
|
|
349
288
|
const schema = buildEditSchema(hashLen);
|
|
350
|
-
const parameters = withThenRunSchema(schema, "edit", fusion !== undefined);
|
|
351
289
|
|
|
352
290
|
return {
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
fusion !== undefined,
|
|
358
|
-
),
|
|
359
|
-
promptSnippet: "Edit file lines using verified anchors",
|
|
360
|
-
promptGuidelines: [
|
|
361
|
-
"Batch all edits to one file into a single edit call.",
|
|
362
|
-
"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.",
|
|
363
|
-
...(fusion ? ACTION_FUSION_GUIDELINES : []),
|
|
364
|
-
],
|
|
365
|
-
parameters,
|
|
366
|
-
// Providers that support it bound the batch by the schema while sampling.
|
|
367
|
-
constrainedSampling: { type: "json_schema", strict: "prefer" } as const,
|
|
368
|
-
prepareArguments: createArgumentPreparer(
|
|
369
|
-
"edit",
|
|
370
|
-
parameters,
|
|
371
|
-
(args, report) => checkEditArguments(args, hashLen, schema.properties.edits.items, report),
|
|
291
|
+
...mutationToolBase({
|
|
292
|
+
tool: "edit",
|
|
293
|
+
cwd,
|
|
294
|
+
fusion,
|
|
372
295
|
budgets,
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
)
|
|
386
|
-
return renderMutationResult(result, options, theme, context, "Editing…", editHeader, "edit");
|
|
387
|
-
},
|
|
388
|
-
|
|
389
|
-
async execute(
|
|
390
|
-
toolCallId: string,
|
|
391
|
-
params: EditParams,
|
|
392
|
-
signal: AbortSignal | undefined,
|
|
393
|
-
onUpdate: AgentToolUpdateCallback<EditDetails> | undefined,
|
|
394
|
-
ctx: ExtensionToolContext,
|
|
395
|
-
) {
|
|
396
|
-
return executeMutation<EditParams, TextMutationDetails, "edit">(
|
|
397
|
-
{
|
|
398
|
-
tool: "edit",
|
|
399
|
-
cwd,
|
|
400
|
-
fusion,
|
|
401
|
-
budgets,
|
|
402
|
-
run: (mutationParams, target) =>
|
|
403
|
-
runEdit(target, mutationParams.edits, hashLen, shiftRadius),
|
|
404
|
-
},
|
|
405
|
-
{ toolCallId, params, signal, onUpdate, ctx },
|
|
406
|
-
);
|
|
407
|
-
},
|
|
296
|
+
schema,
|
|
297
|
+
description:
|
|
298
|
+
"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.",
|
|
299
|
+
promptSnippet: "Edit file lines using verified anchors",
|
|
300
|
+
promptGuidelines: [
|
|
301
|
+
"Batch all edits to one file into a single edit call.",
|
|
302
|
+
"Before citing a line after write, edit, or replace, get its anchor from a new read or grep. Only after edit, lines above the earliest changed line keep their anchors.",
|
|
303
|
+
],
|
|
304
|
+
check: (args, report) =>
|
|
305
|
+
checkEditArguments(args, hashLen, schema.properties.edits.items, report),
|
|
306
|
+
run: (params, target) => runEdit(target, params.edits, hashLen, shiftRadius),
|
|
307
|
+
}),
|
|
308
|
+
...diffCardRenderers("edit", "Editing…", editHeader),
|
|
408
309
|
};
|
|
409
310
|
}
|
|
410
311
|
|
|
@@ -417,24 +318,13 @@ function runEdit(
|
|
|
417
318
|
const anchorFormatter = createAnchorFormatter(hashLen);
|
|
418
319
|
|
|
419
320
|
return runTextMutation<"edit">(target, (currentText) => {
|
|
420
|
-
const translated = toCoreEdits(editOps);
|
|
421
|
-
|
|
422
321
|
// Recovery reports checksum candidates from nearby lines, then the whole file
|
|
423
322
|
// if needed. Every failed anchor still rejects the batch; callers inspect
|
|
424
323
|
// candidates and resubmit with fresh anchors.
|
|
425
|
-
const result = applyEdits(currentText,
|
|
324
|
+
const result = applyEdits(currentText, toCoreEdits(editOps), hashLen, shiftRadius);
|
|
426
325
|
if (!result.ok) {
|
|
427
|
-
throw describeEditFailure(
|
|
428
|
-
result.failure,
|
|
429
|
-
{ currentText, anchors: anchorFormatter },
|
|
430
|
-
translated.length > 1,
|
|
431
|
-
target.budget,
|
|
432
|
-
);
|
|
326
|
+
throw describeEditFailure(currentText, result.failures, anchorFormatter, target.budget);
|
|
433
327
|
}
|
|
434
|
-
|
|
435
|
-
return {
|
|
436
|
-
text: result.text,
|
|
437
|
-
facts: {},
|
|
438
|
-
};
|
|
328
|
+
return { text: result.text, facts: {} };
|
|
439
329
|
});
|
|
440
330
|
}
|
package/src/pi/error-text.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { errnoCode, HashlineError } from "../core/errors.ts";
|
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Cancellation, worded like Pi's built-in tools. A mutation report's
|
|
5
|
-
* `publication`
|
|
5
|
+
* `publication` says where it stopped, so the message does not.
|
|
6
6
|
* Whatever a cancelled operation threw is its effect, not a cause.
|
|
7
7
|
*/
|
|
8
8
|
export function cancellationError(): HashlineError<"OPERATION_ABORTED"> {
|
|
@@ -26,7 +26,7 @@ export class FileChangedDuringReadError extends HashlineError<"FILE_CHANGED"> {
|
|
|
26
26
|
|
|
27
27
|
/**
|
|
28
28
|
* A searched file no longer matches what grep matched. grep binds matches to the
|
|
29
|
-
* revision grep-search hashed while matching, and grep-
|
|
29
|
+
* revision grep-search hashed while matching, and grep-reread reads the file again
|
|
30
30
|
* against it.
|
|
31
31
|
*/
|
|
32
32
|
export function searchChangedError(): HashlineError<"FILE_CHANGED"> {
|
|
@@ -37,12 +37,8 @@ export function searchChangedError(): HashlineError<"FILE_CHANGED"> {
|
|
|
37
37
|
* A per-file failure that leaves the rest of the search valid: a filesystem error, or the
|
|
38
38
|
* file changing while it was searched or displayed. Undefined for any other failure.
|
|
39
39
|
*/
|
|
40
|
-
export function fileReadWarning(
|
|
41
|
-
|
|
42
|
-
error: unknown,
|
|
43
|
-
signal?: AbortSignal,
|
|
44
|
-
): string | undefined {
|
|
45
|
-
if (signal?.aborted || !(error instanceof Error)) return undefined;
|
|
40
|
+
export function fileReadWarning(filePath: string, error: unknown): string | undefined {
|
|
41
|
+
if (!(error instanceof Error)) return undefined;
|
|
46
42
|
const changed = error instanceof HashlineError && error.errorCode === "FILE_CHANGED";
|
|
47
43
|
if (!changed && errnoCode(error) === undefined) return undefined;
|
|
48
44
|
return `Could not read ${filePath}: ${error.message}`;
|