@holmes-lab/holmes-kit 0.29.0 → 0.31.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/CHANGELOG.md +556 -0
- package/README.md +15 -5
- package/bin/holmes-hook-antigravity.js +4 -0
- package/bin/holmes-kit.js +4 -0
- package/bin/holmes-pre-push.js +3 -0
- package/bin/holmes-stop-antigravity.js +4 -0
- package/dist/.build-id +1 -1
- package/dist/holmes/cli/agents-guidance-history.d.ts +1 -1
- package/dist/holmes/cli/agents-guidance-history.js +11 -2
- package/dist/holmes/cli/agents-guidance.d.ts +1 -0
- package/dist/holmes/cli/agents-guidance.js +11 -8
- package/dist/holmes/cli/agents.d.ts +41 -0
- package/dist/holmes/cli/agents.js +382 -2
- package/dist/holmes/cli/attest.d.ts +2 -0
- package/dist/holmes/cli/attest.js +66 -15
- package/dist/holmes/cli/ci-gate.js +16 -1
- package/dist/holmes/cli/claude-switches.d.ts +95 -0
- package/dist/holmes/cli/claude-switches.js +967 -0
- package/dist/holmes/cli/codex-hooks.d.ts +77 -0
- package/dist/holmes/cli/codex-hooks.js +802 -0
- package/dist/holmes/cli/codex-oracle.d.ts +194 -0
- package/dist/holmes/cli/codex-oracle.js +1245 -0
- package/dist/holmes/cli/codex-toml.d.ts +58 -1
- package/dist/holmes/cli/codex-toml.js +456 -40
- package/dist/holmes/cli/doctor.d.ts +108 -8
- package/dist/holmes/cli/doctor.js +1408 -98
- package/dist/holmes/cli/index.js +23 -11
- package/dist/holmes/cli/init.d.ts +13 -0
- package/dist/holmes/cli/init.js +749 -77
- package/dist/holmes/cli/interactive-prompt.js +2 -2
- package/dist/holmes/cli/mcp-launcher.d.ts +64 -6
- package/dist/holmes/cli/mcp-launcher.js +189 -6
- package/dist/holmes/cli/mcp-version.js +13 -2
- package/dist/holmes/cli/settings-merge.js +8 -2
- package/dist/holmes/cli/upgrade.d.ts +13 -0
- package/dist/holmes/cli/upgrade.js +116 -23
- package/dist/holmes/cli/workspace-scope.d.ts +22 -0
- package/dist/holmes/cli/workspace-scope.js +375 -0
- package/dist/holmes/cli/worktree-readiness.d.ts +1 -0
- package/dist/holmes/cli/worktree-readiness.js +17 -3
- package/dist/holmes/cpg/cpg-scanner.d.ts +29 -0
- package/dist/holmes/cpg/cpg-scanner.js +403 -3
- package/dist/holmes/cpg/cycle-detect.js +2 -1
- package/dist/holmes/cpg/forbidden-edges.js +9 -2
- package/dist/holmes/cpg/required-calls.js +8 -1
- package/dist/holmes/governance/autonomy.d.ts +9 -0
- package/dist/holmes/governance/autonomy.js +28 -1
- package/dist/holmes/governance/constitution-debt.js +3 -2
- package/dist/holmes/governance/constitution.js +15 -3
- package/dist/holmes/governance/provenance-chain.js +3 -2
- package/dist/holmes/governance/push-gate-runner.js +4 -3
- package/dist/holmes/guardrail/dependency-delta.js +4 -3
- package/dist/holmes/guardrail/linear-match.d.ts +57 -0
- package/dist/holmes/guardrail/linear-match.js +256 -0
- package/dist/holmes/guardrail/risk-classifier.d.ts +6 -7
- package/dist/holmes/guardrail/risk-classifier.js +931 -44
- package/dist/holmes/guardrail/risk-types.d.ts +6 -0
- package/dist/holmes/guardrail/scope-judgment.d.ts +4 -24
- package/dist/holmes/guardrail/scope-judgment.js +100 -23
- package/dist/holmes/guardrail/shell-words.d.ts +42 -0
- package/dist/holmes/guardrail/shell-words.js +1720 -0
- package/dist/holmes/guardrail/write-target.d.ts +168 -3
- package/dist/holmes/guardrail/write-target.js +2379 -87
- package/dist/holmes/hooks/adapters/antigravity.d.ts +3 -1
- package/dist/holmes/hooks/adapters/antigravity.js +115 -11
- package/dist/holmes/hooks/pre-tool-use.d.ts +32 -6
- package/dist/holmes/hooks/pre-tool-use.js +923 -87
- package/dist/holmes/hooks/rtm-refresh-child.d.ts +22 -1
- package/dist/holmes/hooks/rtm-refresh-child.js +102 -18
- package/dist/holmes/hooks/rtm-refresh.d.ts +20 -1
- package/dist/holmes/hooks/rtm-refresh.js +60 -15
- package/dist/holmes/hooks/session-start.d.ts +10 -0
- package/dist/holmes/hooks/session-start.js +31 -7
- package/dist/holmes/hooks/stop.d.ts +2 -1
- package/dist/holmes/hooks/stop.js +197 -91
- package/dist/holmes/mcp/approval-adapters.d.ts +22 -0
- package/dist/holmes/mcp/approval-adapters.js +21 -0
- package/dist/holmes/mcp/approval-commit.d.ts +20 -0
- package/dist/holmes/mcp/approval-commit.js +108 -0
- package/dist/holmes/mcp/approval-intent.d.ts +44 -0
- package/dist/holmes/mcp/approval-intent.js +67 -0
- package/dist/holmes/mcp/approval-policy.d.ts +14 -0
- package/dist/holmes/mcp/approval-policy.js +18 -0
- package/dist/holmes/mcp/elicit-approval.d.ts +2 -0
- package/dist/holmes/mcp/elicit-approval.js +8 -3
- package/dist/holmes/mcp/handlers/graph-operations.d.ts +17 -1
- package/dist/holmes/mcp/handlers/graph-operations.js +15 -6
- package/dist/holmes/mcp/handlers/maintenance-analysis.js +11 -5
- package/dist/holmes/mcp/handlers/maintenance-evidence.js +3 -2
- package/dist/holmes/mcp/handlers/phase-queries.d.ts +22 -7
- package/dist/holmes/mcp/handlers/phase-queries.js +81 -2
- package/dist/holmes/mcp/handlers/requirement-triage.d.ts +26 -0
- package/dist/holmes/mcp/handlers/requirement-triage.js +48 -11
- package/dist/holmes/mcp/handlers/review-evidence.d.ts +2 -1
- package/dist/holmes/mcp/handlers/review-evidence.js +15 -5
- package/dist/holmes/mcp/handlers/slice-orchestration.d.ts +18 -0
- package/dist/holmes/mcp/handlers/slice-orchestration.js +122 -16
- package/dist/holmes/mcp/handlers/spec-approval.d.ts +35 -2
- package/dist/holmes/mcp/handlers/spec-approval.js +175 -57
- package/dist/holmes/mcp/handlers/spec-authoring.js +36 -3
- package/dist/holmes/mcp/handlers/spec-queries.d.ts +39 -3
- package/dist/holmes/mcp/handlers/spec-queries.js +114 -7
- package/dist/holmes/mcp/handlers/test-execution.js +9 -3
- package/dist/holmes/mcp/handlers.d.ts +126 -8
- package/dist/holmes/mcp/handlers.js +109 -18
- package/dist/holmes/mcp/harness-attestation.d.ts +20 -0
- package/dist/holmes/mcp/harness-attestation.js +179 -0
- package/dist/holmes/mcp/maintenance-analyze.js +28 -4
- package/dist/holmes/mcp/maintenance-evidence.js +1 -1
- package/dist/holmes/mcp/requirement-triage-evidence.d.ts +72 -2
- package/dist/holmes/mcp/requirement-triage-evidence.js +227 -1
- package/dist/holmes/mcp/server.js +24 -3
- package/dist/holmes/mcp/supervisor.js +7 -3
- package/dist/holmes/mcp/tool-schemas.d.ts +8 -0
- package/dist/holmes/mcp/tool-schemas.js +54 -7
- package/dist/holmes/mcp/validate-args.js +12 -0
- package/dist/holmes/project/bounded-io.d.ts +102 -0
- package/dist/holmes/project/bounded-io.js +212 -0
- package/dist/holmes/project/change-source.js +3 -1
- package/dist/holmes/project/ci-runs.js +3 -2
- package/dist/holmes/project/ignore.d.ts +31 -2
- package/dist/holmes/project/ignore.js +409 -50
- package/dist/holmes/project/regular-file-guard.d.ts +13 -0
- package/dist/holmes/project/regular-file-guard.js +149 -0
- package/dist/holmes/project/root.js +12 -3
- package/dist/holmes/refresh/freshness-coordinator.d.ts +67 -0
- package/dist/holmes/refresh/freshness-coordinator.js +230 -0
- package/dist/holmes/reverse/anchor.js +4 -3
- package/dist/holmes/reverse/scan.js +6 -2
- package/dist/holmes/review/commit-text.js +3 -2
- package/dist/holmes/review/condition-hunk-replay.d.ts +12 -0
- package/dist/holmes/review/condition-hunk-replay.js +13 -2
- package/dist/holmes/review/condition-hunk-resolution.js +59 -8
- package/dist/holmes/review/failed-test-names.js +13 -10
- package/dist/holmes/review/findings.js +3 -1
- package/dist/holmes/review/kills-check.js +6 -1
- package/dist/holmes/review/point-in-time-replay.js +5 -4
- package/dist/holmes/review/replay-corpus.js +5 -4
- package/dist/holmes/review/requirement-triage-human-records.d.ts +59 -0
- package/dist/holmes/review/requirement-triage-human-records.js +119 -0
- package/dist/holmes/review/run-replay.js +3 -2
- package/dist/holmes/review/scope.js +6 -1
- package/dist/holmes/review/temporal-prior.js +3 -2
- package/dist/holmes/review/test-evidence.js +3 -2
- package/dist/holmes/review/test-outcomes.d.ts +28 -0
- package/dist/holmes/review/test-outcomes.js +92 -2
- package/dist/holmes/review/test-runner.d.ts +6 -0
- package/dist/holmes/review/test-runner.js +36 -15
- package/dist/holmes/rtm/advisory-outcomes.js +3 -2
- package/dist/holmes/rtm/anchor-ids.js +42 -2
- package/dist/holmes/rtm/file-anchors.js +4 -1
- package/dist/holmes/rtm/ftt-fulfilment.js +8 -3
- package/dist/holmes/rtm/git-changes.js +3 -1
- package/dist/holmes/rtm/graph-store.js +3 -2
- package/dist/holmes/rtm/test-scope.js +9 -4
- package/dist/holmes/spec/compat-impact.d.ts +25 -4
- package/dist/holmes/spec/compat-impact.js +682 -11
- package/dist/holmes/spec/entity-git-snapshot.js +3 -2
- package/dist/holmes/spec/entity-integration.js +3 -2
- package/dist/holmes/spec/entity-renumber-transaction.d.ts +19 -0
- package/dist/holmes/spec/entity-renumber-transaction.js +79 -6
- package/dist/holmes/spec/remote-spec-refs.js +3 -2
- package/dist/holmes/spec/renumber.js +25 -10
- package/dist/holmes/spec/spec-parser.js +9 -3
- package/dist/holmes/spec/yaml-scalar.js +2 -2
- package/dist/holmes/update/refresh.js +3 -1
- package/dist/holmes/update/update-notice.d.ts +6 -0
- package/dist/holmes/update/update-notice.js +18 -1
- package/package.json +11 -4
|
@@ -33,81 +33,255 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.IGNORE_PATH_TOKENS_BUDGET = exports.IGNORE_RULES_CAP = exports.IGNORE_FILE_CAP = void 0;
|
|
36
37
|
exports.parseIgnore = parseIgnore;
|
|
37
38
|
exports.loadIgnore = loadIgnore;
|
|
38
|
-
|
|
39
|
+
exports.readIgnoreFileSafely = readIgnoreFileSafely;
|
|
40
|
+
// @implements A-SPEC-733, A-SPEC-128
|
|
39
41
|
const fs = __importStar(require("node:fs"));
|
|
40
42
|
const path = __importStar(require("node:path"));
|
|
41
43
|
const LIMITATIONS = [
|
|
42
44
|
'only the project-root .gitignore is read — nested per-directory .gitignore files are not',
|
|
43
45
|
'backslash escapes are not interpreted',
|
|
44
46
|
'.git/info/exclude and the global core.excludesFile are not read',
|
|
47
|
+
// A-SPEC-733 (round 13): both in the scan-MORE direction (never hiding a file git tracks).
|
|
48
|
+
'a negation re-includes a path below an excluded directory (git cannot: `dist/` then `!dist/keep.js` keeps dist/keep.js ignored in git)',
|
|
49
|
+
'core.ignorecase is not honoured: patterns match case-sensitively',
|
|
45
50
|
];
|
|
46
51
|
/** Constructs the subset deliberately does not implement: escapes, and an unterminated class. */
|
|
47
52
|
const UNSUPPORTED_RE = /\\/;
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
* earlier version re-assembled the compiled regex's source at match time to express that, which
|
|
55
|
-
* passed its tests and was still the wrong shape — unreadable, and correct only for the cases tried.
|
|
56
|
-
*/
|
|
53
|
+
// @implements A-SPEC-733 (round 9) — `/\[[^\]]*$/` restarted at every `[` of a run that ends in `]`
|
|
54
|
+
// (80 KB: 3 s in test_run — measured); a `[` after the last `]` is the same test, in one look.
|
|
55
|
+
const unterminatedClass = (line) => line.lastIndexOf('[') > line.lastIndexOf(']');
|
|
56
|
+
/** A pattern line the matcher cannot compile (reported as unsupported, never dropped with its file). */
|
|
57
|
+
class UnsupportedIgnorePattern extends Error {
|
|
58
|
+
}
|
|
57
59
|
function compile(pattern, dirOnly) {
|
|
58
60
|
const anchored = pattern.startsWith('/');
|
|
59
|
-
|
|
61
|
+
const body = anchored ? pattern.slice(1) : pattern;
|
|
60
62
|
// A pattern containing a slash anywhere is anchored to the root; a bare name matches at any depth.
|
|
61
63
|
const rooted = anchored || body.includes('/');
|
|
62
|
-
|
|
64
|
+
const tokens = [];
|
|
63
65
|
for (let i = 0; i < body.length; i++) {
|
|
64
66
|
const c = body[i];
|
|
65
67
|
if (c === '*') {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
68
|
+
// @implements A-SPEC-733 (round 12/13) — git's `**` is a double star only when bounded by `/` or the
|
|
69
|
+
// pattern's ends; elsewhere it is one `*` (`a**b` is `a*b`, `/**.log` is `/*.log` — measured drift).
|
|
70
|
+
// Round 13: a RUN of stars is one unit, as git's wildmatch collapses it (`***/x` is `**/x`).
|
|
71
|
+
let end = i;
|
|
72
|
+
while (body[end + 1] === '*')
|
|
73
|
+
end++;
|
|
74
|
+
if (end > i) {
|
|
75
|
+
const boundedLeft = i === 0 || body[i - 1] === '/';
|
|
76
|
+
const after = body[end + 1];
|
|
77
|
+
if (boundedLeft && after === '/') {
|
|
78
|
+
tokens.push({ kind: 'dstarslash' });
|
|
79
|
+
i = end + 1;
|
|
80
|
+
}
|
|
81
|
+
else if (boundedLeft && after === undefined) {
|
|
82
|
+
tokens.push({ kind: 'dstar' });
|
|
83
|
+
i = end;
|
|
71
84
|
}
|
|
72
85
|
else {
|
|
73
|
-
|
|
74
|
-
i
|
|
86
|
+
tokens.push({ kind: 'star' });
|
|
87
|
+
i = end;
|
|
75
88
|
}
|
|
76
89
|
}
|
|
77
|
-
else
|
|
78
|
-
|
|
79
|
-
}
|
|
90
|
+
else
|
|
91
|
+
tokens.push({ kind: 'star' });
|
|
80
92
|
continue;
|
|
81
93
|
}
|
|
82
94
|
if (c === '?') {
|
|
83
|
-
|
|
95
|
+
tokens.push({ kind: 'q' });
|
|
84
96
|
continue;
|
|
85
97
|
}
|
|
86
98
|
if (c === '[') {
|
|
87
|
-
// A character class,
|
|
88
|
-
//
|
|
89
|
-
|
|
99
|
+
// A character class, with git's `!` negation; `/` is excluded so a class can never cross a separator.
|
|
100
|
+
// Round 12: a `]` first in the class (after the negation) is a literal member (`[]a]`, `[!]a]`).
|
|
101
|
+
let j = i + 1;
|
|
102
|
+
if (body[j] === '!' || body[j] === '^')
|
|
103
|
+
j++;
|
|
104
|
+
if (body[j] === ']')
|
|
105
|
+
j++;
|
|
106
|
+
const end = body.indexOf(']', j);
|
|
107
|
+
// Round 13: `[]`, `[!]`, `*.py[!]` — no closing `]` after a leading one — made `i = -1` and the loop
|
|
108
|
+
// restarted forever (every `loadIgnore` consumer wedged — measured); git matches nothing with it.
|
|
109
|
+
if (end === -1)
|
|
110
|
+
throw new UnsupportedIgnorePattern();
|
|
90
111
|
const inner = body.slice(i + 1, end);
|
|
91
112
|
const negated = inner.startsWith('!') || inner.startsWith('^');
|
|
92
|
-
|
|
113
|
+
// @implements A-SPEC-733 (round 11) — a class the engine refuses (`[a-Z]`, a reversed range) makes
|
|
114
|
+
// this LINE unsupported, never the whole file (measured: `loadIgnore` dropped every rule).
|
|
115
|
+
let re;
|
|
116
|
+
try {
|
|
117
|
+
re = new RegExp(`^[${negated ? '^' : ''}${(negated ? inner.slice(1) : inner).replace(/[\\\]]/g, '\\$&')}]$`);
|
|
118
|
+
}
|
|
119
|
+
catch {
|
|
120
|
+
throw new UnsupportedIgnorePattern();
|
|
121
|
+
}
|
|
122
|
+
tokens.push({ kind: 'class', re });
|
|
93
123
|
i = end;
|
|
94
124
|
continue;
|
|
95
125
|
}
|
|
96
|
-
|
|
126
|
+
tokens.push({ kind: 'lit', ch: c });
|
|
97
127
|
}
|
|
98
|
-
//
|
|
99
|
-
//
|
|
100
|
-
|
|
101
|
-
|
|
128
|
+
// @implements A-SPEC-733 (round 11) — adjacent star tokens coalesce: a 20 KB line of `*` was 20,000
|
|
129
|
+
// passes over the path (138 ms per path, 82 s over ci-gate's files — measured). `**` absorbs its
|
|
130
|
+
// neighbours, `*`+`*` is `*`, `**/`+`**/` is `**/`.
|
|
131
|
+
const merged = [];
|
|
132
|
+
for (const tok of tokens) {
|
|
133
|
+
const prev = merged[merged.length - 1];
|
|
134
|
+
const starry = (t) => t !== undefined && (t.kind === 'star' || t.kind === 'dstar' || t.kind === 'dstarslash');
|
|
135
|
+
if (starry(prev) && starry(tok)) {
|
|
136
|
+
if (prev.kind === 'dstar')
|
|
137
|
+
continue;
|
|
138
|
+
if (tok.kind === 'dstar') {
|
|
139
|
+
merged[merged.length - 1] = tok;
|
|
140
|
+
continue;
|
|
141
|
+
}
|
|
142
|
+
if (prev.kind === tok.kind)
|
|
143
|
+
continue;
|
|
144
|
+
}
|
|
145
|
+
merged.push(tok);
|
|
146
|
+
}
|
|
147
|
+
// @implements A-SPEC-733 (round 12) — a literal tail (`*.log` → `.log`) or a rooted literal head dismisses
|
|
148
|
+
// most rules by a string compare before the table walk (100,000 rules: 387 ms per path — measured).
|
|
149
|
+
const firstGlob = (() => { const m = /[*?[]/.exec(body); return m ? m.index : body.length; })();
|
|
150
|
+
const prefix = rooted ? body.slice(0, firstGlob) : '';
|
|
151
|
+
// @implements A-SPEC-733 (round 13) — the REQUIRED LITERAL: the longest run of literal characters within
|
|
152
|
+
// one segment. Any path this rule matches contains it, so the index touches only rules whose literal
|
|
153
|
+
// occurs in the path (round 12's tail index left every glob-ended rule a candidate: 100,000 `a<i>*`
|
|
154
|
+
// rules, 128 ms per path — measured).
|
|
155
|
+
let literal = '';
|
|
156
|
+
let run = '';
|
|
157
|
+
for (const tok of merged) {
|
|
158
|
+
if (tok.kind === 'lit' && tok.ch !== '/') {
|
|
159
|
+
run += tok.ch;
|
|
160
|
+
if (run.length > literal.length)
|
|
161
|
+
literal = run;
|
|
162
|
+
}
|
|
163
|
+
else
|
|
164
|
+
run = '';
|
|
165
|
+
}
|
|
166
|
+
const suffix = literal;
|
|
167
|
+
const matcher = (p, reach, next) => {
|
|
168
|
+
const n = p.length;
|
|
169
|
+
reach.fill(0, 0, n + 1);
|
|
170
|
+
reach[0] = 1;
|
|
171
|
+
if (!rooted)
|
|
172
|
+
for (let k = 0; k < n; k++)
|
|
173
|
+
if (p[k] === '/')
|
|
174
|
+
reach[k + 1] = 1;
|
|
175
|
+
for (const tok of merged) {
|
|
176
|
+
next.fill(0, 0, n + 1);
|
|
177
|
+
let any = false;
|
|
178
|
+
// Round 11: each star kind is ONE forward sweep (an "alive" flag), linear in the path.
|
|
179
|
+
if (tok.kind === 'star') {
|
|
180
|
+
let active = false;
|
|
181
|
+
for (let k = 0; k <= n; k++) {
|
|
182
|
+
if (reach[k])
|
|
183
|
+
active = true;
|
|
184
|
+
if (active) {
|
|
185
|
+
next[k] = 1;
|
|
186
|
+
any = true;
|
|
187
|
+
}
|
|
188
|
+
if (k < n && p[k] === '/')
|
|
189
|
+
active = false;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
else if (tok.kind === 'dstar') {
|
|
193
|
+
let active = false;
|
|
194
|
+
for (let k = 0; k <= n; k++) {
|
|
195
|
+
if (reach[k])
|
|
196
|
+
active = true;
|
|
197
|
+
if (active) {
|
|
198
|
+
next[k] = 1;
|
|
199
|
+
any = true;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
else if (tok.kind === 'dstarslash') {
|
|
204
|
+
// A chain stands at a position; it continues past a `/` only after consuming a non-empty segment.
|
|
205
|
+
let alive = false, contAt = false;
|
|
206
|
+
for (let k = 0; k <= n; k++) {
|
|
207
|
+
const at = reach[k] === 1 || contAt;
|
|
208
|
+
contAt = false;
|
|
209
|
+
if (at) {
|
|
210
|
+
next[k] = 1;
|
|
211
|
+
any = true;
|
|
212
|
+
if (k < n && p[k] !== '/')
|
|
213
|
+
alive = true;
|
|
214
|
+
}
|
|
215
|
+
if (k < n && p[k] === '/') {
|
|
216
|
+
if (alive)
|
|
217
|
+
contAt = true;
|
|
218
|
+
alive = false;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
else {
|
|
223
|
+
for (let pos = 0; pos < n; pos++) {
|
|
224
|
+
if (!reach[pos])
|
|
225
|
+
continue;
|
|
226
|
+
const ch = p[pos];
|
|
227
|
+
const ok = tok.kind === 'lit' ? ch === tok.ch : tok.kind === 'q' ? ch !== '/' : ch !== '/' && tok.re.test(ch);
|
|
228
|
+
if (ok) {
|
|
229
|
+
next[pos + 1] = 1;
|
|
230
|
+
any = true;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
if (!any)
|
|
235
|
+
return false;
|
|
236
|
+
// Swap the buffers (both are the caller's).
|
|
237
|
+
const swap = reach;
|
|
238
|
+
reach = next;
|
|
239
|
+
next = swap;
|
|
240
|
+
}
|
|
241
|
+
for (let pos = 0; pos <= n; pos++) {
|
|
242
|
+
if (!reach[pos])
|
|
243
|
+
continue;
|
|
244
|
+
if (dirOnly ? (pos < n && p[pos] === '/' && pos + 1 < n) : (pos === n || p[pos] === '/'))
|
|
245
|
+
return true;
|
|
246
|
+
}
|
|
247
|
+
return false;
|
|
248
|
+
};
|
|
249
|
+
return { match: matcher, suffix, prefix, tokens: merged.length + 1 };
|
|
102
250
|
}
|
|
103
|
-
|
|
251
|
+
/** The cap on a `.gitignore` the matcher reads (round 12: a planted 2 MB file cost 1.6 s per path). */
|
|
252
|
+
exports.IGNORE_FILE_CAP = 2 * 1024 * 1024;
|
|
253
|
+
/** The most distinct rules a `.gitignore` may carry before none apply (round 13: bounded work per path). */
|
|
254
|
+
exports.IGNORE_RULES_CAP = 10_000;
|
|
255
|
+
/**
|
|
256
|
+
* The most pattern tokens one path's candidate rules may carry (round 13). The walk is O(tokens × path
|
|
257
|
+
* length) per candidate; a planted file of 10,000 rules sharing one literal cost 25 s over 600 paths
|
|
258
|
+
* (measured). Over the budget the path is treated as NOT ignored — every consumer skips ignored files,
|
|
259
|
+
* so the answer errs toward scanning more, never toward hiding — and the matcher reports it.
|
|
260
|
+
*/
|
|
261
|
+
exports.IGNORE_PATH_TOKENS_BUDGET = 4_000;
|
|
262
|
+
function parseIgnore(content, extraUnsupported = []) {
|
|
104
263
|
const rules = [];
|
|
105
|
-
const unsupported = [];
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
264
|
+
const unsupported = [...extraUnsupported];
|
|
265
|
+
// @implements A-SPEC-733 (round 14) — the cap applies in the parser itself, so every reader is bounded
|
|
266
|
+
// (renumber and entity integration passed their own uncapped text; 14 MB ran one out of memory).
|
|
267
|
+
const size = Buffer.byteLength(content, 'utf8');
|
|
268
|
+
if (size > exports.IGNORE_FILE_CAP) {
|
|
269
|
+
unsupported.push(`.gitignore is ${size.toLocaleString('en-US')} bytes, over the ${exports.IGNORE_FILE_CAP.toLocaleString('en-US')}-byte (2 MiB) cap — no rule of it is applied`);
|
|
270
|
+
content = '';
|
|
271
|
+
}
|
|
272
|
+
// @implements A-SPEC-733 (round 13) — git's line reading: a BOM before the first line is dropped, a
|
|
273
|
+
// comment starts at column 0, and only one `\r` and trailing SPACES are trimmed (`trimEnd()` also ate a
|
|
274
|
+
// trailing tab, making `build\t` ignore `build/**` that git tracks — the hiding direction, measured).
|
|
275
|
+
const text = content.startsWith('') ? content.slice(1) : content;
|
|
276
|
+
for (const raw of text.split('\n')) {
|
|
277
|
+
let line = raw.endsWith('\r') ? raw.slice(0, -1) : raw;
|
|
278
|
+
let cut = line.length;
|
|
279
|
+
while (cut > 0 && line[cut - 1] === ' ')
|
|
280
|
+
cut--;
|
|
281
|
+
line = line.slice(0, cut);
|
|
282
|
+
if (line.trim() === '' || line.startsWith('#'))
|
|
109
283
|
continue;
|
|
110
|
-
if (UNSUPPORTED_RE.test(line) ||
|
|
284
|
+
if (UNSUPPORTED_RE.test(line) || unterminatedClass(line)) {
|
|
111
285
|
unsupported.push(line);
|
|
112
286
|
continue;
|
|
113
287
|
}
|
|
@@ -118,28 +292,213 @@ function parseIgnore(content) {
|
|
|
118
292
|
body = body.slice(0, -1);
|
|
119
293
|
if (body === '')
|
|
120
294
|
continue;
|
|
121
|
-
|
|
295
|
+
let compiled;
|
|
296
|
+
try {
|
|
297
|
+
compiled = compile(body, dirOnly);
|
|
298
|
+
}
|
|
299
|
+
catch {
|
|
300
|
+
unsupported.push(line);
|
|
301
|
+
continue;
|
|
302
|
+
}
|
|
303
|
+
rules.push({ negated, dirOnly, match: compiled.match, suffix: compiled.suffix, prefix: compiled.prefix, tokens: compiled.tokens, source: line });
|
|
122
304
|
}
|
|
305
|
+
// @implements A-SPEC-733 (round 12) — an earlier duplicate of a later identical line never decides (the
|
|
306
|
+
// later one wins over the same paths), so only the LAST occurrence is kept; and rules are indexed by
|
|
307
|
+
// their literal tail within one path segment, so a query touches the rules whose tail its own segments
|
|
308
|
+
// end in (100,000 rules: 387 ms per path, 31.7 s over ci-gate's 600 files — measured).
|
|
309
|
+
const lastOf = new Map();
|
|
310
|
+
rules.forEach((r, i) => lastOf.set(r.source, i));
|
|
311
|
+
let kept = rules.filter((r, i) => lastOf.get(r.source) === i);
|
|
312
|
+
if (kept.length > exports.IGNORE_RULES_CAP) {
|
|
313
|
+
unsupported.push(`.gitignore has ${kept.length.toLocaleString('en-US')} distinct rules, over the ${exports.IGNORE_RULES_CAP.toLocaleString('en-US')} cap — no rule of it is applied`);
|
|
314
|
+
kept = [];
|
|
315
|
+
}
|
|
316
|
+
const trie = { next: new Map(), groups: [], seen: 0 };
|
|
317
|
+
const plain = [];
|
|
318
|
+
const groupOf = new Map();
|
|
319
|
+
const groups = [];
|
|
320
|
+
kept.forEach((r, i) => {
|
|
321
|
+
if (r.suffix === '') {
|
|
322
|
+
plain.push(i);
|
|
323
|
+
return;
|
|
324
|
+
}
|
|
325
|
+
let g = groupOf.get(r.suffix);
|
|
326
|
+
if (g === undefined) {
|
|
327
|
+
g = groups.length;
|
|
328
|
+
groupOf.set(r.suffix, g);
|
|
329
|
+
groups.push({ literal: r.suffix, rules: [] });
|
|
330
|
+
let node = trie;
|
|
331
|
+
// Round 14: at most 16 characters of a literal are indexed (any piece of a required literal is
|
|
332
|
+
// required too) — one node per character cost ~300 bytes, and a 14 MB file ran a reader out of memory.
|
|
333
|
+
for (const ch of r.suffix.slice(0, 16)) {
|
|
334
|
+
let child = node.next.get(ch);
|
|
335
|
+
if (!child) {
|
|
336
|
+
child = { next: new Map(), groups: [], seen: 0 };
|
|
337
|
+
node.next.set(ch, child);
|
|
338
|
+
}
|
|
339
|
+
node = child;
|
|
340
|
+
}
|
|
341
|
+
node.groups.push(g);
|
|
342
|
+
}
|
|
343
|
+
groups[g].rules.push(i);
|
|
344
|
+
});
|
|
345
|
+
const indexed = kept.length > plain.length;
|
|
346
|
+
let reach = new Uint8Array(0);
|
|
347
|
+
let next = new Uint8Array(0);
|
|
348
|
+
let seenMark = new Uint32Array(kept.length);
|
|
349
|
+
let stamp = 0;
|
|
350
|
+
let budgetReported = false;
|
|
351
|
+
const overBudget = () => {
|
|
352
|
+
if (!budgetReported) {
|
|
353
|
+
budgetReported = true;
|
|
354
|
+
unsupported.push(`a path meets more than ${exports.IGNORE_PATH_TOKENS_BUDGET.toLocaleString('en-US')} pattern tokens of candidate rules — such paths are treated as not ignored (scanned)`);
|
|
355
|
+
}
|
|
356
|
+
return false;
|
|
357
|
+
};
|
|
358
|
+
const query = (p) => {
|
|
359
|
+
if (reach.length < p.length + 1) {
|
|
360
|
+
reach = new Uint8Array(p.length + 1);
|
|
361
|
+
next = new Uint8Array(p.length + 1);
|
|
362
|
+
}
|
|
363
|
+
let work = 0;
|
|
364
|
+
// Round 14: only candidates that survive the rooted-prefix dismissal cost tokens (an honest monorepo
|
|
365
|
+
// file of 120 `/packages/pkgN/lib/` pairs tripped the budget — measured).
|
|
366
|
+
// @implements A-SPEC-733 (round 16) — a rule's match costs its tokens times the path length, so the charge
|
|
367
|
+
// scales with it (ten 400-token rules under the flat budget cost 10.6 ms per 1 KB path — measured).
|
|
368
|
+
const lengthFactor = 1 + Math.ceil(p.length / 64);
|
|
369
|
+
const charge = (idx) => {
|
|
370
|
+
const r = kept[idx];
|
|
371
|
+
if (r.prefix !== '' && !p.startsWith(r.prefix))
|
|
372
|
+
return true;
|
|
373
|
+
work += r.tokens * lengthFactor;
|
|
374
|
+
return work <= exports.IGNORE_PATH_TOKENS_BUDGET;
|
|
375
|
+
};
|
|
376
|
+
for (const idx of plain)
|
|
377
|
+
if (!charge(idx))
|
|
378
|
+
return overBudget();
|
|
379
|
+
let candidates = plain;
|
|
380
|
+
if (indexed) {
|
|
381
|
+
if (++stamp === 0xffffffff) {
|
|
382
|
+
seenMark = new Uint32Array(kept.length);
|
|
383
|
+
stamp = 1;
|
|
384
|
+
}
|
|
385
|
+
// Round 15: node stamps share the query stamp; a wrap resets every node once.
|
|
386
|
+
if (stamp === 1) {
|
|
387
|
+
const reset = (n) => { n.seen = 0; for (const c of n.next.values())
|
|
388
|
+
reset(c); };
|
|
389
|
+
reset(trie);
|
|
390
|
+
}
|
|
391
|
+
const checkCost = 1 + Math.ceil(p.length / 64);
|
|
392
|
+
const extra = [];
|
|
393
|
+
for (let s = 0; s < p.length; s++) {
|
|
394
|
+
let node = trie;
|
|
395
|
+
for (let k = s; k < p.length && p[k] !== '/'; k++) {
|
|
396
|
+
node = node.next.get(p[k]);
|
|
397
|
+
if (node === undefined)
|
|
398
|
+
break;
|
|
399
|
+
if (node.groups.length === 0 || node.seen === stamp)
|
|
400
|
+
continue;
|
|
401
|
+
node.seen = stamp;
|
|
402
|
+
for (const g of node.groups) {
|
|
403
|
+
work += checkCost;
|
|
404
|
+
if (work > exports.IGNORE_PATH_TOKENS_BUDGET)
|
|
405
|
+
return overBudget();
|
|
406
|
+
const group = groups[g];
|
|
407
|
+
// A literal holds no `/`, so occurring in the path is occurring within one of its segments.
|
|
408
|
+
if (group.literal.length > 16 && !p.includes(group.literal))
|
|
409
|
+
continue;
|
|
410
|
+
for (const idx of group.rules) {
|
|
411
|
+
if (seenMark[idx] === stamp)
|
|
412
|
+
continue;
|
|
413
|
+
seenMark[idx] = stamp;
|
|
414
|
+
if (!charge(idx))
|
|
415
|
+
return overBudget();
|
|
416
|
+
extra.push(idx);
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
if (extra.length > 0) {
|
|
422
|
+
for (const idx of plain)
|
|
423
|
+
extra.push(idx);
|
|
424
|
+
candidates = extra.sort((a, b) => a - b);
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
// LAST match wins, which is what makes negation work: `*.log` then `!keep.log` re-includes.
|
|
428
|
+
// Round 12: last-to-first with early exit; a rooted literal head is dismissed by a string compare.
|
|
429
|
+
for (let k = candidates.length - 1; k >= 0; k--) {
|
|
430
|
+
const r = kept[candidates[k]];
|
|
431
|
+
if (r.prefix !== '' && !p.startsWith(r.prefix))
|
|
432
|
+
continue;
|
|
433
|
+
if (r.match(p, reach, next))
|
|
434
|
+
return !r.negated;
|
|
435
|
+
}
|
|
436
|
+
return false;
|
|
437
|
+
};
|
|
123
438
|
return {
|
|
124
439
|
isIgnored(relPath) {
|
|
125
|
-
const
|
|
126
|
-
|
|
127
|
-
//
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
440
|
+
const raw = relPath.replace(/\\/g, '/').replace(/^\.\//, '');
|
|
441
|
+
// @implements A-SPEC-733 (round 15) — on macOS, ignored only when BOTH the given and the NFC spelling are:
|
|
442
|
+
// git precomposes the path only under `core.precomposeunicode = true` (written by `git init` on macOS, absent
|
|
443
|
+
// in a repository made elsewhere), and either reading alone ignored paths git did not (measured).
|
|
444
|
+
if (process.platform === 'darwin') {
|
|
445
|
+
const nfc = raw.normalize('NFC');
|
|
446
|
+
if (nfc !== raw)
|
|
447
|
+
return query(raw) && query(nfc);
|
|
448
|
+
}
|
|
449
|
+
return query(raw);
|
|
132
450
|
},
|
|
133
451
|
unsupportedPatterns: () => [...unsupported],
|
|
134
452
|
limitations: () => [...LIMITATIONS],
|
|
135
453
|
};
|
|
136
454
|
}
|
|
137
|
-
/**
|
|
455
|
+
/**
|
|
456
|
+
* Load the project-root `.gitignore`. A missing file ignores nothing.
|
|
457
|
+
* @implements A-SPEC-733 (round 12) — a non-blocking read of a REGULAR file at most 2 MB: a FIFO named
|
|
458
|
+
* `.gitignore` blocked every act that loads the file forever (measured); over the cap the file yields no
|
|
459
|
+
* rules and `unsupportedPatterns` names the size — toward scanning more, never less.
|
|
460
|
+
*/
|
|
138
461
|
function loadIgnore(root) {
|
|
462
|
+
const read = readIgnoreFileSafely(root);
|
|
463
|
+
if (read.bytes === null)
|
|
464
|
+
return parseIgnore('', read.reason.startsWith('.gitignore is ') ? [read.reason] : []);
|
|
465
|
+
return parseIgnore(read.bytes.toString('utf8'));
|
|
466
|
+
}
|
|
467
|
+
/**
|
|
468
|
+
* @implements A-SPEC-733 (round 12) / A-SPEC-734 (round 10) — the project-root `.gitignore` read
|
|
469
|
+
* non-blocking, as a REGULAR file, at most 2 MiB: a FIFO there blocked every reader forever (measured,
|
|
470
|
+
* `loadIgnore` and `planSourceRenumber`). `bytes` is null with a reason: `missing`, `not a regular
|
|
471
|
+
* file`, `unreadable`, or the size refusal.
|
|
472
|
+
*/
|
|
473
|
+
function readIgnoreFileSafely(root) {
|
|
474
|
+
const file = path.join(root, '.gitignore');
|
|
475
|
+
let fd = -1;
|
|
139
476
|
try {
|
|
140
|
-
|
|
477
|
+
fd = fs.openSync(file, fs.constants.O_RDONLY | (fs.constants.O_NONBLOCK ?? 0));
|
|
478
|
+
const st = fs.fstatSync(fd);
|
|
479
|
+
if (!st.isFile())
|
|
480
|
+
return { bytes: null, reason: 'not a regular file' };
|
|
481
|
+
if (st.size > exports.IGNORE_FILE_CAP)
|
|
482
|
+
return { bytes: null, reason: `.gitignore is ${st.size.toLocaleString('en-US')} bytes, over the ${exports.IGNORE_FILE_CAP.toLocaleString('en-US')}-byte (2 MiB) cap — no rule of it is applied` };
|
|
483
|
+
const buf = Buffer.alloc(st.size);
|
|
484
|
+
let off = 0;
|
|
485
|
+
while (off < st.size) {
|
|
486
|
+
const n = fs.readSync(fd, buf, off, st.size - off, off);
|
|
487
|
+
if (n <= 0)
|
|
488
|
+
break;
|
|
489
|
+
off += n;
|
|
490
|
+
}
|
|
491
|
+
return { bytes: buf.subarray(0, off), reason: '' };
|
|
141
492
|
}
|
|
142
|
-
catch {
|
|
143
|
-
return
|
|
493
|
+
catch (e) {
|
|
494
|
+
return { bytes: null, reason: e.code === 'ENOENT' ? 'missing' : 'unreadable' };
|
|
495
|
+
}
|
|
496
|
+
finally {
|
|
497
|
+
if (fd >= 0) {
|
|
498
|
+
try {
|
|
499
|
+
fs.closeSync(fd);
|
|
500
|
+
}
|
|
501
|
+
catch { /* closed */ }
|
|
502
|
+
}
|
|
144
503
|
}
|
|
145
504
|
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/** Whether the guard is installed in this thread. */
|
|
2
|
+
export declare function regularFileGuardInstalled(): boolean;
|
|
3
|
+
/** Install the guard for this thread (idempotent). */
|
|
4
|
+
export declare function installRegularFileGuard(): void;
|
|
5
|
+
/** Test seam: restore the real functions. */
|
|
6
|
+
export declare function uninstallRegularFileGuard(): void;
|
|
7
|
+
/**
|
|
8
|
+
* @implements A-SPEC-734 (round 17) — what every product process does at start: the regular-file guard, and the
|
|
9
|
+
* removal of the variables that relocate the repository a git child reads (`GIT_DIR` and the rest of
|
|
10
|
+
* `REPO_LOCATING_GIT_VARS`). Round 16 dropped them at the call sites it knew; the scanner's nesting queries kept an
|
|
11
|
+
* exported `GIT_DIR` and listed a registered worktree's files (measured). One list of entries, one decision.
|
|
12
|
+
*/
|
|
13
|
+
export declare function installProcessGuards(): void;
|