@criogaid/pi-hashline-edit 0.9.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.
- package/README.md +12 -12
- package/README.zh-CN.md +12 -12
- package/THIRD_PARTY_NOTICES.md +0 -6
- package/package.json +1 -1
- package/src/core/AGENTS.md +4 -5
- package/src/core/apply.test.ts +96 -271
- package/src/core/apply.ts +62 -169
- package/src/core/case-fold.ts +8 -67
- package/src/core/character-set.test.ts +2 -3
- package/src/core/character-set.ts +5 -5
- package/src/core/errors.test.ts +23 -7
- package/src/core/errors.ts +32 -5
- package/src/core/hash.test.ts +8 -16
- package/src/core/hash.ts +3 -23
- package/src/core/lines.ts +2 -4
- package/src/core/ranges.test.ts +2 -1
- package/src/core/ranges.ts +1 -1
- package/src/core/regex.ts +3 -4
- package/src/core/replace.test.ts +47 -1
- package/src/core/replace.ts +19 -13
- package/src/core/search-analysis.test.ts +24 -27
- package/src/core/search-analysis.ts +34 -65
- package/src/core/search-matrix.testing.ts +0 -2
- package/src/core/search.ts +1 -1
- package/src/core/text.test.ts +5 -5
- package/src/core/text.ts +5 -12
- package/src/core/types.ts +8 -44
- package/src/index.ts +8 -8
- package/src/integration/config-registration.test.ts +8 -10
- package/src/integration/fusion-dispatch.test.ts +4 -7
- package/src/integration/grep-errors.test.ts +3 -3
- package/src/integration/grep-flags.test.ts +5 -19
- package/src/integration/grep-js-completeness.test.ts +45 -18
- package/src/integration/grep-line-candidates.test.ts +7 -10
- package/src/integration/grep-matrix.test.ts +6 -9
- package/src/integration/grep-order.test.ts +4 -4
- package/src/integration/grep-path-matrix.test.ts +10 -9
- package/src/integration/grep-prefilter-coverage.test.ts +5 -8
- package/src/integration/grep-process-limits.test.ts +76 -0
- package/src/integration/grep-regex.test.ts +10 -10
- package/src/integration/grep-rg.test.ts +166 -66
- package/src/integration/grep-scan-budget.test.ts +9 -9
- package/src/integration/grep-translation.test.ts +18 -32
- package/src/integration/large-text.test.ts +6 -52
- package/src/integration/model-budget-lifecycle.test.ts +10 -9
- package/src/integration/mutation-file-types.testing.ts +4 -4
- package/src/integration/npm-package.testing.ts +3 -3
- package/src/integration/publication-read-changes.test.ts +161 -83
- package/src/integration/read-changes.test.ts +4 -4
- package/src/integration/replace-worker-boundary.test.ts +22 -12
- package/src/integration/report-replay.test.ts +23 -26
- package/src/integration/utf8-errors.test.ts +4 -4
- package/src/pi/AGENTS.md +18 -17
- package/src/pi/action-fusion.test.ts +241 -353
- package/src/pi/action-fusion.testing.ts +38 -0
- package/src/pi/action-fusion.ts +150 -125
- package/src/pi/anchor-format.test.ts +9 -9
- package/src/pi/anchor-format.ts +6 -8
- package/src/pi/argument-diagnostics.ts +25 -28
- package/src/pi/argument-error.ts +2 -1
- package/src/pi/argument-format.test.ts +19 -18
- package/src/pi/argument-validation.test.ts +334 -283
- package/src/pi/argument-validation.ts +5 -8
- package/src/pi/budgets.ts +6 -8
- package/src/pi/codemode.test.ts +7 -2
- package/src/pi/config.test.ts +7 -3
- package/src/pi/config.ts +12 -9
- package/src/pi/diagnostic-buffer.test.ts +34 -13
- package/src/pi/diagnostic-buffer.ts +1 -2
- package/src/pi/directory-sync.test.ts +0 -1
- package/src/pi/edit-tool.ts +86 -211
- package/src/pi/error-text.ts +10 -9
- package/src/pi/execute.test.ts +249 -345
- package/src/pi/failure-context.test.ts +146 -127
- package/src/pi/failure-context.ts +45 -94
- package/src/pi/failure-path.test.ts +182 -155
- package/src/pi/file-commit.test.ts +156 -71
- package/src/pi/file-commit.ts +126 -146
- package/src/pi/file-snapshot.test.ts +3 -5
- package/src/pi/fusion-card.test.ts +26 -22
- package/src/pi/fusion-card.ts +16 -24
- package/src/pi/grep-candidates.test.ts +19 -120
- package/src/pi/grep-candidates.ts +25 -76
- package/src/pi/grep-matrix.test.ts +5 -5
- package/src/pi/grep-order.test.ts +16 -15
- package/src/pi/grep-output.ts +94 -107
- package/src/pi/grep-render.ts +1 -1
- package/src/pi/grep-reread.ts +97 -0
- package/src/pi/grep-rg.testing.ts +70 -0
- package/src/pi/grep-scope.ts +41 -43
- package/src/pi/grep-search.ts +27 -39
- package/src/pi/grep-tool.ts +63 -106
- package/src/pi/grep.test.ts +177 -156
- package/src/pi/model-budgets.test.ts +27 -24
- package/src/pi/model-budgets.ts +6 -38
- package/src/pi/mutation-outcome.testing.ts +0 -1
- package/src/pi/mutation-result.test.ts +44 -35
- package/src/pi/mutation-result.ts +52 -21
- package/src/pi/mutation-runner.ts +134 -74
- package/src/pi/output-budgets.test.ts +86 -42
- package/src/pi/path.ts +1 -1
- package/src/pi/pi.test.ts +18 -13
- package/src/pi/read-tool.ts +18 -23
- package/src/pi/read.test.ts +22 -41
- package/src/pi/regex-worker-contract.ts +3 -13
- package/src/pi/regex-worker.ts +1 -10
- package/src/pi/registration.test.ts +85 -51
- package/src/pi/render.test.ts +88 -59
- package/src/pi/render.ts +64 -65
- package/src/pi/replace-regex.ts +14 -2
- package/src/pi/replace-tool.ts +22 -94
- package/src/pi/replace-worker.ts +1 -1
- package/src/pi/replace.test.ts +53 -38
- package/src/pi/report-cause.ts +3 -8
- package/src/pi/report-failure.testing.ts +10 -3
- package/src/pi/report-schema.ts +251 -148
- package/src/pi/report.test.ts +215 -67
- package/src/pi/report.ts +50 -98
- package/src/pi/result-safety.test.ts +241 -247
- package/src/pi/rg-process.test.ts +77 -63
- package/src/pi/rg-process.ts +53 -75
- package/src/pi/rg-regex.ts +40 -400
- package/src/pi/schema.ts +35 -0
- package/src/pi/text-stream.test.ts +0 -21
- package/src/pi/text-stream.ts +14 -21
- package/src/pi/tool-factories.testing.ts +59 -0
- package/src/pi/write-tool.ts +36 -71
- package/src/pi/write.test.ts +31 -34
- package/src/testing/regex-translation-corpus.ts +12 -12
- package/src/testing/run-tests.ts +1 -1
- package/src/pi/replace-worker-contract.ts +0 -10
|
@@ -1,14 +1,11 @@
|
|
|
1
1
|
import { rejectsArgument } from "./argument-error.testing.ts";
|
|
2
2
|
import { createEditTool } from "@earendil-works/pi-coding-agent";
|
|
3
|
-
import { validateToolArguments } from "@earendil-works/pi-ai";
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
} from "@earendil-works/pi-ai/api/constrained-sampling";
|
|
8
|
-
import { makeEditOverride } from "./edit-tool.ts";
|
|
9
|
-
import { makeReadOverride } from "./read-tool.ts";
|
|
3
|
+
import { validateToolArguments, type Tool } from "@earendil-works/pi-ai";
|
|
4
|
+
import { makeStrictJsonSchema } from "@earendil-works/pi-ai/api/constrained-sampling";
|
|
5
|
+
import { makeEditOverride } from "./tool-factories.testing.ts";
|
|
6
|
+
import { makeReadOverride } from "./tool-factories.testing.ts";
|
|
10
7
|
import { loadConfig } from "./config.ts";
|
|
11
|
-
import { DEFAULT_CONFIG } from "./
|
|
8
|
+
import { DEFAULT_CONFIG } from "./tool-factories.testing.ts";
|
|
12
9
|
import { mkdir, mkdtemp, rm, writeFile, readFile } from "node:fs/promises";
|
|
13
10
|
import { tmpdir } from "node:os";
|
|
14
11
|
import { join } from "node:path";
|
|
@@ -16,48 +13,90 @@ import assert from "node:assert/strict";
|
|
|
16
13
|
import { test } from "node:test";
|
|
17
14
|
import registerHashline from "../index.ts";
|
|
18
15
|
import { initTheme } from "@earendil-works/pi-coding-agent";
|
|
19
|
-
import type { ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
16
|
+
import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
20
17
|
import { ProcessTerminal, TuiMainScreen } from "@earendil-works/pi-tui";
|
|
21
18
|
import { ToolExecutionComponent } from "../../node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/components/tool-execution.js";
|
|
22
19
|
import { theme } from "../../node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/theme/theme.js";
|
|
23
20
|
import { computeLineHash } from "../core/hash.ts";
|
|
24
21
|
import { callTool } from "./tool-call.testing.ts";
|
|
25
22
|
import type { AgentToolResult } from "@earendil-works/pi-agent-core";
|
|
26
|
-
import {
|
|
23
|
+
import type { ActionFusionProgress } from "./report-schema.ts";
|
|
27
24
|
import { reportOf } from "./report.ts";
|
|
28
25
|
import { formatByteSize } from "./budgets.ts";
|
|
29
26
|
import { expectToolFailure } from "./report-failure.testing.ts";
|
|
27
|
+
import { STRICT_SAMPLING } from "./schema.ts";
|
|
30
28
|
|
|
31
|
-
test("
|
|
32
|
-
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
additionalProperties: false,
|
|
47
|
-
required: ["action", "anchor", "end", "body", "before", "after"],
|
|
48
|
-
properties: {
|
|
49
|
-
anchor: { anyOf: [{ type: "string" }, { type: "null" }] },
|
|
50
|
-
end: { anyOf: [{ type: "string" }, { type: "null" }] },
|
|
51
|
-
body: { anyOf: [{ type: "array" }, { type: "null" }] },
|
|
52
|
-
before: { anyOf: [{ type: "string" }, { type: "null" }] },
|
|
53
|
-
after: { anyOf: [{ type: "string" }, { type: "null" }] },
|
|
54
|
-
},
|
|
29
|
+
test("registered tools with or without Fusion → request strict sampling with convertible parameters", async (t) => {
|
|
30
|
+
await withDir(async (dir) => {
|
|
31
|
+
const previousCwd = process.cwd();
|
|
32
|
+
try {
|
|
33
|
+
await mkdir(join(dir, ".pi"));
|
|
34
|
+
process.chdir(dir);
|
|
35
|
+
for (const actionFusion of [false, true]) {
|
|
36
|
+
await writeFile(
|
|
37
|
+
join(dir, ".pi", "settings.json"),
|
|
38
|
+
JSON.stringify({ hashlineEdit: { enabled: true, actionFusion } }),
|
|
39
|
+
);
|
|
40
|
+
const tools: Tool[] = [];
|
|
41
|
+
const api: Pick<ExtensionAPI, "on" | "registerEntryRenderer" | "registerTool"> = {
|
|
42
|
+
on() {
|
|
43
|
+
return () => {};
|
|
55
44
|
},
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
45
|
+
registerEntryRenderer() {},
|
|
46
|
+
registerTool(tool) {
|
|
47
|
+
tools.push(tool);
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
// This fixture only registers tools; the three hooks cover every API call at registration.
|
|
51
|
+
registerHashline(api as ExtensionAPI);
|
|
52
|
+
assert.equal(tools.length, 5);
|
|
53
|
+
for (const tool of tools) {
|
|
54
|
+
await t.test(`${tool.name}/Fusion ${actionFusion} → supports strict sampling`, () => {
|
|
55
|
+
assert.deepEqual(tool.constrainedSampling, STRICT_SAMPLING);
|
|
56
|
+
const strict = makeStrictJsonSchema(tool.parameters);
|
|
57
|
+
if (tool.name === "edit") {
|
|
58
|
+
assert.partialDeepStrictEqual(strict, {
|
|
59
|
+
type: "object",
|
|
60
|
+
additionalProperties: false,
|
|
61
|
+
required: actionFusion ? ["path", "steps", "then_run"] : ["path", "steps"],
|
|
62
|
+
properties: {
|
|
63
|
+
steps: {
|
|
64
|
+
type: "array",
|
|
65
|
+
items: {
|
|
66
|
+
type: "object",
|
|
67
|
+
additionalProperties: false,
|
|
68
|
+
required: ["action", "anchor", "end", "lines"],
|
|
69
|
+
properties: {
|
|
70
|
+
anchor: { anyOf: [{ type: "string" }, { type: "null" }] },
|
|
71
|
+
end: { anyOf: [{ type: "string" }, { type: "null" }] },
|
|
72
|
+
lines: { anyOf: [{ type: "array" }, { type: "null" }] },
|
|
73
|
+
},
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
...(actionFusion
|
|
77
|
+
? { then_run: { anyOf: [{ type: "object" }, { type: "null" }] } }
|
|
78
|
+
: {}),
|
|
79
|
+
},
|
|
80
|
+
});
|
|
81
|
+
const properties = strict.properties as Record<
|
|
82
|
+
string,
|
|
83
|
+
{ items?: { properties?: Record<string, unknown> } }
|
|
84
|
+
>;
|
|
85
|
+
assert.deepEqual(
|
|
86
|
+
Object.keys(properties),
|
|
87
|
+
actionFusion ? ["path", "steps", "then_run"] : ["path", "steps"],
|
|
88
|
+
);
|
|
89
|
+
const stepProperties = properties.steps.items?.properties;
|
|
90
|
+
assert.ok(stepProperties);
|
|
91
|
+
assert.deepEqual(Object.keys(stepProperties), ["action", "anchor", "end", "lines"]);
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
} finally {
|
|
97
|
+
process.chdir(previousCwd);
|
|
98
|
+
}
|
|
99
|
+
});
|
|
61
100
|
});
|
|
62
101
|
|
|
63
102
|
test("mutation cards use Fusion by default and explicit false removes command support", async () => {
|
|
@@ -143,7 +182,7 @@ test("mutation cards use Fusion by default and explicit false removes command su
|
|
|
143
182
|
);
|
|
144
183
|
const cases = [
|
|
145
184
|
{ name: "write", args: { content: "published\n", mode: "create" } },
|
|
146
|
-
{ name: "edit", args: {
|
|
185
|
+
{ name: "edit", args: { steps: [{ action: "append", lines: ["appended"] }] } },
|
|
147
186
|
{
|
|
148
187
|
name: "replace",
|
|
149
188
|
args: { replacements: [{ literal: true, find: "published", replace: "published" }] },
|
|
@@ -284,8 +323,8 @@ test("mutation cards use Fusion by default and explicit false removes command su
|
|
|
284
323
|
const edit = tools.find((tool) => tool.name === "edit");
|
|
285
324
|
const stale = {
|
|
286
325
|
path: "stale.txt",
|
|
287
|
-
|
|
288
|
-
{ action: "replace", anchor: `1#${computeLineHash(1, "target", 4)}`,
|
|
326
|
+
steps: [
|
|
327
|
+
{ action: "replace", anchor: `1#${computeLineHash(1, "target", 4)}`, lines: ["changed"] },
|
|
289
328
|
],
|
|
290
329
|
then_run: { command: "exit 99" },
|
|
291
330
|
};
|
|
@@ -419,7 +458,7 @@ test("loaded configuration controls hash length and recovery radius", async () =
|
|
|
419
458
|
await expectToolFailure(
|
|
420
459
|
call(makeEditOverride(dir, config), {
|
|
421
460
|
path: "configured.txt",
|
|
422
|
-
|
|
461
|
+
steps: [{ action: "delete", anchor: `1#${computeLineHash(1, "target", hashLen)}` }],
|
|
423
462
|
}),
|
|
424
463
|
"ANCHOR_MISMATCH",
|
|
425
464
|
(report) => {
|
|
@@ -442,19 +481,14 @@ test("configured read defaults bound omitted limits and returned bytes", async (
|
|
|
442
481
|
assert.match(description, /default 2\)/);
|
|
443
482
|
await writeFile(join(dir, "short.txt"), "a\nb\nc\n");
|
|
444
483
|
const paged = await call(read, { path: "short.txt" });
|
|
445
|
-
assert.
|
|
446
|
-
|
|
447
|
-
end: 2,
|
|
448
|
-
totalLines: 3,
|
|
449
|
-
nextOffset: 3,
|
|
450
|
-
});
|
|
451
|
-
assert.match(reportOf(paged, "read")?.next ?? "", /offset.*pagination\.nextOffset/);
|
|
484
|
+
assert.equal(reportOf(paged, "read")?.nextOffset, 3);
|
|
485
|
+
assert.match(reportOf(paged, "read")?.next ?? "", /offset.*nextOffset/);
|
|
452
486
|
assert.match(paged.content[0].text, /^2#[0-9A-Z]+│b$/m);
|
|
453
487
|
assert.doesNotMatch(paged.content[0].text, /^3#/m);
|
|
454
488
|
const explicit = await call(read, { path: "short.txt", limit: 3 });
|
|
455
489
|
assert.match(explicit.content[0].text, /^3#[0-9A-Z]+│c$/m);
|
|
456
490
|
await writeFile(join(dir, "wide.txt"), `${"x".repeat(2048)}\n`);
|
|
457
491
|
const wide = await call(read, { path: "wide.txt" });
|
|
458
|
-
assert.
|
|
492
|
+
assert.equal(reportOf(wide, "read")?.lineTooLong, formatByteSize(1024));
|
|
459
493
|
assert.doesNotMatch(wide.content[0].text, /^\d+#/m);
|
|
460
494
|
}));
|
package/src/pi/render.test.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { commandCompletion, type SessionCommand } from "./action-fusion.testing.ts";
|
|
1
2
|
import { argumentError } from "./argument-error.testing.ts";
|
|
2
3
|
import { test } from "node:test";
|
|
3
4
|
import assert from "node:assert/strict";
|
|
@@ -9,25 +10,26 @@ import { visibleWidth } from "@earendil-works/pi-tui";
|
|
|
9
10
|
import { initTheme, type ToolDefinition } from "@earendil-works/pi-coding-agent";
|
|
10
11
|
import type { TSchema } from "typebox";
|
|
11
12
|
import { theme } from "../../node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/theme/theme.js";
|
|
12
|
-
import { makeEditOverride } from "./
|
|
13
|
-
import { makeReplaceTool } from "./
|
|
14
|
-
import {
|
|
13
|
+
import { makeEditOverride } from "./tool-factories.testing.ts";
|
|
14
|
+
import { makeReplaceTool } from "./tool-factories.testing.ts";
|
|
15
|
+
import { MUTATION_CARD_SHOWN, diffCardRenderers, reportLines } from "./render.ts";
|
|
15
16
|
import { withMutationStatus } from "./fusion-card.ts";
|
|
16
|
-
import { makeWriteOverride } from "./
|
|
17
|
+
import { makeWriteOverride } from "./tool-factories.testing.ts";
|
|
17
18
|
import { generateMutationDetails } from "./mutation-result.ts";
|
|
18
|
-
import { createActionFusionExecutor
|
|
19
|
-
import { DEFAULT_CONFIG } from "./
|
|
19
|
+
import { createActionFusionExecutor } from "./action-fusion.ts";
|
|
20
|
+
import { DEFAULT_CONFIG } from "./tool-factories.testing.ts";
|
|
20
21
|
import { toDisplayLines } from "./grep-render.ts";
|
|
21
22
|
import { parseFileHeader } from "./grep-output.ts";
|
|
22
|
-
import { makeReadOverride } from "./
|
|
23
|
+
import { makeReadOverride } from "./tool-factories.testing.ts";
|
|
23
24
|
import { callTool } from "./tool-call.testing.ts";
|
|
24
25
|
import { renderToolError } from "./render.ts";
|
|
25
26
|
import { formatArgumentError } from "./argument-error.ts";
|
|
26
|
-
import { makeGrepOverride } from "./
|
|
27
|
+
import { makeGrepOverride } from "./tool-factories.testing.ts";
|
|
27
28
|
import { openTestSession } from "../testing/session.testing.ts";
|
|
28
|
-
import type { SuccessReport } from "./report-schema.ts";
|
|
29
|
-
import { renderReport
|
|
30
|
-
import {
|
|
29
|
+
import type { ActionFusionProgress, Report, SuccessReport } from "./report-schema.ts";
|
|
30
|
+
import { renderReport } from "./report.ts";
|
|
31
|
+
import { MAX_CONTENT_KIB, outputBudgetsFor } from "./budgets.ts";
|
|
32
|
+
import { DEFAULT_OUTPUT_BUDGETS } from "./tool-factories.testing.ts";
|
|
31
33
|
|
|
32
34
|
const mutationDetails = (
|
|
33
35
|
report: Pick<SuccessReport, "publication" | "freshness" | "then_run">,
|
|
@@ -46,18 +48,16 @@ test("empty logical diff → render according to confirmed publication state", (
|
|
|
46
48
|
assert.equal(diff.diff, "");
|
|
47
49
|
for (const publication of ["PUBLISHED", "NOT_PUBLISHED", undefined] as const) {
|
|
48
50
|
const output = stripVTControlCharacters(
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
"edit",
|
|
60
|
-
)
|
|
51
|
+
diffCardRenderers("edit", "Editing…", () => "")
|
|
52
|
+
.renderResult(
|
|
53
|
+
{
|
|
54
|
+
content: [],
|
|
55
|
+
details: { ...diff, report: { tool: "edit", publication } },
|
|
56
|
+
},
|
|
57
|
+
{ isPartial: false, expanded: true },
|
|
58
|
+
theme,
|
|
59
|
+
{ isError: false, args: {}, state: {} },
|
|
60
|
+
)
|
|
61
61
|
.render(100)
|
|
62
62
|
.join("\n"),
|
|
63
63
|
);
|
|
@@ -77,7 +77,7 @@ test("mutation headers refresh in place and retain isolated per-call counts", ()
|
|
|
77
77
|
]) {
|
|
78
78
|
const args = {
|
|
79
79
|
path: "a.txt",
|
|
80
|
-
|
|
80
|
+
steps: [{ action: "append" as const, lines: ["new"] }],
|
|
81
81
|
replacements: [{ literal: true, find: "old", replace: "new" }],
|
|
82
82
|
};
|
|
83
83
|
const context: any = {
|
|
@@ -111,36 +111,32 @@ test("mutation headers refresh in place and retain isolated per-call counts", ()
|
|
|
111
111
|
test("partial edit actions → refresh per-action counts", () => {
|
|
112
112
|
initTheme("dark");
|
|
113
113
|
const tool = makeEditOverride(process.cwd(), DEFAULT_CONFIG);
|
|
114
|
-
const
|
|
115
|
-
{ action: "replace", anchor: "1#AB",
|
|
116
|
-
{ action: "append",
|
|
117
|
-
{ action: "replace", anchor: "3#CD",
|
|
114
|
+
const steps = [
|
|
115
|
+
{ action: "replace", anchor: "1#AB", lines: ["new"] },
|
|
116
|
+
{ action: "append", lines: ["more"] },
|
|
117
|
+
{ action: "replace", anchor: "3#CD", lines: ["changed"] },
|
|
118
118
|
{ action: "delete", anchor: "5#EF" },
|
|
119
|
-
{ action: "insert_before", anchor: "7#GH",
|
|
120
|
-
{ action: "insert_after", anchor: "9#JK",
|
|
121
|
-
{ action: "prepend",
|
|
122
|
-
{ action: "copy", anchor: "1#AB", before: "3#CD" },
|
|
123
|
-
{ action: "move", anchor: "3#CD", after: "5#EF" },
|
|
119
|
+
{ action: "insert_before", anchor: "7#GH", lines: ["before"] },
|
|
120
|
+
{ action: "insert_after", anchor: "9#JK", lines: ["after"] },
|
|
121
|
+
{ action: "prepend", lines: ["first"] },
|
|
124
122
|
];
|
|
125
123
|
let header: ReturnType<typeof tool.renderCall> | undefined;
|
|
126
124
|
const context = { state: {} } as Parameters<typeof tool.renderCall>[2];
|
|
127
125
|
const render = (value: unknown) => {
|
|
128
126
|
header = tool.renderCall(
|
|
129
127
|
// Streaming arguments reach the renderer before schema validation.
|
|
130
|
-
{ path: "f.txt",
|
|
128
|
+
{ path: "f.txt", steps: value } as Parameters<typeof tool.renderCall>[0],
|
|
131
129
|
theme,
|
|
132
130
|
{ ...context, lastComponent: header },
|
|
133
131
|
);
|
|
134
132
|
return header.render(240).join("\n");
|
|
135
133
|
};
|
|
136
|
-
assert.match(render([
|
|
137
|
-
const mixed = render(
|
|
138
|
-
assert.match(mixed, /
|
|
134
|
+
assert.match(render([steps[0], {}]), /unknown ×1/);
|
|
135
|
+
const mixed = render(steps);
|
|
136
|
+
assert.match(mixed, /7 ops:/);
|
|
139
137
|
for (const [kind, count] of [
|
|
140
138
|
["replace", 2],
|
|
141
139
|
["delete", 1],
|
|
142
|
-
["copy", 1],
|
|
143
|
-
["move", 1],
|
|
144
140
|
["insert_before", 1],
|
|
145
141
|
["insert_after", 1],
|
|
146
142
|
["append", 1],
|
|
@@ -149,14 +145,14 @@ test("partial edit actions → refresh per-action counts", () => {
|
|
|
149
145
|
assert.ok(mixed.includes(`${kind} ×${count}`), mixed);
|
|
150
146
|
}
|
|
151
147
|
assert.doesNotMatch(mixed, /unknown/);
|
|
152
|
-
const single = render([
|
|
148
|
+
const single = render([steps[0]]);
|
|
153
149
|
assert.match(single, /1 op: replace ×1/);
|
|
154
|
-
assert.doesNotMatch(single, /append|
|
|
150
|
+
assert.doesNotMatch(single, /append|delete|insert_before|insert_after|prepend/);
|
|
155
151
|
assert.match(
|
|
156
152
|
render([null, { action: "rep" }, { action: "__proto__" }, { action: { toString: null } }]),
|
|
157
153
|
/4 ops: unknown ×4/,
|
|
158
154
|
);
|
|
159
|
-
for (const invalid of [[], undefined, JSON.stringify(
|
|
155
|
+
for (const invalid of [[], undefined, JSON.stringify(steps), "[{bad"]) {
|
|
160
156
|
assert.doesNotMatch(render(invalid), /ops?:/);
|
|
161
157
|
}
|
|
162
158
|
});
|
|
@@ -174,7 +170,7 @@ test("missing or empty mutation path → show a themed placeholder until the pat
|
|
|
174
170
|
let header: ReturnType<typeof tool.renderCall> | undefined;
|
|
175
171
|
for (const path of [undefined, "", "f.txt"]) {
|
|
176
172
|
// Streaming arguments may contain operations before the path arrives.
|
|
177
|
-
const args = { path,
|
|
173
|
+
const args = { path, steps: [], replacements: [] } as Parameters<
|
|
178
174
|
ReturnType<typeof makeEditOverride>["renderCall"]
|
|
179
175
|
>[0] &
|
|
180
176
|
Parameters<ReturnType<typeof makeReplaceTool>["renderCall"]>[0];
|
|
@@ -191,7 +187,7 @@ test("missing or empty mutation path → show a themed placeholder until the pat
|
|
|
191
187
|
test("mutation card owns stale-anchor notices without internal status", () => {
|
|
192
188
|
initTheme("dark");
|
|
193
189
|
const tool = withMutationStatus(makeEditOverride(process.cwd(), DEFAULT_CONFIG));
|
|
194
|
-
const args = { path: "a.txt",
|
|
190
|
+
const args = { path: "a.txt", steps: [{ action: "append" as const, lines: ["new"] }] };
|
|
195
191
|
const context: any = { args, state: {}, isPartial: false, isError: false, invalidate() {} };
|
|
196
192
|
const card = tool.renderCall!(args, theme, context);
|
|
197
193
|
tool.renderResult!(
|
|
@@ -221,7 +217,7 @@ test("mutation card owns stale-anchor notices without internal status", () => {
|
|
|
221
217
|
test("mutation card omits status when then_run was not requested", () => {
|
|
222
218
|
initTheme("dark");
|
|
223
219
|
const tool = withMutationStatus(makeEditOverride(process.cwd(), DEFAULT_CONFIG));
|
|
224
|
-
const args = { path: "a.txt",
|
|
220
|
+
const args = { path: "a.txt", steps: [{ action: "append" as const, lines: ["new"] }] };
|
|
225
221
|
const context: any = { args, state: {}, isPartial: false, isError: false, invalidate() {} };
|
|
226
222
|
const card = tool.renderCall!(args, theme, context);
|
|
227
223
|
tool.renderResult!(
|
|
@@ -260,12 +256,20 @@ test("unfused write errors retain the native full diagnostic", () => {
|
|
|
260
256
|
initTheme("dark");
|
|
261
257
|
const tool = withMutationStatus(makeWriteOverride(process.cwd()));
|
|
262
258
|
const args = { path: "a.txt", content: "new", mode: "overwrite" as const };
|
|
259
|
+
const diagnostic = "write failed\nimportant detail";
|
|
263
260
|
const context: any = { args, state: {}, isPartial: false, isError: true, invalidate() {} };
|
|
264
261
|
const card = tool.renderCall!(args, theme, context);
|
|
265
262
|
tool.renderResult!(
|
|
266
263
|
{
|
|
267
|
-
content: [{ type: "text", text:
|
|
268
|
-
details: {
|
|
264
|
+
content: [{ type: "text", text: diagnostic }],
|
|
265
|
+
details: {
|
|
266
|
+
report: {
|
|
267
|
+
tool: "write",
|
|
268
|
+
error: "FILESYSTEM_ERROR",
|
|
269
|
+
publication: "NOT_PUBLISHED",
|
|
270
|
+
message: diagnostic,
|
|
271
|
+
},
|
|
272
|
+
},
|
|
269
273
|
},
|
|
270
274
|
{ isPartial: false, expanded: false },
|
|
271
275
|
theme,
|
|
@@ -309,14 +313,20 @@ test("diff previews retain standalone CR and literal control-picture characters"
|
|
|
309
313
|
{ expanded: true, isPartial: false },
|
|
310
314
|
theme,
|
|
311
315
|
{
|
|
312
|
-
args: { path: "a.txt",
|
|
316
|
+
args: { path: "a.txt", steps: [{ action: "append", lines: ["new"] }] },
|
|
313
317
|
state: {},
|
|
314
318
|
isError: false,
|
|
315
319
|
} as Parameters<typeof tool.renderResult>[3],
|
|
316
320
|
);
|
|
317
321
|
assert.match(result.render(160).join("\n"), /␍/);
|
|
318
322
|
}
|
|
319
|
-
|
|
323
|
+
const preview = diffCardRenderers("edit", "Editing…", () => "").renderResult(
|
|
324
|
+
{ content: [], details: { diff: "-1 old␍\n+1 new␍" } },
|
|
325
|
+
{ isPartial: false, expanded: true },
|
|
326
|
+
theme,
|
|
327
|
+
{ isError: false, args: {}, state: {} },
|
|
328
|
+
);
|
|
329
|
+
assert.match(preview.render(160).join("\n"), /␍/);
|
|
320
330
|
});
|
|
321
331
|
|
|
322
332
|
test("150,000 rows in one grep group → renders every row with shared indentation folded", () => {
|
|
@@ -393,12 +403,12 @@ test("all tools render argument issues as field diagnostics while preserving mod
|
|
|
393
403
|
for (const tool of tools) {
|
|
394
404
|
for (const fused of [false, true]) {
|
|
395
405
|
const args = {
|
|
396
|
-
path: "unused.txt",
|
|
406
|
+
path: tool.name === "grep" ? ["unused.txt"] : "unused.txt",
|
|
397
407
|
content: "unused",
|
|
398
408
|
mode: "create" as const,
|
|
399
|
-
|
|
409
|
+
steps: [{ action: "append" as const, lines: ["unused"] }],
|
|
400
410
|
replacements: [{ literal: true, find: "unused", replace: "unused" }],
|
|
401
|
-
pattern: "unused",
|
|
411
|
+
pattern: ["unused"],
|
|
402
412
|
literal: true,
|
|
403
413
|
unexpected: true,
|
|
404
414
|
...(fused ? { then_run: { command: "must-not-run" } } : {}),
|
|
@@ -426,7 +436,9 @@ test("all tools render argument issues as field diagnostics while preserving mod
|
|
|
426
436
|
showImages: false,
|
|
427
437
|
isError: true,
|
|
428
438
|
};
|
|
429
|
-
|
|
439
|
+
// Pi passes unvalidated arguments to renderers after erasing their tool-specific types.
|
|
440
|
+
const renderCall = tool.renderCall as ToolDefinition<TSchema>["renderCall"];
|
|
441
|
+
const call = renderCall?.(args, theme, context);
|
|
430
442
|
// Pi supplies no tool-specific details when argument validation fails.
|
|
431
443
|
const renderError = tool.renderResult as NonNullable<
|
|
432
444
|
ToolDefinition<TSchema, undefined>["renderResult"]
|
|
@@ -476,7 +488,7 @@ test("expanded errors retain every text block while collapsed errors stay bounde
|
|
|
476
488
|
test("argument cards preserve omission notices and all expanded issues", () => {
|
|
477
489
|
initTheme("dark");
|
|
478
490
|
const issues = Array.from({ length: 200 }, (_, index) => ({
|
|
479
|
-
field: `
|
|
491
|
+
field: `steps[${index}].lines`,
|
|
480
492
|
reason: `中文🙂 ${index}: supply a line.\n${"context ".repeat(50)}\nFinal cause: empty body.`,
|
|
481
493
|
}));
|
|
482
494
|
const diagnostic = formatArgumentError(issues, true, DEFAULT_OUTPUT_BUDGETS);
|
|
@@ -522,7 +534,7 @@ test("unrecognized or malformed JSON errors retain their original diagnostic", (
|
|
|
522
534
|
});
|
|
523
535
|
|
|
524
536
|
test("argument diagnostics wrap Unicode and multiline reasons at narrow terminal widths", () => {
|
|
525
|
-
const field = "
|
|
537
|
+
const field = "steps[0].lines";
|
|
526
538
|
const reason = '中文🙂: supply at least one line.\nUse ["空行"] for this example.';
|
|
527
539
|
const diagnostic = formatArgumentError([{ field, reason }], false, DEFAULT_OUTPUT_BUDGETS);
|
|
528
540
|
const result = { content: [{ type: "text" as const, text: diagnostic }] };
|
|
@@ -548,12 +560,13 @@ test("command changes or removes the target → completed mutation stays success
|
|
|
548
560
|
for (const disturbance of ["changed", "missing"] as const) {
|
|
549
561
|
const path = `${disturbance}.txt`;
|
|
550
562
|
const target = join(cwd, path);
|
|
551
|
-
const
|
|
563
|
+
const executeTool: SessionCommand = async () => {
|
|
552
564
|
assert.equal(await readFile(target, "utf8"), "saved\n");
|
|
553
565
|
if (disturbance === "changed") await writeFile(target, "command changed the file\n");
|
|
554
566
|
else await unlink(target);
|
|
555
|
-
return {
|
|
556
|
-
}
|
|
567
|
+
return commandCompletion({ content: [{ type: "text", text: "checked" }] });
|
|
568
|
+
};
|
|
569
|
+
const fusion = createActionFusionExecutor(() => {});
|
|
557
570
|
const tool = withMutationStatus(makeWriteOverride(cwd, fusion));
|
|
558
571
|
const args = {
|
|
559
572
|
path,
|
|
@@ -583,7 +596,7 @@ test("command changes or removes the target → completed mutation stays success
|
|
|
583
596
|
const completedFrames: string[] = [];
|
|
584
597
|
const result = await callTool(tool, args, {
|
|
585
598
|
toolCallId: disturbance,
|
|
586
|
-
ctx: session.extensionRunner.createToolContext(disturbance, undefined),
|
|
599
|
+
ctx: { ...session.extensionRunner.createToolContext(disturbance, undefined), executeTool },
|
|
587
600
|
onUpdate: (update: AgentToolResult<{ actionFusion: ActionFusionProgress }>) => {
|
|
588
601
|
tool.renderCall!(args, theme, context);
|
|
589
602
|
renderResult(update, { isPartial: true, expanded: false }, theme, context);
|
|
@@ -713,3 +726,19 @@ test("report text has many short lines within the byte budget → renders every
|
|
|
713
726
|
});
|
|
714
727
|
}
|
|
715
728
|
});
|
|
729
|
+
|
|
730
|
+
test("TUI-only mutation facts render on the card while model serialization omits them", () => {
|
|
731
|
+
initTheme("dark");
|
|
732
|
+
const report: Report = {
|
|
733
|
+
tool: "edit",
|
|
734
|
+
path: "a.txt",
|
|
735
|
+
publication: "PUBLISHED",
|
|
736
|
+
progressError: { message: "display unavailable" },
|
|
737
|
+
};
|
|
738
|
+
const output = stripVTControlCharacters(
|
|
739
|
+
reportLines(report, theme, MUTATION_CARD_SHOWN).join("\n"),
|
|
740
|
+
);
|
|
741
|
+
assert.match(output, /progressError/);
|
|
742
|
+
assert.match(output, /display unavailable/);
|
|
743
|
+
assert.doesNotMatch(renderReport(report), /progressError|display unavailable/);
|
|
744
|
+
});
|