@criogaid/pi-hashline-edit 0.11.0 → 0.13.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/LICENSE +1 -0
- package/README.md +73 -17
- package/README.zh-CN.md +74 -18
- package/package.json +8 -7
- package/src/core/AGENTS.md +2 -2
- package/src/core/apply.test.ts +15 -2
- package/src/core/apply.ts +6 -10
- package/src/core/case-fold.test.ts +16 -25
- package/src/core/case-fold.ts +4 -4
- package/src/core/character-set.test.ts +1 -6
- package/src/core/character-set.ts +7 -61
- package/src/core/regex.ts +2 -32
- package/src/core/replace.test.ts +51 -0
- package/src/core/replace.ts +10 -4
- package/src/core/search-analysis.test.ts +66 -61
- package/src/core/search-analysis.ts +24 -39
- package/src/core/search-matrix.test.ts +2 -2
- package/src/core/search-matrix.testing.ts +6 -16
- package/src/core/search-schema.ts +0 -1
- package/src/core/search.test.ts +6 -19
- package/src/core/search.ts +10 -8
- package/src/index.ts +28 -3
- package/src/integration/config-registration.test.ts +77 -4
- package/src/integration/fusion-dispatch.test.ts +47 -2
- package/src/integration/grep-errors.test.ts +31 -0
- package/src/integration/grep-flags.test.ts +13 -196
- package/src/integration/grep-js-completeness.test.ts +41 -8
- package/src/integration/grep-line-candidates.test.ts +4 -33
- package/src/integration/grep-matrix.test.ts +1 -1
- package/src/integration/grep-path-matrix.test.ts +59 -65
- package/src/integration/grep-prefilter-coverage.test.ts +26 -8
- package/src/integration/grep-process-limits.test.ts +46 -0
- package/src/integration/grep-regex.test.ts +7 -2
- package/src/integration/grep-rg.test.ts +106 -12
- package/src/integration/grep-translation.test.ts +14 -7
- package/src/integration/model-budget-lifecycle.test.ts +41 -2
- package/src/integration/npm-package.test.ts +12 -10
- package/src/integration/npm-package.testing.ts +147 -1
- package/src/integration/replace-package.testing.ts +2 -2
- package/src/integration/report-replay.test.ts +4 -0
- package/src/pi/AGENTS.md +23 -15
- package/src/pi/action-fusion.test.ts +38 -4
- package/src/pi/action-fusion.ts +23 -19
- package/src/pi/argument-diagnostics.ts +28 -48
- package/src/pi/argument-validation.test.ts +103 -6
- package/src/pi/argument-validation.ts +55 -31
- package/src/pi/budgets.ts +19 -10
- package/src/pi/config.test.ts +1 -1
- package/src/pi/diagnostic-buffer.test.ts +1 -0
- package/src/pi/edit-tool.ts +3 -3
- package/src/pi/execute.test.ts +4 -0
- package/src/pi/failure-context.test.ts +24 -3
- package/src/pi/failure-context.ts +36 -42
- package/src/pi/failure-path.test.ts +8 -3
- package/src/pi/file-commit.test.ts +109 -52
- package/src/pi/file-commit.ts +62 -56
- package/src/pi/fusion-card.ts +12 -7
- package/src/pi/grep-candidates.test.ts +5 -5
- package/src/pi/grep-candidates.ts +80 -48
- package/src/pi/grep-matrix.test.ts +14 -29
- package/src/pi/grep-order.test.ts +132 -9
- package/src/pi/grep-output.ts +173 -48
- package/src/pi/grep-render.ts +40 -34
- package/src/pi/grep-rg.testing.ts +9 -6
- package/src/pi/grep-scope.ts +51 -29
- package/src/pi/grep-search.ts +96 -71
- package/src/pi/grep-tool.ts +28 -34
- package/src/pi/grep.test.ts +348 -83
- package/src/pi/model-budgets.test.ts +56 -6
- package/src/pi/model-budgets.ts +7 -4
- package/src/pi/mutation-result.test.ts +25 -1
- package/src/pi/mutation-result.ts +7 -2
- package/src/pi/mutation-runner.ts +4 -5
- package/src/pi/output-budgets.test.ts +3 -1
- package/src/pi/path.ts +18 -4
- package/src/pi/pi.test.ts +22 -0
- package/src/pi/read-delegation.test.ts +119 -0
- package/src/pi/read-tool.ts +109 -61
- package/src/pi/read.test.ts +351 -17
- package/src/pi/regex-worker.test.ts +42 -0
- package/src/pi/regex-worker.ts +17 -11
- package/src/pi/registration.test.ts +157 -102
- package/src/pi/render.test.ts +97 -0
- package/src/pi/render.ts +9 -9
- package/src/pi/replace-tool.ts +5 -2
- package/src/pi/report-schema.ts +75 -37
- package/src/pi/report.test.ts +73 -31
- package/src/pi/report.ts +12 -5
- package/src/pi/rg-process.ts +41 -5
- package/src/pi/rg-regex.test.ts +12 -39
- package/src/pi/rg-regex.ts +31 -79
- package/src/pi/text-stream.test.ts +3 -0
- package/src/pi/text-stream.ts +1 -1
- package/src/testing/regex-translation-corpus.ts +39 -96
|
@@ -13,7 +13,11 @@ import assert from "node:assert/strict";
|
|
|
13
13
|
import { test } from "node:test";
|
|
14
14
|
import registerHashline from "../index.ts";
|
|
15
15
|
import { initTheme } from "@earendil-works/pi-coding-agent";
|
|
16
|
-
import type {
|
|
16
|
+
import type {
|
|
17
|
+
ExtensionAPI,
|
|
18
|
+
ExtensionContext,
|
|
19
|
+
ToolDefinition,
|
|
20
|
+
} from "@earendil-works/pi-coding-agent";
|
|
17
21
|
import { ProcessTerminal, TuiMainScreen } from "@earendil-works/pi-tui";
|
|
18
22
|
import { ToolExecutionComponent } from "../../node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/components/tool-execution.js";
|
|
19
23
|
import { theme } from "../../node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/theme/theme.js";
|
|
@@ -25,95 +29,138 @@ import { reportOf } from "./report.ts";
|
|
|
25
29
|
import { formatByteSize } from "./budgets.ts";
|
|
26
30
|
import { expectToolFailure } from "./report-failure.testing.ts";
|
|
27
31
|
import { STRICT_SAMPLING } from "./schema.ts";
|
|
32
|
+
import { NEXT_GUIDELINE } from "./report-schema.ts";
|
|
33
|
+
import { ACTION_FUSION_GUIDELINES } from "./action-fusion.ts";
|
|
28
34
|
|
|
29
|
-
test("registered tools with or without Fusion →
|
|
35
|
+
test("registered tools with or without Fusion → expose prompt rules and convertible strict schemas", async (t) => {
|
|
36
|
+
const guidelines = {
|
|
37
|
+
edit: [
|
|
38
|
+
"Batch all steps for one file into a single edit call, and send changes to different files in the same response; they do not interfere.",
|
|
39
|
+
"Before citing a line after write, edit, or replace, get its anchor from a new read or grep. Only after edit, lines above the earliest changed line keep their anchors.",
|
|
40
|
+
],
|
|
41
|
+
grep: [
|
|
42
|
+
"When you need several independent searches, send them as separate grep calls in one response; they run in parallel.",
|
|
43
|
+
],
|
|
44
|
+
};
|
|
30
45
|
await withDir(async (dir) => {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
await
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
)
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
if (
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
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"],
|
|
46
|
+
await mkdir(join(dir, ".pi"));
|
|
47
|
+
for (const actionFusion of [false, true]) {
|
|
48
|
+
await writeFile(
|
|
49
|
+
join(dir, ".pi", "settings.json"),
|
|
50
|
+
JSON.stringify({ hashlineEdit: { enabled: true, actionFusion } }),
|
|
51
|
+
);
|
|
52
|
+
const tools: (Tool & Pick<ToolDefinition, "promptGuidelines">)[] = [];
|
|
53
|
+
const api: Pick<ExtensionAPI, "exec" | "on" | "registerEntryRenderer" | "registerTool"> = {
|
|
54
|
+
async exec() {
|
|
55
|
+
return { stdout: dir, stderr: "", code: 0, killed: false, truncated: false };
|
|
56
|
+
},
|
|
57
|
+
on() {
|
|
58
|
+
return () => {};
|
|
59
|
+
},
|
|
60
|
+
registerEntryRenderer() {},
|
|
61
|
+
registerTool(tool) {
|
|
62
|
+
tools.push(tool);
|
|
63
|
+
},
|
|
64
|
+
};
|
|
65
|
+
// The fixture implements the API methods used during registration.
|
|
66
|
+
await registerHashline(api as ExtensionAPI);
|
|
67
|
+
assert.equal(tools.length, 5);
|
|
68
|
+
for (const tool of tools) {
|
|
69
|
+
const { name } = tool;
|
|
70
|
+
if (name === "read" || name === "edit" || name === "grep") {
|
|
71
|
+
await t.test(`${name}/Fusion ${actionFusion} → registers the tool's prompt rules`, () => {
|
|
72
|
+
if (name === "read") {
|
|
73
|
+
const [codemodeRule = "", ...sharedRules] = tool.promptGuidelines ?? [];
|
|
74
|
+
assert.match(
|
|
75
|
+
codemodeRule,
|
|
76
|
+
/Files containing NUL go to native read without a Hashline header/,
|
|
88
77
|
);
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
assert.deepEqual(
|
|
78
|
+
assert.deepEqual(sharedRules, [NEXT_GUIDELINE]);
|
|
79
|
+
} else {
|
|
80
|
+
assert.deepEqual(tool.promptGuidelines, [
|
|
81
|
+
...guidelines[name],
|
|
82
|
+
...(name === "edit" && actionFusion ? ACTION_FUSION_GUIDELINES : []),
|
|
83
|
+
NEXT_GUIDELINE,
|
|
84
|
+
]);
|
|
92
85
|
}
|
|
93
86
|
});
|
|
94
87
|
}
|
|
88
|
+
await t.test(`${tool.name}/Fusion ${actionFusion} → supports strict sampling`, () => {
|
|
89
|
+
assert.deepEqual(tool.constrainedSampling, STRICT_SAMPLING);
|
|
90
|
+
const strict = makeStrictJsonSchema(tool.parameters);
|
|
91
|
+
if (tool.name === "read") {
|
|
92
|
+
assert.partialDeepStrictEqual(tool.parameters, {
|
|
93
|
+
required: ["path"],
|
|
94
|
+
properties: {
|
|
95
|
+
anchors: {
|
|
96
|
+
type: "boolean",
|
|
97
|
+
description:
|
|
98
|
+
"false omits LINE#HASH│ prefixes for files you will not edit, saving about a third of the tokens. The header stays and standalone CR displays as ␍ (default true).",
|
|
99
|
+
},
|
|
100
|
+
},
|
|
101
|
+
});
|
|
102
|
+
assert.partialDeepStrictEqual(strict, {
|
|
103
|
+
properties: { anchors: { anyOf: [{ type: "boolean" }, { type: "null" }] } },
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
if (tool.name === "edit") {
|
|
107
|
+
assert.partialDeepStrictEqual(strict, {
|
|
108
|
+
type: "object",
|
|
109
|
+
additionalProperties: false,
|
|
110
|
+
required: actionFusion ? ["path", "steps", "then_run"] : ["path", "steps"],
|
|
111
|
+
properties: {
|
|
112
|
+
steps: {
|
|
113
|
+
type: "array",
|
|
114
|
+
items: {
|
|
115
|
+
type: "object",
|
|
116
|
+
additionalProperties: false,
|
|
117
|
+
required: ["action", "anchor", "end", "lines"],
|
|
118
|
+
properties: {
|
|
119
|
+
anchor: { anyOf: [{ type: "string" }, { type: "null" }] },
|
|
120
|
+
end: { anyOf: [{ type: "string" }, { type: "null" }] },
|
|
121
|
+
lines: { anyOf: [{ type: "array" }, { type: "null" }] },
|
|
122
|
+
},
|
|
123
|
+
},
|
|
124
|
+
},
|
|
125
|
+
...(actionFusion
|
|
126
|
+
? { then_run: { anyOf: [{ type: "object" }, { type: "null" }] } }
|
|
127
|
+
: {}),
|
|
128
|
+
},
|
|
129
|
+
});
|
|
130
|
+
const properties = strict.properties as Record<
|
|
131
|
+
string,
|
|
132
|
+
{ items?: { properties?: Record<string, unknown> } }
|
|
133
|
+
>;
|
|
134
|
+
assert.deepEqual(
|
|
135
|
+
Object.keys(properties),
|
|
136
|
+
actionFusion ? ["path", "steps", "then_run"] : ["path", "steps"],
|
|
137
|
+
);
|
|
138
|
+
const stepProperties = properties.steps.items?.properties;
|
|
139
|
+
assert.ok(stepProperties);
|
|
140
|
+
assert.deepEqual(Object.keys(stepProperties), ["action", "anchor", "end", "lines"]);
|
|
141
|
+
}
|
|
142
|
+
});
|
|
95
143
|
}
|
|
96
|
-
} finally {
|
|
97
|
-
process.chdir(previousCwd);
|
|
98
144
|
}
|
|
99
145
|
});
|
|
100
146
|
});
|
|
101
147
|
|
|
102
148
|
test("mutation cards use Fusion by default and explicit false removes command support", async () => {
|
|
103
149
|
const dir = await mkdtemp(join(tmpdir(), "hashline-registration-"));
|
|
104
|
-
const previousCwd = process.cwd();
|
|
105
150
|
try {
|
|
106
151
|
await mkdir(join(dir, ".pi"));
|
|
107
152
|
await writeFile(
|
|
108
153
|
join(dir, ".pi", "settings.json"),
|
|
109
154
|
JSON.stringify({ hashlineEdit: { enabled: true } }),
|
|
110
155
|
);
|
|
111
|
-
process.chdir(dir);
|
|
112
156
|
const tools: any[] = [];
|
|
113
157
|
const entries: any[] = [];
|
|
114
158
|
const renderers = new Map<string, any>();
|
|
115
159
|
let start: ((event: unknown, ctx: unknown) => void) | undefined;
|
|
116
|
-
registerHashline({
|
|
160
|
+
await registerHashline({
|
|
161
|
+
async exec() {
|
|
162
|
+
return { stdout: dir, stderr: "", code: 0, killed: false, truncated: false };
|
|
163
|
+
},
|
|
117
164
|
on(event: string, handler: (event: unknown, ctx: unknown) => void) {
|
|
118
165
|
if (event === "session_start") start = handler;
|
|
119
166
|
},
|
|
@@ -137,7 +184,6 @@ test("mutation cards use Fusion by default and explicit false removes command su
|
|
|
137
184
|
const grep = tools.find((tool) => tool.name === "grep");
|
|
138
185
|
assert.deepEqual(Object.keys(grep.parameters.properties).sort(), [
|
|
139
186
|
"context",
|
|
140
|
-
"flags",
|
|
141
187
|
"glob",
|
|
142
188
|
"ignoreCase",
|
|
143
189
|
"limit",
|
|
@@ -148,6 +194,11 @@ test("mutation cards use Fusion by default and explicit false removes command su
|
|
|
148
194
|
"pattern",
|
|
149
195
|
]);
|
|
150
196
|
assert.equal(grep.parameters.additionalProperties, false);
|
|
197
|
+
assert.match(
|
|
198
|
+
grep.parameters.properties.ignoreCase.description,
|
|
199
|
+
/no pattern contains an uppercase letter/,
|
|
200
|
+
);
|
|
201
|
+
assert.doesNotMatch(grep.parameters.properties.ignoreCase.description, /flag/);
|
|
151
202
|
await assert.rejects(
|
|
152
203
|
callTool(grep, { pattern: "needle", literal: true, unexpected: true }),
|
|
153
204
|
rejectsArgument("unexpected", /not allowed/),
|
|
@@ -157,11 +208,7 @@ test("mutation cards use Fusion by default and explicit false removes command su
|
|
|
157
208
|
tool.parameters.properties.then_run,
|
|
158
209
|
`${tool.name} should expose then_run when actionFusion is enabled`,
|
|
159
210
|
);
|
|
160
|
-
assert.
|
|
161
|
-
tool.description,
|
|
162
|
-
/then_run/,
|
|
163
|
-
`${tool.name} description should mention then_run when actionFusion is enabled`,
|
|
164
|
-
);
|
|
211
|
+
assert.doesNotMatch(tool.description, /then_run/);
|
|
165
212
|
}
|
|
166
213
|
initTheme("dark");
|
|
167
214
|
const tui = new TuiMainScreen(new ProcessTerminal());
|
|
@@ -354,7 +401,10 @@ test("mutation cards use Fusion by default and explicit false removes command su
|
|
|
354
401
|
JSON.stringify({ hashlineEdit: { actionFusion: false } }),
|
|
355
402
|
);
|
|
356
403
|
const disabledTools: any[] = [];
|
|
357
|
-
registerHashline({
|
|
404
|
+
await registerHashline({
|
|
405
|
+
async exec() {
|
|
406
|
+
return { stdout: dir, stderr: "", code: 0, killed: false, truncated: false };
|
|
407
|
+
},
|
|
358
408
|
on() {},
|
|
359
409
|
registerEntryRenderer() {},
|
|
360
410
|
registerTool(tool: any) {
|
|
@@ -371,6 +421,10 @@ test("mutation cards use Fusion by default and explicit false removes command su
|
|
|
371
421
|
assert.equal(tool.parameters.properties.then_run, undefined);
|
|
372
422
|
assert.equal(tool.renderShell, "default");
|
|
373
423
|
assert.doesNotMatch(tool.description, /then_run/);
|
|
424
|
+
assert.equal(
|
|
425
|
+
tool.description,
|
|
426
|
+
tools.find((enabled) => enabled.name === tool.name)?.description,
|
|
427
|
+
);
|
|
374
428
|
// Without Action Fusion the schema has no then_run, so Pi rejects it before execute.
|
|
375
429
|
await assert.rejects(
|
|
376
430
|
callTool(
|
|
@@ -382,7 +436,6 @@ test("mutation cards use Fusion by default and explicit false removes command su
|
|
|
382
436
|
);
|
|
383
437
|
}
|
|
384
438
|
} finally {
|
|
385
|
-
process.chdir(previousCwd);
|
|
386
439
|
await rm(dir, { recursive: true, force: true });
|
|
387
440
|
}
|
|
388
441
|
});
|
|
@@ -408,33 +461,35 @@ function anchorLine(block: string, line: number) {
|
|
|
408
461
|
|
|
409
462
|
test("disabled config registers no tools — built-ins remain", async () => {
|
|
410
463
|
await withDir(async (dir) => {
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
}
|
|
464
|
+
await mkdir(join(dir, ".pi"));
|
|
465
|
+
await writeFile(
|
|
466
|
+
join(dir, ".pi", "settings.json"),
|
|
467
|
+
JSON.stringify({ hashlineEdit: { enabled: false } }),
|
|
468
|
+
);
|
|
469
|
+
await writeFile(join(dir, "f.txt"), "old value\n");
|
|
470
|
+
const registered: string[] = [];
|
|
471
|
+
await registerHashline({
|
|
472
|
+
async exec() {
|
|
473
|
+
return { stdout: dir, stderr: "", code: 0, killed: false, truncated: false };
|
|
474
|
+
},
|
|
475
|
+
on() {
|
|
476
|
+
assert.fail("Disabled extension must not subscribe to events");
|
|
477
|
+
},
|
|
478
|
+
registerEntryRenderer() {
|
|
479
|
+
assert.fail("Disabled extension must not register a replay renderer");
|
|
480
|
+
},
|
|
481
|
+
registerTool(tool: { name: string }) {
|
|
482
|
+
registered.push(tool.name);
|
|
483
|
+
},
|
|
484
|
+
} as any);
|
|
485
|
+
assert.deepEqual(registered, []);
|
|
486
|
+
const builtin = createEditTool(dir);
|
|
487
|
+
const params = validateToolArguments(builtin, {
|
|
488
|
+
name: "edit",
|
|
489
|
+
arguments: { path: "f.txt", edits: [{ oldText: "old value", newText: "new value" }] },
|
|
490
|
+
} as any);
|
|
491
|
+
await call(builtin, params);
|
|
492
|
+
assert.equal(await readFile(join(dir, "f.txt"), "utf-8"), "new value\n");
|
|
438
493
|
});
|
|
439
494
|
});
|
|
440
495
|
|
package/src/pi/render.test.ts
CHANGED
|
@@ -42,6 +42,42 @@ const mutationDetails = (
|
|
|
42
42
|
},
|
|
43
43
|
});
|
|
44
44
|
|
|
45
|
+
test("Fusion mutation card → follows Pi's output padding when it changes", async (t) => {
|
|
46
|
+
initTheme("dark");
|
|
47
|
+
const { cwd } = await openTestSession(t, { tools: [] });
|
|
48
|
+
const tool = withMutationStatus(
|
|
49
|
+
makeWriteOverride(
|
|
50
|
+
cwd,
|
|
51
|
+
createActionFusionExecutor(() => {}),
|
|
52
|
+
),
|
|
53
|
+
);
|
|
54
|
+
const args = { path: "target.txt", content: "saved", mode: "create" as const };
|
|
55
|
+
const context: Parameters<NonNullable<typeof tool.renderCall>>[2] = {
|
|
56
|
+
args,
|
|
57
|
+
toolCallId: "padding",
|
|
58
|
+
cwd,
|
|
59
|
+
state: {},
|
|
60
|
+
lastComponent: undefined,
|
|
61
|
+
durationMs: undefined,
|
|
62
|
+
invalidate() {},
|
|
63
|
+
executionStarted: true,
|
|
64
|
+
argsComplete: true,
|
|
65
|
+
isPartial: true,
|
|
66
|
+
expanded: false,
|
|
67
|
+
showImages: false,
|
|
68
|
+
isError: false,
|
|
69
|
+
outputPad: 0,
|
|
70
|
+
keyText: () => "",
|
|
71
|
+
keyHint: (_key, description) => description,
|
|
72
|
+
};
|
|
73
|
+
for (const outputPad of [0, 4]) {
|
|
74
|
+
const lines = tool.renderCall!(args, theme, { ...context, outputPad }).render(100);
|
|
75
|
+
const header = lines.map(stripVTControlCharacters).find((line) => line.includes("target.txt"));
|
|
76
|
+
assert.ok(header);
|
|
77
|
+
assert.equal(header.length - header.trimStart().length, outputPad);
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
|
|
45
81
|
test("empty logical diff → render according to confirmed publication state", () => {
|
|
46
82
|
initTheme("dark");
|
|
47
83
|
const diff = generateMutationDetails("same\r\nsame\n", "same\nsame\r\n");
|
|
@@ -358,6 +394,55 @@ test("Unicode line separators in grep paths → parses the full file header", as
|
|
|
358
394
|
}
|
|
359
395
|
});
|
|
360
396
|
|
|
397
|
+
test("grep content groups with row-like filenames → headers do not affect row alignment", () => {
|
|
398
|
+
initTheme("dark");
|
|
399
|
+
const raw = [
|
|
400
|
+
"notes.txt · 1 match",
|
|
401
|
+
"9#ABCD│ topic · 1 match",
|
|
402
|
+
"",
|
|
403
|
+
"1234567890#ABCD│name · 1 match",
|
|
404
|
+
"2#ABCD│ hit",
|
|
405
|
+
].join("\n");
|
|
406
|
+
assert.deepEqual(toDisplayLines(raw, theme).map(stripVTControlCharacters), [
|
|
407
|
+
"notes.txt · 1 match",
|
|
408
|
+
" 9: › topic · 1 match",
|
|
409
|
+
"",
|
|
410
|
+
"1234567890#ABCD│name · 1 match",
|
|
411
|
+
" 2: › hit",
|
|
412
|
+
]);
|
|
413
|
+
});
|
|
414
|
+
|
|
415
|
+
test("grep files mode with header-like and anchor-like names → preserves complete paths", () => {
|
|
416
|
+
initTheme("dark");
|
|
417
|
+
const tool = makeGrepOverride(process.cwd(), DEFAULT_CONFIG);
|
|
418
|
+
const paths = ["a · 1 match", "1#ABCD│name"];
|
|
419
|
+
const rendered = tool.renderResult(
|
|
420
|
+
{ content: [{ type: "text", text: paths.join("\n") }], details: undefined },
|
|
421
|
+
{ isPartial: false, expanded: true },
|
|
422
|
+
theme,
|
|
423
|
+
{
|
|
424
|
+
args: { pattern: ["needle"], literal: true, outputMode: "files" },
|
|
425
|
+
toolCallId: "test",
|
|
426
|
+
invalidate() {},
|
|
427
|
+
lastComponent: undefined,
|
|
428
|
+
state: {},
|
|
429
|
+
cwd: process.cwd(),
|
|
430
|
+
executionStarted: true,
|
|
431
|
+
durationMs: undefined,
|
|
432
|
+
outputPad: 1,
|
|
433
|
+
keyText: () => "",
|
|
434
|
+
keyHint: (_key: string, description: string) => description,
|
|
435
|
+
argsComplete: true,
|
|
436
|
+
isPartial: false,
|
|
437
|
+
expanded: true,
|
|
438
|
+
showImages: false,
|
|
439
|
+
isError: false,
|
|
440
|
+
},
|
|
441
|
+
);
|
|
442
|
+
const lines = rendered.render(120).map((line) => stripVTControlCharacters(line).trimEnd());
|
|
443
|
+
for (const path of paths) assert.ok(lines.includes(path), JSON.stringify(lines));
|
|
444
|
+
});
|
|
445
|
+
|
|
361
446
|
test("grep renders anchored and plain groups with shared width and folded indentation", () => {
|
|
362
447
|
initTheme("dark");
|
|
363
448
|
const raw = [
|
|
@@ -430,6 +515,10 @@ test("all tools render argument issues as field diagnostics while preserving mod
|
|
|
430
515
|
lastComponent: undefined,
|
|
431
516
|
cwd,
|
|
432
517
|
executionStarted: true,
|
|
518
|
+
durationMs: undefined,
|
|
519
|
+
outputPad: 1,
|
|
520
|
+
keyText: () => "",
|
|
521
|
+
keyHint: (_key: string, description: string) => description,
|
|
433
522
|
argsComplete: true,
|
|
434
523
|
isPartial: false,
|
|
435
524
|
expanded,
|
|
@@ -582,6 +671,10 @@ test("command changes or removes the target → completed mutation stays success
|
|
|
582
671
|
lastComponent: undefined,
|
|
583
672
|
invalidate() {},
|
|
584
673
|
executionStarted: true,
|
|
674
|
+
durationMs: undefined,
|
|
675
|
+
outputPad: 1,
|
|
676
|
+
keyText: () => "",
|
|
677
|
+
keyHint: (_key: string, description: string) => description,
|
|
585
678
|
argsComplete: true,
|
|
586
679
|
isPartial: true,
|
|
587
680
|
expanded: false,
|
|
@@ -642,6 +735,10 @@ test("success renderers receive replayed or hooked reports → display only sche
|
|
|
642
735
|
lastComponent: undefined,
|
|
643
736
|
invalidate() {},
|
|
644
737
|
executionStarted: true,
|
|
738
|
+
durationMs: undefined,
|
|
739
|
+
outputPad: 1,
|
|
740
|
+
keyText: () => "",
|
|
741
|
+
keyHint: (_key: string, description: string) => description,
|
|
645
742
|
argsComplete: true,
|
|
646
743
|
isPartial: false,
|
|
647
744
|
expanded: true,
|
package/src/pi/render.ts
CHANGED
|
@@ -198,8 +198,7 @@ export function reportLines(
|
|
|
198
198
|
lines.push(
|
|
199
199
|
theme.fg(report.publication === "NOT_PUBLISHED" ? "dim" : "warning", report.publication),
|
|
200
200
|
);
|
|
201
|
-
|
|
202
|
-
for (const line of report.message.split("\n")) lines.push(theme.fg("error", line));
|
|
201
|
+
for (const line of report.message.split("\n")) lines.push(theme.fg("error", line));
|
|
203
202
|
}
|
|
204
203
|
for (const [key, value] of reportEntries(report)) {
|
|
205
204
|
if (HEADER_FIELDS.includes(key) || shown.has(key)) continue;
|
|
@@ -236,13 +235,14 @@ export function renderToolError(
|
|
|
236
235
|
expanded: boolean,
|
|
237
236
|
): Text {
|
|
238
237
|
const report = reportOf(result, tool);
|
|
239
|
-
const lines =
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
238
|
+
const lines =
|
|
239
|
+
report?.error !== undefined
|
|
240
|
+
? reportLines(report, theme)
|
|
241
|
+
: result.content.flatMap((block) =>
|
|
242
|
+
block.type === "text" && block.text
|
|
243
|
+
? block.text.split("\n").map((line) => theme.fg("error", line))
|
|
244
|
+
: [],
|
|
245
|
+
);
|
|
246
246
|
return renderOutputPreview(lines.length ? lines : [theme.fg("error", "Error")], expanded, theme);
|
|
247
247
|
}
|
|
248
248
|
|
package/src/pi/replace-tool.ts
CHANGED
|
@@ -27,7 +27,6 @@
|
|
|
27
27
|
import type { Theme } from "@earendil-works/pi-coding-agent";
|
|
28
28
|
import { Type, type Static } from "typebox";
|
|
29
29
|
import { applyReplacements } from "../core/replace.ts";
|
|
30
|
-
import { checkRegexArguments } from "../core/regex.ts";
|
|
31
30
|
import { REPLACEMENTS_SCHEMA } from "../core/replace-schema.ts";
|
|
32
31
|
import { runRegexReplacements } from "./replace-regex.ts";
|
|
33
32
|
import { unwritableTextError } from "../core/text.ts";
|
|
@@ -44,7 +43,11 @@ import {
|
|
|
44
43
|
type MutationTarget,
|
|
45
44
|
type MutationToolEnvironment,
|
|
46
45
|
} from "./mutation-runner.ts";
|
|
47
|
-
import {
|
|
46
|
+
import {
|
|
47
|
+
argumentItems,
|
|
48
|
+
checkRegexArguments,
|
|
49
|
+
type ReportArgumentIssue,
|
|
50
|
+
} from "./argument-validation.ts";
|
|
48
51
|
import { filePathField } from "./schema.ts";
|
|
49
52
|
|
|
50
53
|
const replaceSchema = Type.Object(
|