rungate 0.2.0 → 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.
Files changed (282) hide show
  1. package/bin/rungate.ts +70 -0
  2. package/lib/aes-calculator.ts +66 -0
  3. package/lib/agent-audit.ts +139 -0
  4. package/lib/agent-brief-validation.ts +359 -0
  5. package/lib/agents-md-refs.ts +90 -0
  6. package/lib/bash-file-read.ts +197 -0
  7. package/lib/behavioral-cache.ts +78 -0
  8. package/lib/branch-cleanup.ts +234 -0
  9. package/lib/brief-context-parser.ts +35 -0
  10. package/lib/canary.ts +117 -0
  11. package/lib/check-registry.ts +226 -0
  12. package/lib/ci-checkout.ts +400 -0
  13. package/lib/cli-commands.ts +137 -0
  14. package/lib/compliance-backfill.ts +220 -0
  15. package/lib/compliance-report.ts +504 -0
  16. package/lib/compliance.ts +361 -0
  17. package/lib/config-loader.ts +255 -0
  18. package/lib/conformity.ts +1818 -131
  19. package/lib/container-provenance.ts +230 -0
  20. package/lib/create-brief.ts +150 -0
  21. package/lib/create-sc.ts +272 -0
  22. package/lib/deep-merge.ts +69 -0
  23. package/lib/dev-liveness.ts +214 -0
  24. package/lib/directive-extractor.ts +210 -0
  25. package/lib/distribution-standing.ts +113 -0
  26. package/lib/doc-hygiene.ts +238 -0
  27. package/lib/eval-criteria.ts +6 -0
  28. package/lib/evidence-portability.ts +123 -0
  29. package/lib/evidence-prevalidator.ts +390 -0
  30. package/lib/evidence-required.ts +150 -0
  31. package/lib/evidence-satisfiability.ts +288 -0
  32. package/lib/frontmatter.ts +163 -0
  33. package/lib/gap-scanner.ts +348 -0
  34. package/lib/gate-enforcement.ts +366 -0
  35. package/lib/generators/agent-briefs.ts +136 -0
  36. package/lib/generators/agents-md.ts +506 -0
  37. package/lib/generators/code-map.ts +60 -0
  38. package/lib/generators/types.ts +184 -0
  39. package/lib/git-ref-normalizer.ts +107 -0
  40. package/lib/github.ts +539 -0
  41. package/lib/harness-identity.ts +63 -0
  42. package/lib/hill-climb.ts +164 -0
  43. package/lib/instruction-effectiveness.ts +131 -0
  44. package/lib/issue-closure-audit.ts +225 -0
  45. package/lib/issue-create-override.ts +343 -0
  46. package/lib/js-top-level-code.ts +250 -0
  47. package/lib/liveness-contradiction.ts +149 -0
  48. package/lib/organize.ts +505 -0
  49. package/lib/paths.ts +197 -6
  50. package/lib/post-fix-verify.ts +157 -0
  51. package/lib/prior-branch.ts +489 -0
  52. package/lib/project-state-shape.ts +166 -0
  53. package/lib/promote-outputs.ts +156 -0
  54. package/lib/prove-label-gate.ts +35 -0
  55. package/lib/reachability.ts +302 -0
  56. package/lib/release-preflight.ts +186 -0
  57. package/lib/rule-health-pipeline.ts +264 -0
  58. package/lib/rule-health-trend.ts +161 -0
  59. package/lib/rule-provenance.ts +149 -0
  60. package/lib/rule-registry.ts +128 -0
  61. package/lib/rungate-schema.ts +114 -4
  62. package/lib/sc-claim-forms.ts +179 -0
  63. package/lib/sc-cover.ts +150 -0
  64. package/lib/sc-guard.ts +157 -0
  65. package/lib/sc-ids.ts +344 -0
  66. package/lib/scaffold/defaults.ts +165 -0
  67. package/lib/scaffold/managed-workflow.ts +370 -0
  68. package/lib/scaffold/owned-files.ts +265 -0
  69. package/lib/scaffold/steps.ts +2680 -0
  70. package/lib/scanner.ts +701 -0
  71. package/lib/screenshot-upload.ts +73 -0
  72. package/lib/secret-patterns.ts +112 -0
  73. package/lib/security-verdict.ts +616 -0
  74. package/lib/signal-phrases.ts +1 -0
  75. package/lib/spec-change-conformity.ts +80 -0
  76. package/lib/spec-files.ts +62 -0
  77. package/lib/spec-registry.ts +133 -0
  78. package/lib/spec-updater.ts +96 -0
  79. package/lib/stale-cleanup.ts +224 -0
  80. package/lib/stale-issue-scanner.ts +36 -0
  81. package/lib/strip-js-comments.ts +269 -0
  82. package/lib/suite-measurement.ts +228 -0
  83. package/lib/task-completion-checks.ts +177 -0
  84. package/lib/test-suite-lock.ts +1136 -0
  85. package/lib/transcript-checker.ts +1140 -0
  86. package/lib/validators/spec-validators.ts +171 -0
  87. package/lib/verdict-capture.ts +73 -0
  88. package/lib/verified-push.ts +358 -0
  89. package/lib/workflow-security.ts +174 -0
  90. package/lib/worktree-cleanup.ts +250 -0
  91. package/lib/worktree-collect.ts +283 -0
  92. package/lib/worktree-isolation.ts +82 -0
  93. package/package.json +36 -3
  94. package/prompts/ac-adversary.md +14 -2
  95. package/prompts/aditi.md +5 -0
  96. package/prompts/blast-radius.md +5 -0
  97. package/prompts/container-verify.md +5 -0
  98. package/prompts/discovery.md +4 -0
  99. package/prompts/environment.md +5 -0
  100. package/prompts/evidence-hierarchy.md +5 -0
  101. package/prompts/evidence-validator.md +11 -0
  102. package/prompts/marcus.md +5 -0
  103. package/prompts/prevention.md +5 -0
  104. package/prompts/prove-reproducer.md +12 -0
  105. package/prompts/quinn-decision-tree.md +5 -0
  106. package/prompts/quinn-ui-brief.md +5 -0
  107. package/prompts/quinn.md +5 -0
  108. package/prompts/rca.md +5 -0
  109. package/prompts/read-before-write.md +4 -0
  110. package/prompts/regression.md +5 -0
  111. package/prompts/serena.md +5 -0
  112. package/scripts/audit-specs.ts +464 -0
  113. package/scripts/convert-spec.ts +293 -0
  114. package/scripts/create-sc.ts +92 -0
  115. package/scripts/create-spec.ts +166 -0
  116. package/scripts/extract-constraints.ts +4 -3
  117. package/scripts/generate-code-map.ts +1 -1
  118. package/scripts/scaffold-project.ts +138 -1426
  119. package/scripts/sync-spec-tests.ts +211 -126
  120. package/.claude/agents/aditi.md +0 -47
  121. package/.claude/agents/marcus.md +0 -50
  122. package/.claude/agents/quinn.md +0 -58
  123. package/.claude/agents/rook.md +0 -47
  124. package/.claude/agents/serena.md +0 -46
  125. package/.claude/rungate.json +0 -11
  126. package/.fallowrc.json +0 -28
  127. package/.github/copilot-instructions.md +0 -20
  128. package/.rungate/conformity-findings.json +0 -648
  129. package/AGENTS.md +0 -106
  130. package/CODE-MAP.md +0 -50
  131. package/HARNESS.md +0 -88
  132. package/bun.lock +0 -26
  133. package/bunfig.toml +0 -2
  134. package/config/brief-policies.json +0 -28
  135. package/config/ceremony-profiles.json +0 -212
  136. package/config/consumer-cascade-map.json +0 -24
  137. package/config/doc-cascade-map.json +0 -24
  138. package/config/eval.json +0 -84
  139. package/config/profiles/account-plan.yaml +0 -36
  140. package/config/profiles/campaign.yaml +0 -94
  141. package/config/prove-evidence.schema.json +0 -65
  142. package/config/spec-policies.json +0 -36
  143. package/config/workflow-schema.json +0 -281
  144. package/gates/SCHEMA-GUIDE.md +0 -121
  145. package/gates/ac-quality.test.ts +0 -106
  146. package/gates/adversarial.test.ts +0 -274
  147. package/gates/brief-assembler.test.ts +0 -429
  148. package/gates/brief-assembler.ts +0 -334
  149. package/gates/bunfig.toml +0 -2
  150. package/gates/chain.test.ts +0 -91
  151. package/gates/e2e-smoke.test.ts +0 -234
  152. package/gates/error-classifier.test.ts +0 -249
  153. package/gates/error-classifier.ts +0 -89
  154. package/gates/orchestrator.test.ts +0 -950
  155. package/gates/orchestrator.ts +0 -569
  156. package/gates/preload.ts +0 -77
  157. package/gates/prompts/ac-adversary.md +0 -20
  158. package/gates/prompts/evidence-validator.md +0 -22
  159. package/gates/prompts/prove-reproducer.md +0 -53
  160. package/gates/prove.test.ts +0 -164
  161. package/gates/run-gate.ts +0 -936
  162. package/gates/schema-parity.test.ts +0 -197
  163. package/gates/schema.ts +0 -362
  164. package/gates/self-heal.test.ts +0 -511
  165. package/gates/self-heal.ts +0 -121
  166. package/gates/ship-orchestrator.test.ts +0 -379
  167. package/gates/ship-orchestrator.ts +0 -363
  168. package/gates/test-fixtures/broken-no-environments.json +0 -60
  169. package/gates/test-fixtures/valid-standard.json +0 -54
  170. package/gates/test-utils.ts +0 -43
  171. package/gates/witness.ts +0 -220
  172. package/gates/workflow.test.ts +0 -1053
  173. package/hooks/AgentBriefGuard.hook.ts +0 -586
  174. package/hooks/AgentVerdictCapture.hook.ts +0 -134
  175. package/hooks/AutoVerifyGate.hook.ts +0 -76
  176. package/hooks/GateEnforcement.hook.ts +0 -273
  177. package/hooks/IssueCloseGuard.hook.ts +0 -116
  178. package/hooks/MergeGuard.hook.ts +0 -55
  179. package/hooks/StaleTTLCleanup.hook.ts +0 -133
  180. package/hooks/VerifyPhaseLock.hook.ts +0 -81
  181. package/hooks/WorkflowStateGuard.hook.ts +0 -37
  182. package/hooks/lib/agentDetection.ts +0 -70
  183. package/hooks/lib/findWorkflow.ts +0 -101
  184. package/hooks/lib/parseStdin.ts +0 -37
  185. package/hooks/lib/paths.ts +0 -111
  186. package/hooks/lib/utils.ts +0 -81
  187. package/reference/migration-manifest.json +0 -554
  188. package/reference/prompts/agent-aditi.md +0 -38
  189. package/reference/prompts/agent-marcus.md +0 -38
  190. package/reference/prompts/agent-quinn.md +0 -38
  191. package/reference/prompts/agent-rook.md +0 -37
  192. package/reference/prompts/agent-serena.md +0 -37
  193. package/reference/prompts/council-skill.md +0 -170
  194. package/reference/prompts/goal-skill.md +0 -235
  195. package/reference/prompts/prove-skill.md +0 -283
  196. package/reference/prompts/quinn-standard.md +0 -246
  197. package/reference/prompts/ship-convergence.md +0 -65
  198. package/reference/prompts/ship-escalation.md +0 -43
  199. package/reference/prompts/ship-iteration.md +0 -382
  200. package/reference/prompts/ship-pending-patches.md +0 -246
  201. package/reference/prompts/ship-reference.md +0 -250
  202. package/reference/prompts/ship-skill.md +0 -347
  203. package/reference/prompts/ship-templates.md +0 -215
  204. package/reference/scripts/batch-status.sh +0 -68
  205. package/reference/scripts/chain-compat-check.sh +0 -67
  206. package/reference/scripts/context-audit.sh +0 -314
  207. package/reference/scripts/dead-export-check.sh +0 -61
  208. package/reference/scripts/generate-qc-tables.sh +0 -92
  209. package/reference/scripts/harness-init.sh +0 -111
  210. package/reference/scripts/pai-054-baseline-check.sh +0 -40
  211. package/reference/scripts/prove-smoke-test.sh +0 -112
  212. package/reference/scripts/setup-keychain-salt.sh +0 -12
  213. package/reference/scripts/skill-optimizer-friday.sh +0 -88
  214. package/reference/scripts/skill-qc-test.sh +0 -351
  215. package/reference/scripts/skill-synthesize-tonight.sh +0 -66
  216. package/reference/specs/HARNESS-EXTRACTION-SPEC.md +0 -263
  217. package/reference/specs/harness-v3-bash-deletion-plan.md +0 -65
  218. package/reference/specs/harness-v3-migration-plan.md +0 -188
  219. package/scripts/decision-reconcile.sh +0 -74
  220. package/scripts/decision-reconcile.ts +0 -152
  221. package/scripts/git-hooks/pre-commit +0 -76
  222. package/scripts/git-hooks/pre-push +0 -271
  223. package/scripts/harness-skill-check.sh +0 -52
  224. package/scripts/lib/gap-emit.sh +0 -65
  225. package/scripts/lib/jq-update.sh +0 -30
  226. package/scripts/lib/resolve-slug.sh +0 -30
  227. package/scripts/lib/verify-spec-compliance.sh +0 -102
  228. package/scripts/prove-backfill.sh +0 -87
  229. package/scripts/scaffold-rungate-config.ts +0 -91
  230. package/scripts/self-containment-check.sh +0 -109
  231. package/scripts/skill-qc-validator.sh +0 -402
  232. package/scripts/slug-resolver.sh +0 -14
  233. package/specs/BOOTSTRAP-DATA-FLOW-SPEC.md +0 -2493
  234. package/specs/BOOTSTRAP-TEST-PLAN.md +0 -571
  235. package/specs/HARNESS-GATES.md +0 -256
  236. package/specs/HARNESS-SKILL-CHAIN.md +0 -286
  237. package/specs/HARNESS-SKILL-CONTRACT.md +0 -93
  238. package/specs/HARNESS-STANDARD.md +0 -488
  239. package/specs/SPEC-TEMPLATE.md +0 -53
  240. package/specs/bootstrap-data-flow.png +0 -0
  241. package/specs/harness-automation-matrix.md +0 -314
  242. package/specs/harness-automation-matrix.rules.json +0 -64
  243. package/test/anti.test.ts +0 -80
  244. package/test/contract-negative.test.ts +0 -86
  245. package/test/contract.test.ts +0 -158
  246. package/test/external-deps.test.ts +0 -48
  247. package/test/fixtures/golden-project/.env.example +0 -3
  248. package/test/fixtures/golden-project/Makefile +0 -7
  249. package/test/fixtures/golden-project/docs/adr/ADR-001-framework.md +0 -23
  250. package/test/fixtures/golden-project/docs/setup-guide.md +0 -10
  251. package/test/fixtures/golden-project/package.json +0 -10
  252. package/test/fixtures/golden-project/specs/api-spec.md +0 -20
  253. package/test/fixtures/golden-project/src/auth.ts +0 -8
  254. package/test/fixtures/golden-project/src/db.ts +0 -11
  255. package/test/fixtures/golden-project/src/index.ts +0 -19
  256. package/test/fixtures/golden-project/src/utils/format.ts +0 -3
  257. package/test/fixtures/golden-project/test/auth.test.ts +0 -15
  258. package/test/fixtures/golden-project/tsconfig.json +0 -12
  259. package/test/meta-sc-coverage.test.ts +0 -159
  260. package/test/phase-0.test.ts +0 -846
  261. package/test/phase-1.test.ts +0 -617
  262. package/test/phase-2.test.ts +0 -620
  263. package/test/phase-3.test.ts +0 -99
  264. package/test/scaffold-conformity.test.ts +0 -8
  265. package/test/schema-canary.test.ts +0 -51
  266. package/test/spec-compliance-auto.test.ts +0 -64
  267. package/test/spec-compliance.test.ts +0 -295
  268. package/test/spec-discovery.test.ts +0 -68
  269. package/test/spec-drift.test.ts +0 -5
  270. package/test/structure.test.ts +0 -165
  271. package/test/unit/agent-brief-guard-ship.test.ts +0 -293
  272. package/test/unit/extract-constraints.test.ts +0 -145
  273. package/test/unit/issue-close-guard.test.ts +0 -204
  274. package/test/unit/scaffold-project.test.ts +0 -417
  275. package/test/unit/skill-cooccurrence.test.ts +0 -177
  276. package/test/unit/skill-sequence-logger.test.ts +0 -244
  277. package/test/unit/workflow-state-guard.test.ts +0 -95
  278. package/workflows/batch-ship.js +0 -295
  279. package/workflows/council.js +0 -481
  280. package/workflows/prove.js +0 -560
  281. package/workflows/ship.js +0 -789
  282. package/workflows/verify.js +0 -236
@@ -1,334 +0,0 @@
1
- import { readFileSync, writeFileSync, existsSync } from "fs";
2
- import { join, basename } from "path";
3
-
4
- export interface AssembleResult {
5
- briefPath: string;
6
- acCount: number;
7
- contextFileCount: number;
8
- validated: boolean;
9
- }
10
-
11
- const BRIEF_POLICIES_PATH = join(
12
- process.env.HOME || "",
13
- ".claude",
14
- "skills",
15
- "ship",
16
- "brief-policies.json",
17
- );
18
-
19
- const REQUIRED_SECTIONS = ["Goal", "ACs", "Files", "Scope", "Verify"] as const;
20
-
21
- export async function assembleBrief(opts: {
22
- slug: string;
23
- workDir: string;
24
- projectRoot: string;
25
- }): Promise<AssembleResult> {
26
- const { slug, workDir, projectRoot } = opts;
27
-
28
- const sf = join(workDir, "workflow-state.json");
29
- if (!existsSync(sf)) {
30
- throw new Error(`workflow-state.json not found at ${sf}`);
31
- }
32
-
33
- const state = JSON.parse(readFileSync(sf, "utf-8"));
34
- const acs: any[] = state.acs || [];
35
-
36
- const contextFiles = deduplicateContextFiles(acs);
37
- const verifyCommands = extractVerifyCommands(acs);
38
- const scopeOut: string[] = state.scopeOut || [];
39
-
40
- const harness = loadProjectHarness(projectRoot);
41
- const projectContextDocs = extractContextDocs(harness);
42
- const hasAgents = existsSync(join(projectRoot, "AGENTS.md"));
43
-
44
- const sections: string[] = [];
45
-
46
- sections.push(buildContextSection(projectRoot));
47
- sections.push(buildSpecAlignment(state.governingSpec));
48
- sections.push(buildTaskSection(state.issueGoal, acs));
49
- if (state.issueType === "bug-fix" || state.issueType === "bug") {
50
- sections.push(buildRCASection(state.rca));
51
- }
52
- sections.push(buildGitProtocol(state.issue));
53
- sections.push(buildFilesSection(contextFiles));
54
- sections.push(buildScopeSection(scopeOut));
55
- sections.push(buildVerifySection(verifyCommands));
56
- sections.push(buildReportSection());
57
-
58
- const brief = sections.join("\n\n");
59
- const briefPath = join(workDir, "marcus-brief.md");
60
- writeFileSync(briefPath, brief);
61
-
62
- const validated = validateBrief(brief);
63
-
64
- const projectContextCount = projectContextDocs.length + (hasAgents ? 1 : 0);
65
-
66
- return {
67
- briefPath,
68
- acCount: acs.length,
69
- contextFileCount: contextFiles.length + projectContextCount,
70
- validated,
71
- };
72
- }
73
-
74
- function deduplicateContextFiles(acs: any[]): Array<{ path: string; reason: string }> {
75
- const seen = new Set<string>();
76
- const result: Array<{ path: string; reason: string }> = [];
77
-
78
- for (const ac of acs) {
79
- for (const cf of ac.contextFiles || []) {
80
- if (!seen.has(cf.path)) {
81
- seen.add(cf.path);
82
- result.push({ path: cf.path, reason: cf.reason || "" });
83
- }
84
- }
85
- }
86
-
87
- return result;
88
- }
89
-
90
- function extractVerifyCommands(acs: any[]): string[] {
91
- const commands: string[] = [];
92
- for (const ac of acs) {
93
- const cmd = ac.evidenceMethod?.command;
94
- if (cmd) commands.push(cmd);
95
- }
96
- return commands;
97
- }
98
-
99
- function loadProjectHarness(projectRoot: string): Record<string, any> | null {
100
- const harnessPath = join(projectRoot, ".claude", "rungate.json");
101
- if (!existsSync(harnessPath)) return null;
102
- try {
103
- return JSON.parse(readFileSync(harnessPath, "utf-8"));
104
- } catch {
105
- return null;
106
- }
107
- }
108
-
109
- function extractContextDocs(harness: Record<string, any> | null): string[] {
110
- if (!harness?.contextDocs) return [];
111
- const docs = harness.contextDocs;
112
- if (Array.isArray(docs)) return docs;
113
- if (typeof docs === "object") return Object.values(docs) as string[];
114
- return [];
115
- }
116
-
117
- function buildContextSection(projectRoot: string): string {
118
- const lines = [
119
- "## Context (read first, in order)",
120
- `1. ${projectRoot}/CLAUDE.md (if exists)`,
121
- `2. ${projectRoot}/MODEL.md (PRIMARY — system flow, three rules, troubleshooting map)`,
122
- `3. ${projectRoot}/PRINCIPLES.md (ONLY if MODEL.md doesn't exist)`,
123
- `4. ${projectRoot}/ARCHITECTURE.md (ONLY if MODEL.md doesn't exist)`,
124
- ];
125
-
126
- let idx = 5;
127
-
128
- // Include AGENTS.md from project repo when present
129
- const agentsPath = join(projectRoot, "AGENTS.md");
130
- if (existsSync(agentsPath)) {
131
- lines.push(`${idx}. ${projectRoot}/AGENTS.md (agent role definitions)`);
132
- idx++;
133
- }
134
-
135
- // Include contextDocs from rungate.json
136
- const harness = loadProjectHarness(projectRoot);
137
- const contextDocs = extractContextDocs(harness);
138
- for (const doc of contextDocs) {
139
- lines.push(`${idx}. ${projectRoot}/${doc}`);
140
- idx++;
141
- }
142
-
143
- return lines.join("\n");
144
- }
145
-
146
- function buildSpecAlignment(governingSpec?: { path: string; detectedFrom?: string }): string {
147
- if (!governingSpec) {
148
- return [
149
- "## Spec Alignment",
150
- "- **Governing spec:** None detected",
151
- "- **Verified no contradiction:** N/A",
152
- ].join("\n");
153
- }
154
-
155
- return [
156
- "## Spec Alignment (MANDATORY)",
157
- `- **Governing spec:** ${governingSpec.path}`,
158
- `- **Detected from:** ${governingSpec.detectedFrom || "unknown"}`,
159
- "- **Verified no contradiction:** DA verified before brief generation",
160
- ].join("\n");
161
- }
162
-
163
- function buildTaskSection(issueGoal: string, acs: any[]): string {
164
- const lines = ["## Task", "", `**Goal:** ${issueGoal}`, ""];
165
-
166
- lines.push("### Acceptance Criteria", "");
167
- if (acs.length === 0) {
168
- lines.push("- (no acceptance criteria defined yet)");
169
- } else {
170
- for (const ac of acs) {
171
- const threshold = ac.threshold
172
- ? ` (${ac.threshold.op} ${ac.threshold.value}${ac.threshold.unit ? " " + ac.threshold.unit : ""})`
173
- : "";
174
- lines.push(`- **${ac.id}** [${ac.type || "CODE"}]: ${ac.statement}${threshold}`);
175
- }
176
- }
177
-
178
- return lines.join("\n");
179
- }
180
-
181
- function buildGitProtocol(issue: number): string {
182
- return [
183
- "## Git protocol",
184
- `- Branch: \`${issue}-deep-modules\` (create from main if not in a worktree)`,
185
- "- Before committing, rebase onto latest main",
186
- "- Commit all changes before reporting back",
187
- "- Push with `-u` before reporting",
188
- "- Never commit to main directly, never force push",
189
- ].join("\n");
190
- }
191
-
192
- function buildFilesSection(contextFiles: Array<{ path: string; reason: string }>): string {
193
- const lines = ["## Files to read before touching anything"];
194
-
195
- if (contextFiles.length === 0) {
196
- lines.push("- (no context files specified)");
197
- } else {
198
- for (const cf of contextFiles) {
199
- lines.push(`- ${cf.path}${cf.reason ? " — " + cf.reason : ""}`);
200
- }
201
- }
202
-
203
- return lines.join("\n");
204
- }
205
-
206
- function buildScopeSection(scopeOut: string[]): string {
207
- const lines = ["## Scope — do NOT touch"];
208
-
209
- if (scopeOut.length === 0) {
210
- lines.push("- (no explicit scope boundaries — stay within task scope)");
211
- } else {
212
- for (const item of scopeOut) {
213
- lines.push(`- ${item}`);
214
- }
215
- }
216
-
217
- lines.push("- Never run `make rebuild` — DA does that");
218
-
219
- return lines.join("\n");
220
- }
221
-
222
- function buildVerifySection(commands: string[]): string {
223
- const lines = ["## Verify"];
224
-
225
- if (commands.length === 0) {
226
- lines.push("- `bunx tsc --noEmit`");
227
- } else {
228
- for (const cmd of commands) {
229
- lines.push(`- \`${cmd}\``);
230
- }
231
- lines.push("- `bunx tsc --noEmit`");
232
- }
233
-
234
- return lines.join("\n");
235
- }
236
-
237
- function buildRCASection(rca?: { rootCause?: string; prediction?: string; predictionVerified?: boolean }): string {
238
- return [
239
- "## Root Cause Analysis (bug-fix)",
240
- `- **Root cause:** ${rca?.rootCause || "(investigate and fill)"}`,
241
- `- **Prediction:** ${rca?.prediction || "(what will the fix change?)"}`,
242
- `- **Prediction verified:** ${rca?.predictionVerified ?? "(verify after fix)"}`,
243
- ].join("\n");
244
- }
245
-
246
- export interface JourneyStep {
247
- action: string;
248
- wait_for?: string;
249
- assertion?: { type: string; target?: string; expected?: string };
250
- on_fail?: string;
251
- }
252
-
253
- export const MAX_JOURNEY_STEPS = 8;
254
-
255
- export function validateJourneySteps(steps: JourneyStep[]): { valid: boolean; splitRequired: boolean } {
256
- if (steps.length <= MAX_JOURNEY_STEPS) return { valid: true, splitRequired: false };
257
- return { valid: false, splitRequired: true };
258
- }
259
-
260
- export function splitJourney(steps: JourneyStep[]): JourneyStep[][] {
261
- const chunks: JourneyStep[][] = [];
262
- for (let i = 0; i < steps.length; i += MAX_JOURNEY_STEPS) {
263
- chunks.push(steps.slice(i, i + MAX_JOURNEY_STEPS));
264
- }
265
- return chunks;
266
- }
267
-
268
- function buildReportSection(): string {
269
- return [
270
- "## Report back",
271
- "For each acceptance criterion, provide evidence:",
272
- "- AC-N: → file.ts:L## [description] (code presence)",
273
- "- AC-N: → grep: \"pattern\" returned N matches (absence/presence)",
274
- "- AC-N: → test: test-name PASS (test-verified)",
275
- "Plus: files changed (paths + line numbers), test output, scope conflicts",
276
- ].join("\n");
277
- }
278
-
279
- function validateBrief(brief: string): boolean {
280
- let policies: any = null;
281
- if (existsSync(BRIEF_POLICIES_PATH)) {
282
- try {
283
- policies = JSON.parse(readFileSync(BRIEF_POLICIES_PATH, "utf-8"));
284
- } catch {
285
- // If policies can't be read, skip validation
286
- }
287
- }
288
-
289
- if (!policies?.policies?.marcus?.requiredPatterns) {
290
- // Fallback: check for required section headers
291
- for (const section of REQUIRED_SECTIONS) {
292
- const patterns: Record<string, RegExp> = {
293
- Goal: /(?:goal|objective|task)/i,
294
- ACs: /(?:acceptance criter|AC-|success criter)/i,
295
- Files: /(?:files to|files changed|file.*read)/i,
296
- Scope: /(?:scope.*not|do not touch|out of scope)/i,
297
- Verify: /(?:verify|verification)/i,
298
- };
299
- if (!patterns[section]?.test(brief)) return false;
300
- }
301
- return true;
302
- }
303
-
304
- for (const pattern of policies.policies.marcus.requiredPatterns) {
305
- let p = pattern.pattern as string;
306
- let flags = "";
307
- if (p.startsWith("(?i)")) {
308
- p = p.slice(4);
309
- flags = "i";
310
- }
311
- const re = new RegExp(p, flags);
312
- if (!re.test(brief)) return false;
313
- }
314
-
315
- return true;
316
- }
317
-
318
- // CLI entry point
319
- if (import.meta.main) {
320
- const args = process.argv.slice(2);
321
- let slug = "", workDir = "", projectRoot = "";
322
- for (let i = 0; i < args.length; i++) {
323
- if (args[i] === "--slug" && args[i + 1]) slug = args[++i];
324
- if (args[i] === "--work-dir" && args[i + 1]) workDir = args[++i];
325
- if (args[i] === "--project-root" && args[i + 1]) projectRoot = args[++i];
326
- }
327
- if (!slug || !workDir || !projectRoot) {
328
- console.error("Usage: bun run brief-assembler.ts --slug SLUG --work-dir DIR --project-root DIR");
329
- process.exit(1);
330
- }
331
- assembleBrief({ slug, workDir, projectRoot })
332
- .then(r => console.log(`Brief written: ${r.briefPath} (${r.acCount} ACs, validated=${r.validated})`))
333
- .catch(e => { console.error(e.message); process.exit(1); });
334
- }
package/gates/bunfig.toml DELETED
@@ -1,2 +0,0 @@
1
- [test]
2
- preload = ["./preload.ts"]
@@ -1,91 +0,0 @@
1
- import { test, expect, describe } from "bun:test";
2
- import { readFileSync, existsSync } from "fs";
3
- import { GoalRecordSchema, ShipEvidenceSchema, ProveEvidenceSchema } from "./schema";
4
-
5
- const TEST_DIR = process.env.TEST_WORK_DIR || "";
6
-
7
- function tryRead(filename: string) {
8
- const path = `${TEST_DIR}/${filename}`;
9
- if (!existsSync(path)) return null;
10
- return JSON.parse(readFileSync(path, "utf-8"));
11
- }
12
-
13
- describe("chain: goal → ship → prove artifacts", () => {
14
- test("goal-record.json validates if present", () => {
15
- const data = tryRead("goal-record.json");
16
- if (!data) return;
17
- const result = GoalRecordSchema.safeParse(data);
18
- if (!result.success) {
19
- const issues = result.error.issues.map(i => `${i.path.join(".")}: ${i.message}`);
20
- expect(issues).toEqual([]);
21
- }
22
- });
23
-
24
- test("goal-record has non-empty success criteria", () => {
25
- const data = tryRead("goal-record.json");
26
- if (!data) return;
27
- expect(data.successCriteria.length).toBeGreaterThan(0);
28
- });
29
-
30
- test("goal-record SCs all have thresholds", () => {
31
- const data = tryRead("goal-record.json");
32
- if (!data) return;
33
- const missing = data.successCriteria.filter((sc: any) => !sc.threshold);
34
- expect(missing.map((sc: any) => sc.id)).toEqual([]);
35
- });
36
-
37
- test("ship-evidence.json validates if present", () => {
38
- const data = tryRead("ship-evidence.json");
39
- if (!data) return;
40
- const result = ShipEvidenceSchema.safeParse(data);
41
- if (!result.success) {
42
- const issues = result.error.issues.map(i => `${i.path.join(".")}: ${i.message}`);
43
- expect(issues).toEqual([]);
44
- }
45
- });
46
-
47
- test("ship-evidence has no FAIL results when status is PASS", () => {
48
- const data = tryRead("ship-evidence.json");
49
- if (!data || data.gateOut.status !== "PASS") return;
50
- const fails = data.gateOut.evidence.filter((e: any) => e.result === "FAIL");
51
- expect(fails.map((e: any) => e.criterion)).toEqual([]);
52
- });
53
-
54
- test("prove-evidence.json validates if present", () => {
55
- const data = tryRead("prove-evidence.json");
56
- if (!data) return;
57
- const result = ProveEvidenceSchema.safeParse(data);
58
- if (!result.success) {
59
- const issues = result.error.issues.map(i => `${i.path.join(".")}: ${i.message}`);
60
- expect(issues).toEqual([]);
61
- }
62
- });
63
-
64
- test("prove verdict consistent with before/after evidence", () => {
65
- const data = tryRead("prove-evidence.json");
66
- if (!data) return;
67
- if (data.verdict === "PROVEN") {
68
- expect(data.afterEvidence.description.length).toBeGreaterThan(0);
69
- expect(data.comparisonSummary.length).toBeGreaterThan(0);
70
- }
71
- });
72
-
73
- test("prove PROVEN has no unresolved gaps", () => {
74
- const data = tryRead("prove-evidence.json");
75
- if (!data || data.verdict !== "PROVEN") return;
76
- const unresolved = (data.gaps || []).filter((g: any) => g.status === "UNPROVEN");
77
- expect(unresolved.map((g: any) => g.ac)).toEqual([]);
78
- });
79
-
80
- test("chain consistency: issue numbers match across artifacts", () => {
81
- const goal = tryRead("goal-record.json");
82
- const ship = tryRead("ship-evidence.json");
83
- const prove = tryRead("prove-evidence.json");
84
- if (!goal || !ship) return;
85
- const goalNum = parseInt(goal.id.replace("issue-", ""));
86
- expect(ship.issueNumber).toBe(goalNum);
87
- if (prove) {
88
- expect(prove.issueNumber).toBe(goalNum);
89
- }
90
- });
91
- });
@@ -1,234 +0,0 @@
1
- import { test, expect, describe } from "bun:test";
2
- import { readFileSync, existsSync } from "fs";
3
- import { join } from "path";
4
- import { WorkflowStateSchema } from "./schema";
5
- import { SIGNAL_PHRASE_PATTERNS } from "../lib/conformity";
6
-
7
- const STANDALONE = !process.env.TEST_WORK_DIR;
8
- const TEST_DIR = process.env.TEST_WORK_DIR || "/tmp/gate-e2e-smoke";
9
- const SF = `${TEST_DIR}/workflow-state.json`;
10
-
11
- function loadState(): any | null {
12
- if (!existsSync(SF)) return null;
13
- const raw = JSON.parse(readFileSync(SF, "utf-8"));
14
- return WorkflowStateSchema.passthrough().parse(raw);
15
- }
16
-
17
- function sf(path: string): any {
18
- if (!existsSync(SF)) return undefined;
19
- const wf = JSON.parse(readFileSync(SF, "utf-8"));
20
- const parts = path.replace(/^\./, "").split(".").filter(Boolean);
21
- let val: any = wf;
22
- for (const p of parts) {
23
- if (val == null) return undefined;
24
- val = val[p];
25
- }
26
- return val;
27
- }
28
-
29
- function loadSpec(path: string, projectRoot?: string): string {
30
- const resolved = path.startsWith('/') ? path : join(projectRoot || '.', path);
31
- return readFileSync(resolved, "utf-8");
32
- }
33
-
34
- function extractSpecRules(spec: string): string[] {
35
- const rules: string[] = [];
36
- for (const p of SIGNAL_PHRASE_PATTERNS) {
37
- for (const m of spec.matchAll(new RegExp(p.source, p.flags))) {
38
- rules.push(m[0].replace(/^[-*] /, "").trim().replace(/[.;]$/, ""));
39
- }
40
- }
41
- return [...new Set(rules)];
42
- }
43
-
44
- describe("E2E: governing spec compliance", () => {
45
- if (STANDALONE || !existsSync(SF)) {
46
- test("skipped — no active workflow (standalone run)", () => {});
47
- return;
48
- }
49
- const tier = sf("sizing")?.ceremonyTier;
50
- if (tier === "LIGHT") {
51
- test("skipped — spec checks not required for LIGHT tier", () => {});
52
- return;
53
- }
54
-
55
- test("governing spec exists and is readable", () => {
56
- const wf = loadState() as any;
57
- expect(wf.sourceSpecs?.[0]?.path).toBeDefined();
58
- const specPath = wf.sourceSpecs[0].path.startsWith('/') ? wf.sourceSpecs[0].path : join(wf.projectRoot || '.', wf.sourceSpecs[0].path);
59
- expect(existsSync(specPath)).toBe(true);
60
- });
61
-
62
- test("spec has extractable rules", () => {
63
- const wf = loadState() as any;
64
- const spec = loadSpec(wf.sourceSpecs[0].path, wf.projectRoot);
65
- const rules = extractSpecRules(spec);
66
- expect(rules.length).toBeGreaterThan(0);
67
- });
68
- });
69
-
70
- describe("E2E: hardcoded values violate spec", () => {
71
- if (STANDALONE || !existsSync(SF)) {
72
- test("skipped — no active workflow (standalone run)", () => {});
73
- return;
74
- }
75
- const tier = sf("sizing")?.ceremonyTier;
76
- if (tier === "LIGHT") {
77
- test("skipped — spec checks not required for LIGHT tier", () => {});
78
- return;
79
- }
80
-
81
- test("no hardcoded paths in AC statements", () => {
82
- const wf = loadState() as any;
83
- const spec = loadSpec(wf.sourceSpecs[0].path, wf.projectRoot);
84
-
85
- if (!spec.match(/never hardcod|read from config|configurable/i)) return;
86
-
87
- const hardcodedPath = /\/usr\/|\/opt\/|\/home\/|\/tmp\/[a-z]/i;
88
- const hardcodedPort = /\bport\s+\d{4}\b/i;
89
- const hits = wf.acs.filter((ac: any) =>
90
- hardcodedPath.test(ac.statement) || hardcodedPort.test(ac.statement)
91
- );
92
-
93
- expect(hits.map((ac: any) => `${ac.id}: ${ac.statement}`)).toEqual([]);
94
- });
95
-
96
- test("no hardcoded numeric thresholds in AC statements", () => {
97
- const wf = loadState() as any;
98
- const spec = loadSpec(wf.sourceSpecs[0].path, wf.projectRoot);
99
-
100
- if (!spec.match(/configurable|environment variable|config/i)) return;
101
-
102
- const hardcodedNum = /\bhardcoded to \d+\.?\d*\b/i;
103
- const hits = wf.acs.filter((ac: any) => hardcodedNum.test(ac.statement));
104
-
105
- expect(hits.map((ac: any) => `${ac.id}: ${ac.statement}`)).toEqual([]);
106
- });
107
- });
108
-
109
- describe("E2E: behavioral language violates spec", () => {
110
- if (STANDALONE || !existsSync(SF)) {
111
- test("skipped — no active workflow (standalone run)", () => {});
112
- return;
113
- }
114
- test("no 'DA should' or behavioral delegation in ACs", () => {
115
- const wf = loadState() as any;
116
- if (!wf) return;
117
- const behavioral = /\b(DA should|remember to|make sure|don't forget)\b/i;
118
- const hits = wf.acs.filter((ac: any) => behavioral.test(ac.statement));
119
-
120
- expect(hits.map((ac: any) => `${ac.id}: ${ac.statement}`)).toEqual([]);
121
- });
122
- });
123
-
124
- describe("E2E: spec-prohibited patterns in ACs", () => {
125
- if (STANDALONE || !existsSync(SF)) {
126
- test("skipped — no active workflow (standalone run)", () => {});
127
- return;
128
- }
129
- const tier = sf("sizing")?.ceremonyTier;
130
- if (tier === "LIGHT") {
131
- test("skipped — spec checks not required for LIGHT tier", () => {});
132
- return;
133
- }
134
-
135
- test("no setTimeout when spec says use backoff", () => {
136
- const wf = loadState() as any;
137
- const spec = loadSpec(wf.sourceSpecs[0].path, wf.projectRoot);
138
-
139
- if (!spec.match(/not use setTimeout|exponential backoff/i)) return;
140
-
141
- const hits = wf.acs.filter((ac: any) =>
142
- /setTimeout/i.test(ac.statement) || /setTimeout/i.test(ac.evidenceMethod?.command || "")
143
- );
144
-
145
- expect(hits.map((ac: any) => `${ac.id}: ${ac.statement}`)).toEqual([]);
146
- });
147
-
148
- test("no stdout/console.log when spec says use logger", () => {
149
- const wf = loadState() as any;
150
- const spec = loadSpec(wf.sourceSpecs[0].path, wf.projectRoot);
151
-
152
- if (!spec.match(/not write directly to stdout|use the logger/i)) return;
153
-
154
- const hits = wf.acs.filter((ac: any) =>
155
- /console\.log|stdout|directly/i.test(ac.statement)
156
- );
157
-
158
- expect(hits.map((ac: any) => `${ac.id}: ${ac.statement}`)).toEqual([]);
159
- });
160
-
161
- test("no string error handling when spec says use typed errors", () => {
162
- const wf = loadState() as any;
163
- const spec = loadSpec(wf.sourceSpecs[0].path, wf.projectRoot);
164
-
165
- if (!spec.match(/structured error|typed error|never raw string/i)) return;
166
-
167
- const hits = wf.acs.filter((ac: any) =>
168
- /string message|raw.*throw|catch.*string/i.test(ac.statement)
169
- );
170
-
171
- expect(hits.map((ac: any) => `${ac.id}: ${ac.statement}`)).toEqual([]);
172
- });
173
- });
174
-
175
- describe("E2E: Marcus brief cites governing spec", () => {
176
- if (STANDALONE || !existsSync(SF)) {
177
- test("skipped — no active workflow (standalone run)", () => {});
178
- return;
179
- }
180
- const tier = sf("sizing")?.ceremonyTier;
181
- if (tier === "LIGHT") {
182
- test("skipped — spec checks not required for LIGHT tier", () => {});
183
- return;
184
- }
185
-
186
- test("brief references spec constraints", () => {
187
- const wf = loadState() as any;
188
- if (!wf.sourceSpecs?.[0]?.path || !wf.agents?.marcus?.brief) return;
189
-
190
- const spec = loadSpec(wf.sourceSpecs[0].path, wf.projectRoot);
191
- const rules = extractSpecRules(spec);
192
- const brief = wf.agents.marcus.brief.toLowerCase();
193
-
194
- const cited = rules.filter(r =>
195
- brief.includes(r.slice(0, 25).toLowerCase())
196
- );
197
-
198
- expect(cited.length).toBeGreaterThanOrEqual(
199
- Math.min(3, rules.length)
200
- );
201
- });
202
- });
203
-
204
- // ═══ ADR-008 MIGRATION COMPLETENESS ════════════════════════════════════
205
-
206
- describe("E2E: ADR-008 migration", () => {
207
- test("ADR-008 'What to delete' files are actually deleted", () => {
208
- const adrPath = join(process.env.HOME || "", ".claude", "PAI", "ADR", "ADR-008-harness-v3-bun-tests-migration.md");
209
- if (!existsSync(adrPath)) return;
210
- const adr = readFileSync(adrPath, "utf-8");
211
-
212
- const deletionTargets = [
213
- "skills/ship/gate-runner.sh",
214
- "skills/ship/gate-checks.sh",
215
- ];
216
-
217
- const existing = deletionTargets.filter(f =>
218
- existsSync(join(process.env.HOME || "", ".claude", f))
219
- );
220
- expect(existing).toEqual([]);
221
- });
222
-
223
- test("stop-the-bleeding: no .sh files in skills/ship/", () => {
224
- const { execSync } = require("child_process");
225
- const shipDir = join(process.env.HOME || "", ".claude", "skills", "ship");
226
- try {
227
- const result = execSync(`find "${shipDir}" -name '*.sh'`, { encoding: "utf-8", timeout: 5000 }).trim();
228
- const files = result ? result.split("\n").filter(Boolean) : [];
229
- expect(files).toEqual([]);
230
- } catch {
231
- // find command failed — skip
232
- }
233
- });
234
- });