@holmes-lab/holmes-kit 0.28.0 → 0.30.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 +100 -0
- package/README.md +24 -21
- 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/codex-toml.d.ts +23 -1
- package/dist/holmes/cli/codex-toml.js +151 -4
- package/dist/holmes/cli/doctor.d.ts +11 -1
- package/dist/holmes/cli/doctor.js +113 -13
- package/dist/holmes/cli/init.d.ts +2 -0
- package/dist/holmes/cli/init.js +20 -40
- package/dist/holmes/cli/interactive-prompt.js +2 -2
- package/dist/holmes/cli/worktree-readiness.d.ts +1 -0
- package/dist/holmes/cli/worktree-readiness.js +17 -3
- package/dist/holmes/cpg/ast-mutation.d.ts +2 -0
- package/dist/holmes/cpg/ast-mutation.js +4 -2
- package/dist/holmes/cpg/foundation/cfg.d.ts +10 -0
- package/dist/holmes/cpg/foundation/cfg.js +27 -1
- package/dist/holmes/governance/autonomy.d.ts +9 -0
- package/dist/holmes/governance/autonomy.js +28 -1
- package/dist/holmes/hooks/rtm-refresh-child.d.ts +22 -1
- package/dist/holmes/hooks/rtm-refresh-child.js +100 -18
- package/dist/holmes/hooks/rtm-refresh.d.ts +20 -1
- package/dist/holmes/hooks/rtm-refresh.js +56 -15
- 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 +21 -0
- package/dist/holmes/mcp/approval-commit.js +92 -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 +5 -2
- package/dist/holmes/mcp/handlers/graph-operations.d.ts +24 -1
- package/dist/holmes/mcp/handlers/graph-operations.js +38 -6
- package/dist/holmes/mcp/handlers/maintenance-evidence.js +1 -1
- package/dist/holmes/mcp/handlers/requirement-triage.d.ts +142 -0
- package/dist/holmes/mcp/handlers/requirement-triage.js +220 -0
- package/dist/holmes/mcp/handlers/review-evidence.d.ts +2 -1
- package/dist/holmes/mcp/handlers/review-evidence.js +9 -5
- package/dist/holmes/mcp/handlers/slice-orchestration.d.ts +7 -0
- package/dist/holmes/mcp/handlers/slice-orchestration.js +8 -1
- package/dist/holmes/mcp/handlers/spec-approval.d.ts +26 -2
- package/dist/holmes/mcp/handlers/spec-approval.js +72 -47
- package/dist/holmes/mcp/handlers/spec-authoring.js +20 -2
- package/dist/holmes/mcp/handlers.d.ts +153 -0
- package/dist/holmes/mcp/handlers.js +67 -13
- 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 +45 -0
- package/dist/holmes/mcp/requirement-triage-evidence.js +149 -0
- package/dist/holmes/mcp/server.js +5 -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 +44 -1
- package/dist/holmes/refresh/freshness-coordinator.d.ts +67 -0
- package/dist/holmes/refresh/freshness-coordinator.js +230 -0
- package/dist/holmes/review/condition-hunk-replay.d.ts +45 -0
- package/dist/holmes/review/condition-hunk-replay.js +122 -0
- package/dist/holmes/review/condition-hunk-resolution.d.ts +65 -0
- package/dist/holmes/review/condition-hunk-resolution.js +258 -0
- package/dist/holmes/review/requirement-triage-benchmark.d.ts +45 -0
- package/dist/holmes/review/requirement-triage-benchmark.js +72 -0
- 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/requirement-triage.d.ts +61 -0
- package/dist/holmes/review/requirement-triage.js +143 -0
- package/dist/holmes/review/scope.js +6 -1
- package/dist/holmes/review/test-outcomes.d.ts +28 -0
- package/dist/holmes/review/test-outcomes.js +90 -1
- package/dist/holmes/semantic/local-model.d.ts +3 -3
- package/dist/holmes/semantic/local-model.js +10 -12
- package/dist/holmes/semantic/model-cache.d.ts +15 -6
- package/dist/holmes/semantic/model-cache.js +77 -21
- package/dist/holmes/semantic/tier.d.ts +5 -1
- package/dist/holmes/semantic/tier.js +7 -6
- package/dist/holmes/semantic/vector-coverage.d.ts +17 -0
- package/dist/holmes/semantic/vector-coverage.js +37 -0
- package/docs/install-guide.md +19 -24
- package/package.json +1 -1
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { ReplayCase } from './replay-corpus';
|
|
2
|
+
import { type HunkResolution } from './condition-hunk-resolution';
|
|
3
|
+
export interface ConditionHunkReplayReport {
|
|
4
|
+
schema: 'condition-hunk-replay/1';
|
|
5
|
+
commits: string[];
|
|
6
|
+
caseCount: number;
|
|
7
|
+
raw: {
|
|
8
|
+
files: number;
|
|
9
|
+
symbols: number;
|
|
10
|
+
candidateSymbols: number;
|
|
11
|
+
hunks: number;
|
|
12
|
+
resolved: number;
|
|
13
|
+
ambiguous: number;
|
|
14
|
+
unavailable: number;
|
|
15
|
+
relaxed: number;
|
|
16
|
+
narrowed: number;
|
|
17
|
+
unknown: number;
|
|
18
|
+
};
|
|
19
|
+
candidateReduction: {
|
|
20
|
+
hunkToResolved: number | null;
|
|
21
|
+
};
|
|
22
|
+
timingMs: {
|
|
23
|
+
baseline: number;
|
|
24
|
+
conditionResolution: number;
|
|
25
|
+
overheadPct: number | null;
|
|
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
|
+
}>;
|
|
38
|
+
elapsedMs: number;
|
|
39
|
+
limitations: string[];
|
|
40
|
+
}
|
|
41
|
+
/** Replays caller-selected commits only; it never checks out, writes a cache, or inspects another repository. */
|
|
42
|
+
export declare function replayConditionHunks(input: {
|
|
43
|
+
root: string;
|
|
44
|
+
cases: readonly ReplayCase[];
|
|
45
|
+
}): Promise<ConditionHunkReplayReport>;
|
|
@@ -0,0 +1,122 @@
|
|
|
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.replayConditionHunks = replayConditionHunks;
|
|
37
|
+
// @implements A-SPEC-717
|
|
38
|
+
// @implements A-SPEC-661
|
|
39
|
+
/** Historical, read-only measurement for the condition-hunk advisory. */
|
|
40
|
+
const node_child_process_1 = require("node:child_process");
|
|
41
|
+
const path = __importStar(require("node:path"));
|
|
42
|
+
const language_parser_1 = require("../cpg/language-parser");
|
|
43
|
+
const condition_hunk_resolution_1 = require("./condition-hunk-resolution");
|
|
44
|
+
const SAFE_COMMIT = /^[0-9a-f]{7,64}$/;
|
|
45
|
+
const sourceLanguage = (file) => {
|
|
46
|
+
if (/\.(ts|mts|cts)$/.test(file))
|
|
47
|
+
return 'typescript';
|
|
48
|
+
if (/\.(tsx|js|jsx|mjs|cjs)$/.test(file))
|
|
49
|
+
return 'tsx';
|
|
50
|
+
return null;
|
|
51
|
+
};
|
|
52
|
+
const safePath = (file) => file !== '' && !path.isAbsolute(file) && !file.split(/[\\/]/).includes('..');
|
|
53
|
+
const git = (root, args) => (0, node_child_process_1.execFileSync)('git', ['-C', root, ...args], {
|
|
54
|
+
encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'], maxBuffer: 16 * 1024 * 1024,
|
|
55
|
+
});
|
|
56
|
+
/** Replays caller-selected commits only; it never checks out, writes a cache, or inspects another repository. */
|
|
57
|
+
async function replayConditionHunks(input) {
|
|
58
|
+
const started = Date.now();
|
|
59
|
+
const parser = new language_parser_1.TreeSitterTsParser();
|
|
60
|
+
const resolutions = [];
|
|
61
|
+
const records = [];
|
|
62
|
+
let files = 0, symbols = 0, candidateSymbols = 0, baselineMs = 0, conditionResolutionMs = 0;
|
|
63
|
+
const commits = [];
|
|
64
|
+
for (const replayCase of input.cases) {
|
|
65
|
+
if (!SAFE_COMMIT.test(replayCase.commit))
|
|
66
|
+
throw new Error('condition replay requires a hexadecimal commit id');
|
|
67
|
+
commits.push(replayCase.commit);
|
|
68
|
+
for (const file of replayCase.files) {
|
|
69
|
+
const language = sourceLanguage(file);
|
|
70
|
+
if (language === null || !safePath(file))
|
|
71
|
+
continue;
|
|
72
|
+
let source, diff;
|
|
73
|
+
const baselineStart = Date.now();
|
|
74
|
+
try {
|
|
75
|
+
source = git(input.root, ['show', `${replayCase.commit}:${file}`]);
|
|
76
|
+
diff = git(input.root, ['diff', '--unified=0', `${replayCase.commit}^`, replayCase.commit, '--', file]);
|
|
77
|
+
}
|
|
78
|
+
catch {
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
const hunks = (0, condition_hunk_resolution_1.parseUnifiedZeroDiff)(diff);
|
|
82
|
+
if (hunks.length === 0)
|
|
83
|
+
continue;
|
|
84
|
+
const rows = parser.extractSymbols(source, language).map((symbol) => ({ file, name: symbol.qualifiedName, startLine: symbol.startLine, endLine: symbol.endLine }));
|
|
85
|
+
baselineMs += Date.now() - baselineStart;
|
|
86
|
+
files++;
|
|
87
|
+
symbols += rows.length;
|
|
88
|
+
candidateSymbols += hunks.reduce((total, hunk) => total + rows.filter((symbol) => symbol.startLine <= hunk.startLine && symbol.endLine >= hunk.endLine).length, 0);
|
|
89
|
+
const conditionStart = Date.now();
|
|
90
|
+
const resolvedRows = await (0, condition_hunk_resolution_1.resolveConditionHunksFromSources)({ diff, sources: [{ file, source }], symbols: rows });
|
|
91
|
+
resolutions.push(...resolvedRows);
|
|
92
|
+
records.push(...resolvedRows.map((row) => ({ commit: replayCase.commit, file, state: row.state, direction: row.direction,
|
|
93
|
+
...(row.symbol === undefined ? {} : { symbol: row.symbol }),
|
|
94
|
+
...(row.conditionText === undefined ? {} : { conditionText: row.conditionText }),
|
|
95
|
+
...(row.reason === undefined ? {} : { reason: row.reason }),
|
|
96
|
+
hunk: { startLine: row.hunk.startLine, endLine: row.hunk.endLine, ...(row.hunk.deletionOnly ? { deletionOnly: true } : {}) },
|
|
97
|
+
})));
|
|
98
|
+
conditionResolutionMs += Date.now() - conditionStart;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
const resolved = resolutions.filter((row) => row.state === 'resolved').length;
|
|
102
|
+
const ambiguous = resolutions.filter((row) => row.state === 'ambiguous').length;
|
|
103
|
+
const unavailable = resolutions.filter((row) => row.state === 'unavailable').length;
|
|
104
|
+
const relaxed = resolutions.filter((row) => row.direction === 'relaxed').length;
|
|
105
|
+
const narrowed = resolutions.filter((row) => row.direction === 'narrowed').length;
|
|
106
|
+
const unknown = resolutions.filter((row) => row.direction === 'unknown').length;
|
|
107
|
+
return {
|
|
108
|
+
schema: 'condition-hunk-replay/1', commits, caseCount: input.cases.length,
|
|
109
|
+
raw: { files, symbols, candidateSymbols, hunks: resolutions.length, resolved, ambiguous, unavailable, relaxed, narrowed, unknown },
|
|
110
|
+
candidateReduction: { hunkToResolved: candidateSymbols === 0 ? null : 1 - resolved / candidateSymbols },
|
|
111
|
+
timingMs: { baseline: baselineMs, conditionResolution: conditionResolutionMs,
|
|
112
|
+
overheadPct: baselineMs === 0 ? null : conditionResolutionMs / baselineMs * 100 },
|
|
113
|
+
records,
|
|
114
|
+
elapsedMs: Date.now() - started,
|
|
115
|
+
limitations: [
|
|
116
|
+
'This measures only caller-selected TypeScript/JavaScript files with readable commit blobs.',
|
|
117
|
+
'A resolved span is provenance coverage, not a precision or correctness claim.',
|
|
118
|
+
'Direction is reported only for a same-position changed control-flow predicate with a locally monotonic syntax rule; every other hunk remains unknown.',
|
|
119
|
+
'The replay is read-only and does not evaluate a gate, mutate changedFiles, or run tests.',
|
|
120
|
+
],
|
|
121
|
+
};
|
|
122
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
export type ConditionDirection = 'relaxed' | 'narrowed' | 'unknown';
|
|
2
|
+
export type HunkResolutionState = 'resolved' | 'ambiguous' | 'unavailable';
|
|
3
|
+
export interface UnifiedZeroHunk {
|
|
4
|
+
file: string;
|
|
5
|
+
startLine: number;
|
|
6
|
+
endLine: number;
|
|
7
|
+
deletionOnly?: boolean;
|
|
8
|
+
/** Exact changed lines are evidence only; resolution never expands the changed line range. */
|
|
9
|
+
removedLines?: string[];
|
|
10
|
+
addedLines?: string[];
|
|
11
|
+
}
|
|
12
|
+
export interface HunkSymbol {
|
|
13
|
+
file: string;
|
|
14
|
+
name: string;
|
|
15
|
+
startLine: number;
|
|
16
|
+
endLine: number;
|
|
17
|
+
}
|
|
18
|
+
export interface ConditionBranch {
|
|
19
|
+
file: string;
|
|
20
|
+
startLine: number;
|
|
21
|
+
endLine: number;
|
|
22
|
+
conditionText?: string;
|
|
23
|
+
beforeConditionText?: string;
|
|
24
|
+
branchLabel: 'true' | 'false' | 'case' | 'default' | string;
|
|
25
|
+
astKind?: string;
|
|
26
|
+
}
|
|
27
|
+
export interface HunkResolution {
|
|
28
|
+
file: string;
|
|
29
|
+
hunk: UnifiedZeroHunk;
|
|
30
|
+
symbol?: string;
|
|
31
|
+
branch?: ConditionBranch;
|
|
32
|
+
conditionText?: string;
|
|
33
|
+
direction: ConditionDirection;
|
|
34
|
+
state: HunkResolutionState;
|
|
35
|
+
reason?: string;
|
|
36
|
+
candidates?: ConditionBranch[];
|
|
37
|
+
}
|
|
38
|
+
/** Parse file headers, @@ ranges, and exact changed lines; body text never widens the changed region. */
|
|
39
|
+
export declare function parseUnifiedZeroDiff(diff: string): UnifiedZeroHunk[];
|
|
40
|
+
/** Classifies only syntactic changes with a local, monotonic meaning; all other changes are unknown. */
|
|
41
|
+
export declare function classifyConditionDirection(before: string | undefined, after: string | undefined): ConditionDirection;
|
|
42
|
+
export interface ResolveConditionHunksInput {
|
|
43
|
+
hunks: readonly UnifiedZeroHunk[];
|
|
44
|
+
symbols: readonly HunkSymbol[];
|
|
45
|
+
branches: readonly ConditionBranch[];
|
|
46
|
+
/** This first advisory implementation preserves TS/JS branch source spans only. */
|
|
47
|
+
language?: string;
|
|
48
|
+
}
|
|
49
|
+
/** Intersects hunk → narrowest symbol → branch span, retaining ties instead of inventing a winner. */
|
|
50
|
+
export declare function resolveConditionHunks(input: ResolveConditionHunksInput): HunkResolution[];
|
|
51
|
+
export interface ConditionHunkSource {
|
|
52
|
+
file: string;
|
|
53
|
+
source: string;
|
|
54
|
+
}
|
|
55
|
+
export interface ResolveConditionHunksFromSourcesInput {
|
|
56
|
+
diff: string;
|
|
57
|
+
sources: readonly ConditionHunkSource[];
|
|
58
|
+
symbols: readonly HunkSymbol[];
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* The explicit heavy advisory path: parse only caller-supplied TS/JS source, derive CFG predicate
|
|
62
|
+
* spans, and feed the same conservative resolver. It is intentionally separate from CpgScanner's
|
|
63
|
+
* synchronous hot path and cannot alter changedFiles, a graph, a gate, or a cache.
|
|
64
|
+
*/
|
|
65
|
+
export declare function resolveConditionHunksFromSources(input: ResolveConditionHunksFromSourcesInput): Promise<HunkResolution[]>;
|