@criogaid/pi-hashline-edit 0.6.0 → 0.7.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 +161 -304
- package/THIRD_PARTY_NOTICES.md +80 -0
- package/package.json +10 -6
- package/src/core/AGENTS.md +20 -0
- package/src/core/apply.test.ts +189 -60
- package/src/core/apply.ts +110 -74
- package/src/core/case-fold.test.ts +40 -0
- package/src/core/case-fold.ts +81 -0
- package/src/core/character-set.test.ts +103 -0
- package/src/core/character-set.ts +170 -0
- package/src/core/errors.test.ts +23 -0
- package/src/core/errors.ts +70 -4
- package/src/core/lines.ts +7 -0
- package/src/core/regex.ts +21 -0
- package/src/core/replace-schema.ts +34 -0
- package/src/core/replace.ts +37 -54
- package/src/core/search-analysis.test.ts +199 -0
- package/src/core/search-analysis.ts +375 -0
- package/src/core/search-matrix.test.ts +64 -0
- package/src/core/search-matrix.testing.ts +183 -0
- package/src/core/search-schema.ts +18 -0
- package/src/core/search.test.ts +145 -0
- package/src/core/search.ts +119 -0
- package/src/core/text.test.ts +16 -8
- package/src/core/text.ts +26 -6
- package/src/core/types.ts +16 -11
- package/src/index.ts +25 -15
- package/src/integration/config-registration.test.ts +30 -24
- package/src/integration/forget-grep.test.ts +52 -2
- package/src/integration/fusion-dispatch.test.ts +21 -105
- package/src/integration/grep-errors.test.ts +50 -0
- package/src/integration/grep-flags.test.ts +280 -0
- package/src/integration/grep-js-completeness.test.ts +208 -0
- package/src/integration/grep-line-candidates.test.ts +233 -0
- package/src/integration/grep-matrix.test.ts +121 -0
- package/src/integration/grep-path-matrix.test.ts +132 -0
- package/src/integration/grep-prefilter-coverage.test.ts +189 -0
- package/src/integration/grep-regex.test.ts +410 -0
- package/src/integration/grep-rg.test.ts +220 -402
- package/src/integration/grep-scan-budget.test.ts +89 -0
- package/src/integration/grep-translation.test.ts +206 -0
- package/src/integration/large-text.test.ts +57 -1
- package/src/integration/model-budget-lifecycle.test.ts +128 -0
- package/src/integration/mutation-file-types.test.ts +12 -25
- package/src/integration/mutation-file-types.testing.ts +33 -0
- package/src/integration/npm-package.test.ts +17 -0
- package/src/integration/npm-package.testing.ts +123 -0
- package/src/integration/publication-read-changes.test.ts +344 -0
- package/src/integration/read-changes.test.ts +98 -0
- package/src/integration/replace-package.test.ts +17 -36
- package/src/integration/replace-package.testing.ts +33 -0
- package/src/integration/replace-worker-boundary.test.ts +107 -0
- package/src/integration/report-replay.test.ts +90 -0
- package/src/integration/utf8-errors.test.ts +46 -0
- package/src/pi/AGENTS.md +55 -0
- package/src/pi/action-fusion.test.ts +253 -103
- package/src/pi/action-fusion.ts +116 -290
- package/src/pi/anchor-format.ts +9 -0
- package/src/pi/argument-diagnostics.ts +478 -0
- package/src/pi/argument-error.testing.ts +43 -0
- package/src/pi/argument-error.ts +78 -0
- package/src/pi/argument-format.test.ts +208 -0
- package/src/pi/argument-validation.test.ts +742 -45
- package/src/pi/argument-validation.ts +56 -59
- package/src/pi/budgets.ts +45 -16
- package/src/pi/codemode.test.ts +96 -0
- package/src/pi/config.test.ts +14 -10
- package/src/pi/config.ts +21 -7
- package/src/pi/diagnostic-buffer.test.ts +52 -16
- package/src/pi/diagnostic-buffer.ts +11 -14
- package/src/pi/directory-sync.test.ts +4 -1
- package/src/pi/edit-tool.ts +100 -93
- package/src/pi/error-text.ts +39 -16
- package/src/pi/execute.test.ts +362 -315
- package/src/pi/extension-loading.test.ts +14 -0
- package/src/pi/extension-loading.testing.ts +3 -0
- package/src/pi/failure-context.test.ts +220 -88
- package/src/pi/failure-context.ts +161 -180
- package/src/pi/failure-path.test.ts +85 -88
- package/src/pi/file-commit.test.ts +78 -45
- package/src/pi/file-commit.ts +218 -151
- package/src/pi/file-read.test.ts +29 -0
- package/src/pi/file-read.ts +60 -0
- package/src/pi/file-snapshot.test.ts +1 -1
- package/src/pi/forget-tool.ts +189 -90
- package/src/pi/forget.test.ts +309 -22
- package/src/pi/forget.testing.ts +41 -113
- package/src/pi/fusion-card.test.ts +40 -14
- package/src/pi/fusion-card.ts +84 -50
- package/src/pi/grep-candidates.test.ts +127 -0
- package/src/pi/grep-candidates.ts +193 -0
- package/src/pi/grep-matrix.test.ts +83 -0
- package/src/pi/grep-output.ts +181 -138
- package/src/pi/grep-render.ts +28 -25
- package/src/pi/grep-scope.ts +61 -53
- package/src/pi/grep-search.ts +299 -242
- package/src/pi/grep-tool.ts +150 -140
- package/src/pi/grep-worker.mjs +4 -0
- package/src/pi/grep-worker.ts +14 -0
- package/src/pi/grep.test.ts +631 -632
- package/src/pi/model-budgets.test.ts +43 -0
- package/src/pi/model-budgets.ts +44 -0
- package/src/pi/mutation-outcome.testing.ts +5 -5
- package/src/pi/mutation-result.test.ts +21 -74
- package/src/pi/mutation-result.ts +74 -87
- package/src/pi/mutation-runner.ts +83 -75
- package/src/pi/output-budgets.test.ts +166 -0
- package/src/pi/path.ts +7 -0
- package/src/pi/read-tool.ts +151 -137
- package/src/pi/read.test.ts +39 -33
- package/src/pi/regex-worker-contract.ts +73 -0
- package/src/pi/regex-worker.ts +101 -0
- package/src/pi/registration.test.ts +111 -92
- package/src/pi/render.test.ts +193 -19
- package/src/pi/render.ts +137 -29
- package/src/pi/replace-regex.ts +11 -44
- package/src/pi/replace-tool.ts +38 -145
- package/src/pi/replace-worker-contract.ts +19 -0
- package/src/pi/replace-worker.ts +12 -8
- package/src/pi/replace.test.ts +93 -160
- package/src/pi/report-cause.ts +99 -0
- package/src/pi/report-failure.testing.ts +20 -0
- package/src/pi/report-schema.ts +512 -0
- package/src/pi/report.test.ts +276 -0
- package/src/pi/report.ts +288 -0
- package/src/pi/result-safety.test.ts +122 -427
- package/src/pi/rg-process.test.ts +78 -79
- package/src/pi/rg-process.ts +124 -177
- package/src/pi/rg-regex.test.ts +50 -0
- package/src/pi/rg-regex.ts +709 -0
- package/src/pi/text-stream.test.ts +67 -38
- package/src/pi/text-stream.ts +96 -75
- package/src/pi/tool-call.testing.ts +3 -39
- package/src/pi/write-tool.ts +45 -34
- package/src/pi/write.test.ts +45 -37
- package/src/testing/extension-loader.testing.ts +24 -0
- package/src/testing/installation.testing.ts +77 -0
- package/src/testing/process.testing.ts +33 -0
- package/src/testing/regex-host.testing.ts +20 -0
- package/src/testing/regex-translation-corpus.ts +308 -0
- package/src/testing/rg-line-listing.fixture.mjs +7 -0
- package/src/testing/run-tests.ts +47 -0
- package/src/testing/session.testing.ts +127 -0
- package/src/pi/rg-line-ranges.test.ts +0 -66
- package/src/pi/rg-line-ranges.ts +0 -75
- package/src/pi/rg-match-bytes.ts +0 -95
- package/src/pi/rg-text-view.ts +0 -192
- package/src/pi/tool-prompts.ts +0 -15
package/src/pi/grep-scope.ts
CHANGED
|
@@ -1,45 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* grep's search scope: path resolution, explicit-file admission under the caller's globs, and
|
|
3
|
+
* the only conversion of a scope into rg flags.
|
|
4
|
+
*
|
|
5
|
+
* @module pi-hashline-edit/pi
|
|
6
|
+
*/
|
|
1
7
|
import { stat } from "node:fs/promises";
|
|
2
8
|
import { dirname, resolve } from "node:path";
|
|
3
9
|
import { canonicalPath } from "./path.ts";
|
|
4
|
-
import { COMMON_RG_ARGS } from "./rg-process.ts";
|
|
5
|
-
import {
|
|
6
|
-
recordSearchDiagnostics,
|
|
7
|
-
scopeArgs,
|
|
8
|
-
type GrepBackend,
|
|
9
|
-
type SearchScope,
|
|
10
|
-
} from "./grep-search.ts";
|
|
11
|
-
import { throwIfCancelled } from "./error-text.ts";
|
|
10
|
+
import { COMMON_RG_ARGS, recordSearchDiagnostics, type GrepBackend } from "./rg-process.ts";
|
|
11
|
+
import { errnoCode, HashlineError } from "../core/errors.ts";
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
const NON_RUST_REGEX_SYNTAX = /(?:^|[^\\])(?:\\\\)*(?:\(\?<?[=!]|\\[1-9]|\\k<)/;
|
|
19
|
-
|
|
20
|
-
/** Explain a parse failure caused by another regex dialect's syntax, if the query contains any. */
|
|
21
|
-
function regexDialectHint(patterns: readonly string[]): string | undefined {
|
|
22
|
-
return patterns.some((pattern) => NON_RUST_REGEX_SYNTAX.test(pattern))
|
|
23
|
-
? "ripgrep's Rust regex has no lookaround or backreferences; rewrite the pattern, or use replace for a JavaScript regex within one file"
|
|
24
|
-
: undefined;
|
|
13
|
+
export interface SearchScope {
|
|
14
|
+
readonly globs: readonly string[];
|
|
15
|
+
readonly noIgnore: boolean;
|
|
16
|
+
readonly follow: boolean;
|
|
17
|
+
readonly searchPaths: readonly string[];
|
|
25
18
|
}
|
|
26
19
|
|
|
27
|
-
/**
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
throw new Error(`${result.stderr.trim()}\n${hint}.`);
|
|
41
|
-
}
|
|
42
|
-
throw new Error(result.stderr.trim() || `ripgrep exited with code ${result.code}`);
|
|
20
|
+
/**
|
|
21
|
+
* The only place scope becomes rg flags. Traversal that respects ignore rules also skips
|
|
22
|
+
* `.git` directories, which `--hidden` would otherwise search; a named path is still searched.
|
|
23
|
+
* The exclusion follows the caller's globs, because a later rg glob takes precedence.
|
|
24
|
+
*/
|
|
25
|
+
export function scopeArgs(scope: SearchScope): string[] {
|
|
26
|
+
return [
|
|
27
|
+
"--hidden",
|
|
28
|
+
...(scope.noIgnore ? ["--no-ignore"] : []),
|
|
29
|
+
...(scope.follow ? ["--follow"] : []),
|
|
30
|
+
...scope.globs.flatMap((glob) => ["--glob", glob]),
|
|
31
|
+
...(scope.noIgnore ? [] : ["--glob", "!.git"]),
|
|
32
|
+
];
|
|
43
33
|
}
|
|
44
34
|
|
|
45
35
|
/** Normalize a `string | string[]` param to an array (`undefined` → `[]`). */
|
|
@@ -49,10 +39,11 @@ export function toArray(v: string | string[] | undefined): string[] {
|
|
|
49
39
|
}
|
|
50
40
|
|
|
51
41
|
export interface SearchPathInfo {
|
|
52
|
-
path: string;
|
|
53
|
-
isFile: boolean;
|
|
42
|
+
readonly path: string;
|
|
43
|
+
readonly isFile: boolean;
|
|
54
44
|
}
|
|
55
45
|
|
|
46
|
+
/** Canonical search paths, the working directory when none is given; a missing one fails. */
|
|
56
47
|
export async function resolveSearchPaths(cwd: string, path: string | string[] | undefined) {
|
|
57
48
|
const searchPaths = (() => {
|
|
58
49
|
const values = toArray(path);
|
|
@@ -63,23 +54,38 @@ export async function resolveSearchPaths(cwd: string, path: string | string[] |
|
|
|
63
54
|
try {
|
|
64
55
|
pathInfo.push({ path: searchPath, isFile: (await stat(searchPath)).isFile() });
|
|
65
56
|
} catch (error) {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
missing
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
throw new Error(`Path not found: ${searchPath}${hint}`);
|
|
57
|
+
// Only a missing path is PATH_NOT_FOUND; other filesystem errors keep their cause.
|
|
58
|
+
if (errnoCode(error) !== "ENOENT") throw error;
|
|
59
|
+
throw new HashlineError("PATH_NOT_FOUND", "Search path not found.", {
|
|
60
|
+
facts: { missing: searchPath },
|
|
61
|
+
...(/[*?]/.test(searchPath) ? { next: "useGlob" as const } : {}),
|
|
62
|
+
});
|
|
73
63
|
}
|
|
74
64
|
}
|
|
75
65
|
return { searchPaths, pathInfo };
|
|
76
66
|
}
|
|
77
67
|
|
|
78
|
-
|
|
68
|
+
/** Groups spellings that a case-insensitive filesystem may treat as one file. */
|
|
69
|
+
const foldedKey = (path: string): string => resolve(path).toLowerCase();
|
|
70
|
+
|
|
71
|
+
/** Whether rg listed the named file, possibly under its on-disk case spelling. */
|
|
72
|
+
async function isListed(path: string, listed: ReadonlyMap<string, readonly string[]>) {
|
|
73
|
+
const spellings = listed.get(foldedKey(path)) ?? [];
|
|
79
74
|
const absolute = resolve(path);
|
|
80
|
-
|
|
75
|
+
if (spellings.some((spelling) => resolve(spelling) === absolute)) return true;
|
|
76
|
+
if (!spellings.length) return false;
|
|
77
|
+
const identity = (spelling: string) =>
|
|
78
|
+
stat(spelling, { bigint: true }).then(
|
|
79
|
+
({ dev, ino }) => `${dev}:${ino}`,
|
|
80
|
+
() => undefined,
|
|
81
|
+
);
|
|
82
|
+
const named = await identity(path);
|
|
83
|
+
for (const spelling of spellings)
|
|
84
|
+
if (named !== undefined && (await identity(spelling)) === named) return true;
|
|
85
|
+
return false;
|
|
81
86
|
}
|
|
82
87
|
|
|
88
|
+
/** Keep directories and the explicitly named files that the ordered globs admit. */
|
|
83
89
|
export async function filterExplicitFilesByGlob(
|
|
84
90
|
backend: GrepBackend,
|
|
85
91
|
rgPath: string,
|
|
@@ -92,7 +98,7 @@ export async function filterExplicitFilesByGlob(
|
|
|
92
98
|
if (scope.globs.length === 0 || explicitFiles.length === 0) return paths.map(({ path }) => path);
|
|
93
99
|
|
|
94
100
|
const parents = [...new Set(explicitFiles.map(({ path }) => dirname(path)))];
|
|
95
|
-
const allowed = new
|
|
101
|
+
const allowed = new Map<string, string[]>();
|
|
96
102
|
// Direct file arguments bypass ignore and symlink traversal; let only the ordered globs decide admission.
|
|
97
103
|
const args = [
|
|
98
104
|
...COMMON_RG_ARGS,
|
|
@@ -104,11 +110,13 @@ export async function filterExplicitFilesByGlob(
|
|
|
104
110
|
...parents,
|
|
105
111
|
];
|
|
106
112
|
const listed = await backend.runRgPaths(rgPath, args, signal, async (path) => {
|
|
107
|
-
|
|
113
|
+
const key = foldedKey(path);
|
|
114
|
+
allowed.set(key, [...(allowed.get(key) ?? []), path]);
|
|
108
115
|
return true;
|
|
109
116
|
});
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
117
|
+
const admitted = new Set<string>();
|
|
118
|
+
for (const { path } of explicitFiles) if (await isListed(path, allowed)) admitted.add(path);
|
|
119
|
+
// Listing diagnostics about sibling entries matter only when they may explain an exclusion.
|
|
120
|
+
if (admitted.size < explicitFiles.length) recordSearchDiagnostics(listed, warnings);
|
|
121
|
+
return paths.filter(({ path, isFile }) => !isFile || admitted.has(path)).map(({ path }) => path);
|
|
114
122
|
}
|