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,359 @@
1
+ export const meta = {
2
+ name: 'wf-grill',
3
+ description: 'Adversarial stress-testing with meta-skeptic challenge and 3-vote verdict',
4
+ whenToUse: 'Accelerate maestro-grill with parallel branch probing + meta-adversarial synthesis + 3-vote verdict',
5
+ phases: [
6
+ { title: 'Explore', detail: 'Codebase evidence gathering via cli-explore-agent' },
7
+ { title: 'Stress', detail: 'Parallel adversarial branch probing' },
8
+ { title: 'MetaChallenge', detail: 'Meta-skeptic challenges the stress-test findings themselves' },
9
+ { title: 'Synthesize', detail: '3-vote adversarial verdict (optimist/pessimist/realist)' },
10
+ ],
11
+ }
12
+
13
+ const BRANCHES = [
14
+ { key: 'scope', focus: 'Scope & Boundaries — What is explicitly in/out? Where are the edges? Challenge vague boundaries with concrete code symbols.' },
15
+ { key: 'data-model', focus: 'Data Model & State — How does data flow? What state transitions exist? Challenge naming conflicts with codebase terminology.' },
16
+ { key: 'edge-cases', focus: 'Edge Cases & Failure Modes — What breaks at scale? What happens on invalid input? What if dependent services fail?' },
17
+ { key: 'integration', focus: 'Integration & Dependencies — What existing systems are touched? What contracts must be honored? What breaks if we change X?' },
18
+ { key: 'scale', focus: 'Scale & Performance — At 10x/100x current load, what breaks first? Which queries degrade? Where are the O(n^2) risks?' },
19
+ { key: 'security', focus: 'Security & Access Control — What is the attack surface? Who can access what? Where is trust assumed but not verified?' },
20
+ { key: 'operations', focus: 'Observability & Operations — How do we know it is working? What alerts fire? How do we debug production issues?' },
21
+ { key: 'migration', focus: 'Migration & Rollback — What is the rollback path? Can we do a zero-downtime deploy? What data migration is needed?' },
22
+ ]
23
+
24
+ const EXPLORATION_SCHEMA = {
25
+ type: 'object',
26
+ properties: {
27
+ relevant_symbols: { type: 'array', items: { type: 'object', properties: { symbol: { type: 'string' }, file: { type: 'string' }, line: { type: 'number' }, type: { type: 'string' } }, required: ['symbol', 'file'] } },
28
+ existing_terminology: { type: 'array', items: { type: 'object', properties: { term: { type: 'string' }, usage_location: { type: 'string' }, context: { type: 'string' } }, required: ['term', 'usage_location'] } },
29
+ data_flows: { type: 'array', items: { type: 'object', properties: { from: { type: 'string' }, to: { type: 'string' }, data_shape: { type: 'string' } }, required: ['from', 'to'] } },
30
+ integration_points: { type: 'array', items: { type: 'object', properties: { system: { type: 'string' }, interface: { type: 'string' }, contract: { type: 'string' } }, required: ['system', 'interface'] } },
31
+ },
32
+ required: ['relevant_symbols', 'existing_terminology'],
33
+ }
34
+
35
+ const BRANCH_SCHEMA = {
36
+ type: 'object',
37
+ properties: {
38
+ branch: { type: 'string' },
39
+ challenges: {
40
+ type: 'array',
41
+ items: {
42
+ type: 'object',
43
+ properties: {
44
+ question: { type: 'string' },
45
+ code_evidence: { type: 'string' },
46
+ contradiction: { type: 'string' },
47
+ severity: { type: 'string', enum: ['blocking', 'significant', 'minor'] },
48
+ proposed_resolution: { type: 'string' },
49
+ },
50
+ required: ['question', 'severity'],
51
+ },
52
+ },
53
+ terminology_conflicts: {
54
+ type: 'array',
55
+ items: {
56
+ type: 'object',
57
+ properties: {
58
+ proposed_term: { type: 'string' },
59
+ codebase_term: { type: 'string' },
60
+ location: { type: 'string' },
61
+ recommendation: { type: 'string' },
62
+ },
63
+ required: ['proposed_term', 'codebase_term', 'recommendation'],
64
+ },
65
+ },
66
+ assumptions_challenged: { type: 'array', items: { type: 'string' } },
67
+ verdict: { type: 'string', enum: ['sound', 'needs-clarification', 'fundamentally-flawed'] },
68
+ },
69
+ required: ['branch', 'challenges', 'terminology_conflicts', 'assumptions_challenged', 'verdict'],
70
+ }
71
+
72
+ const META_CHALLENGE_SCHEMA = {
73
+ type: 'object',
74
+ properties: {
75
+ overblown_findings: {
76
+ type: 'array',
77
+ items: {
78
+ type: 'object',
79
+ properties: {
80
+ branch: { type: 'string' },
81
+ finding: { type: 'string' },
82
+ why_overblown: { type: 'string' },
83
+ actual_severity: { type: 'string', enum: ['blocking', 'significant', 'minor', 'non-issue'] },
84
+ },
85
+ required: ['branch', 'finding', 'why_overblown', 'actual_severity'],
86
+ },
87
+ },
88
+ missed_issues: {
89
+ type: 'array',
90
+ items: {
91
+ type: 'object',
92
+ properties: {
93
+ area: { type: 'string' },
94
+ missed_issue: { type: 'string' },
95
+ severity: { type: 'string', enum: ['blocking', 'significant', 'minor'] },
96
+ evidence: { type: 'string' },
97
+ },
98
+ required: ['area', 'missed_issue', 'severity'],
99
+ },
100
+ },
101
+ stress_test_quality: { type: 'number', minimum: 1, maximum: 5 },
102
+ meta_assessment: { type: 'string' },
103
+ },
104
+ required: ['overblown_findings', 'missed_issues', 'stress_test_quality', 'meta_assessment'],
105
+ }
106
+
107
+ const VERDICT_VOTE_SCHEMA = {
108
+ type: 'object',
109
+ properties: {
110
+ perspective: { type: 'string' },
111
+ verdict: { type: 'string', enum: ['ready-for-brainstorm', 'needs-refinement', 'back-to-drawing-board'] },
112
+ argument: { type: 'string' },
113
+ confidence: { type: 'number', minimum: 0, maximum: 100 },
114
+ key_reasons: { type: 'array', items: { type: 'string' } },
115
+ },
116
+ required: ['perspective', 'verdict', 'argument', 'confidence'],
117
+ }
118
+
119
+ const SYNTHESIS_SCHEMA = {
120
+ type: 'object',
121
+ properties: {
122
+ overall_verdict: { type: 'string', enum: ['ready-for-brainstorm', 'needs-refinement', 'back-to-drawing-board'] },
123
+ adversarial_outcome: { type: 'object', properties: { optimist: { type: 'string' }, pessimist: { type: 'string' }, realist: { type: 'string' }, decisive_factor: { type: 'string' } }, required: ['optimist', 'pessimist', 'realist', 'decisive_factor'] },
124
+ blocking_issues: { type: 'array', items: { type: 'object', properties: { branch: { type: 'string' }, issue: { type: 'string' }, must_resolve_before: { type: 'string' } }, required: ['branch', 'issue'] } },
125
+ terminology: { type: 'array', items: { type: 'object', properties: { term: { type: 'string' }, definition: { type: 'string' }, code_alignment: { type: 'string' } }, required: ['term', 'definition'] } },
126
+ contradictions: { type: 'array', items: { type: 'object', properties: { between_branches: { type: 'array', items: { type: 'string' } }, description: { type: 'string' }, resolution: { type: 'string' } }, required: ['between_branches', 'description'] } },
127
+ constraints_discovered: { type: 'array', items: { type: 'object', properties: { constraint: { type: 'string' }, source: { type: 'string' }, impact: { type: 'string' }, status: { type: 'string', enum: ['locked', 'free', 'deferred'] } }, required: ['constraint', 'source', 'status'] } },
128
+ executive_summary: { type: 'string' },
129
+ },
130
+ required: ['overall_verdict', 'adversarial_outcome', 'blocking_issues', 'terminology', 'contradictions', 'constraints_discovered', 'executive_summary'],
131
+ }
132
+
133
+ const topic = args?.topic || ''
134
+ const context = args?.context || ''
135
+ const depth = args?.depth || 'standard'
136
+ const branchCount = depth === 'shallow' ? 3 : depth === 'deep' ? 8 : 5
137
+ const selectedBranches = BRANCHES.slice(0, branchCount)
138
+
139
+ // Phase 1: Codebase evidence gathering
140
+ phase('Explore')
141
+ log('Gathering codebase evidence for stress-testing...')
142
+
143
+ const exploration = await agent(
144
+ `Explore the codebase to gather evidence for stress-testing this proposal:
145
+ Topic: ${topic}
146
+ ${context ? 'Context: ' + context : ''}
147
+
148
+ Find:
149
+ 1. Relevant symbols — functions, classes, types, variables related to this topic
150
+ 2. Existing terminology — how the codebase names things in this domain (for conflict detection)
151
+ 3. Data flows — how data moves through the system in this area
152
+ 4. Integration points — external systems, internal modules, APIs touched
153
+
154
+ This evidence will be used to challenge assumptions and detect contradictions.`,
155
+ { label: 'explore:evidence', phase: 'Explore', schema: EXPLORATION_SCHEMA, agentType: 'cli-explore-agent' }
156
+ )
157
+
158
+ const evidenceContext = exploration
159
+ ? `Codebase evidence:
160
+ Symbols: ${exploration.relevant_symbols.map(s => s.symbol + ' @ ' + s.file).join(', ')}
161
+ Terminology: ${exploration.existing_terminology.map(t => t.term + ' (' + t.usage_location + ')').join(', ')}
162
+ Data flows: ${(exploration.data_flows || []).map(d => d.from + ' → ' + d.to).join(', ')}
163
+ Integration: ${(exploration.integration_points || []).map(i => i.system + ':' + i.interface).join(', ')}`
164
+ : ''
165
+
166
+ // Phase 2: Parallel adversarial branch probing
167
+ phase('Stress')
168
+ log(`Stress-testing ${selectedBranches.length} branches in parallel...`)
169
+
170
+ const branchResults = await parallel(
171
+ selectedBranches.map(branch => () =>
172
+ agent(
173
+ `You are an adversarial stress-tester for the "${branch.key}" branch.
174
+
175
+ Proposal being tested: ${topic}
176
+ ${context ? 'Proposal context: ' + context : ''}
177
+ ${evidenceContext}
178
+
179
+ Your focus: ${branch.focus}
180
+
181
+ Your job is to BREAK this proposal by:
182
+ 1. Finding contradictions with existing code (cite file:line)
183
+ 2. Detecting terminology conflicts (proposed names vs codebase names)
184
+ 3. Challenging unstated assumptions with concrete counter-scenarios
185
+ 4. Probing for cases the proposal hasn't considered
186
+
187
+ For each challenge:
188
+ - Ground it in code evidence (file paths, symbol names, data shapes)
189
+ - Classify severity: blocking (must fix before proceeding), significant (should address), minor (nice to clarify)
190
+ - Propose a resolution direction
191
+
192
+ Be adversarial but fair — only raise real issues backed by evidence.`,
193
+ { label: `stress:${branch.key}`, phase: 'Stress', schema: BRANCH_SCHEMA }
194
+ )
195
+ )
196
+ )
197
+
198
+ const validBranches = branchResults.filter(Boolean)
199
+ log(`${validBranches.length}/${selectedBranches.length} branches probed`)
200
+
201
+ const branchDigest = validBranches.map(b => {
202
+ const blocking = b.challenges.filter(c => c.severity === 'blocking')
203
+ return `## ${b.branch} [${b.verdict}]
204
+ Challenges: ${b.challenges.length} (${blocking.length} blocking)
205
+ ${blocking.map(c => ` ! ${c.question}${c.contradiction ? ' — ' + c.contradiction : ''}`).join('\n')}
206
+ Terminology conflicts: ${b.terminology_conflicts.map(t => t.proposed_term + ' vs ' + t.codebase_term).join(', ') || 'none'}
207
+ Assumptions challenged: ${b.assumptions_challenged.join('; ') || 'none'}`
208
+ }).join('\n\n')
209
+
210
+ // Phase 3: Meta-skeptic challenges the stress-test findings
211
+ phase('MetaChallenge')
212
+ log('Meta-skeptic challenging the stress-test findings themselves...')
213
+
214
+ const metaChallenge = await agent(
215
+ `You are the META-SKEPTIC — the devil's advocate OF the devil's advocates.
216
+
217
+ The stress-testers above tried to break this proposal:
218
+ Topic: ${topic}
219
+
220
+ Their findings:
221
+ ${branchDigest}
222
+
223
+ ${evidenceContext}
224
+
225
+ Your job is to challenge THE STRESS-TESTERS:
226
+ 1. OVERBLOWN FINDINGS: Which challenges are exaggerated, based on unlikely scenarios, or missing context?
227
+ - Check if the "blocking" issues are actually blocking
228
+ - See if the code evidence actually supports the claimed contradiction
229
+ - Identify where stress-testers assumed worst-case without justification
230
+ 2. MISSED ISSUES: What did the stress-testers NOT catch that they should have?
231
+ - Blind spots across all branches
232
+ - Interactions between branches that no single branch tested
233
+ - Real risks that were obscured by focus on minor issues
234
+ 3. Rate the overall stress_test_quality (1-5): how thorough and fair were the findings?
235
+
236
+ Be ruthlessly honest. Some stress-test findings ARE real; confirm those. But call out any that are theatrical rather than substantive.`,
237
+ { label: 'meta-skeptic', phase: 'MetaChallenge', schema: META_CHALLENGE_SCHEMA }
238
+ )
239
+
240
+ const metaDigest = metaChallenge
241
+ ? `Meta-skeptic assessment (quality: ${metaChallenge.stress_test_quality}/5):
242
+ Overblown: ${metaChallenge.overblown_findings.length} findings downgraded
243
+ ${metaChallenge.overblown_findings.map(f => ` ${f.branch}: "${f.finding}" → ${f.actual_severity} — ${f.why_overblown}`).join('\n')}
244
+ Missed: ${metaChallenge.missed_issues.length} new issues surfaced
245
+ ${metaChallenge.missed_issues.map(m => ` [${m.severity}] ${m.area}: ${m.missed_issue}`).join('\n')}
246
+ Assessment: ${metaChallenge.meta_assessment}`
247
+ : 'Meta-challenge not available.'
248
+
249
+ // Phase 4: 3-vote adversarial verdict
250
+ phase('Synthesize')
251
+ log('Launching 3-vote adversarial verdict (optimist / pessimist / realist)...')
252
+
253
+ const votes = await parallel([
254
+ () => agent(
255
+ `You are the OPTIMIST. Vote on the proposal's readiness.
256
+
257
+ Proposal: ${topic}
258
+ Stress-test findings:\n${branchDigest}
259
+ Meta-skeptic review:\n${metaDigest}
260
+
261
+ Your lens: Focus on what IS working. Discount overblown findings. Trust proposed resolutions.
262
+ - "ready-for-brainstorm": blocking issues are addressable, proceed with awareness
263
+ - "needs-refinement": some issues need attention but proposal has merit
264
+ - "back-to-drawing-board": only if genuinely unfixable (you should almost never vote this)
265
+
266
+ Vote with your confidence level.`,
267
+ { label: 'vote:optimist', phase: 'Synthesize', schema: VERDICT_VOTE_SCHEMA }
268
+ ),
269
+ () => agent(
270
+ `You are the PESSIMIST. Vote on the proposal's readiness.
271
+
272
+ Proposal: ${topic}
273
+ Stress-test findings:\n${branchDigest}
274
+ Meta-skeptic review:\n${metaDigest}
275
+
276
+ Your lens: Focus on what is BROKEN. Amplify blocking issues. Question proposed resolutions.
277
+ - "back-to-drawing-board": if there are fundamental flaws or too many blocking issues
278
+ - "needs-refinement": if issues are real but fixable
279
+ - "ready-for-brainstorm": only if stress-testing found almost nothing (you should almost never vote this)
280
+
281
+ Vote with your confidence level.`,
282
+ { label: 'vote:pessimist', phase: 'Synthesize', schema: VERDICT_VOTE_SCHEMA }
283
+ ),
284
+ () => agent(
285
+ `You are the REALIST. Vote on the proposal's readiness.
286
+
287
+ Proposal: ${topic}
288
+ Stress-test findings:\n${branchDigest}
289
+ Meta-skeptic review:\n${metaDigest}
290
+
291
+ Your lens: Evidence-based, no bias. Weigh the meta-skeptic's corrections. Discount both theatrical threats and wishful thinking.
292
+ - "ready-for-brainstorm": if blocking issues are few, well-understood, and have clear resolutions
293
+ - "needs-refinement": if real issues exist but are tractable
294
+ - "back-to-drawing-board": if fundamental assumptions are wrong
295
+
296
+ Vote with your confidence level.`,
297
+ { label: 'vote:realist', phase: 'Synthesize', schema: VERDICT_VOTE_SCHEMA }
298
+ ),
299
+ ])
300
+
301
+ const validVotes = votes.filter(Boolean)
302
+ const voteDigest = validVotes.map(v =>
303
+ `${v.perspective}: ${v.verdict} (confidence: ${v.confidence}%)\n ${v.argument}`
304
+ ).join('\n\n')
305
+
306
+ const verdictCounts = {}
307
+ validVotes.forEach(v => { verdictCounts[v.verdict] = (verdictCounts[v.verdict] || 0) + 1 })
308
+ log(`Votes: ${Object.entries(verdictCounts).map(([k, v]) => k + '=' + v).join(', ')}`)
309
+
310
+ log('Synthesizing final verdict from adversarial votes...')
311
+
312
+ const synthesis = await agent(
313
+ `Synthesize the final stress-test verdict from 3 adversarial voters.
314
+
315
+ Proposal: ${topic}
316
+
317
+ === VOTES ===
318
+ ${voteDigest}
319
+
320
+ Vote tally: ${Object.entries(verdictCounts).map(([k, v]) => k + '=' + v).join(', ')}
321
+
322
+ === META-SKEPTIC REVIEW ===
323
+ ${metaDigest}
324
+
325
+ === BRANCH FINDINGS ===
326
+ ${branchDigest}
327
+
328
+ RESOLVE:
329
+ 1. Majority vote wins. Tie-break: go with the REALIST.
330
+ 2. Record adversarial_outcome with each voter's verdict and the decisive factor
331
+ 3. Compile blocking_issues from branches BUT exclude any the meta-skeptic downgraded to non-issue
332
+ 4. Add any missed_issues from meta-skeptic as additional blocking if severity is blocking
333
+ 5. Build unified terminology list
334
+ 6. Detect cross-branch contradictions
335
+ 7. Extract discovered constraints (locked/free/deferred)
336
+ 8. Write executive summary including the adversarial debate and meta-challenge outcomes`,
337
+ { label: 'synthesize', phase: 'Synthesize', schema: SYNTHESIS_SCHEMA }
338
+ )
339
+
340
+ return {
341
+ exploration: exploration,
342
+ branches: validBranches,
343
+ metaChallenge: metaChallenge,
344
+ votes: validVotes,
345
+ synthesis: synthesis,
346
+ metadata: {
347
+ topic: topic,
348
+ depth: depth,
349
+ branch_count: selectedBranches.length,
350
+ completed_count: validBranches.length,
351
+ meta_overblown: metaChallenge ? metaChallenge.overblown_findings.length : 0,
352
+ meta_missed: metaChallenge ? metaChallenge.missed_issues.length : 0,
353
+ stress_test_quality: metaChallenge ? metaChallenge.stress_test_quality : null,
354
+ blocking_count: synthesis ? synthesis.blocking_issues.length : 0,
355
+ contradiction_count: synthesis ? synthesis.contradictions.length : 0,
356
+ verdict_votes: verdictCounts,
357
+ overall_verdict: synthesis ? synthesis.overall_verdict : 'unknown',
358
+ },
359
+ }