@criogaid/pi-hashline-edit 0.8.0 → 0.10.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 +13 -10
- package/README.zh-CN.md +12 -9
- package/THIRD_PARTY_NOTICES.md +0 -6
- package/package.json +1 -1
- package/src/core/AGENTS.md +4 -5
- package/src/core/apply.test.ts +118 -293
- package/src/core/apply.ts +63 -165
- package/src/core/case-fold.ts +8 -67
- package/src/core/character-set.ts +4 -4
- package/src/core/errors.test.ts +23 -7
- package/src/core/errors.ts +32 -5
- package/src/core/hash.test.ts +8 -16
- package/src/core/hash.ts +3 -23
- package/src/core/lines.ts +2 -4
- package/src/core/ranges.test.ts +16 -8
- package/src/core/ranges.ts +10 -6
- package/src/core/regex.ts +3 -4
- package/src/core/replace.test.ts +47 -1
- package/src/core/replace.ts +19 -13
- package/src/core/search-analysis.test.ts +24 -27
- package/src/core/search-analysis.ts +34 -65
- package/src/core/search-matrix.testing.ts +0 -2
- package/src/core/search.ts +1 -1
- package/src/core/text.test.ts +5 -5
- package/src/core/text.ts +5 -12
- package/src/core/types.ts +7 -43
- package/src/integration/config-registration.test.ts +2 -2
- package/src/integration/fusion-dispatch.test.ts +2 -5
- package/src/integration/grep-flags.test.ts +0 -14
- package/src/integration/grep-js-completeness.test.ts +34 -8
- package/src/integration/grep-line-candidates.test.ts +4 -8
- package/src/integration/grep-matrix.test.ts +3 -7
- package/src/integration/grep-path-matrix.test.ts +5 -5
- package/src/integration/grep-prefilter-coverage.test.ts +3 -7
- package/src/integration/grep-process-limits.test.ts +78 -0
- package/src/integration/grep-rg.test.ts +123 -25
- package/src/integration/grep-scan-budget.test.ts +2 -2
- package/src/integration/grep-translation.test.ts +12 -27
- package/src/integration/large-text.test.ts +1 -47
- package/src/integration/model-budget-lifecycle.test.ts +13 -3
- package/src/integration/mutation-file-types.testing.ts +1 -1
- package/src/integration/npm-package.testing.ts +1 -1
- package/src/integration/publication-read-changes.test.ts +125 -47
- package/src/integration/replace-worker-boundary.test.ts +21 -11
- package/src/integration/report-replay.test.ts +21 -23
- package/src/integration/utf8-errors.test.ts +1 -1
- package/src/pi/AGENTS.md +16 -16
- package/src/pi/action-fusion.test.ts +168 -300
- package/src/pi/action-fusion.ts +148 -111
- package/src/pi/anchor-format.test.ts +9 -9
- package/src/pi/anchor-format.ts +6 -8
- package/src/pi/argument-diagnostics.ts +52 -207
- package/src/pi/argument-error.ts +2 -1
- package/src/pi/argument-format.test.ts +20 -22
- package/src/pi/argument-validation.test.ts +382 -418
- package/src/pi/argument-validation.ts +5 -8
- package/src/pi/budgets.ts +5 -4
- package/src/pi/config.test.ts +5 -2
- package/src/pi/config.ts +4 -6
- package/src/pi/diagnostic-buffer.test.ts +12 -1
- package/src/pi/diagnostic-buffer.ts +1 -2
- package/src/pi/directory-sync.test.ts +0 -1
- package/src/pi/edit-tool.ts +173 -226
- package/src/pi/error-text.ts +4 -8
- package/src/pi/execute.test.ts +165 -266
- package/src/pi/failure-context.test.ts +144 -126
- package/src/pi/failure-context.ts +45 -94
- package/src/pi/failure-path.test.ts +168 -141
- package/src/pi/file-commit.test.ts +110 -53
- package/src/pi/file-commit.ts +90 -137
- package/src/pi/file-snapshot.test.ts +3 -5
- package/src/pi/fusion-card.test.ts +4 -1
- package/src/pi/fusion-card.ts +16 -24
- package/src/pi/grep-candidates.test.ts +2 -101
- package/src/pi/grep-candidates.ts +23 -69
- package/src/pi/grep-matrix.test.ts +2 -2
- package/src/pi/grep-order.test.ts +4 -4
- package/src/pi/grep-output.ts +62 -96
- package/src/pi/grep-render.ts +1 -1
- package/src/pi/grep-reread.ts +92 -0
- package/src/pi/grep-scope.ts +40 -42
- package/src/pi/grep-search.ts +22 -31
- package/src/pi/grep-tool.ts +55 -82
- package/src/pi/grep.test.ts +81 -46
- package/src/pi/model-budgets.test.ts +25 -23
- package/src/pi/model-budgets.ts +6 -38
- package/src/pi/mutation-result.test.ts +44 -35
- package/src/pi/mutation-result.ts +51 -20
- package/src/pi/mutation-runner.ts +126 -70
- package/src/pi/output-budgets.test.ts +38 -16
- package/src/pi/path.ts +1 -1
- package/src/pi/pi.test.ts +3 -1
- package/src/pi/read-tool.ts +5 -5
- package/src/pi/regex-worker-contract.ts +3 -13
- package/src/pi/regex-worker.ts +1 -10
- package/src/pi/registration.test.ts +82 -20
- package/src/pi/render.test.ts +79 -42
- package/src/pi/render.ts +69 -63
- package/src/pi/replace-regex.ts +14 -2
- package/src/pi/replace-tool.ts +22 -83
- package/src/pi/replace-worker.ts +1 -1
- package/src/pi/replace.test.ts +9 -5
- package/src/pi/report-cause.ts +3 -8
- package/src/pi/report-failure.testing.ts +1 -2
- package/src/pi/report-schema.ts +65 -81
- package/src/pi/report.test.ts +171 -25
- package/src/pi/report.ts +33 -87
- package/src/pi/result-safety.test.ts +177 -189
- package/src/pi/rg-process.test.ts +77 -63
- package/src/pi/rg-process.ts +48 -64
- package/src/pi/rg-regex.ts +40 -400
- package/src/pi/schema.ts +12 -0
- package/src/pi/text-stream.test.ts +0 -21
- package/src/pi/text-stream.ts +14 -21
- package/src/pi/write-tool.ts +33 -62
- package/src/pi/write.test.ts +1 -3
- package/src/testing/regex-translation-corpus.ts +12 -12
- package/src/pi/replace-worker-contract.ts +0 -10
|
@@ -15,7 +15,7 @@ import type { ArgumentIssue, ReportTool } from "./report-schema.ts";
|
|
|
15
15
|
|
|
16
16
|
/** Report one semantic issue: what is wrong (a fact), and how to correct it when the fact alone does not say. */
|
|
17
17
|
export type ReportArgumentIssue = (field: string, reason: string, fix?: string) => void;
|
|
18
|
-
type CheckArguments = (args: unknown, report: ReportArgumentIssue) => void;
|
|
18
|
+
export type CheckArguments = (args: unknown, report: ReportArgumentIssue) => void;
|
|
19
19
|
|
|
20
20
|
/** Inspect arrays and the singleton objects Pi may coerce, without changing input. */
|
|
21
21
|
export function argumentItems(value: unknown): readonly unknown[] {
|
|
@@ -82,18 +82,15 @@ export function createArgumentPreparer<T extends TObject>(
|
|
|
82
82
|
check?.(checked, (field, reason, fix) =>
|
|
83
83
|
issues.push(fix === undefined ? { field, reason } : { field, reason, fix }),
|
|
84
84
|
);
|
|
85
|
+
// Keep Pi's preparation contract: the framework performs its own coercion next.
|
|
85
86
|
if (schemaFailure === undefined && issues.length === 0) return args as Static<T>;
|
|
86
87
|
const result = diagnoseArguments(parameters, checked, issues, schemaFailure !== undefined);
|
|
87
88
|
const reported =
|
|
88
89
|
result.issues.length > 0
|
|
89
90
|
? result.issues
|
|
90
91
|
: [{ field: "$", reason: errorMessage(schemaFailure) }];
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
// Keep Pi's preparation contract: the framework performs its own coercion next.
|
|
97
|
-
return args as Static<T>;
|
|
92
|
+
throw new Error(formatArgumentError(reported, result.limited, budgets()), {
|
|
93
|
+
cause: schemaFailure,
|
|
94
|
+
});
|
|
98
95
|
};
|
|
99
96
|
}
|
package/src/pi/budgets.ts
CHANGED
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
* The context window is a capacity hint, not a tokenizer or remaining-context counter.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
const BYTES_PER_CONTEXT_TOKEN = 1;
|
|
7
6
|
const BLOCK_SHARE = 4;
|
|
8
7
|
const FIELD_SHARE = 4;
|
|
9
8
|
const UTF16_PREVIEW_BYTES = 4;
|
|
@@ -16,6 +15,7 @@ const MIN_FIELD_BYTES = 128;
|
|
|
16
15
|
export const MAX_CONTENT_KIB = 4096;
|
|
17
16
|
const MAX_CONTENT_BYTES = MAX_CONTENT_KIB * 1024;
|
|
18
17
|
|
|
18
|
+
// Declared apart so Object.freeze keeps these as numbers rather than literal types.
|
|
19
19
|
const fallbackBudgets = {
|
|
20
20
|
readBytes: 256 * 1024,
|
|
21
21
|
grepBytes: 50 * 1024,
|
|
@@ -32,7 +32,8 @@ export function outputBudgetsFor(contextWindow: number | undefined): OutputBudge
|
|
|
32
32
|
if (contextWindow === undefined || !Number.isSafeInteger(contextWindow) || contextWindow <= 0) {
|
|
33
33
|
return DEFAULT_OUTPUT_BUDGETS;
|
|
34
34
|
}
|
|
35
|
-
|
|
35
|
+
// One byte per declared context token.
|
|
36
|
+
const contentBytes = Math.min(contextWindow, MAX_CONTENT_BYTES);
|
|
36
37
|
const blockBytes = Math.max(MIN_BLOCK_BYTES, Math.floor(contentBytes / BLOCK_SHARE));
|
|
37
38
|
const fieldBytes = Math.max(MIN_FIELD_BYTES, Math.floor(blockBytes / FIELD_SHARE));
|
|
38
39
|
return Object.freeze({
|
|
@@ -49,7 +50,7 @@ export const defaultOutputBudgets: OutputBudgetProvider = () => DEFAULT_OUTPUT_B
|
|
|
49
50
|
|
|
50
51
|
const MIB = 1024 * 1024;
|
|
51
52
|
|
|
52
|
-
/** Size wording for every model-facing limit: whole MiB as `256 MiB`, otherwise `
|
|
53
|
+
/** Size wording for every model-facing limit: whole MiB as `256 MiB`, otherwise `195.3 KiB`. */
|
|
53
54
|
export function formatByteSize(bytes: number): string {
|
|
54
|
-
return bytes % MIB === 0 ? `${bytes / MIB} MiB` : `${bytes / 1024} KiB`;
|
|
55
|
+
return bytes % MIB === 0 ? `${bytes / MIB} MiB` : `${Number((bytes / 1024).toFixed(1))} KiB`;
|
|
55
56
|
}
|
package/src/pi/config.test.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { DEFAULT_MAX_LINES } from "@earendil-works/pi-coding-agent";
|
|
1
2
|
import { mkdir, mkdtemp, rm, writeFile } from "node:fs/promises";
|
|
2
3
|
import { tmpdir } from "node:os";
|
|
3
4
|
import { join } from "node:path";
|
|
@@ -34,7 +35,7 @@ test("defaults come from the settings schema", () => {
|
|
|
34
35
|
actionFusion: true,
|
|
35
36
|
hashLen: 4,
|
|
36
37
|
shiftRadius: 15,
|
|
37
|
-
read: { defaultLimit:
|
|
38
|
+
read: { defaultLimit: DEFAULT_MAX_LINES, maxKiB: undefined },
|
|
38
39
|
grep: { ...DEFAULT_CONFIG.grep, defaultLimit: 100, defaultContext: 0 },
|
|
39
40
|
replace: { regexTimeoutMs: 5_000 },
|
|
40
41
|
});
|
|
@@ -114,7 +115,9 @@ test("project settings replace global groups while absent project settings use g
|
|
|
114
115
|
join(agentDir, "settings.json"),
|
|
115
116
|
JSON.stringify({ hashlineEdit: globalConfig }),
|
|
116
117
|
);
|
|
117
|
-
|
|
118
|
+
const withoutSettings = join(root, "without-settings");
|
|
119
|
+
await mkdir(withoutSettings);
|
|
120
|
+
assert.deepEqual(loadConfig(withoutSettings), globalConfig);
|
|
118
121
|
assert.deepEqual(loadConfig(root), globalConfig);
|
|
119
122
|
for (const settings of [{}, null, [], 42, "settings"]) {
|
|
120
123
|
await write(settings);
|
package/src/pi/config.ts
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* @module pi-hashline-edit/pi
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import { getAgentDir } from "@earendil-works/pi-coding-agent";
|
|
9
|
+
import { DEFAULT_MAX_LINES, getAgentDir } from "@earendil-works/pi-coding-agent";
|
|
10
10
|
import * as fs from "node:fs";
|
|
11
11
|
import * as path from "node:path";
|
|
12
12
|
import { Type, type Static, type TSchema } from "typebox";
|
|
@@ -24,7 +24,6 @@ function integerSetting(
|
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
// The floor exceeds measured worker startup+handshake on slower Windows hosts.
|
|
27
|
-
// README's regex timeout settings link to this shared definition.
|
|
28
27
|
const regexTimeoutSetting = integerSetting(
|
|
29
28
|
integerRange(3_000, 300_000),
|
|
30
29
|
5_000,
|
|
@@ -55,7 +54,7 @@ const configSchema = Type.Object({
|
|
|
55
54
|
read: Type.Object({
|
|
56
55
|
defaultLimit: integerSetting(
|
|
57
56
|
POSITIVE_SAFE_INTEGER,
|
|
58
|
-
|
|
57
|
+
DEFAULT_MAX_LINES,
|
|
59
58
|
"Lines returned when limit is omitted.",
|
|
60
59
|
),
|
|
61
60
|
maxKiB: Type.Optional(
|
|
@@ -113,7 +112,6 @@ export const DEFAULT_CONFIG: HashlineEditConfig = resolveSetting(configSchema, {
|
|
|
113
112
|
/** Parse JSON directly without stripping comments (standard JSON forbids comments; on error fall back to default). */
|
|
114
113
|
function readSettings(filePath: string): Record<string, unknown> {
|
|
115
114
|
try {
|
|
116
|
-
if (!fs.existsSync(filePath)) return {};
|
|
117
115
|
return asRecord(JSON.parse(fs.readFileSync(filePath, "utf-8")));
|
|
118
116
|
} catch {
|
|
119
117
|
return {};
|
|
@@ -124,9 +122,9 @@ function readSettings(filePath: string): Record<string, unknown> {
|
|
|
124
122
|
* Load config. The `hashlineEdit` in project `cwd/.pi/settings.json` replaces
|
|
125
123
|
* the global one wholesale; missing or invalid settings use their defaults.
|
|
126
124
|
*/
|
|
127
|
-
export function loadConfig(cwd
|
|
125
|
+
export function loadConfig(cwd: string): HashlineEditConfig {
|
|
128
126
|
const globalSettings = readSettings(path.join(getAgentDir(), "settings.json"));
|
|
129
|
-
const projectSettings =
|
|
127
|
+
const projectSettings = readSettings(path.join(cwd, ".pi", "settings.json"));
|
|
130
128
|
// Any project value replaces the global one, even null or an invalid value, which yields defaults.
|
|
131
129
|
const settings = Object.hasOwn(projectSettings, "hashlineEdit")
|
|
132
130
|
? projectSettings
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import assert from "node:assert/strict";
|
|
2
2
|
import { test } from "node:test";
|
|
3
|
+
import childProcess from "node:child_process";
|
|
4
|
+
import { syncBuiltinESMExports } from "node:module";
|
|
3
5
|
import { DiagnosticBuffer } from "./diagnostic-buffer.ts";
|
|
4
6
|
import { DEFAULT_OUTPUT_BUDGETS } from "./budgets.ts";
|
|
5
7
|
import { assembleGrepOutput } from "./grep-output.ts";
|
|
@@ -53,6 +55,7 @@ test("search warning aggregation retains the final cause and labels truncation",
|
|
|
53
55
|
files: 1,
|
|
54
56
|
},
|
|
55
57
|
warnings: [diagnostic(DEFAULT_OUTPUT_BUDGETS.fieldBytes)],
|
|
58
|
+
searchFacts: {},
|
|
56
59
|
outputMode: "content",
|
|
57
60
|
matchLimitReached: false,
|
|
58
61
|
effectiveLimit: 100,
|
|
@@ -64,13 +67,21 @@ test("search warning aggregation retains the final cause and labels truncation",
|
|
|
64
67
|
});
|
|
65
68
|
|
|
66
69
|
test("stderr overflow → UTF-8 opening and final cause survive", async (t) => {
|
|
70
|
+
const spawn = childProcess.spawn;
|
|
71
|
+
t.mock.method(childProcess, "spawn", (...args: Parameters<typeof spawn>) =>
|
|
72
|
+
spawn(process.execPath, args[1] ?? [], args[2]),
|
|
73
|
+
);
|
|
74
|
+
syncBuiltinESMExports();
|
|
75
|
+
t.after(() => {
|
|
76
|
+
t.mock.restoreAll();
|
|
77
|
+
syncBuiltinESMExports();
|
|
78
|
+
});
|
|
67
79
|
const directory = await mkdtemp(join(tmpdir(), "hl-rg-stderr-"));
|
|
68
80
|
t.after(() => rm(directory, { recursive: true, force: true }));
|
|
69
81
|
const path = join(directory, "stderr.txt");
|
|
70
82
|
for (const source of ["权限不足🙂\n", diagnostic(MAX_RG_STDERR_BYTES)]) {
|
|
71
83
|
await writeFile(path, source);
|
|
72
84
|
const result = await runRgPaths(
|
|
73
|
-
process.execPath,
|
|
74
85
|
[
|
|
75
86
|
"--input-type=module",
|
|
76
87
|
"--eval",
|
|
@@ -17,12 +17,11 @@ export class DiagnosticBuffer {
|
|
|
17
17
|
private head = "";
|
|
18
18
|
private tail = "";
|
|
19
19
|
private truncated = false;
|
|
20
|
+
private readonly maxBytes: number;
|
|
20
21
|
private readonly notice: string;
|
|
21
22
|
private readonly headBytes: number;
|
|
22
23
|
private readonly tailBytes: number;
|
|
23
24
|
|
|
24
|
-
private readonly maxBytes: number;
|
|
25
|
-
|
|
26
25
|
constructor(maxBytes: number) {
|
|
27
26
|
this.maxBytes = maxBytes;
|
|
28
27
|
this.notice = `\n[Diagnostics truncated (${formatByteSize(maxBytes)} limit); middle omitted.]\n`;
|
|
@@ -37,7 +37,6 @@ test("macOS attempts directory sync, tolerates unsupported operations, and prese
|
|
|
37
37
|
(error: unknown) =>
|
|
38
38
|
error instanceof FileMutationError &&
|
|
39
39
|
error.publication === "PUBLISHED" &&
|
|
40
|
-
error.stage === "post_process" &&
|
|
41
40
|
error.cause instanceof Error &&
|
|
42
41
|
"code" in error.cause &&
|
|
43
42
|
error.cause.code === "EIO",
|