@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
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.regularFileGuardInstalled = regularFileGuardInstalled;
|
|
4
|
+
exports.installRegularFileGuard = installRegularFileGuard;
|
|
5
|
+
exports.uninstallRegularFileGuard = uninstallRegularFileGuard;
|
|
6
|
+
exports.installProcessGuards = installProcessGuards;
|
|
7
|
+
/**
|
|
8
|
+
* The real module object. `import * as fs` yields an interop copy whose members are getters onto it, so
|
|
9
|
+
* the guard assigns on the module every other file's `fs.x(...)` reads at call time.
|
|
10
|
+
*/
|
|
11
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
12
|
+
const fs = require('node:fs');
|
|
13
|
+
const C = fs.constants;
|
|
14
|
+
const NONBLOCK = typeof C.O_NONBLOCK === 'number' ? C.O_NONBLOCK : 0;
|
|
15
|
+
const SYNC = typeof C.O_SYNC === 'number' ? C.O_SYNC : 0;
|
|
16
|
+
/** Node's string flags as numbers; null for a spelling this guard does not know (the call then passes as is). */
|
|
17
|
+
function flagsOf(flag, fallback) {
|
|
18
|
+
if (typeof flag === 'number')
|
|
19
|
+
return flag;
|
|
20
|
+
const f = flag === undefined || flag === null ? fallback : flag;
|
|
21
|
+
switch (f) {
|
|
22
|
+
case 'r': return C.O_RDONLY;
|
|
23
|
+
case 'rs':
|
|
24
|
+
case 'sr': return C.O_RDONLY | SYNC;
|
|
25
|
+
case 'r+': return C.O_RDWR;
|
|
26
|
+
case 'rs+':
|
|
27
|
+
case 'sr+': return C.O_RDWR | SYNC;
|
|
28
|
+
case 'w': return C.O_TRUNC | C.O_CREAT | C.O_WRONLY;
|
|
29
|
+
case 'wx':
|
|
30
|
+
case 'xw': return C.O_TRUNC | C.O_CREAT | C.O_WRONLY | C.O_EXCL;
|
|
31
|
+
case 'w+': return C.O_TRUNC | C.O_CREAT | C.O_RDWR;
|
|
32
|
+
case 'wx+':
|
|
33
|
+
case 'xw+': return C.O_TRUNC | C.O_CREAT | C.O_RDWR | C.O_EXCL;
|
|
34
|
+
case 'a': return C.O_APPEND | C.O_CREAT | C.O_WRONLY;
|
|
35
|
+
case 'ax':
|
|
36
|
+
case 'xa': return C.O_APPEND | C.O_CREAT | C.O_WRONLY | C.O_EXCL;
|
|
37
|
+
case 'as':
|
|
38
|
+
case 'sa': return C.O_APPEND | C.O_CREAT | C.O_WRONLY | SYNC;
|
|
39
|
+
case 'a+': return C.O_APPEND | C.O_CREAT | C.O_RDWR;
|
|
40
|
+
case 'ax+':
|
|
41
|
+
case 'xa+': return C.O_APPEND | C.O_CREAT | C.O_RDWR | C.O_EXCL;
|
|
42
|
+
case 'as+':
|
|
43
|
+
case 'sa+': return C.O_APPEND | C.O_CREAT | C.O_RDWR | SYNC;
|
|
44
|
+
default: return null;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
const isPath = (p) => typeof p === 'string' || Buffer.isBuffer(p) || p instanceof URL;
|
|
48
|
+
const optionOf = (o, key) => (o !== null && typeof o === 'object' ? o[key] : undefined);
|
|
49
|
+
/** The caller's options without `flag`, for the call made on the descriptor. */
|
|
50
|
+
const withoutFlag = (o) => {
|
|
51
|
+
if (o === null || typeof o !== 'object')
|
|
52
|
+
return o;
|
|
53
|
+
const { flag: _flag, ...rest } = o;
|
|
54
|
+
void _flag;
|
|
55
|
+
return rest;
|
|
56
|
+
};
|
|
57
|
+
function notRegular(p, syscall) {
|
|
58
|
+
const err = new Error(`EINVAL: not a regular file, ${syscall} '${String(p)}'`);
|
|
59
|
+
err.code = 'EINVAL';
|
|
60
|
+
err.syscall = syscall;
|
|
61
|
+
err.path = String(p);
|
|
62
|
+
return err;
|
|
63
|
+
}
|
|
64
|
+
let originals = null;
|
|
65
|
+
/** Whether the guard is installed in this thread. */
|
|
66
|
+
function regularFileGuardInstalled() { return originals !== null; }
|
|
67
|
+
/** Install the guard for this thread (idempotent). */
|
|
68
|
+
function installRegularFileGuard() {
|
|
69
|
+
if (originals !== null)
|
|
70
|
+
return;
|
|
71
|
+
const o = { readFileSync: fs.readFileSync, writeFileSync: fs.writeFileSync, appendFileSync: fs.appendFileSync, openSync: fs.openSync };
|
|
72
|
+
originals = o;
|
|
73
|
+
const openChecked = (p, flags, mode, syscall) => {
|
|
74
|
+
const fd = o.openSync(p, flags | NONBLOCK, typeof mode === "number" || typeof mode === "string" ? mode : 0o666);
|
|
75
|
+
let ok = false;
|
|
76
|
+
try {
|
|
77
|
+
ok = fs.fstatSync(fd).isFile();
|
|
78
|
+
}
|
|
79
|
+
catch {
|
|
80
|
+
ok = false;
|
|
81
|
+
}
|
|
82
|
+
if (!ok) {
|
|
83
|
+
fs.closeSync(fd);
|
|
84
|
+
throw notRegular(p, syscall);
|
|
85
|
+
}
|
|
86
|
+
return fd;
|
|
87
|
+
};
|
|
88
|
+
const target = fs;
|
|
89
|
+
target.readFileSync = function readFileSync(p, options) {
|
|
90
|
+
if (!isPath(p))
|
|
91
|
+
return o.readFileSync(p, options);
|
|
92
|
+
const flags = flagsOf(optionOf(options, 'flag'), 'r');
|
|
93
|
+
if (flags === null)
|
|
94
|
+
return o.readFileSync(p, options);
|
|
95
|
+
const fd = openChecked(p, flags, undefined, 'open');
|
|
96
|
+
try {
|
|
97
|
+
return o.readFileSync(fd, withoutFlag(options));
|
|
98
|
+
}
|
|
99
|
+
finally {
|
|
100
|
+
fs.closeSync(fd);
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
const writeLike = (orig, fallback) => function (p, data, options) {
|
|
104
|
+
if (!isPath(p))
|
|
105
|
+
return orig(p, data, options);
|
|
106
|
+
const flags = flagsOf(typeof options === 'string' ? undefined : optionOf(options, 'flag'), fallback);
|
|
107
|
+
if (flags === null)
|
|
108
|
+
return orig(p, data, options);
|
|
109
|
+
const fd = openChecked(p, flags, optionOf(options, 'mode'), 'open');
|
|
110
|
+
try {
|
|
111
|
+
return orig(fd, data, withoutFlag(options));
|
|
112
|
+
}
|
|
113
|
+
finally {
|
|
114
|
+
fs.closeSync(fd);
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
target.writeFileSync = writeLike(o.writeFileSync, 'w');
|
|
118
|
+
target.appendFileSync = writeLike(o.appendFileSync, 'a');
|
|
119
|
+
target.openSync = function openSync(p, flags, mode) {
|
|
120
|
+
if (!isPath(p))
|
|
121
|
+
return o.openSync(p, flags, mode);
|
|
122
|
+
const n = flagsOf(flags, 'r');
|
|
123
|
+
return n === null ? o.openSync(p, flags, mode) : o.openSync(p, n | NONBLOCK, mode);
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
/** Test seam: restore the real functions. */
|
|
127
|
+
function uninstallRegularFileGuard() {
|
|
128
|
+
if (originals === null)
|
|
129
|
+
return;
|
|
130
|
+
const target = fs;
|
|
131
|
+
target.readFileSync = originals.readFileSync;
|
|
132
|
+
target.writeFileSync = originals.writeFileSync;
|
|
133
|
+
target.appendFileSync = originals.appendFileSync;
|
|
134
|
+
target.openSync = originals.openSync;
|
|
135
|
+
originals = null;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* @implements A-SPEC-734 (round 17) — what every product process does at start: the regular-file guard, and the
|
|
139
|
+
* removal of the variables that relocate the repository a git child reads (`GIT_DIR` and the rest of
|
|
140
|
+
* `REPO_LOCATING_GIT_VARS`). Round 16 dropped them at the call sites it knew; the scanner's nesting queries kept an
|
|
141
|
+
* exported `GIT_DIR` and listed a registered worktree's files (measured). One list of entries, one decision.
|
|
142
|
+
*/
|
|
143
|
+
function installProcessGuards() {
|
|
144
|
+
installRegularFileGuard();
|
|
145
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
146
|
+
const { REPO_LOCATING_GIT_VARS } = require('./bounded-io');
|
|
147
|
+
for (const k of REPO_LOCATING_GIT_VARS)
|
|
148
|
+
delete process.env[k];
|
|
149
|
+
}
|
|
@@ -38,11 +38,12 @@ exports.cleanSubprocessEnv = cleanSubprocessEnv;
|
|
|
38
38
|
exports.cleanTestEnv = cleanTestEnv;
|
|
39
39
|
exports.sameCanonicalDirectory = sameCanonicalDirectory;
|
|
40
40
|
exports.resolveProjectRoot = resolveProjectRoot;
|
|
41
|
-
// @implements A-SPEC-205, A-SPEC-627
|
|
41
|
+
// @implements A-SPEC-205, A-SPEC-627, A-SPEC-734
|
|
42
42
|
// @implements A-SPEC-128
|
|
43
43
|
const fs = __importStar(require("node:fs"));
|
|
44
44
|
const path = __importStar(require("node:path"));
|
|
45
45
|
const node_child_process_1 = require("node:child_process");
|
|
46
|
+
const bounded_io_1 = require("./bounded-io");
|
|
46
47
|
// @implements A-SPEC-194
|
|
47
48
|
// @implements A-SPEC-196
|
|
48
49
|
// @implements A-SPEC-205
|
|
@@ -56,6 +57,9 @@ function cleanSubprocessEnv(env = process.env) {
|
|
|
56
57
|
delete cleaned[k];
|
|
57
58
|
}
|
|
58
59
|
}
|
|
60
|
+
// @implements A-SPEC-734 (round 16) — a child git reads the repository at its cwd, not one an exported GIT_DIR names.
|
|
61
|
+
for (const k of bounded_io_1.REPO_LOCATING_GIT_VARS)
|
|
62
|
+
delete cleaned[k];
|
|
59
63
|
return cleaned;
|
|
60
64
|
}
|
|
61
65
|
// @implements A-SPEC-514.1
|
|
@@ -140,9 +144,13 @@ function sameCanonicalDirectory(a, b, realpath = exports.canonicalPath) {
|
|
|
140
144
|
return spell(a) === spell(b);
|
|
141
145
|
}
|
|
142
146
|
function gitTopLevel(dir) {
|
|
147
|
+
// @implements A-SPEC-734 (round 12) — a root whose git timed out is not asked again for a minute
|
|
148
|
+
// (`include.path` naming a FIFO blocked this rev-parse in every hook — measured).
|
|
149
|
+
if ((0, bounded_io_1.gitRootBlocked)(dir, 'repo'))
|
|
150
|
+
return undefined;
|
|
143
151
|
try {
|
|
144
152
|
// stderr silenced: "not a git repository" is an expected branch here, not a fault worth printing.
|
|
145
|
-
const out = (0, node_child_process_1.execFileSync)('git', ['-C', dir, 'rev-parse', '--show-toplevel'], {
|
|
153
|
+
const out = (0, node_child_process_1.execFileSync)('git', ['-C', dir, 'rev-parse', '--show-toplevel'], { timeout: bounded_io_1.GIT_TIMEOUT_MS, maxBuffer: bounded_io_1.GIT_MAX_BUFFER,
|
|
146
154
|
encoding: 'utf8',
|
|
147
155
|
stdio: ['ignore', 'pipe', 'ignore'],
|
|
148
156
|
env: cleanSubprocessEnv(),
|
|
@@ -151,7 +159,8 @@ function gitTopLevel(dir) {
|
|
|
151
159
|
// (macOS /var -> /private/var otherwise makes an identical directory look like a mismatch).
|
|
152
160
|
return out ? canonical(out) : undefined;
|
|
153
161
|
}
|
|
154
|
-
catch {
|
|
162
|
+
catch (e) {
|
|
163
|
+
(0, bounded_io_1.noteGitFailure)(dir, e, 'repo');
|
|
155
164
|
return undefined;
|
|
156
165
|
}
|
|
157
166
|
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
export type FreshnessLane = 'current' | 'refreshing' | 'retry-at' | 'failed' | 'suppressed' | 'not-adopted' | 'stale';
|
|
2
|
+
export interface FreshnessReceipt {
|
|
3
|
+
schema: 'fresh-evidence/1';
|
|
4
|
+
workspaceId: string;
|
|
5
|
+
head: string | null;
|
|
6
|
+
generation: string;
|
|
7
|
+
state: FreshnessLane;
|
|
8
|
+
startedAt?: string;
|
|
9
|
+
completedAt?: string;
|
|
10
|
+
attempt: number;
|
|
11
|
+
retryAt?: string;
|
|
12
|
+
graph: FreshnessLane;
|
|
13
|
+
sourceSemantic: FreshnessLane;
|
|
14
|
+
requirementSemantic: FreshnessLane;
|
|
15
|
+
}
|
|
16
|
+
export interface RefreshRequest {
|
|
17
|
+
workspaceId: string;
|
|
18
|
+
head: string | null;
|
|
19
|
+
now: Date;
|
|
20
|
+
}
|
|
21
|
+
export interface RefreshCompletion {
|
|
22
|
+
graph: FreshnessLane;
|
|
23
|
+
sourceSemantic: FreshnessLane;
|
|
24
|
+
requirementSemantic: FreshnessLane;
|
|
25
|
+
head: string | null;
|
|
26
|
+
}
|
|
27
|
+
export declare const FRESHNESS_RECEIPT_FILE: string;
|
|
28
|
+
export declare const FRESHNESS_LEASE_MS: number;
|
|
29
|
+
/** A failed detached worker is visible immediately but retries only after this bounded pause. */
|
|
30
|
+
export declare const FRESHNESS_RETRY_MS: number;
|
|
31
|
+
/**
|
|
32
|
+
* A usable terminal receipt coalesces for its HEAD only this long. HEAD alone does not move while
|
|
33
|
+
* someone edits, so without an interval the graph would never refresh between commits — the former
|
|
34
|
+
* marker's 30-minute window, which A-SPEC-566.4 measured as the advisory's quality factor.
|
|
35
|
+
*/
|
|
36
|
+
export declare const FRESHNESS_REREFRESH_MS: number;
|
|
37
|
+
/**
|
|
38
|
+
* Whether a receipt can ground requirement intake: a current graph plus a requirement lane that is
|
|
39
|
+
* current or the owner-chosen lexical-only `not-adopted`/`suppressed`. The source lane never counts.
|
|
40
|
+
*/
|
|
41
|
+
export declare function intakeUsable(receipt: FreshnessReceipt | null | undefined): boolean;
|
|
42
|
+
/** Usable, but without requirement vectors: triage ran on lexical evidence alone. */
|
|
43
|
+
export declare function lexicalOnly(receipt: FreshnessReceipt | null | undefined): boolean;
|
|
44
|
+
/** Read-only judgement: untrusted, expired, foreign, and commit-mismatched state is never current. */
|
|
45
|
+
export declare function readFreshnessReceipt(root: string, expected: RefreshRequest): FreshnessReceipt | null;
|
|
46
|
+
/**
|
|
47
|
+
* Publish a new lease before the detached worker is started. The caller alone
|
|
48
|
+
* performs spawning when `spawn` is true; all matching live callers coalesce.
|
|
49
|
+
*/
|
|
50
|
+
export declare function requestRefresh(root: string, input: RefreshRequest): {
|
|
51
|
+
spawn: boolean;
|
|
52
|
+
receipt: FreshnessReceipt;
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
* True only while `generation` still holds the live lease in an existing root. A worker asks this
|
|
56
|
+
* before each phase that writes, so a superseded or orphaned child stops instead of recreating
|
|
57
|
+
* `.ax` under a root that was removed (A-SPEC-724).
|
|
58
|
+
*/
|
|
59
|
+
export declare function ownsLease(root: string, generation: string): boolean;
|
|
60
|
+
/** Publish only the lease owner’s terminal observation; a superseded worker cannot overwrite a newer lease. */
|
|
61
|
+
export declare function completeRefresh(root: string, generation: string, completion: RefreshCompletion, now: Date): FreshnessReceipt | null;
|
|
62
|
+
/**
|
|
63
|
+
* Initialized/registered workspaces use their governed identity. Legacy
|
|
64
|
+
* workspaces remain safe to refresh: their canonical real path is a local,
|
|
65
|
+
* deterministic identity and is never persisted as a secret or sent remotely.
|
|
66
|
+
*/
|
|
67
|
+
export declare function workspaceIdFor(root: string): string;
|
|
@@ -0,0 +1,230 @@
|
|
|
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
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.FRESHNESS_REREFRESH_MS = exports.FRESHNESS_RETRY_MS = exports.FRESHNESS_LEASE_MS = exports.FRESHNESS_RECEIPT_FILE = void 0;
|
|
37
|
+
exports.intakeUsable = intakeUsable;
|
|
38
|
+
exports.lexicalOnly = lexicalOnly;
|
|
39
|
+
exports.readFreshnessReceipt = readFreshnessReceipt;
|
|
40
|
+
exports.requestRefresh = requestRefresh;
|
|
41
|
+
exports.ownsLease = ownsLease;
|
|
42
|
+
exports.completeRefresh = completeRefresh;
|
|
43
|
+
exports.workspaceIdFor = workspaceIdFor;
|
|
44
|
+
// @implements A-SPEC-719
|
|
45
|
+
/**
|
|
46
|
+
* The durable source of truth for refresh work. A receipt names the workspace and
|
|
47
|
+
* commit it describes, so an old detached worker cannot make a newer tree look
|
|
48
|
+
* current merely by leaving behind a successful timestamp.
|
|
49
|
+
*/
|
|
50
|
+
const crypto = __importStar(require("node:crypto"));
|
|
51
|
+
const fs = __importStar(require("node:fs"));
|
|
52
|
+
const path = __importStar(require("node:path"));
|
|
53
|
+
const workspace_identity_1 = require("../project/workspace-identity");
|
|
54
|
+
exports.FRESHNESS_RECEIPT_FILE = path.join('.ax', 'state', 'fresh-evidence.json');
|
|
55
|
+
// A crashed detached child becomes eligible quickly. This is intentionally much
|
|
56
|
+
// shorter than the former 30-minute marker window, while still bounding spawn bursts.
|
|
57
|
+
exports.FRESHNESS_LEASE_MS = 2 * 60 * 1000;
|
|
58
|
+
/** A failed detached worker is visible immediately but retries only after this bounded pause. */
|
|
59
|
+
exports.FRESHNESS_RETRY_MS = 30 * 1000;
|
|
60
|
+
/**
|
|
61
|
+
* A usable terminal receipt coalesces for its HEAD only this long. HEAD alone does not move while
|
|
62
|
+
* someone edits, so without an interval the graph would never refresh between commits — the former
|
|
63
|
+
* marker's 30-minute window, which A-SPEC-566.4 measured as the advisory's quality factor.
|
|
64
|
+
*/
|
|
65
|
+
exports.FRESHNESS_REREFRESH_MS = 30 * 60 * 1000;
|
|
66
|
+
/** Requirement lanes a receipt may carry and still ground intake (A-SPEC-719, owner decision 2026-09-23). */
|
|
67
|
+
const INTAKE_REQUIREMENT_LANES = new Set(['current', 'not-adopted', 'suppressed']);
|
|
68
|
+
/**
|
|
69
|
+
* Whether a receipt can ground requirement intake: a current graph plus a requirement lane that is
|
|
70
|
+
* current or the owner-chosen lexical-only `not-adopted`/`suppressed`. The source lane never counts.
|
|
71
|
+
*/
|
|
72
|
+
function intakeUsable(receipt) {
|
|
73
|
+
return !!receipt && receipt.graph === 'current' && receipt.state === (receipt.requirementSemantic === 'current' ? 'current' : receipt.requirementSemantic)
|
|
74
|
+
&& INTAKE_REQUIREMENT_LANES.has(receipt.requirementSemantic);
|
|
75
|
+
}
|
|
76
|
+
/** Usable, but without requirement vectors: triage ran on lexical evidence alone. */
|
|
77
|
+
function lexicalOnly(receipt) {
|
|
78
|
+
return intakeUsable(receipt) && receipt.requirementSemantic !== 'current';
|
|
79
|
+
}
|
|
80
|
+
const lanes = new Set(['current', 'refreshing', 'retry-at', 'failed', 'suppressed', 'not-adopted', 'stale']);
|
|
81
|
+
const receiptPath = (root) => path.join(root, exports.FRESHNESS_RECEIPT_FILE);
|
|
82
|
+
const sameIdentity = (r, i) => r.workspaceId === i.workspaceId && r.head === i.head;
|
|
83
|
+
function isReceipt(value) {
|
|
84
|
+
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
85
|
+
return false;
|
|
86
|
+
const r = value;
|
|
87
|
+
return r.schema === 'fresh-evidence/1' && typeof r.workspaceId === 'string'
|
|
88
|
+
&& (typeof r.head === 'string' || r.head === null) && typeof r.generation === 'string'
|
|
89
|
+
&& typeof r.state === 'string' && lanes.has(r.state)
|
|
90
|
+
&& typeof r.attempt === 'number' && Number.isInteger(r.attempt) && r.attempt > 0
|
|
91
|
+
&& typeof r.graph === 'string' && lanes.has(r.graph)
|
|
92
|
+
&& typeof r.sourceSemantic === 'string' && lanes.has(r.sourceSemantic)
|
|
93
|
+
&& typeof r.requirementSemantic === 'string' && lanes.has(r.requirementSemantic)
|
|
94
|
+
&& (r.startedAt === undefined || typeof r.startedAt === 'string')
|
|
95
|
+
&& (r.completedAt === undefined || typeof r.completedAt === 'string')
|
|
96
|
+
&& (r.retryAt === undefined || typeof r.retryAt === 'string');
|
|
97
|
+
}
|
|
98
|
+
function storedReceipt(root) {
|
|
99
|
+
try {
|
|
100
|
+
const parsed = JSON.parse(fs.readFileSync(receiptPath(root), 'utf8'));
|
|
101
|
+
return isReceipt(parsed) ? parsed : null;
|
|
102
|
+
}
|
|
103
|
+
catch {
|
|
104
|
+
return null;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
function writeReceipt(root, receipt) {
|
|
108
|
+
const file = receiptPath(root), dir = path.dirname(file);
|
|
109
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
110
|
+
const temp = path.join(dir, `.fresh-evidence-${crypto.randomUUID()}.tmp`);
|
|
111
|
+
let written = false;
|
|
112
|
+
try {
|
|
113
|
+
const fd = fs.openSync(temp, 'wx', 0o600);
|
|
114
|
+
written = true;
|
|
115
|
+
try {
|
|
116
|
+
fs.writeFileSync(fd, JSON.stringify(receipt, null, 2) + '\n');
|
|
117
|
+
fs.fsyncSync(fd);
|
|
118
|
+
}
|
|
119
|
+
finally {
|
|
120
|
+
fs.closeSync(fd);
|
|
121
|
+
}
|
|
122
|
+
fs.renameSync(temp, file);
|
|
123
|
+
}
|
|
124
|
+
finally {
|
|
125
|
+
if (written) {
|
|
126
|
+
try {
|
|
127
|
+
fs.unlinkSync(temp);
|
|
128
|
+
}
|
|
129
|
+
catch { /* rename consumed the temporary file */ }
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
function expired(receipt, now) {
|
|
134
|
+
if (receipt.state !== 'refreshing' || !receipt.startedAt)
|
|
135
|
+
return false;
|
|
136
|
+
const started = Date.parse(receipt.startedAt);
|
|
137
|
+
return !Number.isFinite(started) || now.getTime() - started >= exports.FRESHNESS_LEASE_MS;
|
|
138
|
+
}
|
|
139
|
+
function stale(receipt) {
|
|
140
|
+
return { ...receipt, state: 'stale', graph: 'stale', sourceSemantic: 'stale', requirementSemantic: 'stale' };
|
|
141
|
+
}
|
|
142
|
+
/** Read-only judgement: untrusted, expired, foreign, and commit-mismatched state is never current. */
|
|
143
|
+
function readFreshnessReceipt(root, expected) {
|
|
144
|
+
const receipt = storedReceipt(root);
|
|
145
|
+
if (!receipt)
|
|
146
|
+
return null;
|
|
147
|
+
return sameIdentity(receipt, expected) && !expired(receipt, expected.now) ? receipt : stale(receipt);
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Publish a new lease before the detached worker is started. The caller alone
|
|
151
|
+
* performs spawning when `spawn` is true; all matching live callers coalesce.
|
|
152
|
+
*/
|
|
153
|
+
function requestRefresh(root, input) {
|
|
154
|
+
const previous = storedReceipt(root);
|
|
155
|
+
if (previous && sameIdentity(previous, input) && previous.state === 'refreshing' && !expired(previous, input.now)) {
|
|
156
|
+
return { spawn: false, receipt: previous };
|
|
157
|
+
}
|
|
158
|
+
if (previous && sameIdentity(previous, input) && previous.state === 'retry-at'
|
|
159
|
+
&& previous.retryAt && Date.parse(previous.retryAt) > input.now.getTime()) {
|
|
160
|
+
return { spawn: false, receipt: previous };
|
|
161
|
+
}
|
|
162
|
+
if (previous && sameIdentity(previous, input) && intakeUsable(previous)) {
|
|
163
|
+
const completed = previous.completedAt ? Date.parse(previous.completedAt) : NaN;
|
|
164
|
+
const age = input.now.getTime() - completed; // a future stamp (clock skew) is not fresh: refresh
|
|
165
|
+
if (Number.isFinite(completed) && age >= 0 && age <= exports.FRESHNESS_REREFRESH_MS)
|
|
166
|
+
return { spawn: false, receipt: previous };
|
|
167
|
+
}
|
|
168
|
+
const attempt = previous && sameIdentity(previous, input) ? previous.attempt + 1 : 1;
|
|
169
|
+
const receipt = {
|
|
170
|
+
schema: 'fresh-evidence/1', workspaceId: input.workspaceId, head: input.head,
|
|
171
|
+
generation: crypto.randomUUID(), state: 'refreshing', startedAt: input.now.toISOString(), attempt,
|
|
172
|
+
graph: 'refreshing', sourceSemantic: 'refreshing', requirementSemantic: 'refreshing',
|
|
173
|
+
};
|
|
174
|
+
writeReceipt(root, receipt);
|
|
175
|
+
return { spawn: true, receipt };
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* True only while `generation` still holds the live lease in an existing root. A worker asks this
|
|
179
|
+
* before each phase that writes, so a superseded or orphaned child stops instead of recreating
|
|
180
|
+
* `.ax` under a root that was removed (A-SPEC-724).
|
|
181
|
+
*/
|
|
182
|
+
function ownsLease(root, generation) {
|
|
183
|
+
const receipt = storedReceipt(root);
|
|
184
|
+
return receipt !== null && receipt.generation === generation && receipt.state === 'refreshing';
|
|
185
|
+
}
|
|
186
|
+
/** Publish only the lease owner’s terminal observation; a superseded worker cannot overwrite a newer lease. */
|
|
187
|
+
function completeRefresh(root, generation, completion, now) {
|
|
188
|
+
const previous = storedReceipt(root);
|
|
189
|
+
if (!previous || previous.generation !== generation || previous.state !== 'refreshing')
|
|
190
|
+
return null;
|
|
191
|
+
if (previous.head !== completion.head) {
|
|
192
|
+
const superseded = stale(previous);
|
|
193
|
+
writeReceipt(root, superseded);
|
|
194
|
+
return superseded;
|
|
195
|
+
}
|
|
196
|
+
// Currentness is the graph and requirement lanes (A-SPEC-719). The source lane is reported beside
|
|
197
|
+
// them and never substitutes for, nor withholds, requirement coverage.
|
|
198
|
+
const judged = [completion.graph, completion.requirementSemantic];
|
|
199
|
+
const lanesCurrent = judged.every((lane) => lane === 'current');
|
|
200
|
+
const retry = judged.some((lane) => lane === 'failed' || lane === 'retry-at');
|
|
201
|
+
const state = lanesCurrent ? 'current'
|
|
202
|
+
: judged.includes('suppressed') ? 'suppressed'
|
|
203
|
+
: judged.includes('not-adopted') ? 'not-adopted'
|
|
204
|
+
: retry ? 'retry-at' : 'failed';
|
|
205
|
+
const receipt = {
|
|
206
|
+
...previous, ...completion, state, completedAt: now.toISOString(),
|
|
207
|
+
...(retry ? { retryAt: new Date(now.getTime() + exports.FRESHNESS_RETRY_MS).toISOString() } : {}),
|
|
208
|
+
};
|
|
209
|
+
writeReceipt(root, receipt);
|
|
210
|
+
return receipt;
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Initialized/registered workspaces use their governed identity. Legacy
|
|
214
|
+
* workspaces remain safe to refresh: their canonical real path is a local,
|
|
215
|
+
* deterministic identity and is never persisted as a secret or sent remotely.
|
|
216
|
+
*/
|
|
217
|
+
function workspaceIdFor(root) {
|
|
218
|
+
try {
|
|
219
|
+
const identity = (0, workspace_identity_1.workspaceIdentity)(root, 'status');
|
|
220
|
+
if (identity.state !== 'legacy')
|
|
221
|
+
return identity.workspaceId;
|
|
222
|
+
}
|
|
223
|
+
catch { /* maintenance is fail-soft; fall through to local identity */ }
|
|
224
|
+
let canonical = root;
|
|
225
|
+
try {
|
|
226
|
+
canonical = fs.realpathSync(root);
|
|
227
|
+
}
|
|
228
|
+
catch { /* retain caller root */ }
|
|
229
|
+
return `legacy-${crypto.createHash('sha256').update(canonical).digest('hex')}`;
|
|
230
|
+
}
|
|
@@ -35,9 +35,10 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
36
|
exports.planAnchors = planAnchors;
|
|
37
37
|
exports.applyAnchors = applyAnchors;
|
|
38
|
-
// @implements A-SPEC-126
|
|
38
|
+
// @implements A-SPEC-126, A-SPEC-734
|
|
39
39
|
const fs = __importStar(require("node:fs"));
|
|
40
40
|
const path = __importStar(require("node:path"));
|
|
41
|
+
const bounded_io_1 = require("../project/bounded-io");
|
|
41
42
|
/**
|
|
42
43
|
* Comment prefix per language, covering every extension in `SCANNABLE_EXTENSIONS`.
|
|
43
44
|
* An anchor written with the wrong prefix is a syntax error in the target file, so this table is
|
|
@@ -113,7 +114,7 @@ function planAnchors(root, mapping, approvedAspecs) {
|
|
|
113
114
|
}
|
|
114
115
|
let code;
|
|
115
116
|
try {
|
|
116
|
-
code =
|
|
117
|
+
code = (0, bounded_io_1.readRegularTextSync)(abs);
|
|
117
118
|
}
|
|
118
119
|
catch {
|
|
119
120
|
refused.push({ file, aspec, reason: 'unreadable' });
|
|
@@ -143,7 +144,7 @@ function applyAnchors(root, edits, opts = {}) {
|
|
|
143
144
|
for (const e of edits) {
|
|
144
145
|
try {
|
|
145
146
|
const abs = path.join(root, e.file);
|
|
146
|
-
const code =
|
|
147
|
+
const code = (0, bounded_io_1.readRegularTextSync)(abs);
|
|
147
148
|
// Match the file's own line ending. Splicing an LF line into a CRLF file leaves one stray
|
|
148
149
|
// ending, which reads as a whole-file change in some tooling and a lint error in others —
|
|
149
150
|
// noise attributable to the anchor rather than to the code. Brownfield trees have both.
|
|
@@ -35,7 +35,7 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
36
|
exports.candidates = candidates;
|
|
37
37
|
exports.reverseScan = reverseScan;
|
|
38
|
-
// @implements A-SPEC-126
|
|
38
|
+
// @implements A-SPEC-126, A-SPEC-734
|
|
39
39
|
const fs = __importStar(require("node:fs"));
|
|
40
40
|
const path = __importStar(require("node:path"));
|
|
41
41
|
const node_child_process_1 = require("node:child_process");
|
|
@@ -48,6 +48,7 @@ const surface_1 = require("./surface");
|
|
|
48
48
|
// @implements A-SPEC-128
|
|
49
49
|
const ignore_1 = require("../project/ignore");
|
|
50
50
|
const draft_1 = require("./draft");
|
|
51
|
+
const bounded_io_1 = require("../project/bounded-io");
|
|
51
52
|
const SCANNABLE_RE = new RegExp(`(${cpg_scanner_1.SCANNABLE_EXTENSIONS.map((e) => e.replace('.', '\\.')).join('|')})$`);
|
|
52
53
|
/** Walk a non-git tree for test files, mirroring the scanner's own vendor-directory skips. */
|
|
53
54
|
function walkTestFiles(root) {
|
|
@@ -65,6 +66,8 @@ function walkTestFiles(root) {
|
|
|
65
66
|
continue;
|
|
66
67
|
const abs = path.join(dir, e.name);
|
|
67
68
|
const rel = path.relative(root, abs).split(path.sep).join('/');
|
|
69
|
+
if (e.isDirectory() && (0, cpg_scanner_1.isNestedWorkTree)(abs, root))
|
|
70
|
+
continue; // A-SPEC-734: another repository
|
|
68
71
|
if (e.isDirectory())
|
|
69
72
|
walk(abs);
|
|
70
73
|
else if (SCANNABLE_RE.test(e.name) && (0, test_files_1.isTestFile)(rel))
|
|
@@ -87,7 +90,8 @@ function candidates(root, scan) {
|
|
|
87
90
|
tracked = new Set(
|
|
88
91
|
// stderr is silenced: on a non-git tree git's "not a repository" complaint is an expected
|
|
89
92
|
// branch of this function, not a fault worth printing over the caller's output.
|
|
90
|
-
(
|
|
93
|
+
// A-SPEC-734 (round 15): an index read with the fsmonitor hook off (a slow hook read as "not git" — measured).
|
|
94
|
+
(0, node_child_process_1.execFileSync)('git', ['-c', 'core.fsmonitor=false', '-C', root, 'ls-files', '-z'], { timeout: bounded_io_1.GIT_TIMEOUT_MS, encoding: 'utf8', maxBuffer: 1 << 28, stdio: ['ignore', 'pipe', 'ignore'], env: (0, bounded_io_1.gitEnv)() })
|
|
91
95
|
.split('\0')
|
|
92
96
|
.filter(Boolean));
|
|
93
97
|
}
|
|
@@ -2,16 +2,17 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.commitTextProfile = commitTextProfile;
|
|
4
4
|
exports.rankByCommitText = rankByCommitText;
|
|
5
|
-
// @implements A-SPEC-385
|
|
5
|
+
// @implements A-SPEC-385, A-SPEC-734
|
|
6
6
|
// @implements A-SPEC-386
|
|
7
7
|
const node_child_process_1 = require("node:child_process");
|
|
8
8
|
const maintenance_analyze_1 = require("../mcp/maintenance-analyze");
|
|
9
9
|
const localize_1 = require("../rtm/localize");
|
|
10
|
+
const bounded_io_1 = require("../project/bounded-io");
|
|
10
11
|
function commitTextProfile(root, before, limit = 400) {
|
|
11
12
|
const empty = { byFile: new Map(), commits: 0, documentFrequency: new Map(), commitIds: new Set() };
|
|
12
13
|
let raw;
|
|
13
14
|
try {
|
|
14
|
-
raw = (0, node_child_process_1.execFileSync)('git', ['-C', root, 'log', '--no-merges', `-${limit}`, '--format=%x00%H%x00%s', '--name-only', before], { encoding: 'utf8', maxBuffer: 64 * 1024 * 1024 });
|
|
15
|
+
raw = (0, node_child_process_1.execFileSync)('git', ['-C', root, 'log', '--no-merges', `-${limit}`, '--format=%x00%H%x00%s', '--name-only', before], { timeout: bounded_io_1.GIT_TIMEOUT_MS, encoding: 'utf8', maxBuffer: 64 * 1024 * 1024 });
|
|
15
16
|
}
|
|
16
17
|
catch {
|
|
17
18
|
return empty;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { ReplayCase } from './replay-corpus';
|
|
2
|
+
import { type HunkResolution } from './condition-hunk-resolution';
|
|
2
3
|
export interface ConditionHunkReplayReport {
|
|
3
4
|
schema: 'condition-hunk-replay/1';
|
|
4
5
|
commits: string[];
|
|
@@ -23,6 +24,17 @@ export interface ConditionHunkReplayReport {
|
|
|
23
24
|
conditionResolution: number;
|
|
24
25
|
overheadPct: number | null;
|
|
25
26
|
};
|
|
27
|
+
/** Auditable summaries only; source blobs and candidate lists remain outside the replay report. */
|
|
28
|
+
records: Array<{
|
|
29
|
+
commit: string;
|
|
30
|
+
file: string;
|
|
31
|
+
state: HunkResolution['state'];
|
|
32
|
+
direction: HunkResolution['direction'];
|
|
33
|
+
symbol?: string;
|
|
34
|
+
conditionText?: string;
|
|
35
|
+
reason?: string;
|
|
36
|
+
hunk: Pick<HunkResolution['hunk'], 'startLine' | 'endLine' | 'deletionOnly'>;
|
|
37
|
+
}>;
|
|
26
38
|
elapsedMs: number;
|
|
27
39
|
limitations: string[];
|
|
28
40
|
}
|
|
@@ -34,12 +34,14 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
36
|
exports.replayConditionHunks = replayConditionHunks;
|
|
37
|
+
// @implements A-SPEC-717, A-SPEC-734
|
|
37
38
|
// @implements A-SPEC-661
|
|
38
39
|
/** Historical, read-only measurement for the condition-hunk advisory. */
|
|
39
40
|
const node_child_process_1 = require("node:child_process");
|
|
40
41
|
const path = __importStar(require("node:path"));
|
|
41
42
|
const language_parser_1 = require("../cpg/language-parser");
|
|
42
43
|
const condition_hunk_resolution_1 = require("./condition-hunk-resolution");
|
|
44
|
+
const bounded_io_1 = require("../project/bounded-io");
|
|
43
45
|
const SAFE_COMMIT = /^[0-9a-f]{7,64}$/;
|
|
44
46
|
const sourceLanguage = (file) => {
|
|
45
47
|
if (/\.(ts|mts|cts)$/.test(file))
|
|
@@ -49,7 +51,7 @@ const sourceLanguage = (file) => {
|
|
|
49
51
|
return null;
|
|
50
52
|
};
|
|
51
53
|
const safePath = (file) => file !== '' && !path.isAbsolute(file) && !file.split(/[\\/]/).includes('..');
|
|
52
|
-
const git = (root, args) => (0, node_child_process_1.execFileSync)('git', ['-C', root, ...args], {
|
|
54
|
+
const git = (root, args) => (0, node_child_process_1.execFileSync)('git', ['-C', root, ...args], { timeout: bounded_io_1.GIT_LONG_TIMEOUT_MS,
|
|
53
55
|
encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'], maxBuffer: 16 * 1024 * 1024,
|
|
54
56
|
});
|
|
55
57
|
/** Replays caller-selected commits only; it never checks out, writes a cache, or inspects another repository. */
|
|
@@ -57,6 +59,7 @@ async function replayConditionHunks(input) {
|
|
|
57
59
|
const started = Date.now();
|
|
58
60
|
const parser = new language_parser_1.TreeSitterTsParser();
|
|
59
61
|
const resolutions = [];
|
|
62
|
+
const records = [];
|
|
60
63
|
let files = 0, symbols = 0, candidateSymbols = 0, baselineMs = 0, conditionResolutionMs = 0;
|
|
61
64
|
const commits = [];
|
|
62
65
|
for (const replayCase of input.cases) {
|
|
@@ -85,7 +88,14 @@ async function replayConditionHunks(input) {
|
|
|
85
88
|
symbols += rows.length;
|
|
86
89
|
candidateSymbols += hunks.reduce((total, hunk) => total + rows.filter((symbol) => symbol.startLine <= hunk.startLine && symbol.endLine >= hunk.endLine).length, 0);
|
|
87
90
|
const conditionStart = Date.now();
|
|
88
|
-
|
|
91
|
+
const resolvedRows = await (0, condition_hunk_resolution_1.resolveConditionHunksFromSources)({ diff, sources: [{ file, source }], symbols: rows });
|
|
92
|
+
resolutions.push(...resolvedRows);
|
|
93
|
+
records.push(...resolvedRows.map((row) => ({ commit: replayCase.commit, file, state: row.state, direction: row.direction,
|
|
94
|
+
...(row.symbol === undefined ? {} : { symbol: row.symbol }),
|
|
95
|
+
...(row.conditionText === undefined ? {} : { conditionText: row.conditionText }),
|
|
96
|
+
...(row.reason === undefined ? {} : { reason: row.reason }),
|
|
97
|
+
hunk: { startLine: row.hunk.startLine, endLine: row.hunk.endLine, ...(row.hunk.deletionOnly ? { deletionOnly: true } : {}) },
|
|
98
|
+
})));
|
|
89
99
|
conditionResolutionMs += Date.now() - conditionStart;
|
|
90
100
|
}
|
|
91
101
|
}
|
|
@@ -101,6 +111,7 @@ async function replayConditionHunks(input) {
|
|
|
101
111
|
candidateReduction: { hunkToResolved: candidateSymbols === 0 ? null : 1 - resolved / candidateSymbols },
|
|
102
112
|
timingMs: { baseline: baselineMs, conditionResolution: conditionResolutionMs,
|
|
103
113
|
overheadPct: baselineMs === 0 ? null : conditionResolutionMs / baselineMs * 100 },
|
|
114
|
+
records,
|
|
104
115
|
elapsedMs: Date.now() - started,
|
|
105
116
|
limitations: [
|
|
106
117
|
'This measures only caller-selected TypeScript/JavaScript files with readable commit blobs.',
|