@criogaid/pi-hashline-edit 0.7.0 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +76 -220
- package/README.zh-CN.md +166 -0
- package/package.json +2 -1
- package/src/core/AGENTS.md +1 -1
- package/src/core/apply.test.ts +171 -133
- package/src/core/apply.ts +34 -31
- package/src/core/case-fold.test.ts +11 -7
- package/src/core/case-fold.ts +2 -6
- package/src/core/character-set.ts +14 -0
- package/src/core/hash.test.ts +1 -25
- package/src/core/hash.ts +0 -5
- package/src/core/lines.ts +25 -7
- package/src/core/ranges.test.ts +49 -9
- package/src/core/ranges.ts +15 -4
- package/src/core/regex.ts +36 -6
- package/src/core/replace-schema.ts +18 -11
- package/src/core/replace.test.ts +90 -0
- package/src/core/replace.ts +6 -5
- package/src/core/search-analysis.test.ts +9 -0
- package/src/core/search-analysis.ts +35 -31
- package/src/core/search.ts +1 -1
- package/src/core/types.ts +6 -8
- package/src/index.ts +2 -4
- package/src/integration/config-registration.test.ts +18 -10
- package/src/integration/fusion-dispatch.test.ts +41 -22
- package/src/integration/grep-flags.test.ts +6 -13
- package/src/integration/grep-js-completeness.test.ts +41 -31
- package/src/integration/grep-order.test.ts +78 -0
- package/src/integration/grep-path-matrix.test.ts +4 -3
- package/src/integration/grep-regex.test.ts +13 -16
- package/src/integration/grep-rg.test.ts +132 -92
- package/src/integration/grep-scan-budget.test.ts +27 -5
- package/src/integration/large-text.test.ts +4 -5
- package/src/integration/model-budget-lifecycle.test.ts +26 -8
- package/src/integration/mutation-file-types.test.ts +0 -1
- package/src/integration/mutation-file-types.testing.ts +2 -2
- package/src/integration/npm-package.testing.ts +7 -33
- package/src/integration/publication-read-changes.test.ts +60 -28
- package/src/integration/replace-package.testing.ts +4 -1
- package/src/integration/replace-worker-boundary.test.ts +34 -24
- package/src/integration/report-replay.test.ts +3 -3
- package/src/integration/utf8-errors.test.ts +3 -3
- package/src/pi/AGENTS.md +13 -14
- package/src/pi/action-fusion.test.ts +75 -220
- package/src/pi/action-fusion.ts +37 -74
- package/src/pi/anchor-format.test.ts +16 -0
- package/src/pi/anchor-format.ts +7 -3
- package/src/pi/argument-diagnostics.ts +35 -186
- package/src/pi/argument-error.testing.ts +7 -4
- package/src/pi/argument-error.ts +5 -7
- package/src/pi/argument-format.test.ts +25 -38
- package/src/pi/argument-validation.test.ts +446 -420
- package/src/pi/argument-validation.ts +4 -5
- package/src/pi/budgets.ts +5 -7
- package/src/pi/config.test.ts +15 -5
- package/src/pi/config.ts +6 -6
- package/src/pi/diagnostic-buffer.test.ts +2 -3
- package/src/pi/diagnostic-buffer.ts +2 -2
- package/src/pi/edit-tool.ts +175 -121
- package/src/pi/execute.test.ts +170 -227
- package/src/pi/failure-context.test.ts +61 -16
- package/src/pi/failure-context.ts +13 -10
- package/src/pi/failure-path.test.ts +115 -50
- package/src/pi/file-commit.test.ts +30 -46
- package/src/pi/file-commit.ts +11 -40
- package/src/pi/file-revision.ts +25 -0
- package/src/pi/fusion-card-interaction.test.ts +143 -0
- package/src/pi/fusion-card.test.ts +193 -37
- package/src/pi/fusion-card.ts +186 -116
- package/src/pi/grep-candidates.ts +25 -27
- package/src/pi/grep-matrix.test.ts +1 -1
- package/src/pi/grep-order.test.ts +323 -0
- package/src/pi/grep-output.testing.ts +24 -0
- package/src/pi/grep-output.ts +62 -69
- package/src/pi/grep-render.ts +4 -1
- package/src/pi/grep-scope.ts +1 -1
- package/src/pi/grep-search.ts +85 -56
- package/src/pi/grep-tool.ts +17 -48
- package/src/pi/grep.test.ts +271 -170
- package/src/pi/mutation-outcome.testing.ts +2 -3
- package/src/pi/mutation-result.test.ts +26 -19
- package/src/pi/mutation-result.ts +25 -40
- package/src/pi/mutation-runner.ts +9 -17
- package/src/pi/output-budgets.test.ts +27 -18
- package/src/pi/path.ts +3 -1
- package/src/pi/pi.test.ts +7 -6
- package/src/pi/read-tool.ts +32 -80
- package/src/pi/read.test.ts +145 -92
- package/src/pi/regex-worker-contract.ts +5 -23
- package/src/pi/regex-worker.ts +4 -10
- package/src/pi/registration.test.ts +106 -67
- package/src/pi/render.test.ts +239 -109
- package/src/pi/render.ts +42 -22
- package/src/pi/replace-regex.ts +3 -5
- package/src/pi/replace-tool.ts +29 -27
- package/src/pi/replace-worker-contract.ts +3 -12
- package/src/pi/replace.test.ts +144 -226
- package/src/pi/report-cause.ts +23 -19
- package/src/pi/report-failure.testing.ts +2 -2
- package/src/pi/report-schema.ts +60 -45
- package/src/pi/report.test.ts +138 -71
- package/src/pi/report.ts +40 -43
- package/src/pi/result-safety.test.ts +186 -131
- package/src/pi/rg-process.test.ts +36 -10
- package/src/pi/rg-process.ts +9 -3
- package/src/pi/rg-regex.test.ts +17 -0
- package/src/pi/rg-regex.ts +28 -22
- package/src/pi/text-stream.test.ts +35 -36
- package/src/pi/text-stream.ts +14 -14
- package/src/pi/tool-call.testing.ts +17 -7
- package/src/pi/write-tool.ts +9 -11
- package/src/pi/write.test.ts +43 -75
- package/src/testing/regex-translation-corpus.ts +16 -0
- package/src/testing/rg-line-listing.fixture.mjs +1 -1
- package/src/integration/forget-grep.test.ts +0 -148
- package/src/pi/forget-tool.ts +0 -367
- package/src/pi/forget.test.ts +0 -630
- package/src/pi/forget.testing.ts +0 -201
|
@@ -11,7 +11,8 @@ import { makeWriteOverride } from "./write-tool.ts";
|
|
|
11
11
|
import { computeLineHash } from "../core/hash.ts";
|
|
12
12
|
import type { ActionFusionProgress, CommandOutcome } from "./action-fusion.ts";
|
|
13
13
|
import { ACTION_FUSION_GUIDELINES, createActionFusionExecutor } from "./action-fusion.ts";
|
|
14
|
-
import {
|
|
14
|
+
import { FileMutationError } from "./file-commit.ts";
|
|
15
|
+
import { DEFAULT_OUTPUT_BUDGETS } from "./budgets.ts";
|
|
15
16
|
import { DEFAULT_CONFIG } from "./config.ts";
|
|
16
17
|
import { ACTION_FUSION_PROGRESS_SCHEMA, REREAD } from "./report-schema.ts";
|
|
17
18
|
import { Value } from "typebox/value";
|
|
@@ -38,6 +39,7 @@ test("mutation tools expose Fusion schemas and guidance when supplied an executo
|
|
|
38
39
|
assert.ok(
|
|
39
40
|
"then_run" in enabled.parameters.properties && enabled.parameters.properties.then_run,
|
|
40
41
|
);
|
|
42
|
+
assert.match(enabled.description, /set the then_run parameter/i);
|
|
41
43
|
assert.deepEqual(enabled.promptGuidelines, [
|
|
42
44
|
...(disabled.promptGuidelines ?? []),
|
|
43
45
|
...ACTION_FUSION_GUIDELINES,
|
|
@@ -59,9 +61,9 @@ test("then_run schemas reject invalid commands, unknown keys, and excessive time
|
|
|
59
61
|
await writeFile(join(dir, path), "old\n");
|
|
60
62
|
const mutation =
|
|
61
63
|
tool.name === "edit"
|
|
62
|
-
? { edits: [{
|
|
64
|
+
? { edits: [{ action: "append", body: ["new"] }] }
|
|
63
65
|
: tool.name === "replace"
|
|
64
|
-
? { replacements: [{ find: "old", replace: "new" }] }
|
|
66
|
+
? { replacements: [{ literal: true, find: "old", replace: "new" }] }
|
|
65
67
|
: { content: "new\n", mode: "overwrite" };
|
|
66
68
|
for (const then_run of [
|
|
67
69
|
{},
|
|
@@ -72,7 +74,7 @@ test("then_run schemas reject invalid commands, unknown keys, and excessive time
|
|
|
72
74
|
await assert.rejects(
|
|
73
75
|
callTool(tool, { path, ...mutation, then_run }, { ctx: await ctx(dir, t) }),
|
|
74
76
|
(error: unknown) =>
|
|
75
|
-
rejectsArguments(
|
|
77
|
+
rejectsArguments()(error) &&
|
|
76
78
|
argumentError(error).issues.some((issue) => issue.field.startsWith("then_run.")),
|
|
77
79
|
);
|
|
78
80
|
assert.equal(await readFile(join(dir, path), "utf8"), "old\n");
|
|
@@ -89,7 +91,7 @@ test("edit and replace share one embedded executor and preserve mutation results
|
|
|
89
91
|
const calls: string[] = [];
|
|
90
92
|
const fusion = createActionFusionExecutor(async (_id, input) => {
|
|
91
93
|
calls.push(input.command);
|
|
92
|
-
return { status: "succeeded",
|
|
94
|
+
return { status: "succeeded", result: { content: [{ type: "text", text: "checked" }] } };
|
|
93
95
|
});
|
|
94
96
|
const edit = makeEditOverride(dir, DEFAULT_CONFIG, fusion);
|
|
95
97
|
const replace = makeReplaceTool(dir, DEFAULT_CONFIG, fusion);
|
|
@@ -99,7 +101,7 @@ test("edit and replace share one embedded executor and preserve mutation results
|
|
|
99
101
|
"edit-1",
|
|
100
102
|
{
|
|
101
103
|
path: "edit.txt",
|
|
102
|
-
edits: [{
|
|
104
|
+
edits: [{ action: "append", body: ["after"] }],
|
|
103
105
|
then_run: { command: "check edit" },
|
|
104
106
|
},
|
|
105
107
|
undefined,
|
|
@@ -110,7 +112,7 @@ test("edit and replace share one embedded executor and preserve mutation results
|
|
|
110
112
|
"replace-1",
|
|
111
113
|
{
|
|
112
114
|
path: "replace.txt",
|
|
113
|
-
replacements: [{ find: "before", replace: "after" }],
|
|
115
|
+
replacements: [{ literal: true, find: "before", replace: "after" }],
|
|
114
116
|
then_run: { command: "check replace" },
|
|
115
117
|
},
|
|
116
118
|
undefined,
|
|
@@ -119,11 +121,11 @@ test("edit and replace share one embedded executor and preserve mutation results
|
|
|
119
121
|
);
|
|
120
122
|
const editOutput = editResult.content.at(-1);
|
|
121
123
|
assert.ok(editOutput?.type === "text");
|
|
122
|
-
assert.equal(reportOf(editResult)?.then_run?.status, "succeeded");
|
|
124
|
+
assert.equal(reportOf(editResult, "edit")?.then_run?.status, "succeeded");
|
|
123
125
|
assert.equal(editResult.content.length, 1);
|
|
124
126
|
const replaceOutput = replaceResult.content.at(-1);
|
|
125
127
|
assert.ok(replaceOutput?.type === "text");
|
|
126
|
-
assert.equal(reportOf(replaceResult)?.then_run?.status, "succeeded");
|
|
128
|
+
assert.equal(reportOf(replaceResult, "replace")?.then_run?.status, "succeeded");
|
|
127
129
|
assert.deepEqual(calls, ["check edit", "check replace"]);
|
|
128
130
|
assert.equal(await readFile(join(dir, "edit.txt"), "utf8"), "before\nafter\n");
|
|
129
131
|
assert.equal(await readFile(join(dir, "replace.txt"), "utf8"), "after\n");
|
|
@@ -143,6 +145,7 @@ test("mutation failure skips the command and command failure does not roll back"
|
|
|
143
145
|
});
|
|
144
146
|
await assert.rejects(
|
|
145
147
|
fusion({
|
|
148
|
+
budget: DEFAULT_OUTPUT_BUDGETS,
|
|
146
149
|
toolCallId: "x",
|
|
147
150
|
tool: "edit",
|
|
148
151
|
displayPath: join(dir, "missing.txt"),
|
|
@@ -163,6 +166,7 @@ test("mutation failure skips the command and command failure does not roll back"
|
|
|
163
166
|
const target = join(dir, "changed.txt");
|
|
164
167
|
await writeFile(target, "changed\n");
|
|
165
168
|
const result = await fusion({
|
|
169
|
+
budget: DEFAULT_OUTPUT_BUDGETS,
|
|
166
170
|
toolCallId: "y",
|
|
167
171
|
tool: "edit",
|
|
168
172
|
displayPath: target,
|
|
@@ -177,8 +181,8 @@ test("mutation failure skips the command and command failure does not roll back"
|
|
|
177
181
|
ctx: await ctx(dir, t),
|
|
178
182
|
});
|
|
179
183
|
assert.equal(result.details.ok, true);
|
|
180
|
-
assert.equal(reportOf(result)?.then_run?.status, "failed");
|
|
181
|
-
assert.equal(reportOf(result)?.then_run?.output, commandFailure);
|
|
184
|
+
assert.equal(reportOf(result, "edit")?.then_run?.status, "failed");
|
|
185
|
+
assert.equal(reportOf(result, "edit")?.then_run?.output, commandFailure);
|
|
182
186
|
assert.equal(await readFile(target, "utf8"), "changed\n");
|
|
183
187
|
assert.equal(calls, 1);
|
|
184
188
|
} finally {
|
|
@@ -195,10 +199,11 @@ test("cancelled calls do not mutate or run the command", async (t) => {
|
|
|
195
199
|
let commanded = false;
|
|
196
200
|
const fusion = createActionFusionExecutor(async () => {
|
|
197
201
|
commanded = true;
|
|
198
|
-
return { status: "succeeded",
|
|
202
|
+
return { status: "succeeded", result: { content: [] } };
|
|
199
203
|
});
|
|
200
204
|
await assert.rejects(
|
|
201
205
|
fusion({
|
|
206
|
+
budget: DEFAULT_OUTPUT_BUDGETS,
|
|
202
207
|
toolCallId: "x",
|
|
203
208
|
tool: "edit",
|
|
204
209
|
displayPath: join(dir, "cancelled.txt"),
|
|
@@ -219,43 +224,6 @@ test("cancelled calls do not mutate or run the command", async (t) => {
|
|
|
219
224
|
}
|
|
220
225
|
});
|
|
221
226
|
|
|
222
|
-
test("command changes the target → reports changed freshness", async (t) => {
|
|
223
|
-
const dir = await tempDir();
|
|
224
|
-
try {
|
|
225
|
-
const target = join(dir, "stale.txt");
|
|
226
|
-
await writeFile(target, "before\n");
|
|
227
|
-
const fusion = createActionFusionExecutor(async () => {
|
|
228
|
-
await writeFile(target, "changed by command\n");
|
|
229
|
-
return { status: "succeeded", output: "changed" };
|
|
230
|
-
});
|
|
231
|
-
const result = await fusion({
|
|
232
|
-
toolCallId: "stale",
|
|
233
|
-
tool: "edit",
|
|
234
|
-
displayPath: target,
|
|
235
|
-
absolutePath: target,
|
|
236
|
-
thenRun: { command: "mutate target" },
|
|
237
|
-
mutate: async () => {
|
|
238
|
-
await writeFile(target, "after mutation\n");
|
|
239
|
-
return publishedMutation("after mutation\n", {
|
|
240
|
-
content: [{ type: "text", text: "mutated" }],
|
|
241
|
-
details: undefined,
|
|
242
|
-
});
|
|
243
|
-
},
|
|
244
|
-
signal: undefined,
|
|
245
|
-
ctx: await ctx(dir, t),
|
|
246
|
-
});
|
|
247
|
-
const output = result.content
|
|
248
|
-
.filter((block) => block.type === "text")
|
|
249
|
-
.map((block) => (block.type === "text" ? block.text : ""))
|
|
250
|
-
.join("\n");
|
|
251
|
-
assert.equal(reportOf(result)?.next, REREAD);
|
|
252
|
-
assert.doesNotMatch(output, /ANCHOR/);
|
|
253
|
-
assert.equal((result.details as any)?.actionFusion?.freshness, "changed");
|
|
254
|
-
} finally {
|
|
255
|
-
await rm(dir, { recursive: true, force: true });
|
|
256
|
-
}
|
|
257
|
-
});
|
|
258
|
-
|
|
259
227
|
test("unreadable target after mutation → reports unknown freshness and skips the command", async (t) => {
|
|
260
228
|
const dir = await tempDir();
|
|
261
229
|
try {
|
|
@@ -263,9 +231,10 @@ test("unreadable target after mutation → reports unknown freshness and skips t
|
|
|
263
231
|
let commands = 0;
|
|
264
232
|
const fusion = createActionFusionExecutor(async () => {
|
|
265
233
|
commands++;
|
|
266
|
-
return { status: "succeeded",
|
|
234
|
+
return { status: "succeeded", result: { content: [{ type: "text", text: "unexpected" }] } };
|
|
267
235
|
});
|
|
268
236
|
const result = await fusion({
|
|
237
|
+
budget: DEFAULT_OUTPUT_BUDGETS,
|
|
269
238
|
toolCallId: "unknown",
|
|
270
239
|
tool: "edit",
|
|
271
240
|
displayPath: missing,
|
|
@@ -287,40 +256,9 @@ test("unreadable target after mutation → reports unknown freshness and skips t
|
|
|
287
256
|
.map((block) => (block.type === "text" ? block.text : ""))
|
|
288
257
|
.join("\n");
|
|
289
258
|
assert.equal(commands, 0);
|
|
290
|
-
assert.equal((result
|
|
259
|
+
assert.equal(reportOf(result, "edit")?.freshness, "unknown");
|
|
291
260
|
assert.doesNotMatch(output, /ANCHOR/);
|
|
292
|
-
assert.equal(reportOf(result)?.next, REREAD);
|
|
293
|
-
} finally {
|
|
294
|
-
await rm(dir, { recursive: true, force: true });
|
|
295
|
-
}
|
|
296
|
-
});
|
|
297
|
-
|
|
298
|
-
test("then_run changes the target → reports changed freshness", async (t) => {
|
|
299
|
-
const dir = await tempDir();
|
|
300
|
-
try {
|
|
301
|
-
const target = join(dir, "edit-stale.txt");
|
|
302
|
-
await writeFile(target, "before\n");
|
|
303
|
-
const fusion = createActionFusionExecutor(async () => {
|
|
304
|
-
await writeFile(target, "command changed\n");
|
|
305
|
-
return { status: "succeeded", output: "changed" };
|
|
306
|
-
});
|
|
307
|
-
const result = await makeEditOverride(dir, DEFAULT_CONFIG, fusion).execute(
|
|
308
|
-
"edit-stale",
|
|
309
|
-
{
|
|
310
|
-
path: "edit-stale.txt",
|
|
311
|
-
edits: [{ op: "replace", anchor: `1#${computeLineHash(1, "before", 4)}`, body: ["after"] }],
|
|
312
|
-
then_run: { command: "change target" },
|
|
313
|
-
},
|
|
314
|
-
undefined,
|
|
315
|
-
undefined,
|
|
316
|
-
await ctx(dir, t),
|
|
317
|
-
);
|
|
318
|
-
const output = result.content.map((block: any) => block.text ?? "").join("\n");
|
|
319
|
-
assert.ok(result.details.actionFusion);
|
|
320
|
-
assert.equal(result.details.actionFusion.freshness, "changed");
|
|
321
|
-
assert.equal(reportOf(result)?.next, REREAD);
|
|
322
|
-
assert.doesNotMatch(output, /Updated anchors|\b1#[0-9A-Z]+│/);
|
|
323
|
-
assert.equal(await readFile(target, "utf8"), "command changed\n");
|
|
261
|
+
assert.equal(reportOf(result, "edit")?.next, REREAD);
|
|
324
262
|
} finally {
|
|
325
263
|
await rm(dir, { recursive: true, force: true });
|
|
326
264
|
}
|
|
@@ -335,7 +273,9 @@ test("all mutation tools forward command progress before completion in RPC mode"
|
|
|
335
273
|
async (_id, _input, _signal, _ctx, onUpdate) => {
|
|
336
274
|
assert.equal(events.at(-1)?.command, "running");
|
|
337
275
|
onUpdate?.({ content: [{ type: "text", text: "live output" }], details: undefined });
|
|
338
|
-
assert.
|
|
276
|
+
assert.deepEqual(updates.at(-1).details.actionFusion.result?.content, [
|
|
277
|
+
{ type: "text", text: "live output" },
|
|
278
|
+
]);
|
|
339
279
|
assert.ok(
|
|
340
280
|
updates.every(
|
|
341
281
|
(update) =>
|
|
@@ -345,8 +285,11 @@ test("all mutation tools forward command progress before completion in RPC mode"
|
|
|
345
285
|
),
|
|
346
286
|
),
|
|
347
287
|
);
|
|
348
|
-
assert.
|
|
349
|
-
return {
|
|
288
|
+
assert.deepEqual(events.at(-1)?.result?.content, [{ type: "text", text: "live output" }]);
|
|
289
|
+
return {
|
|
290
|
+
status: "succeeded",
|
|
291
|
+
result: { content: [{ type: "text", text: "final output" }] },
|
|
292
|
+
};
|
|
350
293
|
},
|
|
351
294
|
(event) => events.push(event),
|
|
352
295
|
);
|
|
@@ -357,7 +300,7 @@ test("all mutation tools forward command progress before completion in RPC mode"
|
|
|
357
300
|
"edit",
|
|
358
301
|
{
|
|
359
302
|
path: "progress.txt",
|
|
360
|
-
edits: [{
|
|
303
|
+
edits: [{ action: "append", body: ["after"] }],
|
|
361
304
|
then_run: { command: "check" },
|
|
362
305
|
},
|
|
363
306
|
undefined,
|
|
@@ -369,7 +312,7 @@ test("all mutation tools forward command progress before completion in RPC mode"
|
|
|
369
312
|
"replace",
|
|
370
313
|
{
|
|
371
314
|
path: "progress.txt",
|
|
372
|
-
replacements: [{ find: "before", replace: "after" }],
|
|
315
|
+
replacements: [{ literal: true, find: "before", replace: "after" }],
|
|
373
316
|
then_run: { command: "check" },
|
|
374
317
|
},
|
|
375
318
|
undefined,
|
|
@@ -394,7 +337,11 @@ test("all mutation tools forward command progress before completion in RPC mode"
|
|
|
394
337
|
events.length = 0;
|
|
395
338
|
updates.length = 0;
|
|
396
339
|
await writeFile(join(dir, "progress.txt"), "before\n");
|
|
397
|
-
await run();
|
|
340
|
+
const result = await run();
|
|
341
|
+
assert.equal(Object.hasOwn(result.details, "actionFusion"), false);
|
|
342
|
+
assert.equal(result.details.report.publication, "PUBLISHED");
|
|
343
|
+
assert.equal(result.details.report.then_run?.status, "succeeded");
|
|
344
|
+
assert.equal(Object.hasOwn(result.details.report, "freshness"), false);
|
|
398
345
|
for (const update of updates)
|
|
399
346
|
assert.equal(Value.Check(ACTION_FUSION_PROGRESS_SCHEMA, update.details.actionFusion), true);
|
|
400
347
|
assert.deepEqual(
|
|
@@ -405,8 +352,7 @@ test("all mutation tools forward command progress before completion in RPC mode"
|
|
|
405
352
|
events.map((event) => event.mutationCompleted),
|
|
406
353
|
[false, true, true, true, true],
|
|
407
354
|
);
|
|
408
|
-
assert.
|
|
409
|
-
assert.equal(events.at(-1)?.publication, "PUBLISHED");
|
|
355
|
+
assert.deepEqual(events.at(-1)?.result?.content, [{ type: "text", text: "final output" }]);
|
|
410
356
|
assert.equal(updates.at(-1).details.actionFusion.command, "succeeded");
|
|
411
357
|
}
|
|
412
358
|
} finally {
|
|
@@ -430,7 +376,7 @@ test("progress reports skipped mutations and failed commands without rolling bac
|
|
|
430
376
|
"skip",
|
|
431
377
|
{
|
|
432
378
|
path: "missing.txt",
|
|
433
|
-
edits: [{
|
|
379
|
+
edits: [{ action: "append", body: ["after"] }],
|
|
434
380
|
then_run: { command: "check" },
|
|
435
381
|
},
|
|
436
382
|
undefined,
|
|
@@ -438,13 +384,13 @@ test("progress reports skipped mutations and failed commands without rolling bac
|
|
|
438
384
|
await ctx(dir, t),
|
|
439
385
|
);
|
|
440
386
|
assert.equal(skipped.isError, true);
|
|
441
|
-
assert.equal(reportOf(skipped)?.then_run?.status, "skipped");
|
|
387
|
+
assert.equal(reportOf(skipped, "edit")?.then_run?.status, "skipped");
|
|
442
388
|
assert.equal(commands, 0);
|
|
443
389
|
assert.deepEqual(
|
|
444
390
|
events.map((event) => event.command),
|
|
445
391
|
["waiting", "skipped"],
|
|
446
392
|
);
|
|
447
|
-
assert.equal(events.at(-1)
|
|
393
|
+
assert.equal(events.at(-1)?.result, undefined);
|
|
448
394
|
assert.equal(events.at(-1)!.mutationCompleted, false);
|
|
449
395
|
events.length = 0;
|
|
450
396
|
await writeFile(join(dir, "replace.txt"), "original\n");
|
|
@@ -452,7 +398,7 @@ test("progress reports skipped mutations and failed commands without rolling bac
|
|
|
452
398
|
"replace-skip",
|
|
453
399
|
{
|
|
454
400
|
path: "replace.txt",
|
|
455
|
-
replacements: [{ find: "missing", replace: "changed" }],
|
|
401
|
+
replacements: [{ literal: true, find: "missing", replace: "changed" }],
|
|
456
402
|
then_run: { command: "check" },
|
|
457
403
|
},
|
|
458
404
|
undefined,
|
|
@@ -460,7 +406,7 @@ test("progress reports skipped mutations and failed commands without rolling bac
|
|
|
460
406
|
await ctx(dir, t),
|
|
461
407
|
);
|
|
462
408
|
assert.equal(unmatched.isError, true);
|
|
463
|
-
assert.equal(reportOf(unmatched)?.error, "NO_MATCH");
|
|
409
|
+
assert.equal(reportOf(unmatched, "replace")?.error, "NO_MATCH");
|
|
464
410
|
assert.equal(commands, 0);
|
|
465
411
|
assert.deepEqual(
|
|
466
412
|
events.map((event) => event.command),
|
|
@@ -480,13 +426,14 @@ test("progress reports skipped mutations and failed commands without rolling bac
|
|
|
480
426
|
undefined,
|
|
481
427
|
await ctx(dir, t),
|
|
482
428
|
);
|
|
483
|
-
assert.
|
|
484
|
-
assert.equal(failed.details.actionFusion.command, "failed");
|
|
429
|
+
assert.equal(reportOf(failed, "write")?.then_run?.status, "failed");
|
|
485
430
|
assert.deepEqual(
|
|
486
431
|
events.map((event) => event.command),
|
|
487
432
|
["waiting", "waiting", "running", "failed"],
|
|
488
433
|
);
|
|
489
|
-
assert.
|
|
434
|
+
assert.deepEqual(events.at(-1)?.result, {
|
|
435
|
+
content: [{ type: "text", text: "diagnostic\nCommand exited with code 7" }],
|
|
436
|
+
});
|
|
490
437
|
assert.equal(await readFile(join(dir, "failed.txt"), "utf8"), "published\n");
|
|
491
438
|
} finally {
|
|
492
439
|
await rm(dir, { recursive: true, force: true });
|
|
@@ -506,6 +453,7 @@ test("concurrent mutations on case-differing paths serialize on Windows", {
|
|
|
506
453
|
releaseFirst = resolve;
|
|
507
454
|
});
|
|
508
455
|
const p1 = fusion({
|
|
456
|
+
budget: DEFAULT_OUTPUT_BUDGETS,
|
|
509
457
|
toolCallId: "1",
|
|
510
458
|
tool: "edit",
|
|
511
459
|
displayPath: join(dir, "caseTest.txt"),
|
|
@@ -523,6 +471,7 @@ test("concurrent mutations on case-differing paths serialize on Windows", {
|
|
|
523
471
|
});
|
|
524
472
|
await firstStarted.promise;
|
|
525
473
|
const p2 = fusion({
|
|
474
|
+
budget: DEFAULT_OUTPUT_BUDGETS,
|
|
526
475
|
toolCallId: "2",
|
|
527
476
|
tool: "edit",
|
|
528
477
|
displayPath: join(dir, "CASETEST.TXT"),
|
|
@@ -546,104 +495,6 @@ test("concurrent mutations on case-differing paths serialize on Windows", {
|
|
|
546
495
|
}
|
|
547
496
|
});
|
|
548
497
|
|
|
549
|
-
test("published mutation failure → preserves the original failure and states command and recovery once", async (t) => {
|
|
550
|
-
const dir = await tempDir();
|
|
551
|
-
try {
|
|
552
|
-
const fusion = createActionFusionExecutor();
|
|
553
|
-
const mutationError = new FileMutationError(
|
|
554
|
-
"POST_PROCESS_FAILED",
|
|
555
|
-
"post_process",
|
|
556
|
-
"PUBLISHED",
|
|
557
|
-
"post-process failed",
|
|
558
|
-
);
|
|
559
|
-
let caught: unknown;
|
|
560
|
-
try {
|
|
561
|
-
await fusion({
|
|
562
|
-
toolCallId: "test-rewrap",
|
|
563
|
-
tool: "edit",
|
|
564
|
-
displayPath: join(dir, "target.txt"),
|
|
565
|
-
absolutePath: join(dir, "target.txt"),
|
|
566
|
-
thenRun: { command: "echo done" },
|
|
567
|
-
mutate: async () => {
|
|
568
|
-
throw mutationError;
|
|
569
|
-
},
|
|
570
|
-
signal: undefined,
|
|
571
|
-
ctx: await ctx(dir, t),
|
|
572
|
-
});
|
|
573
|
-
} catch (error) {
|
|
574
|
-
caught = error;
|
|
575
|
-
}
|
|
576
|
-
|
|
577
|
-
assert.ok(caught instanceof CommandNotRun);
|
|
578
|
-
assert.equal(caught.status, "skipped");
|
|
579
|
-
assert.equal(caught.error, mutationError);
|
|
580
|
-
const report = describeFailure("edit", caught, { mutation: true });
|
|
581
|
-
assert.equal(report.publication, "PUBLISHED");
|
|
582
|
-
assert.equal(report.stage, "post_process");
|
|
583
|
-
assert.equal(report.then_run?.status, "skipped");
|
|
584
|
-
assert.match(report.next ?? "", /change is saved; do not repeat/);
|
|
585
|
-
const diagnostic = renderReport(report);
|
|
586
|
-
assert.equal(diagnostic.split("post-process failed").length - 1, 1);
|
|
587
|
-
assert.equal(diagnostic.split('"status": "skipped"').length - 1, 1);
|
|
588
|
-
} finally {
|
|
589
|
-
await rm(dir, { recursive: true, force: true });
|
|
590
|
-
}
|
|
591
|
-
});
|
|
592
|
-
|
|
593
|
-
test("Fusion uses commit facts when details omit or contradict publication and revision", async (t) => {
|
|
594
|
-
const dir = await tempDir();
|
|
595
|
-
try {
|
|
596
|
-
const target = join(dir, "unchanged.txt");
|
|
597
|
-
await writeFile(target, "same\n");
|
|
598
|
-
const commit = {
|
|
599
|
-
publication: "NOT_PUBLISHED" as const,
|
|
600
|
-
baseRevision: byteRevision("same\n"),
|
|
601
|
-
publishedRevision: byteRevision("same\n"),
|
|
602
|
-
observedRevision: byteRevision("same\n"),
|
|
603
|
-
created: false as const,
|
|
604
|
-
};
|
|
605
|
-
for (const details of [
|
|
606
|
-
undefined,
|
|
607
|
-
{ publication: "UNKNOWN", publishedRevision: "wrong", observedRevision: "wrong" },
|
|
608
|
-
]) {
|
|
609
|
-
for (const thenRun of [undefined, { command: "check" }]) {
|
|
610
|
-
let commands = 0;
|
|
611
|
-
const fusion = createActionFusionExecutor(async () => {
|
|
612
|
-
commands++;
|
|
613
|
-
return { status: "succeeded", output: "checked" };
|
|
614
|
-
});
|
|
615
|
-
const result = await fusion({
|
|
616
|
-
toolCallId: "commit-facts",
|
|
617
|
-
tool: "edit",
|
|
618
|
-
displayPath: target,
|
|
619
|
-
absolutePath: target,
|
|
620
|
-
thenRun,
|
|
621
|
-
signal: undefined,
|
|
622
|
-
ctx: await ctx(dir, t),
|
|
623
|
-
mutate: async () => ({
|
|
624
|
-
details: details ?? {},
|
|
625
|
-
facts: {},
|
|
626
|
-
commit,
|
|
627
|
-
}),
|
|
628
|
-
});
|
|
629
|
-
assert.equal(result.content.length, 1);
|
|
630
|
-
for (const [key, value] of Object.entries(details ?? {}))
|
|
631
|
-
assert.deepEqual(Reflect.get(result.details, key), value);
|
|
632
|
-
assert.equal(reportOf(result)?.publication, "NOT_PUBLISHED");
|
|
633
|
-
assert.deepEqual(result.details.actionFusion, {
|
|
634
|
-
publication: "NOT_PUBLISHED",
|
|
635
|
-
command: thenRun ? "succeeded" : "not_requested",
|
|
636
|
-
freshness: "unchanged",
|
|
637
|
-
});
|
|
638
|
-
assert.equal(commands, thenRun ? 1 : 0);
|
|
639
|
-
assert.equal(await readFile(target, "utf8"), "same\n");
|
|
640
|
-
}
|
|
641
|
-
}
|
|
642
|
-
} finally {
|
|
643
|
-
await rm(dir, { recursive: true, force: true });
|
|
644
|
-
}
|
|
645
|
-
});
|
|
646
|
-
|
|
647
498
|
test("timed command progress ticks during silence, preserves output, and stops at every outcome", async (t) => {
|
|
648
499
|
for (const outcome of ["succeeded", "failed", "timeout", "cancelled"] as const) {
|
|
649
500
|
await t.test(outcome, async (t) => {
|
|
@@ -665,6 +516,7 @@ test("timed command progress ticks during silence, preserves output, and stops a
|
|
|
665
516
|
(event) => events.push(event),
|
|
666
517
|
);
|
|
667
518
|
const execution = fusion({
|
|
519
|
+
budget: DEFAULT_OUTPUT_BUDGETS,
|
|
668
520
|
toolCallId: outcome,
|
|
669
521
|
tool: "edit",
|
|
670
522
|
displayPath: join(dir, "target.txt"),
|
|
@@ -687,16 +539,23 @@ test("timed command progress ticks during silence, preserves output, and stops a
|
|
|
687
539
|
t.mock.timers.tick(2_000);
|
|
688
540
|
assert.equal(updates.length, updateCount + 2);
|
|
689
541
|
assert.equal(events.at(-1)?.timing?.remainingSeconds, 8);
|
|
690
|
-
assert.
|
|
542
|
+
assert.deepEqual(events.at(-1)?.result?.content, [{ type: "text", text: "latest output" }]);
|
|
691
543
|
if (outcome === "cancelled") controller.abort();
|
|
692
544
|
finished.resolve({
|
|
693
545
|
status: outcome,
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
546
|
+
result: {
|
|
547
|
+
content: [
|
|
548
|
+
{
|
|
549
|
+
type: "text",
|
|
550
|
+
text:
|
|
551
|
+
outcome === "succeeded"
|
|
552
|
+
? "complete"
|
|
553
|
+
: outcome === "timeout"
|
|
554
|
+
? "Command timed out"
|
|
555
|
+
: "command stopped\nunderlying cause",
|
|
556
|
+
},
|
|
557
|
+
],
|
|
558
|
+
},
|
|
700
559
|
});
|
|
701
560
|
await execution;
|
|
702
561
|
assert.equal(events.at(-1)?.command, outcome);
|
|
@@ -704,7 +563,7 @@ test("timed command progress ticks during silence, preserves output, and stops a
|
|
|
704
563
|
t.mock.timers.tick(20_000);
|
|
705
564
|
assert.equal(updates.length, terminalCount);
|
|
706
565
|
} finally {
|
|
707
|
-
finished.resolve({ status: "succeeded",
|
|
566
|
+
finished.resolve({ status: "succeeded", result: { content: [] } });
|
|
708
567
|
await rm(dir, { recursive: true, force: true });
|
|
709
568
|
}
|
|
710
569
|
});
|
|
@@ -727,6 +586,7 @@ test("commands without an explicit timeout do not start countdown updates", asyn
|
|
|
727
586
|
(event) => events.push(event),
|
|
728
587
|
);
|
|
729
588
|
const execution = fusion({
|
|
589
|
+
budget: DEFAULT_OUTPUT_BUDGETS,
|
|
730
590
|
toolCallId: "untimed",
|
|
731
591
|
tool: "edit",
|
|
732
592
|
displayPath: join(dir, "target.txt"),
|
|
@@ -744,10 +604,13 @@ test("commands without an explicit timeout do not start countdown updates", asyn
|
|
|
744
604
|
t.mock.timers.tick(20_000);
|
|
745
605
|
assert.equal(events.length, count);
|
|
746
606
|
assert.equal(events.at(-1)?.timing, undefined);
|
|
747
|
-
finished.resolve({
|
|
607
|
+
finished.resolve({
|
|
608
|
+
status: "succeeded",
|
|
609
|
+
result: { content: [{ type: "text", text: "complete" }] },
|
|
610
|
+
});
|
|
748
611
|
await execution;
|
|
749
612
|
} finally {
|
|
750
|
-
finished.resolve({ status: "succeeded",
|
|
613
|
+
finished.resolve({ status: "succeeded", result: { content: [] } });
|
|
751
614
|
await rm(dir, { recursive: true, force: true });
|
|
752
615
|
}
|
|
753
616
|
});
|
|
@@ -782,7 +645,7 @@ test("Fusion fails at a mutation or command boundary → reports each command ou
|
|
|
782
645
|
: scenario === "command cancelled"
|
|
783
646
|
? "cancelled"
|
|
784
647
|
: "failed",
|
|
785
|
-
|
|
648
|
+
result: { content: [{ type: "text", text: "command diagnostic" }] },
|
|
786
649
|
};
|
|
787
650
|
});
|
|
788
651
|
const stoppedDuringMutation = [
|
|
@@ -801,6 +664,7 @@ test("Fusion fails at a mutation or command boundary → reports each command ou
|
|
|
801
664
|
? "failed"
|
|
802
665
|
: "skipped";
|
|
803
666
|
const invocation = fusion({
|
|
667
|
+
budget: DEFAULT_OUTPUT_BUDGETS,
|
|
804
668
|
toolCallId: scenario,
|
|
805
669
|
tool: "edit",
|
|
806
670
|
displayPath: target,
|
|
@@ -832,7 +696,7 @@ test("Fusion fails at a mutation or command boundary → reports each command ou
|
|
|
832
696
|
if (stoppedDuringMutation) {
|
|
833
697
|
await assert.rejects(invocation, (error: unknown) => {
|
|
834
698
|
assert.ok(error instanceof CommandNotRun);
|
|
835
|
-
const report = describeFailure("edit", error, {
|
|
699
|
+
const report = describeFailure("edit", error, { budget: DEFAULT_OUTPUT_BUDGETS });
|
|
836
700
|
diagnostic = renderReport(report);
|
|
837
701
|
assert.equal(report.then_run?.status, expectedCommand);
|
|
838
702
|
return true;
|
|
@@ -842,17 +706,8 @@ test("Fusion fails at a mutation or command boundary → reports each command ou
|
|
|
842
706
|
diagnostic = result.content
|
|
843
707
|
.map((block) => (block.type === "text" ? block.text : ""))
|
|
844
708
|
.join("\n");
|
|
845
|
-
|
|
846
|
-
assert.
|
|
847
|
-
const state = details.actionFusion;
|
|
848
|
-
assert.ok(
|
|
849
|
-
state !== null &&
|
|
850
|
-
typeof state === "object" &&
|
|
851
|
-
"command" in state &&
|
|
852
|
-
"publication" in state,
|
|
853
|
-
);
|
|
854
|
-
assert.equal(state.command, expectedCommand);
|
|
855
|
-
assert.equal(state.publication, "PUBLISHED");
|
|
709
|
+
assert.equal(result.details.report.publication, "PUBLISHED");
|
|
710
|
+
assert.equal(renderReport(result.details.report), diagnostic);
|
|
856
711
|
}
|
|
857
712
|
const report = JSON.parse(diagnostic);
|
|
858
713
|
assert.equal(report.then_run.status, expectedCommand);
|