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,468 @@
1
+ export const meta = {
2
+ name: 'wf-plan',
3
+ description: 'Parallel context + 3-proposal judge panel planning + 3-critic adversarial verification',
4
+ whenToUse: 'Accelerate maestro-plan with parallel context + competing plan proposals + multi-critic adversarial check',
5
+ phases: [
6
+ { title: 'Context', detail: 'Parallel context exploration from multiple sources' },
7
+ { title: 'Compete', detail: '3 independent plan proposals from competing strategies' },
8
+ { title: 'Select', detail: 'Judge panel scores proposals and selects best' },
9
+ { title: 'Check', detail: '3 specialized critics (dependency/scope/quality) challenge the selected plan' },
10
+ ],
11
+ }
12
+
13
+ const CONTEXT_SCHEMA = {
14
+ type: 'object',
15
+ properties: {
16
+ source: { type: 'string' },
17
+ decisions: { type: 'array', items: { type: 'object', properties: { id: { type: 'string' }, decision: { type: 'string' }, status: { type: 'string', enum: ['locked', 'free', 'deferred'] }, rationale: { type: 'string' } }, required: ['decision', 'status'] } },
18
+ requirements: { type: 'array', items: { type: 'object', properties: { id: { type: 'string' }, objective: { type: 'string' }, acceptance_criteria: { type: 'string' }, priority: { type: 'string' }, target_files: { type: 'array', items: { type: 'string' } } }, required: ['objective'] } },
19
+ constraints: { type: 'array', items: { type: 'string' } },
20
+ existing_patterns: { type: 'array', items: { type: 'object', properties: { pattern: { type: 'string' }, file: { type: 'string' }, usage: { type: 'string' } }, required: ['pattern', 'file'] } },
21
+ dependencies: { type: 'array', items: { type: 'string' } },
22
+ },
23
+ required: ['source', 'decisions', 'requirements'],
24
+ }
25
+
26
+ const PLAN_SCHEMA = {
27
+ type: 'object',
28
+ properties: {
29
+ strategy: { type: 'string' },
30
+ summary: { type: 'string' },
31
+ approach: { type: 'string' },
32
+ complexity: { type: 'string', enum: ['low', 'medium', 'high'] },
33
+ waves: {
34
+ type: 'array',
35
+ items: {
36
+ type: 'object',
37
+ properties: {
38
+ wave_index: { type: 'number' },
39
+ rationale: { type: 'string' },
40
+ tasks: {
41
+ type: 'array',
42
+ items: {
43
+ type: 'object',
44
+ properties: {
45
+ task_id: { type: 'string' },
46
+ title: { type: 'string' },
47
+ description: { type: 'string' },
48
+ scope: { type: 'string' },
49
+ focus_paths: { type: 'array', items: { type: 'string' } },
50
+ depends_on: { type: 'array', items: { type: 'string' } },
51
+ convergence_criteria: { type: 'array', items: { type: 'string' } },
52
+ files: { type: 'array', items: { type: 'object', properties: { path: { type: 'string' }, action: { type: 'string', enum: ['create', 'modify', 'delete'] }, change: { type: 'string' } }, required: ['path', 'action'] } },
53
+ issue_id: { type: 'string' },
54
+ },
55
+ required: ['task_id', 'title', 'description', 'convergence_criteria'],
56
+ },
57
+ },
58
+ },
59
+ required: ['wave_index', 'tasks'],
60
+ },
61
+ },
62
+ total_tasks: { type: 'number' },
63
+ trade_offs: { type: 'string' },
64
+ confidence: { type: 'number', minimum: 0, maximum: 100 },
65
+ },
66
+ required: ['strategy', 'summary', 'approach', 'waves', 'total_tasks', 'confidence'],
67
+ }
68
+
69
+ const PLAN_SCORE_SCHEMA = {
70
+ type: 'object',
71
+ properties: {
72
+ proposal_strategy: { type: 'string' },
73
+ scores: {
74
+ type: 'object',
75
+ properties: {
76
+ coverage: { type: 'number', minimum: 1, maximum: 5 },
77
+ parallelism: { type: 'number', minimum: 1, maximum: 5 },
78
+ risk_mitigation: { type: 'number', minimum: 1, maximum: 5 },
79
+ convergence_quality: { type: 'number', minimum: 1, maximum: 5 },
80
+ simplicity: { type: 'number', minimum: 1, maximum: 5 },
81
+ },
82
+ required: ['coverage', 'parallelism', 'risk_mitigation', 'convergence_quality', 'simplicity'],
83
+ },
84
+ total_score: { type: 'number' },
85
+ strengths: { type: 'array', items: { type: 'string' } },
86
+ weaknesses: { type: 'array', items: { type: 'string' } },
87
+ recommendation: { type: 'string' },
88
+ },
89
+ required: ['proposal_strategy', 'scores', 'total_score', 'strengths', 'weaknesses'],
90
+ }
91
+
92
+ const CRITIC_SCHEMA = {
93
+ type: 'object',
94
+ properties: {
95
+ critic_type: { type: 'string' },
96
+ verdict: { type: 'string', enum: ['pass', 'pass-with-notes', 'needs-revision'] },
97
+ issues: {
98
+ type: 'array',
99
+ items: {
100
+ type: 'object',
101
+ properties: {
102
+ severity: { type: 'string', enum: ['critical', 'warning', 'note'] },
103
+ category: { type: 'string' },
104
+ description: { type: 'string' },
105
+ affected_tasks: { type: 'array', items: { type: 'string' } },
106
+ suggestion: { type: 'string' },
107
+ },
108
+ required: ['severity', 'category', 'description'],
109
+ },
110
+ },
111
+ confidence: { type: 'number', minimum: 0, maximum: 100 },
112
+ summary: { type: 'string' },
113
+ },
114
+ required: ['critic_type', 'verdict', 'issues', 'confidence', 'summary'],
115
+ }
116
+
117
+ const CHECK_SCHEMA = {
118
+ type: 'object',
119
+ properties: {
120
+ verdict: { type: 'string', enum: ['pass', 'pass-with-notes', 'needs-revision'] },
121
+ adversarial_outcome: {
122
+ type: 'object',
123
+ properties: {
124
+ dependency_verdict: { type: 'string' },
125
+ scope_verdict: { type: 'string' },
126
+ quality_verdict: { type: 'string' },
127
+ decisive_factor: { type: 'string' },
128
+ },
129
+ required: ['dependency_verdict', 'scope_verdict', 'quality_verdict', 'decisive_factor'],
130
+ },
131
+ issues: {
132
+ type: 'array',
133
+ items: {
134
+ type: 'object',
135
+ properties: {
136
+ severity: { type: 'string', enum: ['critical', 'warning', 'note'] },
137
+ category: { type: 'string' },
138
+ description: { type: 'string' },
139
+ affected_tasks: { type: 'array', items: { type: 'string' } },
140
+ suggestion: { type: 'string' },
141
+ source_critic: { type: 'string' },
142
+ },
143
+ required: ['severity', 'category', 'description'],
144
+ },
145
+ },
146
+ metrics: {
147
+ type: 'object',
148
+ properties: {
149
+ task_count: { type: 'number' },
150
+ wave_count: { type: 'number' },
151
+ avg_convergence_criteria: { type: 'number' },
152
+ dependency_depth: { type: 'number' },
153
+ estimated_parallelism: { type: 'number' },
154
+ },
155
+ },
156
+ summary: { type: 'string' },
157
+ },
158
+ required: ['verdict', 'adversarial_outcome', 'issues', 'summary'],
159
+ }
160
+
161
+ const contextDir = args?.context_dir || ''
162
+ const fromSource = args?.from || ''
163
+ const phaseNum = args?.phase || null
164
+ const scope = args?.scope || ''
165
+ const specs = args?.specs || ''
166
+ const gaps = args?.gaps || false
167
+ const quick = args?.quick || false
168
+
169
+ // Phase 1: Parallel context exploration
170
+ phase('Context')
171
+ log('Gathering context from multiple sources in parallel...')
172
+
173
+ const contextSources = [
174
+ () => agent(
175
+ `Load analysis context for planning.
176
+ ${contextDir ? 'Context directory: ' + contextDir + ' — read context.md and context-package.json' : ''}
177
+ ${fromSource ? 'Upstream source: ' + fromSource + ' — resolve and load context-package.json' : ''}
178
+ ${phaseNum ? 'Phase: ' + phaseNum + ' — read roadmap.md for phase definition' : ''}
179
+ ${gaps ? 'Gap-fix mode: load issues from .workflow/issues/issues.jsonl with analysis records' : ''}
180
+
181
+ Extract:
182
+ 1. Locked/Free/Deferred decisions from context.md
183
+ 2. Requirements with acceptance criteria from context-package.json or conclusions.json
184
+ 3. Constraints from upstream analysis
185
+ 4. Dependencies identified`,
186
+ { label: 'ctx:analysis', phase: 'Context', schema: CONTEXT_SCHEMA }
187
+ ),
188
+ () => agent(
189
+ `Explore existing codebase patterns relevant to the planned work.
190
+ ${scope ? 'Scope: ' + scope : phaseNum ? 'Phase ' + phaseNum + ' scope from roadmap' : 'Full project'}
191
+ ${specs ? 'Specs to respect: ' + specs : 'Load via: maestro spec load --category arch'}
192
+
193
+ Find:
194
+ 1. Existing patterns in the target area (how similar features are implemented)
195
+ 2. File organization conventions
196
+ 3. Test patterns used
197
+ 4. Import/export conventions
198
+ 5. Error handling patterns
199
+
200
+ Report as existing_patterns[] with file references.`,
201
+ { label: 'ctx:patterns', phase: 'Context', schema: CONTEXT_SCHEMA, agentType: 'cli-explore-agent' }
202
+ ),
203
+ ]
204
+
205
+ const contexts = await parallel(contextSources)
206
+ const validContexts = contexts.filter(Boolean)
207
+
208
+ const mergedDecisions = validContexts.flatMap(c => c.decisions || [])
209
+ const mergedRequirements = validContexts.flatMap(c => c.requirements || [])
210
+ const mergedPatterns = validContexts.flatMap(c => c.existing_patterns || [])
211
+ const mergedConstraints = validContexts.flatMap(c => c.constraints || [])
212
+
213
+ log(`Context gathered: ${mergedDecisions.length} decisions, ${mergedRequirements.length} requirements, ${mergedPatterns.length} patterns`)
214
+
215
+ const contextDigest = `Decisions (${mergedDecisions.length}):
216
+ ${mergedDecisions.map(d => `- [${d.status}] ${d.decision}${d.rationale ? ' — ' + d.rationale : ''}`).join('\n')}
217
+
218
+ Requirements (${mergedRequirements.length}):
219
+ ${mergedRequirements.map(r => `- ${r.objective}${r.acceptance_criteria ? ' (done when: ' + r.acceptance_criteria + ')' : ''}${r.target_files ? ' [' + r.target_files.join(', ') + ']' : ''}`).join('\n')}
220
+
221
+ Constraints: ${mergedConstraints.join('; ') || 'none'}
222
+
223
+ Existing patterns:
224
+ ${mergedPatterns.map(p => `- ${p.pattern} @ ${p.file}`).join('\n') || 'none found'}`
225
+
226
+ // Phase 2: 3 competing plan proposals from different strategies
227
+ phase('Compete')
228
+ log('Launching 3 competing plan proposals...')
229
+
230
+ const planProposals = await parallel([
231
+ () => agent(
232
+ `Create an execution plan using BREADTH-FIRST strategy.
233
+ ${phaseNum ? 'Phase: ' + phaseNum : ''}
234
+ ${scope ? 'Scope: ' + scope : ''}
235
+ ${quick ? 'QUICK mode: minimize tasks' : ''}
236
+ ${gaps ? 'GAP-FIX mode: tasks fix identified issues' : ''}
237
+
238
+ Context:\n${contextDigest}
239
+
240
+ Strategy: BREADTH-FIRST
241
+ - Maximize parallelism: put as many tasks as possible in wave 1
242
+ - Minimize dependencies between tasks
243
+ - Prefer many small independent tasks over fewer large sequential ones
244
+ - Trade off: may have more integration work later but faster early progress
245
+
246
+ Set strategy="breadth-first" in output.
247
+
248
+ Rules:
249
+ 1. Feature-level tasks (one feature = one task)
250
+ 2. Each task needs >=2 testable convergence criteria
251
+ 3. Include focus_paths and files[] with specific paths
252
+ 4. Respect Locked decisions
253
+ 5. Task IDs: TASK-001, TASK-002, etc.`,
254
+ { label: 'plan:breadth', phase: 'Compete', schema: PLAN_SCHEMA, agentType: 'workflow-planner' }
255
+ ),
256
+ () => agent(
257
+ `Create an execution plan using DEPTH-FIRST strategy.
258
+ ${phaseNum ? 'Phase: ' + phaseNum : ''}
259
+ ${scope ? 'Scope: ' + scope : ''}
260
+ ${quick ? 'QUICK mode: minimize tasks' : ''}
261
+ ${gaps ? 'GAP-FIX mode: tasks fix identified issues' : ''}
262
+
263
+ Context:\n${contextDigest}
264
+
265
+ Strategy: DEPTH-FIRST
266
+ - Build foundation first: core infrastructure in wave 1, features on top in wave 2+
267
+ - Strong dependency chains ensure solid base before building up
268
+ - Fewer tasks per wave but each fully tested before moving on
269
+ - Trade off: slower start but less rework and integration issues
270
+
271
+ Set strategy="depth-first" in output.
272
+
273
+ Rules:
274
+ 1. Feature-level tasks (one feature = one task)
275
+ 2. Each task needs >=2 testable convergence criteria
276
+ 3. Include focus_paths and files[] with specific paths
277
+ 4. Respect Locked decisions
278
+ 5. Task IDs: TASK-001, TASK-002, etc.`,
279
+ { label: 'plan:depth', phase: 'Compete', schema: PLAN_SCHEMA, agentType: 'workflow-planner' }
280
+ ),
281
+ () => agent(
282
+ `Create an execution plan using RISK-FIRST strategy.
283
+ ${phaseNum ? 'Phase: ' + phaseNum : ''}
284
+ ${scope ? 'Scope: ' + scope : ''}
285
+ ${quick ? 'QUICK mode: minimize tasks' : ''}
286
+ ${gaps ? 'GAP-FIX mode: tasks fix identified issues' : ''}
287
+
288
+ Context:\n${contextDigest}
289
+
290
+ Strategy: RISK-FIRST
291
+ - Tackle highest-risk items first (complex integrations, uncertain requirements, new patterns)
292
+ - Wave 1 = risk spikes and proof-of-concepts
293
+ - Wave 2+ = validated features building on proven foundations
294
+ - Trade off: may seem slow early but catches showstoppers before heavy investment
295
+
296
+ Set strategy="risk-first" in output.
297
+
298
+ Rules:
299
+ 1. Feature-level tasks (one feature = one task)
300
+ 2. Each task needs >=2 testable convergence criteria
301
+ 3. Include focus_paths and files[] with specific paths
302
+ 4. Respect Locked decisions
303
+ 5. Task IDs: TASK-001, TASK-002, etc.`,
304
+ { label: 'plan:risk', phase: 'Compete', schema: PLAN_SCHEMA, agentType: 'workflow-planner' }
305
+ ),
306
+ ])
307
+
308
+ const validProposals = planProposals.filter(Boolean)
309
+ log(`${validProposals.length} competing plans generated`)
310
+
311
+ // Judge panel scores each proposal
312
+ phase('Select')
313
+ log('Judge panel scoring proposals...')
314
+
315
+ const judgeScores = await parallel(
316
+ validProposals.map(proposal => () =>
317
+ agent(
318
+ `Score this plan proposal objectively.
319
+
320
+ Strategy: ${proposal.strategy}
321
+ Summary: ${proposal.summary}
322
+ Approach: ${proposal.approach}
323
+ Complexity: ${proposal.complexity}
324
+ Tasks: ${proposal.total_tasks} across ${proposal.waves.length} waves
325
+ Trade-offs: ${proposal.trade_offs || 'not stated'}
326
+
327
+ Wave breakdown:
328
+ ${proposal.waves.map(w => `Wave ${w.wave_index} (${w.tasks.length} tasks): ${w.tasks.map(t => t.task_id + ': ' + t.title).join(', ')}`).join('\n')}
329
+
330
+ Requirements to cover:
331
+ ${mergedRequirements.map(r => r.objective).join('\n')}
332
+
333
+ Score each dimension 1-5:
334
+ - coverage: do tasks cover all requirements?
335
+ - parallelism: how much work can run concurrently?
336
+ - risk_mitigation: are high-risk items addressed early?
337
+ - convergence_quality: are criteria specific and testable?
338
+ - simplicity: is the plan as simple as possible?
339
+
340
+ Calculate total_score = sum of all dimensions.
341
+ List specific strengths and weaknesses.`,
342
+ { label: `judge:${proposal.strategy}`, phase: 'Select', schema: PLAN_SCORE_SCHEMA }
343
+ )
344
+ )
345
+ )
346
+
347
+ const validJudges = judgeScores.filter(Boolean)
348
+ const bestIdx = validJudges.reduce((best, score, idx) => score.total_score > (validJudges[best] ? validJudges[best].total_score : 0) ? idx : best, 0)
349
+ const selectedPlan = validProposals[bestIdx]
350
+
351
+ const scoreDigest = validJudges.map((s, i) =>
352
+ `${validProposals[i].strategy}: ${s.total_score}/25 (cov:${s.scores.coverage} par:${s.scores.parallelism} risk:${s.scores.risk_mitigation} conv:${s.scores.convergence_quality} sim:${s.scores.simplicity})`
353
+ ).join('\n')
354
+
355
+ log(`Selected: ${selectedPlan.strategy} (${validJudges[bestIdx].total_score}/25)\n${scoreDigest}`)
356
+
357
+ // Phase 4: 3 specialized critics challenge the selected plan
358
+ phase('Check')
359
+ log('3 specialized critics challenging the selected plan...')
360
+
361
+ const criticResults = await parallel([
362
+ () => agent(
363
+ `You are the DEPENDENCY CRITIC. Challenge the task dependency structure.
364
+
365
+ Selected plan (${selectedPlan.strategy}):
366
+ ${selectedPlan.waves.map(w => `Wave ${w.wave_index}: ${w.tasks.map(t => t.task_id + ': ' + t.title + ' [depends: ' + (t.depends_on || []).join(',') + ']').join(', ')}`).join('\n')}
367
+
368
+ Focus:
369
+ 1. Are depends_on relationships correct? Any missing dependencies?
370
+ 2. Could more tasks be parallelized (false dependencies)?
371
+ 3. Are there circular or impossible dependency chains?
372
+ 4. Do later waves actually need ALL prior wave completions?
373
+ 5. Are file modification conflicts between parallel tasks?
374
+
375
+ Set critic_type="dependency" in output.
376
+ Be adversarial — assume dependencies are WRONG until proven correct.`,
377
+ { label: 'critic:dependency', phase: 'Check', schema: CRITIC_SCHEMA, agentType: 'workflow-plan-checker' }
378
+ ),
379
+ () => agent(
380
+ `You are the SCOPE CRITIC. Challenge the plan's coverage and boundaries.
381
+
382
+ Selected plan (${selectedPlan.strategy}):
383
+ ${selectedPlan.waves.map(w => `Wave ${w.wave_index}: ${w.tasks.map(t => t.task_id + ': ' + t.title).join(', ')}`).join('\n')}
384
+
385
+ Requirements:
386
+ ${mergedRequirements.map(r => `- ${r.objective}`).join('\n')}
387
+
388
+ Focus:
389
+ 1. Are there requirements without corresponding tasks?
390
+ 2. Are there tasks that don't map to any requirement (scope creep)?
391
+ 3. Is each task properly scoped (not too large, not too granular)?
392
+ 4. Are edge cases and error paths covered?
393
+ 5. Does the plan handle the Free decisions appropriately?
394
+
395
+ Set critic_type="scope" in output.
396
+ Be adversarial — assume requirements are NOT fully covered.`,
397
+ { label: 'critic:scope', phase: 'Check', schema: CRITIC_SCHEMA, agentType: 'workflow-plan-checker' }
398
+ ),
399
+ () => agent(
400
+ `You are the QUALITY CRITIC. Challenge the convergence criteria and testability.
401
+
402
+ Selected plan (${selectedPlan.strategy}):
403
+ ${selectedPlan.waves.map(w => `Wave ${w.wave_index}: ${w.tasks.map(t => t.task_id + ': ' + t.title + ' [criteria: ' + (t.convergence_criteria || []).join(' | ') + ']').join('\n')}`).join('\n')}
404
+
405
+ Focus:
406
+ 1. Are convergence criteria SPECIFIC and TESTABLE (grep-verifiable or command-runnable)?
407
+ 2. Would a robot be able to verify each criterion unambiguously?
408
+ 3. Are there vague criteria ("works correctly", "properly implemented")?
409
+ 4. Is each task's convergence achievable within that task's scope?
410
+ 5. Are there criteria that should exist but don't?
411
+
412
+ Set critic_type="quality" in output.
413
+ Be adversarial — assume criteria are VAGUE until proven specific.`,
414
+ { label: 'critic:quality', phase: 'Check', schema: CRITIC_SCHEMA, agentType: 'workflow-plan-checker' }
415
+ ),
416
+ ])
417
+
418
+ const validCritics = criticResults.filter(Boolean)
419
+ const criticDigest = validCritics.map(c =>
420
+ `${c.critic_type}: ${c.verdict} (confidence: ${c.confidence}%)\n${c.issues.map(i => ` [${i.severity}] ${i.category}: ${i.description}`).join('\n')}`
421
+ ).join('\n\n')
422
+
423
+ log('Synthesizing critic feedback into final verdict...')
424
+
425
+ const check = await agent(
426
+ `Synthesize 3 critic assessments into a final plan verdict.
427
+
428
+ Selected plan: ${selectedPlan.strategy}
429
+
430
+ === CRITIC ASSESSMENTS ===
431
+ ${criticDigest}
432
+
433
+ === PLAN COMPETITION SCORES ===
434
+ ${scoreDigest}
435
+
436
+ RESOLVE:
437
+ 1. Merge all issues from all critics, tagged with source_critic
438
+ 2. Verdict rules:
439
+ - Any critic has critical issues → "needs-revision"
440
+ - All critics pass → "pass"
441
+ - Only warnings/notes → "pass-with-notes"
442
+ 3. Record adversarial_outcome with each critic's verdict and decisive_factor
443
+ 4. Calculate metrics: task_count, wave_count, avg_convergence_criteria, dependency_depth, estimated_parallelism
444
+ 5. Summarize the competition outcome and critic feedback`,
445
+ { label: 'check:synthesize', phase: 'Check', schema: CHECK_SCHEMA }
446
+ )
447
+
448
+ return {
449
+ contexts: validContexts,
450
+ proposals: validProposals,
451
+ scores: validJudges,
452
+ selected_plan: selectedPlan,
453
+ critics: validCritics,
454
+ check: check,
455
+ metadata: {
456
+ phase: phaseNum,
457
+ scope: scope,
458
+ decision_count: mergedDecisions.length,
459
+ requirement_count: mergedRequirements.length,
460
+ proposals_generated: validProposals.length,
461
+ selected_strategy: selectedPlan.strategy,
462
+ selected_score: validJudges[bestIdx] ? validJudges[bestIdx].total_score : null,
463
+ total_tasks: selectedPlan.total_tasks,
464
+ wave_count: selectedPlan.waves.length,
465
+ check_verdict: check ? check.verdict : 'unknown',
466
+ critical_issues: check ? check.issues.filter(i => i.severity === 'critical').length : 0,
467
+ },
468
+ }