maestro-flow 0.4.19 → 0.4.21

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 (163) hide show
  1. package/.agents/agents/workflow-collab-planner.md +4 -1
  2. package/.agents/agents/workflow-plan-checker.md +11 -1
  3. package/.agents/agents/workflow-planner.md +4 -1
  4. package/.agents/skills/maestro/SKILL.md +8 -5
  5. package/.agents/skills/maestro-analyze/SKILL.md +1 -1
  6. package/.agents/skills/maestro-brainstorm/SKILL.md +2 -1
  7. package/.agents/skills/maestro-companion/SKILL.md +533 -0
  8. package/.agents/skills/maestro-grill/SKILL.md +116 -0
  9. package/.agents/skills/maestro-plan/SKILL.md +4 -0
  10. package/.agents/skills/maestro-ralph/SKILL.md +11 -7
  11. package/.agents/skills/maestro-ralph-execute/SKILL.md +2 -1
  12. package/.agents/skills/maestro-swarm-workflow/SKILL.md +266 -0
  13. package/.agents/skills/maestro-universal-workflow/SKILL.md +563 -0
  14. package/.agents/skills/manage-codebase-rebuild/SKILL.md +13 -1
  15. package/.agents/skills/manage-codebase-refresh/SKILL.md +3 -0
  16. package/.agents/skills/spec-setup/SKILL.md +9 -5
  17. package/.agents/skills/team-adversarial-swarm/SKILL.md +235 -0
  18. package/.agents/skills/team-adversarial-swarm/scripts/aco.py +473 -0
  19. package/.agents/skills/team-adversarial-swarm/scripts/pheromone.py +144 -0
  20. package/.agents/skills/team-adversarial-swarm/scripts/scoring.py +92 -0
  21. package/.agents/skills/team-adversarial-swarm/scripts/test_aco.py +475 -0
  22. package/.agents/skills/team-adversarial-swarm/specs/ant-output-schema.md +115 -0
  23. package/.agents/skills/team-adversarial-swarm/specs/convergence-criteria.md +75 -0
  24. package/.agents/skills/team-adversarial-swarm/specs/pheromone-schema.md +90 -0
  25. package/.agents/skills/team-adversarial-swarm/specs/swarm-config-template.json +66 -0
  26. package/.agents/skills/team-adversarial-swarm/specs/swarm-protocol.md +105 -0
  27. package/.agents/skills/team-adversarial-swarm/workflows/wf-swarm-converge.js +197 -0
  28. package/.agents/skills/team-adversarial-swarm/workflows/wf-swarm-explore.js +194 -0
  29. package/.agents/skills/team-adversarial-swarm/workflows/wf-swarm-score.js +188 -0
  30. package/.agents/skills/team-adversarial-swarm/workflows/wf-swarm-synthesize.js +248 -0
  31. package/.agy/agents/workflow-collab-planner.md +4 -1
  32. package/.agy/agents/workflow-plan-checker.md +11 -1
  33. package/.agy/agents/workflow-planner.md +4 -1
  34. package/.agy/skills/maestro/SKILL.md +8 -5
  35. package/.agy/skills/maestro-analyze/SKILL.md +1 -1
  36. package/.agy/skills/maestro-brainstorm/SKILL.md +2 -1
  37. package/.agy/skills/maestro-companion/SKILL.md +529 -0
  38. package/.agy/skills/maestro-grill/SKILL.md +116 -0
  39. package/.agy/skills/maestro-plan/SKILL.md +4 -0
  40. package/.agy/skills/maestro-ralph/SKILL.md +11 -7
  41. package/.agy/skills/maestro-ralph-execute/SKILL.md +2 -1
  42. package/.agy/skills/maestro-swarm-workflow/SKILL.md +263 -0
  43. package/.agy/skills/maestro-universal-workflow/SKILL.md +560 -0
  44. package/.agy/skills/manage-codebase-rebuild/SKILL.md +13 -1
  45. package/.agy/skills/manage-codebase-refresh/SKILL.md +3 -0
  46. package/.agy/skills/spec-setup/SKILL.md +9 -5
  47. package/.agy/skills/team-adversarial-swarm/SKILL.md +244 -0
  48. package/.agy/skills/team-adversarial-swarm/scripts/aco.py +473 -0
  49. package/.agy/skills/team-adversarial-swarm/scripts/pheromone.py +144 -0
  50. package/.agy/skills/team-adversarial-swarm/scripts/scoring.py +92 -0
  51. package/.agy/skills/team-adversarial-swarm/scripts/test_aco.py +475 -0
  52. package/.agy/skills/team-adversarial-swarm/specs/ant-output-schema.md +115 -0
  53. package/.agy/skills/team-adversarial-swarm/specs/convergence-criteria.md +75 -0
  54. package/.agy/skills/team-adversarial-swarm/specs/pheromone-schema.md +90 -0
  55. package/.agy/skills/team-adversarial-swarm/specs/swarm-config-template.json +66 -0
  56. package/.agy/skills/team-adversarial-swarm/specs/swarm-protocol.md +105 -0
  57. package/.agy/skills/team-adversarial-swarm/workflows/wf-swarm-converge.js +197 -0
  58. package/.agy/skills/team-adversarial-swarm/workflows/wf-swarm-explore.js +194 -0
  59. package/.agy/skills/team-adversarial-swarm/workflows/wf-swarm-score.js +188 -0
  60. package/.agy/skills/team-adversarial-swarm/workflows/wf-swarm-synthesize.js +248 -0
  61. package/.claude/agents/workflow-collab-planner.md +4 -1
  62. package/.claude/agents/workflow-plan-checker.md +11 -1
  63. package/.claude/agents/workflow-planner.md +4 -1
  64. package/.claude/commands/maestro-analyze.md +1 -1
  65. package/.claude/commands/maestro-brainstorm.md +2 -1
  66. package/.claude/commands/maestro-companion.md +531 -0
  67. package/.claude/commands/maestro-grill.md +114 -0
  68. package/.claude/commands/maestro-plan.md +4 -0
  69. package/.claude/commands/maestro-ralph-execute.md +2 -1
  70. package/.claude/commands/maestro-ralph.md +11 -7
  71. package/.claude/commands/maestro-swarm-workflow.md +264 -0
  72. package/.claude/commands/maestro-universal-workflow.md +561 -0
  73. package/.claude/commands/maestro.md +8 -5
  74. package/.claude/commands/manage-codebase-rebuild.md +13 -1
  75. package/.claude/commands/manage-codebase-refresh.md +3 -0
  76. package/.claude/commands/spec-setup.md +9 -5
  77. package/.claude/skills/team-adversarial-swarm/SKILL.md +233 -0
  78. package/.claude/skills/team-adversarial-swarm/scripts/aco.py +473 -0
  79. package/.claude/skills/team-adversarial-swarm/scripts/pheromone.py +144 -0
  80. package/.claude/skills/team-adversarial-swarm/scripts/scoring.py +92 -0
  81. package/.claude/skills/team-adversarial-swarm/scripts/test_aco.py +475 -0
  82. package/.claude/skills/team-adversarial-swarm/specs/ant-output-schema.md +115 -0
  83. package/.claude/skills/team-adversarial-swarm/specs/convergence-criteria.md +75 -0
  84. package/.claude/skills/team-adversarial-swarm/specs/pheromone-schema.md +90 -0
  85. package/.claude/skills/team-adversarial-swarm/specs/swarm-config-template.json +66 -0
  86. package/.claude/skills/team-adversarial-swarm/specs/swarm-protocol.md +105 -0
  87. package/.claude/skills/team-adversarial-swarm/workflows/wf-swarm-converge.js +197 -0
  88. package/.claude/skills/team-adversarial-swarm/workflows/wf-swarm-explore.js +194 -0
  89. package/.claude/skills/team-adversarial-swarm/workflows/wf-swarm-score.js +188 -0
  90. package/.claude/skills/team-adversarial-swarm/workflows/wf-swarm-synthesize.js +248 -0
  91. package/.codex/skills/maestro/SKILL.md +7 -2
  92. package/.codex/skills/maestro-companion/SKILL.md +485 -0
  93. package/.codex/skills/maestro-grill/SKILL.md +111 -0
  94. package/.codex/skills/maestro-ralph/SKILL.md +11 -7
  95. package/.codex/skills/manage-codebase-rebuild/SKILL.md +6 -0
  96. package/.codex/skills/manage-codebase-refresh/SKILL.md +6 -0
  97. package/dashboard/dist-server/dashboard/src/server/wiki/graph-analysis.d.ts +36 -0
  98. package/dashboard/dist-server/dashboard/src/server/wiki/graph-analysis.js +138 -2
  99. package/dashboard/dist-server/dashboard/src/server/wiki/graph-analysis.js.map +1 -1
  100. package/dashboard/dist-server/dashboard/src/server/wiki/search.js +13 -0
  101. package/dashboard/dist-server/dashboard/src/server/wiki/search.js.map +1 -1
  102. package/dashboard/dist-server/dashboard/src/server/wiki/virtual-wiki-adapters.d.ts +11 -0
  103. package/dashboard/dist-server/dashboard/src/server/wiki/virtual-wiki-adapters.js +178 -0
  104. package/dashboard/dist-server/dashboard/src/server/wiki/virtual-wiki-adapters.js.map +1 -1
  105. package/dashboard/dist-server/dashboard/src/server/wiki/wiki-indexer.d.ts +1 -0
  106. package/dashboard/dist-server/dashboard/src/server/wiki/wiki-indexer.js +39 -23
  107. package/dashboard/dist-server/dashboard/src/server/wiki/wiki-indexer.js.map +1 -1
  108. package/dashboard/dist-server/src/graph/types.d.ts +111 -0
  109. package/dashboard/dist-server/src/graph/types.js +2 -0
  110. package/dashboard/dist-server/src/graph/types.js.map +1 -0
  111. package/dist/src/cli.js +1 -0
  112. package/dist/src/cli.js.map +1 -1
  113. package/dist/src/commands/kg.d.ts +11 -0
  114. package/dist/src/commands/kg.d.ts.map +1 -0
  115. package/dist/src/commands/kg.js +486 -0
  116. package/dist/src/commands/kg.js.map +1 -0
  117. package/dist/src/graph/analyzers/fs-analyzer.d.ts +10 -0
  118. package/dist/src/graph/analyzers/fs-analyzer.d.ts.map +1 -0
  119. package/dist/src/graph/analyzers/fs-analyzer.js +959 -0
  120. package/dist/src/graph/analyzers/fs-analyzer.js.map +1 -0
  121. package/dist/src/graph/index.d.ts +6 -0
  122. package/dist/src/graph/index.d.ts.map +1 -0
  123. package/dist/src/graph/index.js +6 -0
  124. package/dist/src/graph/index.js.map +1 -0
  125. package/dist/src/graph/loader.d.ts +3 -0
  126. package/dist/src/graph/loader.d.ts.map +1 -0
  127. package/dist/src/graph/loader.js +12 -0
  128. package/dist/src/graph/loader.js.map +1 -0
  129. package/dist/src/graph/merger.d.ts +56 -0
  130. package/dist/src/graph/merger.d.ts.map +1 -0
  131. package/dist/src/graph/merger.js +896 -0
  132. package/dist/src/graph/merger.js.map +1 -0
  133. package/dist/src/graph/query.d.ts +7 -0
  134. package/dist/src/graph/query.d.ts.map +1 -0
  135. package/dist/src/graph/query.js +126 -0
  136. package/dist/src/graph/query.js.map +1 -0
  137. package/dist/src/graph/types.d.ts +112 -0
  138. package/dist/src/graph/types.d.ts.map +1 -0
  139. package/dist/src/graph/types.js +2 -0
  140. package/dist/src/graph/types.js.map +1 -0
  141. package/dist/src/tui/install-ui/KgVendorConfig.d.ts +7 -0
  142. package/dist/src/tui/install-ui/KgVendorConfig.d.ts.map +1 -0
  143. package/dist/src/tui/install-ui/KgVendorConfig.js +9 -0
  144. package/dist/src/tui/install-ui/KgVendorConfig.js.map +1 -0
  145. package/dist/src/utils/update-notices.js +23 -0
  146. package/dist/src/utils/update-notices.js.map +1 -1
  147. package/package.json +1 -1
  148. package/workflows/analyze.md +2 -1
  149. package/workflows/brainstorm.md +24 -1
  150. package/workflows/codebase-rebuild.md +141 -1
  151. package/workflows/codebase-refresh.md +20 -0
  152. package/workflows/finish-work.md +7 -2
  153. package/workflows/grill.md +513 -0
  154. package/workflows/plan.md +7 -4
  155. package/workflows/specs-setup.md +99 -3
  156. package/workflows/swarm/wf-analyze.js +347 -0
  157. package/workflows/swarm/wf-brainstorm.js +456 -0
  158. package/workflows/swarm/wf-execute.js +379 -0
  159. package/workflows/swarm/wf-grill.js +359 -0
  160. package/workflows/swarm/wf-milestone-audit.js +385 -0
  161. package/workflows/swarm/wf-plan.js +468 -0
  162. package/workflows/swarm/wf-review.js +341 -0
  163. package/workflows/swarm/wf-verify.js +395 -0
@@ -0,0 +1,385 @@
1
+ export const meta = {
2
+ name: 'wf-milestone-audit',
3
+ description: 'Parallel milestone audit with adversarial challenge and 3-vote verdict',
4
+ whenToUse: 'Accelerate maestro-milestone-audit with parallel dimension checks + adversarial challenge + 3-vote verdict',
5
+ phases: [
6
+ { title: 'Audit', detail: 'Parallel 4-dimension milestone audit' },
7
+ { title: 'Challenge', detail: 'Adversarial challenge of each audit dimension' },
8
+ { title: 'Report', detail: '3-vote adversarial verdict (strict/lenient/objective)' },
9
+ ],
10
+ }
11
+
12
+ const COVERAGE_SCHEMA = {
13
+ type: 'object',
14
+ properties: {
15
+ check_type: { type: 'string' },
16
+ passed: { type: 'boolean' },
17
+ phases: {
18
+ type: 'array',
19
+ items: {
20
+ type: 'object',
21
+ properties: {
22
+ phase: { type: 'string' },
23
+ has_plan: { type: 'boolean' },
24
+ has_execute: { type: 'boolean' },
25
+ has_verify: { type: 'boolean' },
26
+ plan_artifact_id: { type: 'string' },
27
+ execute_artifact_id: { type: 'string' },
28
+ status: { type: 'string', enum: ['complete', 'partial', 'missing'] },
29
+ },
30
+ required: ['phase', 'has_plan', 'has_execute', 'status'],
31
+ },
32
+ },
33
+ summary: { type: 'string' },
34
+ },
35
+ required: ['check_type', 'passed', 'phases', 'summary'],
36
+ }
37
+
38
+ const EXECUTION_SCHEMA = {
39
+ type: 'object',
40
+ properties: {
41
+ check_type: { type: 'string' },
42
+ passed: { type: 'boolean' },
43
+ plans: {
44
+ type: 'array',
45
+ items: {
46
+ type: 'object',
47
+ properties: {
48
+ plan_id: { type: 'string' },
49
+ plan_dir: { type: 'string' },
50
+ total_tasks: { type: 'number' },
51
+ completed_tasks: { type: 'number' },
52
+ failed_tasks: { type: 'number' },
53
+ pending_tasks: { type: 'number' },
54
+ incomplete_task_ids: { type: 'array', items: { type: 'string' } },
55
+ },
56
+ required: ['plan_id', 'total_tasks', 'completed_tasks'],
57
+ },
58
+ },
59
+ summary: { type: 'string' },
60
+ },
61
+ required: ['check_type', 'passed', 'plans', 'summary'],
62
+ }
63
+
64
+ const INTEGRATION_SCHEMA = {
65
+ type: 'object',
66
+ properties: {
67
+ check_type: { type: 'string' },
68
+ passed: { type: 'boolean' },
69
+ interfaces: {
70
+ type: 'array',
71
+ items: {
72
+ type: 'object',
73
+ properties: {
74
+ interface_name: { type: 'string' },
75
+ producer_phase: { type: 'string' },
76
+ consumer_phase: { type: 'string' },
77
+ status: { type: 'string', enum: ['pass', 'fail', 'warning'] },
78
+ issue: { type: 'string' },
79
+ },
80
+ required: ['interface_name', 'producer_phase', 'consumer_phase', 'status'],
81
+ },
82
+ },
83
+ data_contract_issues: { type: 'array', items: { type: 'object', properties: { contract: { type: 'string' }, mismatch: { type: 'string' }, affected_phases: { type: 'array', items: { type: 'string' } } }, required: ['contract', 'mismatch'] } },
84
+ circular_dependencies: { type: 'array', items: { type: 'string' } },
85
+ summary: { type: 'string' },
86
+ },
87
+ required: ['check_type', 'passed', 'interfaces', 'summary'],
88
+ }
89
+
90
+ const CHALLENGE_SCHEMA = {
91
+ type: 'object',
92
+ properties: {
93
+ dimension: { type: 'string' },
94
+ original_passed: { type: 'boolean' },
95
+ challenge_result: { type: 'string', enum: ['confirmed', 'overturned-to-fail', 'overturned-to-pass'] },
96
+ counter_evidence: { type: 'array', items: { type: 'object', properties: { point: { type: 'string' }, evidence: { type: 'string' } }, required: ['point', 'evidence'] } },
97
+ reasoning: { type: 'string' },
98
+ confidence: { type: 'number', minimum: 0, maximum: 100 },
99
+ },
100
+ required: ['dimension', 'original_passed', 'challenge_result', 'reasoning', 'confidence'],
101
+ }
102
+
103
+ const VERDICT_VOTE_SCHEMA = {
104
+ type: 'object',
105
+ properties: {
106
+ perspective: { type: 'string' },
107
+ verdict: { type: 'string', enum: ['PASS', 'FAIL'] },
108
+ rationale: { type: 'string' },
109
+ confidence: { type: 'number', minimum: 0, maximum: 100 },
110
+ next_step: { type: 'string', enum: ['milestone-complete', 'plan-gaps', 'execute', 'verify'] },
111
+ },
112
+ required: ['perspective', 'verdict', 'rationale', 'confidence', 'next_step'],
113
+ }
114
+
115
+ const REPORT_SCHEMA = {
116
+ type: 'object',
117
+ properties: {
118
+ verdict: { type: 'string', enum: ['PASS', 'FAIL'] },
119
+ confidence: { type: 'number', minimum: 0, maximum: 100 },
120
+ adversarial_outcome: {
121
+ type: 'object',
122
+ properties: {
123
+ strict: { type: 'string' },
124
+ lenient: { type: 'string' },
125
+ objective: { type: 'string' },
126
+ challenges_overturned: { type: 'number' },
127
+ decisive_factor: { type: 'string' },
128
+ },
129
+ required: ['strict', 'lenient', 'objective', 'decisive_factor'],
130
+ },
131
+ dimension_results: {
132
+ type: 'array',
133
+ items: {
134
+ type: 'object',
135
+ properties: {
136
+ dimension: { type: 'string' },
137
+ original_passed: { type: 'boolean' },
138
+ post_challenge_passed: { type: 'boolean' },
139
+ issue_count: { type: 'number' },
140
+ },
141
+ required: ['dimension', 'original_passed', 'post_challenge_passed'],
142
+ },
143
+ },
144
+ blocking_issues: { type: 'array', items: { type: 'object', properties: { dimension: { type: 'string' }, description: { type: 'string' }, remediation: { type: 'string' } }, required: ['dimension', 'description', 'remediation'] } },
145
+ next_step: { type: 'string', enum: ['milestone-complete', 'plan-gaps', 'execute', 'verify'] },
146
+ summary: { type: 'string' },
147
+ },
148
+ required: ['verdict', 'confidence', 'adversarial_outcome', 'dimension_results', 'blocking_issues', 'next_step', 'summary'],
149
+ }
150
+
151
+ const milestone = args?.milestone || ''
152
+ const isAdhoc = args?.is_adhoc || false
153
+
154
+ // Phase 1: Parallel audit dimensions
155
+ phase('Audit')
156
+
157
+ const checks = [
158
+ () => agent(
159
+ `Phase Coverage Audit${isAdhoc ? ' (ADHOC — skip roadmap phase checks, only verify artifact chain PLN→EXC exists)' : ''}.
160
+ ${milestone ? 'Milestone: ' + milestone : 'Use current_milestone from .workflow/state.json'}
161
+
162
+ ${isAdhoc ? `Adhoc milestone: skip roadmap.md parsing. Only check:
163
+ 1. At least one PLN artifact exists for this milestone
164
+ 2. Each PLN has a corresponding EXC artifact
165
+ 3. All are status=completed` : `Standard milestone:
166
+ 1. Read .workflow/roadmap.md to get milestone → phase mapping
167
+ 2. Read .workflow/state.json artifacts[] filtered by this milestone
168
+ 3. For each phase in the milestone:
169
+ - Check: has plan artifact (type=plan, status=completed)?
170
+ - Check: has execute artifact (type=execute, status=completed)?
171
+ - Check: has verify artifact (type=verify)? (optional but noted)
172
+ 4. Report each phase as complete/partial/missing`}
173
+
174
+ Set check_type="phase-coverage" in output.`,
175
+ { label: 'audit:coverage', phase: 'Audit', schema: COVERAGE_SCHEMA }
176
+ ),
177
+ () => agent(
178
+ `Execution Completeness Audit.
179
+ ${milestone ? 'Milestone: ' + milestone : 'Use current_milestone from .workflow/state.json'}
180
+
181
+ 1. Read .workflow/state.json — find all execute artifacts for this milestone
182
+ 2. For each execute artifact:
183
+ - Resolve its plan directory (artifact.path)
184
+ - Read all .task/TASK-*.json files in that directory
185
+ - Count: total, completed, failed, pending
186
+ - List any incomplete task IDs
187
+ 3. Passed only if ALL tasks across ALL plans are completed (no pending/failed)
188
+
189
+ Set check_type="execution-completeness" in output.`,
190
+ { label: 'audit:execution', phase: 'Audit', schema: EXECUTION_SCHEMA }
191
+ ),
192
+ () => agent(
193
+ `Cross-Phase Integration Audit.
194
+ ${milestone ? 'Milestone: ' + milestone : 'Use current_milestone from .workflow/state.json'}
195
+
196
+ Check that phases compose correctly:
197
+ 1. Scan for shared interfaces, types, APIs across phase boundaries
198
+ 2. Verify contract compliance:
199
+ - Type definitions match usage across phases
200
+ - API request/response schemas are consistent
201
+ - Event names and payloads align between producer and consumer
202
+ 3. Check dependency health:
203
+ - Cross-phase imports resolve correctly
204
+ - No circular dependencies across phase boundaries
205
+ - Shared dependency versions are compatible
206
+ 4. Trace data flow across boundaries:
207
+ - Input/output formats match
208
+ - Error propagation is handled at boundaries
209
+
210
+ Report each interface check as pass/fail/warning with specific issues.
211
+ Set check_type="integration" in output.`,
212
+ { label: 'audit:integration', phase: 'Audit', schema: INTEGRATION_SCHEMA, agentType: 'workflow-integration-checker' }
213
+ ),
214
+ ]
215
+
216
+ log(`Running ${checks.length} audit dimensions in parallel...`)
217
+ const results = await parallel(checks)
218
+ const validResults = results.filter(Boolean)
219
+
220
+ const coverage = validResults.find(r => r.check_type === 'phase-coverage')
221
+ const execution = validResults.find(r => r.check_type === 'execution-completeness')
222
+ const integration = validResults.find(r => r.check_type === 'integration')
223
+
224
+ const auditDigest = `Phase Coverage: ${coverage ? (coverage.passed ? 'PASS' : 'FAIL') + ' — ' + coverage.summary : 'NOT RUN'}
225
+
226
+ Execution Completeness: ${execution ? (execution.passed ? 'PASS' : 'FAIL') + ' — ' + execution.summary : 'NOT RUN'}
227
+ ${execution && !execution.passed ? 'Incomplete: ' + execution.plans.filter(p => p.pending_tasks > 0 || p.failed_tasks > 0).map(p => p.plan_id + ' (' + p.pending_tasks + ' pending, ' + p.failed_tasks + ' failed)').join('; ') : ''}
228
+
229
+ Integration: ${integration ? (integration.passed ? 'PASS' : 'FAIL') + ' — ' + integration.summary : 'NOT RUN'}
230
+ ${integration && !integration.passed ? 'Failed: ' + integration.interfaces.filter(i => i.status === 'fail').map(i => i.interface_name + ': ' + i.issue).join('; ') : ''}`
231
+
232
+ // Phase 2: Adversarial challenge of each audit dimension
233
+ phase('Challenge')
234
+ log('Adversarial challenge of audit dimension results...')
235
+
236
+ const dimensionData = [
237
+ { name: 'coverage', result: coverage },
238
+ { name: 'execution', result: execution },
239
+ { name: 'integration', result: integration },
240
+ ].filter(d => d.result)
241
+
242
+ const challengeResults = await parallel(
243
+ dimensionData.map(dim => () =>
244
+ agent(
245
+ `ADVERSARIAL CHALLENGE of the "${dim.name}" audit dimension.
246
+
247
+ Original result: ${dim.result.passed ? 'PASS' : 'FAIL'}
248
+ Summary: ${dim.result.summary}
249
+
250
+ ${dim.name === 'coverage' && dim.result.phases ? 'Phase details:\n' + dim.result.phases.map(p => ` ${p.phase}: ${p.status} (plan:${p.has_plan} execute:${p.has_execute})`).join('\n') : ''}
251
+ ${dim.name === 'execution' && dim.result.plans ? 'Plan details:\n' + dim.result.plans.map(p => ` ${p.plan_id}: ${p.completed_tasks}/${p.total_tasks} complete`).join('\n') : ''}
252
+ ${dim.name === 'integration' && dim.result.interfaces ? 'Interface details:\n' + dim.result.interfaces.map(i => ` ${i.interface_name}: ${i.status}`).join('\n') : ''}
253
+
254
+ Your job: Try to OVERTURN the result.
255
+ - If it PASSED: find evidence it should have FAILED (missed checks, false passes, overlooked issues)
256
+ - If it FAILED: find evidence it should have PASSED (issues are minor, not blocking, or already resolved)
257
+
258
+ Challenge the audit's thoroughness:
259
+ 1. Did it check everything it should?
260
+ 2. Were the checks actually verifying what they claim?
261
+ 3. Is the evidence genuine or superficial?
262
+
263
+ challenge_result:
264
+ - "confirmed": the original result stands after challenge
265
+ - "overturned-to-fail": was PASS, should be FAIL (found missed issues)
266
+ - "overturned-to-pass": was FAIL, should be PASS (issues are not blocking)
267
+
268
+ Default to "confirmed" only if you genuinely cannot find counter-evidence.`,
269
+ { label: `challenge:${dim.name}`, phase: 'Challenge', schema: CHALLENGE_SCHEMA }
270
+ )
271
+ )
272
+ )
273
+
274
+ const validChallenges = challengeResults.filter(Boolean)
275
+ const overturnedCount = validChallenges.filter(c => c.challenge_result !== 'confirmed').length
276
+
277
+ const challengeDigest = validChallenges.map(c =>
278
+ `${c.dimension}: ${c.original_passed ? 'PASS' : 'FAIL'} → ${c.challenge_result} (confidence: ${c.confidence}%)\n ${c.reasoning}`
279
+ ).join('\n\n')
280
+
281
+ log(`Challenges: ${overturnedCount}/${validChallenges.length} dimensions overturned`)
282
+
283
+ // Phase 3: 3-vote adversarial verdict
284
+ phase('Report')
285
+ log('3-vote adversarial verdict (strict / lenient / objective)...')
286
+
287
+ const fullContext = `=== ORIGINAL AUDIT ===\n${auditDigest}\n\n=== ADVERSARIAL CHALLENGES ===\n${challengeDigest}`
288
+
289
+ const verdictVotes = await parallel([
290
+ () => agent(
291
+ `STRICT VOTER: Apply the highest quality bar for milestone completion.
292
+
293
+ ${fullContext}
294
+
295
+ Your philosophy: A milestone is complete ONLY when everything is truly done.
296
+ - If any challenge overturned a PASS to FAIL → FAIL
297
+ - If any dimension was originally FAIL and not overturned → FAIL
298
+ - PASS only if all dimensions pass AND all challenges confirm
299
+
300
+ Vote with next_step recommendation.`,
301
+ { label: 'vote:strict', phase: 'Report', schema: VERDICT_VOTE_SCHEMA }
302
+ ),
303
+ () => agent(
304
+ `LENIENT VOTER: Apply a practical bar for milestone completion.
305
+
306
+ ${fullContext}
307
+
308
+ Your philosophy: Milestones should move forward when substantially complete.
309
+ - If challenges overturned FAILs to PASs → good, count them
310
+ - Minor coverage/execution gaps are acceptable if integration is solid
311
+ - PASS if the core functionality works even with minor gaps
312
+
313
+ Vote with next_step recommendation.`,
314
+ { label: 'vote:lenient', phase: 'Report', schema: VERDICT_VOTE_SCHEMA }
315
+ ),
316
+ () => agent(
317
+ `OBJECTIVE VOTER: Apply evidence-based judgment for milestone completion.
318
+
319
+ ${fullContext}
320
+
321
+ Your philosophy: Follow the evidence, weigh challenge confidence.
322
+ - High-confidence challenges (>80%) override original results
323
+ - Low-confidence challenges (<50%) are noise
324
+ - If the post-challenge picture shows all dimensions pass → PASS
325
+ - If any dimension genuinely fails after challenge → FAIL
326
+
327
+ Vote with next_step recommendation.`,
328
+ { label: 'vote:objective', phase: 'Report', schema: VERDICT_VOTE_SCHEMA }
329
+ ),
330
+ ])
331
+
332
+ const validVotes = verdictVotes.filter(Boolean)
333
+ const voteCounts = { PASS: 0, FAIL: 0 }
334
+ validVotes.forEach(v => { voteCounts[v.verdict] = (voteCounts[v.verdict] || 0) + 1 })
335
+
336
+ const voteDigest = validVotes.map(v =>
337
+ `${v.perspective}: ${v.verdict} → ${v.next_step} (confidence: ${v.confidence}%)\n ${v.rationale}`
338
+ ).join('\n\n')
339
+
340
+ log(`Verdict votes: PASS=${voteCounts.PASS} FAIL=${voteCounts.FAIL}`)
341
+
342
+ const report = await agent(
343
+ `Generate final milestone audit report from adversarial deliberation.
344
+
345
+ === VOTES ===
346
+ ${voteDigest}
347
+
348
+ Vote tally: PASS=${voteCounts.PASS}, FAIL=${voteCounts.FAIL}
349
+
350
+ === CHALLENGE RESULTS ===
351
+ ${challengeDigest}
352
+
353
+ === ORIGINAL AUDIT ===
354
+ ${auditDigest}
355
+
356
+ RESOLVE:
357
+ 1. Majority vote wins. Tie: go with OBJECTIVE voter.
358
+ 2. Record adversarial_outcome with each voter's position and challenges_overturned count
359
+ 3. Build dimension_results with original AND post-challenge status
360
+ 4. Compile blocking_issues from dimensions that FAIL after challenges
361
+ 5. Determine next_step by majority vote (tie: go with objective)
362
+ 6. Write summary including challenge and deliberation outcomes`,
363
+ { label: 'report', phase: 'Report', schema: REPORT_SCHEMA }
364
+ )
365
+
366
+ return {
367
+ coverage: coverage,
368
+ execution: execution,
369
+ integration: integration,
370
+ challenges: validChallenges,
371
+ votes: validVotes,
372
+ report: report,
373
+ metadata: {
374
+ milestone: milestone,
375
+ is_adhoc: isAdhoc,
376
+ dimensions_checked: validResults.length,
377
+ dimensions_overturned: overturnedCount,
378
+ coverage_passed: coverage ? coverage.passed : null,
379
+ execution_passed: execution ? execution.passed : null,
380
+ integration_passed: integration ? integration.passed : null,
381
+ vote_counts: voteCounts,
382
+ verdict: report ? report.verdict : 'UNKNOWN',
383
+ next_step: report ? report.next_step : null,
384
+ },
385
+ }