@holmes-lab/holmes-kit 0.30.0 → 0.31.1
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 +505 -0
- package/README.md +10 -1
- 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.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 +35 -0
- package/dist/holmes/cli/codex-toml.js +321 -52
- package/dist/holmes/cli/doctor.d.ts +98 -8
- package/dist/holmes/cli/doctor.js +1328 -94
- package/dist/holmes/cli/index.js +26 -11
- package/dist/holmes/cli/init.d.ts +11 -0
- package/dist/holmes/cli/init.js +736 -44
- 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 +18 -0
- package/dist/holmes/cli/upgrade.js +129 -24
- package/dist/holmes/cli/workspace-scope.d.ts +22 -0
- package/dist/holmes/cli/workspace-scope.js +375 -0
- 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/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.js +3 -1
- package/dist/holmes/hooks/rtm-refresh.js +8 -4
- 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-commit.d.ts +5 -6
- package/dist/holmes/mcp/approval-commit.js +18 -2
- package/dist/holmes/mcp/elicit-approval.js +4 -2
- package/dist/holmes/mcp/handlers/graph-operations.js +3 -2
- 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.js +5 -3
- package/dist/holmes/mcp/handlers/review-evidence.js +8 -2
- package/dist/holmes/mcp/handlers/slice-orchestration.d.ts +11 -0
- package/dist/holmes/mcp/handlers/slice-orchestration.js +115 -16
- package/dist/holmes/mcp/handlers/spec-approval.d.ts +9 -0
- package/dist/holmes/mcp/handlers/spec-approval.js +110 -17
- package/dist/holmes/mcp/handlers/spec-authoring.js +17 -2
- 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 +81 -9
- package/dist/holmes/mcp/handlers.js +70 -23
- package/dist/holmes/mcp/harness-attestation.d.ts +20 -0
- package/dist/holmes/mcp/harness-attestation.js +179 -0
- package/dist/holmes/mcp/requirement-triage-evidence.d.ts +36 -0
- package/dist/holmes/mcp/requirement-triage-evidence.js +160 -4
- package/dist/holmes/mcp/server.js +20 -1
- package/dist/holmes/mcp/tool-schemas.js +26 -9
- 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/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.js +3 -2
- 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/run-replay.js +3 -2
- package/dist/holmes/review/temporal-prior.js +3 -2
- package/dist/holmes/review/test-evidence.js +3 -2
- package/dist/holmes/review/test-outcomes.js +3 -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.d.ts +5 -0
- package/dist/holmes/update/refresh.js +26 -1
- package/dist/holmes/update/update-notice.d.ts +6 -0
- package/dist/holmes/update/update-notice.js +18 -1
- package/dist/holmes/update/upgrade-plan.d.ts +28 -0
- package/dist/holmes/update/upgrade-plan.js +31 -2
- package/package.json +11 -4
|
@@ -1,8 +1,45 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
2
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CELL_VERDICTS = exports.OS_CELLS = exports.HARNESS_CELLS = void 0;
|
|
36
|
+
exports.FileTooLargeError = exports.CELL_VERDICTS = exports.OS_CELLS = exports.HARNESS_CELLS = void 0;
|
|
37
|
+
exports.osSignalOf = osSignalOf;
|
|
4
38
|
exports.filesToTouch = filesToTouch;
|
|
39
|
+
exports.normalizePosixPath = normalizePosixPath;
|
|
5
40
|
exports.checkCompatDeclared = checkCompatDeclared;
|
|
41
|
+
const path = __importStar(require("node:path"));
|
|
42
|
+
const scope_judgment_1 = require("../guardrail/scope-judgment");
|
|
6
43
|
/**
|
|
7
44
|
* REQ-565's enforcement device: the obligation to declare HARNESS (claude/codex/agy) and OS
|
|
8
45
|
* (windows/mac/linux) impact lives on the ACT of approval — the exact shape ADR-013 gave
|
|
@@ -23,6 +60,20 @@ exports.checkCompatDeclared = checkCompatDeclared;
|
|
|
23
60
|
exports.HARNESS_CELLS = ['claude', 'codex', 'agy'];
|
|
24
61
|
exports.OS_CELLS = ['windows', 'mac', 'linux'];
|
|
25
62
|
exports.CELL_VERDICTS = ['supported', 'unavailable', 'n-a'];
|
|
63
|
+
/**
|
|
64
|
+
* @implements A-SPEC-733 (round 5) — thrown by a reader for a file too large to judge. The OS check
|
|
65
|
+
* refuses on it ("never by skipping"); any other reader error still reads as unreadable.
|
|
66
|
+
*/
|
|
67
|
+
class FileTooLargeError extends Error {
|
|
68
|
+
rel;
|
|
69
|
+
size;
|
|
70
|
+
constructor(rel, size) {
|
|
71
|
+
super(`${rel} is ${size} bytes`);
|
|
72
|
+
this.rel = rel;
|
|
73
|
+
this.size = size;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
exports.FileTooLargeError = FileTooLargeError;
|
|
26
77
|
/** Directory-or-file prefixes that ARE the harness surface. A trailing '/' is a directory boundary;
|
|
27
78
|
* without it the rule names a file stem (`cli/init` catches `cli/init.ts`), and the boundary test
|
|
28
79
|
* below keeps `hooks-util.ts` from matching `hooks/`. */
|
|
@@ -32,10 +83,505 @@ const HARNESS_SURFACES = [
|
|
|
32
83
|
'src/holmes/cli/agents',
|
|
33
84
|
'src/holmes/cli/interactive-prompt',
|
|
34
85
|
'src/holmes/mcp/server',
|
|
86
|
+
// A-SPEC-733 (round 2): this package's launchers and hook scripts.
|
|
87
|
+
'bin/',
|
|
88
|
+
// A-SPEC-733 (round 3): Codex wiring readers, the doctor, shipped guidance and the MCP wiring.
|
|
89
|
+
'src/holmes/cli/codex-hooks',
|
|
90
|
+
'src/holmes/cli/codex-toml',
|
|
91
|
+
'src/holmes/cli/doctor',
|
|
92
|
+
'src/holmes/cli/agents-guidance',
|
|
93
|
+
'playbooks/',
|
|
94
|
+
'.mcp.json',
|
|
95
|
+
// A-SPEC-733 (round 11): the project's Codex, Claude and Antigravity wiring, the shipped skill copies
|
|
96
|
+
// and the harness guidance files (ADR-018 parity: `.codex/config.toml` is the Codex twin of `.mcp.json`).
|
|
97
|
+
'.codex/',
|
|
98
|
+
'.claude/settings',
|
|
99
|
+
'.claude/hooks/',
|
|
100
|
+
'.claude/skills/',
|
|
101
|
+
'.agents/',
|
|
102
|
+
'AGENTS.md',
|
|
103
|
+
'CLAUDE.md',
|
|
104
|
+
'GEMINI.md',
|
|
105
|
+
// A-SPEC-733 (round 12): the Claude plugin marketplace, the Codex plugin dir, agents/commands, Gemini
|
|
106
|
+
// settings, and the modules that render guidance, install skills, upgrade and ask the Codex oracle.
|
|
107
|
+
'.claude-plugin/',
|
|
108
|
+
'.holmes/',
|
|
109
|
+
'.claude/agents/',
|
|
110
|
+
'.claude/commands/',
|
|
111
|
+
'.gemini/',
|
|
112
|
+
'src/holmes/cli/codex-oracle',
|
|
113
|
+
'src/holmes/cli/agents-guidance-plan',
|
|
114
|
+
'src/holmes/cli/playbook-skills',
|
|
115
|
+
'src/holmes/cli/upgrade',
|
|
35
116
|
];
|
|
36
117
|
/** Conservative OS-sensitivity signals — content properties, not directories. Grown by measurement,
|
|
37
118
|
* never by guess (the goal records this as an explicitly open list). */
|
|
38
|
-
|
|
119
|
+
// @implements A-SPEC-733 — by language and by SHAPE: a raw `spawn(` substring read Python asyncio's
|
|
120
|
+
// `loop.spawn(` and any `respawn(` as process creation (external-session report, 2026-09-24).
|
|
121
|
+
const JS_EXT = /\.(?:[cm]?[jt]sx?|mts|cts)$/i;
|
|
122
|
+
const QUOTED_WIN32 = /(['"`])win32\1/;
|
|
123
|
+
const COMMON = [[/\.ps1\b/i, '.ps1'], [QUOTED_WIN32, "'win32'"]];
|
|
124
|
+
const JS_SIGNALS = [[/\bprocess\.(?:platform|arch)\b/, 'process.platform'], ...COMMON,
|
|
125
|
+
// A-SPEC-733 (round 2) — measured false negatives. Round 11: `os.type|platform|release|arch` are CALLS
|
|
126
|
+
// (`parseUA(ua).os; os.type` was a signal), and `path.posix` is not a signal (the spec names sep|delimiter|win32).
|
|
127
|
+
[/\bos\.EOL\b|\bos\.(?:type|platform|release|arch)\s*\(/, 'os.EOL/os.platform()'], [/\bpath\.(?:sep|delimiter|win32)\b/, 'path.sep']];
|
|
128
|
+
// A-SPEC-733 (round 11) — a process library's import IS the signal (its only purpose), `require('os').x()`,
|
|
129
|
+
// POSIX signals (`process.kill`, `process.on('SIG…')` — Windows has neither).
|
|
130
|
+
JS_SIGNALS.push([/(?:\bfrom\s*|\brequire\s*\(\s*|\bimport\s*\(\s*)['"](?:shelljs|zx|execa|cross-spawn)['"]/, 'process library import'], [/\brequire\s*\(\s*['"](?:node:)?os['"]\s*\)\s*\.\s*(?:platform|type|release|arch|EOL|userInfo)\b/, "require('os').platform"], [/\bprocess\.kill\s*\(/, 'process.kill('], [/\bprocess\.on\s*\(\s*['"]SIG/, "process.on('SIG…')"],
|
|
131
|
+
// Round 12 (measured misses): platform environment variables, POSIX ids, Deno's build target, os.userInfo.
|
|
132
|
+
[/\bprocess\.env\.(?:APPDATA|LOCALAPPDATA|XDG_\w+)\b|\bprocess\.env\[\s*['"](?:APPDATA|LOCALAPPDATA|XDG_\w+)['"]\s*\]/, 'process.env.APPDATA/XDG_*'], [/\bprocess\.(?:getuid|geteuid|getgid|getegid)\s*\(/, 'process.getuid('], [/\bDeno\.build\.os\b/, 'Deno.build.os'],
|
|
133
|
+
// Round 13: `userInfo()` only on an `os` binding (`os.userInfo(`, or a name `jsOsBareSignal` binds) —
|
|
134
|
+
// an application's own `userInfo()` was a signal (measured).
|
|
135
|
+
[/\bos\.userInfo\s*\(/, 'os.userInfo()']);
|
|
136
|
+
// A-SPEC-733 (round 3) — runtimes and wrappers that are process or permission handling on their own.
|
|
137
|
+
// A-SPEC-733 (round 9) — measured misses: the environment's OS variables, a bracketed `platform`, `darwin`.
|
|
138
|
+
JS_SIGNALS.push([/\bprocess\.env\.(?:OS|USERPROFILE|HOMEDRIVE|HOMEPATH|SystemRoot|SYSTEMROOT|COMSPEC|ComSpec|PATHEXT)\b/, 'process.env.OS'], [/\bprocess\[\s*["']platform["']\s*\]/, 'process["platform"]'], [/(['"`])darwin\1/, "'darwin'"]);
|
|
139
|
+
/**
|
|
140
|
+
* `platform()`/`type()`/`release()` called bare are the `os` module's only where an import or a
|
|
141
|
+
* destructured require BINDS them (round 10: a quoted `os` anywhere plus a mutex `release()` was a signal).
|
|
142
|
+
*/
|
|
143
|
+
/**
|
|
144
|
+
* @implements A-SPEC-733 (round 13) — every destructuring import/require in ONE linear pass: the last `{`
|
|
145
|
+
* before each `}` (at most 4,000 characters apart), the text before it read in a 40-character window and
|
|
146
|
+
* the text after it by sticky patterns. The bounded negated class `\{([^}]{0,4000})\}` restarted at every
|
|
147
|
+
* `import {` (2 MB of `import {`: 12.1 s in the approval act — measured).
|
|
148
|
+
*/
|
|
149
|
+
function destructuredBindings(code) {
|
|
150
|
+
const out = [];
|
|
151
|
+
const FROM = /\s{0,200}from\s{0,200}['"]([^'"\n]{1,200})['"]/y;
|
|
152
|
+
const REQ = /\s{0,200}=\s{0,200}(?:require\s*\(|(?:await\s+)?import\s*\()\s{0,200}['"]([^'"\n]{1,200})['"]/y;
|
|
153
|
+
let open = -1;
|
|
154
|
+
for (let i = 0; i < code.length; i++) {
|
|
155
|
+
const c = code[i];
|
|
156
|
+
if (c === '{') {
|
|
157
|
+
open = i;
|
|
158
|
+
continue;
|
|
159
|
+
}
|
|
160
|
+
if (c !== '}' || open < 0)
|
|
161
|
+
continue;
|
|
162
|
+
const start = open;
|
|
163
|
+
open = -1;
|
|
164
|
+
if (i - start > 4000)
|
|
165
|
+
continue;
|
|
166
|
+
const before = code.slice(Math.max(0, start - 40), start);
|
|
167
|
+
const isImport = /\bimport\s*$/.test(before);
|
|
168
|
+
const isDecl = !isImport && /\b(?:const|let|var)\s*$/.test(before);
|
|
169
|
+
if (!isImport && !isDecl)
|
|
170
|
+
continue;
|
|
171
|
+
const re = isImport ? FROM : REQ;
|
|
172
|
+
re.lastIndex = i + 1;
|
|
173
|
+
const m = re.exec(code);
|
|
174
|
+
if (m)
|
|
175
|
+
out.push({ list: code.slice(start + 1, i), kind: isImport ? 'import' : 'require', module: m[1].replace(/^node:/, '') });
|
|
176
|
+
}
|
|
177
|
+
return out;
|
|
178
|
+
}
|
|
179
|
+
function jsOsBareSignal(code) {
|
|
180
|
+
const out = [];
|
|
181
|
+
const names = new Set();
|
|
182
|
+
const bind = (list, wanted) => {
|
|
183
|
+
let hit = false;
|
|
184
|
+
for (const item of list.split(',')) {
|
|
185
|
+
const m = /^\s*(\w+)(?:\s+as\s+(\w+)|\s*:\s*(\w+))?\s*$/.exec(item);
|
|
186
|
+
if (!m)
|
|
187
|
+
continue;
|
|
188
|
+
const imported = m[1];
|
|
189
|
+
const local = m[2] ?? m[3] ?? imported;
|
|
190
|
+
if (wanted.test(imported)) {
|
|
191
|
+
hit = true;
|
|
192
|
+
if (/^(?:platform|type|release|userInfo)$/.test(imported))
|
|
193
|
+
names.add(local);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
return hit;
|
|
197
|
+
};
|
|
198
|
+
// Round 11: the class allows newlines (a prettier-style multi-line import was no signal), and the
|
|
199
|
+
// IMPORT itself is the signal for `os` `EOL|platform|type|release|arch`, `path` `sep|delimiter|win32`,
|
|
200
|
+
// `process` `platform|arch` and `fs` `chmod|chown|symlink…` — measured misses, each an OS branch by name.
|
|
201
|
+
const MODULES = [
|
|
202
|
+
['os', /^(?:EOL|platform|type|release|arch|userInfo)$/, 'os import (platform/EOL)'],
|
|
203
|
+
['path', /^(?:sep|delimiter|win32)$/, 'path import (sep)'],
|
|
204
|
+
['process', /^(?:platform|arch)$/, 'process import (platform)'],
|
|
205
|
+
['fs', /^(?:chmod|chmodSync|chown|chownSync|lchown|lchownSync|lchmod|lchmodSync|symlink|symlinkSync)$/, 'fs import (chmod/symlink)'],
|
|
206
|
+
['fs/promises', /^(?:chmod|chown|lchown|lchmod|symlink)$/, 'fs/promises import (chmod/symlink)'],
|
|
207
|
+
];
|
|
208
|
+
// Round 12: a 4,000-character reach (a 500-character one hid `chmodSync` behind 35 names); round 13:
|
|
209
|
+
// found by the linear brace-pair pass.
|
|
210
|
+
const bindings = destructuredBindings(code);
|
|
211
|
+
for (const [mod, wanted, label] of MODULES) {
|
|
212
|
+
let bound = false;
|
|
213
|
+
for (const b of bindings)
|
|
214
|
+
if (b.module === mod && bind(b.list, wanted))
|
|
215
|
+
bound = true;
|
|
216
|
+
if (bound)
|
|
217
|
+
out.push([new RegExp(String.raw `\}\s*(?:from\s*|=\s*require\(\s*)['"](?:node:)?` + mod.replace('/', '\\/') + String.raw `['"]`), label]);
|
|
218
|
+
}
|
|
219
|
+
if (names.size > 0)
|
|
220
|
+
out.push([new RegExp(`(?<![\\w.$])(?:${[...names].join('|')})\\s*\\(\\s*\\)`), 'os.platform()']);
|
|
221
|
+
// @implements A-SPEC-733 (round 14) — a NAMESPACE binding of `os` (`import * as nodeOs from 'os'`,
|
|
222
|
+
// `const nodeOs = require('os')`) calling an OS function (round 13 dropped `nodeOs.userInfo()` — measured).
|
|
223
|
+
const nsNames = new Set();
|
|
224
|
+
for (const m of code.matchAll(/\bimport\s+\*\s+as\s+([\w$]+)\s+from\s*['"](?:node:)?os['"]/g))
|
|
225
|
+
nsNames.add(m[1]);
|
|
226
|
+
for (const m of code.matchAll(/\b(?:const|let|var)\s+([\w$]+)\s*=\s*require\(\s*['"](?:node:)?os['"]\s*\)/g))
|
|
227
|
+
nsNames.add(m[1]);
|
|
228
|
+
nsNames.delete('os'); // `os.…` has its own signals
|
|
229
|
+
if (nsNames.size > 0)
|
|
230
|
+
out.push([new RegExp(`(?<![\\w.$])(?:${[...nsNames].map((n) => n.replace(/\$/g, '\\$')).join('|')})\\s*\\.\\s*(?:userInfo|platform|type|release|arch)\\s*\\(`), 'os.platform()']);
|
|
231
|
+
return out;
|
|
232
|
+
}
|
|
233
|
+
JS_SIGNALS.push([/\bBun\.spawn(?:Sync)?\s*\(/, 'Bun.spawn('], [/\bDeno\.(?:Command|run)\b/, 'Deno.Command'], [/\b(?:fs|fsp|promises)\.(?:symlink|chmod|chown|lchown|lchmod)(?:Sync)?\s*\(/, 'fs.chmod/symlink'], [/\bpromisify\(\s*(?:\w+\.)?(?:exec|execFile|spawn)\b/, 'promisify(exec)']);
|
|
234
|
+
const JS_PROCESS_FNS = 'spawn|spawnSync|exec|execSync|execFile|execFileSync|fork|execa|execaSync|execaCommand';
|
|
235
|
+
/**
|
|
236
|
+
* @implements A-SPEC-733 (round 4) — a process call is a bare call, or a method call on a name the
|
|
237
|
+
* file bound to `child_process` (or on `require(…)` directly). A method on anything else is not one:
|
|
238
|
+
* `/^(..) (.+)$/.exec(line)` in a file that imports child_process read as process creation (measured
|
|
239
|
+
* on scripts/verify-release.js).
|
|
240
|
+
*/
|
|
241
|
+
function jsProcessCall(text) {
|
|
242
|
+
// @implements A-SPEC-733 (round 5) — every way a file binds child_process (measured misses: default
|
|
243
|
+
// import, `import x = require`, `await import`, renamed imports and destructures, a bound function,
|
|
244
|
+
// bracket calls). Bounded `{0,2000}` keeps each pattern linear per occurrence.
|
|
245
|
+
// Round 11: `shelljs`, `zx`, `execa` and `cross-spawn` bind like child_process (round 2 promised shelljs;
|
|
246
|
+
// the round-4 binding rule defeated `shell.exec(` — measured).
|
|
247
|
+
const CP = String.raw `\s*['"](?:(?:node:)?child_process|shelljs|zx|execa|cross-spawn)['"]`;
|
|
248
|
+
const ns = new Set(), fns = new Set();
|
|
249
|
+
const each = (re, f) => { for (const m of text.matchAll(re))
|
|
250
|
+
f(m); };
|
|
251
|
+
each(new RegExp(String.raw `import\s+\*\s+as\s+([\w$]+)\s+from` + CP, 'g'), (m) => ns.add(m[1]));
|
|
252
|
+
each(new RegExp(String.raw `import\s+([\w$]+)\s+from` + CP, 'g'), (m) => ns.add(m[1]));
|
|
253
|
+
each(new RegExp(String.raw `import\s+([\w$]+)\s*=\s*require\s*\(` + CP, 'g'), (m) => ns.add(m[1]));
|
|
254
|
+
each(new RegExp(String.raw `(?:const|let|var)\s+([\w$]+)\s*=\s*require\s*\(` + CP + String.raw `\s*\)(?!\s*\.)`, 'g'), (m) => ns.add(m[1]));
|
|
255
|
+
each(new RegExp(String.raw `(?:const|let|var)\s+([\w$]+)\s*=\s*(?:await\s+)?import\s*\(` + CP, 'g'), (m) => ns.add(m[1]));
|
|
256
|
+
each(new RegExp(String.raw `(?:const|let|var)\s+([\w$]+)\s*=\s*require\s*\(` + CP + String.raw `\s*\)\s*\.\s*(?:` + JS_PROCESS_FNS + String.raw `)\b`, 'g'), (m) => fns.add(m[1]));
|
|
257
|
+
// Round 13: destructured bindings from the linear brace-pair pass (the bounded class restarted at every `{`).
|
|
258
|
+
for (const b of destructuredBindings(text)) {
|
|
259
|
+
if (!/^(?:child_process|shelljs|zx|execa|cross-spawn)$/.test(b.module))
|
|
260
|
+
continue;
|
|
261
|
+
for (const part of b.list.split(',')) {
|
|
262
|
+
const a = b.kind === 'import' ? /\bas\s+([\w$]+)/.exec(part) : /:\s*([\w$]+)/.exec(part);
|
|
263
|
+
if (a)
|
|
264
|
+
fns.add(a[1]);
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
const esc = (a) => a.replace(/\$/g, '\\$');
|
|
268
|
+
const bare = [JS_PROCESS_FNS, ...[...fns].map(esc)].join('|');
|
|
269
|
+
const nsAlt = [...ns].map(esc).join('|');
|
|
270
|
+
// Round 11: a tagged-template call (`execSync\`ls\``) is a call.
|
|
271
|
+
const parts = [String.raw `(?<![\w$.])(?:` + bare + String.raw `)\s*[(\x60]`, String.raw `\)\s*\.\s*(?:` + JS_PROCESS_FNS + String.raw `)\s*\(`];
|
|
272
|
+
if (nsAlt) {
|
|
273
|
+
parts.push(String.raw `(?<![\w$.])(?:` + nsAlt + String.raw `)\s*\.\s*(?:` + JS_PROCESS_FNS + String.raw `)\s*[(\x60]`);
|
|
274
|
+
parts.push(String.raw `(?<![\w$.])(?:` + nsAlt + String.raw `)\s*\[\s*['"](?:` + JS_PROCESS_FNS + String.raw `)['"]\s*\]\s*\(`);
|
|
275
|
+
}
|
|
276
|
+
return [new RegExp(parts.join('|')), 'child_process call'];
|
|
277
|
+
}
|
|
278
|
+
/** Process libraries whose presence makes a `spawn(`/`exec(` call a process call (not only child_process). */
|
|
279
|
+
const JS_PROCESS_LIBS = /child_process|['"](?:execa|cross-spawn|shelljs|zx)['"/]/;
|
|
280
|
+
const PY_SIGNALS = [[/\bsubprocess\b/, 'subprocess'], [/\bos\.system\s*\(/, 'os.system('], [/\bos\.startfile\s*\(/, 'os.startfile('],
|
|
281
|
+
[/\bsys\.platform\b/, 'sys.platform'], [/\bos\.name\b/, 'os.name'], [/\.ps1\b/i, '.ps1'],
|
|
282
|
+
// Round 11 (measured misses): process creation and identity, platform-only modules, ctypes.windll, pathlib flavours.
|
|
283
|
+
[/\bos\.(?:popen|fork|forkpty|execl|execle|execlp|execlpe|execv|execve|execvp|execvpe|spawnl|spawnle|spawnlp|spawnlpe|spawnv|spawnve|spawnvp|spawnvpe|posix_spawn|posix_spawnp|getuid|geteuid|getgid|getegid|kill|killpg)\s*\(/, 'os.popen/fork/exec('],
|
|
284
|
+
[/^\s*(?:import|from)\s+(?:fcntl|winreg|msvcrt|pty|termios|resource|_winapi)\b/, 'import fcntl/winreg'], [/\bctypes\.windll\b/, 'ctypes.windll'],
|
|
285
|
+
[/\bpathlib\.(?:WindowsPath|PosixPath)\b|(?<![\w.])(?:WindowsPath|PosixPath)\s*\(/, 'pathlib.WindowsPath'],
|
|
286
|
+
// Round 12 (measured misses).
|
|
287
|
+
[/\bsys\.getwindowsversion\b|\bos\.(?:symlink|mkfifo|setsid|add_dll_directory|link|mknod|chroot)\s*\(|\bos\.O_BINARY\b/, 'os.symlink/sys.getwindowsversion'],
|
|
288
|
+
[/^\s*(?:import|from)\s+(?:grp|pwd|posix|nt)\b/, 'import grp/pwd'], [/^\s*from\s+ctypes\s+import\b[^\n]*\bwindll\b/, 'from ctypes import windll'],
|
|
289
|
+
[/\bos\.environ(?:\.get\s*\(\s*|\s*\[\s*)['"](?:APPDATA|LOCALAPPDATA|USERPROFILE|XDG_\w+|HOMEDRIVE|HOMEPATH|SystemRoot|COMSPEC)['"]/, 'os.environ APPDATA/XDG_*'],
|
|
290
|
+
[/\bos\.(?:sep|linesep|pathsep|altsep|uname|chmod|chown)\b/, 'os.sep'], [/\bshutil\.which\b/, 'shutil.which'], [/\bPure(?:Windows|Posix)Path\b/, 'PureWindowsPath'],
|
|
291
|
+
// Round 9: `os.path.sep`/`altsep`, and `platform` imported from `sys` by name.
|
|
292
|
+
[/\bos\.path\.(?:sep|altsep)\b/, 'os.path.sep'], [/^\s*from\s+sys\s+import\b[^\n]*\bplatform\b/, 'from sys import platform']];
|
|
293
|
+
/** Round 11: `platform.<fn>(` only where the file binds the `platform` module (a Django `Platform` instance was a signal). */
|
|
294
|
+
function pyPlatformSignal(code) {
|
|
295
|
+
// Round 12: `import a, platform, b`, `import platform as p` and `from platform import system` bind too.
|
|
296
|
+
const ns = new Set();
|
|
297
|
+
const fns = new Set();
|
|
298
|
+
// `[ \t]*`, never `\s*`, at a multi-line anchor: `\s*` ran across a 2 MB run of blanked lines from every
|
|
299
|
+
// line start (1.2 s in the approval act — profiled).
|
|
300
|
+
// Round 13: an import statement ends at `;` (`import platform; platform.system()`); round 14: one may
|
|
301
|
+
// also start after `;` (`import os; import platform`).
|
|
302
|
+
for (const m of code.matchAll(/(?:^|;)[ \t]*import[ \t]+([^\n#;]+)/gm)) {
|
|
303
|
+
for (const item of m[1].split(',')) {
|
|
304
|
+
const p = /^\s*platform(?:\s+as\s+(\w+))?\s*$/.exec(item);
|
|
305
|
+
if (p)
|
|
306
|
+
ns.add(p[1] ?? 'platform');
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
// Round 13: a parenthesised list may span lines; round 14: found by index (a bounded `\([^)]{0,4000}\)`
|
|
310
|
+
// restarted at every line — 15 such files in one approval act took 14.1 s, measured).
|
|
311
|
+
const FROM = /(?:^|;)[ \t]*from[ \t]+platform[ \t]+import[ \t]+/gm;
|
|
312
|
+
// The first `)` at or after a position, memoised: a later start before it shares the answer (each
|
|
313
|
+
// search from scratch was quadratic on unclosed groups — 2 s for 2 MB, measured).
|
|
314
|
+
let lastClose = -2; // -2: not searched yet; -1: none after the last search start
|
|
315
|
+
for (let m = FROM.exec(code); m !== null; m = FROM.exec(code)) {
|
|
316
|
+
const start = m.index + m[0].length;
|
|
317
|
+
let list;
|
|
318
|
+
if (code[start] === '(') {
|
|
319
|
+
if (lastClose === -2 || (lastClose !== -1 && lastClose < start))
|
|
320
|
+
lastClose = code.indexOf(')', start);
|
|
321
|
+
const close = lastClose;
|
|
322
|
+
if (close === -1 || close - start > 4000)
|
|
323
|
+
continue;
|
|
324
|
+
list = code.slice(start + 1, close);
|
|
325
|
+
FROM.lastIndex = close + 1;
|
|
326
|
+
}
|
|
327
|
+
else {
|
|
328
|
+
const end = code.slice(start, start + 4000).search(/[\n#;]/);
|
|
329
|
+
list = code.slice(start, end === -1 ? start + 4000 : start + end);
|
|
330
|
+
}
|
|
331
|
+
for (const item of list.split(',')) {
|
|
332
|
+
const p = /^\s*(\w+)(?:\s+as\s+(\w+))?\s*$/.exec(item);
|
|
333
|
+
if (p && p[1] !== '*')
|
|
334
|
+
fns.add(p[2] ?? p[1]);
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
const out = [];
|
|
338
|
+
if (ns.size > 0)
|
|
339
|
+
out.push([new RegExp(String.raw `(?<![\w.])(?:${[...ns].join('|')})\.\w+\s*\(`), 'platform.<fn>(']);
|
|
340
|
+
if (fns.size > 0)
|
|
341
|
+
out.push([new RegExp(String.raw `(?<![\w.])(?:${[...fns].join('|')})\s*\(`), 'platform function']);
|
|
342
|
+
return out;
|
|
343
|
+
}
|
|
344
|
+
/** Round 11: Rust `Command::new(` only where the file names `std::process` (clap's `Command::new("app")` was a signal). */
|
|
345
|
+
function rsCommandSignal(code) {
|
|
346
|
+
return /\bstd::process\b|\bprocess::Command\b/.test(code) ? [[/\bCommand::new\s*\(/, 'Command::new(']] : [];
|
|
347
|
+
}
|
|
348
|
+
const LANG_SIGNALS = [
|
|
349
|
+
[/\.go$/i, [[/\bruntime\.GOOS\b/, 'runtime.GOOS'], [/\bexec\.Command(?:Context)?\s*\(/, 'exec.Command('], [/"os\/exec"/, '"os/exec"'], [/\bfilepath\.(?:Separator|ListSeparator)\b/, 'filepath.Separator']]],
|
|
350
|
+
[/\.rs$/i, [[/#\[cfg\(\s*(?:not\(\s*)?(?:target_os|target_family|windows|unix)\b/, 'cfg(target_os)'], [/\bcfg!\(\s*(?:target_os|target_family|windows|unix)\b/, 'cfg!('],
|
|
351
|
+
[/\bstd::os::(?:unix|windows|linux)\b/, 'std::os::unix'], [/\blibc::/, 'libc::']]],
|
|
352
|
+
[/\.(?:java|kt|kts|scala)$/i, [[/System\.getProperty\(\s*"os\.name"/, 'os.name'], [/\bProcessBuilder\b/, 'ProcessBuilder'], [/Runtime\.getRuntime\(\)\.exec/, 'Runtime.exec'], [/\bFile\.(?:separator|pathSeparator)\b/, 'File.separator'],
|
|
353
|
+
[/\bSystemUtils\.IS_OS_\w+/, 'SystemUtils.IS_OS_'], [/\bsetPosixFilePermissions\b|\bPosixFilePermission/, 'PosixFilePermissions']]],
|
|
354
|
+
[/\.(?:cs|fs|vb)$/i, [[/\bRuntimeInformation\b/, 'RuntimeInformation'], [/\bOperatingSystem\.Is\w+\s*\(/, 'OperatingSystem.Is…('], [/\bProcess\.Start\s*\(/, 'Process.Start('], [/\bEnvironment\.OSVersion\b/, 'Environment.OSVersion'], [/\bPath\.(?:DirectorySeparatorChar|PathSeparator)\b/, 'Path.DirectorySeparatorChar'],
|
|
355
|
+
[/\[\s*DllImport\s*\(/, '[DllImport('], [/\[\s*SupportedOSPlatform\s*\(/, '[SupportedOSPlatform(']]],
|
|
356
|
+
[/\.(?:sh|bash|zsh|ksh)$/i, [[/\buname\b/, 'uname'], [/\$\{?OSTYPE\b/, '$OSTYPE'], [/\bsw_vers\b/, 'sw_vers'],
|
|
357
|
+
[/\bsed\s+-i\s+''/, "sed -i ''"], [/\breadlink\s+-f\b/, 'readlink -f'], [/(?:^|[\s"'=(])\/proc\//, '/proc/'], [/(?:^|[\s;&|(])(?:brew|apt-get|apt|yum|dnf|pacman)\s/, 'brew/apt-get']]],
|
|
358
|
+
// Round 9: a Dockerfile's RUN lines are shell.
|
|
359
|
+
[/(?:^|\/)(?:Dockerfile|Containerfile)(?:\.[\w.-]+)?$/, [[/\buname\b/, 'uname'], [/\bsw_vers\b/, 'sw_vers']]],
|
|
360
|
+
// A-SPEC-733 (round 3) — bounded `[^…]{0,200}` keeps each pattern linear on a long line.
|
|
361
|
+
[/\.(?:c|h|cc|cpp|cxx|hpp|hh|hxx|m|mm)$/i, [[/^\s*#\s*(?:if|ifdef|ifndef|elif)\b[^\n]{0,200}\b(?:_WIN32|_WIN64|__APPLE__|__MACH__|__linux__|__unix__|_MSC_VER)\b/, '#if _WIN32'],
|
|
362
|
+
// Round 11: bare calls only (`registry.system(0)` was a signal); `std::system(` counted; the include label says what it saw.
|
|
363
|
+
[/^\s*#\s*include\s*<(?:windows|unistd|sys\/\w+)\.h>/, '#include <windows.h>/<unistd.h>/<sys/…>'], [/(?<![\w.>:])(?:system|popen|fork|CreateProcess\w*|execv\w*)\s*\(|\bstd::system\s*\(/, 'system(/popen(']]],
|
|
364
|
+
[/\.swift$/i, [[/^\s*#(?:if|elseif)\b[^\n]{0,200}\bos\(/, '#if os('], [/^\s*import\s+(?:Darwin|Glibc)\b/, 'import Darwin']]],
|
|
365
|
+
// Round 12: ONE `.rb` entry — round 11 added a second ahead of this one and `LANG_SIGNALS.find` shadowed it.
|
|
366
|
+
[/\.rb$/i, [[/\bRUBY_PLATFORM\b/, 'RUBY_PLATFORM'], [/\bGem\.win_platform\?/, 'Gem.win_platform?'],
|
|
367
|
+
[/(?<![\w.:])(?:system|spawn|exec|fork)\s*\(/, 'system('], [/\bProcess\.(?:spawn|kill|fork)\b|\bIO\.popen\b|\bOpen3\b|\bPTY\.spawn\b/, 'Process.spawn'], [/\bRbConfig::CONFIG\b/, 'RbConfig::CONFIG'],
|
|
368
|
+
[/%x[([{|]/, '%x('], [/\bFile::(?:SEPARATOR|ALT_SEPARATOR|PATH_SEPARATOR)\b/, 'File::SEPARATOR'],
|
|
369
|
+
// Round 13: backticks — the most common Ruby shell-out (spec rule 14 named it; it was never added).
|
|
370
|
+
// Round 14: only a backtick OUTSIDE a string literal (648 of 4,425 Homebrew files were refused for
|
|
371
|
+
// backticks inside "…" prose — measured); quoted spans are blanked before the test.
|
|
372
|
+
[/^(?:[^"'`\n]|"(?:[^"\\\n]|\\.)*"|'(?:[^'\\\n]|\\.)*')*`[^`\n]+`/, 'backtick command']]],
|
|
373
|
+
[/(?:^|\/)(?:GNUmakefile|[Mm]akefile)$|\.mk$/, [[/\$\(OS\)|\bWindows_NT\b/, '$(OS)'], [/\buname\b/, 'uname']]],
|
|
374
|
+
];
|
|
375
|
+
// Rust (round 3): cfg(any|all(…)), cfg_attr, and the consts.
|
|
376
|
+
LANG_SIGNALS[1][1].push([/#!?\[cfg(?:_attr)?\([^\]\n]{0,200}\b(?:target_os|target_family|windows|unix)\b/, 'cfg(any(target_os))'], [/\bcfg!\([^)\n]{0,200}\b(?:target_os|target_family|windows|unix)\b/, 'cfg!('], [/\benv::consts::(?:OS|FAMILY)\b/, 'env::consts::OS']);
|
|
377
|
+
// Go (round 3): a build constraint names the platform.
|
|
378
|
+
LANG_SIGNALS[0][1].push([/^\s*\/\/(?:go:build|\s*\+build)\b[^\n]{0,200}\b(?:windows|linux|darwin|unix|freebsd|openbsd|netbsd|plan9|solaris)\b/, '//go:build'], [/\bos\.(?:PathSeparator|PathListSeparator)\b/, 'os.PathSeparator'], // round 9
|
|
379
|
+
[/"syscall"|"golang\.org\/x\/sys\//, '"syscall"'], [/\bos\.Get(?:uid|euid|gid|egid)\s*\(/, 'os.Getuid('], // round 11
|
|
380
|
+
[/\bos\.(?:Chmod|Chown|Lchown|Symlink|Link)\s*\(|\bfilepath\.VolumeName\s*\(/, 'os.Chmod/filepath.VolumeName'], [/\bos\.Getenv\s*\(\s*"(?:USERPROFILE|APPDATA|LOCALAPPDATA|XDG_\w+|HOMEDRIVE|SystemRoot)"/, 'os.Getenv("USERPROFILE")']); // round 12
|
|
381
|
+
// Rust (round 12): the separator constant, the platform crates, the fd module.
|
|
382
|
+
LANG_SIGNALS[1][1].push([/\bMAIN_SEPARATOR(?:_STR)?\b/, 'MAIN_SEPARATOR'], [/\b(?:winapi|windows_sys|windows|nix|libc)::/, 'winapi::/nix::'], [/\bstd::os::fd\b/, 'std::os::fd']);
|
|
383
|
+
// Java/Kotlin (round 12): the line separator, the path separator property, platform environment, JNA.
|
|
384
|
+
LANG_SIGNALS[2][1].push([/\bSystem\.lineSeparator\s*\(/, 'System.lineSeparator()'], [/"path\.separator"|"line\.separator"|"file\.separator"/, '"path.separator"'], [/\bgetenv\s*\(\s*"(?:APPDATA|LOCALAPPDATA|USERPROFILE|XDG_\w+|HOMEDRIVE)"/, 'getenv("APPDATA")'], [/\bPlatform\.is(?:Windows|Mac|Linux)\s*\(/, 'Platform.isWindows()']);
|
|
385
|
+
// C# (round 12).
|
|
386
|
+
LANG_SIGNALS[3][1].push([/\bEnvironment\.NewLine\b/, 'Environment.NewLine'], [/\bSpecialFolder\.\w+/, 'SpecialFolder']);
|
|
387
|
+
// Shell (round 12): desktop and platform tools, BSD/GNU-only flags, the os-release file.
|
|
388
|
+
// Round 13: at a COMMAND position (line start, `;`, `&&`, `||`, `|`, `(`, `$(`, a backtick, `then`/`do`,
|
|
389
|
+
// behind `sudo`/`command`/`exec`) and ending at a blank, `)`, `;`, `|`, `&` or the line end; `open` is not
|
|
390
|
+
// one (`echo "failed to open $f"` refused a build script — measured), and `n=$(nproc)` / `… | pbcopy` count.
|
|
391
|
+
// Round 14: after the compound-command words too (`if`, `elif`, `while`, `until`, `else`, `!`, `nohup`,
|
|
392
|
+
// `time`, `xargs …`, `env VAR=…`, `sudo -E`), and a `case` label (`powershell)` with nothing before it but
|
|
393
|
+
// blanks) is not a command position (measured regressions and one false signal).
|
|
394
|
+
LANG_SIGNALS[4][1].push([/(?:(?:^|[;&|`]|\b(?:then|do|if|elif|while|until|else)\s|!\s)\s*(?:(?:sudo(?:\s+-\w+)*|command|exec|nohup|time|env(?:\s+-\w+|\s+[A-Za-z_]\w*=\S*)*|xargs(?:\s+-\S+)*)\s+)*(?:xdg-open|osascript|nproc|pbcopy|pbpaste|lsb_release|systemctl|launchctl|powershell|pwsh|cmd\.exe|greadlink|gsed|sysctl)(?=\s|$|[;|&`]))|(?:\$\(|\()\s*(?:(?:sudo(?:\s+-\w+)*|command|exec|env(?:\s+[A-Za-z_]\w*=\S*)*)\s+)*(?:xdg-open|osascript|nproc|pbcopy|pbpaste|lsb_release|systemctl|launchctl|powershell|pwsh|cmd\.exe|greadlink|gsed|sysctl)(?=\s|\)|$|[;|&`])/, 'xdg-open/osascript/systemctl'], [/\bstat\s+-f\b|\bdate\s+-v|\bsed\s+-i\s+""|\bmd5\s+-q\b/, "stat -f/date -v/sed -i \"\""], [/(?:^|[\s"'=(])\/etc\/os-release\b/, '/etc/os-release']);
|
|
395
|
+
// C/C++ (round 12): more platform macros, headers and Win32/POSIX-only calls.
|
|
396
|
+
LANG_SIGNALS[6][1].push([/^\s*#\s*(?:if|ifdef|ifndef|elif)\b[^\n]{0,200}\b(?:WIN32|__linux|__ANDROID__|__FreeBSD__|__OpenBSD__|__NetBSD__|TARGET_OS_MAC|TARGET_OS_IPHONE|__CYGWIN__|__MINGW32__|__MINGW64__|_POSIX_VERSION)\b/, '#ifdef WIN32'], [/^\s*#\s*include\s*<(?:pthread|winsock2?|io|dirent|dlfcn|TargetConditionals|sys\/mman|sys\/wait|sys\/socket|mach\/\w+)\.h>/, '#include <pthread.h>'], [/\b(?:LoadLibrary\w*|GetModuleHandle\w*|Sleep|usleep|nanosleep|uname|getuid|geteuid|fchmod|chmod|symlink|readlink|realpath)\s*\(/, 'LoadLibrary(/usleep(/uname('], [/\b(?:MAX_PATH|PATH_MAX)\b|#\s*pragma\s+comment\s*\(\s*lib|\b__declspec\b|\b__attribute__\s*\(\s*\(\s*visibility/, 'MAX_PATH/__declspec']);
|
|
397
|
+
// Swift (round 12).
|
|
398
|
+
LANG_SIGNALS[7][1].push([/\bProcess\s*\(\s*\)/, 'Process()'], [/\bcanImport\s*\(\s*(?:Darwin|Glibc|AppKit|UIKit|WinSDK)\s*\)/, 'canImport(Darwin)'], [/^\s*import\s+(?:AppKit|UIKit|WinSDK|Foundation\.NSTask)\b/, 'import AppKit'], [/\boperatingSystemVersion\b|\bProcessInfo\.processInfo\.(?:environment|hostName)\b/, 'operatingSystemVersion']);
|
|
399
|
+
// Dockerfile (round 12): an explicit platform.
|
|
400
|
+
LANG_SIGNALS[5][1].push([/^\s*FROM\s+--platform=/im, 'FROM --platform=']);
|
|
401
|
+
/** Files whose NAME is the platform (round 3): a Go `_windows.go`, a PowerShell or batch script. */
|
|
402
|
+
const FILE_SIGNALS = [
|
|
403
|
+
[/_(?:windows|linux|darwin|unix|freebsd|openbsd|netbsd|solaris)(?:_\w+)?\.go$/i, 'Go platform file suffix'],
|
|
404
|
+
[/\.(?:ps1|psm1|bat|cmd)$/i, 'platform script file'],
|
|
405
|
+
];
|
|
406
|
+
/** C-like comment syntax (`//`, `/* … *\/`); hash-comment languages. Others keep the line rule. */
|
|
407
|
+
const C_LIKE = /\.(?:[cm]?[jt]sx?|mts|cts|java|kt|kts|scala|cs|fs|go|rs|c|h|cc|cpp|cxx|hpp|hh|hxx|m|mm|swift|dart)$/i;
|
|
408
|
+
const HASH_LANG = /\.(?:pyi?|sh|bash|zsh|ksh|rb|pl|pm|ya?ml|toml|ps1|psm1|r|mk)$|(?:^|\/)(?:GNUmakefile|[Mm]akefile|Dockerfile(?:\.[\w.-]+)?|Containerfile(?:\.[\w.-]+)?)$/i;
|
|
409
|
+
const GO_BUILD_TAG = /^\s*\/\/(?:go:build|\s*\+build)\b/;
|
|
410
|
+
/**
|
|
411
|
+
* @implements A-SPEC-733 (round 3) — the code part of each line, comments removed per language.
|
|
412
|
+
* Round 2 skipped a line whose first character looked like a comment: `#isWin = process.platform`
|
|
413
|
+
* (a JS private field) and `*gen()` were code, and `/* c *\/ if (process.platform…)` hid code after
|
|
414
|
+
* a closed comment (measured). A single pass, linear in the text; quotes are tracked per line.
|
|
415
|
+
*/
|
|
416
|
+
function codeOf(file, rawLines) {
|
|
417
|
+
const cLike = C_LIKE.test(file);
|
|
418
|
+
if (!cLike && !HASH_LANG.test(file))
|
|
419
|
+
return rawLines.map((l) => (COMMENT_ONLY.test(l) ? '' : l));
|
|
420
|
+
const lines = proseBlocksBlanked(file, rawLines);
|
|
421
|
+
// @implements A-SPEC-733 (round 4) — a `/*` inside a regex literal or a multi-line template opened a
|
|
422
|
+
// "block" that hid the rest of the file, and `//` inside `/https?:\/\//` cut the line (measured).
|
|
423
|
+
// A block opens only where `/*` starts the line; mid-line, only a `/* … */` closed on the same line
|
|
424
|
+
// is removed; `//` is a comment only at the start or after whitespace or `;{}(),=`.
|
|
425
|
+
// Round 5 (measured): a `/*` inside a regex paired with a later `*/` on the line; a template line
|
|
426
|
+
// `/*` hid the rest of the file; shell `$#` read as a comment. A `/*` counts only at a word start,
|
|
427
|
+
// a backtick left open carries the template to the next lines, and shell `#` needs a word start.
|
|
428
|
+
const shellLike = /\.(?:sh|bash|zsh|ksh)$/i.test(file);
|
|
429
|
+
const wordStart = (line, i) => i === 0 || /[\s;{}(),=]/.test(line[i - 1]);
|
|
430
|
+
const shellWordStart = (line, i) => i === 0 || /[\s;|&()]/.test(line[i - 1]);
|
|
431
|
+
let inBlock = false;
|
|
432
|
+
let inTemplate = false;
|
|
433
|
+
return lines.map((raw) => {
|
|
434
|
+
let line = raw;
|
|
435
|
+
if (inBlock) {
|
|
436
|
+
const end = line.indexOf('*/');
|
|
437
|
+
if (end === -1)
|
|
438
|
+
return '';
|
|
439
|
+
inBlock = false;
|
|
440
|
+
line = ' ' + line.slice(end + 2);
|
|
441
|
+
}
|
|
442
|
+
if (cLike && !inTemplate && GO_BUILD_TAG.test(line))
|
|
443
|
+
return line; // a build constraint is code
|
|
444
|
+
if (cLike && !inTemplate && /^\s*\/\*/.test(line)) {
|
|
445
|
+
const open = line.indexOf('/*');
|
|
446
|
+
const end = line.indexOf('*/', open + 2);
|
|
447
|
+
if (end === -1) {
|
|
448
|
+
inBlock = true;
|
|
449
|
+
return '';
|
|
450
|
+
}
|
|
451
|
+
line = line.slice(0, open) + ' ' + line.slice(end + 2);
|
|
452
|
+
}
|
|
453
|
+
const lastClose = line.lastIndexOf('*/');
|
|
454
|
+
let out = '';
|
|
455
|
+
let quote = inTemplate ? '`' : '';
|
|
456
|
+
for (let i = 0; i < line.length; i++) {
|
|
457
|
+
const c = line[i];
|
|
458
|
+
if (quote) {
|
|
459
|
+
out += c;
|
|
460
|
+
if (c === '\\') {
|
|
461
|
+
out += line[i + 1] ?? '';
|
|
462
|
+
i++;
|
|
463
|
+
}
|
|
464
|
+
else if (c === quote)
|
|
465
|
+
quote = '';
|
|
466
|
+
continue;
|
|
467
|
+
}
|
|
468
|
+
// Round 6: an escaped quote outside a string (`/\`/` in a regex) opens nothing.
|
|
469
|
+
if ((c === '"' || c === "'" || c === '`') && line[i - 1] !== '\\') {
|
|
470
|
+
quote = c;
|
|
471
|
+
out += c;
|
|
472
|
+
continue;
|
|
473
|
+
}
|
|
474
|
+
if (cLike && c === '/' && line[i + 1] === '/' && wordStart(line, i))
|
|
475
|
+
break;
|
|
476
|
+
if (cLike && c === '/' && line[i + 1] === '*' && i + 2 <= lastClose && wordStart(line, i)) {
|
|
477
|
+
const end = line.indexOf('*/', i + 2);
|
|
478
|
+
if (end !== -1) {
|
|
479
|
+
out += ' ';
|
|
480
|
+
i = end + 1;
|
|
481
|
+
continue;
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
if (!cLike && c === '#' && (!shellLike || shellWordStart(line, i)))
|
|
485
|
+
break;
|
|
486
|
+
out += c;
|
|
487
|
+
}
|
|
488
|
+
inTemplate = cLike && quote === '`';
|
|
489
|
+
return out;
|
|
490
|
+
});
|
|
491
|
+
}
|
|
492
|
+
/**
|
|
493
|
+
* @implements A-SPEC-733 (round 11) — Python triple-quoted spans and Ruby `=begin`…`=end` blocks are prose
|
|
494
|
+
* to the stripper (a docstring saying `subprocess` forced a mapping — measured). Linear: one pass, the
|
|
495
|
+
* span text replaced by blanks so line numbers hold.
|
|
496
|
+
*/
|
|
497
|
+
function proseBlocksBlanked(file, lines) {
|
|
498
|
+
if (/\.pyi?$/i.test(file)) {
|
|
499
|
+
let open = null;
|
|
500
|
+
return lines.map((line) => {
|
|
501
|
+
let out = '';
|
|
502
|
+
let i = 0;
|
|
503
|
+
// Round 12: each kind's next index is remembered and recomputed only once passed — recomputing both
|
|
504
|
+
// at every boundary rescanned the line (2 MB of `"""`: 7.8–9.1 s in the approval act — measured).
|
|
505
|
+
let a = line.indexOf('"""'), b = line.indexOf("'''");
|
|
506
|
+
while (i < line.length) {
|
|
507
|
+
if (open !== null) {
|
|
508
|
+
if (open === '"""' ? a !== -1 && a < i : b !== -1 && b < i) {
|
|
509
|
+
if (open === '"""')
|
|
510
|
+
a = line.indexOf('"""', i);
|
|
511
|
+
else
|
|
512
|
+
b = line.indexOf("'''", i);
|
|
513
|
+
}
|
|
514
|
+
const end = open === '"""' ? a : b;
|
|
515
|
+
if (end === -1) {
|
|
516
|
+
out += ' '.repeat(line.length - i);
|
|
517
|
+
i = line.length;
|
|
518
|
+
break;
|
|
519
|
+
}
|
|
520
|
+
out += ' '.repeat(end + 3 - i);
|
|
521
|
+
i = end + 3;
|
|
522
|
+
open = null;
|
|
523
|
+
continue;
|
|
524
|
+
}
|
|
525
|
+
if (a !== -1 && a < i)
|
|
526
|
+
a = line.indexOf('"""', i);
|
|
527
|
+
if (b !== -1 && b < i)
|
|
528
|
+
b = line.indexOf("'''", i);
|
|
529
|
+
const next = a === -1 ? b : b === -1 ? a : Math.min(a, b);
|
|
530
|
+
if (next === -1) {
|
|
531
|
+
out += line.slice(i);
|
|
532
|
+
break;
|
|
533
|
+
}
|
|
534
|
+
out += line.slice(i, next) + ' ';
|
|
535
|
+
open = next === a ? '"""' : "'''";
|
|
536
|
+
i = next + 3;
|
|
537
|
+
}
|
|
538
|
+
return out;
|
|
539
|
+
});
|
|
540
|
+
}
|
|
541
|
+
if (/\.rb$/i.test(file)) {
|
|
542
|
+
let inBlock = false;
|
|
543
|
+
return lines.map((line) => {
|
|
544
|
+
if (inBlock) {
|
|
545
|
+
if (/^=end\b/.test(line))
|
|
546
|
+
inBlock = false;
|
|
547
|
+
return '';
|
|
548
|
+
}
|
|
549
|
+
if (/^=begin\b/.test(line)) {
|
|
550
|
+
inBlock = true;
|
|
551
|
+
return '';
|
|
552
|
+
}
|
|
553
|
+
return line;
|
|
554
|
+
});
|
|
555
|
+
}
|
|
556
|
+
return lines;
|
|
557
|
+
}
|
|
558
|
+
/** A line that is only a comment — not a signal (round 2: a comment naming process.platform forced a
|
|
559
|
+
* mapping). Round 3: only for languages without their own comment rule below (markdown, text…). */
|
|
560
|
+
const COMMENT_ONLY = /^\s*(?:\/\/|\/\*|\*|--|#(?![[!]))/;
|
|
561
|
+
/** The first line of `text` that handles the platform or processes in `file`'s own language. */
|
|
562
|
+
function osSignalOf(file, text) {
|
|
563
|
+
const lang = LANG_SIGNALS.find(([re]) => re.test(file));
|
|
564
|
+
const lines = text.split('\n');
|
|
565
|
+
const fileHit = FILE_SIGNALS.find(([re]) => re.test(file));
|
|
566
|
+
if (fileHit)
|
|
567
|
+
return { line: 1, text: (lines[0] ?? '').trim().slice(0, 120), signal: fileHit[1] };
|
|
568
|
+
const code = codeOf(file, lines);
|
|
569
|
+
const joined = code.join('\n');
|
|
570
|
+
// Round 12: the process-library test reads the comment-stripped code (a comment saying `child_process`
|
|
571
|
+
// made a bare `function fork(` definition a call — measured).
|
|
572
|
+
const signals = JS_EXT.test(file) ? [...JS_SIGNALS, ...(JS_PROCESS_LIBS.test(joined) ? [jsProcessCall(joined)] : []), ...jsOsBareSignal(joined)]
|
|
573
|
+
: /\.pyi?$/i.test(file) ? [...PY_SIGNALS, ...pyPlatformSignal(joined)]
|
|
574
|
+
: /\.rs$/i.test(file) && lang ? [...lang[1], ...rsCommandSignal(joined), ...COMMON]
|
|
575
|
+
: lang ? [...lang[1], ...COMMON] : COMMON;
|
|
576
|
+
for (let i = 0; i < lines.length; i++) {
|
|
577
|
+
if (code[i].trim() === '')
|
|
578
|
+
continue;
|
|
579
|
+
for (const [re, name] of signals)
|
|
580
|
+
if (re.test(code[i]))
|
|
581
|
+
return { line: i + 1, text: lines[i].trim().slice(0, 120), signal: name };
|
|
582
|
+
}
|
|
583
|
+
return null;
|
|
584
|
+
}
|
|
39
585
|
const FORMAT_HINT = (field, cells) => `${field} 형식: 'none: <실이유>' 또는 3셀 매핑 { ${cells.map((c) => `${c}: '<supported|unavailable|n-a>: <근거>'`).join(', ')} }`;
|
|
40
586
|
/** A reason that says nothing is not a reason: empty, or still carrying the scaffold's TODO/TBD. */
|
|
41
587
|
const emptyReason = (reason) => reason.trim() === '' || /\bTODO\b|\bTBD\b/i.test(reason);
|
|
@@ -87,15 +633,114 @@ function parseAxis(field, raw, cells) {
|
|
|
87
633
|
* Backslashes normalize to `/` FIRST (adversarial round-1): a Windows author legitimately writes
|
|
88
634
|
* `src\holmes\hooks\stop.ts`, and un-normalized it walked straight past the surface prefixes —
|
|
89
635
|
* an OS-compat gate defeated by an OS path convention would be its own counterexample. */
|
|
636
|
+
const EDGE_JUNK = new Set(['*', '_', '~', '.', ',', ';', ':', '!', '?', '[', ']']);
|
|
637
|
+
/** Strip markdown emphasis and trailing punctuation, a `#L…` fragment and leading `./`/`../` —
|
|
638
|
+
* loops, not regexes, so a long run of punctuation stays linear. `[id].ts` keeps its brackets. */
|
|
639
|
+
function cleanToken(raw) {
|
|
640
|
+
let t = raw;
|
|
641
|
+
const frag = t.indexOf('#L');
|
|
642
|
+
if (frag > 0)
|
|
643
|
+
t = t.slice(0, frag);
|
|
644
|
+
let a = 0;
|
|
645
|
+
let b = t.length;
|
|
646
|
+
while (a < b && (t[a] === '*' || t[a] === '_' || t[a] === '~'))
|
|
647
|
+
a++;
|
|
648
|
+
const bracketed = t.includes('['); // `[id].ts`, `x/[slug]` keep their `]`
|
|
649
|
+
while (b > a && EDGE_JUNK.has(t[b - 1]) && !(t[b - 1] === ']' && bracketed))
|
|
650
|
+
b--;
|
|
651
|
+
t = t.slice(a, b);
|
|
652
|
+
while (t.startsWith('./') || t.startsWith('../'))
|
|
653
|
+
t = t.slice(t.indexOf('/') + 1);
|
|
654
|
+
return t;
|
|
655
|
+
}
|
|
90
656
|
function filesToTouch(spec) {
|
|
91
657
|
const body = (spec.sections?.['Files to Touch'] ?? '')
|
|
92
658
|
.replace(/\\/g, '/')
|
|
93
659
|
.replace(/\/{2,}/g, '/'); // round-2: `src\\holmes` normalized to `src//holmes` and slid past the prefix
|
|
660
|
+
// @implements A-SPEC-733 (round 2) — every path, not only `src/…`: bin/, scripts/, packages/ and
|
|
661
|
+
// lib/ files were never inspected (measured). A token with a `/`, or a file name with an extension;
|
|
662
|
+
// URLs are not paths.
|
|
663
|
+
// @implements A-SPEC-733 (round 3) — the round-2 regex dropped forms the old gate caught (globs,
|
|
664
|
+
// `**x**`, `<x>`, `[id].ts`, non-ASCII names, `#L10`, table cells) and its whole-text URL regex was
|
|
665
|
+
// quadratic (160 KB: 7.9 s in the hook). Now: split into tokens, clean each in linear time, check
|
|
666
|
+
// URLs per token, and keep the old `src/…` substring match alongside.
|
|
94
667
|
const out = [];
|
|
95
|
-
|
|
96
|
-
|
|
668
|
+
const keep = (raw) => {
|
|
669
|
+
const p = cleanToken(raw);
|
|
670
|
+
if (p === '' || /^[a-z][a-z0-9+.-]+:\//i.test(raw.replace(/^[*_~<(]+/, '')))
|
|
671
|
+
return; // `//` was collapsed above
|
|
672
|
+
if (p.includes('/') || /\.[A-Za-z][\w-]*$/.test(path.posix.basename(p)))
|
|
673
|
+
out.push(p);
|
|
674
|
+
};
|
|
675
|
+
for (const token of body.split(/[\s`'"|,<>()]+/))
|
|
676
|
+
keep(token);
|
|
677
|
+
for (const m of body.matchAll(/src\/[^\s`'"|,<>()]+/g))
|
|
678
|
+
keep(m[0]);
|
|
97
679
|
return [...new Set(out)];
|
|
98
680
|
}
|
|
681
|
+
/**
|
|
682
|
+
* @implements A-SPEC-733 (round 11) — a linear segment-stack normalizer. `posix.normalize` is quadratic on
|
|
683
|
+
* any `..` that climbs above the first real segment (round 10 stripped only a LEADING run: `x/` + 170,000
|
|
684
|
+
* `../` took 5.4 s through `approvalBlockers` — every Edit that anchors such a draft — measured).
|
|
685
|
+
* `climbs` counts the `..` components that leave the root; `path` is what remains.
|
|
686
|
+
*/
|
|
687
|
+
function normalizePosixPath(t) {
|
|
688
|
+
const stack = [];
|
|
689
|
+
let climbs = 0;
|
|
690
|
+
for (const seg of t.split('/')) {
|
|
691
|
+
if (seg === '' || seg === '.')
|
|
692
|
+
continue;
|
|
693
|
+
if (seg === '..') {
|
|
694
|
+
if (stack.length > 0)
|
|
695
|
+
stack.pop();
|
|
696
|
+
else
|
|
697
|
+
climbs++;
|
|
698
|
+
continue;
|
|
699
|
+
}
|
|
700
|
+
stack.push(seg);
|
|
701
|
+
}
|
|
702
|
+
return { path: stack.join('/'), climbs };
|
|
703
|
+
}
|
|
704
|
+
/** The posix-normalized, case-folded form a Files-to-Touch path is judged in (A-SPEC-733 round 4). */
|
|
705
|
+
function normalizedFtt(p) {
|
|
706
|
+
let t = p;
|
|
707
|
+
if (t.startsWith('[') && t.endsWith(']'))
|
|
708
|
+
t = t.slice(1, -1);
|
|
709
|
+
const n = normalizePosixPath(t);
|
|
710
|
+
return ('../'.repeat(n.climbs) + n.path).toLowerCase();
|
|
711
|
+
}
|
|
712
|
+
/** A refusal quotes at most this much of a token (round 11: a 1 MB token made a 1 MB refusal). */
|
|
713
|
+
const clip = (p) => {
|
|
714
|
+
if (p.length <= 200)
|
|
715
|
+
return p;
|
|
716
|
+
// Round 13: never end inside a surrogate pair (a lone high surrogate is ill-formed UTF-16).
|
|
717
|
+
const code = p.charCodeAt(199);
|
|
718
|
+
return `${p.slice(0, code >= 0xd800 && code <= 0xdbff ? 199 : 200)}…`;
|
|
719
|
+
};
|
|
720
|
+
/**
|
|
721
|
+
* @implements A-SPEC-733 (round 4) — the surface a Files-to-Touch entry names, or null. An ANCESTOR of
|
|
722
|
+
* a surface names it too: `- src/holmes/hooks` passed `harness_impact: none` while the edit gate
|
|
723
|
+
* admitted every file under it (measured). A glob is judged by the directory before its first
|
|
724
|
+
* `*?[{`.
|
|
725
|
+
*/
|
|
726
|
+
function harnessSurfaceOf(raw) {
|
|
727
|
+
const p = normalizedFtt(raw);
|
|
728
|
+
const glob = p.search(/[*?[{]/);
|
|
729
|
+
const dir = glob === -1 ? null : p.slice(0, glob > 0 ? p.lastIndexOf('/', glob - 1) + 1 : 0); // round 8: linear
|
|
730
|
+
for (const s of HARNESS_SURFACES) {
|
|
731
|
+
const sl = s.toLowerCase();
|
|
732
|
+
const named = sl.endsWith('/') ? p.startsWith(sl) || p === sl.slice(0, -1) : p === sl || p.startsWith(`${sl}.`) || p.startsWith(`${sl}/`);
|
|
733
|
+
const ancestor = p !== '' && sl.startsWith(`${p.replace(/\/$/, '')}/`);
|
|
734
|
+
// A root glob descends only through `/` or `**`; `*.md` names root files, not every surface.
|
|
735
|
+
const descends = dir !== null && (dir !== '' || /\*\*|\//.test(p));
|
|
736
|
+
const globbed = descends && (sl.startsWith(dir) || dir.startsWith(sl.endsWith('/') ? sl : `${sl}/`));
|
|
737
|
+
if (p !== '' && (named || ancestor || globbed))
|
|
738
|
+
return s;
|
|
739
|
+
}
|
|
740
|
+
return null;
|
|
741
|
+
}
|
|
742
|
+
/** Past this total, the OS cross-check refuses rather than reading on (A-SPEC-733 round 4). */
|
|
743
|
+
const OS_READ_TOTAL_LIMIT = 32 * 1024 * 1024;
|
|
99
744
|
function checkCompatDeclared(spec, opts) {
|
|
100
745
|
if (spec.type !== 'A-SPEC')
|
|
101
746
|
return null;
|
|
@@ -109,31 +754,57 @@ function checkCompatDeclared(spec, opts) {
|
|
|
109
754
|
// Cross-checks apply ONLY to `none` — a 3-cell mapping already faced the axis, and re-litigating
|
|
110
755
|
// it here would punish exactly the declaration this gate exists to elicit (C1's lesson is that a
|
|
111
756
|
// DECLARATION must not be the only wall; an irrelevance CLAIM is what the machine can contradict).
|
|
112
|
-
|
|
757
|
+
// @implements A-SPEC-733 (round 5) — the edit gate's own tokens too: `- :bin/…` or `- src/x.ts:12`
|
|
758
|
+
// was admitted by the gate while this extractor kept the prefix/suffix and matched nothing (measured).
|
|
759
|
+
// Round 6: from the RAW section too — the gate reads it unnormalized, so a `\` made them differ.
|
|
760
|
+
const rawSection = spec.sections?.['Files to Touch'] ?? '';
|
|
761
|
+
const gateTokens = [...(0, scope_judgment_1.fttPathTokens)(rawSection), ...(0, scope_judgment_1.fttPathTokens)(rawSection.replace(/\\/g, '/'))];
|
|
762
|
+
const ftt = [...new Set([...filesToTouch(spec), ...gateTokens])];
|
|
113
763
|
if (harness.kind === 'none') {
|
|
114
764
|
for (const p of ftt) {
|
|
115
|
-
const hit =
|
|
765
|
+
const hit = harnessSurfaceOf(p);
|
|
116
766
|
if (hit) {
|
|
117
|
-
return `harness_impact 는 none 인데 Files to Touch 의 '${p}' 는 하네스 표면(${hit})입니다 — 모순. 3셀 매핑으로 각 하네스의 영향을
|
|
767
|
+
return `harness_impact 는 none 인데 Files to Touch 의 '${clip(p)}' 는 하네스 표면(${hit})입니다 — 모순. 3셀 매핑으로 각 하네스의 영향을 기술하십시오 — ${FORMAT_HINT('harness_impact', exports.HARNESS_CELLS)}`;
|
|
118
768
|
}
|
|
119
769
|
}
|
|
120
770
|
}
|
|
121
771
|
if (os.kind === 'none' && opts?.readFile) {
|
|
122
|
-
|
|
772
|
+
// Round 4 (measured): 400 `x<i>/../src/big.ts` spellings rescanned one 2 MB file for 21.8 s. Each
|
|
773
|
+
// normalized path is read once, and the total read is bounded by a refusal, never a skip.
|
|
774
|
+
const seen = new Set();
|
|
775
|
+
let total = 0;
|
|
776
|
+
for (const raw of ftt) {
|
|
777
|
+
// Round 10/11: a path that climbs out of the project is never read; the normalizer is linear.
|
|
778
|
+
const n = normalizePosixPath(raw);
|
|
779
|
+
if (n.climbs > 0 || n.path === '')
|
|
780
|
+
continue;
|
|
781
|
+
const p = n.path;
|
|
782
|
+
// Round 6: read once per case-folded spelling (a case-insensitive disk re-read each variant).
|
|
783
|
+
const key = p.normalize('NFC').toUpperCase();
|
|
784
|
+
if (seen.has(key) || /[*?[{]/.test(p))
|
|
785
|
+
continue; // a glob is not a file
|
|
786
|
+
seen.add(key);
|
|
123
787
|
// round-2: an injected reader that THROWS (permissions, FIFO, anything) must degrade to
|
|
124
788
|
// "unreadable = skip", never crash the approval act — this check is a gate, not a hostage.
|
|
125
789
|
let text;
|
|
126
790
|
try {
|
|
127
791
|
text = opts.readFile(p);
|
|
128
792
|
}
|
|
129
|
-
catch {
|
|
793
|
+
catch (e) {
|
|
794
|
+
if (e instanceof FileTooLargeError) {
|
|
795
|
+
return `os_impact 는 none 인데 '${clip(p)}' 는 ${(e.size / 1048576).toFixed(1)} MB 로 OS 교차검사 상한(2 MB)을 넘어 판정할 수 없습니다 — 건너뛰지 않습니다. 3셀 매핑으로 각 OS 의 영향을 기술하십시오 — ${FORMAT_HINT('os_impact', exports.OS_CELLS)}`;
|
|
796
|
+
}
|
|
130
797
|
text = null;
|
|
131
798
|
}
|
|
132
799
|
if (text === null || text === undefined)
|
|
133
800
|
continue; // a file that does not exist yet has no character
|
|
134
|
-
|
|
801
|
+
total += text.length;
|
|
802
|
+
if (total > OS_READ_TOTAL_LIMIT) {
|
|
803
|
+
return `os_impact 는 none 인데 Files to Touch 파일이 합계 ${Math.round(total / 1048576)} MB 를 넘어 OS 교차검사를 끝까지 할 수 없습니다(상한 32 MB) — 3셀 매핑으로 각 OS 의 영향을 기술하십시오 — ${FORMAT_HINT('os_impact', exports.OS_CELLS)}`;
|
|
804
|
+
}
|
|
805
|
+
const sig = osSignalOf(p, text);
|
|
135
806
|
if (sig) {
|
|
136
|
-
return `os_impact 는 none 인데 '${p}'
|
|
807
|
+
return `os_impact 는 none 인데 '${clip(p)}' line ${sig.line} (${sig.text}) 이 OS 신호 '${sig.signal}' 를 담고 있습니다 — 모순. 3셀 매핑으로 각 OS 의 영향을 기술하십시오 — ${FORMAT_HINT('os_impact', exports.OS_CELLS)}`;
|
|
137
808
|
}
|
|
138
809
|
}
|
|
139
810
|
}
|