ai-engineering-loop 2.6.0 → 2.8.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/.agents/skills/ael/SKILL.md +1 -1
- package/.agents/skills/ael/references/loop-commands.md +13 -1
- package/.agents/skills/ael/references/loop-deliver.md +1 -1
- package/.agents/skills/ael/references/loop-goal.md +2 -0
- package/.agents/skills/ael/references/loop-maker.md +1 -6
- package/.agents/skills/ael/references/loop-report.md +8 -0
- package/.agents/skills/ael/references/loop-verify.md +11 -9
- package/.claude/agents/devil-advocate.md +7 -2
- package/.claude/agents/judge.md +3 -1
- package/.grok/agents/devil-advocate.md +7 -2
- package/.grok/agents/judge.md +3 -1
- package/CHANGELOG.md +31 -0
- package/agents/devil-advocate.md +8 -0
- package/agents/judge.md +1 -0
- package/agents/shared/devil-advocate.body.md +7 -2
- package/agents/shared/judge.body.md +3 -1
- package/bin/ai-engineering-loop.js +326 -21
- package/core/bench.md +15 -0
- package/core/formal-statechart.md +49 -0
- package/core/goal-contract.md +53 -0
- package/core/verification-loop.md +106 -1
- package/lib/ablation.js +52 -0
- package/lib/ac-status.js +95 -0
- package/lib/baseline.js +138 -0
- package/lib/bench.js +24 -1
- package/lib/budget.js +9 -1
- package/lib/calibration.js +129 -0
- package/lib/claimed-vs-reality.js +106 -12
- package/lib/clean-state.js +85 -0
- package/lib/cli-args.js +5 -3
- package/lib/comment-findings.js +111 -0
- package/lib/debt.js +110 -0
- package/lib/feature-map.js +57 -0
- package/lib/features.js +95 -0
- package/lib/flow.js +86 -0
- package/lib/gates.js +257 -41
- package/lib/harness-audit.js +141 -0
- package/lib/learn.js +24 -1
- package/lib/no-progress.js +6 -1
- package/lib/receipt.js +33 -2
- package/lib/reverts.js +77 -0
- package/lib/review-ingest.js +54 -2
- package/lib/rule-check.js +90 -0
- package/lib/rules.js +205 -0
- package/lib/stats.js +110 -0
- package/lib/sync-hosts.js +1 -0
- package/lib/verification-integrity.js +164 -0
- package/lib/verification-lanes.js +96 -0
- package/lib/verification-recorder.js +20 -8
- package/package.json +1 -1
- package/schemas/finding-ledger.schema.json +14 -0
- package/schemas/goal-contract.schema.json +50 -0
- package/schemas/verdict.schema.json +2 -1
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// Evaluator calibration (C-13, learn-harness-engineering L11 + L14 anchors):
|
|
4
|
+
// pin the Devil's Advocate and Judge to reality. Post-delivery outcomes (a
|
|
5
|
+
// human MR comment, a revert, a bug traced to a Run) are compared with that
|
|
6
|
+
// Run's Finding Ledger, so misses and wrong dismissals become visible and
|
|
7
|
+
// can drive prompt changes (tracked by the reviewer prompt hash, C-16).
|
|
8
|
+
|
|
9
|
+
const fs = require('fs');
|
|
10
|
+
const path = require('path');
|
|
11
|
+
const { runsDir, loadRun } = require('./run-state.js');
|
|
12
|
+
|
|
13
|
+
const OUTCOMES_FILE = 'outcomes.jsonl';
|
|
14
|
+
const SOURCES = Object.freeze(['mr-comment', 'revert', 'bug', 'incident']);
|
|
15
|
+
|
|
16
|
+
function calibrationError(message, code) {
|
|
17
|
+
return Object.assign(new Error(message), { code });
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const fileOf = (location) => String(location || '').replace(/:\d+(?::\d+)?$/, '');
|
|
21
|
+
|
|
22
|
+
function recordOutcome(rootDir, { runId, source, location, summary, evidence = null, by, now = new Date() } = {}) {
|
|
23
|
+
if (!runId) throw calibrationError('outcome record needs --run <id> (the delivered Run the outcome traces to).', 'INVALID_USAGE');
|
|
24
|
+
if (!SOURCES.includes(source)) throw calibrationError(`--source must be one of ${SOURCES.join(', ')}`, 'INVALID_USAGE');
|
|
25
|
+
if (!String(location || '').trim()) throw calibrationError('--location <file[:line]> is required so the outcome can be matched to findings.', 'INVALID_USAGE');
|
|
26
|
+
if (!String(summary || '').trim()) throw calibrationError('--summary <text> is required.', 'INVALID_USAGE');
|
|
27
|
+
if (!String(by || '').trim()) throw calibrationError('--by <name> is required: outcomes are human-reported evidence.', 'INVALID_USAGE');
|
|
28
|
+
loadRun(rootDir, runId);
|
|
29
|
+
const entry = { source, location: String(location).trim(), summary: String(summary).trim(), by: String(by).trim(), at: now.toISOString(), ...(evidence ? { evidence } : {}) };
|
|
30
|
+
fs.appendFileSync(path.join(runsDir(rootDir), runId, OUTCOMES_FILE), `${JSON.stringify(entry)}\n`, { mode: 0o600 });
|
|
31
|
+
return entry;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function readJsonLines(filePath) {
|
|
35
|
+
let text = '';
|
|
36
|
+
try {
|
|
37
|
+
text = fs.readFileSync(filePath, 'utf8');
|
|
38
|
+
} catch {
|
|
39
|
+
return [];
|
|
40
|
+
}
|
|
41
|
+
return text.split('\n').filter((line) => line.trim()).flatMap((line) => {
|
|
42
|
+
try {
|
|
43
|
+
return [JSON.parse(line)];
|
|
44
|
+
} catch {
|
|
45
|
+
return [];
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// Classify one outcome against the Run's ledger findings.
|
|
51
|
+
function classifyOutcome(outcome, findings) {
|
|
52
|
+
const file = fileOf(outcome.location);
|
|
53
|
+
const related = (findings || []).filter((finding) => fileOf(finding.location) === file);
|
|
54
|
+
if (!related.length) return { verdict: 'DA_MISS', findings: [] };
|
|
55
|
+
const dismissed = related.filter((finding) => finding.validity === 'INVALID' || finding.dismissal);
|
|
56
|
+
if (dismissed.length) return { verdict: 'FALSE_DISMISS', findings: dismissed.map((finding) => finding.id) };
|
|
57
|
+
return { verdict: 'CAUGHT_BUT_SHIPPED', findings: related.map((finding) => finding.id) };
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function calibrate(rootDir) {
|
|
61
|
+
let runs = [];
|
|
62
|
+
try {
|
|
63
|
+
runs = fs.readdirSync(runsDir(rootDir), { withFileTypes: true }).filter((entry) => entry.isDirectory()).map((entry) => entry.name).sort();
|
|
64
|
+
} catch {
|
|
65
|
+
runs = [];
|
|
66
|
+
}
|
|
67
|
+
const rows = [];
|
|
68
|
+
const byPrompt = {};
|
|
69
|
+
for (const runId of runs) {
|
|
70
|
+
const outcomes = readJsonLines(path.join(runsDir(rootDir), runId, OUTCOMES_FILE));
|
|
71
|
+
if (!outcomes.length) continue;
|
|
72
|
+
let ledger = null;
|
|
73
|
+
try {
|
|
74
|
+
ledger = JSON.parse(fs.readFileSync(path.join(runsDir(rootDir), runId, 'findings.json'), 'utf8'));
|
|
75
|
+
} catch {
|
|
76
|
+
ledger = null;
|
|
77
|
+
}
|
|
78
|
+
const prompt = ledger?.reviewer?.promptSha256 ? ledger.reviewer.promptSha256.slice(0, 12) : 'unknown';
|
|
79
|
+
for (const outcome of outcomes) {
|
|
80
|
+
const result = classifyOutcome(outcome, ledger?.findings);
|
|
81
|
+
rows.push({ runId, ...outcome, ...result, prompt });
|
|
82
|
+
const bucket = byPrompt[prompt] || (byPrompt[prompt] = { outcomes: 0, DA_MISS: 0, FALSE_DISMISS: 0, CAUGHT_BUT_SHIPPED: 0 });
|
|
83
|
+
bucket.outcomes += 1;
|
|
84
|
+
bucket[result.verdict] += 1;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
// C-24: reverts found in git count as outcomes too, unless already recorded.
|
|
88
|
+
for (const item of require('./reverts.js').detectReverts(rootDir).reverted) {
|
|
89
|
+
if (rows.some((row) => row.runId === item.runId && row.source === 'revert')) continue;
|
|
90
|
+
let ledger = null;
|
|
91
|
+
try {
|
|
92
|
+
ledger = JSON.parse(fs.readFileSync(path.join(runsDir(rootDir), item.runId, 'findings.json'), 'utf8'));
|
|
93
|
+
} catch {
|
|
94
|
+
ledger = null;
|
|
95
|
+
}
|
|
96
|
+
const outcome = { source: 'revert', location: item.location, summary: `reverted by ${String(item.revertSha).slice(0, 12)}`, by: 'git' };
|
|
97
|
+
const result = classifyOutcome(outcome, ledger?.findings);
|
|
98
|
+
const prompt = ledger?.reviewer?.promptSha256 ? ledger.reviewer.promptSha256.slice(0, 12) : 'unknown';
|
|
99
|
+
rows.push({ runId: item.runId, ...outcome, ...result, prompt });
|
|
100
|
+
const bucket = byPrompt[prompt] || (byPrompt[prompt] = { outcomes: 0, DA_MISS: 0, FALSE_DISMISS: 0, CAUGHT_BUT_SHIPPED: 0 });
|
|
101
|
+
bucket.outcomes += 1;
|
|
102
|
+
bucket[result.verdict] += 1;
|
|
103
|
+
}
|
|
104
|
+
const count = (verdict) => rows.filter((row) => row.verdict === verdict).length;
|
|
105
|
+
return {
|
|
106
|
+
outcomes: rows.length,
|
|
107
|
+
daMiss: count('DA_MISS'),
|
|
108
|
+
falseDismiss: count('FALSE_DISMISS'),
|
|
109
|
+
caughtButShipped: count('CAUGHT_BUT_SHIPPED'),
|
|
110
|
+
byPrompt,
|
|
111
|
+
rows
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function formatCalibration(report) {
|
|
116
|
+
const lines = [`Outcomes: ${report.outcomes} (DA missed ${report.daMiss}, wrongly dismissed ${report.falseDismiss}, caught but shipped ${report.caughtButShipped})`];
|
|
117
|
+
for (const row of report.rows.filter((r) => r.verdict !== 'CAUGHT_BUT_SHIPPED')) {
|
|
118
|
+
lines.push(`- ${row.verdict} ${row.runId} ${row.location}: ${row.summary}${row.findings.length ? ` (findings ${row.findings.join(', ')})` : ''}`);
|
|
119
|
+
}
|
|
120
|
+
if (report.daMiss || report.falseDismiss) {
|
|
121
|
+
lines.push('Next: add each miss as a concrete check to agents/shared/devil-advocate.body.md (or a learn promote rule), then compare the next prompt hash here.');
|
|
122
|
+
}
|
|
123
|
+
for (const [prompt, bucket] of Object.entries(report.byPrompt)) {
|
|
124
|
+
lines.push(`- prompt ${prompt}: ${bucket.outcomes} outcome(s), ${bucket.DA_MISS} miss, ${bucket.FALSE_DISMISS} false dismiss`);
|
|
125
|
+
}
|
|
126
|
+
return lines.join('\n');
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
module.exports = { OUTCOMES_FILE, SOURCES, calibrate, classifyOutcome, formatCalibration, recordOutcome };
|
|
@@ -70,11 +70,11 @@ function assertNoSymlinkPath(root, targetPath) {
|
|
|
70
70
|
}
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
-
function renderClaimedVsRealityTemplate(goal) {
|
|
73
|
+
function renderClaimedVsRealityTemplate(goal, tier = null) {
|
|
74
74
|
const lines = [
|
|
75
75
|
'# Claimed vs Reality',
|
|
76
76
|
'',
|
|
77
|
-
'> Generated from the frozen Goal Contract. Fill Claimed and Reality only after implementation and verification. Reality must cite observed command output; this template is not verification evidence.',
|
|
77
|
+
'> Generated from the frozen Goal Contract. Fill Claimed and Reality only after implementation and verification. Reality must cite observed command output; this template is not verification evidence. Layer: L1 static, L2 tests, L3 e2e; "needs L3" rows need L3 or "L3 waived: <reason>".',
|
|
78
78
|
'',
|
|
79
79
|
'| AC | Claimed | Reality from command log | Layer |',
|
|
80
80
|
'|---|---|---|---|'
|
|
@@ -87,7 +87,8 @@ function renderClaimedVsRealityTemplate(goal) {
|
|
|
87
87
|
evidence ? `Evidence: ${evidence}` : '',
|
|
88
88
|
failures ? `Failure cases: ${failures}` : ''
|
|
89
89
|
].filter(Boolean).join(' — ');
|
|
90
|
-
|
|
90
|
+
const layerHint = criterionNeedsL3(criterion, tier) ? 'needs L3' : '';
|
|
91
|
+
lines.push(`| ${markdownCell(description)} | | | ${layerHint} |`);
|
|
91
92
|
}
|
|
92
93
|
return `${lines.join('\n')}\n`;
|
|
93
94
|
}
|
|
@@ -125,7 +126,7 @@ function createClaimedVsRealityTemplate(rootDir, { runId, outputPath } = {}) {
|
|
|
125
126
|
throw cause;
|
|
126
127
|
}
|
|
127
128
|
try {
|
|
128
|
-
fs.writeFileSync(descriptor, renderClaimedVsRealityTemplate(goal));
|
|
129
|
+
fs.writeFileSync(descriptor, renderClaimedVsRealityTemplate(goal, run.tier?.current || null));
|
|
129
130
|
fs.fsyncSync(descriptor);
|
|
130
131
|
} finally {
|
|
131
132
|
fs.closeSync(descriptor);
|
|
@@ -156,20 +157,113 @@ function parseClaimedVsReality(markdown) {
|
|
|
156
157
|
return { rows };
|
|
157
158
|
}
|
|
158
159
|
|
|
159
|
-
|
|
160
|
+
// Three-layer termination check (#110, learn-harness-engineering lectures 09/10):
|
|
161
|
+
// L1 static (typecheck/lint/build), L2 runtime (unit/related/all tests),
|
|
162
|
+
// L3 end-to-end (e2e or the AC's real user flow). Unit tests isolate and mock
|
|
163
|
+
// by design, so they cannot prove a cross-component AC.
|
|
164
|
+
const LAYER_TOKEN = /^L[123F]$/; // LF = formal (C-23)
|
|
165
|
+
const WAIVER = /^L3\s+waived\s*:\s*(.+)$/i;
|
|
166
|
+
const MIN_WAIVER_REASON = 15;
|
|
167
|
+
|
|
168
|
+
function acIdOf(cell) {
|
|
169
|
+
const match = String(cell || '').match(/\bAC-[0-9]+\b/);
|
|
170
|
+
return match ? match[0] : null;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
function criterionNeedsL3(criterion, tier) {
|
|
174
|
+
return criterion?.crossComponent === true || tier === 'T2';
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
// Parse a Layer cell such as "L2", "L1+L2+L3", or "L2; L3 waived: <reason>".
|
|
178
|
+
// Returns { layers, waiver, invalid } where invalid lists unknown tokens.
|
|
179
|
+
function parseLayerCell(cell) {
|
|
180
|
+
const layers = new Set();
|
|
181
|
+
const invalid = [];
|
|
182
|
+
let waiver = null;
|
|
183
|
+
const text = String(cell || '').trim();
|
|
184
|
+
if (!text || /^needs L3$/i.test(text)) return { layers, waiver, invalid, empty: true };
|
|
185
|
+
for (const part of text.split(/[;,]/).map((p) => p.trim()).filter(Boolean)) {
|
|
186
|
+
const waived = part.match(WAIVER);
|
|
187
|
+
if (waived) {
|
|
188
|
+
waiver = waived[1].trim();
|
|
189
|
+
continue;
|
|
190
|
+
}
|
|
191
|
+
for (const token of part.split(/[+\s]+/).map((t) => t.trim().toUpperCase()).filter(Boolean)) {
|
|
192
|
+
if (LAYER_TOKEN.test(token)) layers.add(token);
|
|
193
|
+
else invalid.push(token);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
return { layers, waiver, invalid, empty: false };
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
// Agent-oriented check: every problem says what is wrong and how to fix it.
|
|
200
|
+
// options.goal (frozen Goal Contract) and options.tier switch on the L3
|
|
201
|
+
// requirement; without them only the Layer cell syntax is checked, so legacy
|
|
202
|
+
// 3-column files keep working.
|
|
203
|
+
// C-01: a Layer tag must be backed by evidence of that layer. `layers` is
|
|
204
|
+
// the set of layers present in the recorded verification commands (null =
|
|
205
|
+
// unknown, skip the check). L3 may instead cite a manual end-to-end flow.
|
|
206
|
+
const MANUAL_FLOW = /\b(manual(?:ly)?|user flow|clicked|screenshot|playwright|cypress|browser|curl|https?:\/\/)/i;
|
|
207
|
+
|
|
208
|
+
function checkClaimedVsReality(markdown, { goal = null, tier = null, layers = null } = {}) {
|
|
160
209
|
const { rows } = parseClaimedVsReality(markdown);
|
|
161
|
-
|
|
162
|
-
|
|
210
|
+
const problems = [];
|
|
211
|
+
if (rows.length === 0) {
|
|
212
|
+
problems.push('claimed-vs-reality has no AC rows. FIX: scaffold it with `context claimed-vs-reality --run <id>` and fill every row.');
|
|
213
|
+
return { ready: false, problems };
|
|
214
|
+
}
|
|
215
|
+
const hasLayerColumn = /^\s*\|\s*AC\s*\|.*\|\s*Layer\s*\|\s*$/im.test(String(markdown));
|
|
216
|
+
const criteria = new Map((goal?.acceptanceCriteria || []).map((c) => [c.id, c]));
|
|
217
|
+
const effectiveTier = tier || goal?.tier || null;
|
|
218
|
+
for (const row of rows) {
|
|
219
|
+
const label = acIdOf(row.ac) || markdownCell(row.ac).slice(0, 40);
|
|
163
220
|
const reality = (row.reality || '').trim();
|
|
164
|
-
if (!
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
221
|
+
if (!(row.claimed || '').trim()) {
|
|
222
|
+
problems.push(`${label}: Claimed is empty. FIX: state what the change does for this AC.`);
|
|
223
|
+
}
|
|
224
|
+
if (!reality) {
|
|
225
|
+
problems.push(`${label}: Reality is empty. FIX: paste the command and its observed result (exit code, pass count).`);
|
|
226
|
+
} else if (/^seems green$/i.test(reality)) {
|
|
227
|
+
problems.push(`${label}: Reality "seems green" is not evidence. FIX: cite the command output from this iteration.`);
|
|
228
|
+
}
|
|
229
|
+
const layer = parseLayerCell(row.layer);
|
|
230
|
+
if (layer.invalid.length) {
|
|
231
|
+
problems.push(`${label}: Layer has unknown token(s) ${layer.invalid.join(', ')}. FIX: use L1 (static), L2 (runtime tests), L3 (end-to-end), e.g. "L2+L3".`);
|
|
232
|
+
}
|
|
233
|
+
if (layer.waiver !== null && layer.waiver.length < MIN_WAIVER_REASON) {
|
|
234
|
+
problems.push(`${label}: L3 waiver reason is too short. FIX: write "L3 waived: <why no e2e or manual flow could run>" with a concrete reason.`);
|
|
235
|
+
}
|
|
236
|
+
if (layers) {
|
|
237
|
+
for (const tag of layer.layers) {
|
|
238
|
+
if (layers.has(tag)) continue;
|
|
239
|
+
if (tag === 'L3' && MANUAL_FLOW.test(reality)) continue;
|
|
240
|
+
problems.push(tag === 'L3'
|
|
241
|
+
? `${label}: Layer says L3 but no e2e command was recorded and Reality cites no manual flow. FIX: run \`verify --cmd "<e2e command>"\`, or describe the real user flow you exercised (steps, URL, screenshot path) in Reality.`
|
|
242
|
+
: `${label}: Layer says ${tag} but no ${tag} command was recorded for this diff. FIX: run the ${tag === 'L1' ? 'typecheck/lint/build' : 'test'} command through \`verify\`, or correct the tag.`);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
const criterion = criteria.get(acIdOf(row.ac));
|
|
246
|
+
const needsL3 = criterion ? criterionNeedsL3(criterion, effectiveTier) : (effectiveTier === 'T2' && Boolean(goal));
|
|
247
|
+
if (needsL3 && !layer.layers.has('L3') && !(layer.waiver && layer.waiver.length >= MIN_WAIVER_REASON)) {
|
|
248
|
+
const why = criterion?.crossComponent === true ? 'it is marked crossComponent' : `tier ${effectiveTier} requires L1-L3`;
|
|
249
|
+
problems.push(hasLayerColumn
|
|
250
|
+
? `${label}: needs L3 end-to-end evidence because ${why}; unit/related tests mock the boundaries this AC crosses. FIX: run \`e2e\` (or the AC's real user flow), cite it in Reality and tag Layer "L3", or write "L3 waived: <reason>".`
|
|
251
|
+
: `${label}: needs L3 evidence because ${why}, but the file has no Layer column. FIX: add a 4th column "Layer" and tag this row L3 (or "L3 waived: <reason>").`);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
return { ready: problems.length === 0, problems };
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
function readyForDa(markdown, options) {
|
|
258
|
+
return checkClaimedVsReality(markdown, options).ready;
|
|
169
259
|
}
|
|
170
260
|
|
|
171
261
|
module.exports = {
|
|
262
|
+
checkClaimedVsReality,
|
|
172
263
|
createClaimedVsRealityTemplate,
|
|
264
|
+
criterionNeedsL3,
|
|
265
|
+
loadFrozenGoal: frozenGoal,
|
|
266
|
+
parseLayerCell,
|
|
173
267
|
parseClaimedVsReality,
|
|
174
268
|
readyForDa
|
|
175
269
|
};
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// Clean state at delivery (C-06, learn-harness-engineering L12): the next
|
|
4
|
+
// session must start from a tree it can trust. Checked at `gate delivery`.
|
|
5
|
+
|
|
6
|
+
const fs = require('fs');
|
|
7
|
+
const path = require('path');
|
|
8
|
+
const { execFileSync } = require('child_process');
|
|
9
|
+
const { runsDir } = require('./run-state.js');
|
|
10
|
+
const { parseDiff } = require('./verification-integrity.js');
|
|
11
|
+
|
|
12
|
+
const DEBUG_MARKERS = [
|
|
13
|
+
{ pattern: /^\s*debugger\s*;?\s*$/, label: 'debugger statement' },
|
|
14
|
+
{ pattern: /^(<{7}|={7}|>{7})( |$)/, label: 'merge conflict marker' },
|
|
15
|
+
{ pattern: /\bbreakpoint\(\)|\bpdb\.set_trace\(\)|\bbinding\.pry\b/, label: 'interactive breakpoint' }
|
|
16
|
+
];
|
|
17
|
+
const SECRET_FILE = /(^|\/)\.env(\.(?!example$|sample$|template$)[\w-]+)?$|(^|\/)(id_rsa|id_ed25519)$|\.(pem|p12|pfx|key)$/;
|
|
18
|
+
|
|
19
|
+
function untrackedFiles(rootDir) {
|
|
20
|
+
try {
|
|
21
|
+
return execFileSync('git', ['ls-files', '--others', '--exclude-standard', '-z', '--', '.', ':(exclude).ai-engineering-loop'], {
|
|
22
|
+
cwd: rootDir, encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore']
|
|
23
|
+
}).split('\0').filter(Boolean);
|
|
24
|
+
} catch {
|
|
25
|
+
return [];
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function templateOnlyArtifacts(rootDir, run) {
|
|
30
|
+
const found = [];
|
|
31
|
+
const dirs = [path.join(runsDir(rootDir), run.runId), path.join(rootDir, '.ai-engineering-loop', 'tasks')];
|
|
32
|
+
for (const dir of dirs) {
|
|
33
|
+
let entries = [];
|
|
34
|
+
try {
|
|
35
|
+
entries = fs.readdirSync(dir).filter((name) => name.endsWith('.json'));
|
|
36
|
+
} catch {
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
for (const name of entries) {
|
|
40
|
+
try {
|
|
41
|
+
if (JSON.parse(fs.readFileSync(path.join(dir, name), 'utf8'))?._templateOnly === true) {
|
|
42
|
+
found.push(path.relative(rootDir, path.join(dir, name)).split(path.sep).join('/'));
|
|
43
|
+
}
|
|
44
|
+
} catch {
|
|
45
|
+
// Not JSON we own; ignore.
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return found;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// { errors, warnings }: errors always block delivery; stray untracked files
|
|
53
|
+
// block in UNATTENDED and warn in ASSISTED (people keep scratch files).
|
|
54
|
+
function checkCleanState(rootDir, run, { mode = 'ASSISTED' } = {}) {
|
|
55
|
+
const errors = [];
|
|
56
|
+
const warnings = [];
|
|
57
|
+
let diffText = '';
|
|
58
|
+
try {
|
|
59
|
+
diffText = fs.readFileSync(path.join(rootDir, run.artifacts.diff.path), 'utf8');
|
|
60
|
+
} catch {
|
|
61
|
+
diffText = '';
|
|
62
|
+
}
|
|
63
|
+
const files = parseDiff(diffText);
|
|
64
|
+
for (const file of files) {
|
|
65
|
+
if (!file.deleted && SECRET_FILE.test(file.path)) {
|
|
66
|
+
errors.push(`${file.path}: secret-like file is part of the change. FIX: remove it from the change and add it to .gitignore; ship an .env.example instead.`);
|
|
67
|
+
}
|
|
68
|
+
for (const added of file.added) {
|
|
69
|
+
const hit = DEBUG_MARKERS.find((marker) => marker.pattern.test(added.text));
|
|
70
|
+
if (hit) errors.push(`${file.path}:${added.line}: ${hit.label} left in the change. FIX: remove it, re-run the Maker gate and verify.`);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
for (const artifact of templateOnlyArtifacts(rootDir, run)) {
|
|
74
|
+
errors.push(`${artifact}: still a _templateOnly scaffold. FIX: fill it with observed facts and remove _templateOnly, or delete it.`);
|
|
75
|
+
}
|
|
76
|
+
const inDiff = new Set(files.map((file) => file.path));
|
|
77
|
+
const strays = untrackedFiles(rootDir).filter((file) => !inDiff.has(file));
|
|
78
|
+
if (strays.length) {
|
|
79
|
+
const message = `untracked file(s) not part of the reviewed change: ${strays.slice(0, 10).join(', ')}${strays.length > 10 ? ', ...' : ''}. FIX: delete them, add them to .gitignore, or include them and re-run the Maker gate.`;
|
|
80
|
+
(mode === 'UNATTENDED' ? errors : warnings).push(message);
|
|
81
|
+
}
|
|
82
|
+
return { errors, warnings };
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
module.exports = { checkCleanState, untrackedFiles };
|
package/lib/cli-args.js
CHANGED
|
@@ -21,14 +21,16 @@ const WRITER_COMMANDS = Object.freeze({
|
|
|
21
21
|
'run:abandon': { flags: ['--abandon', '--yes', '--json'], valued: ['--run', '--reason', '--by'], positionals: [] },
|
|
22
22
|
bench: {
|
|
23
23
|
flags: ['--json', '--sandbox-home'],
|
|
24
|
-
valued: ['--host', '--model', '--scenario', '--repeat', '--bin', '--mode', '--timeout', '--host-arg'],
|
|
24
|
+
valued: ['--host', '--model', '--scenario', '--repeat', '--bin', '--mode', '--timeout', '--host-arg', '--without'],
|
|
25
25
|
positionals: []
|
|
26
26
|
},
|
|
27
27
|
migrate: { flags: ['--json', '--dry-run'], valued: ['--from'], positionals: [] },
|
|
28
|
-
|
|
28
|
+
debt: { flags: ['--json'], valued: ['--by', '--note', '--file'], positionals: null },
|
|
29
|
+
outcome: { flags: ['--json'], valued: ['--run', '--source', '--location', '--summary', '--evidence', '--by'], positionals: ['record'] },
|
|
30
|
+
verify: { flags: ['--json', '--serial', '--shell', '--related', '--final', '--fresh', '--baseline'], valued: ['--run', '--cmd', '--timeout-ms'], positionals: [] },
|
|
29
31
|
quick: { flags: ['--json', '--serial', '--shell'], valued: ['--run', '--cmd', '--timeout-ms', '--mode'], positionals: null },
|
|
30
32
|
review: { flags: ['--json'], valued: ['--run', '--child-id', '--file'], positionals: ['ingest'] },
|
|
31
|
-
learn: { flags: ['--json', '--dry-run', '--prune'], valued: ['--max-age-runs'], positionals:
|
|
33
|
+
learn: { flags: ['--json', '--dry-run', '--prune', '--no-shell'], valued: ['--max-age-runs', '--check', '--fix', '--why', '--by', '--scope', '--forbid-import', '--forbid-api', '--except'], positionals: null },
|
|
32
34
|
guard: { flags: ['--json'], valued: ['--run', '--tool', '--input', '--path', '--command', '--hook'], positionals: ['check'] },
|
|
33
35
|
hooks: { flags: ['--json'], valued: ['--host'], positionals: ['install', 'uninstall', 'status'] },
|
|
34
36
|
impact: { flags: ['--json', '--force'], valued: ['--run', '--by', '--reason', '--allow', '--remove', '--limit'], positionals: ['map', 'show', 'confirm', 'skip', 'drift'] },
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// C-18 ("All Code Is Slop (Except Mine)", 06:46-08:46): agents write comments
|
|
4
|
+
// to justify not doing the right thing, and comments cannot be enforced.
|
|
5
|
+
// New suppressions and justification comments in product code become
|
|
6
|
+
// standards findings, so the reviewer must decide: root cause or patch?
|
|
7
|
+
// Unlike C-11 integrity findings, a reviewer may dismiss these with evidence.
|
|
8
|
+
|
|
9
|
+
const fs = require('fs');
|
|
10
|
+
const path = require('path');
|
|
11
|
+
const { isTestFile, parseDiff } = require('./verification-integrity.js');
|
|
12
|
+
|
|
13
|
+
const SOURCE = 'comment-justification';
|
|
14
|
+
const SKIP_FILE = /\.(md|mdx|txt|rst|json|lock|ya?ml|toml|csv|svg|snap)$|(^|\/)(CHANGELOG|LICENSE)/i;
|
|
15
|
+
const COMMENT = /(\/\/|\/\*|^\s*\*|(^|\s)#|<!--|(^|\s)--\s)/;
|
|
16
|
+
const SUPPRESS = [
|
|
17
|
+
{ pattern: /eslint-disable(?:-next-line|-line)?/, reason: /eslint-disable\S*(?:\s.*?)?\s--\s+(.{10,})/ },
|
|
18
|
+
{ pattern: /@ts-ignore/, reason: /@ts-ignore\s+(.{10,})/ },
|
|
19
|
+
{ pattern: /@ts-expect-error/, reason: /@ts-expect-error\s+(.{10,})/ },
|
|
20
|
+
{ pattern: /#\s*type:\s*ignore/, reason: /type:\s*ignore\S*\s+#?\s*(.{10,})/ },
|
|
21
|
+
{ pattern: /#\s*noqa/, reason: /noqa\S*\s+#?\s*(.{10,})/ },
|
|
22
|
+
{ pattern: /\/\/\s*nolint/, reason: /nolint\S*\s+\/\/\s*(.{10,})/ },
|
|
23
|
+
{ pattern: /NOSONAR/, reason: /NOSONAR\s+(.{10,})/ },
|
|
24
|
+
{ pattern: /istanbul ignore|c8 ignore/, reason: /ignore \w+\s+(.{10,})/ }
|
|
25
|
+
];
|
|
26
|
+
const JUSTIFICATION = /\b(work-?around|quick[- ]?fix|hack(y)?|temporary|temp fix|for now|band-?aid|kludge|until we|proper fix later|fix (this )?later)\b/i;
|
|
27
|
+
|
|
28
|
+
function loadExtraPatterns(rootDir) {
|
|
29
|
+
try {
|
|
30
|
+
const value = JSON.parse(fs.readFileSync(path.join(rootDir, '.ai-engineering-loop', 'rules.json'), 'utf8'));
|
|
31
|
+
return (value.justificationPatterns || []).map((text) => new RegExp(text, 'i'));
|
|
32
|
+
} catch {
|
|
33
|
+
return [];
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function scanComments(diffText, { extraPatterns = [] } = {}) {
|
|
38
|
+
const findings = [];
|
|
39
|
+
let n = 0;
|
|
40
|
+
for (const file of parseDiff(diffText)) {
|
|
41
|
+
if (file.deleted || isTestFile(file.path) || SKIP_FILE.test(file.path)) continue;
|
|
42
|
+
for (const added of file.added) {
|
|
43
|
+
const text = added.text;
|
|
44
|
+
if (!COMMENT.test(text)) continue;
|
|
45
|
+
const location = `${file.path}:${added.line}`;
|
|
46
|
+
const suppress = SUPPRESS.find((item) => item.pattern.test(text));
|
|
47
|
+
if (suppress) {
|
|
48
|
+
const reasoned = suppress.reason.test(text);
|
|
49
|
+
findings.push({
|
|
50
|
+
id: `COMMENT-${++n}`,
|
|
51
|
+
axis: 'standards',
|
|
52
|
+
location,
|
|
53
|
+
failureScenario: reasoned
|
|
54
|
+
? 'A lint/type/coverage suppression was added; it hides the signal instead of fixing what the check found'
|
|
55
|
+
: 'A lint/type/coverage suppression was added with no reason; the next agent will copy it as the established pattern',
|
|
56
|
+
evidence: `added line: ${text.trim().slice(0, 160)}`,
|
|
57
|
+
severity: reasoned ? 'MEDIUM' : 'HIGH',
|
|
58
|
+
validity: 'VALID',
|
|
59
|
+
disposition: 'WEAK',
|
|
60
|
+
concreteAlternativeDiff: `- ${text.trim()}\n+ (remove the suppression and fix the code the check flagged)`,
|
|
61
|
+
source: SOURCE
|
|
62
|
+
});
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
const custom = extraPatterns.find((pattern) => pattern.test(text));
|
|
66
|
+
if (JUSTIFICATION.test(text) || custom) {
|
|
67
|
+
findings.push({
|
|
68
|
+
id: `COMMENT-${++n}`,
|
|
69
|
+
axis: 'standards',
|
|
70
|
+
location,
|
|
71
|
+
failureScenario: 'A comment justifies a workaround instead of fixing the root cause; comments cannot be enforced and the workaround spreads',
|
|
72
|
+
evidence: `added line: ${text.trim().slice(0, 160)}`,
|
|
73
|
+
severity: 'MEDIUM',
|
|
74
|
+
validity: 'VALID',
|
|
75
|
+
disposition: 'WEAK',
|
|
76
|
+
source: SOURCE
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return findings;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function scanRunComments(rootDir, run) {
|
|
85
|
+
try {
|
|
86
|
+
return scanComments(fs.readFileSync(path.join(rootDir, run.artifacts.diff.path), 'utf8'), { extraPatterns: loadExtraPatterns(rootDir) });
|
|
87
|
+
} catch {
|
|
88
|
+
return [];
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// Reviewers may downgrade these, but only with dismissal.evidence.
|
|
93
|
+
function mergeCommentFindings(ledger, findings) {
|
|
94
|
+
const errors = [];
|
|
95
|
+
const existing = new Map((ledger.findings || []).filter((item) => item.source === SOURCE).map((item) => [item.location, item]));
|
|
96
|
+
const additions = [];
|
|
97
|
+
for (const item of findings) {
|
|
98
|
+
const present = existing.get(item.location);
|
|
99
|
+
if (!present) {
|
|
100
|
+
additions.push(item);
|
|
101
|
+
continue;
|
|
102
|
+
}
|
|
103
|
+
const downgraded = present.validity !== 'VALID' || present.severity !== item.severity;
|
|
104
|
+
if (downgraded && !String(present.dismissal?.evidence || '').trim()) {
|
|
105
|
+
errors.push(`${present.id} (${present.location}) was downgraded without dismissal.evidence. FIX: restore it, or add dismissal: {by, evidence} explaining why the suppression or workaround is the right call here.`);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
return { ledger: { ...ledger, findings: [...(ledger.findings || []), ...additions] }, added: additions.length, errors };
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
module.exports = { SOURCE, mergeCommentFindings, scanComments, scanRunComments };
|
package/lib/debt.js
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// Tech-debt ledger (C-14, OpenAI pack tech-debt-tracker, L12 "clean up later
|
|
4
|
+
// means never"). Trade-offs the Judge accepted and L3 waivers outlive the Run
|
|
5
|
+
// in .ai-engineering-loop/debt.json and come back when a later change
|
|
6
|
+
// touches the same file.
|
|
7
|
+
|
|
8
|
+
const fs = require('fs');
|
|
9
|
+
const path = require('path');
|
|
10
|
+
const { atomicWriteJson, runsDir } = require('./run-state.js');
|
|
11
|
+
const { parseClaimedVsReality, parseLayerCell } = require('./claimed-vs-reality.js');
|
|
12
|
+
|
|
13
|
+
const DEBT_FILE = path.join('.ai-engineering-loop', 'debt.json');
|
|
14
|
+
|
|
15
|
+
function debtPath(rootDir) {
|
|
16
|
+
return path.join(rootDir, DEBT_FILE);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function loadDebt(rootDir) {
|
|
20
|
+
try {
|
|
21
|
+
const value = JSON.parse(fs.readFileSync(debtPath(rootDir), 'utf8'));
|
|
22
|
+
return Array.isArray(value.items) ? value : { schemaVersion: 1, items: [] };
|
|
23
|
+
} catch {
|
|
24
|
+
return { schemaVersion: 1, items: [] };
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const fileOf = (location) => String(location || '').replace(/:\d+(?::\d+)?$/, '');
|
|
29
|
+
|
|
30
|
+
// Debt items for one delivered Run: VALID MEDIUM/LOW findings the Judge
|
|
31
|
+
// accepted as trade-offs, and claimed-vs-reality rows with an L3 waiver.
|
|
32
|
+
function collectRunDebt(rootDir, runId, { now = new Date() } = {}) {
|
|
33
|
+
const items = [];
|
|
34
|
+
const dir = path.join(runsDir(rootDir), runId);
|
|
35
|
+
let ledger = null;
|
|
36
|
+
try {
|
|
37
|
+
ledger = JSON.parse(fs.readFileSync(path.join(dir, 'findings.json'), 'utf8'));
|
|
38
|
+
} catch {
|
|
39
|
+
ledger = null;
|
|
40
|
+
}
|
|
41
|
+
for (const finding of ledger?.findings || []) {
|
|
42
|
+
if (finding.validity !== 'VALID' || !['MEDIUM', 'LOW'].includes(finding.severity)) continue;
|
|
43
|
+
items.push({
|
|
44
|
+
id: `${runId}:${finding.id}`,
|
|
45
|
+
runId,
|
|
46
|
+
kind: 'accepted-finding',
|
|
47
|
+
file: fileOf(finding.location),
|
|
48
|
+
location: finding.location,
|
|
49
|
+
debt: finding.failureScenario,
|
|
50
|
+
whyDeferred: `Judge accepted ${finding.severity} ${finding.axis || 'spec'} finding as a trade-off`,
|
|
51
|
+
risk: finding.severity,
|
|
52
|
+
nextTrigger: `next change touching ${fileOf(finding.location)}`,
|
|
53
|
+
status: 'open',
|
|
54
|
+
createdAt: now.toISOString()
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
let markdown = '';
|
|
58
|
+
try {
|
|
59
|
+
markdown = fs.readFileSync(path.join(rootDir, '.ai-engineering-loop', 'tasks', 'claimed-vs-reality.md'), 'utf8');
|
|
60
|
+
} catch {
|
|
61
|
+
markdown = '';
|
|
62
|
+
}
|
|
63
|
+
for (const row of parseClaimedVsReality(markdown).rows) {
|
|
64
|
+
const waiver = parseLayerCell(row.layer).waiver;
|
|
65
|
+
if (!waiver) continue;
|
|
66
|
+
const ac = (String(row.ac).match(/\bAC-\d+\b/) || [row.ac.slice(0, 20)])[0];
|
|
67
|
+
items.push({
|
|
68
|
+
id: `${runId}:${ac}:L3`,
|
|
69
|
+
runId,
|
|
70
|
+
kind: 'l3-waiver',
|
|
71
|
+
file: null,
|
|
72
|
+
location: ac,
|
|
73
|
+
debt: `${ac} shipped without end-to-end (L3) evidence`,
|
|
74
|
+
whyDeferred: waiver,
|
|
75
|
+
risk: 'MEDIUM',
|
|
76
|
+
nextTrigger: 'when an e2e command is added to verification.md',
|
|
77
|
+
status: 'open',
|
|
78
|
+
createdAt: now.toISOString()
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
return items;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function recordRunDebt(rootDir, runId, options) {
|
|
85
|
+
const ledger = loadDebt(rootDir);
|
|
86
|
+
const known = new Set(ledger.items.map((item) => item.id));
|
|
87
|
+
const added = collectRunDebt(rootDir, runId, options).filter((item) => !known.has(item.id));
|
|
88
|
+
if (!added.length) return { added: 0, path: DEBT_FILE.split(path.sep).join('/') };
|
|
89
|
+
atomicWriteJson(debtPath(rootDir), { schemaVersion: 1, items: [...ledger.items, ...added] });
|
|
90
|
+
return { added: added.length, path: DEBT_FILE.split(path.sep).join('/') };
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// Open debt on any of `files` (plus file-less waivers when `includeGlobal`).
|
|
94
|
+
function openDebtFor(rootDir, files = [], { includeGlobal = false } = {}) {
|
|
95
|
+
const wanted = new Set(files);
|
|
96
|
+
return loadDebt(rootDir).items.filter((item) => item.status === 'open'
|
|
97
|
+
&& ((item.file && wanted.has(item.file)) || (includeGlobal && !item.file)));
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function closeDebt(rootDir, id, { by, note } = {}) {
|
|
101
|
+
if (!String(by || '').trim()) throw Object.assign(new Error('debt close needs --by <name>'), { code: 'INVALID_USAGE' });
|
|
102
|
+
const ledger = loadDebt(rootDir);
|
|
103
|
+
const item = ledger.items.find((entry) => entry.id === id);
|
|
104
|
+
if (!item) throw Object.assign(new Error(`No debt item ${id}`), { code: 'NOT_FOUND' });
|
|
105
|
+
Object.assign(item, { status: 'closed', closedBy: by, closedAt: new Date().toISOString(), ...(note ? { note } : {}) });
|
|
106
|
+
atomicWriteJson(debtPath(rootDir), ledger);
|
|
107
|
+
return item;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
module.exports = { DEBT_FILE, closeDebt, collectRunDebt, loadDebt, openDebtFor, recordRunDebt };
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// Feature map (C-22, "All Code Is Slop (Except Mine)" 10:06-10:46): a
|
|
4
|
+
// site map of what users can do, so agents stop guessing what "the thingy in
|
|
5
|
+
// the left sidebar" means and runtime verification has a shared vocabulary.
|
|
6
|
+
// .ai-engineering-loop/feature-map.md holds one Markdown table:
|
|
7
|
+
//
|
|
8
|
+
// | Feature | Where (UI or endpoint) | Paths | How to reach | Driver |
|
|
9
|
+
// |---|---|---|---|---|
|
|
10
|
+
// | export-csv | Reports > Export button | src/reports/**, src/export/** | open Reports, click Export | npm run drive -- export |
|
|
11
|
+
//
|
|
12
|
+
// `Paths` are globs (comma separated) used to pick the entries a diff
|
|
13
|
+
// touches; `Driver` is an optional reusable command that runs the flow.
|
|
14
|
+
|
|
15
|
+
const fs = require('fs');
|
|
16
|
+
const path = require('path');
|
|
17
|
+
const { matchesGlob } = require('./impact-map.js');
|
|
18
|
+
|
|
19
|
+
const FEATURE_MAP_FILE = path.join('.ai-engineering-loop', 'feature-map.md');
|
|
20
|
+
|
|
21
|
+
function parseFeatureMap(text) {
|
|
22
|
+
const entries = [];
|
|
23
|
+
for (const raw of String(text || '').split('\n')) {
|
|
24
|
+
const line = raw.trim();
|
|
25
|
+
if (!line.startsWith('|') || /^\|\s*-/.test(line)) continue;
|
|
26
|
+
const cells = line.split('|').slice(1, -1).map((cell) => cell.trim());
|
|
27
|
+
if (cells.length < 4 || /^feature$/i.test(cells[0])) continue;
|
|
28
|
+
entries.push({
|
|
29
|
+
id: cells[0],
|
|
30
|
+
where: cells[1],
|
|
31
|
+
paths: cells[2].split(',').map((glob) => glob.trim().replace(/`/g, '')).filter(Boolean),
|
|
32
|
+
how: cells[3],
|
|
33
|
+
driver: (cells[4] || '').replace(/`/g, '').trim() || null
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
return entries;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function loadFeatureMap(rootDir) {
|
|
40
|
+
try {
|
|
41
|
+
return parseFeatureMap(fs.readFileSync(path.join(rootDir, FEATURE_MAP_FILE), 'utf8'));
|
|
42
|
+
} catch {
|
|
43
|
+
return [];
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function featuresForFiles(rootDir, files) {
|
|
48
|
+
return loadFeatureMap(rootDir).filter((entry) => files.some((file) => entry.paths.some((glob) => matchesGlob(file, glob))));
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function renderForPack(entries) {
|
|
52
|
+
if (!entries.length) return '';
|
|
53
|
+
return ['', '## Features this change touches (feature map)', '',
|
|
54
|
+
...entries.map((entry) => `- ${entry.id}: ${entry.where}. Reach: ${entry.how}.${entry.driver ? ` Driver: \`${entry.driver}\`` : ''}`)].join('\n');
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
module.exports = { FEATURE_MAP_FILE, featuresForFiles, loadFeatureMap, parseFeatureMap, renderForPack };
|