@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
@@ -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,
@@ -612,9 +618,16 @@ test("failed commands preserve mutation results and stay out of all main card re
612
618
  ];
613
619
  for (const { path, run, expected } of cases) {
614
620
  await writeFile(join(dir, path), "before\n");
615
- const { result, rendered } = await run();
621
+ const { result, rendered, tool } = await run();
616
622
  assert.equal("isError" in result, false);
617
- const report = detailsReport(result.details);
623
+ assert.ok(
624
+ tool === "edit" ||
625
+ tool === "replace" ||
626
+ tool === "write" ||
627
+ tool === "read" ||
628
+ tool === "grep",
629
+ );
630
+ const report = detailsReport(result.details, tool);
618
631
  assert.equal(report?.publication, "PUBLISHED");
619
632
  const last = result.content.at(-1);
620
633
  assert.ok(last?.type === "text");
@@ -643,7 +656,7 @@ test("missing or directory targets → tools share path diagnostics without file
643
656
  { tool: makeReadOverride(dir, DEFAULT_CONFIG), args: { path } },
644
657
  {
645
658
  tool: makeEditOverride(dir, DEFAULT_CONFIG),
646
- args: { path, edits: [{ action: "append", body: ["changed"] }] },
659
+ args: { path, steps: [{ action: "append", lines: ["changed"] }] },
647
660
  },
648
661
  {
649
662
  tool: makeReplaceTool(dir, DEFAULT_CONFIG),
@@ -661,7 +674,7 @@ test("missing or directory targets → tools share path diagnostics without file
661
674
  ];
662
675
  for (const { tool, args } of cases) {
663
676
  await t.test(`${tool.name}/${target.name}`, async () => {
664
- const report = failureReport(await callTool(tool, args));
677
+ const report = failureReport(await callTool(tool, args), tool.name);
665
678
  assert.equal(report.error, target.code);
666
679
  assert.equal(report.message, PATH_ERROR_MESSAGES[target.code]);
667
680
  if (target.code === "PATH_NOT_FOUND") {
@@ -692,14 +705,14 @@ test("text tools reject malformed UTF-8 and NUL bytes without rewriting source b
692
705
  [makeReadOverride(dir, DEFAULT_CONFIG), { path: "invalid-utf8.txt" }],
693
706
  [
694
707
  makeEditOverride(dir, DEFAULT_CONFIG),
695
- { path: "invalid-utf8.txt", edits: [{ action: "append", body: ["x"] }] },
708
+ { path: "invalid-utf8.txt", steps: [{ action: "append", lines: ["x"] }] },
696
709
  ],
697
710
  [
698
711
  makeReplaceTool(dir, DEFAULT_CONFIG),
699
712
  { path: "invalid-utf8.txt", replacements: [{ literal: true, find: "a", replace: "b" }] },
700
713
  ],
701
714
  ] as const) {
702
- assert.equal(failureReport(await call(tool, args)).error, "UNSUPPORTED_ENCODING");
715
+ assert.equal(failureReport(await call(tool, args), tool.name).error, "UNSUPPORTED_ENCODING");
703
716
  }
704
717
  assert.deepEqual(await readFile(target), original);
705
718
 
@@ -709,14 +722,14 @@ test("text tools reject malformed UTF-8 and NUL bytes without rewriting source b
709
722
  for (const [tool, args] of [
710
723
  [
711
724
  makeEditOverride(dir, DEFAULT_CONFIG),
712
- { path: "nul.txt", edits: [{ action: "append", body: ["x"] }] },
725
+ { path: "nul.txt", steps: [{ action: "append", lines: ["x"] }] },
713
726
  ],
714
727
  [
715
728
  makeReplaceTool(dir, DEFAULT_CONFIG),
716
729
  { path: "nul.txt", replacements: [{ literal: true, find: "a", replace: "b" }] },
717
730
  ],
718
731
  ] as const) {
719
- assert.equal(failureReport(await call(tool, args)).error, "UNSUPPORTED_TEXT");
732
+ assert.equal(failureReport(await call(tool, args), tool.name).error, "UNSUPPORTED_TEXT");
720
733
  }
721
734
  assert.deepEqual(await readFile(nulTarget), nulOriginal);
722
735
 
@@ -726,7 +739,10 @@ test("text tools reject malformed UTF-8 and NUL bytes without rewriting source b
726
739
  const utf16Target = join(dir, "utf16.txt");
727
740
  await writeFile(utf16Target, Buffer.from([0xff, 0xfe, 0x49, 0x6c]));
728
741
  assert.equal(
729
- failureReport(await call(makeReadOverride(dir, DEFAULT_CONFIG), { path: "utf16.txt" })).error,
742
+ failureReport(
743
+ await call(makeReadOverride(dir, DEFAULT_CONFIG), { path: "utf16.txt" }),
744
+ "read",
745
+ ).error,
730
746
  "UNSUPPORTED_ENCODING",
731
747
  );
732
748
  }));
@@ -739,7 +755,7 @@ test("edit rejects embedded line terminators at its schema boundary", async () =
739
755
  await assert.rejects(
740
756
  call(makeEditOverride(dir, DEFAULT_CONFIG), {
741
757
  path: "body.txt",
742
- edits: [{ action: "append", body: [line] }],
758
+ steps: [{ action: "append", lines: [line] }],
743
759
  }),
744
760
  rejectsArguments(),
745
761
  );
@@ -751,14 +767,14 @@ test("edit rejects unwritable body lines before reading a missing target", async
751
767
  withDir(async (dir) => {
752
768
  const target = join(dir, "missing.txt");
753
769
  const edit = makeEditOverride(dir, DEFAULT_CONFIG);
754
- const valid = { path: target, edits: [{ action: "append" as const, body: ["ok"] }] };
770
+ const valid = { path: target, steps: [{ action: "append" as const, lines: ["ok"] }] };
755
771
  assert.equal(edit.prepareArguments(valid), valid);
756
772
  for (const [line, expected] of [
757
- ["bad\0", rejectsArgument("edits[0].body[1]", /NUL/)],
758
- ["\ud800", rejectsArgument("edits[0].body[1]", /losslessly.*UTF-8/)],
773
+ ["bad\0", rejectsArgument("steps[0].lines[1]", /NUL/)],
774
+ ["\ud800", rejectsArgument("steps[0].lines[1]", /losslessly.*UTF-8/)],
759
775
  ] as const) {
760
776
  await assert.rejects(
761
- call(edit, { path: target, edits: [{ action: "append", body: ["ok", line] }] }),
777
+ call(edit, { path: target, steps: [{ action: "append", lines: ["ok", line] }] }),
762
778
  expected,
763
779
  );
764
780
  await assert.rejects(readFile(target, "utf8"), { code: "ENOENT" });
@@ -774,7 +790,7 @@ test("editing a BOM-prefixed file → publishes the changed bytes with the BOM i
774
790
  await writeFile(target, original);
775
791
  const result = await call(makeEditOverride(dir, DEFAULT_CONFIG), {
776
792
  path: "bom.txt",
777
- edits: [{ action: "replace", anchor: h(source, line), body: ["new"] }],
793
+ steps: [{ action: "replace", anchor: h(source, line), lines: ["new"] }],
778
794
  });
779
795
  const expected = Buffer.from(line === 1 ? "\ufeffnew\nold\n" : "\ufeffguard\nnew\n", "utf8");
780
796
  assert.deepEqual(await readFile(target), expected);
@@ -791,9 +807,9 @@ test("edit and replace reject NUL arguments without rewriting source bytes", asy
791
807
  await assert.rejects(
792
808
  call(makeEditOverride(dir, DEFAULT_CONFIG), {
793
809
  path: "output.txt",
794
- edits: [{ action: "append", body: ["bad\0text"] }],
810
+ steps: [{ action: "append", lines: ["bad\0text"] }],
795
811
  }),
796
- rejectsArgument("edits[0].body[0]", /NUL/),
812
+ rejectsArgument("steps[0].lines[0]", /NUL/),
797
813
  );
798
814
  assert.deepEqual(await readFile(target), original);
799
815
  await assert.rejects(
@@ -806,7 +822,7 @@ test("edit and replace reject NUL arguments without rewriting source bytes", asy
806
822
  assert.deepEqual(await readFile(target), original);
807
823
  }));
808
824
 
809
- test("failed edits return candidate code for a verified fused retry", async () =>
825
+ test("failed steps return candidate code for a verified fused retry", async () =>
810
826
  withDir(async (dir) => {
811
827
  const original = Array.from({ length: 14 }, (_, index) => `line-${index + 1}`);
812
828
  original[4] = "if (!fusion) throw new Error();";
@@ -815,10 +831,11 @@ test("failed edits return candidate code for a verified fused retry", async () =
815
831
  const file = join(dir, "candidate.txt");
816
832
  await writeFile(file, before);
817
833
  let commands = 0;
818
- const fusion = createActionFusionExecutor(async () => {
834
+ const executeTool: SessionCommand = async () => {
819
835
  commands++;
820
- return { status: "succeeded", result: { content: [{ type: "text", text: "checked" }] } };
821
- });
836
+ return commandCompletion({ content: [{ type: "text", text: "checked" }] });
837
+ };
838
+ const fusion = createActionFusionExecutor(() => {});
822
839
  const edit = makeEditOverride(dir, DEFAULT_CONFIG, fusion);
823
840
  const stale = h(original.join("\n"), 5);
824
841
  const stable = h(before, 12);
@@ -828,18 +845,18 @@ test("failed edits return candidate code for a verified fused retry", async () =
828
845
  edit,
829
846
  {
830
847
  path: file,
831
- edits: [
832
- { action: "insert_after", anchor: stale, body: ["const hashLen = 4;"] },
833
- { action: "replace", anchor: stable, body: ["changed"] },
848
+ steps: [
849
+ { action: "insert_after", anchor: stale, lines: ["const hashLen = 4;"] },
850
+ { action: "replace", anchor: stable, lines: ["changed"] },
834
851
  ],
835
852
  then_run: { command: "check" },
836
853
  },
837
- { toolCallId: "failed", ctx: { cwd: dir } },
854
+ { toolCallId: "failed", ctx: { ...{ cwd: dir }, executeTool } },
838
855
  ),
839
856
  );
840
857
  assert.equal(report.then_run?.status, "skipped");
841
858
  assert.equal(report.publication, "NOT_PUBLISHED");
842
- assert.equal(report.failures?.[0].field, "edits[0].anchor");
859
+ assert.equal(report.failures?.[0].field, "steps[0].anchor");
843
860
  assert.equal(report.failures?.[0].cited, stale);
844
861
  assert.equal(report.failures?.[0].candidate, candidate);
845
862
  assert.equal(report.failures?.[0].content, original[4]);
@@ -851,17 +868,17 @@ test("failed edits return candidate code for a verified fused retry", async () =
851
868
  edit,
852
869
  {
853
870
  path: file,
854
- edits: [
871
+ steps: [
855
872
  {
856
873
  action: "insert_after",
857
874
  anchor: report.failures![0].candidate!,
858
- body: ["const hashLen = 4;"],
875
+ lines: ["const hashLen = 4;"],
859
876
  },
860
- { action: "replace", anchor: stable, body: ["changed"] },
877
+ { action: "replace", anchor: stable, lines: ["changed"] },
861
878
  ],
862
879
  then_run: { command: "check" },
863
880
  },
864
- { toolCallId: "retry", ctx: { cwd: dir } },
881
+ { toolCallId: "retry", ctx: { ...{ cwd: dir }, executeTool } },
865
882
  );
866
883
  const expected = splitLines(before);
867
884
  expected[11] = "changed";
@@ -884,11 +901,11 @@ test("ambiguous candidates include distinguishing neighborhoods for a verified r
884
901
  const report = failureReport(
885
902
  await call(edit, {
886
903
  path: file,
887
- edits: [
904
+ steps: [
888
905
  {
889
906
  action: "replace",
890
907
  anchor: h("header\n return value;\n", 2),
891
- body: [" return updated;"],
908
+ lines: [" return updated;"],
892
909
  },
893
910
  ],
894
911
  }),
@@ -906,7 +923,7 @@ test("ambiguous candidates include distinguishing neighborhoods for a verified r
906
923
  assert.equal(await readFile(file, "utf8"), before);
907
924
  await call(edit, {
908
925
  path: file,
909
- edits: [{ action: "replace", anchor: anchorLine(context, 15), body: [" return updated;"] }],
926
+ steps: [{ action: "replace", anchor: anchorLine(context, 15), lines: [" return updated;"] }],
910
927
  });
911
928
  lines[14] = " return updated;";
912
929
  assert.equal(await readFile(file, "utf8"), lines.join("\n") + "\n");
@@ -920,14 +937,14 @@ test("schema-invalid bodies reject before anchor verification; retries revalidat
920
937
  const edit = makeEditOverride(dir, DEFAULT_CONFIG);
921
938
  const stable = h(before, 1);
922
939
  for (const operation of [
923
- { action: "replace", anchor: stable, body: ["bad\nline"] },
924
- { action: "append", body: ["bad\nline"] },
940
+ { action: "replace", anchor: stable, lines: ["bad\nline"] },
941
+ { action: "append", lines: ["bad\nline"] },
925
942
  ]) {
926
943
  for (const laterAnchor of [h(before, 2), "2#XXXX"]) {
927
944
  await assert.rejects(
928
945
  call(edit, {
929
946
  path: file,
930
- edits: [operation, { action: "replace", anchor: laterAnchor, body: ["B"] }],
947
+ steps: [operation, { action: "replace", anchor: laterAnchor, lines: ["B"] }],
931
948
  }),
932
949
  (error: Error) => {
933
950
  rejectsArguments()(error);
@@ -942,54 +959,54 @@ test("schema-invalid bodies reject before anchor verification; retries revalidat
942
959
  const rejected = failureReport(
943
960
  await call(edit, {
944
961
  path: file,
945
- edits: [
946
- { action: "replace", anchor: stable, body: ["A"] },
962
+ steps: [
963
+ { action: "replace", anchor: stable, lines: ["A"] },
947
964
  { action: "delete", anchor: h(before, 2), end: "3#ZZZZ" },
948
965
  ],
949
966
  }),
950
967
  );
951
- assert.equal(rejected.failures?.[0].field, "edits[1].end");
968
+ assert.equal(rejected.failures?.[0].field, "steps[1].end");
952
969
  assert.equal(rejected.failures?.[0].cited, "3#ZZZZ");
953
970
  assert.equal(await readFile(file, "utf8"), before);
954
971
  await writeFile(file, "changed\nb\nc\n");
955
972
  const retry = failureReport(
956
973
  await call(edit, {
957
974
  path: file,
958
- edits: [
959
- { action: "replace", anchor: stable, body: ["A"] },
960
- { action: "replace", anchor: "3#ZZZZ", body: ["B"] },
975
+ steps: [
976
+ { action: "replace", anchor: stable, lines: ["A"] },
977
+ { action: "replace", anchor: "3#ZZZZ", lines: ["B"] },
961
978
  ],
962
979
  }),
963
980
  );
964
981
  assert.deepEqual(
965
982
  retry.failures?.map(({ field, cited }) => ({ field, cited })),
966
983
  [
967
- { field: "edits[0].anchor", cited: stable },
968
- { field: "edits[1].anchor", cited: "3#ZZZZ" },
984
+ { field: "steps[0].anchor", cited: stable },
985
+ { field: "steps[1].anchor", cited: "3#ZZZZ" },
969
986
  ],
970
987
  );
971
988
  assert.equal(await readFile(file, "utf8"), "changed\nb\nc\n");
972
989
  }));
973
990
 
974
- test("failed batches over forty edits → report every failed anchor and its candidate content", async () =>
991
+ test("failed batches over forty steps → report every failed anchor and its candidate content", async () =>
975
992
  withDir(async (dir) => {
976
993
  const original = "a\ntarget\nz\n";
977
994
  const before = `prefix\n${original}`;
978
995
  const file = join(dir, "many-checks.txt");
979
996
  await writeFile(file, before);
980
- const edits = Array.from({ length: 45 }, () => ({
997
+ const steps = Array.from({ length: 45 }, () => ({
981
998
  action: "replace",
982
999
  anchor: h(original, 2),
983
- body: ["changed"],
1000
+ lines: ["changed"],
984
1001
  }));
985
1002
  const report = failureReport(
986
- await call(makeEditOverride(dir, DEFAULT_CONFIG), { path: file, edits }),
1003
+ await call(makeEditOverride(dir, DEFAULT_CONFIG), { path: file, steps }),
987
1004
  );
988
1005
  assert.equal(report.failures?.length, 45);
989
1006
  assert.equal(report.omittedFailures, undefined);
990
1007
  assert.deepEqual(
991
1008
  report.failures?.map((failure) => failure.field),
992
- edits.map((_, index) => `edits[${index}].anchor`),
1009
+ steps.map((_, index) => `steps[${index}].anchor`),
993
1010
  );
994
1011
  assert.ok(
995
1012
  report.failures?.every(
@@ -1008,7 +1025,7 @@ test("unique candidate content is independent of oversized neighboring rows", as
1008
1025
  const report = failureReport(
1009
1026
  await call(makeEditOverride(dir, DEFAULT_CONFIG), {
1010
1027
  path: file,
1011
- edits: [{ action: "replace", anchor: h(original, 2), body: ["updated"] }],
1028
+ steps: [{ action: "replace", anchor: h(original, 2), lines: ["updated"] }],
1012
1029
  }),
1013
1030
  );
1014
1031
  const candidate = report.failures?.[0].candidate;
@@ -1020,7 +1037,7 @@ test("unique candidate content is independent of oversized neighboring rows", as
1020
1037
  assert.equal(await readFile(file, "utf8"), before);
1021
1038
  await call(makeEditOverride(dir, DEFAULT_CONFIG), {
1022
1039
  path: file,
1023
- edits: [{ action: "replace", anchor: candidate, body: ["updated"] }],
1040
+ steps: [{ action: "replace", anchor: candidate, lines: ["updated"] }],
1024
1041
  });
1025
1042
  assert.equal(await readFile(file, "utf8"), before.replace("target", "updated"));
1026
1043
  }));
@@ -1051,13 +1068,13 @@ test("shifted unique candidate → displays standalone CR without altering its a
1051
1068
  await writeFile(file, before);
1052
1069
  await call(makeEditOverride(dir, DEFAULT_CONFIG), {
1053
1070
  path: file,
1054
- edits: [{ action: "delete", anchor: h(before, 1) }],
1071
+ steps: [{ action: "delete", anchor: h(before, 1) }],
1055
1072
  });
1056
1073
  assert.equal(await readFile(file, "utf8"), "a\rb\n");
1057
1074
  const report = failureReport(
1058
1075
  await call(makeEditOverride(dir, DEFAULT_CONFIG), {
1059
1076
  path: file,
1060
- edits: [{ action: "delete", anchor: h(before, 2) }],
1077
+ steps: [{ action: "delete", anchor: h(before, 2) }],
1061
1078
  }),
1062
1079
  );
1063
1080
  assert.equal(report.failures?.[0].candidate, h("a\rb\n", 1));
@@ -1075,19 +1092,19 @@ test("edit receives multiple wrong-length anchors → reports each location with
1075
1092
  const short = h(text, 2).slice(0, -2);
1076
1093
  const args = {
1077
1094
  path: "f.txt",
1078
- edits: [
1079
- { action: "replace", anchor, end: short, body: ["x"] },
1095
+ steps: [
1096
+ { action: "replace", anchor, end: short, lines: ["x"] },
1080
1097
  { action: "delete", anchor: short },
1081
1098
  ],
1082
1099
  };
1083
1100
 
1084
1101
  await assert.rejects(call(edit, args), (error: Error) => {
1085
- rejectsArgument("edits[0].end")(error);
1086
- rejectsArgument("edits[1].anchor")(error);
1102
+ rejectsArgument("steps[0].end")(error);
1103
+ rejectsArgument("steps[1].anchor")(error);
1087
1104
  const issues = argumentError(error).issues;
1088
1105
  assert.deepEqual(
1089
1106
  issues.map((issue) => issue.field),
1090
- ["edits[0].end", "edits[1].anchor"],
1107
+ ["steps[0].end", "steps[1].anchor"],
1091
1108
  );
1092
1109
  assert.equal(issues.filter((issue) => issue.fix?.includes("Read or grep")).length, 1);
1093
1110
  assert.match(error.message, new RegExp(`${hashLen - 2} hash characters`));
@@ -1097,20 +1114,20 @@ test("edit receives multiple wrong-length anchors → reports each location with
1097
1114
  assert.equal(await readFile(file, "utf8"), text);
1098
1115
  }));
1099
1116
 
1100
- test("Pi-converted single-object edits execute as a canonical array", async () =>
1117
+ test("Pi-converted single-object steps execute as a canonical array", async () =>
1101
1118
  withDir(async (dir) => {
1102
1119
  const file = join(dir, "converted.txt");
1103
1120
  const original = "first\nsecond\n";
1104
1121
  await writeFile(file, original);
1105
1122
  const edit = makeEditOverride(dir, DEFAULT_CONFIG);
1106
- const operation = { action: "replace", anchor: h(original, 2), body: ["SECOND"] };
1123
+ const operation = { action: "replace", anchor: h(original, 2), lines: ["SECOND"] };
1107
1124
  const args = validateToolArguments(edit as any, {
1108
1125
  type: "toolCall",
1109
1126
  id: "converted",
1110
1127
  name: "edit",
1111
- arguments: { path: "converted.txt", edits: operation },
1128
+ arguments: { path: "converted.txt", steps: operation },
1112
1129
  });
1113
- assert.deepEqual(args.edits, [operation]);
1130
+ assert.deepEqual(args.steps, [operation]);
1114
1131
  await call(edit, args);
1115
1132
  assert.equal(await readFile(file, "utf8"), "first\nSECOND\n");
1116
1133
  }));
@@ -1125,7 +1142,7 @@ test("unresolved snapshot rows support direct retry and revalidate after further
1125
1142
  const report = failureReport(
1126
1143
  await call(edit, {
1127
1144
  path: "recover.txt",
1128
- edits: [{ action: "replace", anchor: h(observed, 2), body: ["target = new"] }],
1145
+ steps: [{ action: "replace", anchor: h(observed, 2), lines: ["target = new"] }],
1129
1146
  }),
1130
1147
  );
1131
1148
  const diagnostic = report.failures?.[0].observed ?? "";
@@ -1137,7 +1154,7 @@ test("unresolved snapshot rows support direct retry and revalidate after further
1137
1154
  const retry = failureReport(
1138
1155
  await call(edit, {
1139
1156
  path: "recover.txt",
1140
- edits: [{ action: "replace", anchor: retryAnchor, body: ["target = new"] }],
1157
+ steps: [{ action: "replace", anchor: retryAnchor, lines: ["target = new"] }],
1141
1158
  }),
1142
1159
  );
1143
1160
  assert.equal(retry.error, "ANCHOR_MISMATCH");
@@ -1145,7 +1162,7 @@ test("unresolved snapshot rows support direct retry and revalidate after further
1145
1162
  await writeFile(file, current);
1146
1163
  await call(edit, {
1147
1164
  path: "recover.txt",
1148
- edits: [{ action: "replace", anchor: retryAnchor, body: ["target = new"] }],
1165
+ steps: [{ action: "replace", anchor: retryAnchor, lines: ["target = new"] }],
1149
1166
  });
1150
1167
  assert.deepEqual(await readFile(file), Buffer.from(observed.replace("old", "new")));
1151
1168
  });
@@ -1161,7 +1178,7 @@ test("unresolved oversized and out-of-range rows require more context without pa
1161
1178
  const report = failureReport(
1162
1179
  await call(edit, {
1163
1180
  path: "recover.txt",
1164
- edits: [{ action: "replace", anchor, body: ["new"] }],
1181
+ steps: [{ action: "replace", anchor, lines: ["new"] }],
1165
1182
  }),
1166
1183
  );
1167
1184
  assert.match(report.next ?? "", /read or grep/);
@@ -1184,7 +1201,7 @@ test("edit rejects impossible checksum characters before accessing the file", as
1184
1201
  await assert.rejects(
1185
1202
  call(tool, {
1186
1203
  path: "missing.txt",
1187
- edits: [{ action: "delete", anchor: `1#${char.repeat(DEFAULT_CONFIG.hashLen)}` }],
1204
+ steps: [{ action: "delete", anchor: `1#${char.repeat(DEFAULT_CONFIG.hashLen)}` }],
1188
1205
  }),
1189
1206
  rejectsArguments(),
1190
1207
  );
@@ -1202,7 +1219,7 @@ test("ambiguous failure lists and neighborhoods select the same first eight cand
1202
1219
  const report = failureReport(
1203
1220
  await call(tool, {
1204
1221
  path: "candidates.txt",
1205
- edits: [{ action: "delete", anchor: `200#${computeLineHash(200, "target", 4)}` }],
1222
+ steps: [{ action: "delete", anchor: `200#${computeLineHash(200, "target", 4)}` }],
1206
1223
  }),
1207
1224
  );
1208
1225
  assert.equal(report.failures?.[0].omittedCandidates, 1);
@@ -1223,11 +1240,11 @@ test("edit verification → uses the supplied hash length", async () =>
1223
1240
  await writeFile(join(dir, "registered.txt"), "before\n");
1224
1241
  const result = await call(edit, {
1225
1242
  path: "registered.txt",
1226
- edits: [
1243
+ steps: [
1227
1244
  {
1228
1245
  action: "replace",
1229
1246
  anchor: `1#${computeLineHash(1, "before", 6)}`,
1230
- body: ["after"],
1247
+ lines: ["after"],
1231
1248
  },
1232
1249
  ],
1233
1250
  });