@criogaid/pi-hashline-edit 0.11.0 → 0.12.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 +17 -4
- package/README.zh-CN.md +18 -5
- package/package.json +7 -6
- package/src/core/AGENTS.md +2 -2
- package/src/core/apply.test.ts +2 -2
- package/src/core/apply.ts +1 -1
- package/src/core/regex.ts +6 -2
- package/src/core/replace.test.ts +51 -0
- package/src/core/replace.ts +10 -4
- package/src/index.ts +1 -1
- package/src/integration/grep-line-candidates.test.ts +2 -1
- package/src/integration/grep-prefilter-coverage.test.ts +13 -2
- package/src/integration/grep-rg.test.ts +43 -0
- package/src/integration/npm-package.test.ts +12 -10
- package/src/integration/npm-package.testing.ts +148 -1
- package/src/integration/report-replay.test.ts +4 -0
- package/src/pi/AGENTS.md +9 -9
- package/src/pi/argument-validation.test.ts +63 -0
- package/src/pi/argument-validation.ts +21 -31
- package/src/pi/edit-tool.ts +2 -2
- package/src/pi/execute.test.ts +4 -0
- package/src/pi/failure-context.test.ts +1 -1
- package/src/pi/fusion-card.ts +9 -5
- package/src/pi/grep-candidates.ts +5 -4
- package/src/pi/grep-output.ts +10 -3
- package/src/pi/grep-scope.ts +6 -6
- package/src/pi/grep-tool.ts +17 -14
- package/src/pi/grep.test.ts +39 -0
- package/src/pi/mutation-runner.ts +1 -1
- package/src/pi/read.test.ts +45 -0
- package/src/pi/render.test.ts +43 -0
- package/src/pi/report-schema.ts +23 -6
- package/src/pi/report.test.ts +19 -27
- package/src/pi/report.ts +12 -5
- package/src/pi/rg-regex.test.ts +13 -0
- package/src/pi/rg-regex.ts +2 -2
package/src/pi/grep-tool.ts
CHANGED
|
@@ -108,14 +108,11 @@ function streamedList(value: string | readonly string[] | null | undefined): rea
|
|
|
108
108
|
/** Validate JavaScript syntax once; the search never rejects a pattern V8 accepts. */
|
|
109
109
|
function checkGrepArguments(args: unknown, report: ReportArgumentIssue): void {
|
|
110
110
|
const { pattern, literal, flags } = (args ?? {}) as Record<string, unknown>;
|
|
111
|
-
if (
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
)
|
|
116
|
-
return;
|
|
117
|
-
const fields = pattern.map((value, index) => [`pattern[${index}]`, value] as const);
|
|
118
|
-
checkRegexArguments("flags", flags ?? DEFAULT_GREP_FLAGS, literal, fields, report);
|
|
111
|
+
if (flags !== undefined && typeof flags !== "string") return;
|
|
112
|
+
const fields = Array.isArray(pattern)
|
|
113
|
+
? pattern.map((value, index) => [`pattern[${index}]`, value] as const)
|
|
114
|
+
: [];
|
|
115
|
+
checkRegexArguments("flags", flags ?? DEFAULT_GREP_FLAGS, literal !== false, fields, report);
|
|
119
116
|
}
|
|
120
117
|
|
|
121
118
|
/** Build the grep override (a ToolDefinition fragment for registerTool). */
|
|
@@ -127,7 +124,7 @@ export function makeGrepOverride({ cwd, config, budgets }: ToolEnvironment) {
|
|
|
127
124
|
name: "grep" as const,
|
|
128
125
|
label: "grep",
|
|
129
126
|
description:
|
|
130
|
-
"Search file contents. Content mode returns LINE#HASH edit anchors for valid UTF-8 and plain line numbers without anchors otherwise; files/count modes return paths or matching-line counts. NUL-containing files are skipped. Directory searches respect ignore rules and skip .git and linked directories, even beneath a directory named in path; to search an ignored file or one of those directories, name it itself in path. Use
|
|
127
|
+
"Search file contents. Content mode returns LINE#HASH edit anchors for valid UTF-8 and plain line numbers without anchors otherwise; files/count modes return paths or matching-line counts. NUL-containing files are skipped. Directory searches respect ignore rules and skip .git and linked directories, even beneath a directory named in path; to search an ignored file or one of those directories, name it itself in path. Use this tool instead of running rg or grep in a shell to search files; use the shell only to filter another command's output.",
|
|
131
128
|
promptSnippet: "Search file contents",
|
|
132
129
|
promptGuidelines: [
|
|
133
130
|
"When you need several independent searches, send them as separate grep calls in one response; they run in parallel.",
|
|
@@ -167,11 +164,15 @@ export function makeGrepOverride({ cwd, config, budgets }: ToolEnvironment) {
|
|
|
167
164
|
if (context.isError) return renderToolError(result, "grep", theme, expanded);
|
|
168
165
|
const { content, report } = splitReport(result, "grep");
|
|
169
166
|
const payload = content[0];
|
|
167
|
+
const mode = context.args?.outputMode ?? "content";
|
|
168
|
+
const lines =
|
|
169
|
+
payload?.type !== "text"
|
|
170
|
+
? []
|
|
171
|
+
: mode === "content"
|
|
172
|
+
? toDisplayLines(payload.text, theme)
|
|
173
|
+
: payload.text.split("\n").map((line) => theme.fg("toolOutput", line));
|
|
170
174
|
return renderOutputPreview(
|
|
171
|
-
[
|
|
172
|
-
...(payload?.type === "text" ? toDisplayLines(payload.text, theme) : []),
|
|
173
|
-
...(report ? reportLines(report, theme) : []),
|
|
174
|
-
],
|
|
175
|
+
[...lines, ...(report ? reportLines(report, theme) : [])],
|
|
175
176
|
expanded,
|
|
176
177
|
theme,
|
|
177
178
|
);
|
|
@@ -211,7 +212,7 @@ export function makeGrepOverride({ cwd, config, budgets }: ToolEnvironment) {
|
|
|
211
212
|
timeoutMs: config.grep.regexTimeoutMs,
|
|
212
213
|
signal,
|
|
213
214
|
});
|
|
214
|
-
const { payload, facts } = await grepOutput({
|
|
215
|
+
const { payload, facts, next } = await grepOutput({
|
|
215
216
|
cwd,
|
|
216
217
|
search,
|
|
217
218
|
outputMode,
|
|
@@ -227,6 +228,8 @@ export function makeGrepOverride({ cwd, config, budgets }: ToolEnvironment) {
|
|
|
227
228
|
return reportResult(
|
|
228
229
|
{ tool: "grep" as const, path: params.path, ...facts },
|
|
229
230
|
payload === undefined ? [] : [{ type: "text" as const, text: payload }],
|
|
231
|
+
undefined,
|
|
232
|
+
next,
|
|
230
233
|
);
|
|
231
234
|
});
|
|
232
235
|
},
|
package/src/pi/grep.test.ts
CHANGED
|
@@ -327,6 +327,41 @@ test("grep payload blocks → only a single complete content or count block omit
|
|
|
327
327
|
}
|
|
328
328
|
}));
|
|
329
329
|
|
|
330
|
+
test("grep output byte limit → recovery follows output mode and effective context before match limit", async () =>
|
|
331
|
+
withDir(async (dir) => {
|
|
332
|
+
const paths = Array.from({ length: 8 }, (_, index) => join(dir, `file-${index}.txt`));
|
|
333
|
+
await Promise.all(
|
|
334
|
+
paths.map((path) => writeFile(path, "before\nneedle\nafter\nneedle\nafter\nneedle\nafter\n")),
|
|
335
|
+
);
|
|
336
|
+
const budget = outputBudgetsFor(32);
|
|
337
|
+
const config = {
|
|
338
|
+
...DEFAULT_CONFIG,
|
|
339
|
+
grep: { ...DEFAULT_CONFIG.grep, defaultContext: 2 },
|
|
340
|
+
};
|
|
341
|
+
for (const [outputMode, context, limit, expected] of [
|
|
342
|
+
["content", 2, 1000, "Set context to 0 to see more of the omitted matches."],
|
|
343
|
+
["content", undefined, 1000, "Set context to 0 to see more of the omitted matches."],
|
|
344
|
+
["content", 0, 1000, "Narrow path, glob, or pattern to see the omitted output."],
|
|
345
|
+
["files", undefined, 1000, "Narrow path, glob, or pattern to see the omitted output."],
|
|
346
|
+
["count", undefined, 1000, "Narrow path, glob, or pattern to see the omitted output."],
|
|
347
|
+
["content", 2, 12, "Set context to 0 to see more of the omitted matches."],
|
|
348
|
+
["content", 0, 12, "Narrow path, glob, or pattern to see the omitted output."],
|
|
349
|
+
] as const) {
|
|
350
|
+
const { backend } = fakeBackend({ paths });
|
|
351
|
+
const result = await callTool(
|
|
352
|
+
makeMockGrep(dir, config, backend, () => budget),
|
|
353
|
+
{ path: dir, pattern: ["needle"], literal: true, outputMode, context, limit },
|
|
354
|
+
);
|
|
355
|
+
const scenario = JSON.stringify({ outputMode, context, limit });
|
|
356
|
+
assert.equal(result.isError, undefined, scenario);
|
|
357
|
+
const report = reportOf(result, "grep");
|
|
358
|
+
assert.ok(report, scenario);
|
|
359
|
+
assert.equal(report.outputLimit, formatByteSize(budget.grepBytes), scenario);
|
|
360
|
+
assert.equal(report.matchLimit, limit === 12 ? limit : undefined, scenario);
|
|
361
|
+
assert.equal(report.next, expected, scenario);
|
|
362
|
+
}
|
|
363
|
+
}));
|
|
364
|
+
|
|
330
365
|
test("grep output truncates preview rows → reports only displayed preview facts", async () =>
|
|
331
366
|
withDir(async (dir) => {
|
|
332
367
|
const paths = [join(dir, "a.txt"), join(dir, "z.txt")];
|
|
@@ -669,6 +704,10 @@ for (const diagnosticLineCount of [0, 80]) {
|
|
|
669
704
|
state: {},
|
|
670
705
|
cwd: process.cwd(),
|
|
671
706
|
executionStarted: true,
|
|
707
|
+
durationMs: undefined,
|
|
708
|
+
outputPad: 1,
|
|
709
|
+
keyText: () => "",
|
|
710
|
+
keyHint: (_key, description) => description,
|
|
672
711
|
argsComplete: true,
|
|
673
712
|
isPartial: false,
|
|
674
713
|
expanded,
|
|
@@ -58,7 +58,7 @@ import type { OutputBudgets } from "./budgets.ts";
|
|
|
58
58
|
import type { ToolEnvironment } from "./config.ts";
|
|
59
59
|
import { STRICT_SAMPLING } from "./schema.ts";
|
|
60
60
|
|
|
61
|
-
|
|
61
|
+
type ActionFusionExecutor = ReturnType<typeof createActionFusionExecutor>;
|
|
62
62
|
|
|
63
63
|
/** A mutation tool's registration environment; fusion is undefined when Action Fusion is off. */
|
|
64
64
|
export interface MutationToolEnvironment extends ToolEnvironment {
|
package/src/pi/read.test.ts
CHANGED
|
@@ -4,6 +4,7 @@ import assert from "node:assert/strict";
|
|
|
4
4
|
import { mkdir, mkdtemp, rm, readFile, writeFile } from "node:fs/promises";
|
|
5
5
|
import { tmpdir } from "node:os";
|
|
6
6
|
import { join } from "node:path";
|
|
7
|
+
import { pathToFileURL } from "node:url";
|
|
7
8
|
import { initTheme } from "@earendil-works/pi-coding-agent";
|
|
8
9
|
import type { Theme } from "@earendil-works/pi-coding-agent";
|
|
9
10
|
import { validateToolArguments } from "@earendil-works/pi-ai";
|
|
@@ -88,6 +89,46 @@ test("read execute: Pi-supported images without NUL bypass text decoding", async
|
|
|
88
89
|
}
|
|
89
90
|
}));
|
|
90
91
|
|
|
92
|
+
test("file URLs escape special filenames → text and delegated reads open the exact file", async (t) => {
|
|
93
|
+
await withDir(async (dir) => {
|
|
94
|
+
const tool = makeReadOverride(dir, DEFAULT_CONFIG);
|
|
95
|
+
const cases = [
|
|
96
|
+
{ name: "text.txt", bytes: Buffer.from("first\nsecond\n"), native: false },
|
|
97
|
+
{ name: "binary.bin", bytes: Buffer.from("first\0\nsecond\n"), native: true },
|
|
98
|
+
{
|
|
99
|
+
name: "image.gif",
|
|
100
|
+
bytes: Buffer.from("R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7", "base64"),
|
|
101
|
+
native: true,
|
|
102
|
+
},
|
|
103
|
+
];
|
|
104
|
+
for (const { name, bytes, native } of cases) {
|
|
105
|
+
await t.test(name, async () => {
|
|
106
|
+
const path = join(dir, `space\u202Fname #% ${name}`);
|
|
107
|
+
await writeFile(path, bytes);
|
|
108
|
+
const result = await callTool(tool, { path: pathToFileURL(path).href });
|
|
109
|
+
assert.equal(result.isError, undefined);
|
|
110
|
+
assert.equal(result.details?.nativeRead === true, native);
|
|
111
|
+
if (name === "image.gif") {
|
|
112
|
+
assert.ok(result.content.some((block) => block.type === "image"));
|
|
113
|
+
} else {
|
|
114
|
+
const text = result.content.find((block) => block.type === "text")?.text;
|
|
115
|
+
assert.ok(text);
|
|
116
|
+
assert.ok(text.includes(native ? "first\0" : "│first"));
|
|
117
|
+
assert.ok(text.includes("second"));
|
|
118
|
+
if (!native) {
|
|
119
|
+
const header = text.split("\n")[0];
|
|
120
|
+
const returnedPath = header.slice(0, header.lastIndexOf(" · "));
|
|
121
|
+
const reread = await callTool(tool, { path: returnedPath });
|
|
122
|
+
assert.equal(reread.isError, undefined);
|
|
123
|
+
assert.deepEqual(reread.content, result.content);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
assert.deepEqual(await readFile(path), bytes);
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
});
|
|
131
|
+
|
|
91
132
|
test("read execute: a missing final newline is stated in the header", async () => {
|
|
92
133
|
await withDir(async (dir) => {
|
|
93
134
|
await writeFile(join(dir, "f.txt"), "line1\nline2");
|
|
@@ -382,6 +423,10 @@ test("Unicode line separators in a read path or middle row → renders every fol
|
|
|
382
423
|
lastComponent: undefined,
|
|
383
424
|
invalidate() {},
|
|
384
425
|
executionStarted: true,
|
|
426
|
+
durationMs: undefined,
|
|
427
|
+
outputPad: 1,
|
|
428
|
+
keyText: () => "",
|
|
429
|
+
keyHint: (_key, description) => description,
|
|
385
430
|
argsComplete: true,
|
|
386
431
|
isPartial: false,
|
|
387
432
|
expanded: true,
|
package/src/pi/render.test.ts
CHANGED
|
@@ -358,6 +358,37 @@ test("Unicode line separators in grep paths → parses the full file header", as
|
|
|
358
358
|
}
|
|
359
359
|
});
|
|
360
360
|
|
|
361
|
+
test("grep files mode with header-like and anchor-like names → preserves complete paths", () => {
|
|
362
|
+
initTheme("dark");
|
|
363
|
+
const tool = makeGrepOverride(process.cwd(), DEFAULT_CONFIG);
|
|
364
|
+
const paths = ["a · 1 match", "1#ABCD│name"];
|
|
365
|
+
const rendered = tool.renderResult(
|
|
366
|
+
{ content: [{ type: "text", text: paths.join("\n") }], details: undefined },
|
|
367
|
+
{ isPartial: false, expanded: true },
|
|
368
|
+
theme,
|
|
369
|
+
{
|
|
370
|
+
args: { pattern: ["needle"], literal: true, outputMode: "files" },
|
|
371
|
+
toolCallId: "test",
|
|
372
|
+
invalidate() {},
|
|
373
|
+
lastComponent: undefined,
|
|
374
|
+
state: {},
|
|
375
|
+
cwd: process.cwd(),
|
|
376
|
+
executionStarted: true,
|
|
377
|
+
durationMs: undefined,
|
|
378
|
+
outputPad: 1,
|
|
379
|
+
keyText: () => "",
|
|
380
|
+
keyHint: (_key: string, description: string) => description,
|
|
381
|
+
argsComplete: true,
|
|
382
|
+
isPartial: false,
|
|
383
|
+
expanded: true,
|
|
384
|
+
showImages: false,
|
|
385
|
+
isError: false,
|
|
386
|
+
},
|
|
387
|
+
);
|
|
388
|
+
const lines = rendered.render(120).map((line) => stripVTControlCharacters(line).trimEnd());
|
|
389
|
+
for (const path of paths) assert.ok(lines.includes(path), JSON.stringify(lines));
|
|
390
|
+
});
|
|
391
|
+
|
|
361
392
|
test("grep renders anchored and plain groups with shared width and folded indentation", () => {
|
|
362
393
|
initTheme("dark");
|
|
363
394
|
const raw = [
|
|
@@ -430,6 +461,10 @@ test("all tools render argument issues as field diagnostics while preserving mod
|
|
|
430
461
|
lastComponent: undefined,
|
|
431
462
|
cwd,
|
|
432
463
|
executionStarted: true,
|
|
464
|
+
durationMs: undefined,
|
|
465
|
+
outputPad: 1,
|
|
466
|
+
keyText: () => "",
|
|
467
|
+
keyHint: (_key: string, description: string) => description,
|
|
433
468
|
argsComplete: true,
|
|
434
469
|
isPartial: false,
|
|
435
470
|
expanded,
|
|
@@ -582,6 +617,10 @@ test("command changes or removes the target → completed mutation stays success
|
|
|
582
617
|
lastComponent: undefined,
|
|
583
618
|
invalidate() {},
|
|
584
619
|
executionStarted: true,
|
|
620
|
+
durationMs: undefined,
|
|
621
|
+
outputPad: 1,
|
|
622
|
+
keyText: () => "",
|
|
623
|
+
keyHint: (_key: string, description: string) => description,
|
|
585
624
|
argsComplete: true,
|
|
586
625
|
isPartial: true,
|
|
587
626
|
expanded: false,
|
|
@@ -642,6 +681,10 @@ test("success renderers receive replayed or hooked reports → display only sche
|
|
|
642
681
|
lastComponent: undefined,
|
|
643
682
|
invalidate() {},
|
|
644
683
|
executionStarted: true,
|
|
684
|
+
durationMs: undefined,
|
|
685
|
+
outputPad: 1,
|
|
686
|
+
keyText: () => "",
|
|
687
|
+
keyHint: (_key: string, description: string) => description,
|
|
645
688
|
argsComplete: true,
|
|
646
689
|
isPartial: false,
|
|
647
690
|
expanded: true,
|
package/src/pi/report-schema.ts
CHANGED
|
@@ -274,11 +274,11 @@ const FACT_FIELDS = {
|
|
|
274
274
|
),
|
|
275
275
|
outputLimit: modelFact(
|
|
276
276
|
Type.String({ description: "The output byte budget that cut the result." }),
|
|
277
|
-
"
|
|
277
|
+
"Remove context or narrow the scope to see omitted output.",
|
|
278
278
|
),
|
|
279
279
|
linePreviewLimit: modelFact(
|
|
280
280
|
Type.Integer({ description: "UTF-16 units kept in a cut line preview." }),
|
|
281
|
-
"
|
|
281
|
+
"Inspect the full line with a tool that supports its encoding before rewriting a partial preview.",
|
|
282
282
|
),
|
|
283
283
|
invalidUtf8: modelFact(
|
|
284
284
|
Type.Array(Type.String(), {
|
|
@@ -391,7 +391,7 @@ export const ERROR_DEFINITIONS = {
|
|
|
391
391
|
OVERLAPPING_EDITS: {
|
|
392
392
|
facts: facts(["conflict"]),
|
|
393
393
|
next: {
|
|
394
|
-
default: "Merge them into one
|
|
394
|
+
default: "Merge them into one step per range or position.",
|
|
395
395
|
},
|
|
396
396
|
},
|
|
397
397
|
NO_MATCH: {
|
|
@@ -464,10 +464,24 @@ export const PUBLICATION_NEXT = {
|
|
|
464
464
|
"The change may or may not be saved. Read the file, and repeat the change only if it is missing.",
|
|
465
465
|
} as const satisfies Record<Exclude<PublicationStatus, "NOT_PUBLISHED">, string>;
|
|
466
466
|
|
|
467
|
+
/** The byte budget cut a grep payload: context rows go first, and without them only a narrower search helps. */
|
|
468
|
+
const OUTPUT_LIMIT_NEXT = {
|
|
469
|
+
default: "Narrow path, glob, or pattern to see the omitted output.",
|
|
470
|
+
contextRows: "Set context to 0 to see more of the omitted matches.",
|
|
471
|
+
} as const;
|
|
472
|
+
|
|
473
|
+
/** Recovery alternatives the producing layer may select for a successful result. */
|
|
474
|
+
export type OutcomeVariant = Exclude<keyof typeof OUTPUT_LIMIT_NEXT, "default">;
|
|
475
|
+
|
|
476
|
+
/** One recovery, or a default with the named alternatives its producer may select. */
|
|
477
|
+
type OutcomeNext =
|
|
478
|
+
| string
|
|
479
|
+
| ({ readonly default: string } & Partial<Record<OutcomeVariant, string>>);
|
|
480
|
+
|
|
467
481
|
/** One fact's recovery; `except` is a value of that fact which needs none. */
|
|
468
482
|
type OutcomeRule =
|
|
469
483
|
| {
|
|
470
|
-
[F in FactName]: readonly [fact: F, next:
|
|
484
|
+
[F in FactName]: readonly [fact: F, next: OutcomeNext, except?: Static<FactSchema<F>>];
|
|
471
485
|
}[FactName]
|
|
472
486
|
| readonly [fact: "publication", next: string, except?: PublicationStatus];
|
|
473
487
|
|
|
@@ -489,7 +503,7 @@ export const OUTCOME_NEXT: readonly OutcomeRule[] = [
|
|
|
489
503
|
],
|
|
490
504
|
["nextOffset", "If you need more lines, set offset to nextOffset."],
|
|
491
505
|
// Ahead of matchLimit: once the byte budget cuts the output, raising limit shows nothing more.
|
|
492
|
-
["outputLimit",
|
|
506
|
+
["outputLimit", OUTPUT_LIMIT_NEXT],
|
|
493
507
|
["matchLimit", "If you need more matches, raise limit to include rows after the last one shown."],
|
|
494
508
|
[
|
|
495
509
|
"literalPipe",
|
|
@@ -499,7 +513,10 @@ export const OUTCOME_NEXT: readonly OutcomeRule[] = [
|
|
|
499
513
|
"scanLimit",
|
|
500
514
|
"Narrow path or glob, or add text every match must contain, to search the remaining files.",
|
|
501
515
|
],
|
|
502
|
-
[
|
|
516
|
+
[
|
|
517
|
+
"linePreviewLimit",
|
|
518
|
+
"For paths listed in invalidUtf8, inspect the full line with bash; otherwise use read before rewriting a partial preview.",
|
|
519
|
+
],
|
|
503
520
|
];
|
|
504
521
|
|
|
505
522
|
/** The report envelope and facts, in output order; `next` is always last. */
|
package/src/pi/report.test.ts
CHANGED
|
@@ -358,6 +358,16 @@ test("success facts survive details and model serialization", () => {
|
|
|
358
358
|
}
|
|
359
359
|
});
|
|
360
360
|
|
|
361
|
+
test("grep preview from invalid UTF-8 → recovery selects bash for the listed paths", () => {
|
|
362
|
+
const result = reportResult({
|
|
363
|
+
tool: "grep",
|
|
364
|
+
linePreviewLimit: DEFAULT_OUTPUT_BUDGETS.grepPreviewUnits,
|
|
365
|
+
invalidUtf8: ["invalid.txt"],
|
|
366
|
+
});
|
|
367
|
+
const next = reportOf(result, "grep")?.next ?? "";
|
|
368
|
+
assert.match(next, /invalidUtf8.*bash/);
|
|
369
|
+
});
|
|
370
|
+
|
|
361
371
|
test("match and scan limits → recovery prioritizes the match limit", () => {
|
|
362
372
|
const next = OUTCOME_NEXT.find(([fact]) => fact === "matchLimit")?.[1];
|
|
363
373
|
assert.ok(next);
|
|
@@ -370,34 +380,16 @@ test("match and scan limits → recovery prioritizes the match limit", () => {
|
|
|
370
380
|
assert.equal(reportOf(result, "grep")?.next, next);
|
|
371
381
|
});
|
|
372
382
|
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
outputLimit: formatByteSize(DEFAULT_OUTPUT_BUDGETS.grepBytes),
|
|
381
|
-
},
|
|
382
|
-
fact: "outputLimit",
|
|
383
|
-
},
|
|
384
|
-
{
|
|
385
|
-
name: "output limit with read next offset → recovery prioritizes the next offset",
|
|
386
|
-
report: {
|
|
387
|
-
tool: "read",
|
|
388
|
-
nextOffset: 2,
|
|
389
|
-
outputLimit: formatByteSize(DEFAULT_OUTPUT_BUDGETS.readBytes),
|
|
390
|
-
},
|
|
391
|
-
fact: "nextOffset",
|
|
392
|
-
},
|
|
393
|
-
] satisfies { name: string; report: SuccessReport; fact: "outputLimit" | "nextOffset" }[]) {
|
|
394
|
-
test(name, () => {
|
|
395
|
-
const next = OUTCOME_NEXT.find(([key]) => key === fact)?.[1];
|
|
396
|
-
assert.ok(next);
|
|
397
|
-
const result = reportResult(report);
|
|
398
|
-
assert.equal(reportOf(result, report.tool)?.next, next);
|
|
383
|
+
test("output limit with read next offset → recovery prioritizes the next offset", () => {
|
|
384
|
+
const next = OUTCOME_NEXT.find(([key]) => key === "nextOffset")?.[1];
|
|
385
|
+
assert.ok(next);
|
|
386
|
+
const result = reportResult({
|
|
387
|
+
tool: "read",
|
|
388
|
+
nextOffset: 2,
|
|
389
|
+
outputLimit: formatByteSize(DEFAULT_OUTPUT_BUDGETS.readBytes),
|
|
399
390
|
});
|
|
400
|
-
|
|
391
|
+
assert.equal(reportOf(result, "read")?.next, next);
|
|
392
|
+
});
|
|
401
393
|
|
|
402
394
|
test("text-only error contains facts invalid for the originating tool → preserves the raw diagnostic", () => {
|
|
403
395
|
const diagnostic = '{"publication":"PUBLISHED"}';
|
package/src/pi/report.ts
CHANGED
|
@@ -37,6 +37,7 @@ import {
|
|
|
37
37
|
WIRE_REPORT_SCHEMA,
|
|
38
38
|
type ErrorCode,
|
|
39
39
|
type FailureReport,
|
|
40
|
+
type OutcomeVariant,
|
|
40
41
|
type ModelOmittedField,
|
|
41
42
|
type Report,
|
|
42
43
|
type ReportTool,
|
|
@@ -121,24 +122,30 @@ export function reportOf(
|
|
|
121
122
|
return last?.type === "text" ? decodeReport(last.text, tool) : undefined;
|
|
122
123
|
}
|
|
123
124
|
|
|
124
|
-
/**
|
|
125
|
-
|
|
126
|
-
|
|
125
|
+
/**
|
|
126
|
+
* The recovery a successful result's facts call for: the first in OUTCOME_NEXT order, in the
|
|
127
|
+
* producer's selected alternative when that rule names it.
|
|
128
|
+
*/
|
|
129
|
+
function outcomeNext(report: Report, variant: OutcomeVariant | undefined): string | undefined {
|
|
130
|
+
const next = OUTCOME_NEXT.find(
|
|
127
131
|
([fact, , except]) => report[fact] !== undefined && report[fact] !== except,
|
|
128
132
|
)?.[1];
|
|
133
|
+
return typeof next === "object" ? ((variant && next[variant]) ?? next.default) : next;
|
|
129
134
|
}
|
|
130
135
|
|
|
131
136
|
/**
|
|
132
137
|
* A successful result: the tool's payload, then its report when it states
|
|
133
|
-
* anything beyond tool and path or when there is no payload.
|
|
138
|
+
* anything beyond tool and path or when there is no payload. `variant` is the recovery
|
|
139
|
+
* alternative the producing layer selected.
|
|
134
140
|
*/
|
|
135
141
|
export function reportResult<TDetails extends object | undefined>(
|
|
136
142
|
report: SuccessReport,
|
|
137
143
|
payload: Content = [],
|
|
138
144
|
details?: TDetails,
|
|
145
|
+
variant?: OutcomeVariant,
|
|
139
146
|
): AgentToolResult<TDetails & ReportDetails<SuccessReport>> {
|
|
140
147
|
const complete = Object.fromEntries(
|
|
141
|
-
reportEntries({ ...report, next: outcomeNext(report) }),
|
|
148
|
+
reportEntries({ ...report, next: outcomeNext(report, variant) }),
|
|
142
149
|
) as SuccessReport;
|
|
143
150
|
const stated = Object.keys(complete).some(
|
|
144
151
|
(key) => !MODEL_OMITTED_FIELDS.has(key as ModelOmittedField),
|
package/src/pi/rg-regex.test.ts
CHANGED
|
@@ -49,6 +49,19 @@ test("capture disables i inside a caseless reference → retain the reference's
|
|
|
49
49
|
);
|
|
50
50
|
});
|
|
51
51
|
|
|
52
|
+
test("caseless backreference repeats a v string-class capture → retains native case variants", () => {
|
|
53
|
+
const pattern = "([\\q{a}])\\1";
|
|
54
|
+
assert.equal(new RegExp(pattern, "iv").test("aA"), true);
|
|
55
|
+
const candidates = lineCandidatePatterns({
|
|
56
|
+
patterns: [pattern],
|
|
57
|
+
literal: false,
|
|
58
|
+
flags: "iv",
|
|
59
|
+
multiline: false,
|
|
60
|
+
});
|
|
61
|
+
// This ASCII-only translation uses syntax shared by rg and JavaScript.
|
|
62
|
+
assert.ok(candidates?.some((candidate) => new RegExp(candidate).test("aA")));
|
|
63
|
+
});
|
|
64
|
+
|
|
52
65
|
test("deeply nested pattern → line candidates retain the native match", () => {
|
|
53
66
|
for (const depth of [50, 200, 500, 1_000, 2_000, 4_000]) {
|
|
54
67
|
const pattern = `${"(?:".repeat(depth)}A${")".repeat(depth)}`;
|
package/src/pi/rg-regex.ts
CHANGED
|
@@ -121,8 +121,8 @@ function nativeFlags(node: AST.Node, ctx: Context): string {
|
|
|
121
121
|
|
|
122
122
|
function scalarRanges(node: CharacterNode, ctx: Context): Ranges {
|
|
123
123
|
const ranges = nativeCharacterRanges(node.raw, nativeFlags(node, ctx));
|
|
124
|
-
//
|
|
125
|
-
return ctx.repeated
|
|
124
|
+
// Reference comparison can widen even a capture whose native class already uses i.
|
|
125
|
+
return ctx.repeated ? folded(ranges, ctx) : ranges;
|
|
126
126
|
}
|
|
127
127
|
|
|
128
128
|
const choice = (patterns: readonly string[]): string =>
|