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
package/workflows/ship.js DELETED
@@ -1,789 +0,0 @@
1
- export const meta = {
2
- name: 'ship',
3
- description: 'Programmatic ship lifecycle: GOAL → DISCOVERY → SCOPE → IMPLEMENT → VALIDATE → COMMIT → VERIFY → SHIP → PROVE',
4
- whenToUse: 'Ship a GitHub issue through the full harness. Replaces reading SKILL.md manually.',
5
- phases: [
6
- { title: 'Goal', detail: 'Read issue, extract goal' },
7
- { title: 'Discovery', detail: 'Read project docs, size work, write ACs, detect prior work' },
8
- { title: 'Scope', detail: 'Run scope gate with self-heal' },
9
- { title: 'Implement', detail: 'Brief + Marcus implements (no commit)' },
10
- { title: 'Validate', detail: 'Quinn local dev, iterate with Marcus if needed' },
11
- { title: 'Commit', detail: 'Commit + push after Quinn local PASS' },
12
- { title: 'Verify', detail: 'Verify gate + container rebuild + Quinn container' },
13
- { title: 'Ship', detail: 'Ship gate' },
14
- { title: 'Prove', detail: 'Prove gate — verify fix actually works' },
15
- ],
16
- }
17
-
18
- // ── Structured output schemas ────────────────────────────────
19
-
20
- const GOAL_SCHEMA = {
21
- type: 'object',
22
- properties: {
23
- issueGoal: { type: 'string' },
24
- successCriteria: { type: 'array', items: { type: 'string' } },
25
- issueTitle: { type: 'string' },
26
- labels: { type: 'array', items: { type: 'string' } },
27
- },
28
- required: ['issueGoal', 'successCriteria', 'issueTitle'],
29
- }
30
-
31
- const DISCOVERY_SCHEMA = {
32
- type: 'object',
33
- properties: {
34
- sizing: { type: 'string', enum: ['XS', 'S', 'M', 'L'] },
35
- ceremonyTier: { type: 'string', enum: ['LIGHT', 'STANDARD', 'THOROUGH'] },
36
- acs: {
37
- type: 'array',
38
- items: {
39
- type: 'object',
40
- properties: {
41
- id: { type: 'string' },
42
- type: { type: 'string', enum: ['CODE', 'OUTCOME'] },
43
- statement: { type: 'string' },
44
- threshold: { type: 'object', properties: { op: { type: 'string', enum: ['==', '>=', '<=', '>', '<', '!=', 'contains', 'exists'] }, value: {}, unit: { type: 'string' } }, required: ['op', 'value'] },
45
- evidenceMethod: { type: 'object', properties: { type: { type: 'string', enum: ['GREP_CHECK', 'FILE_EXISTS', 'CURL_CHECK', 'BUN_TEST', 'SCREENSHOT', 'PLAYWRIGHT', 'COMMAND', 'MANUAL', 'grep', 'command', 'api', 'screenshot', 'manual'] }, command: { type: 'string' } }, required: ['type'] },
46
- specElement: { type: 'string' },
47
- contextFiles: { type: 'array', items: { type: 'object', properties: { path: { type: 'string' }, lines: { type: 'string' }, reason: { type: 'string' } }, required: ['path', 'reason'] } },
48
- },
49
- required: ['id', 'type', 'statement', 'threshold', 'evidenceMethod'],
50
- },
51
- },
52
- priorWork: {
53
- type: 'object',
54
- properties: {
55
- explicitCommits: { type: 'array', items: { type: 'string' } },
56
- acStatus: {
57
- type: 'array',
58
- items: {
59
- type: 'object',
60
- properties: {
61
- id: { type: 'string' },
62
- status: { type: 'string', enum: ['MET', 'PARTIAL', 'UNMET'] },
63
- evidence: { type: 'string' },
64
- },
65
- required: ['id', 'status'],
66
- },
67
- },
68
- },
69
- required: ['explicitCommits', 'acStatus'],
70
- },
71
- filesToModify: { type: 'array', items: { type: 'string' } },
72
- scopeOut: { type: 'array', items: { type: 'string' } },
73
- governingSpec: { type: 'string' },
74
- sourceSpecs: { type: 'array', items: { type: 'object', properties: { path: { type: 'string' }, citedInDiscovery: { type: 'boolean' }, specElements: { type: 'array', items: { type: 'string' } } }, required: ['path', 'citedInDiscovery'] } },
75
- },
76
- required: ['sizing', 'ceremonyTier', 'acs', 'filesToModify', 'scopeOut', 'priorWork'],
77
- }
78
-
79
- const GATE_RESULT_SCHEMA = {
80
- type: 'object',
81
- properties: {
82
- result: { type: 'string', enum: ['PASS', 'FAIL'] },
83
- failures: { type: 'array', items: { type: 'string' } },
84
- category: { type: 'string', enum: ['STATE', 'CODE', 'DISCOVERY', 'ENVIRONMENT', 'NON_RETRYABLE'] },
85
- regressionTarget: { type: 'string', enum: ['BUILD', 'DISCOVERY'] },
86
- },
87
- required: ['result'],
88
- }
89
-
90
- const BUILD_RESULT_SCHEMA = {
91
- type: 'object',
92
- properties: {
93
- success: { type: 'boolean' },
94
- branch: { type: 'string' },
95
- commitSha: { type: 'string' },
96
- filesChanged: { type: 'array', items: { type: 'string' } },
97
- testOutput: { type: 'string' },
98
- findings: { type: 'array', items: { type: 'string' } },
99
- },
100
- required: ['success'],
101
- }
102
-
103
- // ── Args ─────────────────────────────────────────────────────
104
-
105
- let parsedArgs = args || {}
106
- if (typeof parsedArgs === 'string') {
107
- try { parsedArgs = JSON.parse(parsedArgs) } catch { parsedArgs = {} }
108
- }
109
-
110
- if (!parsedArgs.issue || !parsedArgs.projectRoot) {
111
- return { status: 'ARGS_ERROR', message: 'Usage: Workflow({ name: "ship", args: { issue: N, projectRoot: "/path" } })' }
112
- }
113
-
114
- const ISSUE = parsedArgs.issue
115
- const REPO = parsedArgs.repo || 'hornjason/asaCommandCenter'
116
- const ISSUE_REPO = parsedArgs.issueRepo || REPO
117
- const PROJECT_ROOT = parsedArgs.projectRoot
118
- const PHASE_TARGET = parsedArgs.phase || 'all'
119
- const SLUG = parsedArgs.slug || `ddb-${ISSUE}`
120
- if (!parsedArgs.harnessRoot) return { status: 'ARGS_ERROR', message: 'harnessRoot is required' }
121
- const HARNESS_ROOT = parsedArgs.harnessRoot
122
- const HOME = parsedArgs.home || PROJECT_ROOT.split('/Projects/')[0] || process.env.HOME || ''
123
- const WORK_DIR = `${process.env.RUNGATE_WORK_DIR || `${HOME}/.rungate`}/${SLUG}`
124
- const DRY_RUN = parsedArgs.dryRun || false
125
- const MAX_REGRESSIONS = 2
126
-
127
- // ── Helper: run gate with self-heal + error classification ──
128
-
129
- async function runGateWithHeal(gateName, phaseName, healContext) {
130
- for (let attempt = 1; attempt <= 3; attempt++) {
131
- const result = await agent(`
132
- Run the ${gateName} gate and classify any failures:
133
-
134
- 1. Run: TEST_WORK_DIR=${WORK_DIR} bun run ${HARNESS_ROOT}/gates/run-gate.ts --gate ${gateName} --slug ${SLUG} --issue ${ISSUE} 2>&1
135
- 2. Read ${WORK_DIR}/workflow-state.json for gate result
136
- 3. If FAIL, classify failures: bun -e "
137
- import {classifyFailures} from '${HARNESS_ROOT}/gates/error-classifier.ts';
138
- import {readFileSync} from 'fs';
139
- const s = JSON.parse(readFileSync('${WORK_DIR}/workflow-state.json','utf-8'));
140
- const f = s.gates?.['${gateName}']?.failures || [];
141
- console.log(JSON.stringify(classifyFailures(f)));
142
- " 2>&1
143
- 4. Report: result (PASS/FAIL), failures list, category, regressionTarget
144
- `, { label: `${gateName}-${attempt}`, phase: phaseName, schema: GATE_RESULT_SCHEMA })
145
-
146
- if (!result || result.result === 'PASS') return result
147
- if (result.category === 'NON_RETRYABLE') return result
148
- if (attempt >= 3) return result
149
- if (result.regressionTarget) return result
150
-
151
- log(`${gateName} attempt ${attempt}/3 FAILED (${result.category || 'unknown'}) — healing`)
152
- await agent(`
153
- ${gateName} gate failed. Category: ${result.category || 'unknown'}
154
- Failures: ${(result.failures || []).join('\n')}
155
- Read ${HARNESS_ROOT}/gates/SCHEMA-GUIDE.md. Read ${WORK_DIR}/workflow-state.json.
156
- Read ${PROJECT_ROOT}/.claude/rungate.json for environment config.
157
- ${healContext}
158
- Edit workflow-state.json ONLY via writeWorkflowState():
159
- bun -e "import {writeWorkflowState} from '${HARNESS_ROOT}/gates/orchestrator.ts'; import {readFileSync} from 'fs'; const s = JSON.parse(readFileSync('${WORK_DIR}/workflow-state.json','utf8')); /* apply fix here */; writeWorkflowState('${WORK_DIR}/workflow-state.json', s);"
160
- This validates via Zod at write time — you get immediate error feedback. Report what you fixed.
161
- `, { label: `${gateName}-heal-${attempt}`, phase: phaseName })
162
- }
163
- }
164
-
165
- // ════════════════════════════════════════════════════════════
166
- // PHASE 1: GOAL
167
- // ════════════════════════════════════════════════════════════
168
-
169
- phase('Goal')
170
- log(`Ship #${ISSUE}: reading issue`)
171
-
172
- const goalData = await agent(`
173
- Read this GitHub issue and extract the goal and success criteria:
174
- gh issue view ${ISSUE} --repo ${ISSUE_REPO} --json title,body,labels
175
-
176
- Extract verbatim:
177
- 1. issueGoal — main goal statement (first paragraph of body, or title if short)
178
- 2. successCriteria — each SC/AC (look for "- [ ] SC-" or "## Success Criteria")
179
- 3. issueTitle — the title
180
- 4. labels — label names
181
- `, { label: 'read-issue', phase: 'Goal', schema: GOAL_SCHEMA })
182
-
183
- if (!goalData) return { status: 'GOAL_FAILED', message: `Could not read issue #${ISSUE}` }
184
- log(`Goal: "${goalData.issueTitle}" — ${goalData.successCriteria.length} SCs`)
185
-
186
- // ════════════════════════════════════════════════════════════
187
- // PHASE 2: DISCOVERY (with regression support + prior work)
188
- // ════════════════════════════════════════════════════════════
189
-
190
- let discovery = null
191
- let regressionCount = 0
192
-
193
- async function runDiscovery(context) {
194
- phase('Discovery')
195
- log(`DISCOVERY${context ? ' (regression: ' + context + ')' : ''}`)
196
-
197
- discovery = await agent(`
198
- You are performing DISCOVERY for ship issue #${ISSUE}.${context ? '\n\nREGRESSION CONTEXT: ' + context : ''}
199
-
200
- ## Issue
201
- Title: ${goalData.issueTitle}
202
- Goal: ${goalData.issueGoal}
203
- Success criteria: ${goalData.successCriteria.map((sc, i) => `${i + 1}. ${sc}`).join('\n')}
204
-
205
- ## Instructions
206
- 1. Read ${HARNESS_ROOT}/gates/SCHEMA-GUIDE.md FIRST.
207
- 2. Read ${PROJECT_ROOT}/.claude/rungate.json and ${PROJECT_ROOT}/AGENTS.md.
208
- 3. Check prior work: git log --oneline --all --grep="#${ISSUE}" in ${PROJECT_ROOT}.
209
-
210
- ## AC ANCHORING (CRITICAL — do not skip)
211
- ACs MUST map 1:1 to the issue's Success Criteria listed above. Rules:
212
- - AC-1 corresponds to SC-1, AC-2 to SC-2, etc. Do NOT invent new ACs beyond the issue SCs.
213
- - If the issue has no structured SCs (no "SC-" or "- [ ]" items), derive ACs from the issue body paragraphs — but still anchor each AC to a specific sentence from the issue.
214
- - The AC statement should be a testable restatement of the SC, not a reinterpretation.
215
- - For UI bugs: at least one AC must be type OUTCOME (not CODE) so Quinn verifies it.
216
-
217
- ## PRIOR WORK CHECK
218
- For EACH AC, run its evidenceMethod command against the CURRENT code on main. Classify:
219
- - MET: evidence command succeeds and threshold is satisfied by existing code
220
- - PARTIAL: some evidence exists but threshold not fully met
221
- - UNMET: no evidence, needs implementation
222
- Report in priorWork.acStatus array. Include evidence string (command output snippet).
223
- Also include git log results in priorWork.explicitCommits array.
224
-
225
- 4. Read relevant source files. Identify filesToModify, scopeOut, contextFiles per AC.
226
- 5. Size: XS→LIGHT | S/M→STANDARD | L→THOROUGH.
227
- 6. Write ACs: id, type, statement (min 5 words), threshold (op + value as string|number NEVER boolean), evidenceMethod, specElement, contextFiles.
228
- EVIDENCE TYPE RULE: At least 50% of ACs must use non-grep evidence (BUN_TEST, COMMAND, PLAYWRIGHT). If you have 4 ACs, at least 2 must use bun test or curl commands, not grep. A regression test AC should use evidenceMethod type "BUN_TEST" with command "bun test test/unit/relevant.test.ts".
229
- 7. Garbage test each AC.
230
- 8. Find governingSpec from ${PROJECT_ROOT}/DOCS.md routing table (absolute path or empty).
231
- 9. Set sourceSpecs with citedInDiscovery:true, specElements[]. One AC per specElement minimum.
232
-
233
- Project root: ${PROJECT_ROOT}
234
- `, { label: `discovery${regressionCount > 0 ? '-r' + regressionCount : ''}`, phase: 'Discovery', schema: DISCOVERY_SCHEMA })
235
-
236
- if (!discovery) return false
237
-
238
- for (const ac of discovery.acs) {
239
- if (ac.threshold && typeof ac.threshold.value === 'boolean') ac.threshold.value = String(ac.threshold.value)
240
- }
241
-
242
- await agent(`
243
- You have ONE task: run this EXACT command and report the output. Do NOT implement any code. Do NOT read source files. Do NOT write any code. Just run this command:
244
-
245
- mkdir -p ${WORK_DIR} && bun -e "
246
- import {initWorkflow, writeACs} from '${HARNESS_ROOT}/gates/orchestrator.ts';
247
- const sf = '${WORK_DIR}/workflow-state.json';
248
- initWorkflow(sf, {
249
- issue: ${ISSUE}, repo: '${REPO}', issueRepo: '${ISSUE_REPO}',
250
- projectRoot: '${PROJECT_ROOT}', slug: '${SLUG}',
251
- issueGoal: ${JSON.stringify(goalData.issueGoal)},
252
- sizing: {predicted:'${discovery.sizing}', ceremonyTier:'${discovery.ceremonyTier}'},
253
- sourceSpecs: ${JSON.stringify(discovery.sourceSpecs || [])},
254
- bootstrappedFrom: 'ship-workflow',
255
- priorWork: ${JSON.stringify(discovery.priorWork || null)},
256
- });
257
- writeACs(sf, ${JSON.stringify(discovery.acs.map(ac => ({
258
- id: ac.id, type: ac.type, statement: ac.statement,
259
- threshold: ac.threshold, evidenceMethod: ac.evidenceMethod, specElement: ac.specElement,
260
- })))});
261
- console.log('initialized');
262
- " 2>&1
263
-
264
- Then verify the file exists: ls -la ${WORK_DIR}/workflow-state.json
265
- Report the command output only.
266
- `, { label: 'init-state', phase: 'Discovery' })
267
-
268
- log(`Sized: ${discovery.sizing}/${discovery.ceremonyTier} — ${discovery.acs.length} ACs`)
269
- return true
270
- }
271
-
272
- if (!await runDiscovery(null)) return { status: 'DISCOVERY_FAILED' }
273
-
274
- // ── Prior-work short circuit ────────────────────────────────
275
- if (discovery.priorWork) {
276
- const metCount = discovery.priorWork.acStatus.filter(a => a.status === 'MET').length
277
- const totalCount = discovery.priorWork.acStatus.length
278
-
279
- if (metCount === totalCount && totalCount > 0) {
280
- log(`ALREADY_SHIPPED: ALL ${totalCount} ACs already MET — running prove`)
281
- discovery.priorWork.acStatus.forEach(a => log(` ${a.id}: MET — ${a.evidence || 'verified'}`))
282
-
283
- // Still must run prove — code exists doesn't mean it works
284
- phase('Prove')
285
- log('Running prove WORKFLOW (with Quinn for UI) on already-shipped code')
286
- const alreadyProve = await workflow(
287
- { scriptPath: `${HARNESS_ROOT}/workflows/prove.js` },
288
- { issue: ISSUE, projectRoot: PROJECT_ROOT, repo: REPO, issueRepo: ISSUE_REPO, home: HOME, slug: SLUG }
289
- )
290
-
291
- const alreadyVerdict = alreadyProve?.verdict === 'PROVEN' ? 'PROVEN' : 'UNPROVEN'
292
- log(`Prove (already-shipped): ${alreadyVerdict}`)
293
-
294
- await agent(`
295
- Post prove result to issue #${ISSUE}:
296
- 1. gh issue comment ${ISSUE} --repo ${ISSUE_REPO} --body "Prove verdict: ${alreadyVerdict} (already-shipped path — all ACs MET, prove ran mechanically)"
297
- 2. If verdict is PROVEN: gh issue edit ${ISSUE} --repo ${ISSUE_REPO} --add-label "proven"
298
- 3. If verdict is PROVEN and no goal-record.json at ${WORK_DIR}/goal-record.json: gh issue close ${ISSUE} --repo ${ISSUE_REPO}
299
- `, { label: 'already-prove-label', phase: 'Prove' })
300
-
301
- return {
302
- status: alreadyVerdict === 'PROVEN' ? 'ALREADY_SHIPPED_AND_PROVEN' : 'ALREADY_SHIPPED_PROVE_FAILED',
303
- issue: ISSUE, slug: SLUG,
304
- sizing: discovery.sizing, ceremonyTier: discovery.ceremonyTier,
305
- priorWork: discovery.priorWork,
306
- proveVerdict: alreadyVerdict,
307
- workDir: WORK_DIR,
308
- }
309
- }
310
-
311
- if (metCount > 0) {
312
- log(`Prior work: ${metCount}/${totalCount} ACs already MET — building only gaps`)
313
- discovery.priorWork.acStatus.filter(a => a.status === 'MET').forEach(a =>
314
- log(` ${a.id}: MET — ${a.evidence || 'verified'}`)
315
- )
316
- const unmetIds = new Set(discovery.priorWork.acStatus.filter(a => a.status !== 'MET').map(a => a.id))
317
- discovery.acs = discovery.acs.filter(ac => unmetIds.has(ac.id))
318
- discovery.priorWork.acStatus.filter(a => a.status === 'MET').forEach(a => {
319
- discovery.scopeOut.push(`${a.id} — already satisfied, do not re-implement`)
320
- })
321
- log(`Remaining ACs for BUILD: ${discovery.acs.length}`)
322
- }
323
- }
324
-
325
- if (PHASE_TARGET === 'discovery') {
326
- return { status: 'DISCOVERY_COMPLETE', issue: ISSUE, slug: SLUG, sizing: discovery.sizing, acs: discovery.acs, workDir: WORK_DIR }
327
- }
328
-
329
- // ════════════════════════════════════════════════════════════
330
- // PHASE 3: SCOPE GATE
331
- // ════════════════════════════════════════════════════════════
332
-
333
- phase('Scope')
334
- const skipScope = discovery.ceremonyTier === 'LIGHT'
335
-
336
- let scopeResult = { result: 'PASS' }
337
- if (!skipScope) {
338
- scopeResult = await runGateWithHeal('scope', 'Scope', `Fix scope gate failures.
339
- For AC/threshold/sourceSpec failures: fix in workflow-state.json via writeWorkflowState().
340
- For evidence-type-ratio: add non-grep evidence methods (BUN_TEST, COMMAND, PLAYWRIGHT) to ACs.
341
- For tests-pass: run cd ${PROJECT_ROOT} && bun test --isolate test/unit/ and write result to environments.local.tests in workflow-state.json.
342
- For local-api-validated: check if dev server is up (curl localhost:7778). If down, run cd ${PROJECT_ROOT} && make dev-all in background. Write environments.local.api.
343
- For local-ui-validated: check if UI is up (curl localhost:5173). Write environments.local.ui or set skipReason.
344
- Edit workflow-state.json ONLY via writeWorkflowState():
345
- bun -e "import {writeWorkflowState} from '${HARNESS_ROOT}/gates/orchestrator.ts'; import {readFileSync} from 'fs'; const s = JSON.parse(readFileSync('${WORK_DIR}/workflow-state.json','utf8')); /* apply fix here */; writeWorkflowState('${WORK_DIR}/workflow-state.json', s);"
346
- This validates via Zod at write time — you get immediate error feedback.`)
347
- if (scopeResult?.result === 'FAIL') return { status: 'SCOPE_FAILED', failures: scopeResult.failures, workDir: WORK_DIR }
348
- }
349
- log(`Scope: ${scopeResult?.result || 'SKIPPED'}`)
350
-
351
- if (DRY_RUN) {
352
- log('DRY RUN — stopping after scope. No agents will be spawned.')
353
- return {
354
- status: 'DRY_RUN_COMPLETE',
355
- issue: ISSUE, slug: SLUG,
356
- sizing: discovery.sizing, ceremonyTier: discovery.ceremonyTier,
357
- acs: discovery.acs.map(ac => ({ id: ac.id, type: ac.type, statement: ac.statement })),
358
- priorWork: discovery.priorWork,
359
- scopeResult: scopeResult?.result || 'SKIPPED',
360
- workDir: WORK_DIR,
361
- }
362
- }
363
-
364
- // ════════════════════════════════════════════════════════════
365
- // PHASE 4: IMPLEMENT (Marcus writes code — NO commit)
366
- // ════════════════════════════════════════════════════════════
367
-
368
- phase('Implement')
369
-
370
- async function runImplement() {
371
- log('IMPLEMENT: assembling brief + spawning Marcus (no commit)')
372
-
373
- await agent(`
374
- Assemble brief: bun run ${HARNESS_ROOT}/gates/brief-assembler.ts --slug ${SLUG} --work-dir ${WORK_DIR} --project-root ${PROJECT_ROOT} 2>&1
375
- Report the output.
376
- `, { label: 'assemble-brief', phase: 'Implement' })
377
-
378
- const buildResult = await agent(`
379
- You are Marcus Webb, senior engineer.
380
- Read ${WORK_DIR}/marcus-brief.md for full instructions.
381
- Read every file in Context section first. Read "Files to modify" before changes.
382
-
383
- IMPORTANT: Implement the fix and run unit tests (bun test, tsc --noEmit).
384
- Do NOT commit or push yet — Quinn will validate on local dev first.
385
- If tests fail, fix them before reporting.
386
-
387
- Report: success, branch name, files changed, test output, evidence per AC.
388
- `, { label: 'marcus', phase: 'Implement', agentType: 'Engineer', schema: BUILD_RESULT_SCHEMA })
389
-
390
- if (!buildResult || !buildResult.success) {
391
- log(`IMPLEMENT FAILED: ${buildResult?.findings?.join(', ') || 'unknown'}`)
392
- return { success: false, buildResult }
393
- }
394
- log(`IMPLEMENT SUCCESS — ${(buildResult.filesChanged || []).length} files changed`)
395
- return { success: true, buildResult }
396
- }
397
-
398
- let implementResult = await runImplement()
399
- if (!implementResult.success) {
400
- return { status: 'IMPLEMENT_FAILED', ...implementResult, workDir: WORK_DIR }
401
- }
402
-
403
- // ════════════════════════════════════════════════════════════
404
- // PHASE 5: VALIDATE (Quinn local dev — fast feedback before commit)
405
- // ════════════════════════════════════════════════════════════
406
-
407
- phase('Validate')
408
- let quinnLocalResult = { result: 'PASS' }
409
-
410
- // Quinn local runs for ALL STANDARD+ tiers (spec: Layer 1, ceremony table: STANDARD = Quinn)
411
- if (discovery.ceremonyTier !== 'LIGHT') {
412
- for (let validateAttempt = 1; validateAttempt <= 3; validateAttempt++) {
413
- log(`Quinn local dev — attempt ${validateAttempt}/3`)
414
-
415
- quinnLocalResult = await agent(`
416
- Read ${HARNESS_ROOT}/prompts/quinn-ui-brief.md for your testing methodology.
417
- Read ${PROJECT_ROOT}/AGENTS.md for project context.
418
-
419
- You are Quinn Torres, QA specialist. You have Playwright MCP tools available.
420
-
421
- ## Environment
422
- - **Dev UI:** http://localhost:5173
423
- - **Dev API:** http://localhost:7778
424
- - **Viewport:** 1280x720 (set via browser_resize FIRST)
425
- - **Test as:** Brand-new user — no prior session state
426
- - **Pages map:** Read ${PROJECT_ROOT}/.claude/rungate.json for exact URL paths
427
-
428
- ## Pre-conditions (GATE — stop if any fail)
429
- 1. browser_resize(1280, 720)
430
- 2. browser_navigate to target URL from rungate.json pages map
431
- 3. browser_snapshot() — verify page loaded (no error banners, data present)
432
- If pre-conditions fail → report FAIL immediately, do NOT proceed.
433
-
434
- ## User Journey for #${ISSUE}
435
- Follow this structured test plan — each step maps to an AC:
436
-
437
- ${discovery.acs.map((ac, i) => `Step ${i + 1}: Verify ${ac.id}: ${ac.statement}
438
- → ACTION: navigate/click/type as needed
439
- → VERIFY: browser_snapshot() — check expected state
440
- → SCREENSHOT: browser_take_screenshot() if state changed`).join('\n\n')}
441
-
442
- ## Anti-checks (ALWAYS run after journey)
443
- - [ ] No "undefined" or "null" rendered as visible text
444
- - [ ] No stuck loading spinners
445
- - [ ] No error banners or toast messages
446
- - [ ] Interactive elements respond to clicks
447
-
448
- Any anti-check failure = FAIL even if all ACs pass.
449
-
450
- ## Screenshot Strategy
451
- - page-load.png — after navigation, before interaction
452
- - After each state-changing action
453
- - final-state.png — end of journey
454
- Do NOT screenshot after every browser_snapshot().
455
-
456
- ## Verdict
457
- - PASS: all pre-conditions + all ACs + all anti-checks pass
458
- - FAIL: any failure — report which AC or anti-check failed with evidence
459
- `, { label: `quinn-local-${validateAttempt}`, phase: 'Validate', schema: GATE_RESULT_SCHEMA })
460
-
461
- if (!quinnLocalResult) {
462
- log(`Quinn local: agent failed (network/API error) — attempt ${validateAttempt}/3`)
463
- if (validateAttempt >= 3) return { status: 'VALIDATE_FAILED', reason: 'Quinn agent unavailable', workDir: WORK_DIR }
464
- continue
465
- }
466
-
467
- if (quinnLocalResult.result === 'PASS') {
468
- log('Quinn local: PASS')
469
- break
470
- }
471
-
472
- if (validateAttempt >= 3) {
473
- log('Quinn local failed 3x — circuit break')
474
- return { status: 'VALIDATE_FAILED', quinnLocalResult, workDir: WORK_DIR }
475
- }
476
-
477
- log(`Quinn local: FAIL — sending back to Marcus (attempt ${validateAttempt}/3)`)
478
- const fixResult = await agent(`
479
- You are Marcus Webb, senior engineer.
480
- Quinn found issues on local dev for issue #${ISSUE}:
481
- ${(quinnLocalResult?.failures || []).join('\n')}
482
-
483
- Read the failing AC details. Fix the code. Run unit tests again.
484
- Do NOT commit — Quinn will retest.
485
- Report what you fixed.
486
- `, { label: `marcus-fix-${validateAttempt}`, phase: 'Validate', agentType: 'Engineer' })
487
- }
488
- } else {
489
- log('Quinn local: SKIPPED (LIGHT tier)')
490
- }
491
-
492
- // ════════════════════════════════════════════════════════════
493
- // PHASE 6: COMMIT (only after Quinn local PASS)
494
- // ════════════════════════════════════════════════════════════
495
-
496
- phase('Commit')
497
- log('Quinn local passed — committing code')
498
-
499
- const commitResult = await agent(`
500
- Commit and push the fix for issue #${ISSUE}:
501
- 1. cd ${PROJECT_ROOT}
502
- 2. git checkout -b ${ISSUE}-fix 2>/dev/null || git checkout ${ISSUE}-fix
503
- 3. git add -A
504
- 4. git commit -m "fix(#${ISSUE}): ${goalData.issueTitle}"
505
- 5. git push -u origin ${ISSUE}-fix
506
- 6. Report: branch name, commit SHA (git rev-parse --short HEAD)
507
- `, { label: 'commit', phase: 'Commit', schema: {
508
- type: 'object',
509
- properties: {
510
- branch: { type: 'string' },
511
- commitSha: { type: 'string' },
512
- pushed: { type: 'boolean' },
513
- },
514
- required: ['branch', 'commitSha'],
515
- }})
516
-
517
- if (!commitResult?.commitSha) {
518
- return { status: 'COMMIT_FAILED', workDir: WORK_DIR }
519
- }
520
- log(`Committed: ${commitResult.commitSha} on ${commitResult.branch}`)
521
-
522
- // Check environment status (structured output — no JSON writing)
523
- const ENV_CHECK_SCHEMA = {
524
- type: 'object',
525
- properties: {
526
- apiStatus: { type: 'string', enum: ['PASS', 'FAIL', 'SKIP'] },
527
- uiStatus: { type: 'string', enum: ['PASS', 'FAIL', 'SKIP'] },
528
- uiSkipReason: { type: 'string' },
529
- testsStatus: { type: 'string', enum: ['PASS', 'FAIL', 'SKIP'] },
530
- testFailCount: { type: 'number' },
531
- testTotalCount: { type: 'number' },
532
- },
533
- required: ['apiStatus', 'uiStatus', 'testsStatus'],
534
- }
535
- const envStatus = await agent(`
536
- Run these 3 checks and report results. Do NOT read or write any JSON files.
537
-
538
- 1. API: curl -s -o /dev/null -w "%{http_code}" http://localhost:7778/api/aes
539
- - If 200: apiStatus = "PASS"
540
- - Otherwise: apiStatus = "FAIL"
541
-
542
- 2. UI: curl -s -o /dev/null -w "%{http_code}" http://localhost:5173
543
- - If 200 or 302: uiStatus = "PASS"
544
- - If unreachable: uiStatus = "SKIP", set uiSkipReason
545
-
546
- 3. Tests — run TWO commands:
547
- a. Run the fix-specific test: cd ${PROJECT_ROOT} && bun test test/unit/campaign-quality-gate.test.ts 2>&1 | tail -3
548
- b. Run the full suite: cd ${PROJECT_ROOT} && bun test --isolate test/unit/ 2>&1 | tail -3
549
- - testsStatus = "PASS" if the fix-specific test (a) passes with 0 fail, regardless of full suite
550
- - testsStatus = "FAIL" ONLY if the fix-specific test (a) has failures
551
- - Report testFailCount and testTotalCount from the full suite (b) for reference
552
- `, { label: 'env-check-local', phase: 'Commit', schema: ENV_CHECK_SCHEMA })
553
-
554
- // Write commit + environment data to workflow-state.json via writeWorkflowState (Zod-validated)
555
- await agent(`
556
- Update workflow-state.json via writeWorkflowState():
557
-
558
- bun -e "import {writeWorkflowState} from '${HARNESS_ROOT}/gates/orchestrator.ts'; import {readFileSync} from 'fs'; const s = JSON.parse(readFileSync('${WORK_DIR}/workflow-state.json','utf8')); s.buildCommit = '${commitResult.commitSha}'; s.agents = {marcus: {branch: '${commitResult.branch}', commitSha: '${commitResult.commitSha}', spawned: true, verdict: 'PASS'}, quinn: {spawned: ${discovery.ceremonyTier !== 'LIGHT'}, verdict: '${discovery.ceremonyTier !== 'LIGHT' ? 'PASS' : 'SKIP'}'}}; s.environments = s.environments || {}; s.environments.local = s.environments.local || {}; s.environments.local.api = '${envStatus?.apiStatus || 'SKIP'}'; s.environments.local.ui = '${envStatus?.uiStatus || 'SKIP'}'; ${envStatus?.uiSkipReason ? `s.environments.local.uiSkipReason = '${envStatus.uiSkipReason}';` : ''} s.environments.local.tests = '${envStatus?.testsStatus || 'SKIP'}'; writeWorkflowState('${WORK_DIR}/workflow-state.json', s);"
559
-
560
- Run this command and report the output.
561
- `, { label: 'record-commit', phase: 'Commit' })
562
-
563
- // ════════════════════════════════════════════════════════════
564
- // PHASE 7: VERIFY (gate + container rebuild + Quinn container)
565
- // ════════════════════════════════════════════════════════════
566
-
567
- phase('Verify')
568
-
569
- // Run verify gate first (mechanical checks)
570
- const verifyResult = await runGateWithHeal('verify', 'Verify',
571
- 'Fix evidence gaps, test failures, uncommitted code. Run AC evidence commands.')
572
-
573
- if (verifyResult?.result === 'FAIL') {
574
- if (verifyResult.regressionTarget === 'DISCOVERY' && regressionCount < MAX_REGRESSIONS) {
575
- regressionCount++
576
- log(`Verify DISCOVERY regression #${regressionCount}`)
577
- if (!await runDiscovery('Verify gate found ACs were wrong: ' + (verifyResult.failures || []).join(', '))) {
578
- return { status: 'VERIFY_FAILED', reason: 'DISCOVERY regression failed', workDir: WORK_DIR }
579
- }
580
- }
581
- if (verifyResult.regressionTarget === 'BUILD' && regressionCount < MAX_REGRESSIONS) {
582
- regressionCount++
583
- log(`Verify CODE regression #${regressionCount}`)
584
- }
585
- }
586
-
587
- // Container rebuild + Quinn container (STANDARD+ — all tiers except LIGHT)
588
- if (discovery.ceremonyTier !== 'LIGHT') {
589
- // Step 1: Force rebuild container image from fix branch (unconditional)
590
- await agent(`
591
- You have ONE task: rebuild the test container. Run this EXACT command and report the output:
592
-
593
- cd ${PROJECT_ROOT} && make test-rebuild 2>&1 | tail -20
594
-
595
- This stops the old container, rebuilds the image from current code, seeds data, and starts a new container on port 7776. Report the full output.
596
- `, { label: 'container-rebuild', phase: 'Verify' })
597
-
598
- // Step 2: Check container availability after rebuild
599
- const envCheck = await agent(`
600
- Check if the rebuilt container is available:
601
- 1. Local: curl -s -o /dev/null -w "%{http_code}" http://localhost:7776/api/aes 2>/dev/null
602
- - localTest = true if 200, false otherwise
603
- 2. Mac Mini: curl -s -o /dev/null -w "%{http_code}" http://mini.local:7776/api/aes 2>/dev/null || echo "unreachable"
604
- - macMini = true if 200, false otherwise
605
- `, { label: 'env-check', phase: 'Verify', schema: {
606
- type: 'object',
607
- properties: {
608
- localTest: { type: 'boolean' },
609
- macMini: { type: 'boolean' },
610
- },
611
- required: ['localTest', 'macMini'],
612
- }})
613
-
614
- const testHost = envCheck?.localTest ? 'localhost' : envCheck?.macMini ? 'mini.local' : null
615
- log(`Container env: local=${envCheck?.localTest}, macMini=${envCheck?.macMini}, using=${testHost || 'NONE'}`)
616
-
617
- if (testHost) {
618
- await agent(`
619
- You are Quinn Torres, QA specialist. You have Playwright MCP tools available.
620
-
621
- ## COMMIT SHA VERIFICATION (MANDATORY)
622
- Read ${WORK_DIR}/workflow-state.json and get the buildCommit value.
623
- Run: cd ${PROJECT_ROOT} && git rev-parse --short HEAD
624
- Verify HEAD matches buildCommit from workflow-state.json.
625
- If mismatch, FAIL with "Container running wrong version — HEAD {actual} != buildCommit {expected}."
626
-
627
- ## Available Playwright MCP Tools (use these, NOT manual browser)
628
- - browser_navigate(url) — go to URL
629
- - browser_snapshot() — get accessibility tree (text, fast, preferred over screenshots)
630
- - browser_click(element) — click by ref from snapshot
631
- - browser_type(element, text) — type text into element
632
- - browser_take_screenshot() — capture PNG evidence
633
- - browser_verify_text_visible(text) — assert text on page
634
-
635
- ## Test Plan for #${ISSUE} on CONTAINER — http://${testHost}:7776
636
- Read ${PROJECT_ROOT}/.claude/rungate.json for page paths.
637
- 1. browser_navigate("http://${testHost}:7776" + page path from rungate.json)
638
- 2. browser_snapshot() — verify page loaded
639
- 3. For each AC:
640
- a. Perform the action (browser_click, browser_type, etc.)
641
- b. browser_snapshot() or browser_verify_text_visible() to verify
642
- c. browser_take_screenshot() for evidence
643
- 4. Report PASS/FAIL per AC. Include verified commit SHA.
644
-
645
- ### ACs to Verify
646
- ${discovery.acs.map(ac => `- ${ac.id}: ${ac.statement}`).join('\n')}
647
- `, { label: 'quinn-container', phase: 'Verify', schema: GATE_RESULT_SCHEMA })
648
- } else {
649
- log('WARN: No test container available — skipping container Quinn')
650
- }
651
- }
652
-
653
- // Rook security review (THOROUGH only)
654
- if (discovery.ceremonyTier === 'THOROUGH') {
655
- log('Spawning Rook')
656
- await agent(`
657
- Security review for issue #${ISSUE}. Changed: ${discovery.filesToModify.join(', ')}
658
- Read ${PROJECT_ROOT}/ARCHITECTURE.md. Check: injection, credentials, path traversal, XSS.
659
- `, { label: 'rook', phase: 'Verify', agentType: 'Pentester', schema: GATE_RESULT_SCHEMA })
660
- }
661
-
662
- // ════════════════════════════════════════════════════════════
663
- // PHASE 8: SHIP (container verify + PR creation + gate)
664
- // ════════════════════════════════════════════════════════════
665
-
666
- phase('Ship')
667
-
668
- // Record container test evidence (SKIP with reason if no container available)
669
- await agent(`
670
- Check test container status, then update workflow-state.json via writeWorkflowState():
671
-
672
- 1. Check test container: curl -s -o /dev/null -w "%{http_code}" http://localhost:7776/api/aes 2>/dev/null
673
- 2. Based on result, run this bun -e command (pick the version matching your result):
674
-
675
- If container is up (200):
676
- bun -e "import {writeWorkflowState} from '${HARNESS_ROOT}/gates/orchestrator.ts'; import {readFileSync} from 'fs'; const s = JSON.parse(readFileSync('${WORK_DIR}/workflow-state.json','utf8')); s.environments = s.environments || {}; s.environments.prod = s.environments.prod || {}; s.environments.prod.rebuild = 'PASS'; s.environments.prod.smoke = 'PASS'; s.environments.prod.quinn = 'SKIP'; s.environments.prod.quinnSkipReason = 'Quinn validated on local dev'; writeWorkflowState('${WORK_DIR}/workflow-state.json', s);"
677
-
678
- If container is down:
679
- bun -e "import {writeWorkflowState} from '${HARNESS_ROOT}/gates/orchestrator.ts'; import {readFileSync} from 'fs'; const s = JSON.parse(readFileSync('${WORK_DIR}/workflow-state.json','utf8')); s.environments = s.environments || {}; s.environments.prod = s.environments.prod || {}; s.environments.prod.rebuild = 'SKIP'; s.environments.prod.rebuildSkipReason = 'test container not running'; s.environments.prod.smoke = 'SKIP'; s.environments.prod.smokeSkipReason = 'test container not running'; s.environments.prod.quinn = 'SKIP'; s.environments.prod.quinnSkipReason = 'test container not running'; writeWorkflowState('${WORK_DIR}/workflow-state.json', s);"
680
-
681
- Run the appropriate command and report the output.
682
- `, { label: 'record-env', phase: 'Ship' })
683
-
684
- // Create PR
685
- log('Creating PR')
686
- await agent(`
687
- Create a PR for issue #${ISSUE}:
688
- 1. cd ${PROJECT_ROOT}
689
- 2. Check: gh pr list --repo ${REPO} --head $(git branch --show-current) --json number
690
- 3. If no PR exists:
691
- gh pr create --repo ${REPO} --title "fix(#${ISSUE}): ${goalData.issueTitle}" --body "$(cat <<'PREOF'
692
- Fixes #${ISSUE}
693
-
694
- ## Test plan
695
- - Unit tests: PASS
696
- - Quinn local dev: verified
697
- - Container: deferred to CI
698
-
699
- 🤖 Generated with [Claude Code](https://claude.com/claude-code)
700
- PREOF
701
- )"
702
- 4. Report the PR URL and number
703
- `, { label: 'create-pr', phase: 'Ship' })
704
-
705
- log('Running ship gate')
706
- const shipResult = await runGateWithHeal('ship', 'Ship',
707
- `Fix ceremony gaps in workflow-state.json via writeWorkflowState():
708
- bun -e "import {writeWorkflowState} from '${HARNESS_ROOT}/gates/orchestrator.ts'; import {readFileSync} from 'fs'; const s = JSON.parse(readFileSync('${WORK_DIR}/workflow-state.json','utf8')); /* apply fix here */; writeWorkflowState('${WORK_DIR}/workflow-state.json', s);"
709
- - branch-merged: set code-pushed="PASS" if branch is pushed. The PR is open for Jason to review — branch-merged may WARN, that's OK.
710
- - Any missing environments fields: add with SKIP + skipReason.
711
- - code-committed: should already be PASS from commit phase.`)
712
-
713
- log(`Ship: ${shipResult?.result || 'UNKNOWN'}`)
714
-
715
- if (shipResult?.result !== 'PASS') {
716
- return { status: 'SHIP_FAILED', issue: ISSUE, slug: SLUG, workDir: WORK_DIR }
717
- }
718
-
719
- // ════════════════════════════════════════════════════════════
720
- // PHASE 9: PROVE (full workflow — B3 + Quinn for UI ACs)
721
- // ════════════════════════════════════════════════════════════
722
-
723
- phase('Prove')
724
- log('Running prove WORKFLOW (with Quinn for UI) — verifying fix actually works')
725
-
726
- const proveResult = await workflow(
727
- { scriptPath: `${HARNESS_ROOT}/workflows/prove.js` },
728
- { issue: ISSUE, projectRoot: PROJECT_ROOT, repo: REPO, issueRepo: ISSUE_REPO, home: HOME, slug: SLUG }
729
- )
730
-
731
- if (proveResult?.verdict !== 'PROVEN' && regressionCount < MAX_REGRESSIONS) {
732
- regressionCount++
733
- log(`Prove UNPROVEN — regression #${regressionCount}, re-implementing`)
734
- phase('Implement')
735
- implementResult = await runImplement()
736
- if (implementResult.success) {
737
- phase('Commit')
738
- const reCommit = await agent(`
739
- Commit the regression fix for issue #${ISSUE}:
740
- cd ${PROJECT_ROOT} && git add -A && git commit -m "fix(#${ISSUE}): address prove regression" && git push
741
- Report commit SHA.
742
- `, { label: 'recommit', phase: 'Commit', schema: { type: 'object', properties: { commitSha: { type: 'string' } }, required: ['commitSha'] } })
743
-
744
- phase('Ship')
745
- const retryShip = await runGateWithHeal('ship', 'Ship', 'Re-ship after prove regression.')
746
- if (retryShip?.result === 'PASS') {
747
- phase('Prove')
748
- const retryProve = await workflow(
749
- { scriptPath: `${HARNESS_ROOT}/workflows/prove.js` },
750
- { issue: ISSUE, projectRoot: PROJECT_ROOT, repo: REPO, issueRepo: ISSUE_REPO, home: HOME, slug: `${SLUG}-retry` }
751
- )
752
- if (retryProve?.verdict === 'PROVEN') log('Prove passed after regression fix')
753
- }
754
- }
755
- }
756
-
757
- const proveVerdict = proveResult?.verdict === 'PROVEN' ? 'PROVEN' : 'UNPROVEN'
758
- log(`Prove: ${proveVerdict}`)
759
-
760
- // Post result + label + close
761
- await agent(`
762
- Post prove result to issue #${ISSUE}:
763
- 1. gh issue comment ${ISSUE} --repo ${ISSUE_REPO} --body "Prove verdict: ${proveVerdict} (mechanical — via ship.js prove gate)"
764
- 2. If verdict is PROVEN: gh issue edit ${ISSUE} --repo ${ISSUE_REPO} --add-label "proven"
765
- 3. If verdict is PROVEN and no goal-record.json at ${WORK_DIR}/goal-record.json: gh issue close ${ISSUE} --repo ${ISSUE_REPO}
766
- `, { label: 'prove-label', phase: 'Prove' })
767
-
768
- // ── Telemetry ──────────────────────────────────────────────
769
- await agent(`
770
- mkdir -p ${HOME}/.claude/MEMORY/LEARNING/SIGNALS
771
- Append a single JSON line to ${HOME}/.claude/MEMORY/LEARNING/SIGNALS/harness-telemetry.jsonl with:
772
- - ts: current ISO timestamp (run date -u command)
773
- - skill: "ship"
774
- - issue: ${ISSUE}
775
- - result: "${proveVerdict}"
776
- - sizing: "${discovery.sizing}"
777
- - ceremonyTier: "${discovery.ceremonyTier}"
778
- - regressions: ${regressionCount}
779
- Use Bash echo to append.
780
- `, { label: 'telemetry', phase: 'Prove' })
781
-
782
- return {
783
- status: proveVerdict === 'PROVEN' ? 'SHIPPED_AND_PROVEN' : 'SHIP_PASSED_PROVE_FAILED',
784
- issue: ISSUE, slug: SLUG,
785
- sizing: discovery.sizing, ceremonyTier: discovery.ceremonyTier,
786
- proveVerdict,
787
- regressions: regressionCount,
788
- workDir: WORK_DIR,
789
- }