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,197 +0,0 @@
1
- import { test, expect, describe } from "bun:test";
2
- import { readFileSync } from "fs";
3
- import { join } from "path";
4
- import { THRESHOLD_OPS, EVIDENCE_METHOD_TYPES } from "./schema";
5
- import { parseTestResults } from "./run-gate";
6
-
7
- const GATES_DIR = __dirname;
8
- const V2_SCHEMA_PATH = join(GATES_DIR, "..", "config", "workflow-schema.json");
9
- const V3_SCHEMA_PATH = join(GATES_DIR, "schema.ts");
10
-
11
- function extractJsonSchemaPaths(obj: any, prefix = ""): string[] {
12
- const paths: string[] = [];
13
- if (!obj || typeof obj !== "object") return paths;
14
-
15
- if (obj.properties) {
16
- for (const [key, val] of Object.entries(obj.properties)) {
17
- const path = prefix ? `${prefix}.${key}` : key;
18
- paths.push(path);
19
- if ((val as any).properties) {
20
- paths.push(...extractJsonSchemaPaths(val, path));
21
- }
22
- if ((val as any).items?.properties) {
23
- paths.push(...extractJsonSchemaPaths((val as any).items, `${path}[]`));
24
- }
25
- }
26
- }
27
- return paths;
28
- }
29
-
30
- function extractZodFields(source: string): string[] {
31
- const fields: string[] = [];
32
- const patterns = [
33
- /(\w+):\s*z\./g,
34
- /(\w+):\s*(?:Agent|Environment|GateResult|SourceSpec|Threshold|EvidenceMethod|Evidence|ContextFile|Changelog|PhaseTiming)/g,
35
- ];
36
- for (const p of patterns) {
37
- for (const m of source.matchAll(p)) {
38
- fields.push(m[1]);
39
- }
40
- }
41
- return [...new Set(fields)];
42
- }
43
-
44
- describe("schema parity: v2 JSON Schema vs v3 Zod", () => {
45
- const v2 = JSON.parse(readFileSync(V2_SCHEMA_PATH, "utf-8"));
46
- const v3Source = readFileSync(V3_SCHEMA_PATH, "utf-8");
47
-
48
- const v2Paths = extractJsonSchemaPaths(v2);
49
- const v3Fields = extractZodFields(v3Source);
50
-
51
- const V2_TOP_LEVEL = [
52
- "schemaVersion", "issue", "repo", "issueRepo", "projectRoot", "slug", "phase",
53
- "issueGoal", "sourceSpecs", "sizing", "acs", "agents", "environments", "gates",
54
- "daDirectEdits", "iterationCount", "startTs", "updatedTs", "phaseTimings",
55
- "gateContract", "changelog",
56
- ];
57
-
58
- for (const field of V2_TOP_LEVEL) {
59
- test(`v2 top-level field "${field}" exists in v3 Zod schema`, () => {
60
- expect(v3Source).toContain(field);
61
- });
62
- }
63
-
64
- const V2_SIZING = ["predicted", "ceremonyTier", "actualFiles", "actualMinutes"];
65
- for (const field of V2_SIZING) {
66
- test(`v2 sizing.${field} exists in v3`, () => {
67
- expect(v3Source).toContain(field);
68
- });
69
- }
70
-
71
- const V2_AC_FIELDS = ["id", "type", "statement", "specElement", "threshold", "evidenceMethod", "contextFiles", "evidence", "verdict"];
72
- for (const field of V2_AC_FIELDS) {
73
- test(`v2 acs[].${field} exists in v3 ACSchema`, () => {
74
- expect(v3Source).toContain(field);
75
- });
76
- }
77
-
78
- const V2_AGENT_FIELDS = ["spawned", "verdict", "branch", "iterations", "comparedToSpec", "screenshots", "findings"];
79
- for (const field of V2_AGENT_FIELDS) {
80
- test(`v2 agents.*.${field} exists in v3 AgentSchema`, () => {
81
- expect(v3Source).toContain(field);
82
- });
83
- }
84
-
85
- const V2_ENV_LOCAL = ["api", "apiSkipReason", "ui", "uiSkipReason", "tests"];
86
- for (const field of V2_ENV_LOCAL) {
87
- test(`v2 environments.local.${field} exists in v3`, () => {
88
- expect(v3Source).toContain(field);
89
- });
90
- }
91
-
92
- const V2_ENV_PROD = ["rebuild", "rebuildSkipReason", "smoke", "smokeSkipReason", "quinn", "quinnSkipReason", "quinnSpot", "quinnSpotSkipReason"];
93
- for (const field of V2_ENV_PROD) {
94
- test(`v2 environments.prod.${field} exists in v3`, () => {
95
- expect(v3Source).toContain(field);
96
- });
97
- }
98
-
99
- const V2_GATE = ["result", "attempt", "failures", "ts"];
100
- for (const field of V2_GATE) {
101
- test(`v2 gates.*.${field} exists in v3 GateResultSchema`, () => {
102
- expect(v3Source).toContain(field);
103
- });
104
- }
105
-
106
- const V2_EVIDENCE_METHOD_TYPES = ["GREP_CHECK", "FILE_EXISTS", "CURL_CHECK", "BUN_TEST", "SCREENSHOT", "PLAYWRIGHT", "COMMAND", "MANUAL"];
107
- for (const t of V2_EVIDENCE_METHOD_TYPES) {
108
- test(`v2 evidenceMethod.type "${t}" in v3 enum`, () => {
109
- expect(v3Source).toContain(t);
110
- });
111
- }
112
-
113
- const V2_THRESHOLD_OPS = ["==", ">=", "<=", ">", "<", "!=", "contains", "exists"];
114
- for (const op of V2_THRESHOLD_OPS) {
115
- test(`v2 threshold.op "${op}" in v3 enum`, () => {
116
- expect(v3Source).toContain(`"${op}"`);
117
- });
118
- }
119
-
120
- test("v2 phase CIRCUIT_BREAK in v3 enum", () => {
121
- expect(v3Source).toContain("CIRCUIT_BREAK");
122
- });
123
-
124
- test("v2 verdict PENDING in v3 ACSchema", () => {
125
- expect(v3Source).toContain("PENDING");
126
- });
127
-
128
- const V2_BASELINES = ["testBaseline", "tscBaseline"];
129
- for (const field of V2_BASELINES) {
130
- test(`v2 gateContract.baselines.${field} exists in v3`, () => {
131
- expect(v3Source).toContain(field);
132
- });
133
- }
134
-
135
- const V2_CHANGELOG = ["event", "detail", "actor"];
136
- for (const field of V2_CHANGELOG) {
137
- test(`v2 changelog[].${field} exists in v3`, () => {
138
- expect(v3Source).toContain(field);
139
- });
140
- }
141
-
142
- test("v2 phaseTimings entry fields in v3", () => {
143
- expect(v3Source).toContain("enteredTs");
144
- expect(v3Source).toContain("exitedTs");
145
- expect(v3Source).toContain("iteration");
146
- });
147
- });
148
-
149
- describe("GI-1: gate failure detail includes Zod error paths", () => {
150
- test("parseTestResults captures lines after (fail) as detail", () => {
151
- const bunOutput = [
152
- "(pass) schema validation > acs-exist: at least one AC",
153
- "(fail) schema validation > workflow-state.json validates (includes threshold + behavioral superRefine)",
154
- " acs.0.threshold.op: Invalid enum value. Expected '==' | '>=' | '<=' | '>' | '<' | '!=' | 'contains' | 'exists', received 'equals'",
155
- " acs.1.statement: AC-2: statement too short (3 words, min 5)",
156
- "(pass) scope checks > sizing-declared",
157
- ].join("\n");
158
- const results = parseTestResults(bunOutput);
159
- const fail = results.find(r => r.result === "FAIL");
160
- expect(fail).toBeTruthy();
161
- expect(fail!.detail).toContain("Invalid enum value");
162
- expect(fail!.detail).toContain("acs.0.threshold.op");
163
- expect(fail!.detail).not.toBe("failed");
164
- });
165
-
166
- test("parseTestResults falls back to 'failed' when no detail lines follow (fail)", () => {
167
- const bunOutput = [
168
- "(fail) some-check",
169
- "(pass) another-check",
170
- ].join("\n");
171
- const results = parseTestResults(bunOutput);
172
- const fail = results.find(r => r.result === "FAIL");
173
- expect(fail!.detail).toBe("failed");
174
- });
175
- });
176
-
177
- describe("GI-5: DISCOVERY_SCHEMA enum parity with schema.ts", () => {
178
- const shipSource = readFileSync(join(GATES_DIR, "..", "workflows", "ship.js"), "utf-8");
179
-
180
- test("DISCOVERY_SCHEMA threshold.op has enum matching THRESHOLD_OPS", () => {
181
- const opEnumMatch = shipSource.match(/op:\s*\{\s*type:\s*'string'\s*,\s*enum:\s*\[([^\]]+)\]/);
182
- expect(opEnumMatch, "threshold.op must have enum constraint in DISCOVERY_SCHEMA").toBeTruthy();
183
- const ops = opEnumMatch![1].split(",").map(s => s.trim().replace(/'/g, ""));
184
- expect(ops.sort()).toEqual([...THRESHOLD_OPS].sort());
185
- });
186
-
187
- test("DISCOVERY_SCHEMA evidenceMethod.type has enum matching EVIDENCE_METHOD_TYPES", () => {
188
- const discoveryBlock = shipSource.slice(
189
- shipSource.indexOf("const DISCOVERY_SCHEMA"),
190
- shipSource.indexOf("const DISCOVERY_SCHEMA") + 3000
191
- );
192
- const evidenceMethodMatch = discoveryBlock.match(/evidenceMethod:\s*\{[^}]*properties:\s*\{[^}]*type:\s*\{\s*type:\s*'string'\s*,\s*enum:\s*\[([^\]]+)\]/s);
193
- expect(evidenceMethodMatch, "evidenceMethod.type must have enum constraint in DISCOVERY_SCHEMA").toBeTruthy();
194
- const types = evidenceMethodMatch![1].split(",").map(s => s.trim().replace(/'/g, ""));
195
- expect(types.sort()).toEqual([...EVIDENCE_METHOD_TYPES].sort());
196
- });
197
- });
package/gates/schema.ts DELETED
@@ -1,362 +0,0 @@
1
- import { z } from "zod";
2
-
3
- const BEHAVIORAL_PATTERN = /\b(DA should|remember to|make sure to|don't forget)\b/i;
4
-
5
- const GARBAGE_PATTERNS = [
6
- /^file exists?$/i,
7
- /^it works?$/i,
8
- /^code is (?:correct|good|done|working)$/i,
9
- /^(?:the )?(?:feature|function|code|system) (?:works?|exists?|is (?:done|complete))$/i,
10
- /^no errors?$/i,
11
- /^tests? pass(?:es)?$/i,
12
- /^changes? (?:are )?(?:made|applied|done)$/i,
13
- ];
14
-
15
- export const THRESHOLD_OPS = ["==", ">=", "<=", ">", "<", "!=", "contains", "exists"] as const;
16
- export const EVIDENCE_METHOD_TYPES = ["GREP_CHECK", "FILE_EXISTS", "CURL_CHECK", "BUN_TEST", "SCREENSHOT", "PLAYWRIGHT", "COMMAND", "MANUAL", "grep", "command", "api", "screenshot", "manual"] as const;
17
-
18
- export const ThresholdSchema = z.object({
19
- op: z.enum(THRESHOLD_OPS),
20
- value: z.union([z.string(), z.number()]),
21
- unit: z.string().optional(),
22
- });
23
-
24
- export const EvidenceMethodSchema = z.object({
25
- type: z.enum(EVIDENCE_METHOD_TYPES),
26
- command: z.string().optional(),
27
- });
28
-
29
- export const EvidenceSchema = z.object({
30
- type: z.enum(["file-citation", "grep-output", "api-response", "screenshot", "test-output", "command-output", "manual-attestation"]),
31
- content: z.string().optional(),
32
- value: z.number().nullable().optional(),
33
- url: z.string().nullable().optional(),
34
- }).nullable().optional();
35
-
36
- export const ContextFileSchema = z.object({
37
- path: z.string(),
38
- lines: z.string().optional(),
39
- reason: z.string().optional(),
40
- });
41
-
42
- export const ACSchema = z.object({
43
- id: z.string(),
44
- type: z.enum(["CODE", "OUTCOME"]).optional(),
45
- statement: z.string(),
46
- specElement: z.string().optional(),
47
- threshold: ThresholdSchema.optional(),
48
- evidenceMethod: EvidenceMethodSchema.optional(),
49
- contextFiles: z.array(ContextFileSchema).optional(),
50
- evidence: EvidenceSchema,
51
- verdict: z.enum(["PENDING", "PASS", "FAIL", "SKIP"]).optional(),
52
- }).superRefine((ac, ctx) => {
53
- if (!ac.threshold) {
54
- ctx.addIssue({ code: z.ZodIssueCode.custom, message: `${ac.id}: missing threshold`, path: ["threshold"] });
55
- }
56
- if (BEHAVIORAL_PATTERN.test(ac.statement)) {
57
- ctx.addIssue({ code: z.ZodIssueCode.custom, message: `${ac.id}: behavioral language "${ac.statement.match(BEHAVIORAL_PATTERN)?.[0]}"`, path: ["statement"] });
58
- }
59
- // Heuristic: minimum statement length (5 words)
60
- const words = ac.statement.split(/\s+/).filter(Boolean);
61
- if (words.length < 5) {
62
- ctx.addIssue({
63
- code: z.ZodIssueCode.custom,
64
- message: `${ac.id}: statement too short (${words.length} words, min 5)`,
65
- path: ["statement"],
66
- });
67
- }
68
- // Heuristic: garbage/tautological statement detection
69
- for (const pattern of GARBAGE_PATTERNS) {
70
- if (pattern.test(ac.statement.trim())) {
71
- ctx.addIssue({
72
- code: z.ZodIssueCode.custom,
73
- message: `${ac.id}: tautological/garbage statement "${ac.statement}"`,
74
- path: ["statement"],
75
- });
76
- break;
77
- }
78
- }
79
- // Heuristic: weak threshold detection
80
- if (ac.threshold) {
81
- const numVal = Number(ac.threshold.value);
82
- if (ac.threshold.op === ">=" && !isNaN(numVal) && numVal <= 1) {
83
- ctx.addIssue({
84
- code: z.ZodIssueCode.custom,
85
- message: `${ac.id}: threshold too weak (${ac.threshold.op} ${ac.threshold.value}) — effectively always passes`,
86
- path: ["threshold"],
87
- });
88
- }
89
- }
90
- });
91
-
92
- export const SourceSpecSchema = z.object({
93
- path: z.string(),
94
- citedInDiscovery: z.boolean(),
95
- specElements: z.array(z.string()).optional(),
96
- });
97
-
98
- export const AgentSchema = z.object({
99
- spawned: z.boolean().optional(),
100
- verdict: z.enum(["PASS", "FAIL", "SKIP"]).nullable().optional(),
101
- branch: z.string().optional(),
102
- iterations: z.number().optional(),
103
- comparedToSpec: z.boolean().optional(),
104
- screenshots: z.array(z.string()).optional(),
105
- findings: z.string().nullable().optional(),
106
- testedSha: z.string().optional(),
107
- testedPaths: z.array(z.string()).optional(),
108
- port: z.number().optional(),
109
- }).optional();
110
-
111
- export const EnvironmentLocalSchema = z.object({
112
- api: z.enum(["PASS", "FAIL", "SKIP"]).nullable().optional(),
113
- apiSkipReason: z.string().optional(),
114
- ui: z.enum(["PASS", "FAIL", "SKIP"]).nullable().optional(),
115
- uiSkipReason: z.string().optional(),
116
- tests: z.enum(["PASS", "FAIL", "SKIP"]).nullable().optional(),
117
- quinn: z.object({
118
- port: z.number().optional(),
119
- }).optional(),
120
- }).optional();
121
-
122
- export const EnvironmentProdSchema = z.object({
123
- rebuild: z.enum(["PASS", "FAIL", "SKIP"]).nullable().optional(),
124
- rebuildSkipReason: z.string().nullable().optional(),
125
- smoke: z.enum(["PASS", "FAIL", "SKIP"]).nullable().optional(),
126
- smokeSkipReason: z.string().nullable().optional(),
127
- quinn: z.enum(["PASS", "FAIL", "SKIP"]).nullable().optional(),
128
- quinnSkipReason: z.string().nullable().optional(),
129
- quinnSpot: z.enum(["PASS", "FAIL", "SKIP"]).nullable().optional(),
130
- quinnSpotSkipReason: z.string().optional(),
131
- }).optional();
132
-
133
- export const GateResultSchema = z.object({
134
- result: z.enum(["PASS", "FAIL"]).nullable().optional(),
135
- attempt: z.number().optional(),
136
- failures: z.array(z.any()).optional(),
137
- ts: z.string().optional(),
138
- commitSha: z.string().optional(),
139
- }).optional();
140
-
141
- export const PhaseTimingEntry = z.object({
142
- enteredTs: z.string(),
143
- exitedTs: z.string().optional(),
144
- iteration: z.number().optional(),
145
- source: z.enum(["gate-runner", "DA"]),
146
- });
147
-
148
- export const ChangelogEntry = z.object({
149
- ts: z.string(),
150
- event: z.string(),
151
- detail: z.string().optional(),
152
- phase: z.string().optional(),
153
- actor: z.enum(["da", "marcus", "quinn", "rook", "gate-runner", "ship-workflow"]).optional(),
154
- });
155
-
156
- export const WorkflowStateSchema = z.object({
157
- schemaVersion: z.literal(2),
158
- issue: z.number(),
159
- repo: z.string().optional(),
160
- issueRepo: z.string().optional(),
161
- projectRoot: z.string().optional(),
162
- slug: z.string(),
163
- phase: z.enum(["GOAL", "DISCOVERY", "SCOPE", "BUILD", "VERIFY", "SHIP", "DONE", "CIRCUIT_BREAK"]),
164
- issueGoal: z.string().min(1, "issueGoal cannot be empty"),
165
-
166
- sourceSpecs: z.array(SourceSpecSchema).optional(),
167
-
168
- sizing: z.object({
169
- predicted: z.enum(["XS", "S", "M", "L"]).optional(),
170
- ceremonyTier: z.enum(["LIGHT", "STANDARD", "THOROUGH"]).optional(),
171
- actualFiles: z.number().optional(),
172
- actualMinutes: z.number().optional(),
173
- }).optional(),
174
-
175
- acs: z.array(ACSchema),
176
-
177
- governingSpec: z.object({
178
- path: z.string(),
179
- detectedFrom: z.string().optional(),
180
- }).optional(),
181
-
182
- agents: z.object({
183
- marcus: AgentSchema,
184
- quinn: AgentSchema,
185
- rook: AgentSchema,
186
- }).optional(),
187
-
188
- environments: z.object({
189
- local: EnvironmentLocalSchema,
190
- prod: EnvironmentProdSchema,
191
- }).optional(),
192
-
193
- gates: z.object({
194
- scope: GateResultSchema,
195
- verify: GateResultSchema,
196
- ship: GateResultSchema,
197
- }).optional(),
198
-
199
- daDirectEdits: z.number().optional(),
200
- iterationCount: z.number().optional(),
201
- startTs: z.string().optional(),
202
- updatedTs: z.string().optional(),
203
-
204
- phaseTimings: z.record(z.string(), z.array(PhaseTimingEntry)).optional(),
205
-
206
- gateContract: z.object({
207
- environments: z.any().optional(),
208
- verdicts: z.any().optional(),
209
- evidence: z.any().optional(),
210
- baselines: z.object({
211
- testBaseline: z.number().optional(),
212
- tscBaseline: z.number().optional(),
213
- }).optional(),
214
- }).optional(),
215
-
216
- changelog: z.array(ChangelogEntry).optional(),
217
-
218
- verifyBlockers: z.array(z.object({
219
- id: z.string(),
220
- description: z.string(),
221
- fixCommit: z.string().optional(),
222
- quinnReverified: z.boolean().default(false),
223
- })).optional(),
224
-
225
- bootstrappedFrom: z.string().optional(),
226
- beforeState: z.object({
227
- type: z.enum(["text", "screenshot", "api", "data", "none"]),
228
- path: z.string().nullable(),
229
- capturedAt: z.string(),
230
- description: z.string().optional(),
231
- }).optional(),
232
-
233
- issueType: z.enum(["feature", "bug-fix", "bug", "refactor", "chore"]).optional(),
234
- rca: z.object({
235
- rootCause: z.string().optional(),
236
- prediction: z.string().optional(),
237
- predictionVerified: z.boolean().optional(),
238
- }).optional(),
239
-
240
- blastRadius: z.object({
241
- filesRead: z.number(),
242
- filesChanged: z.number(),
243
- }).optional(),
244
-
245
- foundIssues: z.array(z.object({
246
- description: z.string(),
247
- disposition: z.enum(["fixed", "filed", "scoped-out"]).optional(),
248
- issueNumber: z.number().optional(),
249
- })).optional(),
250
-
251
- filesChangedOutsideBrief: z.array(z.string()).optional(),
252
-
253
- quinnJourneyPath: z.string().optional(),
254
-
255
- conformityFindings: z.any().optional(),
256
-
257
- preExistingFailures: z.array(z.string()).optional(),
258
-
259
- proofOfFix: z.object({
260
- commitSha: z.string(),
261
- verified: z.boolean(),
262
- }).optional(),
263
- });
264
-
265
- export type WorkflowState = z.infer<typeof WorkflowStateSchema>;
266
-
267
- // ── AFK batch plan schema (#468) ────────────────────────────
268
-
269
- const REJECTED_SKIP_REASONS = [
270
- "needs investigation",
271
- "needs browser testing",
272
- "can't do from here",
273
- ];
274
-
275
- export const AfkBatchPlanSchema = z.object({
276
- approvedAt: z.string(),
277
- planned: z.array(z.number()),
278
- shipped: z.array(z.number()),
279
- skipped: z.array(z.object({
280
- issue: z.number(),
281
- reason: z.string(),
282
- delegationAction: z.string().optional(),
283
- })),
284
- inProgress: z.number().nullable(),
285
- });
286
-
287
- export type AfkBatchPlan = z.infer<typeof AfkBatchPlanSchema>;
288
-
289
- export { REJECTED_SKIP_REASONS };
290
-
291
- // ── Adversary report schema (ADR-009 B1) ──────────────────────
292
-
293
- export const AdversaryReportSchema = z.object({
294
- gameable: z.number(),
295
- approved: z.boolean(),
296
- exploits: z.array(z.object({
297
- acId: z.string(),
298
- exploit: z.string(),
299
- recommendation: z.string(),
300
- })),
301
- });
302
-
303
- // ── Chain artifact schemas ──────────────────────────────────
304
-
305
- export const GoalRecordSchema = z.object({
306
- contractVersion: z.string(),
307
- id: z.string(),
308
- goalStatement: z.string().min(1),
309
- governingSpec: z.object({
310
- path: z.string(),
311
- detectedFrom: z.string().optional(),
312
- }).optional(),
313
- successCriteria: z.array(z.object({
314
- id: z.string(),
315
- assertion: z.string(),
316
- evidenceType: z.string(),
317
- threshold: z.object({ op: z.string(), value: z.string(), unit: z.string().optional() }),
318
- })),
319
- scopeBoundary: z.object({ in: z.array(z.string()), out: z.array(z.string()) }).optional(),
320
- artifactRef: z.object({ type: z.string(), locator: z.string() }).optional(),
321
- });
322
-
323
- export const ShipEvidenceSchema = z.object({
324
- contractVersion: z.string(),
325
- issueNumber: z.number(),
326
- gateOut: z.object({
327
- status: z.enum(["PASS", "FAIL"]),
328
- evidence: z.array(z.object({
329
- criterion: z.string(),
330
- result: z.enum(["PASS", "FAIL", "SKIP"]),
331
- detail: z.any().optional(),
332
- })),
333
- }),
334
- mergeCommitSha: z.string().optional(),
335
- capturedAt: z.string(),
336
- iterationCount: z.number().optional(),
337
- sizing: z.object({ predicted: z.string().optional(), actual: z.string().optional() }).optional(),
338
- });
339
-
340
- export const ProveEvidenceSchema = z.object({
341
- issueNumber: z.number(),
342
- verdict: z.enum(["PROVEN", "UNPROVEN", "INCONCLUSIVE"]),
343
- commitSHA: z.string(),
344
- capturedAt: z.string(),
345
- beforeEvidence: z.object({
346
- type: z.enum(["text", "screenshot", "api", "data", "none"]),
347
- path: z.string().nullable(),
348
- capturedAt: z.string(),
349
- description: z.string(),
350
- }),
351
- afterEvidence: z.object({
352
- type: z.enum(["text", "screenshot", "api", "data", "none"]),
353
- path: z.string().nullable(),
354
- capturedAt: z.string(),
355
- environment: z.enum(["local", "prod"]),
356
- description: z.string(),
357
- }),
358
- comparisonSummary: z.string(),
359
- quinnVerdict: z.enum(["PASS", "FAIL", "SKIP"]).optional(),
360
- reproduced: z.boolean(),
361
- gaps: z.array(z.object({ ac: z.string(), status: z.string(), detail: z.string() })).optional(),
362
- });