@criogaid/pi-hashline-edit 0.10.0 → 0.12.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 (103) hide show
  1. package/README.md +21 -7
  2. package/README.zh-CN.md +22 -8
  3. package/package.json +7 -6
  4. package/src/core/AGENTS.md +2 -2
  5. package/src/core/apply.test.ts +4 -4
  6. package/src/core/apply.ts +3 -3
  7. package/src/core/character-set.test.ts +2 -3
  8. package/src/core/character-set.ts +1 -1
  9. package/src/core/ranges.test.ts +2 -1
  10. package/src/core/ranges.ts +1 -1
  11. package/src/core/regex.ts +6 -2
  12. package/src/core/replace.test.ts +51 -0
  13. package/src/core/replace.ts +10 -4
  14. package/src/core/types.ts +1 -1
  15. package/src/index.ts +9 -9
  16. package/src/integration/config-registration.test.ts +8 -10
  17. package/src/integration/fusion-dispatch.test.ts +2 -2
  18. package/src/integration/grep-errors.test.ts +3 -3
  19. package/src/integration/grep-flags.test.ts +5 -5
  20. package/src/integration/grep-js-completeness.test.ts +12 -11
  21. package/src/integration/grep-line-candidates.test.ts +5 -3
  22. package/src/integration/grep-matrix.test.ts +5 -4
  23. package/src/integration/grep-order.test.ts +4 -4
  24. package/src/integration/grep-path-matrix.test.ts +5 -4
  25. package/src/integration/grep-prefilter-coverage.test.ts +17 -5
  26. package/src/integration/grep-process-limits.test.ts +2 -4
  27. package/src/integration/grep-regex.test.ts +10 -10
  28. package/src/integration/grep-rg.test.ts +93 -48
  29. package/src/integration/grep-scan-budget.test.ts +8 -8
  30. package/src/integration/grep-translation.test.ts +8 -7
  31. package/src/integration/large-text.test.ts +5 -5
  32. package/src/integration/model-budget-lifecycle.test.ts +9 -9
  33. package/src/integration/mutation-file-types.testing.ts +4 -4
  34. package/src/integration/npm-package.test.ts +12 -10
  35. package/src/integration/npm-package.testing.ts +151 -4
  36. package/src/integration/publication-read-changes.test.ts +54 -54
  37. package/src/integration/read-changes.test.ts +4 -4
  38. package/src/integration/replace-worker-boundary.test.ts +1 -1
  39. package/src/integration/report-replay.test.ts +9 -6
  40. package/src/integration/utf8-errors.test.ts +4 -4
  41. package/src/pi/AGENTS.md +13 -12
  42. package/src/pi/action-fusion.test.ts +125 -105
  43. package/src/pi/action-fusion.testing.ts +38 -0
  44. package/src/pi/action-fusion.ts +9 -21
  45. package/src/pi/argument-diagnostics.ts +4 -3
  46. package/src/pi/argument-format.test.ts +19 -18
  47. package/src/pi/argument-validation.test.ts +281 -139
  48. package/src/pi/argument-validation.ts +21 -31
  49. package/src/pi/budgets.ts +1 -4
  50. package/src/pi/codemode.test.ts +7 -2
  51. package/src/pi/config.test.ts +2 -1
  52. package/src/pi/config.ts +8 -3
  53. package/src/pi/diagnostic-buffer.test.ts +23 -13
  54. package/src/pi/edit-tool.ts +48 -63
  55. package/src/pi/error-text.ts +7 -2
  56. package/src/pi/execute.test.ts +178 -157
  57. package/src/pi/failure-context.test.ts +5 -4
  58. package/src/pi/failure-context.ts +1 -1
  59. package/src/pi/failure-path.test.ts +37 -37
  60. package/src/pi/file-commit.test.ts +47 -19
  61. package/src/pi/file-commit.ts +36 -9
  62. package/src/pi/fusion-card.test.ts +22 -21
  63. package/src/pi/fusion-card.ts +9 -5
  64. package/src/pi/grep-candidates.test.ts +18 -20
  65. package/src/pi/grep-candidates.ts +13 -17
  66. package/src/pi/grep-matrix.test.ts +3 -3
  67. package/src/pi/grep-order.test.ts +12 -11
  68. package/src/pi/grep-output.ts +45 -17
  69. package/src/pi/grep-reread.ts +7 -2
  70. package/src/pi/grep-rg.testing.ts +70 -0
  71. package/src/pi/grep-scope.ts +10 -10
  72. package/src/pi/grep-search.ts +8 -11
  73. package/src/pi/grep-tool.ts +40 -53
  74. package/src/pi/grep.test.ts +141 -116
  75. package/src/pi/model-budgets.test.ts +2 -1
  76. package/src/pi/mutation-outcome.testing.ts +0 -1
  77. package/src/pi/mutation-result.test.ts +8 -8
  78. package/src/pi/mutation-result.ts +1 -1
  79. package/src/pi/mutation-runner.ts +10 -6
  80. package/src/pi/output-budgets.test.ts +53 -31
  81. package/src/pi/pi.test.ts +18 -13
  82. package/src/pi/read-tool.ts +13 -18
  83. package/src/pi/read.test.ts +67 -41
  84. package/src/pi/registration.test.ts +25 -19
  85. package/src/pi/render.test.ts +94 -32
  86. package/src/pi/render.ts +7 -4
  87. package/src/pi/replace-regex.ts +1 -1
  88. package/src/pi/replace-tool.ts +6 -16
  89. package/src/pi/replace.test.ts +45 -34
  90. package/src/pi/report-failure.testing.ts +9 -1
  91. package/src/pi/report-schema.ts +225 -86
  92. package/src/pi/report.test.ts +81 -87
  93. package/src/pi/report.ts +35 -22
  94. package/src/pi/result-safety.test.ts +121 -100
  95. package/src/pi/rg-process.test.ts +2 -2
  96. package/src/pi/rg-process.ts +9 -15
  97. package/src/pi/rg-regex.test.ts +13 -0
  98. package/src/pi/rg-regex.ts +2 -2
  99. package/src/pi/schema.ts +23 -0
  100. package/src/pi/tool-factories.testing.ts +59 -0
  101. package/src/pi/write-tool.ts +9 -15
  102. package/src/pi/write.test.ts +30 -31
  103. package/src/testing/run-tests.ts +1 -1
@@ -1,3 +1,4 @@
1
+ import { commandCompletion, type SessionCommand } from "./action-fusion.testing.ts";
1
2
  import { argumentError, rejectsArgument, rejectsArguments } from "./argument-error.testing.ts";
2
3
  /** Tool-level edit and shared mutation workflow tests. */
3
4
  import { test } from "node:test";
@@ -8,17 +9,18 @@ import { join } from "node:path";
8
9
  import { initTheme } from "@earendil-works/pi-coding-agent";
9
10
  import type { Theme } from "@earendil-works/pi-coding-agent";
10
11
  import { validateToolArguments } from "@earendil-works/pi-ai";
11
- import { makeEditOverride } from "./edit-tool.ts";
12
- import { makeReadOverride } from "./read-tool.ts";
13
- import { makeWriteOverride } from "./write-tool.ts";
14
- import { makeReplaceTool } from "./replace-tool.ts";
15
- import { makeGrepOverride } from "./grep-tool.ts";
12
+ import { makeEditOverride } from "./tool-factories.testing.ts";
13
+ import { makeReadOverride } from "./tool-factories.testing.ts";
14
+ import { makeWriteOverride } from "./tool-factories.testing.ts";
15
+ import { makeReplaceTool } from "./tool-factories.testing.ts";
16
+ import { makeGrepOverride } from "./tool-factories.testing.ts";
16
17
  import { createActionFusionExecutor } from "./action-fusion.ts";
17
18
  import { computeLineHash } from "../core/hash.ts";
18
19
  import { splitLines } from "../core/lines.ts";
19
20
  import { callTool } from "./tool-call.testing.ts";
20
- import { DEFAULT_CONFIG } from "./config.ts";
21
- import { formatByteSize, DEFAULT_OUTPUT_BUDGETS } from "./budgets.ts";
21
+ import { DEFAULT_CONFIG } from "./tool-factories.testing.ts";
22
+ import { formatByteSize } from "./budgets.ts";
23
+ import { DEFAULT_OUTPUT_BUDGETS } from "./tool-factories.testing.ts";
22
24
  import { detailsReport, reportOf } from "./report.ts";
23
25
  import type { Report } from "./report-schema.ts";
24
26
  import type { AgentToolResult } from "@earendil-works/pi-agent-core";
@@ -49,9 +51,15 @@ function anchorLine(block: string, line: number) {
49
51
  return `${line}#${m[1]}`;
50
52
  }
51
53
 
52
- function failureReport(result: AgentToolResult<unknown> & { isError?: boolean }): Report {
54
+ function failureReport(
55
+ result: AgentToolResult<unknown> & { isError?: boolean },
56
+ tool = "edit",
57
+ ): Report {
53
58
  assert.equal(result.isError, true);
54
- const report = detailsReport(result.details);
59
+ assert.ok(
60
+ tool === "edit" || tool === "replace" || tool === "write" || tool === "read" || tool === "grep",
61
+ );
62
+ const report = detailsReport(result.details, tool);
55
63
  assert.ok(report?.error);
56
64
  return report;
57
65
  }
@@ -77,7 +85,7 @@ test("edit execute: a file without a final newline stays byte-exact", async () =
77
85
  await call(makeReadOverride(dir, DEFAULT_CONFIG), { path: "f.txt" });
78
86
  const r: any = await call(makeEditOverride(dir, DEFAULT_CONFIG), {
79
87
  path: "f.txt",
80
- edits: [{ action: "replace", anchor: h(text, 2), body: ["new value\u2060"] }],
88
+ steps: [{ action: "replace", anchor: h(text, 2), lines: ["new value\u2060"] }],
81
89
  });
82
90
  assert.equal(r.isError, undefined, "should not be an error");
83
91
  assert.equal(await readFile(f, "utf-8"), "guard\nnew value\u2060");
@@ -92,7 +100,7 @@ test("edit execute: hashline round-trip (read → edit → file changed)", async
92
100
  const read = await call(makeReadOverride(dir, DEFAULT_CONFIG), { path: "f.txt" });
93
101
  const r: any = await call(makeEditOverride(dir, DEFAULT_CONFIG), {
94
102
  path: "f.txt",
95
- edits: [{ action: "replace", anchor: anchorLine(read.content[0].text, 2), body: ["B"] }],
103
+ steps: [{ action: "replace", anchor: anchorLine(read.content[0].text, 2), lines: ["B"] }],
96
104
  });
97
105
  assert.equal(r.isError, undefined, "should not be an error");
98
106
  assert.equal(await readFile(f, "utf-8"), "a\nB\nc\n");
@@ -120,12 +128,12 @@ test("successful mutation → returns one report without anchor payload", async
120
128
  instance: makeEditOverride(dir, DEFAULT_CONFIG),
121
129
  params: {
122
130
  path,
123
- edits: [
131
+ steps: [
124
132
  {
125
133
  action: "replace",
126
134
  anchor: anchorLine(rows, 1),
127
135
  end: anchorLine(rows, count),
128
- body: Array.from({ length: count }, () => "new"),
136
+ lines: Array.from({ length: count }, () => "new"),
129
137
  },
130
138
  ],
131
139
  },
@@ -170,7 +178,7 @@ test("edit on a line that changed externally → anchor mismatch", async () => {
170
178
  const report = failureReport(
171
179
  await call(makeEditOverride(dir, DEFAULT_CONFIG), {
172
180
  path: "f.txt",
173
- edits: [{ action: "replace", anchor: h(text, 2), body: ["x"] }],
181
+ steps: [{ action: "replace", anchor: h(text, 2), lines: ["x"] }],
174
182
  }),
175
183
  );
176
184
  assert.equal(report.error, "ANCHOR_MISMATCH");
@@ -191,7 +199,7 @@ test("unresolved observations require target confirmation before retrying a move
191
199
  const report = failureReport(
192
200
  await call(edit, {
193
201
  path: "recover.txt",
194
- edits: [{ action: "replace", anchor: h(observed, 5), body: ["updated"] }],
202
+ steps: [{ action: "replace", anchor: h(observed, 5), lines: ["updated"] }],
195
203
  }),
196
204
  );
197
205
  assert.equal(report.error, "ANCHOR_MISMATCH");
@@ -202,7 +210,7 @@ test("unresolved observations require target confirmation before retrying a move
202
210
  const retryAnchor = anchorLine(read.content[0].text, 7);
203
211
  await call(edit, {
204
212
  path: "recover.txt",
205
- edits: [{ action: "replace", anchor: retryAnchor, body: ["updated"] }],
213
+ steps: [{ action: "replace", anchor: retryAnchor, lines: ["updated"] }],
206
214
  });
207
215
  assert.equal(
208
216
  await readFile(file, "utf8"),
@@ -219,7 +227,7 @@ test("edit execute: delete op", async () => {
219
227
  await call(makeReadOverride(dir, DEFAULT_CONFIG), { path: "f.txt" });
220
228
  const r: any = await call(makeEditOverride(dir, DEFAULT_CONFIG), {
221
229
  path: "f.txt",
222
- edits: [{ action: "delete", anchor: h(text, 2) }],
230
+ steps: [{ action: "delete", anchor: h(text, 2) }],
223
231
  });
224
232
  assert.equal(r.isError, undefined);
225
233
  assert.equal(await readFile(f, "utf-8"), "a\nc\n");
@@ -275,23 +283,23 @@ test("edit schema rejects misspelled range fields and invalid operation shapes",
275
283
  const anchor = h(original, 2);
276
284
  const callArgs = {
277
285
  path: "range.txt",
278
- edits: [{ action: "replace", anchor, endd: h(original, 3), body: ["merged"] }],
286
+ steps: [{ action: "replace", anchor, endd: h(original, 3), lines: ["merged"] }],
279
287
  };
280
- await assert.rejects(call(edit, callArgs), rejectsArgument("edits[0].endd", /not allowed/));
288
+ await assert.rejects(call(edit, callArgs), rejectsArgument("steps[0].endd", /not allowed/));
281
289
  assert.equal(await readFile(join(dir, "range.txt"), "utf8"), original);
282
- for (const [edits, expected] of [
283
- [[], rejectsArgument("edits")],
284
- [[{ action: "replace", anchor }], rejectsArgument("edits[0].body", /required/)],
285
- [[{ action: "delete", anchor, body: ["bad"] }], rejectsArguments()],
286
- [[{ action: "insert_after", body: ["bad"] }], rejectsArguments()],
287
- [[{ action: "append", anchor, body: ["bad"] }], rejectsArguments()],
290
+ for (const [steps, expected] of [
291
+ [[], rejectsArgument("steps")],
292
+ [[{ action: "replace", anchor }], rejectsArgument("steps[0].lines", /required/)],
293
+ [[{ action: "delete", anchor, lines: ["bad"] }], rejectsArguments()],
294
+ [[{ action: "insert_after", lines: ["bad"] }], rejectsArguments()],
295
+ [[{ action: "append", anchor, lines: ["bad"] }], rejectsArguments()],
288
296
  ] as const) {
289
- await assert.rejects(call(edit, { path: "range.txt", edits }), expected);
297
+ await assert.rejects(call(edit, { path: "range.txt", steps }), expected);
290
298
  assert.equal(await readFile(join(dir, "range.txt"), "utf8"), original);
291
299
  }
292
300
  const alternates: Parameters<typeof validateToolArguments>[1]["arguments"][] = [
293
- { path: "range.txt", action: "replace", anchor, body: ["ok"] },
294
- { path: "range.txt", edits: JSON.stringify([{ action: "replace", anchor, body: ["ok"] }]) },
301
+ { path: "range.txt", action: "replace", anchor, lines: ["ok"] },
302
+ { path: "range.txt", steps: JSON.stringify([{ action: "replace", anchor, lines: ["ok"] }]) },
295
303
  ];
296
304
  for (const alternate of alternates) {
297
305
  const before = structuredClone(alternate);
@@ -299,7 +307,7 @@ test("edit schema rejects misspelled range fields and invalid operation shapes",
299
307
  assert.deepEqual(alternate, before);
300
308
  assert.equal(await readFile(join(dir, "range.txt"), "utf8"), original);
301
309
  }
302
- await call(edit, { path: "range.txt", edits: [{ action: "replace", anchor, body: ["B"] }] });
310
+ await call(edit, { path: "range.txt", steps: [{ action: "replace", anchor, lines: ["B"] }] });
303
311
  assert.equal(await readFile(join(dir, "range.txt"), "utf8"), "a\nB\nc\n");
304
312
  }));
305
313
 
@@ -315,12 +323,12 @@ test("copied string anchors validate and replace an inclusive range", async () =
315
323
  name: "edit",
316
324
  arguments: {
317
325
  path: "range.txt",
318
- edits: [
326
+ steps: [
319
327
  {
320
328
  action: "replace",
321
329
  anchor: anchorLine(read.content[0].text, 2),
322
330
  end: anchorLine(read.content[0].text, 3),
323
- body: ["merged"],
331
+ lines: ["merged"],
324
332
  },
325
333
  ],
326
334
  },
@@ -336,17 +344,17 @@ test("invalid anchors and conflicting fields fail before changing the file", asy
336
344
  const edit = makeEditOverride(dir, DEFAULT_CONFIG);
337
345
  const anchor = h(original, 1);
338
346
  const invalid = [
339
- { action: "replace", anchor: { line: 1, hash: anchor.split("#")[1] }, body: ["changed"] },
347
+ { action: "replace", anchor: { line: 1, hash: anchor.split("#")[1] }, lines: ["changed"] },
340
348
  ...["0#ABCD", "-1#ABCD", "1.5#ABCD", "1#", "1#abcd", "1#ABCD│a", "9007199254740993#ABCD"].map(
341
- (anchor) => ({ action: "replace", anchor, body: ["changed"] }),
349
+ (anchor) => ({ action: "replace", anchor, lines: ["changed"] }),
342
350
  ),
343
- { action: "insert_after", anchor, end: anchor, body: ["changed"] },
344
- { action: "append", anchor, body: ["changed"] },
345
- { action: "delete", anchor, body: ["changed"] },
351
+ { action: "insert_after", anchor, end: anchor, lines: ["changed"] },
352
+ { action: "append", anchor, lines: ["changed"] },
353
+ { action: "delete", anchor, lines: ["changed"] },
346
354
  ];
347
355
  for (const operation of invalid) {
348
356
  await assert.rejects(
349
- call(edit, { path: "invalid.txt", edits: [operation] }),
357
+ call(edit, { path: "invalid.txt", steps: [operation] }),
350
358
  /INVALID_ARGUMENTS|Invalid anchor/,
351
359
  );
352
360
  assert.equal(await readFile(join(dir, "invalid.txt"), "utf8"), original);
@@ -361,17 +369,17 @@ test("edit rejects empty bodies before file access for arrays and Pi-converted o
361
369
  const edit = makeEditOverride(dir, DEFAULT_CONFIG);
362
370
  const anchor = h(original, 1);
363
371
  for (const operation of [
364
- { action: "insert_after", anchor, body: [] },
365
- { action: "insert_before", anchor, body: [] },
366
- { action: "append", body: [] },
367
- { action: "prepend", body: [] },
368
- { action: "replace", anchor, end: h(original, 2), body: [] },
372
+ { action: "insert_after", anchor, lines: [] },
373
+ { action: "insert_before", anchor, lines: [] },
374
+ { action: "append", lines: [] },
375
+ { action: "prepend", lines: [] },
376
+ { action: "replace", anchor, end: h(original, 2), lines: [] },
369
377
  ]) {
370
378
  for (const path of [file, join(dir, "missing.txt")]) {
371
- for (const edits of [[operation], operation]) {
379
+ for (const steps of [[operation], operation]) {
372
380
  await assert.rejects(
373
- call(edit, { path, edits }),
374
- rejectsArgument("edits[0].body", /empty/),
381
+ call(edit, { path, steps }),
382
+ rejectsArgument("steps[0].lines", /empty/),
375
383
  );
376
384
  assert.equal(await readFile(file, "utf8"), original);
377
385
  }
@@ -379,36 +387,37 @@ test("edit rejects empty bodies before file access for arrays and Pi-converted o
379
387
  }
380
388
  }));
381
389
 
382
- test("mixed empty-body batches name every rejected edit without publishing or running commands", async () =>
390
+ test("mixed empty-lines batches name every rejected edit without publishing or running commands", async () =>
383
391
  withDir(async (dir) => {
384
392
  const file = join(dir, "batch.txt");
385
393
  const original = "a\nb\nc\nd\ne\n";
386
394
  await writeFile(file, original);
387
395
  let commandRuns = 0;
388
- const fusion = createActionFusionExecutor(async () => {
396
+ const executeTool: SessionCommand = async () => {
389
397
  commandRuns++;
390
- return { status: "succeeded", result: { content: [{ type: "text", text: "ran" }] } };
391
- });
398
+ return commandCompletion({ content: [{ type: "text", text: "ran" }] });
399
+ };
400
+ const fusion = createActionFusionExecutor(() => {});
392
401
  const edit = makeEditOverride(dir, DEFAULT_CONFIG, fusion);
393
402
  await assert.rejects(
394
403
  callTool(
395
404
  edit,
396
405
  {
397
406
  path: file,
398
- edits: [
399
- { action: "replace", anchor: h(original, 1), body: ["must not be written"] },
400
- { action: "insert_before", anchor: h(original, 3), body: [] },
401
- { action: "append", body: ["must not be written"] },
402
- { action: "replace", anchor: h(original, 4), body: [] },
407
+ steps: [
408
+ { action: "replace", anchor: h(original, 1), lines: ["must not be written"] },
409
+ { action: "insert_before", anchor: h(original, 3), lines: [] },
410
+ { action: "append", lines: ["must not be written"] },
411
+ { action: "replace", anchor: h(original, 4), lines: [] },
403
412
  ],
404
413
  then_run: { command: "must-not-run" },
405
414
  },
406
- { ctx: { cwd: dir } },
415
+ { ctx: { ...{ cwd: dir }, executeTool } },
407
416
  ),
408
417
  (error: Error) => {
409
418
  const issues = argumentError(error).issues;
410
- assert.match(issues.find((issue) => issue.field === "edits[1].body")?.fix ?? "", /\[""\]/);
411
- assert.match(issues.find((issue) => issue.field === "edits[3].body")?.fix ?? "", /delete/);
419
+ assert.match(issues.find((issue) => issue.field === "steps[1].lines")?.fix ?? "", /\[""\]/);
420
+ assert.match(issues.find((issue) => issue.field === "steps[3].lines")?.fix ?? "", /delete/);
412
421
  return true;
413
422
  },
414
423
  );
@@ -416,21 +425,21 @@ test("mixed empty-body batches name every rejected edit without publishing or ru
416
425
  assert.equal(commandRuns, 0);
417
426
  }));
418
427
 
419
- test("blank edit bodies preserve a real blank line for every body-bearing operation", async () =>
428
+ test("blank edit lines preserve a real blank line for every line-bearing operation", async () =>
420
429
  withDir(async (dir) => {
421
430
  const file = join(dir, "blank_line.txt");
422
431
  const original = "a\nb\nc\n";
423
432
  const anchor = h(original, 1);
424
433
  const edit = makeEditOverride(dir, DEFAULT_CONFIG);
425
434
  for (const [operation, expected] of [
426
- [{ action: "replace", anchor, body: [""] }, "\nb\nc\n"],
427
- [{ action: "insert_before", anchor, body: [""] }, "\na\nb\nc\n"],
428
- [{ action: "insert_after", anchor, body: [""] }, "a\n\nb\nc\n"],
429
- [{ action: "append", body: [""] }, "a\nb\nc\n\n"],
430
- [{ action: "prepend", body: [""] }, "\na\nb\nc\n"],
435
+ [{ action: "replace", anchor, lines: [""] }, "\nb\nc\n"],
436
+ [{ action: "insert_before", anchor, lines: [""] }, "\na\nb\nc\n"],
437
+ [{ action: "insert_after", anchor, lines: [""] }, "a\n\nb\nc\n"],
438
+ [{ action: "append", lines: [""] }, "a\nb\nc\n\n"],
439
+ [{ action: "prepend", lines: [""] }, "\na\nb\nc\n"],
431
440
  ] as const) {
432
441
  await writeFile(file, original);
433
- await call(edit, { path: file, edits: [operation] });
442
+ await call(edit, { path: file, steps: [operation] });
434
443
  assert.equal(await readFile(file, "utf8"), expected);
435
444
  }
436
445
  }));
@@ -442,7 +451,7 @@ test("explicit delete → removes an inclusive range", async () =>
442
451
  await writeFile(file, original);
443
452
  await call(makeEditOverride(dir, DEFAULT_CONFIG), {
444
453
  path: file,
445
- edits: [{ action: "delete", anchor: h(original, 1), end: h(original, 2) }],
454
+ steps: [{ action: "delete", anchor: h(original, 1), end: h(original, 2) }],
446
455
  });
447
456
  assert.equal(await readFile(file, "utf8"), "c\n");
448
457
  }));
@@ -458,7 +467,7 @@ test("local and full-file recovery return copyable anchors without changing the
458
467
  const report = failureReport(
459
468
  await call(edit, {
460
469
  path: "shift.txt",
461
- edits: [{ action: "replace", anchor: h(original, 2), body: ["B"] }],
470
+ steps: [{ action: "replace", anchor: h(original, 2), lines: ["B"] }],
462
471
  }),
463
472
  );
464
473
  const failure = report.failures?.[0];
@@ -471,7 +480,7 @@ test("local and full-file recovery return copyable anchors without changing the
471
480
  assert.equal(await readFile(join(dir, "shift.txt"), "utf8"), prefix + original);
472
481
  await call(edit, {
473
482
  path: "shift.txt",
474
- edits: [{ action: "replace", anchor: replacement, body: ["B"] }],
483
+ steps: [{ action: "replace", anchor: replacement, lines: ["B"] }],
475
484
  });
476
485
  assert.equal(await readFile(join(dir, "shift.txt"), "utf8"), prefix + "a\nB\n");
477
486
  }
@@ -486,7 +495,7 @@ test("shifted-anchor recovery keeps the read fallback for oversized candidates",
486
495
  const report = failureReport(
487
496
  await call(edit, {
488
497
  path: "shift-large.txt",
489
- edits: [{ action: "replace", anchor: h(original, 2), body: ["B"] }],
498
+ steps: [{ action: "replace", anchor: h(original, 2), lines: ["B"] }],
490
499
  }),
491
500
  );
492
501
  assert.match(
@@ -500,12 +509,15 @@ test("shifted-anchor recovery keeps the read fallback for oversized candidates",
500
509
  test("failed commands preserve mutation results and stay out of all main card renderers", async () =>
501
510
  withDir(async (dir) => {
502
511
  const commands: string[] = [];
503
- const fusion = createActionFusionExecutor(
504
- async () => {
505
- throw new Error("command-only diagnostic\nCommand exited with code 7");
506
- },
507
- (event) => commands.push(event.command),
508
- );
512
+ const executeTool: SessionCommand = async () => {
513
+ return commandCompletion(
514
+ {
515
+ content: [{ type: "text", text: "command-only diagnostic\nCommand exited with code 7" }],
516
+ },
517
+ true,
518
+ );
519
+ };
520
+ const fusion = createActionFusionExecutor((event) => commands.push(event.command));
509
521
  const cases = [
510
522
  {
511
523
  path: "edit.txt",
@@ -513,18 +525,16 @@ test("failed commands preserve mutation results and stay out of all main card re
513
525
  const tool = makeEditOverride(dir, DEFAULT_CONFIG, fusion);
514
526
  const args = {
515
527
  path: "edit.txt",
516
- edits: [{ action: "append" as const, body: ["after"] }],
528
+ steps: [{ action: "append" as const, lines: ["after"] }],
517
529
  };
518
530
  const result = await callTool(
519
531
  tool,
520
532
  { ...args, then_run: { command: "check" } },
521
- {
522
- toolCallId: args.path,
523
- ctx: { cwd: dir },
524
- },
533
+ { toolCallId: args.path, ctx: { ...{ cwd: dir }, executeTool } },
525
534
  );
526
535
  return {
527
536
  result,
537
+ tool: tool.name,
528
538
  rendered: tool
529
539
  .renderResult(
530
540
  result,
@@ -551,13 +561,11 @@ test("failed commands preserve mutation results and stay out of all main card re
551
561
  const result = await callTool(
552
562
  tool,
553
563
  { ...args, then_run: { command: "check" } },
554
- {
555
- toolCallId: args.path,
556
- ctx: { cwd: dir },
557
- },
564
+ { toolCallId: args.path, ctx: { ...{ cwd: dir }, executeTool } },
558
565
  );
559
566
  return {
560
567
  result,
568
+ tool: tool.name,
561
569
  rendered: tool
562
570
  .renderResult(
563
571
  result,
@@ -581,13 +589,11 @@ test("failed commands preserve mutation results and stay out of all main card re
581
589
  const result = await callTool(
582
590
  tool,
583
591
  { ...args, then_run: { command: "check" } },
584
- {
585
- toolCallId: args.path,
586
- ctx: { cwd: dir },
587
- },
592
+ { toolCallId: args.path, ctx: { ...{ cwd: dir }, executeTool } },
588
593
  );
589
594
  return {
590
595
  result,
596
+ tool: tool.name,
591
597
  rendered: tool
592
598
  .renderResult(result, { expanded: true, isPartial: false }, stubTheme as Theme, {
593
599
  args,
@@ -597,6 +603,10 @@ test("failed commands preserve mutation results and stay out of all main card re
597
603
  invalidate() {},
598
604
  lastComponent: undefined,
599
605
  executionStarted: true,
606
+ durationMs: undefined,
607
+ outputPad: 1,
608
+ keyText: () => "",
609
+ keyHint: (_key, description) => description,
600
610
  argsComplete: true,
601
611
  isPartial: false,
602
612
  expanded: true,
@@ -612,9 +622,16 @@ test("failed commands preserve mutation results and stay out of all main card re
612
622
  ];
613
623
  for (const { path, run, expected } of cases) {
614
624
  await writeFile(join(dir, path), "before\n");
615
- const { result, rendered } = await run();
625
+ const { result, rendered, tool } = await run();
616
626
  assert.equal("isError" in result, false);
617
- const report = detailsReport(result.details);
627
+ assert.ok(
628
+ tool === "edit" ||
629
+ tool === "replace" ||
630
+ tool === "write" ||
631
+ tool === "read" ||
632
+ tool === "grep",
633
+ );
634
+ const report = detailsReport(result.details, tool);
618
635
  assert.equal(report?.publication, "PUBLISHED");
619
636
  const last = result.content.at(-1);
620
637
  assert.ok(last?.type === "text");
@@ -643,7 +660,7 @@ test("missing or directory targets → tools share path diagnostics without file
643
660
  { tool: makeReadOverride(dir, DEFAULT_CONFIG), args: { path } },
644
661
  {
645
662
  tool: makeEditOverride(dir, DEFAULT_CONFIG),
646
- args: { path, edits: [{ action: "append", body: ["changed"] }] },
663
+ args: { path, steps: [{ action: "append", lines: ["changed"] }] },
647
664
  },
648
665
  {
649
666
  tool: makeReplaceTool(dir, DEFAULT_CONFIG),
@@ -661,7 +678,7 @@ test("missing or directory targets → tools share path diagnostics without file
661
678
  ];
662
679
  for (const { tool, args } of cases) {
663
680
  await t.test(`${tool.name}/${target.name}`, async () => {
664
- const report = failureReport(await callTool(tool, args));
681
+ const report = failureReport(await callTool(tool, args), tool.name);
665
682
  assert.equal(report.error, target.code);
666
683
  assert.equal(report.message, PATH_ERROR_MESSAGES[target.code]);
667
684
  if (target.code === "PATH_NOT_FOUND") {
@@ -692,14 +709,14 @@ test("text tools reject malformed UTF-8 and NUL bytes without rewriting source b
692
709
  [makeReadOverride(dir, DEFAULT_CONFIG), { path: "invalid-utf8.txt" }],
693
710
  [
694
711
  makeEditOverride(dir, DEFAULT_CONFIG),
695
- { path: "invalid-utf8.txt", edits: [{ action: "append", body: ["x"] }] },
712
+ { path: "invalid-utf8.txt", steps: [{ action: "append", lines: ["x"] }] },
696
713
  ],
697
714
  [
698
715
  makeReplaceTool(dir, DEFAULT_CONFIG),
699
716
  { path: "invalid-utf8.txt", replacements: [{ literal: true, find: "a", replace: "b" }] },
700
717
  ],
701
718
  ] as const) {
702
- assert.equal(failureReport(await call(tool, args)).error, "UNSUPPORTED_ENCODING");
719
+ assert.equal(failureReport(await call(tool, args), tool.name).error, "UNSUPPORTED_ENCODING");
703
720
  }
704
721
  assert.deepEqual(await readFile(target), original);
705
722
 
@@ -709,14 +726,14 @@ test("text tools reject malformed UTF-8 and NUL bytes without rewriting source b
709
726
  for (const [tool, args] of [
710
727
  [
711
728
  makeEditOverride(dir, DEFAULT_CONFIG),
712
- { path: "nul.txt", edits: [{ action: "append", body: ["x"] }] },
729
+ { path: "nul.txt", steps: [{ action: "append", lines: ["x"] }] },
713
730
  ],
714
731
  [
715
732
  makeReplaceTool(dir, DEFAULT_CONFIG),
716
733
  { path: "nul.txt", replacements: [{ literal: true, find: "a", replace: "b" }] },
717
734
  ],
718
735
  ] as const) {
719
- assert.equal(failureReport(await call(tool, args)).error, "UNSUPPORTED_TEXT");
736
+ assert.equal(failureReport(await call(tool, args), tool.name).error, "UNSUPPORTED_TEXT");
720
737
  }
721
738
  assert.deepEqual(await readFile(nulTarget), nulOriginal);
722
739
 
@@ -726,7 +743,10 @@ test("text tools reject malformed UTF-8 and NUL bytes without rewriting source b
726
743
  const utf16Target = join(dir, "utf16.txt");
727
744
  await writeFile(utf16Target, Buffer.from([0xff, 0xfe, 0x49, 0x6c]));
728
745
  assert.equal(
729
- failureReport(await call(makeReadOverride(dir, DEFAULT_CONFIG), { path: "utf16.txt" })).error,
746
+ failureReport(
747
+ await call(makeReadOverride(dir, DEFAULT_CONFIG), { path: "utf16.txt" }),
748
+ "read",
749
+ ).error,
730
750
  "UNSUPPORTED_ENCODING",
731
751
  );
732
752
  }));
@@ -739,7 +759,7 @@ test("edit rejects embedded line terminators at its schema boundary", async () =
739
759
  await assert.rejects(
740
760
  call(makeEditOverride(dir, DEFAULT_CONFIG), {
741
761
  path: "body.txt",
742
- edits: [{ action: "append", body: [line] }],
762
+ steps: [{ action: "append", lines: [line] }],
743
763
  }),
744
764
  rejectsArguments(),
745
765
  );
@@ -751,14 +771,14 @@ test("edit rejects unwritable body lines before reading a missing target", async
751
771
  withDir(async (dir) => {
752
772
  const target = join(dir, "missing.txt");
753
773
  const edit = makeEditOverride(dir, DEFAULT_CONFIG);
754
- const valid = { path: target, edits: [{ action: "append" as const, body: ["ok"] }] };
774
+ const valid = { path: target, steps: [{ action: "append" as const, lines: ["ok"] }] };
755
775
  assert.equal(edit.prepareArguments(valid), valid);
756
776
  for (const [line, expected] of [
757
- ["bad\0", rejectsArgument("edits[0].body[1]", /NUL/)],
758
- ["\ud800", rejectsArgument("edits[0].body[1]", /losslessly.*UTF-8/)],
777
+ ["bad\0", rejectsArgument("steps[0].lines[1]", /NUL/)],
778
+ ["\ud800", rejectsArgument("steps[0].lines[1]", /losslessly.*UTF-8/)],
759
779
  ] as const) {
760
780
  await assert.rejects(
761
- call(edit, { path: target, edits: [{ action: "append", body: ["ok", line] }] }),
781
+ call(edit, { path: target, steps: [{ action: "append", lines: ["ok", line] }] }),
762
782
  expected,
763
783
  );
764
784
  await assert.rejects(readFile(target, "utf8"), { code: "ENOENT" });
@@ -774,7 +794,7 @@ test("editing a BOM-prefixed file → publishes the changed bytes with the BOM i
774
794
  await writeFile(target, original);
775
795
  const result = await call(makeEditOverride(dir, DEFAULT_CONFIG), {
776
796
  path: "bom.txt",
777
- edits: [{ action: "replace", anchor: h(source, line), body: ["new"] }],
797
+ steps: [{ action: "replace", anchor: h(source, line), lines: ["new"] }],
778
798
  });
779
799
  const expected = Buffer.from(line === 1 ? "\ufeffnew\nold\n" : "\ufeffguard\nnew\n", "utf8");
780
800
  assert.deepEqual(await readFile(target), expected);
@@ -791,9 +811,9 @@ test("edit and replace reject NUL arguments without rewriting source bytes", asy
791
811
  await assert.rejects(
792
812
  call(makeEditOverride(dir, DEFAULT_CONFIG), {
793
813
  path: "output.txt",
794
- edits: [{ action: "append", body: ["bad\0text"] }],
814
+ steps: [{ action: "append", lines: ["bad\0text"] }],
795
815
  }),
796
- rejectsArgument("edits[0].body[0]", /NUL/),
816
+ rejectsArgument("steps[0].lines[0]", /NUL/),
797
817
  );
798
818
  assert.deepEqual(await readFile(target), original);
799
819
  await assert.rejects(
@@ -806,7 +826,7 @@ test("edit and replace reject NUL arguments without rewriting source bytes", asy
806
826
  assert.deepEqual(await readFile(target), original);
807
827
  }));
808
828
 
809
- test("failed edits return candidate code for a verified fused retry", async () =>
829
+ test("failed steps return candidate code for a verified fused retry", async () =>
810
830
  withDir(async (dir) => {
811
831
  const original = Array.from({ length: 14 }, (_, index) => `line-${index + 1}`);
812
832
  original[4] = "if (!fusion) throw new Error();";
@@ -815,10 +835,11 @@ test("failed edits return candidate code for a verified fused retry", async () =
815
835
  const file = join(dir, "candidate.txt");
816
836
  await writeFile(file, before);
817
837
  let commands = 0;
818
- const fusion = createActionFusionExecutor(async () => {
838
+ const executeTool: SessionCommand = async () => {
819
839
  commands++;
820
- return { status: "succeeded", result: { content: [{ type: "text", text: "checked" }] } };
821
- });
840
+ return commandCompletion({ content: [{ type: "text", text: "checked" }] });
841
+ };
842
+ const fusion = createActionFusionExecutor(() => {});
822
843
  const edit = makeEditOverride(dir, DEFAULT_CONFIG, fusion);
823
844
  const stale = h(original.join("\n"), 5);
824
845
  const stable = h(before, 12);
@@ -828,18 +849,18 @@ test("failed edits return candidate code for a verified fused retry", async () =
828
849
  edit,
829
850
  {
830
851
  path: file,
831
- edits: [
832
- { action: "insert_after", anchor: stale, body: ["const hashLen = 4;"] },
833
- { action: "replace", anchor: stable, body: ["changed"] },
852
+ steps: [
853
+ { action: "insert_after", anchor: stale, lines: ["const hashLen = 4;"] },
854
+ { action: "replace", anchor: stable, lines: ["changed"] },
834
855
  ],
835
856
  then_run: { command: "check" },
836
857
  },
837
- { toolCallId: "failed", ctx: { cwd: dir } },
858
+ { toolCallId: "failed", ctx: { ...{ cwd: dir }, executeTool } },
838
859
  ),
839
860
  );
840
861
  assert.equal(report.then_run?.status, "skipped");
841
862
  assert.equal(report.publication, "NOT_PUBLISHED");
842
- assert.equal(report.failures?.[0].field, "edits[0].anchor");
863
+ assert.equal(report.failures?.[0].field, "steps[0].anchor");
843
864
  assert.equal(report.failures?.[0].cited, stale);
844
865
  assert.equal(report.failures?.[0].candidate, candidate);
845
866
  assert.equal(report.failures?.[0].content, original[4]);
@@ -851,17 +872,17 @@ test("failed edits return candidate code for a verified fused retry", async () =
851
872
  edit,
852
873
  {
853
874
  path: file,
854
- edits: [
875
+ steps: [
855
876
  {
856
877
  action: "insert_after",
857
878
  anchor: report.failures![0].candidate!,
858
- body: ["const hashLen = 4;"],
879
+ lines: ["const hashLen = 4;"],
859
880
  },
860
- { action: "replace", anchor: stable, body: ["changed"] },
881
+ { action: "replace", anchor: stable, lines: ["changed"] },
861
882
  ],
862
883
  then_run: { command: "check" },
863
884
  },
864
- { toolCallId: "retry", ctx: { cwd: dir } },
885
+ { toolCallId: "retry", ctx: { ...{ cwd: dir }, executeTool } },
865
886
  );
866
887
  const expected = splitLines(before);
867
888
  expected[11] = "changed";
@@ -884,11 +905,11 @@ test("ambiguous candidates include distinguishing neighborhoods for a verified r
884
905
  const report = failureReport(
885
906
  await call(edit, {
886
907
  path: file,
887
- edits: [
908
+ steps: [
888
909
  {
889
910
  action: "replace",
890
911
  anchor: h("header\n return value;\n", 2),
891
- body: [" return updated;"],
912
+ lines: [" return updated;"],
892
913
  },
893
914
  ],
894
915
  }),
@@ -906,7 +927,7 @@ test("ambiguous candidates include distinguishing neighborhoods for a verified r
906
927
  assert.equal(await readFile(file, "utf8"), before);
907
928
  await call(edit, {
908
929
  path: file,
909
- edits: [{ action: "replace", anchor: anchorLine(context, 15), body: [" return updated;"] }],
930
+ steps: [{ action: "replace", anchor: anchorLine(context, 15), lines: [" return updated;"] }],
910
931
  });
911
932
  lines[14] = " return updated;";
912
933
  assert.equal(await readFile(file, "utf8"), lines.join("\n") + "\n");
@@ -920,14 +941,14 @@ test("schema-invalid bodies reject before anchor verification; retries revalidat
920
941
  const edit = makeEditOverride(dir, DEFAULT_CONFIG);
921
942
  const stable = h(before, 1);
922
943
  for (const operation of [
923
- { action: "replace", anchor: stable, body: ["bad\nline"] },
924
- { action: "append", body: ["bad\nline"] },
944
+ { action: "replace", anchor: stable, lines: ["bad\nline"] },
945
+ { action: "append", lines: ["bad\nline"] },
925
946
  ]) {
926
947
  for (const laterAnchor of [h(before, 2), "2#XXXX"]) {
927
948
  await assert.rejects(
928
949
  call(edit, {
929
950
  path: file,
930
- edits: [operation, { action: "replace", anchor: laterAnchor, body: ["B"] }],
951
+ steps: [operation, { action: "replace", anchor: laterAnchor, lines: ["B"] }],
931
952
  }),
932
953
  (error: Error) => {
933
954
  rejectsArguments()(error);
@@ -942,54 +963,54 @@ test("schema-invalid bodies reject before anchor verification; retries revalidat
942
963
  const rejected = failureReport(
943
964
  await call(edit, {
944
965
  path: file,
945
- edits: [
946
- { action: "replace", anchor: stable, body: ["A"] },
966
+ steps: [
967
+ { action: "replace", anchor: stable, lines: ["A"] },
947
968
  { action: "delete", anchor: h(before, 2), end: "3#ZZZZ" },
948
969
  ],
949
970
  }),
950
971
  );
951
- assert.equal(rejected.failures?.[0].field, "edits[1].end");
972
+ assert.equal(rejected.failures?.[0].field, "steps[1].end");
952
973
  assert.equal(rejected.failures?.[0].cited, "3#ZZZZ");
953
974
  assert.equal(await readFile(file, "utf8"), before);
954
975
  await writeFile(file, "changed\nb\nc\n");
955
976
  const retry = failureReport(
956
977
  await call(edit, {
957
978
  path: file,
958
- edits: [
959
- { action: "replace", anchor: stable, body: ["A"] },
960
- { action: "replace", anchor: "3#ZZZZ", body: ["B"] },
979
+ steps: [
980
+ { action: "replace", anchor: stable, lines: ["A"] },
981
+ { action: "replace", anchor: "3#ZZZZ", lines: ["B"] },
961
982
  ],
962
983
  }),
963
984
  );
964
985
  assert.deepEqual(
965
986
  retry.failures?.map(({ field, cited }) => ({ field, cited })),
966
987
  [
967
- { field: "edits[0].anchor", cited: stable },
968
- { field: "edits[1].anchor", cited: "3#ZZZZ" },
988
+ { field: "steps[0].anchor", cited: stable },
989
+ { field: "steps[1].anchor", cited: "3#ZZZZ" },
969
990
  ],
970
991
  );
971
992
  assert.equal(await readFile(file, "utf8"), "changed\nb\nc\n");
972
993
  }));
973
994
 
974
- test("failed batches over forty edits → report every failed anchor and its candidate content", async () =>
995
+ test("failed batches over forty steps → report every failed anchor and its candidate content", async () =>
975
996
  withDir(async (dir) => {
976
997
  const original = "a\ntarget\nz\n";
977
998
  const before = `prefix\n${original}`;
978
999
  const file = join(dir, "many-checks.txt");
979
1000
  await writeFile(file, before);
980
- const edits = Array.from({ length: 45 }, () => ({
1001
+ const steps = Array.from({ length: 45 }, () => ({
981
1002
  action: "replace",
982
1003
  anchor: h(original, 2),
983
- body: ["changed"],
1004
+ lines: ["changed"],
984
1005
  }));
985
1006
  const report = failureReport(
986
- await call(makeEditOverride(dir, DEFAULT_CONFIG), { path: file, edits }),
1007
+ await call(makeEditOverride(dir, DEFAULT_CONFIG), { path: file, steps }),
987
1008
  );
988
1009
  assert.equal(report.failures?.length, 45);
989
1010
  assert.equal(report.omittedFailures, undefined);
990
1011
  assert.deepEqual(
991
1012
  report.failures?.map((failure) => failure.field),
992
- edits.map((_, index) => `edits[${index}].anchor`),
1013
+ steps.map((_, index) => `steps[${index}].anchor`),
993
1014
  );
994
1015
  assert.ok(
995
1016
  report.failures?.every(
@@ -1008,7 +1029,7 @@ test("unique candidate content is independent of oversized neighboring rows", as
1008
1029
  const report = failureReport(
1009
1030
  await call(makeEditOverride(dir, DEFAULT_CONFIG), {
1010
1031
  path: file,
1011
- edits: [{ action: "replace", anchor: h(original, 2), body: ["updated"] }],
1032
+ steps: [{ action: "replace", anchor: h(original, 2), lines: ["updated"] }],
1012
1033
  }),
1013
1034
  );
1014
1035
  const candidate = report.failures?.[0].candidate;
@@ -1020,7 +1041,7 @@ test("unique candidate content is independent of oversized neighboring rows", as
1020
1041
  assert.equal(await readFile(file, "utf8"), before);
1021
1042
  await call(makeEditOverride(dir, DEFAULT_CONFIG), {
1022
1043
  path: file,
1023
- edits: [{ action: "replace", anchor: candidate, body: ["updated"] }],
1044
+ steps: [{ action: "replace", anchor: candidate, lines: ["updated"] }],
1024
1045
  });
1025
1046
  assert.equal(await readFile(file, "utf8"), before.replace("target", "updated"));
1026
1047
  }));
@@ -1051,13 +1072,13 @@ test("shifted unique candidate → displays standalone CR without altering its a
1051
1072
  await writeFile(file, before);
1052
1073
  await call(makeEditOverride(dir, DEFAULT_CONFIG), {
1053
1074
  path: file,
1054
- edits: [{ action: "delete", anchor: h(before, 1) }],
1075
+ steps: [{ action: "delete", anchor: h(before, 1) }],
1055
1076
  });
1056
1077
  assert.equal(await readFile(file, "utf8"), "a\rb\n");
1057
1078
  const report = failureReport(
1058
1079
  await call(makeEditOverride(dir, DEFAULT_CONFIG), {
1059
1080
  path: file,
1060
- edits: [{ action: "delete", anchor: h(before, 2) }],
1081
+ steps: [{ action: "delete", anchor: h(before, 2) }],
1061
1082
  }),
1062
1083
  );
1063
1084
  assert.equal(report.failures?.[0].candidate, h("a\rb\n", 1));
@@ -1075,19 +1096,19 @@ test("edit receives multiple wrong-length anchors → reports each location with
1075
1096
  const short = h(text, 2).slice(0, -2);
1076
1097
  const args = {
1077
1098
  path: "f.txt",
1078
- edits: [
1079
- { action: "replace", anchor, end: short, body: ["x"] },
1099
+ steps: [
1100
+ { action: "replace", anchor, end: short, lines: ["x"] },
1080
1101
  { action: "delete", anchor: short },
1081
1102
  ],
1082
1103
  };
1083
1104
 
1084
1105
  await assert.rejects(call(edit, args), (error: Error) => {
1085
- rejectsArgument("edits[0].end")(error);
1086
- rejectsArgument("edits[1].anchor")(error);
1106
+ rejectsArgument("steps[0].end")(error);
1107
+ rejectsArgument("steps[1].anchor")(error);
1087
1108
  const issues = argumentError(error).issues;
1088
1109
  assert.deepEqual(
1089
1110
  issues.map((issue) => issue.field),
1090
- ["edits[0].end", "edits[1].anchor"],
1111
+ ["steps[0].end", "steps[1].anchor"],
1091
1112
  );
1092
1113
  assert.equal(issues.filter((issue) => issue.fix?.includes("Read or grep")).length, 1);
1093
1114
  assert.match(error.message, new RegExp(`${hashLen - 2} hash characters`));
@@ -1097,20 +1118,20 @@ test("edit receives multiple wrong-length anchors → reports each location with
1097
1118
  assert.equal(await readFile(file, "utf8"), text);
1098
1119
  }));
1099
1120
 
1100
- test("Pi-converted single-object edits execute as a canonical array", async () =>
1121
+ test("Pi-converted single-object steps execute as a canonical array", async () =>
1101
1122
  withDir(async (dir) => {
1102
1123
  const file = join(dir, "converted.txt");
1103
1124
  const original = "first\nsecond\n";
1104
1125
  await writeFile(file, original);
1105
1126
  const edit = makeEditOverride(dir, DEFAULT_CONFIG);
1106
- const operation = { action: "replace", anchor: h(original, 2), body: ["SECOND"] };
1127
+ const operation = { action: "replace", anchor: h(original, 2), lines: ["SECOND"] };
1107
1128
  const args = validateToolArguments(edit as any, {
1108
1129
  type: "toolCall",
1109
1130
  id: "converted",
1110
1131
  name: "edit",
1111
- arguments: { path: "converted.txt", edits: operation },
1132
+ arguments: { path: "converted.txt", steps: operation },
1112
1133
  });
1113
- assert.deepEqual(args.edits, [operation]);
1134
+ assert.deepEqual(args.steps, [operation]);
1114
1135
  await call(edit, args);
1115
1136
  assert.equal(await readFile(file, "utf8"), "first\nSECOND\n");
1116
1137
  }));
@@ -1125,7 +1146,7 @@ test("unresolved snapshot rows support direct retry and revalidate after further
1125
1146
  const report = failureReport(
1126
1147
  await call(edit, {
1127
1148
  path: "recover.txt",
1128
- edits: [{ action: "replace", anchor: h(observed, 2), body: ["target = new"] }],
1149
+ steps: [{ action: "replace", anchor: h(observed, 2), lines: ["target = new"] }],
1129
1150
  }),
1130
1151
  );
1131
1152
  const diagnostic = report.failures?.[0].observed ?? "";
@@ -1137,7 +1158,7 @@ test("unresolved snapshot rows support direct retry and revalidate after further
1137
1158
  const retry = failureReport(
1138
1159
  await call(edit, {
1139
1160
  path: "recover.txt",
1140
- edits: [{ action: "replace", anchor: retryAnchor, body: ["target = new"] }],
1161
+ steps: [{ action: "replace", anchor: retryAnchor, lines: ["target = new"] }],
1141
1162
  }),
1142
1163
  );
1143
1164
  assert.equal(retry.error, "ANCHOR_MISMATCH");
@@ -1145,7 +1166,7 @@ test("unresolved snapshot rows support direct retry and revalidate after further
1145
1166
  await writeFile(file, current);
1146
1167
  await call(edit, {
1147
1168
  path: "recover.txt",
1148
- edits: [{ action: "replace", anchor: retryAnchor, body: ["target = new"] }],
1169
+ steps: [{ action: "replace", anchor: retryAnchor, lines: ["target = new"] }],
1149
1170
  });
1150
1171
  assert.deepEqual(await readFile(file), Buffer.from(observed.replace("old", "new")));
1151
1172
  });
@@ -1161,7 +1182,7 @@ test("unresolved oversized and out-of-range rows require more context without pa
1161
1182
  const report = failureReport(
1162
1183
  await call(edit, {
1163
1184
  path: "recover.txt",
1164
- edits: [{ action: "replace", anchor, body: ["new"] }],
1185
+ steps: [{ action: "replace", anchor, lines: ["new"] }],
1165
1186
  }),
1166
1187
  );
1167
1188
  assert.match(report.next ?? "", /read or grep/);
@@ -1184,7 +1205,7 @@ test("edit rejects impossible checksum characters before accessing the file", as
1184
1205
  await assert.rejects(
1185
1206
  call(tool, {
1186
1207
  path: "missing.txt",
1187
- edits: [{ action: "delete", anchor: `1#${char.repeat(DEFAULT_CONFIG.hashLen)}` }],
1208
+ steps: [{ action: "delete", anchor: `1#${char.repeat(DEFAULT_CONFIG.hashLen)}` }],
1188
1209
  }),
1189
1210
  rejectsArguments(),
1190
1211
  );
@@ -1202,7 +1223,7 @@ test("ambiguous failure lists and neighborhoods select the same first eight cand
1202
1223
  const report = failureReport(
1203
1224
  await call(tool, {
1204
1225
  path: "candidates.txt",
1205
- edits: [{ action: "delete", anchor: `200#${computeLineHash(200, "target", 4)}` }],
1226
+ steps: [{ action: "delete", anchor: `200#${computeLineHash(200, "target", 4)}` }],
1206
1227
  }),
1207
1228
  );
1208
1229
  assert.equal(report.failures?.[0].omittedCandidates, 1);
@@ -1223,11 +1244,11 @@ test("edit verification → uses the supplied hash length", async () =>
1223
1244
  await writeFile(join(dir, "registered.txt"), "before\n");
1224
1245
  const result = await call(edit, {
1225
1246
  path: "registered.txt",
1226
- edits: [
1247
+ steps: [
1227
1248
  {
1228
1249
  action: "replace",
1229
1250
  anchor: `1#${computeLineHash(1, "before", 6)}`,
1230
- body: ["after"],
1251
+ lines: ["after"],
1231
1252
  },
1232
1253
  ],
1233
1254
  });