@criogaid/pi-hashline-edit 0.10.0 → 0.11.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 (94) hide show
  1. package/README.md +4 -3
  2. package/README.zh-CN.md +4 -3
  3. package/package.json +1 -1
  4. package/src/core/apply.test.ts +2 -2
  5. package/src/core/apply.ts +2 -2
  6. package/src/core/character-set.test.ts +2 -3
  7. package/src/core/character-set.ts +1 -1
  8. package/src/core/ranges.test.ts +2 -1
  9. package/src/core/ranges.ts +1 -1
  10. package/src/core/types.ts +1 -1
  11. package/src/index.ts +8 -8
  12. package/src/integration/config-registration.test.ts +8 -10
  13. package/src/integration/fusion-dispatch.test.ts +2 -2
  14. package/src/integration/grep-errors.test.ts +3 -3
  15. package/src/integration/grep-flags.test.ts +5 -5
  16. package/src/integration/grep-js-completeness.test.ts +12 -11
  17. package/src/integration/grep-line-candidates.test.ts +3 -2
  18. package/src/integration/grep-matrix.test.ts +5 -4
  19. package/src/integration/grep-order.test.ts +4 -4
  20. package/src/integration/grep-path-matrix.test.ts +5 -4
  21. package/src/integration/grep-prefilter-coverage.test.ts +4 -3
  22. package/src/integration/grep-process-limits.test.ts +2 -4
  23. package/src/integration/grep-regex.test.ts +10 -10
  24. package/src/integration/grep-rg.test.ts +50 -48
  25. package/src/integration/grep-scan-budget.test.ts +8 -8
  26. package/src/integration/grep-translation.test.ts +8 -7
  27. package/src/integration/large-text.test.ts +5 -5
  28. package/src/integration/model-budget-lifecycle.test.ts +9 -9
  29. package/src/integration/mutation-file-types.testing.ts +4 -4
  30. package/src/integration/npm-package.testing.ts +3 -3
  31. package/src/integration/publication-read-changes.test.ts +54 -54
  32. package/src/integration/read-changes.test.ts +4 -4
  33. package/src/integration/replace-worker-boundary.test.ts +1 -1
  34. package/src/integration/report-replay.test.ts +5 -6
  35. package/src/integration/utf8-errors.test.ts +4 -4
  36. package/src/pi/AGENTS.md +6 -5
  37. package/src/pi/action-fusion.test.ts +125 -105
  38. package/src/pi/action-fusion.testing.ts +38 -0
  39. package/src/pi/action-fusion.ts +9 -21
  40. package/src/pi/argument-diagnostics.ts +4 -3
  41. package/src/pi/argument-format.test.ts +19 -18
  42. package/src/pi/argument-validation.test.ts +218 -139
  43. package/src/pi/budgets.ts +1 -4
  44. package/src/pi/codemode.test.ts +7 -2
  45. package/src/pi/config.test.ts +2 -1
  46. package/src/pi/config.ts +8 -3
  47. package/src/pi/diagnostic-buffer.test.ts +23 -13
  48. package/src/pi/edit-tool.ts +47 -62
  49. package/src/pi/error-text.ts +7 -2
  50. package/src/pi/execute.test.ts +174 -157
  51. package/src/pi/failure-context.test.ts +4 -3
  52. package/src/pi/failure-context.ts +1 -1
  53. package/src/pi/failure-path.test.ts +37 -37
  54. package/src/pi/file-commit.test.ts +47 -19
  55. package/src/pi/file-commit.ts +36 -9
  56. package/src/pi/fusion-card.test.ts +22 -21
  57. package/src/pi/grep-candidates.test.ts +18 -20
  58. package/src/pi/grep-candidates.ts +8 -13
  59. package/src/pi/grep-matrix.test.ts +3 -3
  60. package/src/pi/grep-order.test.ts +12 -11
  61. package/src/pi/grep-output.ts +36 -15
  62. package/src/pi/grep-reread.ts +7 -2
  63. package/src/pi/grep-rg.testing.ts +70 -0
  64. package/src/pi/grep-scope.ts +4 -4
  65. package/src/pi/grep-search.ts +8 -11
  66. package/src/pi/grep-tool.ts +23 -39
  67. package/src/pi/grep.test.ts +102 -116
  68. package/src/pi/model-budgets.test.ts +2 -1
  69. package/src/pi/mutation-outcome.testing.ts +0 -1
  70. package/src/pi/mutation-result.test.ts +8 -8
  71. package/src/pi/mutation-result.ts +1 -1
  72. package/src/pi/mutation-runner.ts +9 -5
  73. package/src/pi/output-budgets.test.ts +53 -31
  74. package/src/pi/pi.test.ts +18 -13
  75. package/src/pi/read-tool.ts +13 -18
  76. package/src/pi/read.test.ts +22 -41
  77. package/src/pi/registration.test.ts +25 -19
  78. package/src/pi/render.test.ts +51 -32
  79. package/src/pi/render.ts +7 -4
  80. package/src/pi/replace-regex.ts +1 -1
  81. package/src/pi/replace-tool.ts +6 -16
  82. package/src/pi/replace.test.ts +45 -34
  83. package/src/pi/report-failure.testing.ts +9 -1
  84. package/src/pi/report-schema.ts +205 -83
  85. package/src/pi/report.test.ts +66 -64
  86. package/src/pi/report.ts +23 -17
  87. package/src/pi/result-safety.test.ts +121 -100
  88. package/src/pi/rg-process.test.ts +2 -2
  89. package/src/pi/rg-process.ts +9 -15
  90. package/src/pi/schema.ts +23 -0
  91. package/src/pi/tool-factories.testing.ts +59 -0
  92. package/src/pi/write-tool.ts +9 -15
  93. package/src/pi/write.test.ts +30 -31
  94. package/src/testing/run-tests.ts +1 -1
@@ -6,7 +6,7 @@ import { Type } from "typebox";
6
6
  import { createCodemodeToolDefinition } from "../../node_modules/@earendil-works/pi-coding-agent/dist/extensions/codemode/tool.js";
7
7
  import { openTestSession, responseStream, SESSION_TIMEOUT_MS } from "../testing/session.testing.ts";
8
8
  import { createActionFusionExecutor } from "./action-fusion.ts";
9
- import { makeWriteOverride } from "./write-tool.ts";
9
+ import { makeWriteOverride } from "./tool-factories.testing.ts";
10
10
 
11
11
  for (const entry of ["direct", "codemode"] as const) {
12
12
  test(`${entry} mutation waits on then_run → the call and model continuation stay pending`, {
@@ -17,7 +17,12 @@ for (const entry of ["direct", "codemode"] as const) {
17
17
  const { cwd, session, model } = await openTestSession(t, {
18
18
  tools: ["write", "bash", "codemode"],
19
19
  configure(pi, cwd) {
20
- pi.registerTool(makeWriteOverride(cwd, createActionFusionExecutor()));
20
+ pi.registerTool(
21
+ makeWriteOverride(
22
+ cwd,
23
+ createActionFusionExecutor(() => {}),
24
+ ),
25
+ );
21
26
  pi.registerTool(createCodemodeToolDefinition());
22
27
  pi.registerTool({
23
28
  name: "bash",
@@ -4,7 +4,8 @@ import { tmpdir } from "node:os";
4
4
  import { join } from "node:path";
5
5
  import assert from "node:assert/strict";
6
6
  import { test } from "node:test";
7
- import { DEFAULT_CONFIG, loadConfig } from "./config.ts";
7
+ import { loadConfig } from "./config.ts";
8
+ import { DEFAULT_CONFIG } from "./tool-factories.testing.ts";
8
9
 
9
10
  async function withSettings(
10
11
  fn: (
package/src/pi/config.ts CHANGED
@@ -13,7 +13,7 @@ import { Type, type Static, type TSchema } from "typebox";
13
13
  import { Value } from "typebox/value";
14
14
  import { HASH_LEN_MAX, HASH_LEN_MIN } from "../core/hash.ts";
15
15
  import { GREP_CONTEXT_RANGE, integerRange, POSITIVE_SAFE_INTEGER } from "./schema.ts";
16
- import { MAX_CONTENT_KIB } from "./budgets.ts";
16
+ import { MAX_CONTENT_KIB, type OutputBudgetProvider } from "./budgets.ts";
17
17
 
18
18
  function integerSetting(
19
19
  range: ReturnType<typeof integerRange>,
@@ -85,6 +85,13 @@ const configSchema = Type.Object({
85
85
 
86
86
  export type HashlineEditConfig = Static<typeof configSchema>;
87
87
 
88
+ /** What a tool captures at registration and keeps for its lifetime. */
89
+ export interface ToolEnvironment {
90
+ readonly cwd: string;
91
+ readonly config: HashlineEditConfig;
92
+ readonly budgets: OutputBudgetProvider;
93
+ }
94
+
88
95
  function asRecord(value: unknown): Record<string, unknown> {
89
96
  return value !== null && typeof value === "object" && !Array.isArray(value)
90
97
  ? (value as Record<string, unknown>)
@@ -107,8 +114,6 @@ function resolveSetting<T extends TSchema>(schema: T, value: unknown): Static<T>
107
114
  ) as Static<T>;
108
115
  }
109
116
 
110
- export const DEFAULT_CONFIG: HashlineEditConfig = resolveSetting(configSchema, {});
111
-
112
117
  /** Parse JSON directly without stripping comments (standard JSON forbids comments; on error fall back to default). */
113
118
  function readSettings(filePath: string): Record<string, unknown> {
114
119
  try {
@@ -3,9 +3,11 @@ import { test } from "node:test";
3
3
  import childProcess from "node:child_process";
4
4
  import { syncBuiltinESMExports } from "node:module";
5
5
  import { DiagnosticBuffer } from "./diagnostic-buffer.ts";
6
- import { DEFAULT_OUTPUT_BUDGETS } from "./budgets.ts";
7
- import { assembleGrepOutput } from "./grep-output.ts";
8
- import { MAX_RG_STDERR_BYTES, runRgPaths } from "./rg-process.ts";
6
+ import { DEFAULT_OUTPUT_BUDGETS } from "./tool-factories.testing.ts";
7
+ import { grepOutput } from "./grep-output.ts";
8
+ import { createAnchorFormatter } from "./anchor-format.ts";
9
+ import { runRgPaths } from "./rg-process.ts";
10
+ const MAX_RG_STDERR_BYTES = 64 * 1024;
9
11
  import { mkdtemp, writeFile, rm } from "node:fs/promises";
10
12
  import { tmpdir } from "node:os";
11
13
  import { join } from "node:path";
@@ -46,19 +48,27 @@ test("diagnostics within the budget are unchanged", () => {
46
48
  assert.equal(buffer.toString(), source);
47
49
  });
48
50
 
49
- test("search warning aggregation retains the final cause and labels truncation", () => {
50
- const { facts, payload } = assembleGrepOutput({
51
+ test("search warning aggregation retains the final cause and labels truncation", async () => {
52
+ const { facts, payload } = await grepOutput({
51
53
  budget: DEFAULT_OUTPUT_BUDGETS,
52
- formatted: {
53
- blocks: [{ lines: ["confirmed match"] }],
54
- matches: 1,
55
- files: 1,
54
+ cwd: process.cwd(),
55
+ anchors: createAnchorFormatter(4),
56
+ context: 0,
57
+ search: {
58
+ files: [
59
+ {
60
+ filePath: join(process.cwd(), "confirmed match"),
61
+ rows: [],
62
+ snapshot: { revision: "", validUtf8: true },
63
+ },
64
+ ],
65
+ matchLimitReached: false,
66
+ scanLimitReached: false,
56
67
  },
57
- warnings: [diagnostic(DEFAULT_OUTPUT_BUDGETS.fieldBytes)],
58
- searchFacts: {},
59
- outputMode: "content",
60
- matchLimitReached: false,
68
+ warnings: [{ reason: diagnostic(DEFAULT_OUTPUT_BUDGETS.fieldBytes) }],
69
+ outputMode: "files",
61
70
  effectiveLimit: 100,
71
+ literalPipe: false,
62
72
  });
63
73
  assert.equal(payload, "confirmed match");
64
74
  assert.match(facts.diagnostics ?? "", /regex parse error:/);
@@ -1,7 +1,7 @@
1
1
  /**
2
- * Override edit: hashline ops via structured `edits` (LINE#HASH anchors).
2
+ * Override edit: hashline ops via structured `steps` (LINE#HASH anchors).
3
3
  *
4
- * Each op in `edits` references line anchors from read, grep, or edit failure diagnostics.
4
+ * Each op in `steps` references line anchors from read, grep, or edit failure diagnostics.
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
@@ -14,11 +14,10 @@
14
14
  */
15
15
 
16
16
  import type { Theme } from "@earendil-works/pi-coding-agent";
17
- import { Type, type Static, type TLiteral } from "typebox";
17
+ import { Type, type Static } from "typebox";
18
18
  import { applyEdits } from "../core/apply.ts";
19
19
  import { unwritableTextError } from "../core/text.ts";
20
20
  import { EDIT_ANCHOR_FIELDS, type Anchor, type Edit } from "../core/types.ts";
21
- import type { HashlineEditConfig } from "./config.ts";
22
21
  import { anchorPattern, createAnchorFormatter, parseAnchorToken } from "./anchor-format.ts";
23
22
  import {
24
23
  diffCardRenderers,
@@ -27,14 +26,14 @@ import {
27
26
  type DiffCounts,
28
27
  } from "./render.ts";
29
28
  import { describeEditFailure } from "./failure-context.ts";
30
- import { defaultOutputBudgets, type OutputBudgetProvider } from "./budgets.ts";
31
29
  import {
32
30
  mutationToolBase,
33
31
  runTextMutation,
34
- type ActionFusionExecutor,
35
32
  type MutationTarget,
33
+ type MutationToolEnvironment,
36
34
  } from "./mutation-runner.ts";
37
35
  import { argumentItems, type ReportArgumentIssue } from "./argument-validation.ts";
36
+ import { filePathField, literalUnion } from "./schema.ts";
38
37
 
39
38
  /** Split a validated anchor token; prepareArguments and the schema already checked it. */
40
39
  function parseAnchor(value: string): Anchor;
@@ -44,7 +43,7 @@ function parseAnchor(value: string | undefined) {
44
43
  }
45
44
 
46
45
  /** Operation item fields besides `action`. */
47
- type EditItemField = (typeof EDIT_ANCHOR_FIELDS)[number] | "body";
46
+ type EditItemField = (typeof EDIT_ANCHOR_FIELDS)[number] | "lines";
48
47
 
49
48
  /** What one op does and which item fields it takes; it takes no others. */
50
49
  interface EditOpSpec {
@@ -56,21 +55,21 @@ interface EditOpSpec {
56
55
  /** Every op and its fields; the schema states them, and argument checks enforce them. */
57
56
  const EDIT_OPS = {
58
57
  replace: {
59
- meaning: "Replace the cited line(s) with body.",
60
- required: ["anchor", "body"],
58
+ meaning: "Replace the cited line(s) with lines.",
59
+ required: ["anchor", "lines"],
61
60
  optional: ["end"],
62
61
  },
63
62
  delete: { meaning: "Delete the cited line(s).", required: ["anchor"], optional: ["end"] },
64
63
  insert_after: {
65
- meaning: "Insert body after the anchor line, which is kept; do not repeat it in body.",
66
- required: ["anchor", "body"],
64
+ meaning: "Insert lines after the anchor line, which is kept; do not repeat it in lines.",
65
+ required: ["anchor", "lines"],
67
66
  },
68
67
  insert_before: {
69
- meaning: "Insert body before the anchor line, which is kept; do not repeat it in body.",
70
- required: ["anchor", "body"],
68
+ meaning: "Insert lines before the anchor line, which is kept; do not repeat it in lines.",
69
+ required: ["anchor", "lines"],
71
70
  },
72
- append: { meaning: "Add body at the end of the file.", required: ["body"] },
73
- prepend: { meaning: "Add body at the start of the file.", required: ["body"] },
71
+ append: { meaning: "Add lines at the end of the file.", required: ["lines"] },
72
+ prepend: { meaning: "Add lines at the start of the file.", required: ["lines"] },
74
73
  } as const satisfies Record<string, EditOpSpec>;
75
74
  type EditOpName = keyof typeof EDIT_OPS;
76
75
  const EDIT_OP_NAMES = Object.keys(EDIT_OPS) as EditOpName[];
@@ -93,17 +92,13 @@ function buildEditSchema(hashLen: number) {
93
92
  const anchorField = (description: string) => Type.Optional(Type.String({ pattern, description }));
94
93
  const editOpSchema = Type.Object(
95
94
  {
96
- // Constrained sampling and some gateways emit keys alphabetically; `action`
97
- // sorts first, so the operation is chosen before the fields it governs.
98
- // TypeBox infers a union's static type only from a tuple.
99
- action: Type.Union(
100
- EDIT_OP_NAMES.map((op) =>
101
- Type.Literal(op, { description: describeEditOp(EDIT_OPS[op]) }),
102
- ) as [TLiteral<EditOpName>, ...TLiteral<EditOpName>[]],
103
- ),
95
+ // Session evidence is mixed: OpenAI calls usually follow declaration order, while
96
+ // GLM and local calls often use lexical key order. Keep `action`, `anchor`,
97
+ // `end`, `lines` so both orders choose the operation and range before its payload.
98
+ action: literalUnion(EDIT_OP_NAMES, (op) => describeEditOp(EDIT_OPS[op])),
104
99
  anchor: anchorField("LINE#HASH of the target line."),
105
100
  end: anchorField("Inclusive last LINE#HASH of the range; omit for one line."),
106
- body: Type.Optional(
101
+ lines: Type.Optional(
107
102
  Type.Array(Type.String({ pattern: "^[^\\r\\n]*$" }), {
108
103
  minItems: 1,
109
104
  description:
@@ -118,14 +113,11 @@ function buildEditSchema(hashLen: number) {
118
113
  );
119
114
  return Type.Object(
120
115
  {
121
- path: Type.String({
122
- minLength: 1,
123
- description: "Path to the file (relative or absolute)",
124
- }),
125
- edits: Type.Array(editOpSchema, {
116
+ path: filePathField(),
117
+ steps: Type.Array(editOpSchema, {
126
118
  minItems: 1,
127
119
  maxItems: MAX_EDIT_OPS,
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.`,
120
+ 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 operation. 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.`,
129
121
  }),
130
122
  },
131
123
  { additionalProperties: false },
@@ -135,13 +127,13 @@ type EditSchema = ReturnType<typeof buildEditSchema>;
135
127
 
136
128
  type EditParams = Static<EditSchema>;
137
129
 
138
- type EditOpInput = EditParams["edits"][number];
139
- type EditOpSchema = EditSchema["properties"]["edits"]["items"];
130
+ type EditOpInput = EditParams["steps"][number];
131
+ type EditOpSchema = EditSchema["properties"]["steps"]["items"];
140
132
 
141
133
  /** How to correct edit argument issues; each reason states only what is wrong. */
142
134
  const EDIT_ISSUE_FIX = {
143
135
  emptyReplace: 'Use {"action":"delete"} to remove lines, or supply the replacement lines.',
144
- emptyBody: 'Remove this edit or supply at least one line ([""] for a blank line).',
136
+ emptyLines: 'Remove this step or supply at least one line ([""] for a blank line).',
145
137
  unsafeLine: 'Copy a complete "LINE#HASH" token from the latest tool result.',
146
138
  hashLength: "Read or grep the file for current anchors.",
147
139
  } as const;
@@ -157,14 +149,14 @@ function checkEditArguments(
157
149
  item: EditOpSchema,
158
150
  report: ReportArgumentIssue,
159
151
  ): void {
160
- argumentItems((args as { edits?: unknown } | null)?.edits).forEach((value, index) => {
152
+ argumentItems((args as { steps?: unknown } | null)?.steps).forEach((value, index) => {
161
153
  if (value === null || typeof value !== "object") return;
162
154
  const edit = value as Record<string, unknown>;
163
155
  // The schema reports an unknown action; which fields it takes is then unknown.
164
156
  if (typeof edit.action !== "string" || !Object.hasOwn(EDIT_OPS, edit.action)) return;
165
157
  const name = edit.action as EditOpName;
166
158
  const spec: EditOpSpec = EDIT_OPS[name];
167
- const path = `edits[${index}]`;
159
+ const path = `steps[${index}]`;
168
160
  const accepted = new Set([...spec.required, ...(spec.optional ?? [])]);
169
161
  for (const [field, declaration] of Object.entries(item.properties)) {
170
162
  if (field === "action") continue;
@@ -179,18 +171,18 @@ function checkEditArguments(
179
171
  );
180
172
  }
181
173
 
182
- const body = edit.body;
183
- if (accepted.has("body") && Array.isArray(body)) {
184
- if (body.length === 0) {
174
+ const lines = edit.lines;
175
+ if (accepted.has("lines") && Array.isArray(lines)) {
176
+ if (lines.length === 0) {
185
177
  report(
186
- `${path}.body`,
178
+ `${path}.lines`,
187
179
  "is empty",
188
- name === "replace" ? EDIT_ISSUE_FIX.emptyReplace : EDIT_ISSUE_FIX.emptyBody,
180
+ name === "replace" ? EDIT_ISSUE_FIX.emptyReplace : EDIT_ISSUE_FIX.emptyLines,
189
181
  );
190
182
  }
191
- body.forEach((line, lineIndex) => {
183
+ lines.forEach((line, lineIndex) => {
192
184
  const unwritable = typeof line === "string" ? unwritableTextError(line) : undefined;
193
- if (unwritable) report(`${path}.body[${lineIndex}]`, unwritable.message);
185
+ if (unwritable) report(`${path}.lines[${lineIndex}]`, unwritable.message);
194
186
  });
195
187
  }
196
188
  const cited: { anchor?: number; end?: number } = {};
@@ -226,7 +218,7 @@ function checkEditArguments(
226
218
  }
227
219
 
228
220
  /**
229
- * Translate validated public operations into core edits, parsing numeric anchor
221
+ * Translate validated public operations into core steps, parsing numeric anchor
230
222
  * positions. Argument checks guarantee each op carries exactly the fields it takes.
231
223
  */
232
224
  function toCoreEdits(ops: readonly EditOpInput[]): Edit[] {
@@ -237,16 +229,16 @@ function toCoreEdits(ops: readonly EditOpInput[]): Edit[] {
237
229
  op: "replace",
238
230
  anchor: parseAnchor(op.anchor!),
239
231
  end: parseAnchor(op.end),
240
- body: op.body!,
232
+ body: op.lines!,
241
233
  };
242
234
  case "delete":
243
235
  return { op: "delete", anchor: parseAnchor(op.anchor!), end: parseAnchor(op.end) };
244
236
  case "insert_after":
245
237
  case "insert_before":
246
- return { op: op.action, anchor: parseAnchor(op.anchor!), body: op.body! };
238
+ return { op: op.action, anchor: parseAnchor(op.anchor!), body: op.lines! };
247
239
  case "append":
248
240
  case "prepend":
249
- return { op: op.action, body: op.body! };
241
+ return { op: op.action, body: op.lines! };
250
242
  }
251
243
  });
252
244
  }
@@ -255,14 +247,14 @@ function toCoreEdits(ops: readonly EditOpInput[]): Edit[] {
255
247
  function editHeader(args: EditParams, theme: Theme, counts?: DiffCounts): string {
256
248
  let t = theme.fg("toolTitle", theme.bold("edit "));
257
249
  t += formatHeaderPath(args.path, theme);
258
- const edits = Array.isArray(args.edits) ? args.edits : [];
259
- const n = edits.length;
250
+ const steps = Array.isArray(args.steps) ? args.steps : [];
251
+ const n = steps.length;
260
252
  if (n) {
261
253
  const opCounts: Record<string, number> = Object.fromEntries(
262
254
  [...EDIT_OP_NAMES, "unknown"].map((kind) => [kind, 0]),
263
255
  );
264
256
  // Renderers receive partial arguments; fixed buckets keep one-pass counting O(1) in space.
265
- for (const edit of edits) {
257
+ for (const edit of steps) {
266
258
  const kind = edit?.action;
267
259
  if (typeof kind === "string" && Object.hasOwn(opCounts, kind)) opCounts[kind]++;
268
260
  else opCounts.unknown++;
@@ -277,33 +269,26 @@ function editHeader(args: EditParams, theme: Theme, counts?: DiffCounts): string
277
269
  return t;
278
270
  }
279
271
 
280
- export function makeEditOverride(
281
- cwd: string,
282
- config: HashlineEditConfig,
283
- fusion?: ActionFusionExecutor,
284
- budgets: OutputBudgetProvider = defaultOutputBudgets,
285
- ) {
272
+ export function makeEditOverride(env: MutationToolEnvironment) {
286
273
  // Schema, verification, and recovery use the registered configuration.
287
- const { hashLen, shiftRadius } = config;
274
+ const { hashLen, shiftRadius } = env.config;
288
275
  const schema = buildEditSchema(hashLen);
289
276
 
290
277
  return {
291
278
  ...mutationToolBase({
279
+ ...env,
292
280
  tool: "edit",
293
- cwd,
294
- fusion,
295
- budgets,
296
281
  schema,
297
282
  description:
298
283
  "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
284
  promptSnippet: "Edit file lines using verified anchors",
300
285
  promptGuidelines: [
301
- "Batch all edits to one file into a single edit call.",
286
+ "Batch all steps for one file into a single edit call.",
302
287
  "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
288
  ],
304
289
  check: (args, report) =>
305
- checkEditArguments(args, hashLen, schema.properties.edits.items, report),
306
- run: (params, target) => runEdit(target, params.edits, hashLen, shiftRadius),
290
+ checkEditArguments(args, hashLen, schema.properties.steps.items, report),
291
+ run: (params, target) => runEdit(target, params.steps, hashLen, shiftRadius),
307
292
  }),
308
293
  ...diffCardRenderers("edit", "Editing…", editHeader),
309
294
  };
@@ -1,5 +1,10 @@
1
1
  import { errnoCode, HashlineError } from "../core/errors.ts";
2
2
 
3
+ export interface SearchWarning {
4
+ readonly path?: string;
5
+ readonly reason: string;
6
+ }
7
+
3
8
  /**
4
9
  * Cancellation, worded like Pi's built-in tools. A mutation report's
5
10
  * `publication` says where it stopped, so the message does not.
@@ -37,9 +42,9 @@ export function searchChangedError(): HashlineError<"FILE_CHANGED"> {
37
42
  * A per-file failure that leaves the rest of the search valid: a filesystem error, or the
38
43
  * file changing while it was searched or displayed. Undefined for any other failure.
39
44
  */
40
- export function fileReadWarning(filePath: string, error: unknown): string | undefined {
45
+ export function fileReadWarning(filePath: string, error: unknown): SearchWarning | undefined {
41
46
  if (!(error instanceof Error)) return undefined;
42
47
  const changed = error instanceof HashlineError && error.errorCode === "FILE_CHANGED";
43
48
  if (!changed && errnoCode(error) === undefined) return undefined;
44
- return `Could not read ${filePath}: ${error.message}`;
49
+ return { path: filePath, reason: error.message };
45
50
  }