sdtk-code-kit 0.1.3 → 0.2.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.
Files changed (64) hide show
  1. package/README.md +202 -185
  2. package/assets/manifest/toolkit-bundle.manifest.json +49 -49
  3. package/assets/manifest/toolkit-bundle.sha256.txt +24 -24
  4. package/assets/toolkit/toolkit/scripts/install-claude-skills.ps1 +78 -78
  5. package/assets/toolkit/toolkit/scripts/install-codex-skills.ps1 +150 -150
  6. package/assets/toolkit/toolkit/scripts/uninstall-claude-skills.ps1 +62 -62
  7. package/assets/toolkit/toolkit/scripts/uninstall-codex-skills.ps1 +82 -82
  8. package/assets/toolkit/toolkit/sdtk-spec.config.profiles.example.json +12 -12
  9. package/assets/toolkit/toolkit/skills/code-brainstorm/SKILL.md +55 -55
  10. package/assets/toolkit/toolkit/skills/code-debug/SKILL.md +1 -1
  11. package/assets/toolkit/toolkit/skills/code-debug/references/root-cause-tracing.md +68 -68
  12. package/assets/toolkit/toolkit/skills/code-execute/SKILL.md +74 -74
  13. package/assets/toolkit/toolkit/skills/code-finish/SKILL.md +205 -205
  14. package/assets/toolkit/toolkit/skills/code-parallel/SKILL.md +64 -64
  15. package/assets/toolkit/toolkit/skills/code-parallel/references/code-quality-reviewer-prompt.md +26 -26
  16. package/assets/toolkit/toolkit/skills/code-parallel/references/implementer-prompt.md +113 -113
  17. package/assets/toolkit/toolkit/skills/code-parallel/references/spec-reviewer-prompt.md +61 -61
  18. package/assets/toolkit/toolkit/skills/code-plan/SKILL.md +85 -85
  19. package/assets/toolkit/toolkit/skills/code-review/SKILL.md +79 -79
  20. package/assets/toolkit/toolkit/skills/code-review/references/checklist.md +125 -125
  21. package/assets/toolkit/toolkit/skills/code-review/references/code-reviewer.md +146 -146
  22. package/assets/toolkit/toolkit/skills/code-ship/SKILL.md +52 -52
  23. package/assets/toolkit/toolkit/skills/code-tdd/SKILL.md +1 -1
  24. package/assets/toolkit/toolkit/skills/code-tdd/references/testing-anti-patterns.md +299 -299
  25. package/assets/toolkit/toolkit/skills/code-verify/SKILL.md +144 -144
  26. package/assets/toolkit/toolkit/skills/code-worktree/SKILL.md +13 -13
  27. package/assets/toolkit/toolkit/templates/CODE_WORKFLOW_TEMPLATE.md +140 -112
  28. package/bin/sdtk-code.js +14 -14
  29. package/package.json +4 -4
  30. package/src/commands/build.js +53 -53
  31. package/src/commands/doctor.js +52 -0
  32. package/src/commands/generate.js +11 -11
  33. package/src/commands/guardrails.js +123 -0
  34. package/src/commands/help.js +28 -4
  35. package/src/commands/plan.js +53 -53
  36. package/src/commands/readiness.js +77 -0
  37. package/src/commands/resume.js +62 -0
  38. package/src/commands/runtime.js +224 -224
  39. package/src/commands/ship.js +59 -59
  40. package/src/commands/start.js +89 -89
  41. package/src/commands/status.js +78 -0
  42. package/src/commands/verify.js +71 -66
  43. package/src/index.js +32 -1
  44. package/src/lib/args.js +107 -107
  45. package/src/lib/errors.js +41 -41
  46. package/src/lib/powershell.js +65 -65
  47. package/src/lib/scope.js +72 -72
  48. package/src/lib/ship-readiness.js +281 -0
  49. package/src/lib/toolkit-payload.js +72 -72
  50. package/src/lib/trust-events.js +166 -0
  51. package/src/lib/trust-file-scope.js +154 -0
  52. package/src/lib/trust-policy.js +212 -0
  53. package/src/lib/trust-redact.js +35 -0
  54. package/src/lib/trust-trace.js +179 -0
  55. package/src/lib/workflow-artifact.js +503 -496
  56. package/src/lib/workflow-build.js +127 -127
  57. package/src/lib/workflow-doctor.js +84 -0
  58. package/src/lib/workflow-handoff.js +1029 -937
  59. package/src/lib/workflow-intake.js +101 -101
  60. package/src/lib/workflow-plan.js +193 -193
  61. package/src/lib/workflow-review-packet.js +89 -0
  62. package/src/lib/workflow-ship.js +213 -213
  63. package/src/lib/workflow-state.js +439 -0
  64. package/src/lib/workflow-verify.js +43 -6
package/src/lib/errors.js CHANGED
@@ -1,41 +1,41 @@
1
- "use strict";
2
-
3
- class CliError extends Error {
4
- constructor(message, exitCode = 4) {
5
- super(message);
6
- this.name = this.constructor.name;
7
- this.exitCode = exitCode;
8
- }
9
- }
10
-
11
- class ValidationError extends CliError {
12
- constructor(message) {
13
- super(message, 1);
14
- }
15
- }
16
-
17
- class DependencyError extends CliError {
18
- constructor(message) {
19
- super(message, 2);
20
- }
21
- }
22
-
23
- class IntegrityError extends CliError {
24
- constructor(message) {
25
- super(message, 3);
26
- }
27
- }
28
-
29
- class InternalError extends CliError {
30
- constructor(message) {
31
- super(message, 4);
32
- }
33
- }
34
-
35
- module.exports = {
36
- CliError,
37
- ValidationError,
38
- DependencyError,
39
- IntegrityError,
40
- InternalError,
41
- };
1
+ "use strict";
2
+
3
+ class CliError extends Error {
4
+ constructor(message, exitCode = 4) {
5
+ super(message);
6
+ this.name = this.constructor.name;
7
+ this.exitCode = exitCode;
8
+ }
9
+ }
10
+
11
+ class ValidationError extends CliError {
12
+ constructor(message) {
13
+ super(message, 1);
14
+ }
15
+ }
16
+
17
+ class DependencyError extends CliError {
18
+ constructor(message) {
19
+ super(message, 2);
20
+ }
21
+ }
22
+
23
+ class IntegrityError extends CliError {
24
+ constructor(message) {
25
+ super(message, 3);
26
+ }
27
+ }
28
+
29
+ class InternalError extends CliError {
30
+ constructor(message) {
31
+ super(message, 4);
32
+ }
33
+ }
34
+
35
+ module.exports = {
36
+ CliError,
37
+ ValidationError,
38
+ DependencyError,
39
+ IntegrityError,
40
+ InternalError,
41
+ };
@@ -1,65 +1,65 @@
1
- "use strict";
2
-
3
- const { execFile } = require("child_process");
4
- const { DependencyError } = require("./errors");
5
-
6
- function findPowerShell() {
7
- if (process.platform === "win32") {
8
- return "powershell.exe";
9
- }
10
- return "pwsh";
11
- }
12
-
13
- function runScript(scriptPath, params = {}, options = {}) {
14
- return new Promise((resolve, reject) => {
15
- const psExe = findPowerShell();
16
- const args = [
17
- "-ExecutionPolicy",
18
- "Bypass",
19
- "-NoProfile",
20
- "-NonInteractive",
21
- "-File",
22
- scriptPath,
23
- ];
24
-
25
- for (const [key, value] of Object.entries(params)) {
26
- if (value === true) {
27
- args.push(`-${key}`);
28
- } else if (value === false || value === undefined || value === null) {
29
- continue;
30
- } else {
31
- args.push(`-${key}`);
32
- args.push(String(value));
33
- }
34
- }
35
-
36
- execFile(psExe, args, { maxBuffer: 10 * 1024 * 1024 }, (error, stdout, stderr) => {
37
- if (error && error.code === "ENOENT") {
38
- reject(
39
- new DependencyError(
40
- `PowerShell not found. Ensure PowerShell is installed and available in PATH.\nTried: ${psExe}`
41
- )
42
- );
43
- return;
44
- }
45
-
46
- const exitCode = error ? error.code || 1 : 0;
47
- const result = {
48
- exitCode: typeof exitCode === "number" ? exitCode : 1,
49
- stdout: stdout || "",
50
- stderr: stderr || "",
51
- };
52
-
53
- if (!options.silent && result.stdout) {
54
- process.stdout.write(result.stdout);
55
- }
56
-
57
- resolve(result);
58
- });
59
- });
60
- }
61
-
62
- module.exports = {
63
- findPowerShell,
64
- runScript,
65
- };
1
+ "use strict";
2
+
3
+ const { execFile } = require("child_process");
4
+ const { DependencyError } = require("./errors");
5
+
6
+ function findPowerShell() {
7
+ if (process.platform === "win32") {
8
+ return "powershell.exe";
9
+ }
10
+ return "pwsh";
11
+ }
12
+
13
+ function runScript(scriptPath, params = {}, options = {}) {
14
+ return new Promise((resolve, reject) => {
15
+ const psExe = findPowerShell();
16
+ const args = [
17
+ "-ExecutionPolicy",
18
+ "Bypass",
19
+ "-NoProfile",
20
+ "-NonInteractive",
21
+ "-File",
22
+ scriptPath,
23
+ ];
24
+
25
+ for (const [key, value] of Object.entries(params)) {
26
+ if (value === true) {
27
+ args.push(`-${key}`);
28
+ } else if (value === false || value === undefined || value === null) {
29
+ continue;
30
+ } else {
31
+ args.push(`-${key}`);
32
+ args.push(String(value));
33
+ }
34
+ }
35
+
36
+ execFile(psExe, args, { maxBuffer: 10 * 1024 * 1024 }, (error, stdout, stderr) => {
37
+ if (error && error.code === "ENOENT") {
38
+ reject(
39
+ new DependencyError(
40
+ `PowerShell not found. Ensure PowerShell is installed and available in PATH.\nTried: ${psExe}`
41
+ )
42
+ );
43
+ return;
44
+ }
45
+
46
+ const exitCode = error ? error.code || 1 : 0;
47
+ const result = {
48
+ exitCode: typeof exitCode === "number" ? exitCode : 1,
49
+ stdout: stdout || "",
50
+ stderr: stderr || "",
51
+ };
52
+
53
+ if (!options.silent && result.stdout) {
54
+ process.stdout.write(result.stdout);
55
+ }
56
+
57
+ resolve(result);
58
+ });
59
+ });
60
+ }
61
+
62
+ module.exports = {
63
+ findPowerShell,
64
+ runScript,
65
+ };
package/src/lib/scope.js CHANGED
@@ -1,72 +1,72 @@
1
- "use strict";
2
-
3
- const os = require("os");
4
- const path = require("path");
5
-
6
- const VALID_SCOPES = ["project", "user"];
7
-
8
- function defaultScope(runtime) {
9
- return runtime === "claude" ? "project" : "user";
10
- }
11
-
12
- function isProjectScopeSupported(runtime) {
13
- return runtime === "claude" || runtime === "codex";
14
- }
15
-
16
- function resolveCodexProjectHome(projectPath) {
17
- return path.join(projectPath || process.cwd(), ".codex");
18
- }
19
-
20
- function resolveCodexUserHome() {
21
- return process.env.CODEX_HOME || path.join(os.homedir(), ".codex");
22
- }
23
-
24
- function resolveCodexHome(scope, projectPath) {
25
- return scope === "project"
26
- ? resolveCodexProjectHome(projectPath)
27
- : resolveCodexUserHome();
28
- }
29
-
30
- function resolveSkillsDir(runtime, scope, projectPath) {
31
- if (runtime === "claude") {
32
- if (scope === "user") {
33
- return path.join(os.homedir(), ".claude", "skills");
34
- }
35
- return path.join(projectPath || process.cwd(), ".claude", "skills");
36
- }
37
-
38
- const codexHome = resolveCodexHome(scope, projectPath);
39
- return path.join(codexHome, "skills");
40
- }
41
-
42
- const MANAGED_CLAUDE_SKILLS = [
43
- "code-brainstorm",
44
- "code-debug",
45
- "code-discover",
46
- "code-execute",
47
- "code-finish",
48
- "code-parallel",
49
- "code-plan",
50
- "code-review",
51
- "code-ship",
52
- "code-tdd",
53
- "code-verify",
54
- "code-worktree",
55
- ];
56
-
57
- const MANAGED_CODEX_SKILLS = MANAGED_CLAUDE_SKILLS.map((name) => `sdtk-${name}`);
58
-
59
- function managedSkillNames(runtime) {
60
- return runtime === "claude" ? MANAGED_CLAUDE_SKILLS : MANAGED_CODEX_SKILLS;
61
- }
62
-
63
- module.exports = {
64
- VALID_SCOPES,
65
- defaultScope,
66
- isProjectScopeSupported,
67
- resolveCodexHome,
68
- resolveCodexProjectHome,
69
- resolveCodexUserHome,
70
- resolveSkillsDir,
71
- managedSkillNames,
72
- };
1
+ "use strict";
2
+
3
+ const os = require("os");
4
+ const path = require("path");
5
+
6
+ const VALID_SCOPES = ["project", "user"];
7
+
8
+ function defaultScope(runtime) {
9
+ return runtime === "claude" ? "project" : "user";
10
+ }
11
+
12
+ function isProjectScopeSupported(runtime) {
13
+ return runtime === "claude" || runtime === "codex";
14
+ }
15
+
16
+ function resolveCodexProjectHome(projectPath) {
17
+ return path.join(projectPath || process.cwd(), ".codex");
18
+ }
19
+
20
+ function resolveCodexUserHome() {
21
+ return process.env.CODEX_HOME || path.join(os.homedir(), ".codex");
22
+ }
23
+
24
+ function resolveCodexHome(scope, projectPath) {
25
+ return scope === "project"
26
+ ? resolveCodexProjectHome(projectPath)
27
+ : resolveCodexUserHome();
28
+ }
29
+
30
+ function resolveSkillsDir(runtime, scope, projectPath) {
31
+ if (runtime === "claude") {
32
+ if (scope === "user") {
33
+ return path.join(os.homedir(), ".claude", "skills");
34
+ }
35
+ return path.join(projectPath || process.cwd(), ".claude", "skills");
36
+ }
37
+
38
+ const codexHome = resolveCodexHome(scope, projectPath);
39
+ return path.join(codexHome, "skills");
40
+ }
41
+
42
+ const MANAGED_CLAUDE_SKILLS = [
43
+ "code-brainstorm",
44
+ "code-debug",
45
+ "code-discover",
46
+ "code-execute",
47
+ "code-finish",
48
+ "code-parallel",
49
+ "code-plan",
50
+ "code-review",
51
+ "code-ship",
52
+ "code-tdd",
53
+ "code-verify",
54
+ "code-worktree",
55
+ ];
56
+
57
+ const MANAGED_CODEX_SKILLS = MANAGED_CLAUDE_SKILLS.map((name) => `sdtk-${name}`);
58
+
59
+ function managedSkillNames(runtime) {
60
+ return runtime === "claude" ? MANAGED_CLAUDE_SKILLS : MANAGED_CODEX_SKILLS;
61
+ }
62
+
63
+ module.exports = {
64
+ VALID_SCOPES,
65
+ defaultScope,
66
+ isProjectScopeSupported,
67
+ resolveCodexHome,
68
+ resolveCodexProjectHome,
69
+ resolveCodexUserHome,
70
+ resolveSkillsDir,
71
+ managedSkillNames,
72
+ };
@@ -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 };