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,281 +1,281 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
const fs = require("fs");
|
|
4
|
-
const path = require("path");
|
|
5
|
-
|
|
6
|
-
// ---------------------------------------------------------------------------
|
|
7
|
-
// Pure scorer — no fs, no git. All signals supplied by the caller.
|
|
8
|
-
// ---------------------------------------------------------------------------
|
|
9
|
-
|
|
10
|
-
const GATE_POINTS = {
|
|
11
|
-
pass: 1.0,
|
|
12
|
-
partial: 0.5,
|
|
13
|
-
fail: 0,
|
|
14
|
-
absent: 0,
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
function gateScore(gate) {
|
|
18
|
-
const factor = GATE_POINTS[typeof gate === "string" ? gate : "absent"];
|
|
19
|
-
return factor !== undefined ? factor : 0;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
function codeVerifyPoints(verifyGates) {
|
|
23
|
-
const gates = verifyGates && typeof verifyGates === "object" ? verifyGates : {};
|
|
24
|
-
const spec = gateScore(gates.spec) * 10;
|
|
25
|
-
const quality = gateScore(gates.quality) * 10;
|
|
26
|
-
const evidence = gateScore(gates.evidence) * 10;
|
|
27
|
-
return { spec, quality, evidence, total: spec + quality + evidence };
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
function codeVerifyNote(verifyGates) {
|
|
31
|
-
const gates = verifyGates && typeof verifyGates === "object" ? verifyGates : {};
|
|
32
|
-
const parts = [];
|
|
33
|
-
for (const key of ["spec", "quality", "evidence"]) {
|
|
34
|
-
const g = typeof gates[key] === "string" ? gates[key] : "absent";
|
|
35
|
-
if (g !== "pass") {
|
|
36
|
-
parts.push(`${key}:${g}`);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
return parts.length > 0 ? `non-pass gates: ${parts.join(", ")}` : "all gates pass";
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
function fileScopePoints(verdict) {
|
|
43
|
-
if (verdict === "pass") return 10;
|
|
44
|
-
if (verdict === "needs_human") return 5;
|
|
45
|
-
return 0;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
// Deterministic, component-based readiness scorer.
|
|
49
|
-
// signals === null triggers ENV_BLOCKED immediately.
|
|
50
|
-
// Components that are N/A (DESIGN when uiScope=false) are excluded from max.
|
|
51
|
-
function computeReadiness(signals) {
|
|
52
|
-
if (signals === null || signals === undefined) {
|
|
53
|
-
return {
|
|
54
|
-
score: 0,
|
|
55
|
-
max: 0,
|
|
56
|
-
components: [],
|
|
57
|
-
verdict: "ENV_BLOCKED",
|
|
58
|
-
blockers: ["Signals could not be gathered — check project path and workflow artifacts."],
|
|
59
|
-
warnings: [],
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
const components = [];
|
|
64
|
-
let score = 0;
|
|
65
|
-
let max = 0;
|
|
66
|
-
const blockers = [];
|
|
67
|
-
const warnings = [];
|
|
68
|
-
|
|
69
|
-
function addComponent(name, points, compMax, note) {
|
|
70
|
-
components.push({ name, points, max: compMax, note: note || "" });
|
|
71
|
-
score += points;
|
|
72
|
-
max += compMax;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
// 1. SPEC (15 pts) — hasCodeHandoff
|
|
76
|
-
const hasCode = Boolean(signals.hasCodeHandoff);
|
|
77
|
-
addComponent("SPEC", hasCode ? 15 : 0, 15, hasCode ? "CODE handoff present" : "CODE handoff not found");
|
|
78
|
-
if (!hasCode) {
|
|
79
|
-
warnings.push("CODE handoff not found — SPEC component scored 0.");
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
// 2. DESIGN (15 pts) — only when uiScope === true
|
|
83
|
-
if (signals.uiScope === true) {
|
|
84
|
-
const hasDesign = Boolean(signals.hasDesignHandoff);
|
|
85
|
-
addComponent("DESIGN", hasDesign ? 15 : 0, 15, hasDesign ? "DESIGN handoff present" : "DESIGN handoff not found");
|
|
86
|
-
if (!hasDesign) {
|
|
87
|
-
warnings.push("DESIGN handoff not found — DESIGN component scored 0.");
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
// 3. CODE_VERIFY (30 pts) — verifyGates spec(10) + quality(10) + evidence(10)
|
|
92
|
-
const vg = signals.verifyGates && typeof signals.verifyGates === "object" ? signals.verifyGates : {};
|
|
93
|
-
const cvPts = codeVerifyPoints(signals.verifyGates);
|
|
94
|
-
addComponent("CODE_VERIFY", cvPts.total, 30, codeVerifyNote(signals.verifyGates));
|
|
95
|
-
const evidenceGate = typeof vg.evidence === "string" ? vg.evidence : "absent";
|
|
96
|
-
if (evidenceGate === "fail" || evidenceGate === "absent") {
|
|
97
|
-
blockers.push(`CODE verification evidence missing or failed (evidence gate: ${evidenceGate}).`);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
// 4. GUARDRAIL (15 pts) — denyCount===0 → full; any deny → 0 + blocker
|
|
101
|
-
const guardrail = signals.guardrail && typeof signals.guardrail === "object" ? signals.guardrail : {};
|
|
102
|
-
const denyCount = typeof guardrail.denyCount === "number" ? guardrail.denyCount : 0;
|
|
103
|
-
const guardrailPts = denyCount === 0 ? 15 : 0;
|
|
104
|
-
addComponent(
|
|
105
|
-
"GUARDRAIL",
|
|
106
|
-
guardrailPts,
|
|
107
|
-
15,
|
|
108
|
-
denyCount === 0 ? "no unresolved deny events" : `${denyCount} unresolved deny event(s)`
|
|
109
|
-
);
|
|
110
|
-
if (denyCount > 0) {
|
|
111
|
-
blockers.push(`Unresolved guardrail deny events: ${denyCount}.`);
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
// 5. FILE_SCOPE (10 pts) — pass→10, needs_human→5+warning, fail→0+blocker, absent→0
|
|
115
|
-
const fsObj = signals.fileScope && typeof signals.fileScope === "object" ? signals.fileScope : {};
|
|
116
|
-
const fsVerdict = typeof fsObj.verdict === "string" ? fsObj.verdict : "absent";
|
|
117
|
-
const fsPts = fileScopePoints(fsVerdict);
|
|
118
|
-
addComponent(
|
|
119
|
-
"FILE_SCOPE",
|
|
120
|
-
fsPts,
|
|
121
|
-
10,
|
|
122
|
-
`file-scope verdict: ${fsVerdict}`
|
|
123
|
-
);
|
|
124
|
-
if (fsVerdict === "needs_human") {
|
|
125
|
-
warnings.push("File-scope gate needs human review — partial credit only.");
|
|
126
|
-
} else if (fsVerdict === "fail") {
|
|
127
|
-
blockers.push("File-scope check failed — out-of-scope file edits detected.");
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
// 6. OPS (15 pts) — hasOpsHandoff
|
|
131
|
-
const hasOps = Boolean(signals.hasOpsHandoff);
|
|
132
|
-
addComponent("OPS", hasOps ? 15 : 0, 15, hasOps ? "OPS handoff present" : "OPS handoff evidence absent");
|
|
133
|
-
if (!hasOps) {
|
|
134
|
-
warnings.push("OPS handoff evidence absent — OPS component scored 0.");
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
// Verdict mapping (most-restrictive-wins, deterministic)
|
|
138
|
-
let verdict;
|
|
139
|
-
if (blockers.length > 0) {
|
|
140
|
-
verdict = "FAIL";
|
|
141
|
-
} else if (warnings.length > 0) {
|
|
142
|
-
verdict = "PASS_WITH_NOTES";
|
|
143
|
-
} else {
|
|
144
|
-
verdict = "PASS";
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
return { score, max, components, verdict, blockers, warnings };
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
// ---------------------------------------------------------------------------
|
|
151
|
-
// Thin signal gatherer — reads fs artifacts; wraps exceptions → null.
|
|
152
|
-
// Not the test target; computeReadiness is the tested unit.
|
|
153
|
-
// ---------------------------------------------------------------------------
|
|
154
|
-
|
|
155
|
-
function parseGateField(verifyBlock, label) {
|
|
156
|
-
const escaped = label.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
157
|
-
const match = verifyBlock.match(new RegExp(`- ${escaped}: \`([^\\r\\n\`]+)\``));
|
|
158
|
-
return match ? match[1] : null;
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
function extractVerifyBlock(text) {
|
|
162
|
-
const match = text.match(/<!-- SDTK-CODE:VERIFY:START -->([\s\S]*?)<!-- SDTK-CODE:VERIFY:END -->/);
|
|
163
|
-
return match ? match[1] : null;
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
function readAllEvents(eventsDir) {
|
|
167
|
-
const events = [];
|
|
168
|
-
let files;
|
|
169
|
-
try {
|
|
170
|
-
files = fs.readdirSync(eventsDir).filter((f) => f.endsWith(".jsonl"));
|
|
171
|
-
} catch (_e) {
|
|
172
|
-
return events;
|
|
173
|
-
}
|
|
174
|
-
for (const file of files) {
|
|
175
|
-
const filePath = path.join(eventsDir, file);
|
|
176
|
-
try {
|
|
177
|
-
const lines = fs.readFileSync(filePath, "utf8").split(/\r?\n/);
|
|
178
|
-
for (const line of lines) {
|
|
179
|
-
if (!line.trim()) continue;
|
|
180
|
-
try {
|
|
181
|
-
events.push(JSON.parse(line));
|
|
182
|
-
} catch (_e) {
|
|
183
|
-
// skip malformed line
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
} catch (_e) {
|
|
187
|
-
// skip unreadable file
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
return events;
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
function gatherSignals(projectPath, featureKey) {
|
|
194
|
-
try {
|
|
195
|
-
const resolved = path.resolve(projectPath || ".");
|
|
196
|
-
const signals = {};
|
|
197
|
-
|
|
198
|
-
// SPEC handoff
|
|
199
|
-
const codeHandoffPath = path.join(resolved, "docs", "dev", `CODE_HANDOFF_${featureKey}.json`);
|
|
200
|
-
signals.hasCodeHandoff = fs.existsSync(codeHandoffPath);
|
|
201
|
-
|
|
202
|
-
// OPS handoff
|
|
203
|
-
const opsHandoffPath = path.join(resolved, "docs", "dev", `OPS_HANDOFF_${featureKey}.json`);
|
|
204
|
-
signals.hasOpsHandoff = fs.existsSync(opsHandoffPath);
|
|
205
|
-
|
|
206
|
-
// UI scope detection: check CODE_HANDOFF required_refs for docs/design/ entries
|
|
207
|
-
signals.uiScope = false;
|
|
208
|
-
signals.hasDesignHandoff = false;
|
|
209
|
-
if (signals.hasCodeHandoff) {
|
|
210
|
-
try {
|
|
211
|
-
const codeHandoff = JSON.parse(fs.readFileSync(codeHandoffPath, "utf8"));
|
|
212
|
-
if (Array.isArray(codeHandoff.required_refs)) {
|
|
213
|
-
signals.uiScope = codeHandoff.required_refs.some(
|
|
214
|
-
(r) => typeof r === "string" && r.startsWith("docs/design/")
|
|
215
|
-
);
|
|
216
|
-
}
|
|
217
|
-
} catch (_e) {
|
|
218
|
-
// ignore malformed CODE_HANDOFF for signal gathering
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
if (signals.uiScope) {
|
|
222
|
-
const designHandoffPath = path.join(resolved, "docs", "dev", `DESIGN_HANDOFF_${featureKey}.md`);
|
|
223
|
-
signals.hasDesignHandoff = fs.existsSync(designHandoffPath);
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
// verifyGates from CODE_WORKFLOW artifact VERIFY block
|
|
227
|
-
signals.verifyGates = { spec: "absent", quality: "absent", evidence: "absent" };
|
|
228
|
-
const workflowPath = path.join(resolved, "docs", "dev", `CODE_WORKFLOW_${featureKey}.md`);
|
|
229
|
-
if (fs.existsSync(workflowPath)) {
|
|
230
|
-
try {
|
|
231
|
-
const text = fs.readFileSync(workflowPath, "utf8");
|
|
232
|
-
const verifyBlock = extractVerifyBlock(text);
|
|
233
|
-
if (verifyBlock) {
|
|
234
|
-
const specGate = parseGateField(verifyBlock, "Spec/compliance gate");
|
|
235
|
-
const qualityGate = parseGateField(verifyBlock, "Quality gate");
|
|
236
|
-
const evidenceGate = parseGateField(verifyBlock, "Evidence gate");
|
|
237
|
-
if (specGate) signals.verifyGates.spec = specGate;
|
|
238
|
-
if (qualityGate) signals.verifyGates.quality = qualityGate;
|
|
239
|
-
if (evidenceGate) signals.verifyGates.evidence = evidenceGate;
|
|
240
|
-
}
|
|
241
|
-
} catch (_e) {
|
|
242
|
-
// leave verifyGates as absent
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
// Trust events: guardrail_check and file_scope_check
|
|
247
|
-
signals.guardrail = { denyCount: 0, askCount: 0 };
|
|
248
|
-
signals.fileScope = { verdict: "absent" };
|
|
249
|
-
const eventsDir = path.join(resolved, ".sdtk", "trust", "events");
|
|
250
|
-
if (fs.existsSync(eventsDir)) {
|
|
251
|
-
const events = readAllEvents(eventsDir);
|
|
252
|
-
let denyCount = 0;
|
|
253
|
-
let infoCount = 0;
|
|
254
|
-
const fileScopeEvents = [];
|
|
255
|
-
for (const event of events) {
|
|
256
|
-
if (event.event_type === "guardrail_check") {
|
|
257
|
-
if (event.status === "blocked") denyCount++;
|
|
258
|
-
else infoCount++;
|
|
259
|
-
}
|
|
260
|
-
if (event.event_type === "file_scope_check") {
|
|
261
|
-
fileScopeEvents.push(event);
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
signals.guardrail = { denyCount, askCount: infoCount };
|
|
265
|
-
if (fileScopeEvents.length > 0) {
|
|
266
|
-
const last = fileScopeEvents[fileScopeEvents.length - 1];
|
|
267
|
-
let verdict = "pass";
|
|
268
|
-
if (last.status === "blocked") verdict = "fail";
|
|
269
|
-
else if (last.status === "needs_human") verdict = "needs_human";
|
|
270
|
-
signals.fileScope = { verdict };
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
return signals;
|
|
275
|
-
} catch (_error) {
|
|
276
|
-
// Any top-level read failure → null signals → ENV_BLOCKED in computeReadiness
|
|
277
|
-
return null;
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
module.exports = { computeReadiness, gatherSignals };
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const fs = require("fs");
|
|
4
|
+
const path = require("path");
|
|
5
|
+
|
|
6
|
+
// ---------------------------------------------------------------------------
|
|
7
|
+
// Pure scorer — no fs, no git. All signals supplied by the caller.
|
|
8
|
+
// ---------------------------------------------------------------------------
|
|
9
|
+
|
|
10
|
+
const GATE_POINTS = {
|
|
11
|
+
pass: 1.0,
|
|
12
|
+
partial: 0.5,
|
|
13
|
+
fail: 0,
|
|
14
|
+
absent: 0,
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
function gateScore(gate) {
|
|
18
|
+
const factor = GATE_POINTS[typeof gate === "string" ? gate : "absent"];
|
|
19
|
+
return factor !== undefined ? factor : 0;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function codeVerifyPoints(verifyGates) {
|
|
23
|
+
const gates = verifyGates && typeof verifyGates === "object" ? verifyGates : {};
|
|
24
|
+
const spec = gateScore(gates.spec) * 10;
|
|
25
|
+
const quality = gateScore(gates.quality) * 10;
|
|
26
|
+
const evidence = gateScore(gates.evidence) * 10;
|
|
27
|
+
return { spec, quality, evidence, total: spec + quality + evidence };
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function codeVerifyNote(verifyGates) {
|
|
31
|
+
const gates = verifyGates && typeof verifyGates === "object" ? verifyGates : {};
|
|
32
|
+
const parts = [];
|
|
33
|
+
for (const key of ["spec", "quality", "evidence"]) {
|
|
34
|
+
const g = typeof gates[key] === "string" ? gates[key] : "absent";
|
|
35
|
+
if (g !== "pass") {
|
|
36
|
+
parts.push(`${key}:${g}`);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return parts.length > 0 ? `non-pass gates: ${parts.join(", ")}` : "all gates pass";
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function fileScopePoints(verdict) {
|
|
43
|
+
if (verdict === "pass") return 10;
|
|
44
|
+
if (verdict === "needs_human") return 5;
|
|
45
|
+
return 0;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// Deterministic, component-based readiness scorer.
|
|
49
|
+
// signals === null triggers ENV_BLOCKED immediately.
|
|
50
|
+
// Components that are N/A (DESIGN when uiScope=false) are excluded from max.
|
|
51
|
+
function computeReadiness(signals) {
|
|
52
|
+
if (signals === null || signals === undefined) {
|
|
53
|
+
return {
|
|
54
|
+
score: 0,
|
|
55
|
+
max: 0,
|
|
56
|
+
components: [],
|
|
57
|
+
verdict: "ENV_BLOCKED",
|
|
58
|
+
blockers: ["Signals could not be gathered — check project path and workflow artifacts."],
|
|
59
|
+
warnings: [],
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const components = [];
|
|
64
|
+
let score = 0;
|
|
65
|
+
let max = 0;
|
|
66
|
+
const blockers = [];
|
|
67
|
+
const warnings = [];
|
|
68
|
+
|
|
69
|
+
function addComponent(name, points, compMax, note) {
|
|
70
|
+
components.push({ name, points, max: compMax, note: note || "" });
|
|
71
|
+
score += points;
|
|
72
|
+
max += compMax;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// 1. SPEC (15 pts) — hasCodeHandoff
|
|
76
|
+
const hasCode = Boolean(signals.hasCodeHandoff);
|
|
77
|
+
addComponent("SPEC", hasCode ? 15 : 0, 15, hasCode ? "CODE handoff present" : "CODE handoff not found");
|
|
78
|
+
if (!hasCode) {
|
|
79
|
+
warnings.push("CODE handoff not found — SPEC component scored 0.");
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// 2. DESIGN (15 pts) — only when uiScope === true
|
|
83
|
+
if (signals.uiScope === true) {
|
|
84
|
+
const hasDesign = Boolean(signals.hasDesignHandoff);
|
|
85
|
+
addComponent("DESIGN", hasDesign ? 15 : 0, 15, hasDesign ? "DESIGN handoff present" : "DESIGN handoff not found");
|
|
86
|
+
if (!hasDesign) {
|
|
87
|
+
warnings.push("DESIGN handoff not found — DESIGN component scored 0.");
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// 3. CODE_VERIFY (30 pts) — verifyGates spec(10) + quality(10) + evidence(10)
|
|
92
|
+
const vg = signals.verifyGates && typeof signals.verifyGates === "object" ? signals.verifyGates : {};
|
|
93
|
+
const cvPts = codeVerifyPoints(signals.verifyGates);
|
|
94
|
+
addComponent("CODE_VERIFY", cvPts.total, 30, codeVerifyNote(signals.verifyGates));
|
|
95
|
+
const evidenceGate = typeof vg.evidence === "string" ? vg.evidence : "absent";
|
|
96
|
+
if (evidenceGate === "fail" || evidenceGate === "absent") {
|
|
97
|
+
blockers.push(`CODE verification evidence missing or failed (evidence gate: ${evidenceGate}).`);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// 4. GUARDRAIL (15 pts) — denyCount===0 → full; any deny → 0 + blocker
|
|
101
|
+
const guardrail = signals.guardrail && typeof signals.guardrail === "object" ? signals.guardrail : {};
|
|
102
|
+
const denyCount = typeof guardrail.denyCount === "number" ? guardrail.denyCount : 0;
|
|
103
|
+
const guardrailPts = denyCount === 0 ? 15 : 0;
|
|
104
|
+
addComponent(
|
|
105
|
+
"GUARDRAIL",
|
|
106
|
+
guardrailPts,
|
|
107
|
+
15,
|
|
108
|
+
denyCount === 0 ? "no unresolved deny events" : `${denyCount} unresolved deny event(s)`
|
|
109
|
+
);
|
|
110
|
+
if (denyCount > 0) {
|
|
111
|
+
blockers.push(`Unresolved guardrail deny events: ${denyCount}.`);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// 5. FILE_SCOPE (10 pts) — pass→10, needs_human→5+warning, fail→0+blocker, absent→0
|
|
115
|
+
const fsObj = signals.fileScope && typeof signals.fileScope === "object" ? signals.fileScope : {};
|
|
116
|
+
const fsVerdict = typeof fsObj.verdict === "string" ? fsObj.verdict : "absent";
|
|
117
|
+
const fsPts = fileScopePoints(fsVerdict);
|
|
118
|
+
addComponent(
|
|
119
|
+
"FILE_SCOPE",
|
|
120
|
+
fsPts,
|
|
121
|
+
10,
|
|
122
|
+
`file-scope verdict: ${fsVerdict}`
|
|
123
|
+
);
|
|
124
|
+
if (fsVerdict === "needs_human") {
|
|
125
|
+
warnings.push("File-scope gate needs human review — partial credit only.");
|
|
126
|
+
} else if (fsVerdict === "fail") {
|
|
127
|
+
blockers.push("File-scope check failed — out-of-scope file edits detected.");
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// 6. OPS (15 pts) — hasOpsHandoff
|
|
131
|
+
const hasOps = Boolean(signals.hasOpsHandoff);
|
|
132
|
+
addComponent("OPS", hasOps ? 15 : 0, 15, hasOps ? "OPS handoff present" : "OPS handoff evidence absent");
|
|
133
|
+
if (!hasOps) {
|
|
134
|
+
warnings.push("OPS handoff evidence absent — OPS component scored 0.");
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// Verdict mapping (most-restrictive-wins, deterministic)
|
|
138
|
+
let verdict;
|
|
139
|
+
if (blockers.length > 0) {
|
|
140
|
+
verdict = "FAIL";
|
|
141
|
+
} else if (warnings.length > 0) {
|
|
142
|
+
verdict = "PASS_WITH_NOTES";
|
|
143
|
+
} else {
|
|
144
|
+
verdict = "PASS";
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
return { score, max, components, verdict, blockers, warnings };
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// ---------------------------------------------------------------------------
|
|
151
|
+
// Thin signal gatherer — reads fs artifacts; wraps exceptions → null.
|
|
152
|
+
// Not the test target; computeReadiness is the tested unit.
|
|
153
|
+
// ---------------------------------------------------------------------------
|
|
154
|
+
|
|
155
|
+
function parseGateField(verifyBlock, label) {
|
|
156
|
+
const escaped = label.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
157
|
+
const match = verifyBlock.match(new RegExp(`- ${escaped}: \`([^\\r\\n\`]+)\``));
|
|
158
|
+
return match ? match[1] : null;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
function extractVerifyBlock(text) {
|
|
162
|
+
const match = text.match(/<!-- SDTK-CODE:VERIFY:START -->([\s\S]*?)<!-- SDTK-CODE:VERIFY:END -->/);
|
|
163
|
+
return match ? match[1] : null;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
function readAllEvents(eventsDir) {
|
|
167
|
+
const events = [];
|
|
168
|
+
let files;
|
|
169
|
+
try {
|
|
170
|
+
files = fs.readdirSync(eventsDir).filter((f) => f.endsWith(".jsonl"));
|
|
171
|
+
} catch (_e) {
|
|
172
|
+
return events;
|
|
173
|
+
}
|
|
174
|
+
for (const file of files) {
|
|
175
|
+
const filePath = path.join(eventsDir, file);
|
|
176
|
+
try {
|
|
177
|
+
const lines = fs.readFileSync(filePath, "utf8").split(/\r?\n/);
|
|
178
|
+
for (const line of lines) {
|
|
179
|
+
if (!line.trim()) continue;
|
|
180
|
+
try {
|
|
181
|
+
events.push(JSON.parse(line));
|
|
182
|
+
} catch (_e) {
|
|
183
|
+
// skip malformed line
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
} catch (_e) {
|
|
187
|
+
// skip unreadable file
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
return events;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
function gatherSignals(projectPath, featureKey) {
|
|
194
|
+
try {
|
|
195
|
+
const resolved = path.resolve(projectPath || ".");
|
|
196
|
+
const signals = {};
|
|
197
|
+
|
|
198
|
+
// SPEC handoff
|
|
199
|
+
const codeHandoffPath = path.join(resolved, "docs", "dev", `CODE_HANDOFF_${featureKey}.json`);
|
|
200
|
+
signals.hasCodeHandoff = fs.existsSync(codeHandoffPath);
|
|
201
|
+
|
|
202
|
+
// OPS handoff
|
|
203
|
+
const opsHandoffPath = path.join(resolved, "docs", "dev", `OPS_HANDOFF_${featureKey}.json`);
|
|
204
|
+
signals.hasOpsHandoff = fs.existsSync(opsHandoffPath);
|
|
205
|
+
|
|
206
|
+
// UI scope detection: check CODE_HANDOFF required_refs for docs/design/ entries
|
|
207
|
+
signals.uiScope = false;
|
|
208
|
+
signals.hasDesignHandoff = false;
|
|
209
|
+
if (signals.hasCodeHandoff) {
|
|
210
|
+
try {
|
|
211
|
+
const codeHandoff = JSON.parse(fs.readFileSync(codeHandoffPath, "utf8"));
|
|
212
|
+
if (Array.isArray(codeHandoff.required_refs)) {
|
|
213
|
+
signals.uiScope = codeHandoff.required_refs.some(
|
|
214
|
+
(r) => typeof r === "string" && r.startsWith("docs/design/")
|
|
215
|
+
);
|
|
216
|
+
}
|
|
217
|
+
} catch (_e) {
|
|
218
|
+
// ignore malformed CODE_HANDOFF for signal gathering
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
if (signals.uiScope) {
|
|
222
|
+
const designHandoffPath = path.join(resolved, "docs", "dev", `DESIGN_HANDOFF_${featureKey}.md`);
|
|
223
|
+
signals.hasDesignHandoff = fs.existsSync(designHandoffPath);
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
// verifyGates from CODE_WORKFLOW artifact VERIFY block
|
|
227
|
+
signals.verifyGates = { spec: "absent", quality: "absent", evidence: "absent" };
|
|
228
|
+
const workflowPath = path.join(resolved, "docs", "dev", `CODE_WORKFLOW_${featureKey}.md`);
|
|
229
|
+
if (fs.existsSync(workflowPath)) {
|
|
230
|
+
try {
|
|
231
|
+
const text = fs.readFileSync(workflowPath, "utf8");
|
|
232
|
+
const verifyBlock = extractVerifyBlock(text);
|
|
233
|
+
if (verifyBlock) {
|
|
234
|
+
const specGate = parseGateField(verifyBlock, "Spec/compliance gate");
|
|
235
|
+
const qualityGate = parseGateField(verifyBlock, "Quality gate");
|
|
236
|
+
const evidenceGate = parseGateField(verifyBlock, "Evidence gate");
|
|
237
|
+
if (specGate) signals.verifyGates.spec = specGate;
|
|
238
|
+
if (qualityGate) signals.verifyGates.quality = qualityGate;
|
|
239
|
+
if (evidenceGate) signals.verifyGates.evidence = evidenceGate;
|
|
240
|
+
}
|
|
241
|
+
} catch (_e) {
|
|
242
|
+
// leave verifyGates as absent
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
// Trust events: guardrail_check and file_scope_check
|
|
247
|
+
signals.guardrail = { denyCount: 0, askCount: 0 };
|
|
248
|
+
signals.fileScope = { verdict: "absent" };
|
|
249
|
+
const eventsDir = path.join(resolved, ".sdtk", "trust", "events");
|
|
250
|
+
if (fs.existsSync(eventsDir)) {
|
|
251
|
+
const events = readAllEvents(eventsDir);
|
|
252
|
+
let denyCount = 0;
|
|
253
|
+
let infoCount = 0;
|
|
254
|
+
const fileScopeEvents = [];
|
|
255
|
+
for (const event of events) {
|
|
256
|
+
if (event.event_type === "guardrail_check") {
|
|
257
|
+
if (event.status === "blocked") denyCount++;
|
|
258
|
+
else infoCount++;
|
|
259
|
+
}
|
|
260
|
+
if (event.event_type === "file_scope_check") {
|
|
261
|
+
fileScopeEvents.push(event);
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
signals.guardrail = { denyCount, askCount: infoCount };
|
|
265
|
+
if (fileScopeEvents.length > 0) {
|
|
266
|
+
const last = fileScopeEvents[fileScopeEvents.length - 1];
|
|
267
|
+
let verdict = "pass";
|
|
268
|
+
if (last.status === "blocked") verdict = "fail";
|
|
269
|
+
else if (last.status === "needs_human") verdict = "needs_human";
|
|
270
|
+
signals.fileScope = { verdict };
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
return signals;
|
|
275
|
+
} catch (_error) {
|
|
276
|
+
// Any top-level read failure → null signals → ENV_BLOCKED in computeReadiness
|
|
277
|
+
return null;
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
module.exports = { computeReadiness, gatherSignals };
|