@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,258 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseUnifiedZeroDiff = parseUnifiedZeroDiff;
|
|
4
|
+
exports.classifyConditionDirection = classifyConditionDirection;
|
|
5
|
+
exports.resolveConditionHunks = resolveConditionHunks;
|
|
6
|
+
exports.resolveConditionHunksFromSources = resolveConditionHunksFromSources;
|
|
7
|
+
// @implements A-SPEC-717
|
|
8
|
+
// @implements A-SPEC-661
|
|
9
|
+
/** Pure, advisory-only resolution from a supplied zero-context diff to declared source spans. */
|
|
10
|
+
const ast_store_1 = require("../cpg/foundation/ast-store");
|
|
11
|
+
const cfg_1 = require("../cpg/foundation/cfg");
|
|
12
|
+
const ast_mutation_1 = require("../cpg/ast-mutation");
|
|
13
|
+
const normalPath = (raw) => raw.replace(/\\/g, '/').replace(/^[ab]\//, '');
|
|
14
|
+
const contains = (start, end, lineStart, lineEnd) => start <= lineStart && end >= lineEnd;
|
|
15
|
+
const overlaps = (start, end, lineStart, lineEnd) => start <= lineEnd && end >= lineStart;
|
|
16
|
+
/** Parse file headers, @@ ranges, and exact changed lines; body text never widens the changed region. */
|
|
17
|
+
function parseUnifiedZeroDiff(diff) {
|
|
18
|
+
if (typeof diff !== 'string')
|
|
19
|
+
return [];
|
|
20
|
+
let file = null;
|
|
21
|
+
let current = null;
|
|
22
|
+
const hunks = [];
|
|
23
|
+
for (const line of diff.split(/\r?\n/)) {
|
|
24
|
+
if (line.startsWith('+++ ')) {
|
|
25
|
+
const next = line.slice(4).trim();
|
|
26
|
+
file = next === '/dev/null' ? null : normalPath(next);
|
|
27
|
+
current = null;
|
|
28
|
+
continue;
|
|
29
|
+
}
|
|
30
|
+
const match = /^@@ -\d+(?:,(\d+))? \+(\d+)(?:,(\d+))? @@/.exec(line);
|
|
31
|
+
if (match && file !== null) {
|
|
32
|
+
const start = Number(match[2]), added = match[3] === undefined ? 1 : Number(match[3]);
|
|
33
|
+
current = { file, startLine: start, endLine: start + Math.max(added, 1) - 1, ...(added === 0 ? { deletionOnly: true } : {}),
|
|
34
|
+
removedLines: [], addedLines: [] };
|
|
35
|
+
hunks.push(current);
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
if (current === null)
|
|
39
|
+
continue;
|
|
40
|
+
if (line.startsWith('-') && !line.startsWith('--- '))
|
|
41
|
+
current.removedLines.push(line.slice(1));
|
|
42
|
+
if (line.startsWith('+') && !line.startsWith('+++ '))
|
|
43
|
+
current.addedLines.push(line.slice(1));
|
|
44
|
+
}
|
|
45
|
+
return hunks;
|
|
46
|
+
}
|
|
47
|
+
const compact = (value) => value.replace(/\s+/g, ' ').trim();
|
|
48
|
+
const count = (value, token) => value.split(token).length - 1;
|
|
49
|
+
/** Remove only parentheses which enclose the whole expression, preserving all inner grouping. */
|
|
50
|
+
function unwrapOuterParens(value) {
|
|
51
|
+
let text = compact(value);
|
|
52
|
+
while (text.startsWith('(') && text.endsWith(')')) {
|
|
53
|
+
let depth = 0;
|
|
54
|
+
let encloses = true;
|
|
55
|
+
for (let index = 0; index < text.length; index++) {
|
|
56
|
+
if (text[index] === '(')
|
|
57
|
+
depth++;
|
|
58
|
+
if (text[index] === ')')
|
|
59
|
+
depth--;
|
|
60
|
+
if (depth === 0 && index < text.length - 1) {
|
|
61
|
+
encloses = false;
|
|
62
|
+
break;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
if (!encloses || depth !== 0)
|
|
66
|
+
break;
|
|
67
|
+
text = compact(text.slice(1, -1));
|
|
68
|
+
}
|
|
69
|
+
return text;
|
|
70
|
+
}
|
|
71
|
+
/** Extract a control-flow predicate from one changed line without attempting expression parsing. */
|
|
72
|
+
function predicateInChangedLine(line) {
|
|
73
|
+
const keyword = /\b(?:if|while|switch)\s*\(/.exec(line);
|
|
74
|
+
if (keyword === null)
|
|
75
|
+
return undefined;
|
|
76
|
+
const open = keyword.index + keyword[0].lastIndexOf('(');
|
|
77
|
+
let depth = 0;
|
|
78
|
+
for (let index = open; index < line.length; index++) {
|
|
79
|
+
if (line[index] === '(')
|
|
80
|
+
depth++;
|
|
81
|
+
if (line[index] === ')')
|
|
82
|
+
depth--;
|
|
83
|
+
if (depth === 0)
|
|
84
|
+
return line.slice(open + 1, index);
|
|
85
|
+
}
|
|
86
|
+
return undefined;
|
|
87
|
+
}
|
|
88
|
+
/** A multiline hunk is usable only when it contains one balanced, complete control predicate. */
|
|
89
|
+
function completePredicateInChangedLines(lines) {
|
|
90
|
+
if (!Array.isArray(lines) || lines.length === 0)
|
|
91
|
+
return undefined;
|
|
92
|
+
const text = lines.join('\n');
|
|
93
|
+
const keywords = [...text.matchAll(/\b(?:if|while|switch)\s*\(/g)];
|
|
94
|
+
if (keywords.length !== 1)
|
|
95
|
+
return undefined;
|
|
96
|
+
const keyword = keywords[0];
|
|
97
|
+
const open = keyword.index + keyword[0].lastIndexOf('(');
|
|
98
|
+
let depth = 0;
|
|
99
|
+
for (let index = open; index < text.length; index++) {
|
|
100
|
+
if (text[index] === '(')
|
|
101
|
+
depth++;
|
|
102
|
+
if (text[index] === ')')
|
|
103
|
+
depth--;
|
|
104
|
+
if (depth < 0)
|
|
105
|
+
return undefined;
|
|
106
|
+
if (depth === 0) {
|
|
107
|
+
const predicate = text.slice(open + 1, index);
|
|
108
|
+
return predicate.trim() === '' ? undefined : predicate;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
return undefined;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Match a changed after-predicate to the CFG span, then take only the same-position removed
|
|
115
|
+
* predicate. Multiple matches, line-count changes, and non-control statements deliberately stay
|
|
116
|
+
* unknown: a zero-context diff cannot establish their correspondence.
|
|
117
|
+
*/
|
|
118
|
+
function beforeConditionFromHunk(hunk, afterCondition) {
|
|
119
|
+
if (afterCondition === undefined || hunk.addedLines === undefined || hunk.removedLines === undefined)
|
|
120
|
+
return undefined;
|
|
121
|
+
const expected = unwrapOuterParens(afterCondition);
|
|
122
|
+
if (hunk.addedLines.length === hunk.removedLines.length) {
|
|
123
|
+
const matches = hunk.addedLines.map(predicateInChangedLine)
|
|
124
|
+
.map((predicate, index) => ({ predicate, index }))
|
|
125
|
+
.filter(({ predicate }) => predicate !== undefined && unwrapOuterParens(predicate) === expected);
|
|
126
|
+
if (matches.length === 1)
|
|
127
|
+
return predicateInChangedLine(hunk.removedLines[matches[0].index]);
|
|
128
|
+
}
|
|
129
|
+
const added = completePredicateInChangedLines(hunk.addedLines);
|
|
130
|
+
const removed = completePredicateInChangedLines(hunk.removedLines);
|
|
131
|
+
return added !== undefined && removed !== undefined && unwrapOuterParens(added) === expected ? removed : undefined;
|
|
132
|
+
}
|
|
133
|
+
/** Classifies only syntactic changes with a local, monotonic meaning; all other changes are unknown. */
|
|
134
|
+
function classifyConditionDirection(before, after) {
|
|
135
|
+
if (typeof before !== 'string' || typeof after !== 'string')
|
|
136
|
+
return 'unknown';
|
|
137
|
+
const left = unwrapOuterParens(before), right = unwrapOuterParens(after);
|
|
138
|
+
if (left === '' || right === '' || left === right)
|
|
139
|
+
return 'unknown';
|
|
140
|
+
const logicalWidening = ast_mutation_1.MUTATION_MAP.logical['&&']?.includes('||') === true;
|
|
141
|
+
const unaryRemoval = ast_mutation_1.MUTATION_MAP.unary['!']?.includes('EMPTY') === true;
|
|
142
|
+
if (logicalWidening && (count(right, '||') > count(left, '||') || count(right, '&&') < count(left, '&&')))
|
|
143
|
+
return 'relaxed';
|
|
144
|
+
if (unaryRemoval && count(right, '!') < count(left, '!'))
|
|
145
|
+
return 'relaxed';
|
|
146
|
+
// A conjunction can inherit a direction from exactly one changed simple term. Do not split OR
|
|
147
|
+
// expressions or reorder terms: both require semantic reasoning this advisory does not claim.
|
|
148
|
+
if (!left.includes('||') && !right.includes('||')) {
|
|
149
|
+
const oldTerms = left.split(/\s*&&\s*/), newTerms = right.split(/\s*&&\s*/);
|
|
150
|
+
if (oldTerms.length > 1 && oldTerms.length === newTerms.length) {
|
|
151
|
+
const changed = oldTerms.map((term, index) => ({ term, next: newTerms[index] })).filter(({ term, next }) => term !== next);
|
|
152
|
+
if (changed.length === 1)
|
|
153
|
+
return classifyConditionDirection(changed[0].term, changed[0].next);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
const relation = /^(.+?)\s*(<=|<|>=|>)\s*(-?\d+(?:\.\d+)?)$/.exec(left);
|
|
157
|
+
const next = /^(.+?)\s*(<=|<|>=|>)\s*(-?\d+(?:\.\d+)?)$/.exec(right);
|
|
158
|
+
if (!relation || !next || compact(relation[1]) !== compact(next[1]))
|
|
159
|
+
return 'unknown';
|
|
160
|
+
const oldValue = Number(relation[3]), newValue = Number(next[3]);
|
|
161
|
+
// The mutation generator stores forward replacement choices only. Direction comparison needs
|
|
162
|
+
// both sides of that vocabulary (for example, `<=` → `<`) plus a same-operator threshold move.
|
|
163
|
+
const relationMutation = relation[2] === next[2]
|
|
164
|
+
|| ast_mutation_1.MUTATION_MAP.relational[relation[2]]?.includes(next[2]) === true
|
|
165
|
+
|| ast_mutation_1.MUTATION_MAP.relational[next[2]]?.includes(relation[2]) === true;
|
|
166
|
+
if (!relationMutation)
|
|
167
|
+
return 'unknown';
|
|
168
|
+
if ((relation[2] === '<' && next[2] === '<=') || (relation[2] === '>' && next[2] === '>='))
|
|
169
|
+
return 'relaxed';
|
|
170
|
+
if ((relation[2] === '<=' && next[2] === '<') || (relation[2] === '>=' && next[2] === '>'))
|
|
171
|
+
return 'narrowed';
|
|
172
|
+
if (['<', '<='].includes(relation[2]) && ['<', '<='].includes(next[2]))
|
|
173
|
+
return newValue > oldValue ? 'relaxed' : newValue < oldValue ? 'narrowed' : 'unknown';
|
|
174
|
+
if (['>', '>='].includes(relation[2]) && ['>', '>='].includes(next[2]))
|
|
175
|
+
return newValue < oldValue ? 'relaxed' : newValue > oldValue ? 'narrowed' : 'unknown';
|
|
176
|
+
return 'unknown';
|
|
177
|
+
}
|
|
178
|
+
/** Intersects hunk → narrowest symbol → branch span, retaining ties instead of inventing a winner. */
|
|
179
|
+
function resolveConditionHunks(input) {
|
|
180
|
+
const supported = input.language === undefined || ['typescript', 'tsx', 'javascript', 'jsx'].includes(input.language);
|
|
181
|
+
return input.hunks.map((hunk) => {
|
|
182
|
+
if (!supported)
|
|
183
|
+
return { file: hunk.file, hunk, direction: 'unknown', state: 'unavailable', reason: 'unsupported-language' };
|
|
184
|
+
if (hunk.deletionOnly)
|
|
185
|
+
return { file: hunk.file, hunk, direction: 'unknown', state: 'unavailable', reason: 'deletion-only-hunk' };
|
|
186
|
+
const enclosing = input.symbols.filter((symbol) => normalPath(symbol.file) === normalPath(hunk.file)
|
|
187
|
+
&& contains(symbol.startLine, symbol.endLine, hunk.startLine, hunk.endLine));
|
|
188
|
+
if (enclosing.length === 0)
|
|
189
|
+
return { file: hunk.file, hunk, direction: 'unknown', state: 'unavailable', reason: 'no-containing-symbol' };
|
|
190
|
+
const width = Math.min(...enclosing.map((symbol) => symbol.endLine - symbol.startLine));
|
|
191
|
+
const symbols = enclosing.filter((symbol) => symbol.endLine - symbol.startLine === width);
|
|
192
|
+
if (symbols.length !== 1)
|
|
193
|
+
return { file: hunk.file, hunk, direction: 'unknown', state: 'ambiguous', reason: 'tied-symbols' };
|
|
194
|
+
const symbol = symbols[0];
|
|
195
|
+
const matchingBranches = input.branches.filter((branch) => normalPath(branch.file) === normalPath(hunk.file)
|
|
196
|
+
&& contains(symbol.startLine, symbol.endLine, branch.startLine, branch.endLine)
|
|
197
|
+
&& overlaps(branch.startLine, branch.endLine, hunk.startLine, hunk.endLine))
|
|
198
|
+
.sort((a, b) => a.startLine - b.startLine || a.endLine - b.endLine
|
|
199
|
+
|| (a.branchLabel === 'true' ? -1 : b.branchLabel === 'true' ? 1 : a.branchLabel.localeCompare(b.branchLabel)));
|
|
200
|
+
// A single predicate normally emits both true and false CFG edges. Those two edges share one
|
|
201
|
+
// source span and are not two competing hunk locations; preserve one stable representative
|
|
202
|
+
// while distinct source spans still remain an explicit ambiguity.
|
|
203
|
+
const byPredicate = new Map();
|
|
204
|
+
for (const branch of matchingBranches) {
|
|
205
|
+
const key = `${branch.startLine}:${branch.endLine}:${branch.conditionText ?? ''}:${branch.astKind ?? ''}`;
|
|
206
|
+
if (!byPredicate.has(key))
|
|
207
|
+
byPredicate.set(key, branch);
|
|
208
|
+
}
|
|
209
|
+
const branches = [...byPredicate.values()];
|
|
210
|
+
if (branches.length === 0)
|
|
211
|
+
return { file: hunk.file, hunk, symbol: symbol.name, direction: 'unknown', state: 'unavailable', reason: 'no-condition-span' };
|
|
212
|
+
if (branches.length !== 1)
|
|
213
|
+
return { file: hunk.file, hunk, symbol: symbol.name, direction: 'unknown', state: 'ambiguous', reason: 'tied-condition-spans', candidates: branches };
|
|
214
|
+
const selected = branches[0];
|
|
215
|
+
const requiresCompletePredicate = (hunk.addedLines?.length ?? 0) > 1 || (hunk.removedLines?.length ?? 0) === 0;
|
|
216
|
+
const addedPredicate = completePredicateInChangedLines(hunk.addedLines);
|
|
217
|
+
if (requiresCompletePredicate) {
|
|
218
|
+
if (addedPredicate === undefined)
|
|
219
|
+
return { file: hunk.file, hunk, symbol: symbol.name, direction: 'unknown', state: 'unavailable', reason: 'incomplete-or-multiple-predicate' };
|
|
220
|
+
if (unwrapOuterParens(addedPredicate) !== unwrapOuterParens(selected.conditionText ?? '')) {
|
|
221
|
+
return { file: hunk.file, hunk, symbol: symbol.name, direction: 'unknown', state: 'unavailable', reason: 'predicate-does-not-match-condition' };
|
|
222
|
+
}
|
|
223
|
+
if ((hunk.removedLines?.length ?? 0) > 0 && completePredicateInChangedLines(hunk.removedLines) === undefined) {
|
|
224
|
+
return { file: hunk.file, hunk, symbol: symbol.name, direction: 'unknown', state: 'unavailable', reason: 'incomplete-before-predicate' };
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
const beforeConditionText = selected.beforeConditionText ?? beforeConditionFromHunk(hunk, selected.conditionText);
|
|
228
|
+
const branch = beforeConditionText === undefined ? selected : { ...selected, beforeConditionText };
|
|
229
|
+
return { file: hunk.file, hunk, symbol: symbol.name, branch, conditionText: branch.conditionText,
|
|
230
|
+
direction: classifyConditionDirection(beforeConditionText, branch.conditionText), state: 'resolved' };
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
const lineAt = (source, offset) => source.slice(0, offset).split('\n').length;
|
|
234
|
+
/**
|
|
235
|
+
* The explicit heavy advisory path: parse only caller-supplied TS/JS source, derive CFG predicate
|
|
236
|
+
* spans, and feed the same conservative resolver. It is intentionally separate from CpgScanner's
|
|
237
|
+
* synchronous hot path and cannot alter changedFiles, a graph, a gate, or a cache.
|
|
238
|
+
*/
|
|
239
|
+
async function resolveConditionHunksFromSources(input) {
|
|
240
|
+
const branches = [];
|
|
241
|
+
for (const item of input.sources) {
|
|
242
|
+
const ast = await (0, ast_store_1.parseAst)(item.source, item.file);
|
|
243
|
+
if (ast === null || ast.errorCount > 0 || !['typescript', 'tsx'].includes(ast.lang))
|
|
244
|
+
continue;
|
|
245
|
+
for (const fn of (0, cfg_1.functionsIn)(ast)) {
|
|
246
|
+
const cfg = (0, cfg_1.cfgOf)(ast, fn, item.source);
|
|
247
|
+
if ('unsupported' in cfg)
|
|
248
|
+
continue;
|
|
249
|
+
for (const branch of cfg.conditionBranches ?? []) {
|
|
250
|
+
if (branch.startOffset === undefined || branch.endOffset === undefined)
|
|
251
|
+
continue;
|
|
252
|
+
branches.push({ file: item.file, startLine: lineAt(item.source, branch.startOffset), endLine: lineAt(item.source, branch.endOffset),
|
|
253
|
+
conditionText: branch.conditionText, branchLabel: branch.branchLabel, astKind: branch.astKind });
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
return resolveConditionHunks({ hunks: parseUnifiedZeroDiff(input.diff), symbols: input.symbols, branches });
|
|
258
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Frozen, blind evaluation protocol for requirement triage. The exported input intentionally
|
|
3
|
+
* omits the analyst judgement; scoring joins it only after a prediction has been recorded.
|
|
4
|
+
*/
|
|
5
|
+
import type { RequirementVerdict } from './requirement-triage';
|
|
6
|
+
export interface RequirementTriagePredictionInput {
|
|
7
|
+
id: string;
|
|
8
|
+
prompt: string;
|
|
9
|
+
}
|
|
10
|
+
export interface RequirementTriagePrediction {
|
|
11
|
+
caseId: string;
|
|
12
|
+
verdict: RequirementVerdict;
|
|
13
|
+
candidates: Array<{
|
|
14
|
+
reqId?: string;
|
|
15
|
+
evidenceComplete?: boolean;
|
|
16
|
+
}>;
|
|
17
|
+
elapsedMs: number;
|
|
18
|
+
}
|
|
19
|
+
/** Preregistered protocol: agents receive only this frozen projection before predicting. */
|
|
20
|
+
export declare function frozenRequirementTriageCases(): RequirementTriagePredictionInput[];
|
|
21
|
+
/** Public preregistration; deliberately contains no expected verdict or analyst choice. */
|
|
22
|
+
export declare function requirementTriageHumanModelProtocol(): {
|
|
23
|
+
schema: 'requirement-triage-human-model/1';
|
|
24
|
+
corpusId: 'requirement-triage-blind-v1';
|
|
25
|
+
caseCount: number;
|
|
26
|
+
releaseGate: false;
|
|
27
|
+
metrics: readonly string[];
|
|
28
|
+
analystProcedure: readonly string[];
|
|
29
|
+
};
|
|
30
|
+
export interface RequirementTriageBenchmarkReport {
|
|
31
|
+
sampleSize: number;
|
|
32
|
+
judged: number;
|
|
33
|
+
retrievalCoverage: number | null;
|
|
34
|
+
humanChoiceAgreement: number | null;
|
|
35
|
+
falseReuse: number | null;
|
|
36
|
+
falseNew: number | null;
|
|
37
|
+
evidenceCompleteness: number | null;
|
|
38
|
+
ambiguityPreservation: number | null;
|
|
39
|
+
elapsedMs: {
|
|
40
|
+
median: number | null;
|
|
41
|
+
};
|
|
42
|
+
limitations: string[];
|
|
43
|
+
}
|
|
44
|
+
/** Scores a completed blind run without turning the human comparison into a release gate. */
|
|
45
|
+
export declare function scoreRequirementTriagePredictions(predictions: readonly RequirementTriagePrediction[]): RequirementTriageBenchmarkReport;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.frozenRequirementTriageCases = frozenRequirementTriageCases;
|
|
4
|
+
exports.requirementTriageHumanModelProtocol = requirementTriageHumanModelProtocol;
|
|
5
|
+
exports.scoreRequirementTriagePredictions = scoreRequirementTriagePredictions;
|
|
6
|
+
const CASES = Object.freeze([
|
|
7
|
+
{ input: { id: 'rt-001', prompt: 'existing approved read-only lifecycle advisory' }, expectedVerdict: 'fulfilled', humanChoice: 'REQ-713' },
|
|
8
|
+
{ input: { id: 'rt-002', prompt: 'change evidence persistence digest handling' }, expectedVerdict: 'existing-change', humanChoice: 'REQ-713' },
|
|
9
|
+
{ input: { id: 'rt-003', prompt: 'a distinct governed requirement with no supporting lineage' }, expectedVerdict: 'new', humanChoice: null },
|
|
10
|
+
{ input: { id: 'rt-004', prompt: 'overlapping but contradictory requirements' }, expectedVerdict: 'ambiguous', humanChoice: null },
|
|
11
|
+
{ input: { id: 'rt-005', prompt: 'verified local semantic model preparation already works' }, expectedVerdict: 'fulfilled', humanChoice: 'REQ-712' },
|
|
12
|
+
{ input: { id: 'rt-006', prompt: 'retry local semantic preparation after a corrupt cache' }, expectedVerdict: 'existing-change', humanChoice: 'REQ-712' },
|
|
13
|
+
{ input: { id: 'rt-007', prompt: 'classify a condition hunk through its CFG predicate' }, expectedVerdict: 'existing-change', humanChoice: 'REQ-661' },
|
|
14
|
+
{ input: { id: 'rt-008', prompt: 'govern a previously unseen product capability' }, expectedVerdict: 'new', humanChoice: null },
|
|
15
|
+
{ input: { id: 'rt-009', prompt: 'two approved intents conflict over the same behavior' }, expectedVerdict: 'ambiguous', humanChoice: null },
|
|
16
|
+
{ input: { id: 'rt-010', prompt: 'the workspace binding diagnostic is already fulfilled' }, expectedVerdict: 'fulfilled', humanChoice: 'REQ-703' },
|
|
17
|
+
{ input: { id: 'rt-011', prompt: 'change the coexistence guidance for an existing harness workflow' }, expectedVerdict: 'existing-change', humanChoice: 'REQ-706' },
|
|
18
|
+
{ input: { id: 'rt-012', prompt: 'introduce an unrelated governed data-retention requirement' }, expectedVerdict: 'new', humanChoice: null },
|
|
19
|
+
]);
|
|
20
|
+
/** Preregistered protocol: agents receive only this frozen projection before predicting. */
|
|
21
|
+
function frozenRequirementTriageCases() {
|
|
22
|
+
return CASES.map((entry) => ({ ...entry.input }));
|
|
23
|
+
}
|
|
24
|
+
/** Public preregistration; deliberately contains no expected verdict or analyst choice. */
|
|
25
|
+
function requirementTriageHumanModelProtocol() {
|
|
26
|
+
return Object.freeze({
|
|
27
|
+
schema: 'requirement-triage-human-model/1', corpusId: 'requirement-triage-blind-v1',
|
|
28
|
+
caseCount: CASES.length, releaseGate: false,
|
|
29
|
+
metrics: Object.freeze(['retrievalCoverage', 'humanChoiceAgreement', 'falseReuse', 'falseNew', 'evidenceCompleteness', 'ambiguityPreservation', 'elapsedMs']),
|
|
30
|
+
analystProcedure: Object.freeze([
|
|
31
|
+
'Record a triage prediction from the frozen prompt projection before opening the answer key.',
|
|
32
|
+
'A human analyst independently records a lifecycle verdict and preferred existing requirement, if any.',
|
|
33
|
+
'Join prediction, analyst record, and answer key only after both records are immutable.',
|
|
34
|
+
'Report disagreements and null metrics as gaps; do not use them as a release or edit-gate decision.',
|
|
35
|
+
]),
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
const ratio = (n, d) => d === 0 ? null : n / d;
|
|
39
|
+
const median = (values) => {
|
|
40
|
+
if (values.length === 0)
|
|
41
|
+
return null;
|
|
42
|
+
const sorted = [...values].sort((a, b) => a - b), mid = Math.floor(sorted.length / 2);
|
|
43
|
+
return sorted.length % 2 === 0 ? (sorted[mid - 1] + sorted[mid]) / 2 : sorted[mid];
|
|
44
|
+
};
|
|
45
|
+
/** Scores a completed blind run without turning the human comparison into a release gate. */
|
|
46
|
+
function scoreRequirementTriagePredictions(predictions) {
|
|
47
|
+
const byId = new Map(predictions.map((prediction) => [prediction.caseId, prediction]));
|
|
48
|
+
const judged = CASES.flatMap((entry) => {
|
|
49
|
+
const prediction = byId.get(entry.input.id);
|
|
50
|
+
return prediction ? [{ entry, prediction }] : [];
|
|
51
|
+
});
|
|
52
|
+
const expectedReuse = judged.filter(({ entry }) => entry.expectedVerdict === 'fulfilled' || entry.expectedVerdict === 'existing-change');
|
|
53
|
+
const expectedNew = judged.filter(({ entry }) => entry.expectedVerdict === 'new');
|
|
54
|
+
const expectedAmbiguous = judged.filter(({ entry }) => entry.expectedVerdict === 'ambiguous');
|
|
55
|
+
const withHumanChoice = judged.filter(({ entry }) => entry.humanChoice !== null);
|
|
56
|
+
return {
|
|
57
|
+
sampleSize: predictions.length,
|
|
58
|
+
judged: judged.length,
|
|
59
|
+
retrievalCoverage: ratio(judged.filter(({ entry, prediction }) => entry.humanChoice === null || prediction.candidates.some((candidate) => candidate.reqId === entry.humanChoice)).length, judged.length),
|
|
60
|
+
humanChoiceAgreement: ratio(withHumanChoice.filter(({ entry, prediction }) => prediction.candidates[0]?.reqId === entry.humanChoice).length, withHumanChoice.length),
|
|
61
|
+
falseReuse: ratio(expectedNew.filter(({ prediction }) => prediction.verdict === 'fulfilled' || prediction.verdict === 'existing-change').length, expectedNew.length),
|
|
62
|
+
falseNew: ratio(expectedReuse.filter(({ prediction }) => prediction.verdict === 'new').length, expectedReuse.length),
|
|
63
|
+
evidenceCompleteness: ratio(judged.filter(({ prediction }) => prediction.candidates.every((candidate) => candidate.evidenceComplete === true)).length, judged.length),
|
|
64
|
+
ambiguityPreservation: ratio(expectedAmbiguous.filter(({ prediction }) => prediction.verdict === 'ambiguous').length, expectedAmbiguous.length),
|
|
65
|
+
elapsedMs: { median: median(judged.map(({ prediction }) => prediction.elapsedMs).filter(Number.isFinite)) },
|
|
66
|
+
limitations: [
|
|
67
|
+
'Blind inputs omit expected verdict and human choice until after prediction recording.',
|
|
68
|
+
'This frozen corpus is a comparison and gap-reporting instrument, not a human-superiority or release-gate claim.',
|
|
69
|
+
'Impact-analysis benchmark results are excluded from requirement-triage metrics.',
|
|
70
|
+
],
|
|
71
|
+
};
|
|
72
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import type { RequirementVerdict } from './requirement-triage';
|
|
2
|
+
export type RecordKind = 'analyst' | 'prediction';
|
|
3
|
+
export interface AnalystTriageRecord {
|
|
4
|
+
analyst: string;
|
|
5
|
+
caseId: string;
|
|
6
|
+
verdict: RequirementVerdict;
|
|
7
|
+
preferredReqId?: string;
|
|
8
|
+
elapsedMs: number;
|
|
9
|
+
evidenceComplete?: boolean;
|
|
10
|
+
}
|
|
11
|
+
export interface ProductTriageRecord {
|
|
12
|
+
caseId: string;
|
|
13
|
+
verdict: RequirementVerdict;
|
|
14
|
+
candidates: Array<{
|
|
15
|
+
reqId?: string;
|
|
16
|
+
evidenceComplete?: boolean;
|
|
17
|
+
}>;
|
|
18
|
+
elapsedMs: number;
|
|
19
|
+
}
|
|
20
|
+
export interface FrozenRequirementTriageRecords<T extends AnalystTriageRecord | ProductTriageRecord> {
|
|
21
|
+
schema: 'requirement-triage-records/1';
|
|
22
|
+
kind: RecordKind;
|
|
23
|
+
caseIds: readonly string[];
|
|
24
|
+
records: readonly T[];
|
|
25
|
+
digest: string;
|
|
26
|
+
}
|
|
27
|
+
export interface AnswerKeyEntry {
|
|
28
|
+
verdict: RequirementVerdict;
|
|
29
|
+
preferredReqId?: string;
|
|
30
|
+
}
|
|
31
|
+
type Metric = {
|
|
32
|
+
numerator: number;
|
|
33
|
+
denominator: number;
|
|
34
|
+
value: number | null;
|
|
35
|
+
unavailable?: string;
|
|
36
|
+
};
|
|
37
|
+
export interface HumanModelMeasurementReport {
|
|
38
|
+
analystCount: number;
|
|
39
|
+
caseCount: number;
|
|
40
|
+
metrics: {
|
|
41
|
+
retrievalCoverage: Metric;
|
|
42
|
+
humanChoiceAgreement: Metric;
|
|
43
|
+
falseReuse: Metric;
|
|
44
|
+
falseNew: Metric;
|
|
45
|
+
evidenceCompleteness: Metric;
|
|
46
|
+
ambiguityPreservation: Metric;
|
|
47
|
+
medianElapsedMs: {
|
|
48
|
+
value: number | null;
|
|
49
|
+
denominator: number;
|
|
50
|
+
unavailable?: string;
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
conclusion: string;
|
|
54
|
+
}
|
|
55
|
+
/** Validate and content-address independent records before joining evaluator-only truth. */
|
|
56
|
+
export declare function freezeRequirementTriageRecords<T extends AnalystTriageRecord | ProductTriageRecord>(kind: RecordKind, caseIds: readonly string[], input: readonly T[]): FrozenRequirementTriageRecords<T>;
|
|
57
|
+
/** Join frozen independent records; answer key fields stay evaluator-only. */
|
|
58
|
+
export declare function joinRequirementTriageHumanRecords(analysts: FrozenRequirementTriageRecords<AnalystTriageRecord>, predictions: FrozenRequirementTriageRecords<ProductTriageRecord>, answerKey: Readonly<Record<string, AnswerKeyEntry>>): HumanModelMeasurementReport;
|
|
59
|
+
export {};
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.freezeRequirementTriageRecords = freezeRequirementTriageRecords;
|
|
4
|
+
exports.joinRequirementTriageHumanRecords = joinRequirementTriageHumanRecords;
|
|
5
|
+
// @implements A-SPEC-715
|
|
6
|
+
const node_crypto_1 = require("node:crypto");
|
|
7
|
+
const VERDICTS = new Set(['fulfilled', 'existing-change', 'new', 'ambiguous']);
|
|
8
|
+
const ANSWER_KEY_FIELDS = new Set(['expectedVerdict', 'humanChoice', 'answerKey', 'expectedChoice']);
|
|
9
|
+
const ANALYST_FIELDS = new Set(['analyst', 'caseId', 'verdict', 'preferredReqId', 'elapsedMs', 'evidenceComplete']);
|
|
10
|
+
const PREDICTION_FIELDS = new Set(['caseId', 'verdict', 'candidates', 'elapsedMs']);
|
|
11
|
+
const stable = (value) => JSON.stringify(value);
|
|
12
|
+
const digest = (value) => 'sha256:' + (0, node_crypto_1.createHash)('sha256').update(stable(value)).digest('hex');
|
|
13
|
+
const ratio = (numerator, denominator, unavailable) => denominator ? { numerator, denominator, value: numerator / denominator } : { numerator, denominator, value: null, unavailable };
|
|
14
|
+
const copy = (value) => JSON.parse(JSON.stringify(value));
|
|
15
|
+
function validateCandidate(candidate, caseId) {
|
|
16
|
+
if (!candidate || typeof candidate !== 'object' || Array.isArray(candidate))
|
|
17
|
+
throw new Error(`invalid candidate for ${caseId}`);
|
|
18
|
+
const fields = Object.keys(candidate);
|
|
19
|
+
for (const field of fields) {
|
|
20
|
+
if (ANSWER_KEY_FIELDS.has(field))
|
|
21
|
+
throw new Error(`answer-key candidate field is forbidden: ${field}`);
|
|
22
|
+
if (field !== 'reqId' && field !== 'evidenceComplete')
|
|
23
|
+
throw new Error(`unsupported candidate field: ${field}`);
|
|
24
|
+
}
|
|
25
|
+
const value = candidate;
|
|
26
|
+
if (value.reqId !== undefined && (typeof value.reqId !== 'string' || value.reqId.trim() === ''))
|
|
27
|
+
throw new Error(`invalid candidate reqId for ${caseId}`);
|
|
28
|
+
if (value.evidenceComplete !== undefined && typeof value.evidenceComplete !== 'boolean')
|
|
29
|
+
throw new Error(`invalid candidate evidenceComplete for ${caseId}`);
|
|
30
|
+
}
|
|
31
|
+
/** Validate and content-address independent records before joining evaluator-only truth. */
|
|
32
|
+
function freezeRequirementTriageRecords(kind, caseIds, input) {
|
|
33
|
+
const declared = [...new Set(caseIds)].sort();
|
|
34
|
+
if (declared.length !== caseIds.length || declared.some((id) => id.trim() === ''))
|
|
35
|
+
throw new Error('declared case ids must be unique and non-empty');
|
|
36
|
+
const seen = new Set(), covered = new Set(), coveredByAnalyst = new Map();
|
|
37
|
+
for (const raw of input) {
|
|
38
|
+
const allowed = kind === 'analyst' ? ANALYST_FIELDS : PREDICTION_FIELDS;
|
|
39
|
+
for (const field of Object.keys(raw)) {
|
|
40
|
+
if (ANSWER_KEY_FIELDS.has(field))
|
|
41
|
+
throw new Error(`answer-key field is forbidden: ${field}`);
|
|
42
|
+
if (!allowed.has(field))
|
|
43
|
+
throw new Error(`unsupported field: ${field}`);
|
|
44
|
+
}
|
|
45
|
+
const caseId = typeof raw.caseId === 'string' ? raw.caseId : '';
|
|
46
|
+
if (!declared.includes(caseId))
|
|
47
|
+
throw new Error(`unknown case id: ${caseId}`);
|
|
48
|
+
if (!VERDICTS.has(raw.verdict))
|
|
49
|
+
throw new Error(`invalid verdict for ${caseId}`);
|
|
50
|
+
if (!Number.isFinite(raw.elapsedMs) || Number(raw.elapsedMs) < 0)
|
|
51
|
+
throw new Error(`invalid elapsedMs for ${caseId}`);
|
|
52
|
+
const analyst = kind === 'analyst' ? (typeof raw.analyst === 'string' ? raw.analyst.trim() : '') : '';
|
|
53
|
+
if (kind === 'analyst' && analyst === '')
|
|
54
|
+
throw new Error(`analyst label is required for ${caseId}`);
|
|
55
|
+
if (kind === 'analyst' && raw.preferredReqId !== undefined && (typeof raw.preferredReqId !== 'string' || raw.preferredReqId.trim() === ''))
|
|
56
|
+
throw new Error(`invalid preferredReqId for ${caseId}`);
|
|
57
|
+
if (kind === 'analyst' && raw.evidenceComplete !== undefined && typeof raw.evidenceComplete !== 'boolean')
|
|
58
|
+
throw new Error(`invalid evidenceComplete for ${caseId}`);
|
|
59
|
+
if (kind === 'prediction') {
|
|
60
|
+
if (!Array.isArray(raw.candidates))
|
|
61
|
+
throw new Error(`prediction candidates are required for ${caseId}`);
|
|
62
|
+
for (const candidate of raw.candidates)
|
|
63
|
+
validateCandidate(candidate, caseId);
|
|
64
|
+
}
|
|
65
|
+
const key = kind === 'analyst' ? `${analyst}\u0000${caseId}` : caseId;
|
|
66
|
+
if (seen.has(key))
|
|
67
|
+
throw new Error(`duplicate record: ${caseId}`);
|
|
68
|
+
seen.add(key);
|
|
69
|
+
covered.add(caseId);
|
|
70
|
+
if (kind === 'analyst') {
|
|
71
|
+
const analystCases = coveredByAnalyst.get(analyst) ?? new Set();
|
|
72
|
+
analystCases.add(caseId);
|
|
73
|
+
coveredByAnalyst.set(analyst, analystCases);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
if (input.length > 0 && covered.size !== declared.length)
|
|
77
|
+
throw new Error('incomplete declared case set');
|
|
78
|
+
if (kind === 'analyst' && [...coveredByAnalyst.values()].some((analystCases) => analystCases.size !== declared.length)) {
|
|
79
|
+
throw new Error('incomplete declared case set for analyst');
|
|
80
|
+
}
|
|
81
|
+
const records = [...copy(input)].sort((a, b) => String(a.analyst ?? '').localeCompare(String(b.analyst ?? '')) || a.caseId.localeCompare(b.caseId));
|
|
82
|
+
const unsigned = { schema: 'requirement-triage-records/1', kind, caseIds: declared, records };
|
|
83
|
+
return Object.freeze({ ...unsigned, digest: digest(unsigned) });
|
|
84
|
+
}
|
|
85
|
+
function assertFrozen(receipt, kind) {
|
|
86
|
+
if (receipt.schema !== 'requirement-triage-records/1' || receipt.kind !== kind)
|
|
87
|
+
throw new Error('wrong record receipt kind');
|
|
88
|
+
const unsigned = { schema: receipt.schema, kind: receipt.kind, caseIds: [...receipt.caseIds], records: [...receipt.records] };
|
|
89
|
+
if (receipt.digest !== digest(unsigned))
|
|
90
|
+
throw new Error('record receipt digest mismatch');
|
|
91
|
+
}
|
|
92
|
+
/** Join frozen independent records; answer key fields stay evaluator-only. */
|
|
93
|
+
function joinRequirementTriageHumanRecords(analysts, predictions, answerKey) {
|
|
94
|
+
assertFrozen(analysts, 'analyst');
|
|
95
|
+
assertFrozen(predictions, 'prediction');
|
|
96
|
+
const caseIds = [...analysts.caseIds];
|
|
97
|
+
if (stable(caseIds) !== stable([...predictions.caseIds]))
|
|
98
|
+
throw new Error('record case sets differ');
|
|
99
|
+
if (Object.keys(answerKey).some((id) => !caseIds.includes(id)))
|
|
100
|
+
throw new Error('answer key contains unknown case id');
|
|
101
|
+
const product = new Map(predictions.records.map((record) => [record.caseId, record]));
|
|
102
|
+
const analystCount = new Set(analysts.records.map((record) => record.analyst)).size;
|
|
103
|
+
const predicted = caseIds.flatMap((caseId) => product.has(caseId) && answerKey[caseId] ? [{ prediction: product.get(caseId), answer: answerKey[caseId] }] : []);
|
|
104
|
+
const pairs = analysts.records.flatMap((analyst) => product.has(analyst.caseId) && answerKey[analyst.caseId] ? [{ analyst, prediction: product.get(analyst.caseId) }] : []);
|
|
105
|
+
const reuse = predicted.filter(({ answer }) => answer.verdict === 'fulfilled' || answer.verdict === 'existing-change');
|
|
106
|
+
const newCases = predicted.filter(({ answer }) => answer.verdict === 'new');
|
|
107
|
+
const ambiguous = predicted.filter(({ answer }) => answer.verdict === 'ambiguous');
|
|
108
|
+
const preferred = predicted.filter(({ answer }) => answer.preferredReqId !== undefined);
|
|
109
|
+
const median = (values) => { const sorted = [...values].sort((a, b) => a - b), m = Math.floor(sorted.length / 2); return sorted.length % 2 ? sorted[m] : (sorted[m - 1] + sorted[m]) / 2; };
|
|
110
|
+
return { analystCount, caseCount: caseIds.length, metrics: {
|
|
111
|
+
retrievalCoverage: ratio(preferred.filter(({ prediction, answer }) => prediction.candidates.some((candidate) => candidate.reqId === answer.preferredReqId)).length, preferred.length, 'no answer-key preferred requirement cases'),
|
|
112
|
+
humanChoiceAgreement: ratio(pairs.filter(({ analyst, prediction }) => analyst.verdict === prediction.verdict && (analyst.preferredReqId ?? null) === (prediction.candidates[0]?.reqId ?? null)).length, pairs.length, analystCount ? 'no overlapping analyst and prediction records' : 'no independent analyst records'),
|
|
113
|
+
falseReuse: ratio(newCases.filter(({ prediction }) => prediction.verdict === 'fulfilled' || prediction.verdict === 'existing-change').length, newCases.length, 'no answer-key new cases'),
|
|
114
|
+
falseNew: ratio(reuse.filter(({ prediction }) => prediction.verdict === 'new').length, reuse.length, 'no answer-key reuse cases'),
|
|
115
|
+
evidenceCompleteness: ratio(predicted.filter(({ prediction }) => prediction.candidates.length > 0 && prediction.candidates.every((candidate) => candidate.evidenceComplete === true)).length, predicted.length, 'no scored prediction cases'),
|
|
116
|
+
ambiguityPreservation: ratio(ambiguous.filter(({ prediction }) => prediction.verdict === 'ambiguous').length, ambiguous.length, 'no ambiguous answer-key cases'),
|
|
117
|
+
medianElapsedMs: predicted.length ? { value: median(predicted.map(({ prediction }) => prediction.elapsedMs)), denominator: predicted.length } : { value: null, denominator: 0, unavailable: 'no scored prediction cases' },
|
|
118
|
+
}, conclusion: analystCount === 0 || predicted.length === 0 ? 'Insufficient independent data; no comparative conclusion.' : 'Measured comparison only; sample and corpus limitations remain part of the result.' };
|
|
119
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { canonicalRequirementDocument as canonicalRequirementDocumentText } from '../semantic/vector-coverage';
|
|
2
|
+
export type RequirementVerdict = 'fulfilled' | 'existing-change' | 'new' | 'ambiguous';
|
|
3
|
+
export type RequirementDocumentKind = 'REQ' | 'H-SPEC' | 'A-SPEC' | 'T-SPEC';
|
|
4
|
+
export interface RequirementDocument {
|
|
5
|
+
id: string;
|
|
6
|
+
type: RequirementDocumentKind;
|
|
7
|
+
title: string;
|
|
8
|
+
status: string;
|
|
9
|
+
dependsOn?: readonly string[];
|
|
10
|
+
sections?: Readonly<Record<string, string>>;
|
|
11
|
+
}
|
|
12
|
+
export interface RequirementLineageEvidence {
|
|
13
|
+
implementationAnchors?: readonly string[];
|
|
14
|
+
freshGreenTests?: boolean;
|
|
15
|
+
contradictory?: boolean;
|
|
16
|
+
}
|
|
17
|
+
export interface RequirementSemanticCandidate {
|
|
18
|
+
id: string;
|
|
19
|
+
score: number;
|
|
20
|
+
}
|
|
21
|
+
export interface RequirementTriageInput {
|
|
22
|
+
prompt: string;
|
|
23
|
+
documents: readonly RequirementDocument[];
|
|
24
|
+
evidence?: Readonly<Record<string, RequirementLineageEvidence>>;
|
|
25
|
+
semanticCandidates?: readonly RequirementSemanticCandidate[];
|
|
26
|
+
/** Omit for the BM25-only comparison arm; configured cold/unavailable coverage is disclosed. */
|
|
27
|
+
semantic?: {
|
|
28
|
+
state: 'covered' | 'cold' | 'unavailable' | 'not-adopted';
|
|
29
|
+
covered: number;
|
|
30
|
+
total: number;
|
|
31
|
+
};
|
|
32
|
+
/** The read-only published RTM graph lane. Any unavailable/stale state is disclosed as ambiguity. */
|
|
33
|
+
graph?: {
|
|
34
|
+
state: 'current' | 'stale' | 'unverified' | 'absent' | 'unreadable' | 'empty';
|
|
35
|
+
};
|
|
36
|
+
topK?: number;
|
|
37
|
+
}
|
|
38
|
+
export interface RequirementTriageCandidate {
|
|
39
|
+
reqId: string;
|
|
40
|
+
documents: RequirementDocument[];
|
|
41
|
+
lexicalScore: number;
|
|
42
|
+
semanticScore?: number;
|
|
43
|
+
contentTerms: string[];
|
|
44
|
+
approved: boolean;
|
|
45
|
+
implementationAnchors: string[];
|
|
46
|
+
freshGreenTests: boolean;
|
|
47
|
+
reasons: string[];
|
|
48
|
+
}
|
|
49
|
+
export interface RequirementTriageResult {
|
|
50
|
+
verdict: RequirementVerdict;
|
|
51
|
+
candidates: RequirementTriageCandidate[];
|
|
52
|
+
/** Stable top-level explanation, duplicated from uncertainty for clients that render reasons. */
|
|
53
|
+
reasons: string[];
|
|
54
|
+
uncertainty: string[];
|
|
55
|
+
}
|
|
56
|
+
/** Re-exported for triage callers; the cache contract belongs to vector coverage. */
|
|
57
|
+
export declare const canonicalRequirementDocument: typeof canonicalRequirementDocumentText;
|
|
58
|
+
/**
|
|
59
|
+
* Retrieval only admits candidates. The verdict requires independent content and operational facts.
|
|
60
|
+
*/
|
|
61
|
+
export declare function triageRequirements(input: RequirementTriageInput): RequirementTriageResult;
|