rungate 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 (196) hide show
  1. package/.claude/agents/aditi.md +47 -0
  2. package/.claude/agents/marcus.md +50 -0
  3. package/.claude/agents/quinn.md +58 -0
  4. package/.claude/agents/rook.md +47 -0
  5. package/.claude/agents/serena.md +46 -0
  6. package/.claude/rungate.json +11 -0
  7. package/.fallowrc.json +28 -0
  8. package/.github/copilot-instructions.md +20 -0
  9. package/.rungate/conformity-findings.json +648 -0
  10. package/AGENTS.md +106 -0
  11. package/CODE-MAP.md +50 -0
  12. package/HARNESS.md +88 -0
  13. package/bun.lock +26 -0
  14. package/bunfig.toml +2 -0
  15. package/config/brief-policies.json +28 -0
  16. package/config/ceremony-profiles.json +212 -0
  17. package/config/consumer-cascade-map.json +24 -0
  18. package/config/doc-cascade-map.json +24 -0
  19. package/config/eval.json +84 -0
  20. package/config/profiles/account-plan.yaml +36 -0
  21. package/config/profiles/campaign.yaml +94 -0
  22. package/config/prove-evidence.schema.json +65 -0
  23. package/config/spec-policies.json +36 -0
  24. package/config/workflow-schema.json +281 -0
  25. package/gates/SCHEMA-GUIDE.md +121 -0
  26. package/gates/ac-quality.test.ts +106 -0
  27. package/gates/adversarial.test.ts +274 -0
  28. package/gates/brief-assembler.test.ts +429 -0
  29. package/gates/brief-assembler.ts +334 -0
  30. package/gates/bunfig.toml +2 -0
  31. package/gates/chain.test.ts +91 -0
  32. package/gates/e2e-smoke.test.ts +234 -0
  33. package/gates/error-classifier.test.ts +249 -0
  34. package/gates/error-classifier.ts +89 -0
  35. package/gates/orchestrator.test.ts +950 -0
  36. package/gates/orchestrator.ts +569 -0
  37. package/gates/preload.ts +77 -0
  38. package/gates/prompts/ac-adversary.md +20 -0
  39. package/gates/prompts/evidence-validator.md +22 -0
  40. package/gates/prompts/prove-reproducer.md +53 -0
  41. package/gates/prove.test.ts +164 -0
  42. package/gates/run-gate.ts +936 -0
  43. package/gates/schema-parity.test.ts +197 -0
  44. package/gates/schema.ts +362 -0
  45. package/gates/self-heal.test.ts +511 -0
  46. package/gates/self-heal.ts +121 -0
  47. package/gates/ship-orchestrator.test.ts +379 -0
  48. package/gates/ship-orchestrator.ts +363 -0
  49. package/gates/test-fixtures/broken-no-environments.json +60 -0
  50. package/gates/test-fixtures/valid-standard.json +54 -0
  51. package/gates/test-utils.ts +43 -0
  52. package/gates/witness.ts +220 -0
  53. package/gates/workflow.test.ts +1053 -0
  54. package/hooks/AgentBriefGuard.hook.ts +586 -0
  55. package/hooks/AgentVerdictCapture.hook.ts +134 -0
  56. package/hooks/AutoVerifyGate.hook.ts +76 -0
  57. package/hooks/GateEnforcement.hook.ts +273 -0
  58. package/hooks/IssueCloseGuard.hook.ts +116 -0
  59. package/hooks/MergeGuard.hook.ts +55 -0
  60. package/hooks/StaleTTLCleanup.hook.ts +133 -0
  61. package/hooks/VerifyPhaseLock.hook.ts +81 -0
  62. package/hooks/WorkflowStateGuard.hook.ts +37 -0
  63. package/hooks/lib/agentDetection.ts +70 -0
  64. package/hooks/lib/findWorkflow.ts +101 -0
  65. package/hooks/lib/parseStdin.ts +37 -0
  66. package/hooks/lib/paths.ts +111 -0
  67. package/hooks/lib/utils.ts +81 -0
  68. package/lib/conformity.ts +959 -0
  69. package/lib/paths.ts +23 -0
  70. package/lib/rungate-schema.ts +60 -0
  71. package/lib/signal-phrases.ts +7 -0
  72. package/package.json +20 -0
  73. package/prompts/ac-adversary.md +20 -0
  74. package/prompts/ac-format.md +34 -0
  75. package/prompts/aditi.md +29 -0
  76. package/prompts/blast-radius.md +29 -0
  77. package/prompts/coding-principles.md +34 -0
  78. package/prompts/container-rebuild.md +29 -0
  79. package/prompts/container-verify.md +28 -0
  80. package/prompts/discovery.md +27 -0
  81. package/prompts/environment.md +28 -0
  82. package/prompts/escalation-decision-tree.md +38 -0
  83. package/prompts/evidence-hierarchy.md +31 -0
  84. package/prompts/evidence-validator.md +22 -0
  85. package/prompts/marcus.md +29 -0
  86. package/prompts/prevention.md +26 -0
  87. package/prompts/prove-reproducer.md +43 -0
  88. package/prompts/quinn-decision-tree.md +31 -0
  89. package/prompts/quinn-ui-brief.md +106 -0
  90. package/prompts/quinn.md +29 -0
  91. package/prompts/rca.md +28 -0
  92. package/prompts/read-before-write.md +30 -0
  93. package/prompts/regression.md +26 -0
  94. package/prompts/rook.md +29 -0
  95. package/prompts/serena.md +28 -0
  96. package/prompts/testing-strategy.md +34 -0
  97. package/reference/migration-manifest.json +554 -0
  98. package/reference/prompts/agent-aditi.md +38 -0
  99. package/reference/prompts/agent-marcus.md +38 -0
  100. package/reference/prompts/agent-quinn.md +38 -0
  101. package/reference/prompts/agent-rook.md +37 -0
  102. package/reference/prompts/agent-serena.md +37 -0
  103. package/reference/prompts/council-skill.md +170 -0
  104. package/reference/prompts/goal-skill.md +235 -0
  105. package/reference/prompts/prove-skill.md +283 -0
  106. package/reference/prompts/quinn-standard.md +246 -0
  107. package/reference/prompts/ship-convergence.md +65 -0
  108. package/reference/prompts/ship-escalation.md +43 -0
  109. package/reference/prompts/ship-iteration.md +382 -0
  110. package/reference/prompts/ship-pending-patches.md +246 -0
  111. package/reference/prompts/ship-reference.md +250 -0
  112. package/reference/prompts/ship-skill.md +347 -0
  113. package/reference/prompts/ship-templates.md +215 -0
  114. package/reference/scripts/batch-status.sh +68 -0
  115. package/reference/scripts/chain-compat-check.sh +67 -0
  116. package/reference/scripts/context-audit.sh +314 -0
  117. package/reference/scripts/dead-export-check.sh +61 -0
  118. package/reference/scripts/generate-qc-tables.sh +92 -0
  119. package/reference/scripts/harness-init.sh +111 -0
  120. package/reference/scripts/pai-054-baseline-check.sh +40 -0
  121. package/reference/scripts/prove-smoke-test.sh +112 -0
  122. package/reference/scripts/setup-keychain-salt.sh +12 -0
  123. package/reference/scripts/skill-optimizer-friday.sh +88 -0
  124. package/reference/scripts/skill-qc-test.sh +351 -0
  125. package/reference/scripts/skill-synthesize-tonight.sh +66 -0
  126. package/reference/specs/HARNESS-EXTRACTION-SPEC.md +263 -0
  127. package/reference/specs/harness-v3-bash-deletion-plan.md +65 -0
  128. package/reference/specs/harness-v3-migration-plan.md +188 -0
  129. package/scripts/decision-reconcile.sh +74 -0
  130. package/scripts/decision-reconcile.ts +152 -0
  131. package/scripts/extract-constraints.ts +260 -0
  132. package/scripts/generate-code-map.ts +339 -0
  133. package/scripts/git-hooks/pre-commit +76 -0
  134. package/scripts/git-hooks/pre-push +271 -0
  135. package/scripts/harness-skill-check.sh +52 -0
  136. package/scripts/lib/gap-emit.sh +65 -0
  137. package/scripts/lib/jq-update.sh +30 -0
  138. package/scripts/lib/resolve-slug.sh +30 -0
  139. package/scripts/lib/verify-spec-compliance.sh +102 -0
  140. package/scripts/prove-backfill.sh +87 -0
  141. package/scripts/scaffold-project.ts +1488 -0
  142. package/scripts/scaffold-rungate-config.ts +91 -0
  143. package/scripts/self-containment-check.sh +109 -0
  144. package/scripts/skill-qc-validator.sh +402 -0
  145. package/scripts/slug-resolver.sh +14 -0
  146. package/scripts/sync-spec-tests.ts +236 -0
  147. package/specs/BOOTSTRAP-DATA-FLOW-SPEC.md +2493 -0
  148. package/specs/BOOTSTRAP-TEST-PLAN.md +571 -0
  149. package/specs/HARNESS-GATES.md +256 -0
  150. package/specs/HARNESS-SKILL-CHAIN.md +286 -0
  151. package/specs/HARNESS-SKILL-CONTRACT.md +93 -0
  152. package/specs/HARNESS-STANDARD.md +488 -0
  153. package/specs/SPEC-TEMPLATE.md +53 -0
  154. package/specs/bootstrap-data-flow.png +0 -0
  155. package/specs/harness-automation-matrix.md +314 -0
  156. package/specs/harness-automation-matrix.rules.json +64 -0
  157. package/test/anti.test.ts +80 -0
  158. package/test/contract-negative.test.ts +86 -0
  159. package/test/contract.test.ts +158 -0
  160. package/test/external-deps.test.ts +48 -0
  161. package/test/fixtures/golden-project/.env.example +3 -0
  162. package/test/fixtures/golden-project/Makefile +7 -0
  163. package/test/fixtures/golden-project/docs/adr/ADR-001-framework.md +23 -0
  164. package/test/fixtures/golden-project/docs/setup-guide.md +10 -0
  165. package/test/fixtures/golden-project/package.json +10 -0
  166. package/test/fixtures/golden-project/specs/api-spec.md +20 -0
  167. package/test/fixtures/golden-project/src/auth.ts +8 -0
  168. package/test/fixtures/golden-project/src/db.ts +11 -0
  169. package/test/fixtures/golden-project/src/index.ts +19 -0
  170. package/test/fixtures/golden-project/src/utils/format.ts +3 -0
  171. package/test/fixtures/golden-project/test/auth.test.ts +15 -0
  172. package/test/fixtures/golden-project/tsconfig.json +12 -0
  173. package/test/meta-sc-coverage.test.ts +159 -0
  174. package/test/phase-0.test.ts +846 -0
  175. package/test/phase-1.test.ts +617 -0
  176. package/test/phase-2.test.ts +620 -0
  177. package/test/phase-3.test.ts +99 -0
  178. package/test/scaffold-conformity.test.ts +8 -0
  179. package/test/schema-canary.test.ts +51 -0
  180. package/test/spec-compliance-auto.test.ts +64 -0
  181. package/test/spec-compliance.test.ts +295 -0
  182. package/test/spec-discovery.test.ts +68 -0
  183. package/test/spec-drift.test.ts +5 -0
  184. package/test/structure.test.ts +165 -0
  185. package/test/unit/agent-brief-guard-ship.test.ts +293 -0
  186. package/test/unit/extract-constraints.test.ts +145 -0
  187. package/test/unit/issue-close-guard.test.ts +204 -0
  188. package/test/unit/scaffold-project.test.ts +417 -0
  189. package/test/unit/skill-cooccurrence.test.ts +177 -0
  190. package/test/unit/skill-sequence-logger.test.ts +244 -0
  191. package/test/unit/workflow-state-guard.test.ts +95 -0
  192. package/workflows/batch-ship.js +295 -0
  193. package/workflows/council.js +481 -0
  194. package/workflows/prove.js +560 -0
  195. package/workflows/ship.js +789 -0
  196. package/workflows/verify.js +236 -0
@@ -0,0 +1,158 @@
1
+ import { test, expect, describe, beforeAll } from "bun:test";
2
+ import { mkdirSync, writeFileSync } from "fs";
3
+ import { join } from "path";
4
+ import { execSync } from "child_process";
5
+
6
+ const TEST_BASE = "/tmp/harness-contract-tests";
7
+ const GATES_DIR = join(import.meta.dir, "..", "gates");
8
+
9
+ function runGate(gate: string, slug: string): { pass: number; fail: number; output: string } {
10
+ const gateRunner = join(GATES_DIR, "run-gate.ts");
11
+ const cmd = `RUNGATE_WORK_DIR=${TEST_BASE} RUNGATE_SKIP_AGENTS=1 bun run ${gateRunner} --gate ${gate} --slug ${slug} --issue 9999 2>&1`;
12
+ try {
13
+ const output = execSync(cmd, { encoding: "utf-8", timeout: 30000 });
14
+ const passMatch = output.match(/(\d+) pass/);
15
+ const failMatch = output.match(/(\d+) fail/);
16
+ return { pass: passMatch ? parseInt(passMatch[1]) : 0, fail: failMatch ? parseInt(failMatch[1]) : 0, output };
17
+ } catch (e: any) {
18
+ const out = (e.stdout || "") + (e.stderr || "");
19
+ const passMatch = out.match(/(\d+) pass/);
20
+ const failMatch = out.match(/(\d+) fail/);
21
+ return { pass: passMatch ? parseInt(passMatch[1]) : 0, fail: failMatch ? parseInt(failMatch[1]) : 0, output: out };
22
+ }
23
+ }
24
+
25
+ describe("contract: LIGHT tier", () => {
26
+ beforeAll(() => {
27
+ const dir = join(TEST_BASE, "light");
28
+ mkdirSync(dir, { recursive: true });
29
+ writeFileSync(join(dir, "workflow-state.json"), JSON.stringify({
30
+ schemaVersion: 2, issue: 9999, repo: "test/repo", issueRepo: "test/repo",
31
+ projectRoot: "/tmp/test", slug: "light", phase: "DONE",
32
+ issueGoal: "Test canary", sizing: { predicted: "XS", ceremonyTier: "LIGHT" },
33
+ acs: [{ id: "AC-1", type: "CODE", statement: "Unit tests pass including canary test suite",
34
+ threshold: { op: ">=", value: 10 }, evidenceMethod: { type: "BUN_TEST", command: "bun test" },
35
+ evidence: { type: "command-output", content: "24 pass" }, verdict: "PASS" }],
36
+ gates: { scope: { result: "PASS", attempt: 1, failures: [] } },
37
+ environments: { local: { api: "PASS", ui: "PASS", tests: "PASS" } },
38
+ agents: { marcus: { spawned: true, verdict: "PASS" } },
39
+ buildCommit: "abc1234", changelog: [], bootstrappedFrom: "ship-workflow"
40
+ }, null, 2));
41
+ writeFileSync(join(dir, "marcus-brief.md"), "# Marcus Brief\n\nCovers: AC-1\n\n## AC-1\nUnit tests pass\n");
42
+ });
43
+
44
+ test("scope passes", () => {
45
+ const r = runGate("scope", "light");
46
+ expect(r.fail).toBe(0);
47
+ expect(r.pass).toBeGreaterThan(0);
48
+ });
49
+
50
+ test("ship passes", () => {
51
+ const r = runGate("ship", "light");
52
+ expect(r.pass).toBeGreaterThan(0);
53
+ });
54
+ });
55
+
56
+ describe("contract: STANDARD tier", () => {
57
+ beforeAll(() => {
58
+ const dir = join(TEST_BASE, "standard");
59
+ mkdirSync(dir, { recursive: true });
60
+ writeFileSync(join(dir, "workflow-state.json"), JSON.stringify({
61
+ schemaVersion: 2, issue: 9998, repo: "test/repo", issueRepo: "test/repo",
62
+ projectRoot: "/tmp/test", slug: "standard", phase: "DONE",
63
+ issueGoal: "Test canary standard", sizing: { predicted: "S", ceremonyTier: "STANDARD" },
64
+ acs: [
65
+ { id: "AC-1", type: "CODE", statement: "Fix applied to target module correctly", threshold: { op: "contains", value: "fix" }, evidenceMethod: { type: "grep", command: "grep fix src/test.ts" }, evidence: { type: "command-output", content: "fix" }, verdict: "PASS" },
66
+ { id: "AC-2", type: "CODE", statement: "All unit tests pass without regression", threshold: { op: ">=", value: 10 }, evidenceMethod: { type: "BUN_TEST", command: "bun test" }, evidence: { type: "command-output", content: "24 pass" }, verdict: "PASS" },
67
+ ],
68
+ sourceSpecs: [{ path: join(process.env.HOME || "", "Projects/rungate/specs/BOOTSTRAP-DATA-FLOW-SPEC.md"), citedInDiscovery: true }],
69
+ gates: { scope: { result: "PASS", attempt: 1, failures: [] }, verify: { result: "PASS", attempt: 1, failures: [] } },
70
+ environments: { local: { api: "PASS", ui: "PASS", tests: "PASS" }, prod: { rebuild: "SKIP", smoke: "SKIP", quinn: "SKIP" } },
71
+ agents: { marcus: { spawned: true, verdict: "PASS" }, quinn: { spawned: true, verdict: "PASS" } },
72
+ buildCommit: "abc1234", changelog: [], bootstrappedFrom: "ship-workflow"
73
+ }, null, 2));
74
+ writeFileSync(join(dir, "marcus-brief.md"), "# Marcus Brief\n\nCovers: AC-1, AC-2\n\n## AC-1\nFix applied\n\n## AC-2\nAll unit tests pass\n");
75
+ });
76
+
77
+ test("scope passes", () => {
78
+ const r = runGate("scope", "standard");
79
+ expect(r.fail).toBe(0);
80
+ });
81
+
82
+ test("verify passes", () => {
83
+ const r = runGate("verify", "standard");
84
+ expect(r.fail).toBe(0);
85
+ });
86
+
87
+ test("ship passes", () => {
88
+ const r = runGate("ship", "standard");
89
+ expect(r.fail).toBe(0);
90
+ });
91
+ });
92
+
93
+ describe("contract: negative cases", () => {
94
+ test("missing environments fails ship", () => {
95
+ const dir = join(TEST_BASE, "broken-env");
96
+ mkdirSync(dir, { recursive: true });
97
+ writeFileSync(join(dir, "workflow-state.json"), JSON.stringify({
98
+ schemaVersion: 2, issue: 9997, repo: "test/repo", issueRepo: "test/repo",
99
+ projectRoot: "/tmp/test", slug: "broken-env", phase: "DONE",
100
+ issueGoal: "Broken env test", sizing: { predicted: "S", ceremonyTier: "STANDARD" },
101
+ acs: [{ id: "AC-1", type: "CODE", statement: "Fix applied correctly to module", threshold: { op: "contains", value: "fix" }, evidenceMethod: { type: "BUN_TEST", command: "bun test" }, evidence: { type: "command-output", content: "24 pass" }, verdict: "PASS" }],
102
+ sourceSpecs: [{ path: join(process.env.HOME || "", "Projects/rungate/specs/BOOTSTRAP-DATA-FLOW-SPEC.md"), citedInDiscovery: true }],
103
+ gates: { scope: { result: "PASS", attempt: 1, failures: [] }, verify: { result: "PASS", attempt: 1, failures: [] } },
104
+ environments: {},
105
+ agents: { marcus: { spawned: true, verdict: "PASS" } },
106
+ buildCommit: "abc1234", changelog: [], bootstrappedFrom: "ship-workflow"
107
+ }, null, 2));
108
+ writeFileSync(join(dir, "marcus-brief.md"), "# Marcus Brief\n\nCovers: AC-1\n\n## AC-1\nFix applied\n");
109
+ const r = runGate("ship", "broken-env");
110
+ expect(r.fail).toBeGreaterThan(0);
111
+ });
112
+
113
+ test("all-grep evidence fails ratio check", () => {
114
+ const dir = join(TEST_BASE, "broken-grep");
115
+ mkdirSync(dir, { recursive: true });
116
+ writeFileSync(join(dir, "workflow-state.json"), JSON.stringify({
117
+ schemaVersion: 2, issue: 9996, repo: "test/repo", issueRepo: "test/repo",
118
+ projectRoot: "/tmp/test", slug: "broken-grep", phase: "DONE",
119
+ issueGoal: "Broken grep test", sizing: { predicted: "S", ceremonyTier: "STANDARD" },
120
+ acs: [
121
+ { id: "AC-1", type: "CODE", statement: "First check passes via grep only", threshold: { op: ">=", value: 10 }, evidenceMethod: { type: "grep", command: "grep x y" }, evidence: { type: "command-output", content: "10" }, verdict: "PASS" },
122
+ { id: "AC-2", type: "CODE", statement: "Second check passes via grep only", threshold: { op: ">=", value: 10 }, evidenceMethod: { type: "grep", command: "grep x y" }, evidence: { type: "command-output", content: "10" }, verdict: "PASS" },
123
+ { id: "AC-3", type: "CODE", statement: "Third check passes via grep only", threshold: { op: ">=", value: 10 }, evidenceMethod: { type: "grep", command: "grep x y" }, evidence: { type: "command-output", content: "10" }, verdict: "PASS" },
124
+ { id: "AC-4", type: "CODE", statement: "Fourth check passes via grep only", threshold: { op: ">=", value: 10 }, evidenceMethod: { type: "grep", command: "grep x y" }, evidence: { type: "command-output", content: "10" }, verdict: "PASS" },
125
+ ],
126
+ sourceSpecs: [{ path: join(process.env.HOME || "", "Projects/rungate/specs/BOOTSTRAP-DATA-FLOW-SPEC.md"), citedInDiscovery: true }],
127
+ gates: { scope: { result: "PASS", attempt: 1, failures: [] }, verify: { result: "PASS", attempt: 1, failures: [] } },
128
+ environments: { local: { api: "PASS", ui: "PASS", tests: "PASS" } },
129
+ agents: { marcus: { spawned: true, verdict: "PASS" } },
130
+ buildCommit: "abc1234", changelog: [], bootstrappedFrom: "ship-workflow"
131
+ }, null, 2));
132
+ writeFileSync(join(dir, "marcus-brief.md"), "# Marcus Brief\n\nCovers: AC-1, AC-2, AC-3, AC-4\n\n## AC-1\nFirst check\n\n## AC-2\nSecond check\n\n## AC-3\nThird check\n\n## AC-4\nFourth check\n");
133
+ const r = runGate("ship", "broken-grep");
134
+ expect(r.output).toContain("evidence-type-ratio");
135
+ });
136
+
137
+ test("missing AC evidence fails at ship", () => {
138
+ const dir = join(TEST_BASE, "broken-evidence");
139
+ mkdirSync(dir, { recursive: true });
140
+ writeFileSync(join(dir, "workflow-state.json"), JSON.stringify({
141
+ schemaVersion: 2, issue: 9995, repo: "test/repo", issueRepo: "test/repo",
142
+ projectRoot: "/tmp/test", slug: "broken-evidence", phase: "DONE",
143
+ issueGoal: "Broken evidence test", sizing: { predicted: "S", ceremonyTier: "STANDARD" },
144
+ acs: [
145
+ { id: "AC-1", type: "CODE", statement: "Has evidence from test run output", threshold: { op: ">=", value: 10 }, evidenceMethod: { type: "BUN_TEST", command: "bun test" }, evidence: { type: "command-output", content: "24 pass" }, verdict: "PASS" },
146
+ { id: "AC-2", type: "CODE", statement: "Missing evidence for grep verification", threshold: { op: ">=", value: 10 }, evidenceMethod: { type: "grep", command: "grep x y" }, verdict: "PENDING" },
147
+ ],
148
+ sourceSpecs: [{ path: join(process.env.HOME || "", "Projects/rungate/specs/BOOTSTRAP-DATA-FLOW-SPEC.md"), citedInDiscovery: true }],
149
+ gates: { scope: { result: "PASS", attempt: 1, failures: [] }, verify: { result: "PASS", attempt: 1, failures: [] } },
150
+ environments: { local: { api: "PASS", ui: "PASS", tests: "PASS" } },
151
+ agents: { marcus: { spawned: true, verdict: "PASS" } },
152
+ buildCommit: "abc1234", changelog: [], bootstrappedFrom: "ship-workflow"
153
+ }, null, 2));
154
+ writeFileSync(join(dir, "marcus-brief.md"), "# Marcus Brief\n\nCovers: AC-1, AC-2\n\n## AC-1\nHas evidence\n\n## AC-2\nMissing evidence\n");
155
+ const r = runGate("ship", "broken-evidence");
156
+ expect(r.output).toContain("all-acs-have-evidence");
157
+ });
158
+ });
@@ -0,0 +1,48 @@
1
+ import { describe, test, expect } from "bun:test";
2
+ import { readFileSync, existsSync } from "fs";
3
+ import { join, resolve } from "path";
4
+
5
+ const HARNESS_ROOT = resolve(import.meta.dir, "..");
6
+ const HOME = process.env.HOME || "";
7
+ const CLAUDE_MD = join(HOME, ".claude", "CLAUDE.md");
8
+ const HARNESS_MD = join(HARNESS_ROOT, "HARNESS.md");
9
+
10
+ function extractExternalDeps(harnessContent: string): string[] {
11
+ const section = harnessContent.split("## External Dependencies")[1];
12
+ if (!section) return [];
13
+ const nextSection = section.indexOf("\n## ");
14
+ const block = nextSection > -1 ? section.slice(0, nextSection) : section;
15
+ const deps: string[] = [];
16
+ for (const line of block.split("\n")) {
17
+ const match = line.match(/^- `([^`]+)`/);
18
+ if (match) deps.push(match[1]);
19
+ }
20
+ return deps;
21
+ }
22
+
23
+ describe("ED-1: HARNESS.md has External Dependencies section", () => {
24
+ test("section exists", () => {
25
+ const content = readFileSync(HARNESS_MD, "utf8");
26
+ expect(content).toContain("## External Dependencies");
27
+ });
28
+ });
29
+
30
+ describe("ED-2: Each external dependency exists in CLAUDE.md", () => {
31
+ const harness = readFileSync(HARNESS_MD, "utf8");
32
+ const deps = extractExternalDeps(harness);
33
+ const claudeContent = existsSync(CLAUDE_MD) ? readFileSync(CLAUDE_MD, "utf8") : "";
34
+
35
+ for (const dep of deps) {
36
+ test(`rule "${dep}" exists in CLAUDE.md`, () => {
37
+ expect(claudeContent).toContain(dep);
38
+ });
39
+ }
40
+ });
41
+
42
+ describe("ED-3: At least 5 external dependencies listed", () => {
43
+ test("minimum dependency count", () => {
44
+ const content = readFileSync(HARNESS_MD, "utf8");
45
+ const deps = extractExternalDeps(content);
46
+ expect(deps.length).toBeGreaterThanOrEqual(5);
47
+ });
48
+ });
@@ -0,0 +1,3 @@
1
+ API_PORT=3000
2
+ DATABASE_URL=
3
+ SECRET_KEY=
@@ -0,0 +1,7 @@
1
+ .PHONY: dev test
2
+
3
+ dev:
4
+ bun run src/index.ts --port 3000
5
+
6
+ test:
7
+ bun test
@@ -0,0 +1,23 @@
1
+ ---
2
+ doc-type: adr
3
+ status: accepted
4
+ created: 2026-08-15
5
+ owner: jason
6
+ updated: 2026-09-18
7
+ ---
8
+
9
+ # ADR-001: Use Hono as HTTP framework
10
+
11
+ ## Context
12
+
13
+ Need a lightweight, fast HTTP framework for Bun runtime.
14
+
15
+ ## Decision
16
+
17
+ Use Hono — native Bun support, minimal overhead, TypeScript-first.
18
+
19
+ ## Consequences
20
+
21
+ - Fast cold starts
22
+ - Smaller dependency tree than Express
23
+ - Less middleware ecosystem than Express
@@ -0,0 +1,10 @@
1
+ ---
2
+ doc-type: guide
3
+ status: active
4
+ owner: jason
5
+ updated: 2026-09-01
6
+ ---
7
+
8
+ # Setup Guide
9
+
10
+ Install dependencies with `bun install`, then run `bun run src/index.ts`.
@@ -0,0 +1,10 @@
1
+ {
2
+ "name": "golden-project",
3
+ "type": "module",
4
+ "scripts": {
5
+ "dev": "bun run src/index.ts"
6
+ },
7
+ "dependencies": {
8
+ "hono": "^4.0.0"
9
+ }
10
+ }
@@ -0,0 +1,20 @@
1
+ ---
2
+ doc-type: spec
3
+ status: draft
4
+ owner: test
5
+ created: 2026-09-01
6
+ updated: 2026-09-01
7
+ governs: API routes — health check and data endpoint behavior
8
+ testable: true
9
+ ---
10
+
11
+ # API Spec
12
+
13
+ ## Problem Statement
14
+
15
+ API routes need documented behavior for agents to implement against.
16
+
17
+ ## Success Criteria
18
+
19
+ - [ ] SC-1: GET /api/health returns `{"status":"ok"}` with 200
20
+ - [ ] SC-2: POST /api/data without Authorization header returns 401
@@ -0,0 +1,8 @@
1
+ export function validateToken(token: string | undefined): boolean {
2
+ if (!token) return false;
3
+ return token.startsWith("Bearer ");
4
+ }
5
+
6
+ export function refreshToken(oldToken: string): string {
7
+ return `Bearer refreshed-${Date.now()}`;
8
+ }
@@ -0,0 +1,11 @@
1
+ export async function query(sql: string): Promise<unknown[]> {
2
+ return [];
3
+ }
4
+
5
+ export async function insert(table: string, data: Record<string, unknown>): Promise<{ id: number }> {
6
+ return { id: 1 };
7
+ }
8
+
9
+ export async function migrate(): Promise<void> {
10
+ // run migrations
11
+ }
@@ -0,0 +1,19 @@
1
+ import { Hono } from "hono";
2
+ import { validateToken } from "./auth";
3
+
4
+ const app = new Hono();
5
+
6
+ app.get("/", (c) => c.text("Golden Project"));
7
+
8
+ app.get("/api/health", (c) => c.json({ status: "ok" }));
9
+
10
+ app.post("/api/data", async (c) => {
11
+ const token = c.req.header("Authorization");
12
+ if (!validateToken(token)) {
13
+ return c.json({ error: "unauthorized" }, 401);
14
+ }
15
+ const body = await c.req.json();
16
+ return c.json({ received: body });
17
+ });
18
+
19
+ export default app;
@@ -0,0 +1,3 @@
1
+ export function formatDate(date: Date): string {
2
+ return date.toISOString().split("T")[0];
3
+ }
@@ -0,0 +1,15 @@
1
+ import { test, expect } from "bun:test";
2
+ import { validateToken, refreshToken } from "../src/auth";
3
+
4
+ test("validateToken rejects undefined", () => {
5
+ expect(validateToken(undefined)).toBe(false);
6
+ });
7
+
8
+ test("validateToken accepts Bearer token", () => {
9
+ expect(validateToken("Bearer abc123")).toBe(true);
10
+ });
11
+
12
+ test("refreshToken returns new Bearer token", () => {
13
+ const token = refreshToken("old");
14
+ expect(token).toStartWith("Bearer refreshed-");
15
+ });
@@ -0,0 +1,12 @@
1
+ {
2
+ "compilerOptions": {
3
+ "strict": true,
4
+ "target": "ESNext",
5
+ "module": "ESNext",
6
+ "moduleResolution": "bundler",
7
+ "esModuleInterop": true,
8
+ "outDir": "dist",
9
+ "rootDir": "src"
10
+ },
11
+ "include": ["src"]
12
+ }
@@ -0,0 +1,159 @@
1
+ import { test, expect, describe } from "bun:test";
2
+ import { readFileSync, existsSync } from "fs";
3
+ import { join } from "path";
4
+ import { execSync } from "child_process";
5
+
6
+ const SPEC_PATH = join(import.meta.dir, "..", "specs", "BOOTSTRAP-DATA-FLOW-SPEC.md");
7
+ const TEST_PLAN_PATH = join(import.meta.dir, "..", "specs", "BOOTSTRAP-TEST-PLAN.md");
8
+
9
+ // Phase header → test file mapping
10
+ const PHASE_MAP: Record<string, string> = {
11
+ "Phase 0": "phase-0",
12
+ "Phase 1": "phase-1",
13
+ "Phase 2": "phase-2",
14
+ "Phase 3": "phase-3",
15
+ "Anti-Criteria": "anti",
16
+ };
17
+
18
+ // Parse SC-to-phase routing from ### subheaders in the Success Criteria section
19
+ function parseRouting(spec: string): Map<string, string> {
20
+ const routing = new Map<string, string>();
21
+ let currentPhase: string | null = null;
22
+
23
+ for (const line of spec.split("\n")) {
24
+ // Match phase subheaders: ### Phase 0 — Scaffold Output
25
+ const headerMatch = line.match(/^### (Phase \d+|Anti-Criteria)/);
26
+ if (headerMatch) {
27
+ const key = headerMatch[1];
28
+ currentPhase = PHASE_MAP[key] || null;
29
+ continue;
30
+ }
31
+
32
+ if (!currentPhase) continue;
33
+
34
+ // Match SC lines under current phase header
35
+ const scMatch = line.match(/^- \[ \] (SC-(?:\d+|A\d+)):/);
36
+ if (scMatch) {
37
+ routing.set(scMatch[1], currentPhase);
38
+ }
39
+ }
40
+
41
+ return routing;
42
+ }
43
+
44
+ describe("meta: SC coverage — every SC in the spec has a test", () => {
45
+ test("all SCs from bootstrap spec appear in at least one test file", () => {
46
+ const spec = readFileSync(SPEC_PATH, "utf-8");
47
+ const routing = parseRouting(spec);
48
+
49
+ // Extract all SC IDs
50
+ const scMatches = [...spec.matchAll(/^- \[ \] (SC-(?:\d+|A\d+)):/gm)];
51
+ const allSCs = [...new Set(scMatches.map(m => m[1]))];
52
+
53
+ // Read all phase test files
54
+ const testFiles = ["phase-0.test.ts", "phase-1.test.ts", "phase-2.test.ts", "phase-3.test.ts", "anti.test.ts"]
55
+ .map(f => join(import.meta.dir, f))
56
+ .filter(f => existsSync(f));
57
+
58
+ const testContent = testFiles.map(f => readFileSync(f, "utf-8")).join("\n");
59
+
60
+ // Find SCs that appear in no test file
61
+ const untested = allSCs.filter(sc => !testContent.includes(sc));
62
+
63
+ // Find SCs not under any phase header (spec structure error)
64
+ const unrouted = allSCs.filter(sc => !routing.has(sc));
65
+
66
+ if (untested.length > 0) {
67
+ console.log(`\n── SC COVERAGE GAP ──────────────────────────`);
68
+ console.log(` ${allSCs.length} SCs in spec, ${allSCs.length - untested.length} tested, ${untested.length} UNTESTED`);
69
+ console.log(` Routed by ### Phase headers in Success Criteria section.\n`);
70
+
71
+ // Group by phase from section headers
72
+ const byPhase = new Map<string, string[]>();
73
+ for (const sc of untested) {
74
+ const phase = routing.get(sc) || "UNROUTED";
75
+ if (!byPhase.has(phase)) byPhase.set(phase, []);
76
+ byPhase.get(phase)!.push(sc);
77
+ }
78
+
79
+ for (const [phase, scs] of [...byPhase.entries()].sort()) {
80
+ const file = phase === "UNROUTED" ? "— move SC under a ### Phase header" : `test/${phase}.test.ts`;
81
+ console.log(` ${phase} → ${file} (${scs.length} untested)`);
82
+ for (const sc of scs) {
83
+ const line = scMatches.find(m => m[1] === sc);
84
+ const scText = line ? line[0].substring(6, 90) : sc;
85
+ console.log(` ✗ ${scText}`);
86
+ }
87
+ }
88
+ console.log(`──────────────────────────────────────────────\n`);
89
+ }
90
+
91
+ if (unrouted.length > 0) {
92
+ console.log(`\n── UNROUTED SCs (not under a ### Phase header) ──`);
93
+ console.log(` These SCs exist in the spec but are outside the phase-grouped section.`);
94
+ console.log(` Move them under the correct ### Phase header in ## Success Criteria.\n`);
95
+ for (const sc of unrouted) {
96
+ console.log(` ✗ ${sc}`);
97
+ }
98
+ console.log(`──────────────────────────────────────────────\n`);
99
+ }
100
+
101
+ const coverage = ((allSCs.length - untested.length) / allSCs.length * 100).toFixed(1);
102
+ console.log(`SC coverage: ${allSCs.length - untested.length}/${allSCs.length} (${coverage}%)`);
103
+
104
+ expect(untested).toEqual([]);
105
+ });
106
+
107
+ test("all SCs are under a phase header (no orphans)", () => {
108
+ const spec = readFileSync(SPEC_PATH, "utf-8");
109
+ const routing = parseRouting(spec);
110
+
111
+ const scMatches = [...spec.matchAll(/^- \[ \] (SC-(?:\d+|A\d+)):/gm)];
112
+ const allSCs = [...new Set(scMatches.map(m => m[1]))];
113
+ const unrouted = allSCs.filter(sc => !routing.has(sc));
114
+
115
+ if (unrouted.length > 0) {
116
+ console.log(`UNROUTED: ${unrouted.join(", ")}`);
117
+ }
118
+
119
+ expect(unrouted).toEqual([]);
120
+ });
121
+
122
+ test("all TPs from test plan spec appear in at least one test file", () => {
123
+ if (!existsSync(TEST_PLAN_PATH)) return;
124
+ const testPlan = readFileSync(TEST_PLAN_PATH, "utf-8");
125
+
126
+ const tpMatches = [...testPlan.matchAll(/^- \[ \] (TP-\d+):/gm)];
127
+ const allTPs = [...new Set(tpMatches.map(m => m[1]))];
128
+
129
+ const testFiles = ["phase-0.test.ts", "phase-1.test.ts", "phase-2.test.ts", "phase-3.test.ts", "meta-sc-coverage.test.ts"]
130
+ .map(f => join(import.meta.dir, f))
131
+ .filter(f => existsSync(f));
132
+
133
+ const testContent = testFiles.map(f => readFileSync(f, "utf-8")).join("\n");
134
+
135
+ const untested = allTPs.filter(tp => !testContent.includes(tp));
136
+
137
+ if (untested.length > 0) {
138
+ console.log(`\n── TP COVERAGE GAP ──────────────────────────`);
139
+ console.log(` ${allTPs.length} TPs in test plan, ${untested.length} UNTESTED:`);
140
+ for (const tp of untested) {
141
+ console.log(` ✗ ${tp}`);
142
+ }
143
+ console.log(`──────────────────────────────────────────────\n`);
144
+ }
145
+
146
+ expect(untested).toEqual([]);
147
+ });
148
+
149
+ // TP-9: Meta-test validates SC coverage
150
+ test("TP-9: this meta-test exists and runs", () => {
151
+ expect(true).toBe(true);
152
+ });
153
+
154
+ // TP-3: Every SC appears in at least one phase test file
155
+ test("TP-3: phase test files exist", () => {
156
+ expect(existsSync(join(import.meta.dir, "phase-0.test.ts"))).toBe(true);
157
+ expect(existsSync(join(import.meta.dir, "phase-1.test.ts"))).toBe(true);
158
+ });
159
+ });