rungate 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (196) hide show
  1. package/.claude/agents/aditi.md +47 -0
  2. package/.claude/agents/marcus.md +50 -0
  3. package/.claude/agents/quinn.md +58 -0
  4. package/.claude/agents/rook.md +47 -0
  5. package/.claude/agents/serena.md +46 -0
  6. package/.claude/rungate.json +11 -0
  7. package/.fallowrc.json +28 -0
  8. package/.github/copilot-instructions.md +20 -0
  9. package/.rungate/conformity-findings.json +648 -0
  10. package/AGENTS.md +106 -0
  11. package/CODE-MAP.md +50 -0
  12. package/HARNESS.md +88 -0
  13. package/bun.lock +26 -0
  14. package/bunfig.toml +2 -0
  15. package/config/brief-policies.json +28 -0
  16. package/config/ceremony-profiles.json +212 -0
  17. package/config/consumer-cascade-map.json +24 -0
  18. package/config/doc-cascade-map.json +24 -0
  19. package/config/eval.json +84 -0
  20. package/config/profiles/account-plan.yaml +36 -0
  21. package/config/profiles/campaign.yaml +94 -0
  22. package/config/prove-evidence.schema.json +65 -0
  23. package/config/spec-policies.json +36 -0
  24. package/config/workflow-schema.json +281 -0
  25. package/gates/SCHEMA-GUIDE.md +121 -0
  26. package/gates/ac-quality.test.ts +106 -0
  27. package/gates/adversarial.test.ts +274 -0
  28. package/gates/brief-assembler.test.ts +429 -0
  29. package/gates/brief-assembler.ts +334 -0
  30. package/gates/bunfig.toml +2 -0
  31. package/gates/chain.test.ts +91 -0
  32. package/gates/e2e-smoke.test.ts +234 -0
  33. package/gates/error-classifier.test.ts +249 -0
  34. package/gates/error-classifier.ts +89 -0
  35. package/gates/orchestrator.test.ts +950 -0
  36. package/gates/orchestrator.ts +569 -0
  37. package/gates/preload.ts +77 -0
  38. package/gates/prompts/ac-adversary.md +20 -0
  39. package/gates/prompts/evidence-validator.md +22 -0
  40. package/gates/prompts/prove-reproducer.md +53 -0
  41. package/gates/prove.test.ts +164 -0
  42. package/gates/run-gate.ts +936 -0
  43. package/gates/schema-parity.test.ts +197 -0
  44. package/gates/schema.ts +362 -0
  45. package/gates/self-heal.test.ts +511 -0
  46. package/gates/self-heal.ts +121 -0
  47. package/gates/ship-orchestrator.test.ts +379 -0
  48. package/gates/ship-orchestrator.ts +363 -0
  49. package/gates/test-fixtures/broken-no-environments.json +60 -0
  50. package/gates/test-fixtures/valid-standard.json +54 -0
  51. package/gates/test-utils.ts +43 -0
  52. package/gates/witness.ts +220 -0
  53. package/gates/workflow.test.ts +1053 -0
  54. package/hooks/AgentBriefGuard.hook.ts +586 -0
  55. package/hooks/AgentVerdictCapture.hook.ts +134 -0
  56. package/hooks/AutoVerifyGate.hook.ts +76 -0
  57. package/hooks/GateEnforcement.hook.ts +273 -0
  58. package/hooks/IssueCloseGuard.hook.ts +116 -0
  59. package/hooks/MergeGuard.hook.ts +55 -0
  60. package/hooks/StaleTTLCleanup.hook.ts +133 -0
  61. package/hooks/VerifyPhaseLock.hook.ts +81 -0
  62. package/hooks/WorkflowStateGuard.hook.ts +37 -0
  63. package/hooks/lib/agentDetection.ts +70 -0
  64. package/hooks/lib/findWorkflow.ts +101 -0
  65. package/hooks/lib/parseStdin.ts +37 -0
  66. package/hooks/lib/paths.ts +111 -0
  67. package/hooks/lib/utils.ts +81 -0
  68. package/lib/conformity.ts +959 -0
  69. package/lib/paths.ts +23 -0
  70. package/lib/rungate-schema.ts +60 -0
  71. package/lib/signal-phrases.ts +7 -0
  72. package/package.json +20 -0
  73. package/prompts/ac-adversary.md +20 -0
  74. package/prompts/ac-format.md +34 -0
  75. package/prompts/aditi.md +29 -0
  76. package/prompts/blast-radius.md +29 -0
  77. package/prompts/coding-principles.md +34 -0
  78. package/prompts/container-rebuild.md +29 -0
  79. package/prompts/container-verify.md +28 -0
  80. package/prompts/discovery.md +27 -0
  81. package/prompts/environment.md +28 -0
  82. package/prompts/escalation-decision-tree.md +38 -0
  83. package/prompts/evidence-hierarchy.md +31 -0
  84. package/prompts/evidence-validator.md +22 -0
  85. package/prompts/marcus.md +29 -0
  86. package/prompts/prevention.md +26 -0
  87. package/prompts/prove-reproducer.md +43 -0
  88. package/prompts/quinn-decision-tree.md +31 -0
  89. package/prompts/quinn-ui-brief.md +106 -0
  90. package/prompts/quinn.md +29 -0
  91. package/prompts/rca.md +28 -0
  92. package/prompts/read-before-write.md +30 -0
  93. package/prompts/regression.md +26 -0
  94. package/prompts/rook.md +29 -0
  95. package/prompts/serena.md +28 -0
  96. package/prompts/testing-strategy.md +34 -0
  97. package/reference/migration-manifest.json +554 -0
  98. package/reference/prompts/agent-aditi.md +38 -0
  99. package/reference/prompts/agent-marcus.md +38 -0
  100. package/reference/prompts/agent-quinn.md +38 -0
  101. package/reference/prompts/agent-rook.md +37 -0
  102. package/reference/prompts/agent-serena.md +37 -0
  103. package/reference/prompts/council-skill.md +170 -0
  104. package/reference/prompts/goal-skill.md +235 -0
  105. package/reference/prompts/prove-skill.md +283 -0
  106. package/reference/prompts/quinn-standard.md +246 -0
  107. package/reference/prompts/ship-convergence.md +65 -0
  108. package/reference/prompts/ship-escalation.md +43 -0
  109. package/reference/prompts/ship-iteration.md +382 -0
  110. package/reference/prompts/ship-pending-patches.md +246 -0
  111. package/reference/prompts/ship-reference.md +250 -0
  112. package/reference/prompts/ship-skill.md +347 -0
  113. package/reference/prompts/ship-templates.md +215 -0
  114. package/reference/scripts/batch-status.sh +68 -0
  115. package/reference/scripts/chain-compat-check.sh +67 -0
  116. package/reference/scripts/context-audit.sh +314 -0
  117. package/reference/scripts/dead-export-check.sh +61 -0
  118. package/reference/scripts/generate-qc-tables.sh +92 -0
  119. package/reference/scripts/harness-init.sh +111 -0
  120. package/reference/scripts/pai-054-baseline-check.sh +40 -0
  121. package/reference/scripts/prove-smoke-test.sh +112 -0
  122. package/reference/scripts/setup-keychain-salt.sh +12 -0
  123. package/reference/scripts/skill-optimizer-friday.sh +88 -0
  124. package/reference/scripts/skill-qc-test.sh +351 -0
  125. package/reference/scripts/skill-synthesize-tonight.sh +66 -0
  126. package/reference/specs/HARNESS-EXTRACTION-SPEC.md +263 -0
  127. package/reference/specs/harness-v3-bash-deletion-plan.md +65 -0
  128. package/reference/specs/harness-v3-migration-plan.md +188 -0
  129. package/scripts/decision-reconcile.sh +74 -0
  130. package/scripts/decision-reconcile.ts +152 -0
  131. package/scripts/extract-constraints.ts +260 -0
  132. package/scripts/generate-code-map.ts +339 -0
  133. package/scripts/git-hooks/pre-commit +76 -0
  134. package/scripts/git-hooks/pre-push +271 -0
  135. package/scripts/harness-skill-check.sh +52 -0
  136. package/scripts/lib/gap-emit.sh +65 -0
  137. package/scripts/lib/jq-update.sh +30 -0
  138. package/scripts/lib/resolve-slug.sh +30 -0
  139. package/scripts/lib/verify-spec-compliance.sh +102 -0
  140. package/scripts/prove-backfill.sh +87 -0
  141. package/scripts/scaffold-project.ts +1488 -0
  142. package/scripts/scaffold-rungate-config.ts +91 -0
  143. package/scripts/self-containment-check.sh +109 -0
  144. package/scripts/skill-qc-validator.sh +402 -0
  145. package/scripts/slug-resolver.sh +14 -0
  146. package/scripts/sync-spec-tests.ts +236 -0
  147. package/specs/BOOTSTRAP-DATA-FLOW-SPEC.md +2493 -0
  148. package/specs/BOOTSTRAP-TEST-PLAN.md +571 -0
  149. package/specs/HARNESS-GATES.md +256 -0
  150. package/specs/HARNESS-SKILL-CHAIN.md +286 -0
  151. package/specs/HARNESS-SKILL-CONTRACT.md +93 -0
  152. package/specs/HARNESS-STANDARD.md +488 -0
  153. package/specs/SPEC-TEMPLATE.md +53 -0
  154. package/specs/bootstrap-data-flow.png +0 -0
  155. package/specs/harness-automation-matrix.md +314 -0
  156. package/specs/harness-automation-matrix.rules.json +64 -0
  157. package/test/anti.test.ts +80 -0
  158. package/test/contract-negative.test.ts +86 -0
  159. package/test/contract.test.ts +158 -0
  160. package/test/external-deps.test.ts +48 -0
  161. package/test/fixtures/golden-project/.env.example +3 -0
  162. package/test/fixtures/golden-project/Makefile +7 -0
  163. package/test/fixtures/golden-project/docs/adr/ADR-001-framework.md +23 -0
  164. package/test/fixtures/golden-project/docs/setup-guide.md +10 -0
  165. package/test/fixtures/golden-project/package.json +10 -0
  166. package/test/fixtures/golden-project/specs/api-spec.md +20 -0
  167. package/test/fixtures/golden-project/src/auth.ts +8 -0
  168. package/test/fixtures/golden-project/src/db.ts +11 -0
  169. package/test/fixtures/golden-project/src/index.ts +19 -0
  170. package/test/fixtures/golden-project/src/utils/format.ts +3 -0
  171. package/test/fixtures/golden-project/test/auth.test.ts +15 -0
  172. package/test/fixtures/golden-project/tsconfig.json +12 -0
  173. package/test/meta-sc-coverage.test.ts +159 -0
  174. package/test/phase-0.test.ts +846 -0
  175. package/test/phase-1.test.ts +617 -0
  176. package/test/phase-2.test.ts +620 -0
  177. package/test/phase-3.test.ts +99 -0
  178. package/test/scaffold-conformity.test.ts +8 -0
  179. package/test/schema-canary.test.ts +51 -0
  180. package/test/spec-compliance-auto.test.ts +64 -0
  181. package/test/spec-compliance.test.ts +295 -0
  182. package/test/spec-discovery.test.ts +68 -0
  183. package/test/spec-drift.test.ts +5 -0
  184. package/test/structure.test.ts +165 -0
  185. package/test/unit/agent-brief-guard-ship.test.ts +293 -0
  186. package/test/unit/extract-constraints.test.ts +145 -0
  187. package/test/unit/issue-close-guard.test.ts +204 -0
  188. package/test/unit/scaffold-project.test.ts +417 -0
  189. package/test/unit/skill-cooccurrence.test.ts +177 -0
  190. package/test/unit/skill-sequence-logger.test.ts +244 -0
  191. package/test/unit/workflow-state-guard.test.ts +95 -0
  192. package/workflows/batch-ship.js +295 -0
  193. package/workflows/council.js +481 -0
  194. package/workflows/prove.js +560 -0
  195. package/workflows/ship.js +789 -0
  196. package/workflows/verify.js +236 -0
@@ -0,0 +1,560 @@
1
+ export const meta = {
2
+ name: 'prove',
3
+ description: 'Standalone verification: prove a fix solves the user problem. GOAL → VERIFY-DEPLOYED → VALIDATE → VERDICT → OUTPUT',
4
+ whenToUse: 'After /ship to prove the fix works. Standalone on any issue. Replaces reading prove SKILL.md manually.',
5
+ phases: [
6
+ { title: 'Goal', detail: 'Read issue, extract what was fixed, load chain context' },
7
+ { title: 'Verify-Deployed', detail: 'Confirm fix commit is on main' },
8
+ { title: 'Validate', detail: 'Spawn B3 reproducer + optional Quinn for UI' },
9
+ { title: 'Verdict', detail: 'Mechanical verdict from criteriaResults' },
10
+ { title: 'Output', detail: 'Write prove-evidence.json, post proof comment, add label, telemetry' },
11
+ ],
12
+ }
13
+
14
+ // ── Structured output schemas ────────────────────────────────
15
+
16
+ const PROVE_EVIDENCE_SCHEMA = {
17
+ type: 'object',
18
+ properties: {
19
+ issueNumber: { type: 'number' },
20
+ verdict: { type: 'string', enum: ['PROVEN', 'UNPROVEN', 'INCONCLUSIVE'] },
21
+ commitSHA: { type: 'string' },
22
+ capturedAt: { type: 'string' },
23
+ criteriaResults: {
24
+ type: 'array',
25
+ items: {
26
+ type: 'object',
27
+ properties: {
28
+ scId: { type: 'string' },
29
+ verdict: { type: 'string', enum: ['PASS', 'FAIL', 'SKIP'] },
30
+ evidence: { type: 'string' },
31
+ },
32
+ required: ['scId', 'verdict'],
33
+ },
34
+ },
35
+ reproduced: { type: 'boolean' },
36
+ },
37
+ required: ['issueNumber', 'verdict', 'commitSHA', 'criteriaResults'],
38
+ }
39
+
40
+ const ISSUE_SCHEMA = {
41
+ type: 'object',
42
+ properties: {
43
+ issueGoal: { type: 'string' },
44
+ issueTitle: { type: 'string' },
45
+ issueBody: { type: 'string' },
46
+ labels: { type: 'array', items: { type: 'string' } },
47
+ successCriteria: { type: 'array', items: { type: 'string' } },
48
+ hasUIACs: { type: 'boolean' },
49
+ },
50
+ required: ['issueGoal', 'issueTitle', 'issueBody'],
51
+ }
52
+
53
+ const DEPLOY_CHECK_SCHEMA = {
54
+ type: 'object',
55
+ properties: {
56
+ deployed: { type: 'boolean' },
57
+ commitSHA: { type: 'string' },
58
+ branch: { type: 'string' },
59
+ reason: { type: 'string' },
60
+ },
61
+ required: ['deployed', 'commitSHA'],
62
+ }
63
+
64
+ const REPRODUCER_SCHEMA = {
65
+ type: 'object',
66
+ properties: {
67
+ verdict: { type: 'string', enum: ['PROVEN', 'UNPROVEN', 'INCONCLUSIVE'] },
68
+ criteriaResults: {
69
+ type: 'array',
70
+ items: {
71
+ type: 'object',
72
+ properties: {
73
+ scId: { type: 'string' },
74
+ verdict: { type: 'string', enum: ['PASS', 'FAIL', 'SKIP'] },
75
+ evidence: { type: 'string' },
76
+ },
77
+ required: ['scId', 'verdict'],
78
+ },
79
+ },
80
+ reproduced: { type: 'boolean' },
81
+ gaps: { type: 'array', items: { type: 'string' } },
82
+ quinnNeeded: { type: 'array', items: { type: 'string' } },
83
+ },
84
+ required: ['verdict', 'criteriaResults', 'reproduced'],
85
+ }
86
+
87
+ const QUINN_SCHEMA = {
88
+ type: 'object',
89
+ properties: {
90
+ verdict: { type: 'string', enum: ['PASS', 'FAIL'] },
91
+ findings: { type: 'array', items: { type: 'string' } },
92
+ criteriaResults: {
93
+ type: 'array',
94
+ items: {
95
+ type: 'object',
96
+ properties: {
97
+ scId: { type: 'string' },
98
+ verdict: { type: 'string', enum: ['PASS', 'FAIL', 'SKIP'] },
99
+ evidence: { type: 'string' },
100
+ },
101
+ required: ['scId', 'verdict'],
102
+ },
103
+ },
104
+ },
105
+ required: ['verdict'],
106
+ }
107
+
108
+ // ── Args ─────────────────────────────────────────────────────
109
+
110
+ let parsedArgs = args || {}
111
+ if (typeof parsedArgs === 'string') {
112
+ try { parsedArgs = JSON.parse(parsedArgs) } catch { parsedArgs = {} }
113
+ }
114
+
115
+ if (!parsedArgs.issue) {
116
+ return { status: 'ARGS_ERROR', message: 'Usage: Workflow({ name: "prove", args: { issue: N, projectRoot: "/path" } })' }
117
+ }
118
+
119
+ const ISSUE = parsedArgs.issue
120
+ const REPO = parsedArgs.repo || 'hornjason/asaCommandCenter'
121
+ const ISSUE_REPO = parsedArgs.issueRepo || REPO
122
+ const PROJECT_ROOT = parsedArgs.projectRoot || ''
123
+ if (!parsedArgs.harnessRoot) return { status: 'ARGS_ERROR', message: 'harnessRoot is required' }
124
+ const HARNESS_ROOT = parsedArgs.harnessRoot
125
+ const HOME = parsedArgs.home || PROJECT_ROOT.split('/Projects/')[0] || process.env.HOME || ''
126
+ const SLUG = parsedArgs.slug || `ddb-${ISSUE}`
127
+ const WORK_DIR = `${process.env.RUNGATE_WORK_DIR || `${HOME}/.rungate`}/${SLUG}`
128
+ const PROVE_PROMPT = `${HARNESS_ROOT}/gates/prompts/prove-reproducer.md`
129
+
130
+ // ── Chain detection ──────────────────────────────────────────
131
+
132
+ const GOAL_RECORD_PATH = `${WORK_DIR}/goal-record.json`
133
+ const SHIP_EVIDENCE_PATH = `${WORK_DIR}/ship-evidence.json`
134
+
135
+ // ════════════════════════════════════════════════════════════
136
+ // PHASE 1: GOAL — Read issue, extract what was fixed
137
+ // ════════════════════════════════════════════════════════════
138
+
139
+ phase('Goal')
140
+ log(`Prove #${ISSUE}: reading issue and chain context`)
141
+
142
+ const issueData = await agent(`
143
+ Read this GitHub issue and extract the goal:
144
+ gh issue view ${ISSUE} --repo ${ISSUE_REPO} --json title,body,labels
145
+
146
+ Also check for chain artifacts:
147
+ 1. test -f ${GOAL_RECORD_PATH} && echo "GOAL_RECORD: exists" || echo "GOAL_RECORD: none"
148
+ 2. test -f ${SHIP_EVIDENCE_PATH} && echo "SHIP_EVIDENCE: exists" || echo "SHIP_EVIDENCE: none"
149
+
150
+ If goal-record.json exists, read it and extract the structured SCs.
151
+ If ship-evidence.json exists, read it and extract mergeCommitSha.
152
+
153
+ Extract:
154
+ 1. issueGoal — main goal statement
155
+ 2. issueTitle — the title
156
+ 3. issueBody — full body text
157
+ 4. labels — label names
158
+ 5. successCriteria — each SC/AC (from goal-record.json if chain mode, else from issue body)
159
+ 6. hasUIACs — true if any AC mentions UI, screenshot, visual, page, component, render
160
+ `, { label: 'read-issue', phase: 'Goal', schema: ISSUE_SCHEMA })
161
+
162
+ if (!issueData) return { status: 'GOAL_FAILED', message: `Could not read issue #${ISSUE}` }
163
+ log(`Goal: "${issueData.issueTitle}" — UI ACs: ${issueData.hasUIACs ? 'yes' : 'no'}`)
164
+
165
+ // ════════════════════════════════════════════════════════════
166
+ // PHASE 2: VERIFY-DEPLOYED — Confirm fix is on main
167
+ // ════════════════════════════════════════════════════════════
168
+
169
+ phase('Verify-Deployed')
170
+ log('Checking fix is deployed to main')
171
+
172
+ const deployCheck = await agent(`
173
+ Verify the fix for issue #${ISSUE} is on main:
174
+
175
+ 1. Check for ship-evidence.json: test -f ${SHIP_EVIDENCE_PATH}
176
+ If it exists, read it and extract mergeCommitSha.
177
+
178
+ 2. If mergeCommitSha exists:
179
+ cd ${PROJECT_ROOT || '.'} && git branch --contains <sha> | grep -q main && echo "ON_MAIN" || echo "NOT_ON_MAIN"
180
+
181
+ 3. If no mergeCommitSha (standalone mode):
182
+ cd ${PROJECT_ROOT || '.'} && git log --oneline --all --grep="#${ISSUE}" | head -5
183
+ Use the latest commit SHA found.
184
+ Verify it's on main: git branch --contains <sha> | grep -q main
185
+
186
+ 4. Get current HEAD:
187
+ cd ${PROJECT_ROOT || '.'} && git rev-parse HEAD
188
+
189
+ Report: deployed (boolean), commitSHA (the fix commit or HEAD), branch, reason.
190
+ `, { label: 'deploy-check', phase: 'Verify-Deployed', schema: DEPLOY_CHECK_SCHEMA })
191
+
192
+ if (!deployCheck || !deployCheck.deployed) {
193
+ log(`VERIFY-DEPLOYED FAILED: ${deployCheck?.reason || 'fix not on main'}`)
194
+ return {
195
+ status: 'DEPLOY_FAILED',
196
+ issue: ISSUE, slug: SLUG,
197
+ reason: deployCheck?.reason || 'Fix commit not found on main',
198
+ workDir: WORK_DIR,
199
+ }
200
+ }
201
+
202
+ const COMMIT_SHA = deployCheck.commitSHA || 'unknown'
203
+ log(`Fix deployed: ${COMMIT_SHA.slice(0, 8)} on main`)
204
+
205
+ // ════════════════════════════════════════════════════════════
206
+ // PHASE 3: VALIDATE — Spawn B3 reproducer + optional Quinn
207
+ // ════════════════════════════════════════════════════════════
208
+
209
+ phase('Validate')
210
+
211
+ // Ensure dev server is running for OUTCOME AC evidence collection
212
+ if (PROJECT_ROOT) {
213
+ log('Checking dev server availability')
214
+ await agent(`
215
+ Check if the dev server is running. Read ${PROJECT_ROOT}/.claude/rungate.json to get dev.apiBase and dev.start.
216
+
217
+ 1. Try: curl -sf $(dev.apiBase)/api/health -o /dev/null && echo "DEV_UP" || echo "DEV_DOWN"
218
+ 2. If DEV_DOWN and dev.start exists:
219
+ - Run: cd ${PROJECT_ROOT} && $(dev.start) &
220
+ - Wait 10 seconds, then retry the health check
221
+ - Report: started (boolean), apiBase, command used
222
+ 3. If DEV_UP: report already running
223
+
224
+ Report the dev server status.
225
+ `, { label: 'ensure-dev-server', phase: 'Validate' })
226
+ }
227
+
228
+ log('Spawning B3 Prove Reproducer')
229
+
230
+ // Read before-state context for the reproducer
231
+ const beforeContext = await agent(`
232
+ Check for before-state evidence:
233
+ 1. test -f ${WORK_DIR}/workflow-state.json && echo "WF_STATE: exists" || echo "WF_STATE: none"
234
+ 2. If workflow-state.json exists, read it and extract beforeState field.
235
+ 3. Read the issue body for reproduction steps.
236
+
237
+ Check project harness for API/UI bases:
238
+ 4. test -f ${PROJECT_ROOT}/.claude/rungate.json && cat ${PROJECT_ROOT}/.claude/rungate.json || echo "NO_HARNESS"
239
+
240
+ Report the before-state description, reproduction steps, apiBase, and uiBase.
241
+ Return as a string summary.
242
+ `, { label: 'before-context', phase: 'Validate' })
243
+
244
+ // Spawn B3 reproducer agent
245
+ const reproducerResult = await agent(`
246
+ You are a prove reproducer for issue #${ISSUE}.
247
+ Read the prove reproducer prompt at ${PROVE_PROMPT} for your full instructions.
248
+
249
+ ## Issue
250
+ Title: ${issueData.issueTitle}
251
+ Body (first 2000 chars): ${(issueData.issueBody || '').slice(0, 2000)}
252
+
253
+ ## Success Criteria
254
+ ${(issueData.successCriteria || []).map((sc, i) => `${i + 1}. ${sc}`).join('\n') || 'Derive from issue body'}
255
+
256
+ ## Before State
257
+ ${beforeContext || 'No before-state captured. Derive from issue description.'}
258
+
259
+ ## Fix Commit
260
+ ${COMMIT_SHA}
261
+
262
+ ## Environment
263
+ Project root: ${PROJECT_ROOT || 'not set'}
264
+
265
+ ## Instructions
266
+ 1. Read ${PROVE_PROMPT} for your full protocol.
267
+ 2. For CODE ACs: run evidence commands (grep, bun test, curl) against current code.
268
+ 3. For UI/OUTCOME ACs: output SKIP with reason "B3 limitation: no browser tools — requires Quinn".
269
+ 4. Compare before-state against current after-state.
270
+ 5. Capture real evidence for each criterion.
271
+
272
+ Output your verdict, criteriaResults, reproduced, gaps, and quinnNeeded (list of AC IDs needing Quinn).
273
+ `, { label: 'b3-reproducer', phase: 'Validate', schema: REPRODUCER_SCHEMA })
274
+
275
+ let allCriteriaResults = reproducerResult?.criteriaResults || []
276
+ let quinnResults = null
277
+
278
+ // Spawn Quinn for UI ACs if needed
279
+ const needsQuinn = issueData.hasUIACs ||
280
+ (reproducerResult?.quinnNeeded && reproducerResult.quinnNeeded.length > 0)
281
+
282
+ if (needsQuinn) {
283
+ log('UI ACs detected — starting prove container with prod data, then spawning Quinn')
284
+
285
+ // Start prove container with prod data (make prove-up = build + rsync prod data + start on :7776)
286
+ await agent(`
287
+ You have ONE task: start the prove container with prod data. Run this EXACT command and report the output:
288
+
289
+ cd ${PROJECT_ROOT} && make prove-up 2>&1 | tail -20
290
+
291
+ This rebuilds the container image, rsyncs prod data to data-test/, and starts the container on port 7776.
292
+ After it completes, verify the container is up: curl -s -o /dev/null -w "%{http_code}" http://localhost:7776/api/aes
293
+ Report the output.
294
+ `, { label: 'prove-container-up', phase: 'Validate' })
295
+
296
+ const quinnACs = (reproducerResult?.quinnNeeded || []).join(', ') ||
297
+ (issueData.successCriteria || []).filter(sc =>
298
+ /ui|screenshot|visual|page|component|render|display|show/i.test(sc)
299
+ ).join('\n')
300
+
301
+ quinnResults = await agent(`
302
+ You are Quinn Torres, QA specialist. You have Playwright MCP tools available.
303
+
304
+ ## Issue #${ISSUE}: ${issueData.issueTitle}
305
+ Fix commit: ${COMMIT_SHA}
306
+
307
+ ## Available Playwright MCP Tools (use these, NOT manual browser)
308
+ - browser_navigate(url) — go to URL
309
+ - browser_snapshot() — get accessibility tree (text, fast, preferred over screenshots)
310
+ - browser_click(element) — click by ref from snapshot
311
+ - browser_type(element, text) — type text into element
312
+ - browser_take_screenshot() — capture PNG evidence
313
+ - browser_verify_text_visible(text) — assert text on page
314
+
315
+ ## Target URLs
316
+ Read ${PROJECT_ROOT}/.claude/rungate.json for page paths.
317
+ Prove container base: http://localhost:7776
318
+
319
+ ## ACs to verify (UI/OUTCOME — skipped by B3)
320
+ ${quinnACs}
321
+
322
+ ## Test Plan for #${ISSUE} on PROVE CONTAINER
323
+ 1. Verify fix deployed: cd ${PROJECT_ROOT} && git rev-parse --short HEAD should match ${COMMIT_SHA.slice(0, 8)}
324
+ 2. For each AC:
325
+ a. browser_navigate("http://localhost:7776" + page path from rungate.json)
326
+ b. browser_snapshot() — verify page loaded
327
+ c. Perform action (browser_click, browser_type, etc.)
328
+ d. browser_snapshot() or browser_verify_text_visible() to verify
329
+ e. browser_take_screenshot() for evidence
330
+ 3. Test as a brand-new user — use a customer that HAS contacts (prod data on :7776)
331
+ 4. Report PASS/FAIL per AC with tool output as evidence
332
+
333
+ IMPORTANT: Test on port 7776 (prove container with prod data), NOT dev server (port 5173/7778).
334
+ Report verdict and criteriaResults.
335
+ `, { label: 'quinn-prove', phase: 'Validate', schema: QUINN_SCHEMA })
336
+
337
+ // Merge Quinn results into allCriteriaResults (replace SKIPs from B3)
338
+ if (quinnResults?.criteriaResults) {
339
+ const quinnMap = new Map(quinnResults.criteriaResults.map(cr => [cr.scId, cr]))
340
+ allCriteriaResults = allCriteriaResults.map(cr => {
341
+ if (cr.verdict === 'SKIP' && quinnMap.has(cr.scId)) {
342
+ return quinnMap.get(cr.scId)
343
+ }
344
+ return cr
345
+ })
346
+ // Add any Quinn results for ACs not in B3 output
347
+ for (const qr of quinnResults.criteriaResults) {
348
+ if (!allCriteriaResults.some(cr => cr.scId === qr.scId)) {
349
+ allCriteriaResults.push(qr)
350
+ }
351
+ }
352
+ }
353
+ log(`Quinn: ${quinnResults?.verdict || 'no result'}`)
354
+ }
355
+
356
+ // ════════════════════════════════════════════════════════════
357
+ // PHASE 4: VERDICT — Mechanical computation + self-heal loop
358
+ // ════════════════════════════════════════════════════════════
359
+
360
+ phase('Verdict')
361
+
362
+ const MAX_SELF_HEAL_ATTEMPTS = 3
363
+
364
+ function computeVerdict(criteriaResults) {
365
+ const fc = criteriaResults.filter(cr => cr.verdict === 'FAIL').length
366
+ const psc = criteriaResults.filter(cr => cr.verdict === 'PASS' || cr.verdict === 'SKIP').length
367
+ let v
368
+ if (criteriaResults.length === 0) {
369
+ v = 'INCONCLUSIVE'
370
+ } else if (fc > 0) {
371
+ v = 'UNPROVEN'
372
+ } else {
373
+ v = 'PROVEN'
374
+ }
375
+ return { verdict: v, failCount: fc, passSkipCount: psc }
376
+ }
377
+
378
+ let { verdict, failCount, passSkipCount } = computeVerdict(allCriteriaResults)
379
+ log(`Verdict: ${verdict} — ${passSkipCount} PASS/SKIP, ${failCount} FAIL, ${allCriteriaResults.length} total`)
380
+
381
+ // ── Self-heal loop: on UNPROVEN, spawn Marcus to fix, re-prove ──
382
+ let selfHealIteration = 0
383
+
384
+ while (verdict === 'UNPROVEN' && selfHealIteration < MAX_SELF_HEAL_ATTEMPTS) {
385
+ selfHealIteration++
386
+ log(`Self-heal iteration ${selfHealIteration}/${MAX_SELF_HEAL_ATTEMPTS} — spawning fix agent`)
387
+
388
+ const failedCriteria = allCriteriaResults.filter(cr => cr.verdict === 'FAIL')
389
+ const failSummary = failedCriteria.map(cr => `${cr.scId}: ${cr.evidence || 'FAIL'}`).join('\n')
390
+
391
+ // Spawn Marcus to fix the failures
392
+ await agent(`
393
+ You are Marcus Webb, senior engineer. Prove found UNPROVEN criteria for issue #${ISSUE}.
394
+
395
+ ## Failed Criteria (iteration ${selfHealIteration}/${MAX_SELF_HEAL_ATTEMPTS})
396
+ ${failSummary}
397
+
398
+ ## Issue
399
+ Title: ${issueData.issueTitle}
400
+ Body (first 2000 chars): ${(issueData.issueBody || '').slice(0, 2000)}
401
+
402
+ ## Instructions
403
+ 1. Read the failed criteria above.
404
+ 2. cd ${PROJECT_ROOT || '.'} and investigate why each criterion failed.
405
+ 3. Fix the code to address each failure.
406
+ 4. Run tests: bun test, tsc --noEmit.
407
+ 5. Commit and push the fix: git add -A && git commit -m "fix(#${ISSUE}): prove self-heal iteration ${selfHealIteration}" && git push
408
+
409
+ Report what you fixed and evidence that each failed criterion is now addressed.
410
+ `, { label: `self-heal-fix-${selfHealIteration}`, phase: 'Verdict', agentType: 'Engineer' })
411
+
412
+ log(`Self-heal fix ${selfHealIteration} complete — re-validating`)
413
+
414
+ // Re-run B3 reproducer to check if fixes resolved the failures
415
+ const revalidateResult = await agent(`
416
+ You are a prove reproducer for issue #${ISSUE} (self-heal re-validation, iteration ${selfHealIteration}).
417
+
418
+ ## Issue
419
+ Title: ${issueData.issueTitle}
420
+ Body (first 2000 chars): ${(issueData.issueBody || '').slice(0, 2000)}
421
+
422
+ ## Success Criteria
423
+ ${(issueData.successCriteria || []).map((sc, i) => `${i + 1}. ${sc}`).join('\n') || 'Derive from issue body'}
424
+
425
+ ## Previously Failed Criteria
426
+ ${failSummary}
427
+
428
+ ## Fix Commit
429
+ Run: cd ${PROJECT_ROOT || '.'} && git rev-parse --short HEAD
430
+
431
+ ## Instructions
432
+ 1. For CODE ACs: run evidence commands (grep, bun test, curl) against current code.
433
+ 2. For UI/OUTCOME ACs: output SKIP with reason "B3 limitation: no browser tools — requires Quinn".
434
+ 3. Focus on the previously failed criteria — verify the fix resolved them.
435
+
436
+ Output your verdict, criteriaResults, reproduced, gaps.
437
+ `, { label: `self-heal-validate-${selfHealIteration}`, phase: 'Verdict', schema: REPRODUCER_SCHEMA })
438
+
439
+ if (revalidateResult?.criteriaResults) {
440
+ allCriteriaResults = revalidateResult.criteriaResults
441
+ }
442
+
443
+ const recomputed = computeVerdict(allCriteriaResults)
444
+ verdict = recomputed.verdict
445
+ failCount = recomputed.failCount
446
+ passSkipCount = recomputed.passSkipCount
447
+
448
+ log(`Self-heal iteration ${selfHealIteration} verdict: ${verdict} — ${passSkipCount} PASS/SKIP, ${failCount} FAIL`)
449
+ }
450
+
451
+ if (selfHealIteration >= MAX_SELF_HEAL_ATTEMPTS && verdict === 'UNPROVEN') {
452
+ log(`CIRCUIT BREAKER: prove self-heal exhausted ${MAX_SELF_HEAL_ATTEMPTS} iterations — still UNPROVEN`)
453
+ }
454
+
455
+ // ════════════════════════════════════════════════════════════
456
+ // PHASE 5: OUTPUT — Write evidence, post comment, label, telemetry
457
+ // ════════════════════════════════════════════════════════════
458
+
459
+ phase('Output')
460
+
461
+ const proveEvidence = {
462
+ contractVersion: '1.0',
463
+ issueNumber: ISSUE,
464
+ verdict,
465
+ commitSHA: COMMIT_SHA,
466
+ capturedAt: 'AGENT_FILL_TIMESTAMP',
467
+ criteriaResults: allCriteriaResults,
468
+ reproduced: reproducerResult?.reproduced ?? false,
469
+ source: 'prove-workflow',
470
+ }
471
+
472
+ // Write prove-evidence.json
473
+ await agent(`
474
+ mkdir -p ${WORK_DIR}
475
+ Write this JSON to ${WORK_DIR}/prove-evidence.json using the Write tool.
476
+ Replace the capturedAt value "AGENT_FILL_TIMESTAMP" with the current ISO timestamp (run: date -u +%Y-%m-%dT%H:%M:%SZ).
477
+
478
+ ${JSON.stringify(proveEvidence, null, 2)}
479
+ `, { label: 'write-evidence', phase: 'Output' })
480
+
481
+ log('prove-evidence.json written')
482
+
483
+ // Post proof comment to issue
484
+ const proofComment = [
485
+ '## Proof',
486
+ '',
487
+ `- **Fix:** commit ${COMMIT_SHA.slice(0, 8)}`,
488
+ `- **Reproduced:** ${proveEvidence.reproduced ? 'yes' : 'no'}`,
489
+ ...allCriteriaResults.map(cr => `- **${cr.scId}:** ${cr.verdict}${cr.evidence ? ' — ' + cr.evidence.slice(0, 100) : ''}`),
490
+ quinnResults ? `- **Quinn:** ${quinnResults.verdict}` : '',
491
+ `- **Verdict:** ${verdict}`,
492
+ ].filter(Boolean).join('\n')
493
+
494
+ await agent(`
495
+ Post this comment to issue #${ISSUE}:
496
+ gh issue comment ${ISSUE} --repo ${ISSUE_REPO} --body ${JSON.stringify(proofComment)}
497
+ `, { label: 'post-comment', phase: 'Output' })
498
+
499
+ log('Proof comment posted')
500
+
501
+ // Add proven label + close issue (chain mode only) if PROVEN
502
+ if (verdict === 'PROVEN') {
503
+ const chainMode = await agent(`
504
+ test -f ${GOAL_RECORD_PATH} && echo "CHAIN" || echo "STANDALONE"
505
+ `, { label: 'chain-check', phase: 'Output' })
506
+
507
+ await agent(`
508
+ Add the "proven" label to issue #${ISSUE}:
509
+ gh issue edit ${ISSUE} --repo ${ISSUE_REPO} --add-label "proven" 2>&1 || echo "label add failed"
510
+
511
+ ${String(chainMode).includes('CHAIN') ? `
512
+ Also close the issue (chain mode — goal-record.json exists):
513
+ gh issue close ${ISSUE} --repo ${ISSUE_REPO} 2>&1 || echo "close failed"
514
+ gh issue comment ${ISSUE} --repo ${ISSUE_REPO} --body "Issue closed by /prove — verdict: PROVEN"
515
+ ` : '# Standalone mode — do NOT close the issue'}
516
+ `, { label: 'label-close', phase: 'Output' })
517
+
518
+ log(String(chainMode).includes('CHAIN') ? 'Issue labeled + closed (chain mode)' : 'Issue labeled proven (standalone)')
519
+ } else if (verdict === 'UNPROVEN') {
520
+ await agent(`
521
+ Post a re-investigation comment:
522
+ gh issue comment ${ISSUE} --repo ${ISSUE_REPO} --body "Prove verdict: UNPROVEN — issue remains open for re-investigation"
523
+ `, { label: 'unproven-comment', phase: 'Output' })
524
+ log('UNPROVEN — issue remains open')
525
+ } else {
526
+ await agent(`
527
+ Post an inconclusive comment:
528
+ gh issue comment ${ISSUE} --repo ${ISSUE_REPO} --body "Prove verdict: INCONCLUSIVE — could not reproduce. Manual investigation needed."
529
+ `, { label: 'inconclusive-comment', phase: 'Output' })
530
+ log('INCONCLUSIVE — manual investigation needed')
531
+ }
532
+
533
+ // Telemetry — agent handles timestamps since workflow sandbox bans Date.now()
534
+ await agent(`
535
+ Append a telemetry entry to ${HOME}/.claude/MEMORY/LEARNING/SIGNALS/harness-telemetry.jsonl.
536
+ Use Bash to echo a single JSON line with: ts (current ISO timestamp), skill: "prove", issue: ${ISSUE}, check: "verdict", result: "${verdict}".
537
+ Create the directory if it doesn't exist: mkdir -p ${HOME}/.claude/MEMORY/LEARNING/SIGNALS
538
+ `, { label: 'telemetry', phase: 'Output' })
539
+
540
+ log(`Telemetry logged — prove #${ISSUE}: ${verdict}`)
541
+
542
+ // Cleanup: stop prove container
543
+ await agent(`
544
+ Run: cd ${PROJECT_ROOT} && make prove-down 2>&1 || true
545
+ Report output.
546
+ `, { label: 'prove-container-down', phase: 'Output' })
547
+
548
+ return {
549
+ status: verdict,
550
+ issue: ISSUE,
551
+ slug: SLUG,
552
+ verdict,
553
+ commitSHA: COMMIT_SHA,
554
+ criteriaResults: allCriteriaResults,
555
+ reproduced: proveEvidence.reproduced,
556
+ quinnVerdict: quinnResults?.verdict || null,
557
+ selfHealIterations: selfHealIteration,
558
+ circuitBroken: selfHealIteration >= MAX_SELF_HEAL_ATTEMPTS && verdict === 'UNPROVEN',
559
+ workDir: WORK_DIR,
560
+ }