@criogaid/pi-hashline-edit 0.6.1 → 0.8.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 +78 -369
- package/README.zh-CN.md +162 -0
- package/THIRD_PARTY_NOTICES.md +80 -0
- package/package.json +11 -6
- package/src/core/AGENTS.md +20 -0
- package/src/core/apply.test.ts +328 -161
- package/src/core/apply.ts +129 -95
- package/src/core/case-fold.test.ts +44 -0
- package/src/core/case-fold.ts +77 -0
- package/src/core/character-set.test.ts +103 -0
- package/src/core/character-set.ts +184 -0
- package/src/core/errors.test.ts +23 -0
- package/src/core/errors.ts +70 -4
- package/src/core/hash.test.ts +1 -25
- package/src/core/hash.ts +0 -5
- package/src/core/lines.ts +32 -7
- package/src/core/ranges.test.ts +41 -9
- package/src/core/ranges.ts +11 -4
- package/src/core/regex.ts +51 -0
- package/src/core/replace-schema.ts +41 -0
- package/src/core/replace.test.ts +90 -0
- package/src/core/replace.ts +40 -56
- package/src/core/search-analysis.test.ts +208 -0
- package/src/core/search-analysis.ts +379 -0
- package/src/core/search-matrix.test.ts +64 -0
- package/src/core/search-matrix.testing.ts +183 -0
- package/src/core/search-schema.ts +18 -0
- package/src/core/search.test.ts +145 -0
- package/src/core/search.ts +119 -0
- package/src/core/text.test.ts +16 -8
- package/src/core/text.ts +26 -6
- package/src/core/types.ts +20 -17
- package/src/index.ts +24 -16
- package/src/integration/config-registration.test.ts +42 -28
- package/src/integration/fusion-dispatch.test.ts +62 -127
- package/src/integration/grep-errors.test.ts +50 -0
- package/src/integration/grep-flags.test.ts +273 -0
- package/src/integration/grep-js-completeness.test.ts +218 -0
- package/src/integration/grep-line-candidates.test.ts +233 -0
- package/src/integration/grep-matrix.test.ts +121 -0
- package/src/integration/grep-order.test.ts +78 -0
- package/src/integration/grep-path-matrix.test.ts +133 -0
- package/src/integration/grep-prefilter-coverage.test.ts +189 -0
- package/src/integration/grep-regex.test.ts +407 -0
- package/src/integration/grep-rg.test.ts +294 -436
- package/src/integration/grep-scan-budget.test.ts +111 -0
- package/src/integration/grep-translation.test.ts +206 -0
- package/src/integration/large-text.test.ts +56 -1
- package/src/integration/model-budget-lifecycle.test.ts +137 -0
- package/src/integration/mutation-file-types.test.ts +12 -26
- package/src/integration/mutation-file-types.testing.ts +33 -0
- package/src/integration/npm-package.test.ts +17 -0
- package/src/integration/npm-package.testing.ts +97 -0
- package/src/integration/publication-read-changes.test.ts +376 -0
- package/src/integration/read-changes.test.ts +98 -0
- package/src/integration/replace-package.test.ts +17 -36
- package/src/integration/replace-package.testing.ts +36 -0
- package/src/integration/replace-worker-boundary.test.ts +117 -0
- package/src/integration/report-replay.test.ts +90 -0
- package/src/integration/utf8-errors.test.ts +46 -0
- package/src/pi/AGENTS.md +54 -0
- package/src/pi/action-fusion.test.ts +256 -251
- package/src/pi/action-fusion.ts +121 -332
- package/src/pi/anchor-format.test.ts +16 -0
- package/src/pi/anchor-format.ts +16 -3
- package/src/pi/argument-diagnostics.ts +478 -0
- package/src/pi/argument-error.testing.ts +46 -0
- package/src/pi/argument-error.ts +76 -0
- package/src/pi/argument-format.test.ts +197 -0
- package/src/pi/argument-validation.test.ts +780 -49
- package/src/pi/argument-validation.ts +55 -58
- package/src/pi/budgets.ts +48 -21
- package/src/pi/codemode.test.ts +96 -0
- package/src/pi/config.test.ts +29 -15
- package/src/pi/config.ts +27 -13
- package/src/pi/diagnostic-buffer.test.ts +51 -16
- package/src/pi/diagnostic-buffer.ts +13 -16
- package/src/pi/directory-sync.test.ts +4 -1
- package/src/pi/edit-tool.ts +103 -99
- package/src/pi/error-text.ts +39 -16
- package/src/pi/execute.test.ts +407 -429
- package/src/pi/extension-loading.test.ts +7 -27
- package/src/pi/extension-loading.testing.ts +2 -14
- package/src/pi/failure-context.test.ts +265 -88
- package/src/pi/failure-context.ts +165 -181
- package/src/pi/failure-path.test.ts +179 -117
- package/src/pi/file-commit.test.ts +90 -73
- package/src/pi/file-commit.ts +216 -178
- package/src/pi/file-read.test.ts +29 -0
- package/src/pi/file-read.ts +60 -0
- package/src/pi/file-revision.ts +25 -0
- package/src/pi/file-snapshot.test.ts +1 -1
- package/src/pi/fusion-card-interaction.test.ts +143 -0
- package/src/pi/fusion-card.test.ts +233 -51
- package/src/pi/fusion-card.ts +246 -142
- package/src/pi/grep-candidates.test.ts +127 -0
- package/src/pi/grep-candidates.ts +191 -0
- package/src/pi/grep-matrix.test.ts +83 -0
- package/src/pi/grep-order.test.ts +323 -0
- package/src/pi/grep-output.testing.ts +24 -0
- package/src/pi/grep-output.ts +187 -151
- package/src/pi/grep-render.ts +31 -25
- package/src/pi/grep-scope.ts +62 -54
- package/src/pi/grep-search.ts +327 -241
- package/src/pi/grep-tool.ts +126 -147
- package/src/pi/grep-worker.mjs +4 -0
- package/src/pi/grep-worker.ts +14 -0
- package/src/pi/grep.test.ts +813 -713
- package/src/pi/model-budgets.test.ts +43 -0
- package/src/pi/model-budgets.ts +44 -0
- package/src/pi/mutation-outcome.testing.ts +6 -7
- package/src/pi/mutation-result.test.ts +45 -91
- package/src/pi/mutation-result.ts +86 -114
- package/src/pi/mutation-runner.ts +81 -81
- package/src/pi/output-budgets.test.ts +175 -0
- package/src/pi/path.ts +10 -1
- package/src/pi/pi.test.ts +4 -5
- package/src/pi/read-tool.ts +108 -142
- package/src/pi/read.test.ts +155 -96
- package/src/pi/regex-worker-contract.ts +55 -0
- package/src/pi/regex-worker.ts +95 -0
- package/src/pi/registration.test.ts +148 -124
- package/src/pi/render.test.ts +361 -84
- package/src/pi/render.ts +150 -32
- package/src/pi/replace-regex.ts +13 -48
- package/src/pi/replace-tool.ts +52 -158
- package/src/pi/replace-worker-contract.ts +10 -0
- package/src/pi/replace-worker.ts +12 -8
- package/src/pi/replace.test.ts +191 -340
- package/src/pi/report-cause.ts +103 -0
- package/src/pi/report-failure.testing.ts +20 -0
- package/src/pi/report-schema.ts +524 -0
- package/src/pi/report.test.ts +343 -0
- package/src/pi/report.ts +285 -0
- package/src/pi/result-safety.test.ts +216 -481
- package/src/pi/rg-process.test.ts +101 -76
- package/src/pi/rg-process.ts +130 -177
- package/src/pi/rg-regex.test.ts +67 -0
- package/src/pi/rg-regex.ts +715 -0
- package/src/pi/text-stream.test.ts +97 -69
- package/src/pi/text-stream.ts +97 -76
- package/src/pi/tool-call.testing.ts +20 -46
- package/src/pi/write-tool.ts +50 -41
- package/src/pi/write.test.ts +71 -95
- package/src/testing/extension-loader.testing.ts +24 -0
- package/src/testing/installation.testing.ts +77 -0
- package/src/testing/process.testing.ts +33 -0
- package/src/testing/regex-host.testing.ts +20 -0
- package/src/testing/regex-translation-corpus.ts +324 -0
- package/src/testing/rg-line-listing.fixture.mjs +7 -0
- package/src/testing/run-tests.ts +47 -0
- package/src/testing/session.testing.ts +127 -0
- package/src/integration/forget-grep.test.ts +0 -98
- package/src/pi/forget-tool.ts +0 -268
- package/src/pi/forget.test.ts +0 -343
- package/src/pi/forget.testing.ts +0 -273
- package/src/pi/rg-line-ranges.test.ts +0 -66
- package/src/pi/rg-line-ranges.ts +0 -75
- package/src/pi/rg-match-bytes.ts +0 -95
- package/src/pi/rg-text-view.ts +0 -192
- package/src/pi/tool-prompts.ts +0 -15
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { rejectsArgument } from "./argument-error.testing.ts";
|
|
1
2
|
import { createEditTool } from "@earendil-works/pi-coding-agent";
|
|
2
3
|
import { validateToolArguments } from "@earendil-works/pi-ai";
|
|
3
4
|
import { makeEditOverride } from "./edit-tool.ts";
|
|
@@ -11,10 +12,17 @@ import assert from "node:assert/strict";
|
|
|
11
12
|
import { test } from "node:test";
|
|
12
13
|
import registerHashline from "../index.ts";
|
|
13
14
|
import { initTheme } from "@earendil-works/pi-coding-agent";
|
|
15
|
+
import type { ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
16
|
+
import { ProcessTerminal, TuiMainScreen } from "@earendil-works/pi-tui";
|
|
14
17
|
import { ToolExecutionComponent } from "../../node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/components/tool-execution.js";
|
|
15
18
|
import { theme } from "../../node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/theme/theme.js";
|
|
16
19
|
import { computeLineHash } from "../core/hash.ts";
|
|
17
20
|
import { callTool } from "./tool-call.testing.ts";
|
|
21
|
+
import type { AgentToolResult } from "@earendil-works/pi-agent-core";
|
|
22
|
+
import type { ActionFusionProgress } from "./action-fusion.ts";
|
|
23
|
+
import { reportOf } from "./report.ts";
|
|
24
|
+
import { formatByteSize } from "./budgets.ts";
|
|
25
|
+
import { expectToolFailure } from "./report-failure.testing.ts";
|
|
18
26
|
|
|
19
27
|
test("mutation cards use Fusion by default and explicit false removes command support", async () => {
|
|
20
28
|
const dir = await mkdtemp(join(tmpdir(), "hashline-registration-"));
|
|
@@ -29,8 +37,14 @@ test("mutation cards use Fusion by default and explicit false removes command su
|
|
|
29
37
|
const tools: any[] = [];
|
|
30
38
|
const entries: any[] = [];
|
|
31
39
|
const renderers = new Map<string, any>();
|
|
40
|
+
let start: ((event: unknown, ctx: unknown) => void) | undefined;
|
|
32
41
|
registerHashline({
|
|
33
|
-
on() {
|
|
42
|
+
on(event: string, handler: (event: unknown, ctx: unknown) => void) {
|
|
43
|
+
if (event === "session_start") start = handler;
|
|
44
|
+
},
|
|
45
|
+
getSettings() {
|
|
46
|
+
return {};
|
|
47
|
+
},
|
|
34
48
|
registerEntryRenderer(type: string, renderer: any) {
|
|
35
49
|
renderers.set(type, renderer);
|
|
36
50
|
},
|
|
@@ -48,6 +62,7 @@ test("mutation cards use Fusion by default and explicit false removes command su
|
|
|
48
62
|
const grep = tools.find((tool) => tool.name === "grep");
|
|
49
63
|
assert.deepEqual(Object.keys(grep.parameters.properties).sort(), [
|
|
50
64
|
"context",
|
|
65
|
+
"flags",
|
|
51
66
|
"glob",
|
|
52
67
|
"ignoreCase",
|
|
53
68
|
"limit",
|
|
@@ -59,68 +74,89 @@ test("mutation cards use Fusion by default and explicit false removes command su
|
|
|
59
74
|
]);
|
|
60
75
|
assert.equal(grep.parameters.additionalProperties, false);
|
|
61
76
|
await assert.rejects(
|
|
62
|
-
callTool(grep, { pattern: "needle", literal: true,
|
|
63
|
-
|
|
77
|
+
callTool(grep, { pattern: "needle", literal: true, unexpected: true }),
|
|
78
|
+
rejectsArgument("unexpected", /not allowed/),
|
|
64
79
|
);
|
|
65
80
|
for (const tool of tools.filter((tool) => ["edit", "replace", "write"].includes(tool.name))) {
|
|
66
81
|
assert.ok(
|
|
67
82
|
tool.parameters.properties.then_run,
|
|
68
83
|
`${tool.name} should expose then_run when actionFusion is enabled`,
|
|
69
84
|
);
|
|
85
|
+
assert.match(
|
|
86
|
+
tool.description,
|
|
87
|
+
/then_run/,
|
|
88
|
+
`${tool.name} description should mention then_run when actionFusion is enabled`,
|
|
89
|
+
);
|
|
70
90
|
}
|
|
71
91
|
initTheme("dark");
|
|
92
|
+
const tui = new TuiMainScreen(new ProcessTerminal());
|
|
93
|
+
tui.requestRender = () => {};
|
|
94
|
+
assert.ok(start);
|
|
95
|
+
start(
|
|
96
|
+
{},
|
|
97
|
+
{
|
|
98
|
+
cwd: dir,
|
|
99
|
+
mode: "tui",
|
|
100
|
+
sessionManager: { getBranch: () => entries },
|
|
101
|
+
ui: {
|
|
102
|
+
setWidget(_key: string, content: Parameters<ExtensionContext["ui"]["setWidget"]>[1]) {
|
|
103
|
+
if (typeof content === "function") content(tui, theme);
|
|
104
|
+
},
|
|
105
|
+
},
|
|
106
|
+
},
|
|
107
|
+
);
|
|
72
108
|
const cases = [
|
|
73
109
|
{ name: "write", args: { content: "published\n", mode: "create" } },
|
|
74
110
|
{ name: "edit", args: { edits: [{ op: "append", body: ["appended"] }] } },
|
|
75
|
-
{
|
|
76
|
-
|
|
111
|
+
{
|
|
112
|
+
name: "replace",
|
|
113
|
+
args: { replacements: [{ literal: true, find: "published", replace: "published" }] },
|
|
114
|
+
},
|
|
115
|
+
] as const;
|
|
77
116
|
for (const { name, args } of cases) {
|
|
78
117
|
const tool = tools.find((tool) => tool.name === name);
|
|
79
118
|
const params = { path: "published.txt", ...args, then_run: { command: "exit 7" } };
|
|
80
|
-
const card = new ToolExecutionComponent(
|
|
81
|
-
name,
|
|
82
|
-
name,
|
|
83
|
-
params,
|
|
84
|
-
{},
|
|
85
|
-
tool,
|
|
86
|
-
{ requestRender() {} } as any,
|
|
87
|
-
dir,
|
|
88
|
-
);
|
|
119
|
+
const card = new ToolExecutionComponent(name, name, params, {}, tool, tui, dir);
|
|
89
120
|
card.setArgsComplete();
|
|
90
121
|
card.markExecutionStarted();
|
|
91
122
|
const frames: {
|
|
92
123
|
command: string;
|
|
93
|
-
publication: string;
|
|
94
124
|
mutationCompleted: boolean;
|
|
95
125
|
output: string;
|
|
96
126
|
commandOutput: string;
|
|
127
|
+
expandedOutput: string;
|
|
97
128
|
}[] = [];
|
|
98
|
-
const result = await tool
|
|
99
|
-
name,
|
|
100
|
-
|
|
101
|
-
undefined,
|
|
102
|
-
(update: any) => {
|
|
129
|
+
const result = await callTool(tool, params, {
|
|
130
|
+
toolCallId: name,
|
|
131
|
+
onUpdate: (update: AgentToolResult<{ actionFusion: ActionFusionProgress }>) => {
|
|
103
132
|
card.updateResult({ ...update, isError: false }, true);
|
|
104
133
|
const entry = entries.find(
|
|
105
134
|
(entry) => entry.customType === "hashline-then-run" && entry.data.toolCallId === name,
|
|
106
135
|
);
|
|
107
136
|
const commandCard = renderers.get(entry.customType)(entry, { expanded: false }, theme);
|
|
137
|
+
card.setExpanded(true);
|
|
138
|
+
const expandedOutput = card.render(100).join("\n");
|
|
139
|
+
card.setExpanded(false);
|
|
108
140
|
frames.push({
|
|
109
141
|
...update.details.actionFusion,
|
|
110
142
|
output: card.render(100).join("\n"),
|
|
111
143
|
commandOutput: commandCard.render(100).join("\n"),
|
|
144
|
+
expandedOutput,
|
|
112
145
|
});
|
|
113
146
|
},
|
|
114
|
-
{ cwd: dir },
|
|
147
|
+
ctx: { cwd: dir },
|
|
148
|
+
});
|
|
149
|
+
assert.equal(
|
|
150
|
+
reportOf(result, name)?.publication,
|
|
151
|
+
name === "replace" ? "NOT_PUBLISHED" : "PUBLISHED",
|
|
115
152
|
);
|
|
116
|
-
assert.equal(result
|
|
117
|
-
assert.match(result.content[1].text, /File changes are saved|No file changes were published/);
|
|
153
|
+
assert.equal(reportOf(result, name)?.then_run?.status, "failed");
|
|
118
154
|
assert.ok(frames[0].output.includes(theme.getBgAnsi("toolPendingBg")));
|
|
119
155
|
const running = frames.find((frame) => frame.command === "running")!;
|
|
120
156
|
assert.ok(running, `${name} should emit running progress`);
|
|
121
157
|
assert.ok(
|
|
122
158
|
running.output.includes(theme.getBgAnsi("toolSuccessBg")),
|
|
123
|
-
`${name} should
|
|
159
|
+
`${name} should finish its mutation card while then_run is running`,
|
|
124
160
|
);
|
|
125
161
|
assert.ok(!running.output.includes(theme.getBgAnsi("toolPendingBg")));
|
|
126
162
|
assert.ok(running.commandOutput.includes(theme.getBgAnsi("toolPendingBg")));
|
|
@@ -130,18 +166,23 @@ test("mutation cards use Fusion by default and explicit false removes command su
|
|
|
130
166
|
)!;
|
|
131
167
|
assert.ok(
|
|
132
168
|
completed?.output.includes(theme.getBgAnsi("toolSuccessBg")),
|
|
133
|
-
"mutation completion must
|
|
169
|
+
"mutation completion must finish its card before command checks",
|
|
134
170
|
);
|
|
135
|
-
|
|
171
|
+
for (const frame of frames) {
|
|
172
|
+
const expectedBackground = theme.getBgAnsi(
|
|
173
|
+
frame.mutationCompleted ? "toolSuccessBg" : "toolPendingBg",
|
|
174
|
+
);
|
|
175
|
+
assert.ok(frame.output.includes(expectedBackground));
|
|
176
|
+
assert.ok(frame.expandedOutput.includes(expectedBackground));
|
|
177
|
+
}
|
|
178
|
+
if (name === "replace") {
|
|
179
|
+
assert.match(running.output, /No diff available/);
|
|
180
|
+
}
|
|
136
181
|
card.updateResult({ ...result, isError: false });
|
|
137
182
|
assert.ok(card.render(100).join("\n").includes(theme.getBgAnsi("toolSuccessBg")));
|
|
183
|
+
if (name === "replace") assert.match(card.render(100).join("\n"), /No net change/);
|
|
138
184
|
card.setExpanded(true);
|
|
139
|
-
assert.doesNotMatch(card.render(100).join("\n"), /
|
|
140
|
-
assert.doesNotMatch(card.render(100).join("\n"), /Command exited|then_run:failed/);
|
|
141
|
-
assert.doesNotMatch(
|
|
142
|
-
frames.at(-1)!.commandOutput,
|
|
143
|
-
/publication=|freshness=|File changes are saved|No file changes were published|mutation completed/,
|
|
144
|
-
);
|
|
185
|
+
assert.doesNotMatch(card.render(100).join("\n"), /Command exited/);
|
|
145
186
|
assert.ok(card.render(100).join("\n").includes(theme.getBgAnsi("toolSuccessBg")));
|
|
146
187
|
|
|
147
188
|
const invalid = {
|
|
@@ -155,56 +196,43 @@ test("mutation cards use Fusion by default and explicit false removes command su
|
|
|
155
196
|
invalid,
|
|
156
197
|
{},
|
|
157
198
|
tool,
|
|
158
|
-
|
|
199
|
+
tui,
|
|
159
200
|
dir,
|
|
160
201
|
);
|
|
161
|
-
await
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
(update:
|
|
167
|
-
|
|
168
|
-
},
|
|
169
|
-
{ cwd: dir },
|
|
170
|
-
),
|
|
171
|
-
(error: Error) => {
|
|
172
|
-
failedCard.updateResult({
|
|
173
|
-
content: [{ type: "text", text: error.message }],
|
|
174
|
-
isError: true,
|
|
175
|
-
});
|
|
176
|
-
const output = failedCard.render(100).join("\n");
|
|
177
|
-
assert.ok(
|
|
178
|
-
output.includes(theme.getBgAnsi("toolErrorBg")),
|
|
179
|
-
`${name} mutation failure should turn red`,
|
|
180
|
-
);
|
|
181
|
-
assert.ok(!output.includes(theme.getBgAnsi("toolPendingBg")));
|
|
182
|
-
failedCard.setExpanded(true);
|
|
183
|
-
const expandedError = failedCard.render(400).join("\n");
|
|
184
|
-
for (const line of error.message.split("\n")) {
|
|
185
|
-
assert.ok(expandedError.includes(line), `${name} hid a failure diagnostic`);
|
|
186
|
-
}
|
|
187
|
-
assert.match(output, name === "write" ? /does not exist/ : /Error reading/);
|
|
188
|
-
const entry = entries.find(
|
|
189
|
-
(entry) =>
|
|
190
|
-
entry.customType === "hashline-then-run" && entry.data.toolCallId === `${name}-bad`,
|
|
191
|
-
);
|
|
192
|
-
const commandOutput = renderers
|
|
193
|
-
.get(entry.customType)(entry, { expanded: true }, theme)
|
|
194
|
-
.render(160)
|
|
195
|
-
.join("\n");
|
|
196
|
-
assert.match(
|
|
197
|
-
commandOutput,
|
|
198
|
-
/skipped[\s\S]*Not run because the mutation did not complete/,
|
|
199
|
-
);
|
|
200
|
-
assert.doesNotMatch(
|
|
201
|
-
commandOutput,
|
|
202
|
-
/Error reading|does not exist|publication=|freshness=/,
|
|
203
|
-
);
|
|
204
|
-
assert.ok(!commandOutput.includes(theme.getBgAnsi("toolErrorBg")));
|
|
205
|
-
return true;
|
|
206
|
-
},
|
|
202
|
+
const failed = await tool.execute(
|
|
203
|
+
`${name}-bad`,
|
|
204
|
+
invalid,
|
|
205
|
+
undefined,
|
|
206
|
+
(update: AgentToolResult<unknown>) =>
|
|
207
|
+
failedCard.updateResult({ ...update, isError: false }, true),
|
|
208
|
+
{ cwd: dir },
|
|
207
209
|
);
|
|
210
|
+
assert.equal(failed.isError, true);
|
|
211
|
+
const report = reportOf(failed, name);
|
|
212
|
+
assert.equal(report?.error, "PATH_NOT_FOUND");
|
|
213
|
+
failedCard.updateResult(failed);
|
|
214
|
+
const output = failedCard.render(100).join("\n");
|
|
215
|
+
assert.ok(
|
|
216
|
+
output.includes(theme.getBgAnsi("toolErrorBg")),
|
|
217
|
+
`${name} mutation failure should turn red`,
|
|
218
|
+
);
|
|
219
|
+
assert.ok(!output.includes(theme.getBgAnsi("toolPendingBg")));
|
|
220
|
+
failedCard.setExpanded(true);
|
|
221
|
+
const expandedError = failedCard.render(400).join("\n");
|
|
222
|
+
assert.ok(expandedError.includes(report?.message ?? ""));
|
|
223
|
+
if (report?.cause?.message) assert.ok(expandedError.includes(report.cause.message));
|
|
224
|
+
assert.match(output, /PATH_NOT_FOUND/);
|
|
225
|
+
const entry = entries.find(
|
|
226
|
+
(entry) =>
|
|
227
|
+
entry.customType === "hashline-then-run" && entry.data.toolCallId === `${name}-bad`,
|
|
228
|
+
);
|
|
229
|
+
const commandOutput = renderers
|
|
230
|
+
.get(entry.customType)(entry, { expanded: true }, theme)
|
|
231
|
+
.render(160)
|
|
232
|
+
.join("\n");
|
|
233
|
+
assert.match(commandOutput, /skipped[\s\S]*Not run.*mutation did not complete/);
|
|
234
|
+
assert.doesNotMatch(commandOutput, /Error reading|does not exist/);
|
|
235
|
+
assert.ok(!commandOutput.includes(theme.getBgAnsi("toolErrorBg")));
|
|
208
236
|
}
|
|
209
237
|
assert.deepEqual(
|
|
210
238
|
entries.map((entry) => entry.data.command),
|
|
@@ -213,7 +241,9 @@ test("mutation cards use Fusion by default and explicit false removes command su
|
|
|
213
241
|
assert.ok(
|
|
214
242
|
entries.every(
|
|
215
243
|
(entry) =>
|
|
216
|
-
!("publication" in entry.data) &&
|
|
244
|
+
!("publication" in entry.data) &&
|
|
245
|
+
!("path" in entry.data) &&
|
|
246
|
+
["unchanged", "changed", "missing", "unknown"].includes(entry.data.freshness),
|
|
217
247
|
),
|
|
218
248
|
);
|
|
219
249
|
await writeFile(join(dir, "stale.txt"), "header\ntarget\n");
|
|
@@ -223,42 +253,28 @@ test("mutation cards use Fusion by default and explicit false removes command su
|
|
|
223
253
|
edits: [{ op: "replace", anchor: `1#${computeLineHash(1, "target", 4)}`, body: ["changed"] }],
|
|
224
254
|
then_run: { command: "exit 99" },
|
|
225
255
|
};
|
|
226
|
-
const staleCard = new ToolExecutionComponent(
|
|
227
|
-
|
|
256
|
+
const staleCard = new ToolExecutionComponent("edit", "stale", stale, {}, edit, tui, dir);
|
|
257
|
+
const failed = await edit.execute(
|
|
228
258
|
"stale",
|
|
229
259
|
stale,
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
dir,
|
|
260
|
+
undefined,
|
|
261
|
+
(update: AgentToolResult<unknown>) =>
|
|
262
|
+
staleCard.updateResult({ ...update, isError: false }, true),
|
|
263
|
+
{ cwd: dir },
|
|
234
264
|
);
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
{ cwd: dir },
|
|
242
|
-
),
|
|
243
|
-
(error: Error) => {
|
|
244
|
-
assert.match(error.message, /checksum-matching candidate/);
|
|
245
|
-
staleCard.updateResult({ content: [{ type: "text", text: error.message }], isError: true });
|
|
246
|
-
assert.match(staleCard.render(160).join("\n"), /Anchor mismatch/);
|
|
247
|
-
const entry = entries.find(
|
|
248
|
-
(entry) => entry.customType === "hashline-then-run" && entry.data.toolCallId === "stale",
|
|
249
|
-
);
|
|
250
|
-
const commandOutput = renderers
|
|
251
|
-
.get(entry.customType)(entry, { expanded: true }, theme)
|
|
252
|
-
.render(160)
|
|
253
|
-
.join("\n");
|
|
254
|
-
assert.match(commandOutput, /skipped/);
|
|
255
|
-
assert.doesNotMatch(
|
|
256
|
-
commandOutput,
|
|
257
|
-
/Anchor mismatch|candidate|Input-anchor|publication=|freshness=/,
|
|
258
|
-
);
|
|
259
|
-
return true;
|
|
260
|
-
},
|
|
265
|
+
assert.equal(failed.isError, true);
|
|
266
|
+
assert.equal(reportOf(failed, "edit")?.failures?.[0].result, "shifted");
|
|
267
|
+
staleCard.updateResult(failed);
|
|
268
|
+
assert.match(staleCard.render(160).join("\n"), /ANCHOR_MISMATCH/);
|
|
269
|
+
const entry = entries.find(
|
|
270
|
+
(entry) => entry.customType === "hashline-then-run" && entry.data.toolCallId === "stale",
|
|
261
271
|
);
|
|
272
|
+
const commandOutput = renderers
|
|
273
|
+
.get(entry.customType)(entry, { expanded: true }, theme)
|
|
274
|
+
.render(160)
|
|
275
|
+
.join("\n");
|
|
276
|
+
assert.match(commandOutput, /skipped/);
|
|
277
|
+
assert.doesNotMatch(commandOutput, /ANCHOR_MISMATCH|candidate/);
|
|
262
278
|
assert.equal(await readFile(join(dir, "stale.txt"), "utf8"), "header\ntarget\n");
|
|
263
279
|
await writeFile(
|
|
264
280
|
join(dir, ".pi", "settings.json"),
|
|
@@ -281,6 +297,7 @@ test("mutation cards use Fusion by default and explicit false removes command su
|
|
|
281
297
|
)) {
|
|
282
298
|
assert.equal(tool.parameters.properties.then_run, undefined);
|
|
283
299
|
assert.equal(tool.renderShell, "default");
|
|
300
|
+
assert.doesNotMatch(tool.description, /then_run/);
|
|
284
301
|
// Without Action Fusion the schema has no then_run, so Pi rejects it before execute.
|
|
285
302
|
await assert.rejects(
|
|
286
303
|
callTool(
|
|
@@ -288,7 +305,7 @@ test("mutation cards use Fusion by default and explicit false removes command su
|
|
|
288
305
|
{ path: "published.txt", then_run: { command: "exit 0" } },
|
|
289
306
|
{ ctx: { cwd: dir } },
|
|
290
307
|
),
|
|
291
|
-
|
|
308
|
+
rejectsArgument("then_run", /not allowed/),
|
|
292
309
|
);
|
|
293
310
|
}
|
|
294
311
|
} finally {
|
|
@@ -354,9 +371,9 @@ test("loaded configuration controls hash length and recovery radius", async () =
|
|
|
354
371
|
await mkdir(join(dir, ".pi"));
|
|
355
372
|
await writeFile(join(dir, "configured.txt"), text);
|
|
356
373
|
for (const [hashLen, shiftRadius, expected] of [
|
|
357
|
-
[6, 0,
|
|
358
|
-
[6, 1,
|
|
359
|
-
[8, 3,
|
|
374
|
+
[6, 0, "unresolved"],
|
|
375
|
+
[6, 1, "shifted"],
|
|
376
|
+
[8, 3, "ambiguous"],
|
|
360
377
|
] as const) {
|
|
361
378
|
await writeFile(
|
|
362
379
|
join(dir, ".pi", "settings.json"),
|
|
@@ -365,12 +382,16 @@ test("loaded configuration controls hash length and recovery radius", async () =
|
|
|
365
382
|
const config = loadConfig(dir);
|
|
366
383
|
const read = await call(makeReadOverride(dir, config), { path: "configured.txt" });
|
|
367
384
|
assert.equal(anchorLine(read.content[0].text, 1).split("#")[1].length, hashLen);
|
|
368
|
-
await
|
|
385
|
+
await expectToolFailure(
|
|
369
386
|
call(makeEditOverride(dir, config), {
|
|
370
387
|
path: "configured.txt",
|
|
371
388
|
edits: [{ op: "delete", anchor: `1#${computeLineHash(1, "target", hashLen)}` }],
|
|
372
389
|
}),
|
|
373
|
-
|
|
390
|
+
"ANCHOR_MISMATCH",
|
|
391
|
+
(report) => {
|
|
392
|
+
assert.equal(report.failures?.[0].result, expected);
|
|
393
|
+
if (expected === "shifted") assert.match(report.failures?.[0].candidate ?? "", /^2#/);
|
|
394
|
+
},
|
|
374
395
|
);
|
|
375
396
|
assert.equal(await readFile(join(dir, "configured.txt"), "utf8"), text);
|
|
376
397
|
}
|
|
@@ -387,16 +408,19 @@ test("configured read defaults bound omitted limits and returned bytes", async (
|
|
|
387
408
|
assert.match(description, /default 2\)/);
|
|
388
409
|
await writeFile(join(dir, "short.txt"), "a\nb\nc\n");
|
|
389
410
|
const paged = await call(read, { path: "short.txt" });
|
|
390
|
-
assert.deepEqual(paged
|
|
391
|
-
|
|
411
|
+
assert.deepEqual(reportOf(paged, "read")?.pagination, {
|
|
412
|
+
start: 1,
|
|
413
|
+
end: 2,
|
|
414
|
+
totalLines: 3,
|
|
415
|
+
nextOffset: 3,
|
|
416
|
+
});
|
|
417
|
+
assert.match(reportOf(paged, "read")?.next ?? "", /offset.*pagination\.nextOffset/);
|
|
392
418
|
assert.match(paged.content[0].text, /^2#[0-9A-Z]+│b$/m);
|
|
393
419
|
assert.doesNotMatch(paged.content[0].text, /^3#/m);
|
|
394
420
|
const explicit = await call(read, { path: "short.txt", limit: 3 });
|
|
395
421
|
assert.match(explicit.content[0].text, /^3#[0-9A-Z]+│c$/m);
|
|
396
422
|
await writeFile(join(dir, "wide.txt"), `${"x".repeat(2048)}\n`);
|
|
397
423
|
const wide = await call(read, { path: "wide.txt" });
|
|
398
|
-
assert.
|
|
399
|
-
assert.
|
|
400
|
-
assert.equal(wide.details.truncation.maxBytes, 1024);
|
|
401
|
-
assert.equal(wide.details.truncation.outputBytes, 0);
|
|
424
|
+
assert.deepEqual(reportOf(wide, "read")?.lineTooLong, { line: 1, limit: formatByteSize(1024) });
|
|
425
|
+
assert.doesNotMatch(wide.content[0].text, /^\d+#/m);
|
|
402
426
|
}));
|