sdtk-code-kit 0.1.3 → 0.2.1
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 +17 -0
- package/assets/manifest/toolkit-bundle.manifest.json +147 -147
- package/assets/manifest/toolkit-bundle.sha256.txt +10 -10
- package/assets/toolkit/toolkit/AGENTS.md +219 -219
- package/assets/toolkit/toolkit/install.ps1 +156 -156
- package/assets/toolkit/toolkit/sdtk-spec.config.json +6 -6
- package/assets/toolkit/toolkit/skills/code-debug/SKILL.md +295 -295
- package/assets/toolkit/toolkit/skills/code-discover/SKILL.md +54 -54
- package/assets/toolkit/toolkit/skills/code-tdd/SKILL.md +377 -377
- package/assets/toolkit/toolkit/skills/code-worktree/SKILL.md +215 -215
- package/assets/toolkit/toolkit/templates/CODE_WORKFLOW_TEMPLATE.md +28 -0
- package/package.json +44 -44
- package/src/commands/doctor.js +52 -0
- package/src/commands/guardrails.js +215 -0
- package/src/commands/help.js +244 -220
- package/src/commands/init.js +98 -98
- package/src/commands/readiness.js +77 -0
- package/src/commands/resume.js +62 -0
- package/src/commands/sleep.js +132 -0
- package/src/commands/status.js +78 -0
- package/src/commands/update.js +11 -11
- package/src/commands/verify.js +5 -0
- package/src/index.js +108 -73
- package/src/lib/project-target-guard.js +53 -53
- package/src/lib/ship-readiness.js +281 -0
- package/src/lib/sleep-plan.js +175 -0
- package/src/lib/sleep-report.js +229 -0
- package/src/lib/trust-events.js +166 -0
- package/src/lib/trust-file-scope.js +154 -0
- package/src/lib/trust-policy.js +212 -0
- package/src/lib/trust-redact.js +35 -0
- package/src/lib/trust-trace.js +179 -0
- package/src/lib/update.js +344 -344
- package/src/lib/workflow-artifact.js +9 -2
- package/src/lib/workflow-doctor.js +84 -0
- package/src/lib/workflow-handoff.js +111 -19
- package/src/lib/workflow-review-packet.js +650 -561
- package/src/lib/workflow-state.js +439 -0
- package/src/lib/workflow-verify.js +393 -356
package/src/index.js
CHANGED
|
@@ -1,73 +1,108 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
const { cmdBuild } = require("./commands/build");
|
|
4
|
-
const {
|
|
5
|
-
const {
|
|
6
|
-
const {
|
|
7
|
-
const {
|
|
8
|
-
const {
|
|
9
|
-
const {
|
|
10
|
-
const {
|
|
11
|
-
const {
|
|
12
|
-
const {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
};
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const { cmdBuild } = require("./commands/build");
|
|
4
|
+
const { cmdDoctor } = require("./commands/doctor");
|
|
5
|
+
const { cmdGuardrails } = require("./commands/guardrails");
|
|
6
|
+
const { cmdHelp } = require("./commands/help");
|
|
7
|
+
const { cmdReadiness } = require("./commands/readiness");
|
|
8
|
+
const { cmdInit } = require("./commands/init");
|
|
9
|
+
const { cmdPlan } = require("./commands/plan");
|
|
10
|
+
const { cmdResume } = require("./commands/resume");
|
|
11
|
+
const { cmdRuntime } = require("./commands/runtime");
|
|
12
|
+
const { cmdShip } = require("./commands/ship");
|
|
13
|
+
const { cmdStart } = require("./commands/start");
|
|
14
|
+
const { cmdStatus } = require("./commands/status");
|
|
15
|
+
const { cmdSleep } = require("./commands/sleep");
|
|
16
|
+
const { cmdUpdate } = require("./commands/update");
|
|
17
|
+
const { cmdVerify } = require("./commands/verify");
|
|
18
|
+
const { ValidationError } = require("./lib/errors");
|
|
19
|
+
|
|
20
|
+
function getVersion() {
|
|
21
|
+
const pkg = require("../package.json");
|
|
22
|
+
return pkg.version;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function parseCommand(argv) {
|
|
26
|
+
if (!argv || argv.length === 0) {
|
|
27
|
+
return { command: "help", args: [] };
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const [first, ...rest] = argv;
|
|
31
|
+
if (first === "-h" || first === "--help") {
|
|
32
|
+
return { command: "help", args: [] };
|
|
33
|
+
}
|
|
34
|
+
if (first === "-v" || first === "--version") {
|
|
35
|
+
return { command: "version", args: [] };
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return { command: first, args: rest };
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const COMMANDS = new Set([
|
|
42
|
+
"help",
|
|
43
|
+
"version",
|
|
44
|
+
"init",
|
|
45
|
+
"runtime",
|
|
46
|
+
"start",
|
|
47
|
+
"plan",
|
|
48
|
+
"build",
|
|
49
|
+
"verify",
|
|
50
|
+
"ship",
|
|
51
|
+
"status",
|
|
52
|
+
"doctor",
|
|
53
|
+
"guardrails",
|
|
54
|
+
"readiness",
|
|
55
|
+
"resume",
|
|
56
|
+
"sleep",
|
|
57
|
+
"update",
|
|
58
|
+
]);
|
|
59
|
+
|
|
60
|
+
async function run(argv) {
|
|
61
|
+
const { command, args } = parseCommand(argv);
|
|
62
|
+
|
|
63
|
+
if (!COMMANDS.has(command)) {
|
|
64
|
+
throw new ValidationError(
|
|
65
|
+
`Unknown command: "${command}". Run "sdtk-code --help" for available commands.`
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
switch (command) {
|
|
70
|
+
case "help":
|
|
71
|
+
return cmdHelp();
|
|
72
|
+
case "version":
|
|
73
|
+
console.log(`sdtk-code-kit ${getVersion()}`);
|
|
74
|
+
return 0;
|
|
75
|
+
case "init":
|
|
76
|
+
return cmdInit(args);
|
|
77
|
+
case "runtime":
|
|
78
|
+
return cmdRuntime(args);
|
|
79
|
+
case "start":
|
|
80
|
+
return cmdStart(args);
|
|
81
|
+
case "plan":
|
|
82
|
+
return cmdPlan(args);
|
|
83
|
+
case "build":
|
|
84
|
+
return cmdBuild(args);
|
|
85
|
+
case "verify":
|
|
86
|
+
return cmdVerify(args);
|
|
87
|
+
case "ship":
|
|
88
|
+
return cmdShip(args);
|
|
89
|
+
case "status":
|
|
90
|
+
return cmdStatus(args);
|
|
91
|
+
case "doctor":
|
|
92
|
+
return cmdDoctor(args);
|
|
93
|
+
case "guardrails":
|
|
94
|
+
return cmdGuardrails(args);
|
|
95
|
+
case "readiness":
|
|
96
|
+
return cmdReadiness(args);
|
|
97
|
+
case "resume":
|
|
98
|
+
return cmdResume(args);
|
|
99
|
+
case "sleep":
|
|
100
|
+
return cmdSleep(args);
|
|
101
|
+
case "update":
|
|
102
|
+
return cmdUpdate(args);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
module.exports = {
|
|
107
|
+
run,
|
|
108
|
+
};
|
|
@@ -1,53 +1,53 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
const fs = require("fs");
|
|
4
|
-
const path = require("path");
|
|
5
|
-
const { ValidationError } = require("./errors");
|
|
6
|
-
|
|
7
|
-
const MAINTAINER_ROOT_MARKERS = [
|
|
8
|
-
"governance/ai/core/IMPROVEMENT_BACKLOG.md",
|
|
9
|
-
"products/sdtk-code/toolkit/install.ps1",
|
|
10
|
-
];
|
|
11
|
-
const PROTECTED_FILES = [
|
|
12
|
-
"AGENTS.md",
|
|
13
|
-
"CODEX.md",
|
|
14
|
-
"CLAUDE.md",
|
|
15
|
-
"sdtk-spec.config.json",
|
|
16
|
-
"sdtk-spec.config.profiles.example.json"
|
|
17
|
-
];
|
|
18
|
-
|
|
19
|
-
function isMaintainerRoot(projectPath) {
|
|
20
|
-
const resolved = path.resolve(projectPath);
|
|
21
|
-
return MAINTAINER_ROOT_MARKERS.every((marker) => fs.existsSync(path.join(resolved, marker)));
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
function buildMaintainerRootMessage(cliName, action, projectPath) {
|
|
25
|
-
const lines = [
|
|
26
|
-
`Refusing to refresh managed project files into the SDTK maintainer repo root: ${projectPath}`,
|
|
27
|
-
`The ${action} flow would overwrite repo-owned files such as ${PROTECTED_FILES.join(", ")}.`,
|
|
28
|
-
"Target a consumer project path instead of the SDTK maintainer monorepo root.",
|
|
29
|
-
];
|
|
30
|
-
|
|
31
|
-
if (action === "update") {
|
|
32
|
-
lines.push(`If you only need package/runtime refresh, rerun ${cliName} update with --skip-project-files.`);
|
|
33
|
-
} else {
|
|
34
|
-
lines.push(`If you only need runtime assets, use ${cliName} runtime install against the desired consumer project path instead of ${cliName} init.`);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
return lines.join("\n");
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
function assertProjectRefreshTargetAllowed(cliName, action, projectPath) {
|
|
41
|
-
if (!isMaintainerRoot(projectPath)) {
|
|
42
|
-
return;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
throw new ValidationError(buildMaintainerRootMessage(cliName, action, projectPath));
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
module.exports = {
|
|
49
|
-
assertProjectRefreshTargetAllowed,
|
|
50
|
-
buildMaintainerRootMessage,
|
|
51
|
-
isMaintainerRoot,
|
|
52
|
-
};
|
|
53
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const fs = require("fs");
|
|
4
|
+
const path = require("path");
|
|
5
|
+
const { ValidationError } = require("./errors");
|
|
6
|
+
|
|
7
|
+
const MAINTAINER_ROOT_MARKERS = [
|
|
8
|
+
"governance/ai/core/IMPROVEMENT_BACKLOG.md",
|
|
9
|
+
"products/sdtk-code/toolkit/install.ps1",
|
|
10
|
+
];
|
|
11
|
+
const PROTECTED_FILES = [
|
|
12
|
+
"AGENTS.md",
|
|
13
|
+
"CODEX.md",
|
|
14
|
+
"CLAUDE.md",
|
|
15
|
+
"sdtk-spec.config.json",
|
|
16
|
+
"sdtk-spec.config.profiles.example.json"
|
|
17
|
+
];
|
|
18
|
+
|
|
19
|
+
function isMaintainerRoot(projectPath) {
|
|
20
|
+
const resolved = path.resolve(projectPath);
|
|
21
|
+
return MAINTAINER_ROOT_MARKERS.every((marker) => fs.existsSync(path.join(resolved, marker)));
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function buildMaintainerRootMessage(cliName, action, projectPath) {
|
|
25
|
+
const lines = [
|
|
26
|
+
`Refusing to refresh managed project files into the SDTK maintainer repo root: ${projectPath}`,
|
|
27
|
+
`The ${action} flow would overwrite repo-owned files such as ${PROTECTED_FILES.join(", ")}.`,
|
|
28
|
+
"Target a consumer project path instead of the SDTK maintainer monorepo root.",
|
|
29
|
+
];
|
|
30
|
+
|
|
31
|
+
if (action === "update") {
|
|
32
|
+
lines.push(`If you only need package/runtime refresh, rerun ${cliName} update with --skip-project-files.`);
|
|
33
|
+
} else {
|
|
34
|
+
lines.push(`If you only need runtime assets, use ${cliName} runtime install against the desired consumer project path instead of ${cliName} init.`);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return lines.join("\n");
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function assertProjectRefreshTargetAllowed(cliName, action, projectPath) {
|
|
41
|
+
if (!isMaintainerRoot(projectPath)) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
throw new ValidationError(buildMaintainerRootMessage(cliName, action, projectPath));
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
module.exports = {
|
|
49
|
+
assertProjectRefreshTargetAllowed,
|
|
50
|
+
buildMaintainerRootMessage,
|
|
51
|
+
isMaintainerRoot,
|
|
52
|
+
};
|
|
53
|
+
|
|
@@ -0,0 +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 };
|