@criogaid/pi-hashline-edit 0.12.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 +59 -16
- package/README.zh-CN.md +59 -16
- package/package.json +2 -2
- package/src/core/AGENTS.md +2 -2
- package/src/core/apply.test.ts +13 -0
- package/src/core/apply.ts +5 -9
- 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 -36
- 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 +27 -2
- 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 +3 -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 +15 -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 +63 -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.testing.ts +2 -3
- package/src/integration/replace-package.testing.ts +2 -2
- package/src/pi/AGENTS.md +21 -13
- 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 +61 -27
- package/src/pi/argument-validation.ts +34 -0
- 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 +1 -1
- package/src/pi/failure-context.test.ts +23 -2
- 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 +3 -2
- package/src/pi/grep-candidates.test.ts +5 -5
- package/src/pi/grep-candidates.ts +81 -50
- package/src/pi/grep-matrix.test.ts +14 -29
- package/src/pi/grep-order.test.ts +132 -9
- package/src/pi/grep-output.ts +169 -51
- 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 +13 -22
- package/src/pi/grep.test.ts +310 -84
- 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 +3 -4
- 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 +306 -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 +54 -0
- package/src/pi/render.ts +9 -9
- package/src/pi/replace-tool.ts +5 -2
- package/src/pi/report-schema.ts +52 -31
- package/src/pi/report.test.ts +60 -10
- package/src/pi/rg-process.ts +41 -5
- package/src/pi/rg-regex.test.ts +12 -52
- package/src/pi/rg-regex.ts +29 -77
- 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,24 @@ 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
|
+
|
|
361
415
|
test("grep files mode with header-like and anchor-like names → preserves complete paths", () => {
|
|
362
416
|
initTheme("dark");
|
|
363
417
|
const tool = makeGrepOverride(process.cwd(), DEFAULT_CONFIG);
|
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(
|
package/src/pi/report-schema.ts
CHANGED
|
@@ -153,20 +153,19 @@ export type ArgumentIssue = Static<typeof ARGUMENT_ISSUE_SCHEMA>;
|
|
|
153
153
|
* facts must also state the decision their value changes; TUI-only facts omit it.
|
|
154
154
|
*/
|
|
155
155
|
type FactAudience = "model" | "tui";
|
|
156
|
-
type FactDefinition<T extends TSchema = TSchema> = {
|
|
156
|
+
type FactDefinition<T extends TSchema = TSchema, A extends FactAudience = FactAudience> = {
|
|
157
157
|
schema: T;
|
|
158
|
-
audience:
|
|
159
|
-
|
|
160
|
-
};
|
|
158
|
+
audience: A;
|
|
159
|
+
} & (A extends "model" ? { decision: string } : { decision?: never });
|
|
161
160
|
|
|
162
161
|
function modelFact<T extends TSchema, const D extends string>(
|
|
163
162
|
schema: T,
|
|
164
163
|
decision: D extends "" ? never : D,
|
|
165
|
-
): FactDefinition<T> {
|
|
164
|
+
): FactDefinition<T, "model"> {
|
|
166
165
|
return { schema, audience: "model", decision };
|
|
167
166
|
}
|
|
168
167
|
|
|
169
|
-
function tuiFact<T extends TSchema>(schema: T): FactDefinition<T> {
|
|
168
|
+
function tuiFact<T extends TSchema>(schema: T): FactDefinition<T, "tui"> {
|
|
170
169
|
return { schema, audience: "tui" };
|
|
171
170
|
}
|
|
172
171
|
|
|
@@ -194,7 +193,7 @@ const FACT_FIELDS = {
|
|
|
194
193
|
Type.Array(Type.String(), {
|
|
195
194
|
description: "Resolved paths that do not exist; shows where a relative path led.",
|
|
196
195
|
}),
|
|
197
|
-
"
|
|
196
|
+
"Correct the missing paths and search them again, or use create mode for a new file.",
|
|
198
197
|
),
|
|
199
198
|
|
|
200
199
|
// Anchor verification (failure-context.ts).
|
|
@@ -425,7 +424,7 @@ export const ERROR_DEFINITIONS = {
|
|
|
425
424
|
SYMLINK_UNRESOLVED: { facts: NONE },
|
|
426
425
|
PUBLISH_FAILED: { facts: NONE },
|
|
427
426
|
POST_PROCESS_FAILED: { facts: NONE },
|
|
428
|
-
SEARCH_INCOMPLETE: { facts: facts(["diagnostics"], ["scanLimit"]) },
|
|
427
|
+
SEARCH_INCOMPLETE: { facts: facts(["diagnostics"], ["scanLimit", "missing"]) },
|
|
429
428
|
RIPGREP_FAILED: { facts: NONE },
|
|
430
429
|
UNSUPPORTED_PATH: { facts: NONE },
|
|
431
430
|
UNCLASSIFIED: { facts: NONE },
|
|
@@ -502,6 +501,11 @@ export const OUTCOME_NEXT: readonly OutcomeRule[] = [
|
|
|
502
501
|
"Inspect the line in chunks with bash, or use replace for a known literal or regex change; a smaller limit cannot split a line.",
|
|
503
502
|
],
|
|
504
503
|
["nextOffset", "If you need more lines, set offset to nextOffset."],
|
|
504
|
+
// Ahead of grep's limits: repeating the corrected search states them again.
|
|
505
|
+
[
|
|
506
|
+
"missing",
|
|
507
|
+
"Only the existing paths were searched. Correct the paths in missing and repeat the search.",
|
|
508
|
+
],
|
|
505
509
|
// Ahead of matchLimit: once the byte budget cuts the output, raising limit shows nothing more.
|
|
506
510
|
["outputLimit", OUTPUT_LIMIT_NEXT],
|
|
507
511
|
["matchLimit", "If you need more matches, raise limit to include rows after the last one shown."],
|
|
@@ -541,6 +545,7 @@ const SUCCESS_DEFINITIONS = {
|
|
|
541
545
|
[
|
|
542
546
|
"matches",
|
|
543
547
|
"files",
|
|
548
|
+
"missing",
|
|
544
549
|
"matchLimit",
|
|
545
550
|
"scanLimit",
|
|
546
551
|
"outputLimit",
|
|
@@ -561,30 +566,40 @@ export type MutationToolName = (typeof MUTATION_TOOLS)[number];
|
|
|
561
566
|
/** Argument rejections may omit message; Pi supplies none for them. */
|
|
562
567
|
const MESSAGE_OPTIONAL = "INVALID_ARGUMENTS" satisfies ErrorCode;
|
|
563
568
|
|
|
564
|
-
const
|
|
569
|
+
const NON_MUTATION_TOOLS = (Object.keys(SUCCESS_DEFINITIONS) as ReportTool[]).filter(
|
|
570
|
+
(tool): tool is Exclude<ReportTool, MutationToolName> =>
|
|
571
|
+
!(MUTATION_TOOLS as readonly ReportTool[]).includes(tool),
|
|
572
|
+
);
|
|
565
573
|
const COMMON_WIRE_FIELDS = {
|
|
566
|
-
tool: TOOL_SCHEMA,
|
|
567
574
|
path: REPORT_SCHEMA.properties.path,
|
|
568
575
|
next: REPORT_SCHEMA.properties.next,
|
|
569
576
|
};
|
|
570
577
|
const MUTATION_WIRE_FIELDS = {
|
|
571
578
|
publication: REPORT_SCHEMA.properties.publication,
|
|
572
|
-
freshness: REPORT_SCHEMA.properties.freshness,
|
|
573
|
-
freshnessError: REPORT_SCHEMA.properties.freshnessError,
|
|
574
579
|
then_run: REPORT_SCHEMA.properties.then_run,
|
|
575
580
|
progressError: REPORT_SCHEMA.properties.progressError,
|
|
576
581
|
};
|
|
577
|
-
const
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
582
|
+
const MUTATION_SUCCESS_WIRE_FIELDS = {
|
|
583
|
+
...MUTATION_WIRE_FIELDS,
|
|
584
|
+
freshness: REPORT_SCHEMA.properties.freshness,
|
|
585
|
+
freshnessError: REPORT_SCHEMA.properties.freshnessError,
|
|
586
|
+
};
|
|
587
|
+
const FAILURE_SCHEMAS = [
|
|
588
|
+
{ tool: literalUnion(NON_MUTATION_TOOLS) },
|
|
589
|
+
{ tool: literalUnion(MUTATION_TOOLS), ...MUTATION_WIRE_FIELDS },
|
|
590
|
+
].flatMap((toolFields) =>
|
|
591
|
+
ERROR_CODES.map((code) =>
|
|
592
|
+
Type.Object(
|
|
593
|
+
{
|
|
594
|
+
...COMMON_WIRE_FIELDS,
|
|
595
|
+
...toolFields,
|
|
596
|
+
cause: REPORT_SCHEMA.properties.cause,
|
|
597
|
+
error: Type.Literal(code),
|
|
598
|
+
message: code === MESSAGE_OPTIONAL ? REPORT_SCHEMA.properties.message : Type.String(),
|
|
599
|
+
...ERROR_DEFINITIONS[code].facts.properties,
|
|
600
|
+
},
|
|
601
|
+
{ additionalProperties: false },
|
|
602
|
+
),
|
|
588
603
|
),
|
|
589
604
|
);
|
|
590
605
|
const SUCCESS_SCHEMAS = Object.entries(SUCCESS_DEFINITIONS).map(([tool, schema]) =>
|
|
@@ -592,7 +607,7 @@ const SUCCESS_SCHEMAS = Object.entries(SUCCESS_DEFINITIONS).map(([tool, schema])
|
|
|
592
607
|
{
|
|
593
608
|
...COMMON_WIRE_FIELDS,
|
|
594
609
|
tool: Type.Literal(tool),
|
|
595
|
-
...((MUTATION_TOOLS as readonly string[]).includes(tool) ?
|
|
610
|
+
...((MUTATION_TOOLS as readonly string[]).includes(tool) ? MUTATION_SUCCESS_WIRE_FIELDS : {}),
|
|
596
611
|
...schema.properties,
|
|
597
612
|
},
|
|
598
613
|
{ additionalProperties: false },
|
|
@@ -609,26 +624,32 @@ type ErrorFactNames = {
|
|
|
609
624
|
[Code in ErrorCode]: keyof Static<(typeof ERROR_DEFINITIONS)[Code]["facts"]>;
|
|
610
625
|
}[ErrorCode] &
|
|
611
626
|
string;
|
|
612
|
-
type MutationWireFactNames = keyof Fields<typeof
|
|
627
|
+
type MutationWireFactNames = keyof Fields<typeof MUTATION_SUCCESS_WIRE_FIELDS> & string;
|
|
613
628
|
type UnusedFactNames = Exclude<FactName, SuccessFactNames | ErrorFactNames | MutationWireFactNames>;
|
|
614
629
|
// Compilation fails here, naming the fact, when no tool, code, or mutation field carries it.
|
|
615
630
|
({}) satisfies Record<UnusedFactNames, never>;
|
|
616
631
|
|
|
617
632
|
// Static counterparts of the per-tool and per-code wire schemas above, built from the same fields.
|
|
618
633
|
type Fields<P extends TProperties> = Static<TObject<P>>;
|
|
619
|
-
type Envelope =
|
|
620
|
-
type
|
|
634
|
+
type Envelope = Fields<typeof COMMON_WIRE_FIELDS>;
|
|
635
|
+
type FailureToolFields =
|
|
636
|
+
| ({ tool: MutationToolName } & Fields<typeof MUTATION_WIRE_FIELDS>)
|
|
637
|
+
| { tool: (typeof NON_MUTATION_TOOLS)[number] };
|
|
621
638
|
|
|
622
639
|
/** Facts owned by one successful tool, derived from its wire schema. */
|
|
623
640
|
export type SuccessFacts<T extends ReportTool> = Static<(typeof SUCCESS_DEFINITIONS)[T]>;
|
|
624
641
|
|
|
625
642
|
// Absent fields stay readable as undefined without admitting another variant's facts.
|
|
626
|
-
type ReportVariant<T> = T
|
|
643
|
+
type ReportVariant<T> = T extends unknown
|
|
644
|
+
? T & { [K in Exclude<keyof ReportFields, keyof T>]?: never }
|
|
645
|
+
: never;
|
|
627
646
|
|
|
628
647
|
/** A success report a tool may produce: its own facts, and mutation facts only for mutation tools. */
|
|
629
648
|
export type SuccessReport = {
|
|
630
649
|
[T in ReportTool]: ReportVariant<
|
|
631
|
-
Envelope & { tool: T } & (T extends MutationToolName
|
|
650
|
+
Envelope & { tool: T } & (T extends MutationToolName
|
|
651
|
+
? Fields<typeof MUTATION_SUCCESS_WIRE_FIELDS>
|
|
652
|
+
: unknown) &
|
|
632
653
|
SuccessFacts<T>
|
|
633
654
|
>;
|
|
634
655
|
}[ReportTool];
|
|
@@ -636,8 +657,8 @@ export type SuccessReport = {
|
|
|
636
657
|
/** A failure report: its code's facts, with message required except where MESSAGE_OPTIONAL allows. */
|
|
637
658
|
export type FailureReport = {
|
|
638
659
|
[C in ErrorCode]: ReportVariant<
|
|
639
|
-
Envelope &
|
|
640
|
-
Pick<ReportFields, "cause"> &
|
|
660
|
+
Envelope &
|
|
661
|
+
FailureToolFields & { error: C } & Pick<ReportFields, "cause"> &
|
|
641
662
|
(C extends typeof MESSAGE_OPTIONAL ? { message?: string } : { message: string }) &
|
|
642
663
|
Static<Definitions[C]["facts"]>
|
|
643
664
|
>;
|