sdtk-code-kit 0.2.1 → 0.3.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/README.md +204 -204
- package/assets/manifest/toolkit-bundle.manifest.json +147 -147
- package/assets/manifest/toolkit-bundle.sha256.txt +5 -5
- package/bin/sdtk-code.js +14 -14
- package/package.json +44 -44
- package/src/commands/agent-team.js +174 -0
- package/src/commands/build.js +53 -53
- package/src/commands/doctor.js +51 -51
- package/src/commands/generate.js +11 -11
- package/src/commands/guardrails.js +215 -215
- package/src/commands/help.js +257 -244
- package/src/commands/init.js +98 -98
- package/src/commands/plan.js +53 -53
- package/src/commands/readiness.js +77 -77
- package/src/commands/resume.js +61 -61
- package/src/commands/runtime.js +224 -224
- package/src/commands/ship.js +59 -59
- package/src/commands/sleep.js +132 -132
- package/src/commands/start.js +89 -89
- package/src/commands/status.js +77 -77
- package/src/commands/update.js +11 -11
- package/src/commands/verify.js +71 -71
- package/src/index.js +112 -108
- package/src/lib/agent-team-export.js +409 -0
- package/src/lib/agent-team-plan.js +514 -0
- package/src/lib/args.js +107 -107
- package/src/lib/errors.js +41 -41
- package/src/lib/powershell.js +65 -65
- package/src/lib/project-target-guard.js +53 -53
- package/src/lib/scope.js +72 -72
- package/src/lib/ship-readiness.js +281 -281
- package/src/lib/sleep-plan.js +175 -175
- package/src/lib/sleep-report.js +229 -229
- package/src/lib/toolkit-payload.js +72 -72
- package/src/lib/trust-events.js +185 -166
- package/src/lib/trust-file-scope.js +154 -154
- package/src/lib/trust-policy.js +212 -212
- package/src/lib/trust-redact.js +35 -35
- package/src/lib/trust-trace.js +179 -179
- package/src/lib/update.js +344 -344
- package/src/lib/workflow-artifact.js +503 -503
- package/src/lib/workflow-build.js +127 -127
- package/src/lib/workflow-doctor.js +83 -83
- package/src/lib/workflow-handoff.js +1029 -1029
- package/src/lib/workflow-intake.js +101 -101
- package/src/lib/workflow-plan.js +193 -193
- package/src/lib/workflow-review-packet.js +650 -650
- package/src/lib/workflow-ship.js +213 -213
- package/src/lib/workflow-state.js +438 -438
- package/src/lib/workflow-verify.js +393 -393
|
@@ -1,650 +1,650 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
const fs = require("fs");
|
|
4
|
-
const path = require("path");
|
|
5
|
-
const { extractManagedBlock } = require("./workflow-artifact");
|
|
6
|
-
|
|
7
|
-
const PLACEHOLDER_BULLETS = new Set([
|
|
8
|
-
"Pending confirmation during workflow planning.",
|
|
9
|
-
"Pending lane-specific planning or build guidance.",
|
|
10
|
-
"Lightweight bugfix planning not recorded yet.",
|
|
11
|
-
"No active build slices recorded yet.",
|
|
12
|
-
"Pending build-phase execution.",
|
|
13
|
-
]);
|
|
14
|
-
const STALE_HANDOFF_OUT_OF_SCOPE_PATTERNS = [
|
|
15
|
-
/FEATURE_IMPL_PLAN \+ CODE_HANDOFF/i,
|
|
16
|
-
/no change to the `\/dev` boundary/i,
|
|
17
|
-
];
|
|
18
|
-
|
|
19
|
-
function getReviewPacketPath(projectPath, featureKey) {
|
|
20
|
-
return path.join(projectPath, "docs", "dev", `REVIEW_PACKET_${featureKey}.md`);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
function normalizeEntries(entries) {
|
|
24
|
-
return (entries || []).map((entry) => String(entry).trim()).filter(Boolean);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
function uniqueStrings(entries) {
|
|
28
|
-
return [...new Set(normalizeEntries(entries))];
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
function humanizeFeatureKey(featureKey) {
|
|
32
|
-
return String(featureKey)
|
|
33
|
-
.split("_")
|
|
34
|
-
.filter(Boolean)
|
|
35
|
-
.map((token) => token.charAt(0) + token.slice(1).toLowerCase())
|
|
36
|
-
.join(" ");
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
function normalizePathForDoc(projectPath, targetPath) {
|
|
40
|
-
return path.relative(projectPath, targetPath).split(path.sep).join("/");
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
function parseBulletSection(text, heading) {
|
|
44
|
-
if (!text) {
|
|
45
|
-
return [];
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
const escaped = heading.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
49
|
-
const match = text.match(new RegExp(`### ${escaped}\\r?\\n([\\s\\S]*?)(?=\\r?\\n(?:### |## |---)|$)`));
|
|
50
|
-
if (!match) {
|
|
51
|
-
return [];
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
return match[1]
|
|
55
|
-
.split(/\r?\n/)
|
|
56
|
-
.map((line) => line.trim())
|
|
57
|
-
.filter((line) => line.startsWith("- "))
|
|
58
|
-
.map((line) => line.slice(2).trim())
|
|
59
|
-
.filter(Boolean);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
function parseManagedField(blockText, label) {
|
|
63
|
-
if (!blockText) {
|
|
64
|
-
return null;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
const escaped = label.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
68
|
-
const match = blockText.match(new RegExp(`- ${escaped}: \`([^\\r\\n\`]+)\``));
|
|
69
|
-
return match ? match[1] : null;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
function parseInlineSliceSection(planBlock) {
|
|
73
|
-
if (!planBlock) {
|
|
74
|
-
return [];
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
const match = planBlock.match(/## 4\. Plan \/ Slices\r?\n([\s\S]*?)(?=\r?\n### Planning Notes)/);
|
|
78
|
-
if (!match) {
|
|
79
|
-
return [];
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
return match[1]
|
|
83
|
-
.split(/\r?\n/)
|
|
84
|
-
.map((line) => line.trim())
|
|
85
|
-
.filter((line) => line.startsWith("- "))
|
|
86
|
-
.map((line) => line.slice(2).trim())
|
|
87
|
-
.filter(Boolean);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
function cleanBulletEntries(entries) {
|
|
91
|
-
return uniqueStrings(entries).filter((entry) => !PLACEHOLDER_BULLETS.has(entry));
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
function filterStaleHandoffOutOfScopeEntries(entries) {
|
|
95
|
-
return cleanBulletEntries(entries).filter(
|
|
96
|
-
(entry) => !STALE_HANDOFF_OUT_OF_SCOPE_PATTERNS.some((pattern) => pattern.test(entry))
|
|
97
|
-
);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
function loadScopeContext(workflowText) {
|
|
101
|
-
const planBlock = extractManagedBlock(workflowText, "PLAN");
|
|
102
|
-
const inScope = cleanBulletEntries(parseBulletSection(planBlock, "In Scope"));
|
|
103
|
-
const outScope = filterStaleHandoffOutOfScopeEntries(parseBulletSection(planBlock, "Out Of Scope"));
|
|
104
|
-
let sliceTitles = cleanBulletEntries(parseBulletSection(planBlock, "Finalized Slices After `plan`"));
|
|
105
|
-
if (sliceTitles.length === 0) {
|
|
106
|
-
sliceTitles = cleanBulletEntries(parseInlineSliceSection(planBlock));
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
return {
|
|
110
|
-
inScope:
|
|
111
|
-
inScope.length > 0
|
|
112
|
-
? inScope
|
|
113
|
-
: sliceTitles.map((entry) => `Approved execution slice: ${entry}`),
|
|
114
|
-
outScope,
|
|
115
|
-
sliceTitles,
|
|
116
|
-
};
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
function loadWorkflowStageSnapshot(workflowText) {
|
|
120
|
-
const metadataBlock = extractManagedBlock(workflowText, "METADATA");
|
|
121
|
-
const statusBlock = extractManagedBlock(workflowText, "STATUS");
|
|
122
|
-
|
|
123
|
-
return {
|
|
124
|
-
currentPhase: parseManagedField(metadataBlock, "Current phase") || "unknown",
|
|
125
|
-
phaseStatus: parseManagedField(metadataBlock, "Phase status") || "unknown",
|
|
126
|
-
intakeOutcome: parseManagedField(metadataBlock, "Intake outcome") || "unknown",
|
|
127
|
-
nextPhase: parseManagedField(statusBlock, "Next recommended phase") || "unknown",
|
|
128
|
-
blockingState: parseManagedField(statusBlock, "Blocking state") || "unknown",
|
|
129
|
-
};
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
function loadFeatureImplPlanContext(projectPath, featureKey) {
|
|
133
|
-
const featureImplPlanPath = path.join(projectPath, "docs", "dev", `FEATURE_IMPL_PLAN_${featureKey}.md`);
|
|
134
|
-
if (!fs.existsSync(featureImplPlanPath)) {
|
|
135
|
-
return {
|
|
136
|
-
featureImplPlanPath,
|
|
137
|
-
nonGoals: [],
|
|
138
|
-
};
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
const text = fs.readFileSync(featureImplPlanPath, "utf-8");
|
|
142
|
-
return {
|
|
143
|
-
featureImplPlanPath,
|
|
144
|
-
nonGoals: filterStaleHandoffOutOfScopeEntries(
|
|
145
|
-
parseBulletSection(text, "2.5 Explicit Non-Goals For This Handoff")
|
|
146
|
-
),
|
|
147
|
-
};
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
function loadCodeHandoffContext(projectPath, featureKey) {
|
|
151
|
-
const handoffPath = path.join(projectPath, "docs", "dev", `CODE_HANDOFF_${featureKey}.json`);
|
|
152
|
-
if (!fs.existsSync(handoffPath)) {
|
|
153
|
-
return {
|
|
154
|
-
handoffPath,
|
|
155
|
-
payload: null,
|
|
156
|
-
error: null,
|
|
157
|
-
};
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
try {
|
|
161
|
-
return {
|
|
162
|
-
handoffPath,
|
|
163
|
-
payload: JSON.parse(fs.readFileSync(handoffPath, "utf-8")),
|
|
164
|
-
error: null,
|
|
165
|
-
};
|
|
166
|
-
} catch (error) {
|
|
167
|
-
return {
|
|
168
|
-
handoffPath,
|
|
169
|
-
payload: null,
|
|
170
|
-
error: error.message,
|
|
171
|
-
};
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
function renderBulletList(entries, emptyText, formatter = null) {
|
|
176
|
-
if (!entries || entries.length === 0) {
|
|
177
|
-
return `- ${emptyText}`;
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
return entries
|
|
181
|
-
.map((entry) => {
|
|
182
|
-
const value = formatter ? formatter(entry) : entry;
|
|
183
|
-
return `- ${value}`;
|
|
184
|
-
})
|
|
185
|
-
.join("\n");
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
function renderTable(headers, rows, emptyText) {
|
|
189
|
-
if (!rows || rows.length === 0) {
|
|
190
|
-
return `- ${emptyText}`;
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
const headerRow = `| ${headers.join(" | ")} |`;
|
|
194
|
-
const separatorRow = `| ${headers.map((_, index) => (index === 0 ? "---:" : "---")).join(" | ")} |`;
|
|
195
|
-
const bodyRows = rows.map((row) => `| ${row.join(" | ")} |`).join("\n");
|
|
196
|
-
return [headerRow, separatorRow, bodyRows].join("\n");
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
function buildUpstreamContractRefs(projectPath, featureImplPlanPath, codeHandoffContext) {
|
|
200
|
-
const refs = [normalizePathForDoc(projectPath, featureImplPlanPath)];
|
|
201
|
-
|
|
202
|
-
if (codeHandoffContext && codeHandoffContext.payload && !codeHandoffContext.error) {
|
|
203
|
-
refs.push(normalizePathForDoc(projectPath, codeHandoffContext.handoffPath));
|
|
204
|
-
if (Array.isArray(codeHandoffContext.payload.required_refs)) {
|
|
205
|
-
refs.push(...codeHandoffContext.payload.required_refs);
|
|
206
|
-
}
|
|
207
|
-
} else if (codeHandoffContext && codeHandoffContext.error) {
|
|
208
|
-
refs.push(
|
|
209
|
-
`${normalizePathForDoc(projectPath, codeHandoffContext.handoffPath)} (invalid JSON: ${codeHandoffContext.error})`
|
|
210
|
-
);
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
return uniqueStrings(refs);
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
function buildLinkedContractRefs(codeHandoffContext) {
|
|
217
|
-
if (!codeHandoffContext || !codeHandoffContext.payload || codeHandoffContext.error) {
|
|
218
|
-
return [];
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
return uniqueStrings(
|
|
222
|
-
(codeHandoffContext.payload.required_refs || []).filter((entry) =>
|
|
223
|
-
/docs\/(product|specs|architecture)\//.test(String(entry))
|
|
224
|
-
)
|
|
225
|
-
);
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
function parseProvenanceContext(workflowText) {
|
|
229
|
-
const match = String(workflowText || "").match(/## Provenance\r?\n([\s\S]*?)(?=\r?\n##\s|$)/);
|
|
230
|
-
if (!match) {
|
|
231
|
-
return {
|
|
232
|
-
sectionPresent: false,
|
|
233
|
-
mode: "missing",
|
|
234
|
-
sourceRefs: [],
|
|
235
|
-
body: "",
|
|
236
|
-
};
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
const body = String(match[1] || "").trim();
|
|
240
|
-
const sourceRefMatches = [...body.matchAll(/\|\s*\d+\s*\|\s*([^|]+)\|\s*([^|]+)\|\s*([^|]+)\|\s*([^|]+)\|/g)];
|
|
241
|
-
const sourceRefs = sourceRefMatches
|
|
242
|
-
.map((item) => ({
|
|
243
|
-
source: item[1].trim(),
|
|
244
|
-
location: item[2].trim(),
|
|
245
|
-
consultedDate: item[3].trim(),
|
|
246
|
-
purpose: item[4].trim(),
|
|
247
|
-
}))
|
|
248
|
-
.filter(
|
|
249
|
-
(entry) =>
|
|
250
|
-
![entry.source, entry.location, entry.consultedDate, entry.purpose].some((value) =>
|
|
251
|
-
/^<.+>$/.test(String(value))
|
|
252
|
-
)
|
|
253
|
-
);
|
|
254
|
-
|
|
255
|
-
const hasNoReferenceDeclaration = /no external source references were consulted for this batch\./i.test(body);
|
|
256
|
-
const hasExternalRefs = sourceRefs.length > 0;
|
|
257
|
-
|
|
258
|
-
return {
|
|
259
|
-
sectionPresent: true,
|
|
260
|
-
mode: hasExternalRefs ? "external" : hasNoReferenceDeclaration ? "no_reference" : "missing",
|
|
261
|
-
sourceRefs,
|
|
262
|
-
body,
|
|
263
|
-
};
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
function buildReferenceDisclosure(provenanceContext) {
|
|
267
|
-
if (!provenanceContext.sectionPresent) {
|
|
268
|
-
return {
|
|
269
|
-
mode: "missing",
|
|
270
|
-
lines: [
|
|
271
|
-
"- Warning: workflow plan is missing the required `## Provenance` section.",
|
|
272
|
-
"- Expected no-reference declaration: `No external source references were consulted for this batch.`",
|
|
273
|
-
],
|
|
274
|
-
};
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
if (provenanceContext.mode === "external") {
|
|
278
|
-
return {
|
|
279
|
-
mode: "external",
|
|
280
|
-
lines: [
|
|
281
|
-
"- External references were consulted for this batch.",
|
|
282
|
-
"- Source references:",
|
|
283
|
-
...provenanceContext.sourceRefs.map(
|
|
284
|
-
(entry, index) =>
|
|
285
|
-
` - ${index + 1}. ${entry.source} | ${entry.location} | ${entry.consultedDate} | ${entry.purpose}`
|
|
286
|
-
),
|
|
287
|
-
],
|
|
288
|
-
};
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
if (provenanceContext.mode === "no_reference") {
|
|
292
|
-
return {
|
|
293
|
-
mode: "no_reference",
|
|
294
|
-
lines: ["- No external references were consulted for this batch."],
|
|
295
|
-
};
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
return {
|
|
299
|
-
mode: "missing",
|
|
300
|
-
lines: [
|
|
301
|
-
"- Warning: unable to classify provenance mode from the workflow plan.",
|
|
302
|
-
"- Provide either a complete provenance log or the no-reference declaration.",
|
|
303
|
-
],
|
|
304
|
-
};
|
|
305
|
-
}
|
|
306
|
-
function buildChangedFileRows(changedFiles) {
|
|
307
|
-
return changedFiles.map((entry, index) => [
|
|
308
|
-
String(index + 1),
|
|
309
|
-
`\`${entry.path}\``,
|
|
310
|
-
entry.rationale,
|
|
311
|
-
]);
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
function buildVerificationRows(evidenceEntries) {
|
|
315
|
-
return evidenceEntries.map((entry, index) => [
|
|
316
|
-
String(index + 1),
|
|
317
|
-
`\`${entry.checkName}\``,
|
|
318
|
-
`\`${entry.result}\``,
|
|
319
|
-
`\`${entry.rawOutputRef}\``,
|
|
320
|
-
entry.summary,
|
|
321
|
-
]);
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
function buildEvidenceRows(evidenceEntries) {
|
|
325
|
-
return evidenceEntries.map((entry, index) => [
|
|
326
|
-
String(index + 1),
|
|
327
|
-
entry.summary,
|
|
328
|
-
`\`${entry.rawOutputRef}\``,
|
|
329
|
-
`Gate result: ${entry.result}`,
|
|
330
|
-
]);
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
function buildAutoCaveats(specGateStatus, qualityGateStatus, specNotes, qualityNotes, debugNotes) {
|
|
334
|
-
const results = [];
|
|
335
|
-
const pushGateNotes = (prefix, status, notes, defaultText) => {
|
|
336
|
-
const normalizedNotes = notes.length > 0 ? notes : status !== "pass" ? [defaultText] : [];
|
|
337
|
-
normalizedNotes.forEach((note, index) => {
|
|
338
|
-
results.push({
|
|
339
|
-
id: `AUTO-${prefix}-${index + 1}`,
|
|
340
|
-
statement: note,
|
|
341
|
-
impact: `${prefix.toLowerCase()} gate is currently ${status}.`,
|
|
342
|
-
owner: "SDTK-CODE",
|
|
343
|
-
});
|
|
344
|
-
});
|
|
345
|
-
};
|
|
346
|
-
|
|
347
|
-
pushGateNotes("SPEC", specGateStatus, specNotes, `Spec/compliance gate is ${specGateStatus}.`);
|
|
348
|
-
pushGateNotes("QUALITY", qualityGateStatus, qualityNotes, `Quality gate is ${qualityGateStatus}.`);
|
|
349
|
-
|
|
350
|
-
debugNotes.forEach((note, index) => {
|
|
351
|
-
results.push({
|
|
352
|
-
id: `AUTO-DEBUG-${index + 1}`,
|
|
353
|
-
statement: note,
|
|
354
|
-
impact: "Reactive debug follow-up remains open from the current verify pass.",
|
|
355
|
-
owner: "SDTK-CODE",
|
|
356
|
-
});
|
|
357
|
-
});
|
|
358
|
-
|
|
359
|
-
return results;
|
|
360
|
-
}
|
|
361
|
-
|
|
362
|
-
function buildCaveatRows(explicitCaveats, autoCaveats) {
|
|
363
|
-
return [...explicitCaveats, ...autoCaveats].map((entry, index) => [
|
|
364
|
-
String(index + 1),
|
|
365
|
-
`\`${entry.id}\``,
|
|
366
|
-
entry.statement,
|
|
367
|
-
entry.impact,
|
|
368
|
-
entry.owner,
|
|
369
|
-
]);
|
|
370
|
-
}
|
|
371
|
-
|
|
372
|
-
function buildExclusionRows(excludedFiles, commitExclude) {
|
|
373
|
-
const rows = excludedFiles.map((entry) => ({
|
|
374
|
-
path: entry.path,
|
|
375
|
-
reason: entry.reason,
|
|
376
|
-
}));
|
|
377
|
-
|
|
378
|
-
commitExclude.forEach((entry) => {
|
|
379
|
-
if (!rows.some((row) => row.path === entry)) {
|
|
380
|
-
rows.push({
|
|
381
|
-
path: entry,
|
|
382
|
-
reason: "Excluded from the proposed commit boundary during verify.",
|
|
383
|
-
});
|
|
384
|
-
}
|
|
385
|
-
});
|
|
386
|
-
|
|
387
|
-
return rows.map((entry, index) => [
|
|
388
|
-
String(index + 1),
|
|
389
|
-
`\`${entry.path}\``,
|
|
390
|
-
entry.reason,
|
|
391
|
-
]);
|
|
392
|
-
}
|
|
393
|
-
|
|
394
|
-
function buildTruthSyncRows(truthSyncTargets) {
|
|
395
|
-
return truthSyncTargets.map((entry, index) => [
|
|
396
|
-
String(index + 1),
|
|
397
|
-
entry.target,
|
|
398
|
-
`\`${entry.status}\``,
|
|
399
|
-
entry.rationale,
|
|
400
|
-
]);
|
|
401
|
-
}
|
|
402
|
-
|
|
403
|
-
function buildCommitBoundary(changedFiles, excludedFiles, commitInclude, commitExclude) {
|
|
404
|
-
const includeList =
|
|
405
|
-
commitInclude.length > 0
|
|
406
|
-
? uniqueStrings(commitInclude)
|
|
407
|
-
: uniqueStrings(changedFiles.map((entry) => entry.path));
|
|
408
|
-
const excludeList =
|
|
409
|
-
commitExclude.length > 0
|
|
410
|
-
? uniqueStrings(commitExclude)
|
|
411
|
-
: uniqueStrings(excludedFiles.map((entry) => entry.path));
|
|
412
|
-
|
|
413
|
-
return {
|
|
414
|
-
includeList,
|
|
415
|
-
excludeList,
|
|
416
|
-
};
|
|
417
|
-
}
|
|
418
|
-
|
|
419
|
-
function buildReviewerGuidance(
|
|
420
|
-
reviewerGuidance,
|
|
421
|
-
truthSyncTargets,
|
|
422
|
-
specNotes,
|
|
423
|
-
qualityNotes,
|
|
424
|
-
debugNotes,
|
|
425
|
-
changedFiles,
|
|
426
|
-
commitBoundary,
|
|
427
|
-
codeHandoffContext
|
|
428
|
-
) {
|
|
429
|
-
const guidance = [...reviewerGuidance];
|
|
430
|
-
|
|
431
|
-
guidance.push(...specNotes.map((entry) => `Spec/compliance follow-up: ${entry}`));
|
|
432
|
-
guidance.push(...qualityNotes.map((entry) => `Quality follow-up: ${entry}`));
|
|
433
|
-
guidance.push(...debugNotes.map((entry) => `Debug follow-up: ${entry}`));
|
|
434
|
-
|
|
435
|
-
if (truthSyncTargets.length === 0) {
|
|
436
|
-
guidance.push(
|
|
437
|
-
"Truth-sync targets were not explicitly provided during verify; downstream review should confirm whether docs, help, runtime, and tests were intentionally untouched."
|
|
438
|
-
);
|
|
439
|
-
}
|
|
440
|
-
|
|
441
|
-
if (changedFiles.length === 0 || commitBoundary.includeList.length === 0) {
|
|
442
|
-
guidance.push(
|
|
443
|
-
"Changed-file or commit-boundary details are incomplete in this verify pass; QA/controller review should treat commit inclusion as provisional until the author records the exact file set."
|
|
444
|
-
);
|
|
445
|
-
}
|
|
446
|
-
|
|
447
|
-
if (codeHandoffContext && codeHandoffContext.error) {
|
|
448
|
-
guidance.push(
|
|
449
|
-
`Formal CODE_HANDOFF could not be parsed while generating the review packet: ${codeHandoffContext.error}`
|
|
450
|
-
);
|
|
451
|
-
}
|
|
452
|
-
|
|
453
|
-
guidance.push(
|
|
454
|
-
"This packet is an evidence package only; final approval remains with downstream QA and the controller."
|
|
455
|
-
);
|
|
456
|
-
guidance.push(
|
|
457
|
-
"No bounded audits were run during verify; the controller may request a bounded audit later if a narrow question remains."
|
|
458
|
-
);
|
|
459
|
-
guidance.push(
|
|
460
|
-
"If QA or controller rejects this batch, keep the next pass bounded to the recorded findings and refresh in order: verify -> QA -> controller."
|
|
461
|
-
);
|
|
462
|
-
|
|
463
|
-
return uniqueStrings(guidance);
|
|
464
|
-
}
|
|
465
|
-
|
|
466
|
-
function createReviewPacket({
|
|
467
|
-
projectPath,
|
|
468
|
-
featureKey,
|
|
469
|
-
workflowText,
|
|
470
|
-
evidenceEntries,
|
|
471
|
-
specGateStatus,
|
|
472
|
-
qualityGateStatus,
|
|
473
|
-
specNotes,
|
|
474
|
-
qualityNotes,
|
|
475
|
-
debugNotes,
|
|
476
|
-
batchSummary,
|
|
477
|
-
changedFiles,
|
|
478
|
-
excludedFiles,
|
|
479
|
-
truthSyncTargets,
|
|
480
|
-
commitInclude,
|
|
481
|
-
commitExclude,
|
|
482
|
-
caveats,
|
|
483
|
-
reviewerGuidance,
|
|
484
|
-
}) {
|
|
485
|
-
const featureName = humanizeFeatureKey(featureKey);
|
|
486
|
-
const scopeContext = loadScopeContext(workflowText);
|
|
487
|
-
const featureImplPlanContext = loadFeatureImplPlanContext(projectPath, featureKey);
|
|
488
|
-
const codeHandoffContext = loadCodeHandoffContext(projectPath, featureKey);
|
|
489
|
-
const workflowStageSnapshot = loadWorkflowStageSnapshot(workflowText);
|
|
490
|
-
const reviewPacketPath = getReviewPacketPath(projectPath, featureKey);
|
|
491
|
-
const commitBoundary = buildCommitBoundary(changedFiles, excludedFiles, commitInclude, commitExclude);
|
|
492
|
-
const effectiveBatchSummary =
|
|
493
|
-
(batchSummary && batchSummary.trim()) ||
|
|
494
|
-
(scopeContext.sliceTitles.length > 0
|
|
495
|
-
? `Verify pass for approved slices: ${scopeContext.sliceTitles.join("; ")}`
|
|
496
|
-
: `Verify pass for ${featureName}.`);
|
|
497
|
-
const autoCaveats = buildAutoCaveats(
|
|
498
|
-
specGateStatus,
|
|
499
|
-
qualityGateStatus,
|
|
500
|
-
specNotes,
|
|
501
|
-
qualityNotes,
|
|
502
|
-
debugNotes
|
|
503
|
-
);
|
|
504
|
-
const effectiveOutOfScope =
|
|
505
|
-
scopeContext.outScope.length > 0
|
|
506
|
-
? scopeContext.outScope
|
|
507
|
-
: featureImplPlanContext.nonGoals;
|
|
508
|
-
const upstreamContractRefs = buildUpstreamContractRefs(
|
|
509
|
-
projectPath,
|
|
510
|
-
featureImplPlanContext.featureImplPlanPath,
|
|
511
|
-
codeHandoffContext
|
|
512
|
-
);
|
|
513
|
-
const linkedContractRefs = buildLinkedContractRefs(codeHandoffContext);
|
|
514
|
-
const provenanceContext = parseProvenanceContext(workflowText);
|
|
515
|
-
const referenceDisclosure = buildReferenceDisclosure(provenanceContext);
|
|
516
|
-
const guidance = buildReviewerGuidance(
|
|
517
|
-
reviewerGuidance,
|
|
518
|
-
truthSyncTargets,
|
|
519
|
-
specNotes,
|
|
520
|
-
qualityNotes,
|
|
521
|
-
debugNotes,
|
|
522
|
-
changedFiles,
|
|
523
|
-
commitBoundary,
|
|
524
|
-
codeHandoffContext
|
|
525
|
-
);
|
|
526
|
-
|
|
527
|
-
const content = [
|
|
528
|
-
`# REVIEW PACKET: ${featureKey}`,
|
|
529
|
-
"",
|
|
530
|
-
"## 1. Review Context",
|
|
531
|
-
`- Feature key: \`${featureKey}\``,
|
|
532
|
-
`- Feature name: ${featureName}`,
|
|
533
|
-
`- Batch summary: ${effectiveBatchSummary}`,
|
|
534
|
-
`- Review date: \`${new Date().toISOString()}\``,
|
|
535
|
-
"- Upstream contract refs:",
|
|
536
|
-
...upstreamContractRefs.map((entry) => ` - \`${entry}\``),
|
|
537
|
-
"",
|
|
538
|
-
"## 2. Approved Scope Snapshot",
|
|
539
|
-
"### Workflow Stage Snapshot",
|
|
540
|
-
`- Current workflow phase when verify started: \`${workflowStageSnapshot.currentPhase}\``,
|
|
541
|
-
`- Phase status when verify started: \`${workflowStageSnapshot.phaseStatus}\``,
|
|
542
|
-
`- Intake outcome: \`${workflowStageSnapshot.intakeOutcome}\``,
|
|
543
|
-
`- Next recommended phase before verify refresh: \`${workflowStageSnapshot.nextPhase}\``,
|
|
544
|
-
`- Blocking state before verify refresh: \`${workflowStageSnapshot.blockingState}\``,
|
|
545
|
-
"",
|
|
546
|
-
"### In Scope",
|
|
547
|
-
renderBulletList(
|
|
548
|
-
scopeContext.inScope,
|
|
549
|
-
"No explicit in-scope items were recorded beyond the current verify pass."
|
|
550
|
-
),
|
|
551
|
-
"",
|
|
552
|
-
"### Out Of Scope",
|
|
553
|
-
renderBulletList(
|
|
554
|
-
effectiveOutOfScope,
|
|
555
|
-
"No explicit out-of-scope items were recorded; defer to the upstream feature implementation plan."
|
|
556
|
-
),
|
|
557
|
-
"",
|
|
558
|
-
"### Linked Backlog / Contract Refs",
|
|
559
|
-
renderBulletList(
|
|
560
|
-
linkedContractRefs,
|
|
561
|
-
"No additional backlog or contract refs were discovered beyond the upstream handoff."
|
|
562
|
-
),
|
|
563
|
-
"",
|
|
564
|
-
"## 3. Changed Files",
|
|
565
|
-
renderTable(
|
|
566
|
-
["No", "Path", "Rationale"],
|
|
567
|
-
buildChangedFileRows(changedFiles),
|
|
568
|
-
"No changed-file entries were recorded during verify."
|
|
569
|
-
),
|
|
570
|
-
"",
|
|
571
|
-
"## 4. Verification Commands Executed",
|
|
572
|
-
renderTable(
|
|
573
|
-
["No", "Command", "Result", "Evidence Ref", "Notes"],
|
|
574
|
-
buildVerificationRows(evidenceEntries),
|
|
575
|
-
"No verification commands were recorded during verify."
|
|
576
|
-
),
|
|
577
|
-
"",
|
|
578
|
-
"## 5. Evidence Index",
|
|
579
|
-
renderTable(
|
|
580
|
-
["No", "Claim", "Evidence Path", "Reviewer Note"],
|
|
581
|
-
buildEvidenceRows(evidenceEntries),
|
|
582
|
-
"No evidence claims were indexed during verify."
|
|
583
|
-
),
|
|
584
|
-
"",
|
|
585
|
-
"## 6. Known Caveats And Unproven Claims",
|
|
586
|
-
renderTable(
|
|
587
|
-
["No", "Caveat ID", "Statement", "Impact", "Follow-Up Owner"],
|
|
588
|
-
buildCaveatRows(caveats, autoCaveats),
|
|
589
|
-
"No explicit caveats or unproven claims were recorded during verify."
|
|
590
|
-
),
|
|
591
|
-
"",
|
|
592
|
-
"## 7. Unrelated Dirt And Exclusions",
|
|
593
|
-
renderTable(
|
|
594
|
-
["No", "Path", "Exclusion Reason"],
|
|
595
|
-
buildExclusionRows(excludedFiles, commitBoundary.excludeList),
|
|
596
|
-
"No unrelated dirt or exclusions were recorded during verify."
|
|
597
|
-
),
|
|
598
|
-
"",
|
|
599
|
-
"## 8. Truth-Sync Targets",
|
|
600
|
-
renderTable(
|
|
601
|
-
["No", "Target Path / Surface", "Status", "Rationale"],
|
|
602
|
-
buildTruthSyncRows(truthSyncTargets),
|
|
603
|
-
"No explicit truth-sync targets were recorded during verify. Downstream review must confirm whether docs, help, runtime, and tests were intentionally untouched."
|
|
604
|
-
),
|
|
605
|
-
"",
|
|
606
|
-
"## 9. Proposed Commit Boundary",
|
|
607
|
-
"### Include List",
|
|
608
|
-
renderBulletList(
|
|
609
|
-
commitBoundary.includeList,
|
|
610
|
-
"No include list was recorded during verify."
|
|
611
|
-
),
|
|
612
|
-
"",
|
|
613
|
-
"### Exclude List",
|
|
614
|
-
renderBulletList(
|
|
615
|
-
commitBoundary.excludeList,
|
|
616
|
-
"No exclude list was recorded during verify."
|
|
617
|
-
),
|
|
618
|
-
"",
|
|
619
|
-
"### Batch Rationale",
|
|
620
|
-
`- ${effectiveBatchSummary}`,
|
|
621
|
-
"",
|
|
622
|
-
"## 10. Reviewer Guidance",
|
|
623
|
-
renderBulletList(
|
|
624
|
-
guidance,
|
|
625
|
-
"No additional reviewer guidance was recorded during verify."
|
|
626
|
-
),
|
|
627
|
-
"",
|
|
628
|
-
"## 11. Reference Disclosure",
|
|
629
|
-
renderBulletList(
|
|
630
|
-
referenceDisclosure.lines,
|
|
631
|
-
"Reference disclosure details were not generated."
|
|
632
|
-
),
|
|
633
|
-
"",
|
|
634
|
-
].join("\n");
|
|
635
|
-
|
|
636
|
-
fs.mkdirSync(path.dirname(reviewPacketPath), { recursive: true });
|
|
637
|
-
fs.writeFileSync(reviewPacketPath, content, "utf-8");
|
|
638
|
-
|
|
639
|
-
return {
|
|
640
|
-
reviewPacketPath,
|
|
641
|
-
hasReferenceDisclosure: content.includes("## 11. Reference Disclosure"),
|
|
642
|
-
provenanceMode: provenanceContext.mode,
|
|
643
|
-
referenceDisclosureMode: referenceDisclosure.mode,
|
|
644
|
-
};
|
|
645
|
-
}
|
|
646
|
-
|
|
647
|
-
module.exports = {
|
|
648
|
-
createReviewPacket,
|
|
649
|
-
getReviewPacketPath,
|
|
650
|
-
};
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const fs = require("fs");
|
|
4
|
+
const path = require("path");
|
|
5
|
+
const { extractManagedBlock } = require("./workflow-artifact");
|
|
6
|
+
|
|
7
|
+
const PLACEHOLDER_BULLETS = new Set([
|
|
8
|
+
"Pending confirmation during workflow planning.",
|
|
9
|
+
"Pending lane-specific planning or build guidance.",
|
|
10
|
+
"Lightweight bugfix planning not recorded yet.",
|
|
11
|
+
"No active build slices recorded yet.",
|
|
12
|
+
"Pending build-phase execution.",
|
|
13
|
+
]);
|
|
14
|
+
const STALE_HANDOFF_OUT_OF_SCOPE_PATTERNS = [
|
|
15
|
+
/FEATURE_IMPL_PLAN \+ CODE_HANDOFF/i,
|
|
16
|
+
/no change to the `\/dev` boundary/i,
|
|
17
|
+
];
|
|
18
|
+
|
|
19
|
+
function getReviewPacketPath(projectPath, featureKey) {
|
|
20
|
+
return path.join(projectPath, "docs", "dev", `REVIEW_PACKET_${featureKey}.md`);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function normalizeEntries(entries) {
|
|
24
|
+
return (entries || []).map((entry) => String(entry).trim()).filter(Boolean);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function uniqueStrings(entries) {
|
|
28
|
+
return [...new Set(normalizeEntries(entries))];
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function humanizeFeatureKey(featureKey) {
|
|
32
|
+
return String(featureKey)
|
|
33
|
+
.split("_")
|
|
34
|
+
.filter(Boolean)
|
|
35
|
+
.map((token) => token.charAt(0) + token.slice(1).toLowerCase())
|
|
36
|
+
.join(" ");
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function normalizePathForDoc(projectPath, targetPath) {
|
|
40
|
+
return path.relative(projectPath, targetPath).split(path.sep).join("/");
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function parseBulletSection(text, heading) {
|
|
44
|
+
if (!text) {
|
|
45
|
+
return [];
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const escaped = heading.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
49
|
+
const match = text.match(new RegExp(`### ${escaped}\\r?\\n([\\s\\S]*?)(?=\\r?\\n(?:### |## |---)|$)`));
|
|
50
|
+
if (!match) {
|
|
51
|
+
return [];
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return match[1]
|
|
55
|
+
.split(/\r?\n/)
|
|
56
|
+
.map((line) => line.trim())
|
|
57
|
+
.filter((line) => line.startsWith("- "))
|
|
58
|
+
.map((line) => line.slice(2).trim())
|
|
59
|
+
.filter(Boolean);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function parseManagedField(blockText, label) {
|
|
63
|
+
if (!blockText) {
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const escaped = label.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
68
|
+
const match = blockText.match(new RegExp(`- ${escaped}: \`([^\\r\\n\`]+)\``));
|
|
69
|
+
return match ? match[1] : null;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function parseInlineSliceSection(planBlock) {
|
|
73
|
+
if (!planBlock) {
|
|
74
|
+
return [];
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const match = planBlock.match(/## 4\. Plan \/ Slices\r?\n([\s\S]*?)(?=\r?\n### Planning Notes)/);
|
|
78
|
+
if (!match) {
|
|
79
|
+
return [];
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return match[1]
|
|
83
|
+
.split(/\r?\n/)
|
|
84
|
+
.map((line) => line.trim())
|
|
85
|
+
.filter((line) => line.startsWith("- "))
|
|
86
|
+
.map((line) => line.slice(2).trim())
|
|
87
|
+
.filter(Boolean);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function cleanBulletEntries(entries) {
|
|
91
|
+
return uniqueStrings(entries).filter((entry) => !PLACEHOLDER_BULLETS.has(entry));
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function filterStaleHandoffOutOfScopeEntries(entries) {
|
|
95
|
+
return cleanBulletEntries(entries).filter(
|
|
96
|
+
(entry) => !STALE_HANDOFF_OUT_OF_SCOPE_PATTERNS.some((pattern) => pattern.test(entry))
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function loadScopeContext(workflowText) {
|
|
101
|
+
const planBlock = extractManagedBlock(workflowText, "PLAN");
|
|
102
|
+
const inScope = cleanBulletEntries(parseBulletSection(planBlock, "In Scope"));
|
|
103
|
+
const outScope = filterStaleHandoffOutOfScopeEntries(parseBulletSection(planBlock, "Out Of Scope"));
|
|
104
|
+
let sliceTitles = cleanBulletEntries(parseBulletSection(planBlock, "Finalized Slices After `plan`"));
|
|
105
|
+
if (sliceTitles.length === 0) {
|
|
106
|
+
sliceTitles = cleanBulletEntries(parseInlineSliceSection(planBlock));
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
return {
|
|
110
|
+
inScope:
|
|
111
|
+
inScope.length > 0
|
|
112
|
+
? inScope
|
|
113
|
+
: sliceTitles.map((entry) => `Approved execution slice: ${entry}`),
|
|
114
|
+
outScope,
|
|
115
|
+
sliceTitles,
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function loadWorkflowStageSnapshot(workflowText) {
|
|
120
|
+
const metadataBlock = extractManagedBlock(workflowText, "METADATA");
|
|
121
|
+
const statusBlock = extractManagedBlock(workflowText, "STATUS");
|
|
122
|
+
|
|
123
|
+
return {
|
|
124
|
+
currentPhase: parseManagedField(metadataBlock, "Current phase") || "unknown",
|
|
125
|
+
phaseStatus: parseManagedField(metadataBlock, "Phase status") || "unknown",
|
|
126
|
+
intakeOutcome: parseManagedField(metadataBlock, "Intake outcome") || "unknown",
|
|
127
|
+
nextPhase: parseManagedField(statusBlock, "Next recommended phase") || "unknown",
|
|
128
|
+
blockingState: parseManagedField(statusBlock, "Blocking state") || "unknown",
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
function loadFeatureImplPlanContext(projectPath, featureKey) {
|
|
133
|
+
const featureImplPlanPath = path.join(projectPath, "docs", "dev", `FEATURE_IMPL_PLAN_${featureKey}.md`);
|
|
134
|
+
if (!fs.existsSync(featureImplPlanPath)) {
|
|
135
|
+
return {
|
|
136
|
+
featureImplPlanPath,
|
|
137
|
+
nonGoals: [],
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
const text = fs.readFileSync(featureImplPlanPath, "utf-8");
|
|
142
|
+
return {
|
|
143
|
+
featureImplPlanPath,
|
|
144
|
+
nonGoals: filterStaleHandoffOutOfScopeEntries(
|
|
145
|
+
parseBulletSection(text, "2.5 Explicit Non-Goals For This Handoff")
|
|
146
|
+
),
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function loadCodeHandoffContext(projectPath, featureKey) {
|
|
151
|
+
const handoffPath = path.join(projectPath, "docs", "dev", `CODE_HANDOFF_${featureKey}.json`);
|
|
152
|
+
if (!fs.existsSync(handoffPath)) {
|
|
153
|
+
return {
|
|
154
|
+
handoffPath,
|
|
155
|
+
payload: null,
|
|
156
|
+
error: null,
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
try {
|
|
161
|
+
return {
|
|
162
|
+
handoffPath,
|
|
163
|
+
payload: JSON.parse(fs.readFileSync(handoffPath, "utf-8")),
|
|
164
|
+
error: null,
|
|
165
|
+
};
|
|
166
|
+
} catch (error) {
|
|
167
|
+
return {
|
|
168
|
+
handoffPath,
|
|
169
|
+
payload: null,
|
|
170
|
+
error: error.message,
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
function renderBulletList(entries, emptyText, formatter = null) {
|
|
176
|
+
if (!entries || entries.length === 0) {
|
|
177
|
+
return `- ${emptyText}`;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
return entries
|
|
181
|
+
.map((entry) => {
|
|
182
|
+
const value = formatter ? formatter(entry) : entry;
|
|
183
|
+
return `- ${value}`;
|
|
184
|
+
})
|
|
185
|
+
.join("\n");
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
function renderTable(headers, rows, emptyText) {
|
|
189
|
+
if (!rows || rows.length === 0) {
|
|
190
|
+
return `- ${emptyText}`;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
const headerRow = `| ${headers.join(" | ")} |`;
|
|
194
|
+
const separatorRow = `| ${headers.map((_, index) => (index === 0 ? "---:" : "---")).join(" | ")} |`;
|
|
195
|
+
const bodyRows = rows.map((row) => `| ${row.join(" | ")} |`).join("\n");
|
|
196
|
+
return [headerRow, separatorRow, bodyRows].join("\n");
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
function buildUpstreamContractRefs(projectPath, featureImplPlanPath, codeHandoffContext) {
|
|
200
|
+
const refs = [normalizePathForDoc(projectPath, featureImplPlanPath)];
|
|
201
|
+
|
|
202
|
+
if (codeHandoffContext && codeHandoffContext.payload && !codeHandoffContext.error) {
|
|
203
|
+
refs.push(normalizePathForDoc(projectPath, codeHandoffContext.handoffPath));
|
|
204
|
+
if (Array.isArray(codeHandoffContext.payload.required_refs)) {
|
|
205
|
+
refs.push(...codeHandoffContext.payload.required_refs);
|
|
206
|
+
}
|
|
207
|
+
} else if (codeHandoffContext && codeHandoffContext.error) {
|
|
208
|
+
refs.push(
|
|
209
|
+
`${normalizePathForDoc(projectPath, codeHandoffContext.handoffPath)} (invalid JSON: ${codeHandoffContext.error})`
|
|
210
|
+
);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
return uniqueStrings(refs);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
function buildLinkedContractRefs(codeHandoffContext) {
|
|
217
|
+
if (!codeHandoffContext || !codeHandoffContext.payload || codeHandoffContext.error) {
|
|
218
|
+
return [];
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
return uniqueStrings(
|
|
222
|
+
(codeHandoffContext.payload.required_refs || []).filter((entry) =>
|
|
223
|
+
/docs\/(product|specs|architecture)\//.test(String(entry))
|
|
224
|
+
)
|
|
225
|
+
);
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
function parseProvenanceContext(workflowText) {
|
|
229
|
+
const match = String(workflowText || "").match(/## Provenance\r?\n([\s\S]*?)(?=\r?\n##\s|$)/);
|
|
230
|
+
if (!match) {
|
|
231
|
+
return {
|
|
232
|
+
sectionPresent: false,
|
|
233
|
+
mode: "missing",
|
|
234
|
+
sourceRefs: [],
|
|
235
|
+
body: "",
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
const body = String(match[1] || "").trim();
|
|
240
|
+
const sourceRefMatches = [...body.matchAll(/\|\s*\d+\s*\|\s*([^|]+)\|\s*([^|]+)\|\s*([^|]+)\|\s*([^|]+)\|/g)];
|
|
241
|
+
const sourceRefs = sourceRefMatches
|
|
242
|
+
.map((item) => ({
|
|
243
|
+
source: item[1].trim(),
|
|
244
|
+
location: item[2].trim(),
|
|
245
|
+
consultedDate: item[3].trim(),
|
|
246
|
+
purpose: item[4].trim(),
|
|
247
|
+
}))
|
|
248
|
+
.filter(
|
|
249
|
+
(entry) =>
|
|
250
|
+
![entry.source, entry.location, entry.consultedDate, entry.purpose].some((value) =>
|
|
251
|
+
/^<.+>$/.test(String(value))
|
|
252
|
+
)
|
|
253
|
+
);
|
|
254
|
+
|
|
255
|
+
const hasNoReferenceDeclaration = /no external source references were consulted for this batch\./i.test(body);
|
|
256
|
+
const hasExternalRefs = sourceRefs.length > 0;
|
|
257
|
+
|
|
258
|
+
return {
|
|
259
|
+
sectionPresent: true,
|
|
260
|
+
mode: hasExternalRefs ? "external" : hasNoReferenceDeclaration ? "no_reference" : "missing",
|
|
261
|
+
sourceRefs,
|
|
262
|
+
body,
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
function buildReferenceDisclosure(provenanceContext) {
|
|
267
|
+
if (!provenanceContext.sectionPresent) {
|
|
268
|
+
return {
|
|
269
|
+
mode: "missing",
|
|
270
|
+
lines: [
|
|
271
|
+
"- Warning: workflow plan is missing the required `## Provenance` section.",
|
|
272
|
+
"- Expected no-reference declaration: `No external source references were consulted for this batch.`",
|
|
273
|
+
],
|
|
274
|
+
};
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
if (provenanceContext.mode === "external") {
|
|
278
|
+
return {
|
|
279
|
+
mode: "external",
|
|
280
|
+
lines: [
|
|
281
|
+
"- External references were consulted for this batch.",
|
|
282
|
+
"- Source references:",
|
|
283
|
+
...provenanceContext.sourceRefs.map(
|
|
284
|
+
(entry, index) =>
|
|
285
|
+
` - ${index + 1}. ${entry.source} | ${entry.location} | ${entry.consultedDate} | ${entry.purpose}`
|
|
286
|
+
),
|
|
287
|
+
],
|
|
288
|
+
};
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
if (provenanceContext.mode === "no_reference") {
|
|
292
|
+
return {
|
|
293
|
+
mode: "no_reference",
|
|
294
|
+
lines: ["- No external references were consulted for this batch."],
|
|
295
|
+
};
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
return {
|
|
299
|
+
mode: "missing",
|
|
300
|
+
lines: [
|
|
301
|
+
"- Warning: unable to classify provenance mode from the workflow plan.",
|
|
302
|
+
"- Provide either a complete provenance log or the no-reference declaration.",
|
|
303
|
+
],
|
|
304
|
+
};
|
|
305
|
+
}
|
|
306
|
+
function buildChangedFileRows(changedFiles) {
|
|
307
|
+
return changedFiles.map((entry, index) => [
|
|
308
|
+
String(index + 1),
|
|
309
|
+
`\`${entry.path}\``,
|
|
310
|
+
entry.rationale,
|
|
311
|
+
]);
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
function buildVerificationRows(evidenceEntries) {
|
|
315
|
+
return evidenceEntries.map((entry, index) => [
|
|
316
|
+
String(index + 1),
|
|
317
|
+
`\`${entry.checkName}\``,
|
|
318
|
+
`\`${entry.result}\``,
|
|
319
|
+
`\`${entry.rawOutputRef}\``,
|
|
320
|
+
entry.summary,
|
|
321
|
+
]);
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
function buildEvidenceRows(evidenceEntries) {
|
|
325
|
+
return evidenceEntries.map((entry, index) => [
|
|
326
|
+
String(index + 1),
|
|
327
|
+
entry.summary,
|
|
328
|
+
`\`${entry.rawOutputRef}\``,
|
|
329
|
+
`Gate result: ${entry.result}`,
|
|
330
|
+
]);
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
function buildAutoCaveats(specGateStatus, qualityGateStatus, specNotes, qualityNotes, debugNotes) {
|
|
334
|
+
const results = [];
|
|
335
|
+
const pushGateNotes = (prefix, status, notes, defaultText) => {
|
|
336
|
+
const normalizedNotes = notes.length > 0 ? notes : status !== "pass" ? [defaultText] : [];
|
|
337
|
+
normalizedNotes.forEach((note, index) => {
|
|
338
|
+
results.push({
|
|
339
|
+
id: `AUTO-${prefix}-${index + 1}`,
|
|
340
|
+
statement: note,
|
|
341
|
+
impact: `${prefix.toLowerCase()} gate is currently ${status}.`,
|
|
342
|
+
owner: "SDTK-CODE",
|
|
343
|
+
});
|
|
344
|
+
});
|
|
345
|
+
};
|
|
346
|
+
|
|
347
|
+
pushGateNotes("SPEC", specGateStatus, specNotes, `Spec/compliance gate is ${specGateStatus}.`);
|
|
348
|
+
pushGateNotes("QUALITY", qualityGateStatus, qualityNotes, `Quality gate is ${qualityGateStatus}.`);
|
|
349
|
+
|
|
350
|
+
debugNotes.forEach((note, index) => {
|
|
351
|
+
results.push({
|
|
352
|
+
id: `AUTO-DEBUG-${index + 1}`,
|
|
353
|
+
statement: note,
|
|
354
|
+
impact: "Reactive debug follow-up remains open from the current verify pass.",
|
|
355
|
+
owner: "SDTK-CODE",
|
|
356
|
+
});
|
|
357
|
+
});
|
|
358
|
+
|
|
359
|
+
return results;
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
function buildCaveatRows(explicitCaveats, autoCaveats) {
|
|
363
|
+
return [...explicitCaveats, ...autoCaveats].map((entry, index) => [
|
|
364
|
+
String(index + 1),
|
|
365
|
+
`\`${entry.id}\``,
|
|
366
|
+
entry.statement,
|
|
367
|
+
entry.impact,
|
|
368
|
+
entry.owner,
|
|
369
|
+
]);
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
function buildExclusionRows(excludedFiles, commitExclude) {
|
|
373
|
+
const rows = excludedFiles.map((entry) => ({
|
|
374
|
+
path: entry.path,
|
|
375
|
+
reason: entry.reason,
|
|
376
|
+
}));
|
|
377
|
+
|
|
378
|
+
commitExclude.forEach((entry) => {
|
|
379
|
+
if (!rows.some((row) => row.path === entry)) {
|
|
380
|
+
rows.push({
|
|
381
|
+
path: entry,
|
|
382
|
+
reason: "Excluded from the proposed commit boundary during verify.",
|
|
383
|
+
});
|
|
384
|
+
}
|
|
385
|
+
});
|
|
386
|
+
|
|
387
|
+
return rows.map((entry, index) => [
|
|
388
|
+
String(index + 1),
|
|
389
|
+
`\`${entry.path}\``,
|
|
390
|
+
entry.reason,
|
|
391
|
+
]);
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
function buildTruthSyncRows(truthSyncTargets) {
|
|
395
|
+
return truthSyncTargets.map((entry, index) => [
|
|
396
|
+
String(index + 1),
|
|
397
|
+
entry.target,
|
|
398
|
+
`\`${entry.status}\``,
|
|
399
|
+
entry.rationale,
|
|
400
|
+
]);
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
function buildCommitBoundary(changedFiles, excludedFiles, commitInclude, commitExclude) {
|
|
404
|
+
const includeList =
|
|
405
|
+
commitInclude.length > 0
|
|
406
|
+
? uniqueStrings(commitInclude)
|
|
407
|
+
: uniqueStrings(changedFiles.map((entry) => entry.path));
|
|
408
|
+
const excludeList =
|
|
409
|
+
commitExclude.length > 0
|
|
410
|
+
? uniqueStrings(commitExclude)
|
|
411
|
+
: uniqueStrings(excludedFiles.map((entry) => entry.path));
|
|
412
|
+
|
|
413
|
+
return {
|
|
414
|
+
includeList,
|
|
415
|
+
excludeList,
|
|
416
|
+
};
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
function buildReviewerGuidance(
|
|
420
|
+
reviewerGuidance,
|
|
421
|
+
truthSyncTargets,
|
|
422
|
+
specNotes,
|
|
423
|
+
qualityNotes,
|
|
424
|
+
debugNotes,
|
|
425
|
+
changedFiles,
|
|
426
|
+
commitBoundary,
|
|
427
|
+
codeHandoffContext
|
|
428
|
+
) {
|
|
429
|
+
const guidance = [...reviewerGuidance];
|
|
430
|
+
|
|
431
|
+
guidance.push(...specNotes.map((entry) => `Spec/compliance follow-up: ${entry}`));
|
|
432
|
+
guidance.push(...qualityNotes.map((entry) => `Quality follow-up: ${entry}`));
|
|
433
|
+
guidance.push(...debugNotes.map((entry) => `Debug follow-up: ${entry}`));
|
|
434
|
+
|
|
435
|
+
if (truthSyncTargets.length === 0) {
|
|
436
|
+
guidance.push(
|
|
437
|
+
"Truth-sync targets were not explicitly provided during verify; downstream review should confirm whether docs, help, runtime, and tests were intentionally untouched."
|
|
438
|
+
);
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
if (changedFiles.length === 0 || commitBoundary.includeList.length === 0) {
|
|
442
|
+
guidance.push(
|
|
443
|
+
"Changed-file or commit-boundary details are incomplete in this verify pass; QA/controller review should treat commit inclusion as provisional until the author records the exact file set."
|
|
444
|
+
);
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
if (codeHandoffContext && codeHandoffContext.error) {
|
|
448
|
+
guidance.push(
|
|
449
|
+
`Formal CODE_HANDOFF could not be parsed while generating the review packet: ${codeHandoffContext.error}`
|
|
450
|
+
);
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
guidance.push(
|
|
454
|
+
"This packet is an evidence package only; final approval remains with downstream QA and the controller."
|
|
455
|
+
);
|
|
456
|
+
guidance.push(
|
|
457
|
+
"No bounded audits were run during verify; the controller may request a bounded audit later if a narrow question remains."
|
|
458
|
+
);
|
|
459
|
+
guidance.push(
|
|
460
|
+
"If QA or controller rejects this batch, keep the next pass bounded to the recorded findings and refresh in order: verify -> QA -> controller."
|
|
461
|
+
);
|
|
462
|
+
|
|
463
|
+
return uniqueStrings(guidance);
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
function createReviewPacket({
|
|
467
|
+
projectPath,
|
|
468
|
+
featureKey,
|
|
469
|
+
workflowText,
|
|
470
|
+
evidenceEntries,
|
|
471
|
+
specGateStatus,
|
|
472
|
+
qualityGateStatus,
|
|
473
|
+
specNotes,
|
|
474
|
+
qualityNotes,
|
|
475
|
+
debugNotes,
|
|
476
|
+
batchSummary,
|
|
477
|
+
changedFiles,
|
|
478
|
+
excludedFiles,
|
|
479
|
+
truthSyncTargets,
|
|
480
|
+
commitInclude,
|
|
481
|
+
commitExclude,
|
|
482
|
+
caveats,
|
|
483
|
+
reviewerGuidance,
|
|
484
|
+
}) {
|
|
485
|
+
const featureName = humanizeFeatureKey(featureKey);
|
|
486
|
+
const scopeContext = loadScopeContext(workflowText);
|
|
487
|
+
const featureImplPlanContext = loadFeatureImplPlanContext(projectPath, featureKey);
|
|
488
|
+
const codeHandoffContext = loadCodeHandoffContext(projectPath, featureKey);
|
|
489
|
+
const workflowStageSnapshot = loadWorkflowStageSnapshot(workflowText);
|
|
490
|
+
const reviewPacketPath = getReviewPacketPath(projectPath, featureKey);
|
|
491
|
+
const commitBoundary = buildCommitBoundary(changedFiles, excludedFiles, commitInclude, commitExclude);
|
|
492
|
+
const effectiveBatchSummary =
|
|
493
|
+
(batchSummary && batchSummary.trim()) ||
|
|
494
|
+
(scopeContext.sliceTitles.length > 0
|
|
495
|
+
? `Verify pass for approved slices: ${scopeContext.sliceTitles.join("; ")}`
|
|
496
|
+
: `Verify pass for ${featureName}.`);
|
|
497
|
+
const autoCaveats = buildAutoCaveats(
|
|
498
|
+
specGateStatus,
|
|
499
|
+
qualityGateStatus,
|
|
500
|
+
specNotes,
|
|
501
|
+
qualityNotes,
|
|
502
|
+
debugNotes
|
|
503
|
+
);
|
|
504
|
+
const effectiveOutOfScope =
|
|
505
|
+
scopeContext.outScope.length > 0
|
|
506
|
+
? scopeContext.outScope
|
|
507
|
+
: featureImplPlanContext.nonGoals;
|
|
508
|
+
const upstreamContractRefs = buildUpstreamContractRefs(
|
|
509
|
+
projectPath,
|
|
510
|
+
featureImplPlanContext.featureImplPlanPath,
|
|
511
|
+
codeHandoffContext
|
|
512
|
+
);
|
|
513
|
+
const linkedContractRefs = buildLinkedContractRefs(codeHandoffContext);
|
|
514
|
+
const provenanceContext = parseProvenanceContext(workflowText);
|
|
515
|
+
const referenceDisclosure = buildReferenceDisclosure(provenanceContext);
|
|
516
|
+
const guidance = buildReviewerGuidance(
|
|
517
|
+
reviewerGuidance,
|
|
518
|
+
truthSyncTargets,
|
|
519
|
+
specNotes,
|
|
520
|
+
qualityNotes,
|
|
521
|
+
debugNotes,
|
|
522
|
+
changedFiles,
|
|
523
|
+
commitBoundary,
|
|
524
|
+
codeHandoffContext
|
|
525
|
+
);
|
|
526
|
+
|
|
527
|
+
const content = [
|
|
528
|
+
`# REVIEW PACKET: ${featureKey}`,
|
|
529
|
+
"",
|
|
530
|
+
"## 1. Review Context",
|
|
531
|
+
`- Feature key: \`${featureKey}\``,
|
|
532
|
+
`- Feature name: ${featureName}`,
|
|
533
|
+
`- Batch summary: ${effectiveBatchSummary}`,
|
|
534
|
+
`- Review date: \`${new Date().toISOString()}\``,
|
|
535
|
+
"- Upstream contract refs:",
|
|
536
|
+
...upstreamContractRefs.map((entry) => ` - \`${entry}\``),
|
|
537
|
+
"",
|
|
538
|
+
"## 2. Approved Scope Snapshot",
|
|
539
|
+
"### Workflow Stage Snapshot",
|
|
540
|
+
`- Current workflow phase when verify started: \`${workflowStageSnapshot.currentPhase}\``,
|
|
541
|
+
`- Phase status when verify started: \`${workflowStageSnapshot.phaseStatus}\``,
|
|
542
|
+
`- Intake outcome: \`${workflowStageSnapshot.intakeOutcome}\``,
|
|
543
|
+
`- Next recommended phase before verify refresh: \`${workflowStageSnapshot.nextPhase}\``,
|
|
544
|
+
`- Blocking state before verify refresh: \`${workflowStageSnapshot.blockingState}\``,
|
|
545
|
+
"",
|
|
546
|
+
"### In Scope",
|
|
547
|
+
renderBulletList(
|
|
548
|
+
scopeContext.inScope,
|
|
549
|
+
"No explicit in-scope items were recorded beyond the current verify pass."
|
|
550
|
+
),
|
|
551
|
+
"",
|
|
552
|
+
"### Out Of Scope",
|
|
553
|
+
renderBulletList(
|
|
554
|
+
effectiveOutOfScope,
|
|
555
|
+
"No explicit out-of-scope items were recorded; defer to the upstream feature implementation plan."
|
|
556
|
+
),
|
|
557
|
+
"",
|
|
558
|
+
"### Linked Backlog / Contract Refs",
|
|
559
|
+
renderBulletList(
|
|
560
|
+
linkedContractRefs,
|
|
561
|
+
"No additional backlog or contract refs were discovered beyond the upstream handoff."
|
|
562
|
+
),
|
|
563
|
+
"",
|
|
564
|
+
"## 3. Changed Files",
|
|
565
|
+
renderTable(
|
|
566
|
+
["No", "Path", "Rationale"],
|
|
567
|
+
buildChangedFileRows(changedFiles),
|
|
568
|
+
"No changed-file entries were recorded during verify."
|
|
569
|
+
),
|
|
570
|
+
"",
|
|
571
|
+
"## 4. Verification Commands Executed",
|
|
572
|
+
renderTable(
|
|
573
|
+
["No", "Command", "Result", "Evidence Ref", "Notes"],
|
|
574
|
+
buildVerificationRows(evidenceEntries),
|
|
575
|
+
"No verification commands were recorded during verify."
|
|
576
|
+
),
|
|
577
|
+
"",
|
|
578
|
+
"## 5. Evidence Index",
|
|
579
|
+
renderTable(
|
|
580
|
+
["No", "Claim", "Evidence Path", "Reviewer Note"],
|
|
581
|
+
buildEvidenceRows(evidenceEntries),
|
|
582
|
+
"No evidence claims were indexed during verify."
|
|
583
|
+
),
|
|
584
|
+
"",
|
|
585
|
+
"## 6. Known Caveats And Unproven Claims",
|
|
586
|
+
renderTable(
|
|
587
|
+
["No", "Caveat ID", "Statement", "Impact", "Follow-Up Owner"],
|
|
588
|
+
buildCaveatRows(caveats, autoCaveats),
|
|
589
|
+
"No explicit caveats or unproven claims were recorded during verify."
|
|
590
|
+
),
|
|
591
|
+
"",
|
|
592
|
+
"## 7. Unrelated Dirt And Exclusions",
|
|
593
|
+
renderTable(
|
|
594
|
+
["No", "Path", "Exclusion Reason"],
|
|
595
|
+
buildExclusionRows(excludedFiles, commitBoundary.excludeList),
|
|
596
|
+
"No unrelated dirt or exclusions were recorded during verify."
|
|
597
|
+
),
|
|
598
|
+
"",
|
|
599
|
+
"## 8. Truth-Sync Targets",
|
|
600
|
+
renderTable(
|
|
601
|
+
["No", "Target Path / Surface", "Status", "Rationale"],
|
|
602
|
+
buildTruthSyncRows(truthSyncTargets),
|
|
603
|
+
"No explicit truth-sync targets were recorded during verify. Downstream review must confirm whether docs, help, runtime, and tests were intentionally untouched."
|
|
604
|
+
),
|
|
605
|
+
"",
|
|
606
|
+
"## 9. Proposed Commit Boundary",
|
|
607
|
+
"### Include List",
|
|
608
|
+
renderBulletList(
|
|
609
|
+
commitBoundary.includeList,
|
|
610
|
+
"No include list was recorded during verify."
|
|
611
|
+
),
|
|
612
|
+
"",
|
|
613
|
+
"### Exclude List",
|
|
614
|
+
renderBulletList(
|
|
615
|
+
commitBoundary.excludeList,
|
|
616
|
+
"No exclude list was recorded during verify."
|
|
617
|
+
),
|
|
618
|
+
"",
|
|
619
|
+
"### Batch Rationale",
|
|
620
|
+
`- ${effectiveBatchSummary}`,
|
|
621
|
+
"",
|
|
622
|
+
"## 10. Reviewer Guidance",
|
|
623
|
+
renderBulletList(
|
|
624
|
+
guidance,
|
|
625
|
+
"No additional reviewer guidance was recorded during verify."
|
|
626
|
+
),
|
|
627
|
+
"",
|
|
628
|
+
"## 11. Reference Disclosure",
|
|
629
|
+
renderBulletList(
|
|
630
|
+
referenceDisclosure.lines,
|
|
631
|
+
"Reference disclosure details were not generated."
|
|
632
|
+
),
|
|
633
|
+
"",
|
|
634
|
+
].join("\n");
|
|
635
|
+
|
|
636
|
+
fs.mkdirSync(path.dirname(reviewPacketPath), { recursive: true });
|
|
637
|
+
fs.writeFileSync(reviewPacketPath, content, "utf-8");
|
|
638
|
+
|
|
639
|
+
return {
|
|
640
|
+
reviewPacketPath,
|
|
641
|
+
hasReferenceDisclosure: content.includes("## 11. Reference Disclosure"),
|
|
642
|
+
provenanceMode: provenanceContext.mode,
|
|
643
|
+
referenceDisclosureMode: referenceDisclosure.mode,
|
|
644
|
+
};
|
|
645
|
+
}
|
|
646
|
+
|
|
647
|
+
module.exports = {
|
|
648
|
+
createReviewPacket,
|
|
649
|
+
getReviewPacketPath,
|
|
650
|
+
};
|