maestro-flow 0.4.18 → 0.4.20

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 (181) 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-next/SKILL.md +147 -112
  10. package/.agents/skills/maestro-plan/SKILL.md +4 -0
  11. package/.agents/skills/maestro-ralph/SKILL.md +11 -7
  12. package/.agents/skills/maestro-swarm-workflow/SKILL.md +258 -0
  13. package/.agents/skills/manage-codebase-rebuild/SKILL.md +13 -1
  14. package/.agents/skills/manage-codebase-refresh/SKILL.md +3 -0
  15. package/.agents/skills/spec-setup/SKILL.md +9 -5
  16. package/.agents/skills/team-swarm/SKILL.md +180 -0
  17. package/.agents/skills/team-swarm/roles/analyst/role.md +187 -0
  18. package/.agents/skills/team-swarm/roles/ant/role.md +169 -0
  19. package/.agents/skills/team-swarm/roles/coordinator/commands/converge.md +146 -0
  20. package/.agents/skills/team-swarm/roles/coordinator/commands/init-swarm.md +136 -0
  21. package/.agents/skills/team-swarm/roles/coordinator/commands/iterate.md +232 -0
  22. package/.agents/skills/team-swarm/roles/coordinator/role.md +211 -0
  23. package/.agents/skills/team-swarm/roles/scorer/role.md +157 -0
  24. package/.agents/skills/team-swarm/scripts/aco.py +473 -0
  25. package/.agents/skills/team-swarm/scripts/pheromone.py +144 -0
  26. package/.agents/skills/team-swarm/scripts/scoring.py +92 -0
  27. package/.agents/skills/team-swarm/scripts/test_aco.py +475 -0
  28. package/.agents/skills/team-swarm/specs/ant-output-schema.md +119 -0
  29. package/.agents/skills/team-swarm/specs/convergence-criteria.md +106 -0
  30. package/.agents/skills/team-swarm/specs/pheromone-schema.md +123 -0
  31. package/.agents/skills/team-swarm/specs/swarm-config-template.json +71 -0
  32. package/.agents/skills/team-swarm/specs/swarm-protocol.md +117 -0
  33. package/.agy/agents/workflow-collab-planner.md +4 -1
  34. package/.agy/agents/workflow-plan-checker.md +11 -1
  35. package/.agy/agents/workflow-planner.md +4 -1
  36. package/.agy/skills/maestro/SKILL.md +8 -5
  37. package/.agy/skills/maestro-analyze/SKILL.md +1 -1
  38. package/.agy/skills/maestro-brainstorm/SKILL.md +2 -1
  39. package/.agy/skills/maestro-companion/SKILL.md +529 -0
  40. package/.agy/skills/maestro-grill/SKILL.md +116 -0
  41. package/.agy/skills/maestro-next/SKILL.md +147 -112
  42. package/.agy/skills/maestro-plan/SKILL.md +4 -0
  43. package/.agy/skills/maestro-ralph/SKILL.md +11 -7
  44. package/.agy/skills/maestro-swarm-workflow/SKILL.md +255 -0
  45. package/.agy/skills/manage-codebase-rebuild/SKILL.md +13 -1
  46. package/.agy/skills/manage-codebase-refresh/SKILL.md +3 -0
  47. package/.agy/skills/spec-setup/SKILL.md +9 -5
  48. package/.agy/skills/team-swarm/SKILL.md +176 -0
  49. package/.agy/skills/team-swarm/roles/analyst/role.md +183 -0
  50. package/.agy/skills/team-swarm/roles/ant/role.md +165 -0
  51. package/.agy/skills/team-swarm/roles/coordinator/commands/converge.md +134 -0
  52. package/.agy/skills/team-swarm/roles/coordinator/commands/init-swarm.md +136 -0
  53. package/.agy/skills/team-swarm/roles/coordinator/commands/iterate.md +202 -0
  54. package/.agy/skills/team-swarm/roles/coordinator/role.md +209 -0
  55. package/.agy/skills/team-swarm/roles/scorer/role.md +153 -0
  56. package/.agy/skills/team-swarm/scripts/aco.py +473 -0
  57. package/.agy/skills/team-swarm/scripts/pheromone.py +144 -0
  58. package/.agy/skills/team-swarm/scripts/scoring.py +92 -0
  59. package/.agy/skills/team-swarm/scripts/test_aco.py +475 -0
  60. package/.agy/skills/team-swarm/specs/ant-output-schema.md +119 -0
  61. package/.agy/skills/team-swarm/specs/convergence-criteria.md +106 -0
  62. package/.agy/skills/team-swarm/specs/pheromone-schema.md +123 -0
  63. package/.agy/skills/team-swarm/specs/swarm-config-template.json +71 -0
  64. package/.agy/skills/team-swarm/specs/swarm-protocol.md +117 -0
  65. package/.claude/agents/workflow-collab-planner.md +4 -1
  66. package/.claude/agents/workflow-plan-checker.md +11 -1
  67. package/.claude/agents/workflow-planner.md +4 -1
  68. package/.claude/commands/maestro-analyze.md +1 -1
  69. package/.claude/commands/maestro-brainstorm.md +2 -1
  70. package/.claude/commands/maestro-companion.md +531 -0
  71. package/.claude/commands/maestro-grill.md +114 -0
  72. package/.claude/commands/maestro-next.md +147 -112
  73. package/.claude/commands/maestro-plan.md +4 -0
  74. package/.claude/commands/maestro-ralph.md +11 -7
  75. package/.claude/commands/maestro-swarm-workflow.md +256 -0
  76. package/.claude/commands/maestro.md +8 -5
  77. package/.claude/commands/manage-codebase-rebuild.md +13 -1
  78. package/.claude/commands/manage-codebase-refresh.md +3 -0
  79. package/.claude/commands/spec-setup.md +9 -5
  80. package/.claude/skills/team-swarm/SKILL.md +178 -0
  81. package/.claude/skills/team-swarm/roles/analyst/role.md +185 -0
  82. package/.claude/skills/team-swarm/roles/ant/role.md +167 -0
  83. package/.claude/skills/team-swarm/roles/coordinator/commands/converge.md +146 -0
  84. package/.claude/skills/team-swarm/roles/coordinator/commands/init-swarm.md +136 -0
  85. package/.claude/skills/team-swarm/roles/coordinator/commands/iterate.md +232 -0
  86. package/.claude/skills/team-swarm/roles/coordinator/role.md +209 -0
  87. package/.claude/skills/team-swarm/roles/scorer/role.md +155 -0
  88. package/.claude/skills/team-swarm/scripts/aco.py +473 -0
  89. package/.claude/skills/team-swarm/scripts/pheromone.py +144 -0
  90. package/.claude/skills/team-swarm/scripts/scoring.py +92 -0
  91. package/.claude/skills/team-swarm/scripts/test_aco.py +475 -0
  92. package/.claude/skills/team-swarm/specs/ant-output-schema.md +119 -0
  93. package/.claude/skills/team-swarm/specs/convergence-criteria.md +106 -0
  94. package/.claude/skills/team-swarm/specs/pheromone-schema.md +123 -0
  95. package/.claude/skills/team-swarm/specs/swarm-config-template.json +71 -0
  96. package/.claude/skills/team-swarm/specs/swarm-protocol.md +117 -0
  97. package/.codex/skills/maestro/SKILL.md +7 -2
  98. package/.codex/skills/maestro-companion/SKILL.md +485 -0
  99. package/.codex/skills/maestro-grill/SKILL.md +111 -0
  100. package/.codex/skills/maestro-next/SKILL.md +297 -0
  101. package/.codex/skills/maestro-ralph/SKILL.md +11 -7
  102. package/.codex/skills/manage-codebase-rebuild/SKILL.md +6 -0
  103. package/.codex/skills/manage-codebase-refresh/SKILL.md +6 -0
  104. package/dashboard/dist-server/dashboard/src/server/wiki/graph-analysis.d.ts +36 -0
  105. package/dashboard/dist-server/dashboard/src/server/wiki/graph-analysis.js +138 -2
  106. package/dashboard/dist-server/dashboard/src/server/wiki/graph-analysis.js.map +1 -1
  107. package/dashboard/dist-server/dashboard/src/server/wiki/search.js +13 -0
  108. package/dashboard/dist-server/dashboard/src/server/wiki/search.js.map +1 -1
  109. package/dashboard/dist-server/dashboard/src/server/wiki/virtual-wiki-adapters.d.ts +11 -0
  110. package/dashboard/dist-server/dashboard/src/server/wiki/virtual-wiki-adapters.js +178 -0
  111. package/dashboard/dist-server/dashboard/src/server/wiki/virtual-wiki-adapters.js.map +1 -1
  112. package/dashboard/dist-server/dashboard/src/server/wiki/wiki-indexer.d.ts +1 -0
  113. package/dashboard/dist-server/dashboard/src/server/wiki/wiki-indexer.js +39 -23
  114. package/dashboard/dist-server/dashboard/src/server/wiki/wiki-indexer.js.map +1 -1
  115. package/dist/src/cli.js +1 -0
  116. package/dist/src/cli.js.map +1 -1
  117. package/dist/src/commands/install-backend.d.ts +7 -0
  118. package/dist/src/commands/install-backend.d.ts.map +1 -1
  119. package/dist/src/commands/install-backend.js +14 -0
  120. package/dist/src/commands/install-backend.js.map +1 -1
  121. package/dist/src/commands/install.d.ts.map +1 -1
  122. package/dist/src/commands/install.js +23 -1
  123. package/dist/src/commands/install.js.map +1 -1
  124. package/dist/src/commands/kg.d.ts +11 -0
  125. package/dist/src/commands/kg.d.ts.map +1 -0
  126. package/dist/src/commands/kg.js +515 -0
  127. package/dist/src/commands/kg.js.map +1 -0
  128. package/dist/src/i18n/locales/en.d.ts.map +1 -1
  129. package/dist/src/i18n/locales/en.js +19 -0
  130. package/dist/src/i18n/locales/en.js.map +1 -1
  131. package/dist/src/i18n/locales/zh.d.ts.map +1 -1
  132. package/dist/src/i18n/locales/zh.js +19 -0
  133. package/dist/src/i18n/locales/zh.js.map +1 -1
  134. package/dist/src/i18n/types.d.ts +12 -0
  135. package/dist/src/i18n/types.d.ts.map +1 -1
  136. package/dist/src/tui/install-ui/HooksConfig.d.ts +5 -1
  137. package/dist/src/tui/install-ui/HooksConfig.d.ts.map +1 -1
  138. package/dist/src/tui/install-ui/HooksConfig.js +5 -3
  139. package/dist/src/tui/install-ui/HooksConfig.js.map +1 -1
  140. package/dist/src/tui/install-ui/InstallConfirm.d.ts +3 -0
  141. package/dist/src/tui/install-ui/InstallConfirm.d.ts.map +1 -1
  142. package/dist/src/tui/install-ui/InstallConfirm.js +1 -1
  143. package/dist/src/tui/install-ui/InstallConfirm.js.map +1 -1
  144. package/dist/src/tui/install-ui/InstallExecution.d.ts +2 -0
  145. package/dist/src/tui/install-ui/InstallExecution.d.ts.map +1 -1
  146. package/dist/src/tui/install-ui/InstallExecution.js +48 -3
  147. package/dist/src/tui/install-ui/InstallExecution.js.map +1 -1
  148. package/dist/src/tui/install-ui/InstallFlow.d.ts +1 -1
  149. package/dist/src/tui/install-ui/InstallFlow.d.ts.map +1 -1
  150. package/dist/src/tui/install-ui/InstallFlow.js +95 -17
  151. package/dist/src/tui/install-ui/InstallFlow.js.map +1 -1
  152. package/dist/src/tui/install-ui/InstallHub.d.ts +4 -0
  153. package/dist/src/tui/install-ui/InstallHub.d.ts.map +1 -1
  154. package/dist/src/tui/install-ui/InstallHub.js +14 -0
  155. package/dist/src/tui/install-ui/InstallHub.js.map +1 -1
  156. package/dist/src/tui/install-ui/InstallResult.d.ts.map +1 -1
  157. package/dist/src/tui/install-ui/InstallResult.js +1 -1
  158. package/dist/src/tui/install-ui/InstallResult.js.map +1 -1
  159. package/dist/src/tui/install-ui/KgVendorConfig.d.ts +7 -0
  160. package/dist/src/tui/install-ui/KgVendorConfig.d.ts.map +1 -0
  161. package/dist/src/tui/install-ui/KgVendorConfig.js +9 -0
  162. package/dist/src/tui/install-ui/KgVendorConfig.js.map +1 -0
  163. package/dist/src/utils/update-notices.js +22 -0
  164. package/dist/src/utils/update-notices.js.map +1 -1
  165. package/package.json +1 -1
  166. package/workflows/analyze.md +2 -1
  167. package/workflows/brainstorm.md +24 -1
  168. package/workflows/codebase-rebuild.md +141 -1
  169. package/workflows/codebase-refresh.md +20 -0
  170. package/workflows/finish-work.md +7 -2
  171. package/workflows/grill.md +513 -0
  172. package/workflows/plan.md +7 -4
  173. package/workflows/specs-setup.md +99 -3
  174. package/workflows/swarm/wf-analyze.js +186 -0
  175. package/workflows/swarm/wf-brainstorm.js +284 -0
  176. package/workflows/swarm/wf-execute.js +203 -0
  177. package/workflows/swarm/wf-grill.js +198 -0
  178. package/workflows/swarm/wf-milestone-audit.js +236 -0
  179. package/workflows/swarm/wf-plan.js +233 -0
  180. package/workflows/swarm/wf-review.js +226 -0
  181. package/workflows/swarm/wf-verify.js +298 -0
@@ -0,0 +1,232 @@
1
+ # Command: iterate
2
+
3
+ Phase 3 execution guide. ONE iteration body. Loop is driven by callback re-entry — each iteration is spawn-and-stop.
4
+
5
+ ## Two Entry Points
6
+
7
+ | Entry | Trigger | Action |
8
+ |-------|---------|--------|
9
+ | **Iteration start** | Phase 3 invoked OR previous iteration converged=false | Run "Iteration Start" workflow |
10
+ | **Iteration end** | All ants of current iter reported via callback | Run "Iteration End" workflow |
11
+
12
+ ## Iteration Start Workflow
13
+
14
+ ### Step 1: Determine iteration number
15
+
16
+ ```
17
+ k = session.iteration + 1
18
+ ```
19
+
20
+ If `k > session.max_iterations`: force converge to Phase 4 (safety net).
21
+
22
+ ### Step 2: Call aco.py select
23
+
24
+ ```
25
+ Bash: python <skill_root>/scripts/aco.py --session <session> select --iter <k>
26
+ ```
27
+
28
+ Parse stdout JSON. Expected:
29
+ ```json
30
+ {
31
+ "status": "ok",
32
+ "iteration": <k>,
33
+ "n_assignments": <N>,
34
+ "assignments": [
35
+ {
36
+ "ant_id": "ANT-<k>-<i>",
37
+ "start_node": "<node>",
38
+ "edge_preferences": {"a::b": 0.4, ...},
39
+ "max_path_length": <int>,
40
+ "iteration": <k>
41
+ }, ...
42
+ ]
43
+ }
44
+ ```
45
+
46
+ On error -> log to issues.md, AskUserQuestion (retry / abort).
47
+
48
+ ### Step 3: Create ant tasks
49
+
50
+ For each assignment:
51
+
52
+ ```
53
+ TaskCreate({
54
+ subject: "ANT-<k>-<i>: explore from <start_node>",
55
+ description: "Session: <session_path>\nAssignment: <assignment JSON>\nObjective: <config.ant_prompt.objective>"
56
+ })
57
+ TaskUpdate({ taskId: <new>, owner: "ant" })
58
+ ```
59
+
60
+ Set the task ID to match `ANT-<k>-<i>` (or record mapping in `.msg/meta.json` if framework auto-assigns IDs).
61
+
62
+ ### Step 4: Spawn N ant workers in parallel
63
+
64
+ For each assignment, spawn one team-worker:
65
+
66
+ ```
67
+ Agent({
68
+ subagent_type: "team-worker",
69
+ description: "Spawn ant <ANT-k-i>",
70
+ team_name: "swarm",
71
+ name: "ant-<k>-<i>",
72
+ run_in_background: true,
73
+ prompt: `## Role Assignment
74
+ role: ant
75
+ role_spec: <skill_root>/roles/ant/role.md
76
+ session: <session_path>
77
+ session_id: <session_id>
78
+ team_name: swarm
79
+ requirement: <config.ant_prompt.objective>
80
+ inner_loop: false
81
+
82
+ ## Assignment
83
+ <assignment JSON>
84
+
85
+ ## Progress Milestones
86
+ Report progress via team_msg at phase boundaries.
87
+ Report blockers immediately via team_msg type="blocker".
88
+ Report completion via team_msg type="task_complete" after final SendMessage.
89
+
90
+ Read role_spec (@<skill_root>/roles/ant/role.md) for Phase 2-4 instructions.`
91
+ })
92
+ ```
93
+
94
+ All N spawns in a single message (parallel).
95
+
96
+ ### Step 5: Update session state
97
+
98
+ ```
99
+ session.iteration = <k> (mark "in progress")
100
+ session.active_workers = [<list of ant IDs>]
101
+ ```
102
+
103
+ Log state_update:
104
+ ```
105
+ team_msg.log({
106
+ type: "state_update",
107
+ summary: "Iteration <k> dispatched: <N> ants",
108
+ data: { iteration: <k>, n_ants: <N>, status: "ants_running" }
109
+ })
110
+ ```
111
+
112
+ ### Step 6: STOP
113
+
114
+ Wait for ant callbacks. Each ant reports via team_msg(type="task_complete"). When ALL N reported, callback handler invokes "Iteration End" workflow.
115
+
116
+ ---
117
+
118
+ ## Iteration End Workflow
119
+
120
+ ### Step 1: Verify completion
121
+
122
+ Check `ANT-<k>-*` task statuses. If any still in_progress: not yet complete, do nothing.
123
+
124
+ If all completed -> proceed.
125
+
126
+ ### Step 2: (Conditional) Spawn scorer
127
+
128
+ If `config.scoring.mode == "llm"`:
129
+
130
+ ```
131
+ Agent({
132
+ subagent_type: "team-worker",
133
+ team_name: "swarm",
134
+ name: "scorer-<k>",
135
+ run_in_background: true,
136
+ prompt: `## Role Assignment
137
+ role: scorer
138
+ role_spec: <skill_root>/roles/scorer/role.md
139
+ session: <session_path>
140
+ session_id: <session_id>
141
+ team_name: swarm
142
+ requirement: score iteration <k> ants
143
+ inner_loop: false
144
+
145
+ ## Context
146
+ Iteration to score: <k>
147
+ Output file: <session>/scores/iter-<k>-scores.json
148
+ Read all artifacts: <session>/artifacts/ant-<k>-*.json`
149
+ })
150
+ ```
151
+
152
+ STOP and await scorer callback. On callback resume at Step 3.
153
+
154
+ If `scoring.mode == "script"` or `"fallback"` -> proceed directly to Step 3.
155
+
156
+ ### Step 3: Call aco.py update
157
+
158
+ ```
159
+ Bash: python <skill_root>/scripts/aco.py --session <session> update --iter <k>
160
+ ```
161
+
162
+ Parse stdout JSON. Expected:
163
+ ```json
164
+ {
165
+ "status": "ok",
166
+ "iteration": <k>,
167
+ "n_ants_processed": <N>,
168
+ "mean_score": <float>,
169
+ "best_score": <float>,
170
+ "delta": <float>,
171
+ "elite_updated": <bool>,
172
+ "hallucinations_flagged": [<ant_ids>],
173
+ "stats": {<pheromone stats>}
174
+ }
175
+ ```
176
+
177
+ ### Step 4: Log iteration result
178
+
179
+ ```
180
+ team_msg.log({
181
+ type: "state_update",
182
+ summary: "Iter <k> done: best=<X>, mean=<Y>, delta=<Z>",
183
+ data: { iteration: <k>, best_score, mean_score, delta, elite_updated, hallucinations_flagged }
184
+ })
185
+ ```
186
+
187
+ If `hallucinations_flagged.length > N/2`: append warning to wisdom/issues.md (high-noise iteration).
188
+
189
+ ### Step 5: Call aco.py converged
190
+
191
+ ```
192
+ Bash: python <skill_root>/scripts/aco.py --session <session> converged
193
+ ```
194
+
195
+ Parse:
196
+ ```json
197
+ { "converged": <bool>, "triggered_by": [...], "reason": "...", "metrics": {...} }
198
+ ```
199
+
200
+ ### Step 6: Branch on convergence
201
+
202
+ ```
203
+ if converged:
204
+ update session: completed_iterations.push(k), status = "converging"
205
+ -> proceed to Phase 4 (converge.md)
206
+ else:
207
+ update session: completed_iterations.push(k), active_workers = []
208
+ -> re-enter "Iteration Start" workflow with k+1
209
+ ```
210
+
211
+ ### Step 7: Output progress to user
212
+
213
+ After each iteration:
214
+ ```
215
+ [coordinator] Iteration <k>/<max> complete.
216
+ [coordinator] best=<best_score> mean=<mean_score> delta=<delta>
217
+ [coordinator] entropy=<entropy> hallucinations=<count>
218
+ [coordinator] Status: <converged | continuing to iter k+1>
219
+ ```
220
+
221
+ ---
222
+
223
+ ## Edge Cases
224
+
225
+ | Condition | Handling |
226
+ |-----------|----------|
227
+ | Ant task failed | Mark task failed; if >50% failed in iter -> halt, AskUserQuestion |
228
+ | Ant produced no artifact | Script's update will skip it; if all skipped -> error -> halt |
229
+ | `aco.py update` fails | Retry once; if persistent -> halt with error report |
230
+ | Scorer worker fails | Fall back to `script` or `fallback` mode for this iter, log warning |
231
+ | Iteration takes too long | After timeout (configurable), check `team_msg` for blockers |
232
+ | User sends `feedback <text>` mid-iteration | Append to wisdom/learnings.md; apply at next iteration start (not mid-iter) |
@@ -0,0 +1,209 @@
1
+ ---
2
+ role: coordinator
3
+ ---
4
+
5
+ # Coordinator Role — team-swarm
6
+
7
+ Orchestrate the swarm intelligence pipeline: parse user task -> generate swarm-config -> run iteration loop (script-driven select/spawn/update) -> converge -> synthesize. Hybrid LLM + Python script coordinator.
8
+
9
+ ## Identity
10
+
11
+ - **Name**: `coordinator` | **Tag**: `[coordinator]`
12
+ - **Responsibility**: Translate user intent into swarm-config -> drive K-iteration outer loop -> dispatch N ants per iteration -> consume script verdicts -> deliver final synthesis
13
+
14
+ ## Boundaries
15
+
16
+ ### MUST
17
+ - Generate `swarm-config.json` from user task description (Phase 1)
18
+ - Invoke `scripts/aco.py` for ALL numeric decisions (selection, update, convergence)
19
+ - Spawn ant workers with strict role-spec assignment + path hints from script
20
+ - After each iteration callback: call `aco.py update` -> `aco.py converged` -> decide loop/exit
21
+ - Persist session state via team_msg between iterations
22
+ - Trigger analyst for final synthesis when converged
23
+
24
+ ### MUST NOT
25
+ - Make selection/update/convergence decisions on its own — these belong to the script
26
+ - Modify `pheromone/*.json`, `best.json`, or `trails/*.jsonl` directly — script owns these
27
+ - Skip the convergence check after each iteration
28
+ - Spawn more than `config.swarm.n_ants` ants per iteration
29
+ - Exceed `config.convergence.max_iterations` outer loops
30
+
31
+ ---
32
+
33
+ ## Message Types
34
+
35
+ | Type | Direction | Trigger |
36
+ |------|-----------|---------|
37
+ | state_update | outbound | Iteration start/end, session init |
38
+ | task_unblocked | outbound | Ant batch ready |
39
+ | ant_done | inbound | Individual ant completion (rolled up to batch check) |
40
+ | iteration_complete | inbound | All ants in batch reported |
41
+ | capability_gap | inbound | Ant requests config change |
42
+ | error | inbound | Worker / script failure |
43
+
44
+ ## Command Execution Protocol
45
+
46
+ When coordinator needs to execute a phase command:
47
+
48
+ 1. Read the command file: `roles/coordinator/commands/<command-name>.md`
49
+ 2. Follow the workflow defined inline
50
+ 3. Commands are inline execution guides — NOT separate agents
51
+
52
+ ## Toolbox
53
+
54
+ | Tool | Type | Purpose |
55
+ |------|------|---------|
56
+ | commands/init-swarm.md | Command | Phase 2: build swarm-config + call `aco.py init` |
57
+ | commands/iterate.md | Command | Phase 3: single iteration loop body (select/spawn/update) |
58
+ | commands/converge.md | Command | Phase 4: convergence handler + analyst spawn |
59
+ | `scripts/aco.py` | Script | All numeric decisions (Bash subprocess) |
60
+ | team-worker | Subagent | Worker spawning (ant, scorer, analyst) |
61
+ | TaskCreate / TaskList / TaskGet / TaskUpdate | System | Task lifecycle |
62
+ | team_msg | System | Message bus |
63
+ | SendMessage / AskUserQuestion | System | Comms |
64
+
65
+ ---
66
+
67
+ ## Entry Router
68
+
69
+ | Detection | Condition | Handler |
70
+ |-----------|-----------|---------|
71
+ | Worker callback | Message contains `[ant]` / `[scorer]` / `[analyst]` | -> handleCallback |
72
+ | Status check | Args contain `check` or `status` | -> handleCheck |
73
+ | Manual resume | Args contain `resume` or `continue` | -> handleResume |
74
+ | Iteration complete | All ants of current iteration reported | -> Phase 3.5 (update + converged?) |
75
+ | Pipeline complete | aco.py converged returned true | -> Phase 4 |
76
+ | Interrupted session | Active session exists in `.workflow/.team/TS-*` | -> Phase 0 |
77
+ | New session | None of above | -> Phase 1 |
78
+
79
+ ---
80
+
81
+ ## Phase 0: Session Resume Check
82
+
83
+ 1. Scan `.workflow/.team/TS-*/team-session.json` for `status` in {active, paused}
84
+ 2. Single session -> resume; multiple -> AskUserQuestion
85
+ 3. Reconcile: TaskList vs session.iteration vs pheromone/current.json
86
+ 4. If interrupted mid-iteration -> reset in_progress ant tasks to pending, respawn
87
+ 5. If iteration was complete but update not run -> call `aco.py update` for that iter
88
+ 6. Resume Phase 3 loop at current iteration
89
+
90
+ ---
91
+
92
+ ## Phase 1: Task Analysis + Config Generation
93
+
94
+ **Objective**: Translate user task into `swarm-config.json`.
95
+
96
+ **Workflow**:
97
+
98
+ 1. Parse user task description (text-level only, no codebase exploration)
99
+ 2. Clarify via AskUserQuestion if ambiguous:
100
+ - What is the search space? (file glob, explicit node list, abstract decisions)
101
+ - What is the objective? (find best X, discover Y, optimize Z)
102
+ - How should results be scored? (test pass rate, lint, custom rule, LLM judge)
103
+ - Budget? (max iterations, max ants per iter, token budget)
104
+ 3. Generate `swarm-config.json` (see template at `specs/swarm-config-template.json`):
105
+ - `swarm.n_ants` (default 5)
106
+ - `swarm.max_iterations` -> mirrored into `convergence.max_iterations`
107
+ - `aco.alpha/beta/rho/q` (defaults sane)
108
+ - `task_space.nodes` OR `task_space.auto_discover_from`
109
+ - `scoring.mode` ∈ {script, llm, fallback} based on user answer
110
+ - `ant_prompt.objective` — the actual goal injected into ant role-spec at spawn
111
+ 4. Write config to `<session>/swarm-config.json`
112
+
113
+ **CRITICAL**: Phase 1 does NOT call `aco.py`. It only produces the config.
114
+
115
+ ---
116
+
117
+ ## Phase 2: Init Swarm + Session Setup
118
+
119
+ Delegate to `@commands/init-swarm.md`:
120
+
121
+ 1. Generate session ID: `TS-<slug>-<date>` (slug from task)
122
+ 2. Create session folder structure:
123
+ ```
124
+ .workflow/.team/<session-id>/
125
+ ├── swarm-config.json (from Phase 1)
126
+ ├── pheromone/, trails/, scores/, artifacts/, wisdom/
127
+ ├── .msg/
128
+ └── role-binding.json (paths to role.md files)
129
+ ```
130
+ 3. TeamCreate with team_name = `swarm`
131
+ 4. Bash: `python <skill_root>/scripts/aco.py --session <session> init`
132
+ 5. Parse stdout JSON: capture `n_nodes`, `n_edges`, `pheromone_path`
133
+ 6. Initialize team-session.json with `iteration: 0`, `status: "active"`
134
+ 7. Log state_update via team_msg with config summary
135
+
136
+ ---
137
+
138
+ ## Phase 3: Iteration Loop
139
+
140
+ **Objective**: Run iteration k = 1..K. Each iteration = spawn-and-stop + callback resume.
141
+
142
+ **Per-iteration workflow** (delegate to `@commands/iterate.md`):
143
+
144
+ 1. Increment iteration counter: k = session.iteration + 1
145
+ 2. Bash: `python aco.py --session <session> select --iter <k>`
146
+ -> returns `{assignments: [{ant_id, start_node, edge_preferences, max_path_length}, ...]}`
147
+ 3. For each assignment:
148
+ - TaskCreate `ANT-<k>-<i>` with description including session path + assignment
149
+ - TaskUpdate set owner = `ant`
150
+ 4. Spawn N × team-worker(ant) in background, each with assignment injected into prompt:
151
+ ```
152
+ role: ant
153
+ role_spec: <skill_root>/roles/ant/role.md
154
+ session: <session>
155
+ session_id: <id>
156
+ team_name: swarm
157
+ requirement: <ant_prompt.objective> | Assignment: <full assignment JSON>
158
+ inner_loop: false
159
+ ```
160
+ 5. STOP
161
+
162
+ **On all-ants-complete callback** (Phase 3.5):
163
+
164
+ 1. Verify all `ANT-<k>-*` tasks have status = completed
165
+ 2. (Optional, if `scoring.mode == "llm"`) Spawn scorer worker for iteration k, await callback
166
+ 3. Bash: `python aco.py --session <session> update --iter <k>`
167
+ -> parse `{best_score, mean_score, delta, hallucinations_flagged, ...}`
168
+ 4. Bash: `python aco.py --session <session> converged`
169
+ -> parse `{converged, triggered_by, reason, metrics}`
170
+ 5. Update session.iteration = k, log state_update
171
+ 6. Branch:
172
+ - `converged == true` -> Phase 4
173
+ - `converged == false` -> loop back to step 1 (iteration k+1)
174
+
175
+ ---
176
+
177
+ ## Phase 4: Converge + Synthesize
178
+
179
+ Delegate to `@commands/converge.md`:
180
+
181
+ 1. Bash: `python aco.py --session <session> report` -> capture best + top_k + curve
182
+ 2. Spawn analyst worker:
183
+ ```
184
+ role: analyst
185
+ role_spec: <skill_root>/roles/analyst/role.md
186
+ requirement: synthesize swarm results | session: <session>
187
+ ```
188
+ 3. Await analyst callback -> `best-solution.md` written
189
+ 4. Build completion report:
190
+ - Total iterations, total ants
191
+ - Best score + best path + best solution summary
192
+ - Convergence reason
193
+ - Top 5 trails table
194
+ 5. Execute completion action (interactive AskUserQuestion: Archive / Keep / Export)
195
+
196
+ ---
197
+
198
+ ## Error Handling
199
+
200
+ | Error | Resolution |
201
+ |-------|------------|
202
+ | `aco.py` exits non-zero | Capture stderr, log to issues.md, retry once with same args |
203
+ | Ant produces invalid JSON | Script's `update` skips that artifact + logs warning; coordinator continues |
204
+ | All ants in iteration fail | Halt loop, AskUserQuestion (retry / abort) |
205
+ | Convergence flag never trips | max_iterations safety net always triggers |
206
+ | Script not found | Resolve `<skill_root>/scripts/aco.py`; if missing, fail with install hint |
207
+ | Hallucination cluster (>50% ants flagged) | Pause, AskUserQuestion (continue / refine config) |
208
+ | Task description too vague | AskUserQuestion before Phase 1 config generation |
209
+ | Session corruption | Phase 0 reconciliation; if irrecoverable, archive and start fresh |
@@ -0,0 +1,155 @@
1
+ ---
2
+ role: scorer
3
+ prefix: SCORE
4
+ inner_loop: false
5
+ output_tag: "[scorer]"
6
+ message_types:
7
+ success: scoring_complete
8
+ error: error
9
+ ---
10
+
11
+ # Scorer Role — Phase 2-4
12
+
13
+ Tag: `[scorer]` | Prefix: `SCORE-*`
14
+ Responsibility: After all ants of one iteration complete, compute an authoritative `verified_score` for each ant. Used only when `config.scoring.mode == "llm"`. For `script` or `fallback` modes, this role is not spawned.
15
+
16
+ ## Boundaries
17
+
18
+ ### MUST
19
+ - Read ALL `ant-<iter>-*.json` artifacts for the target iteration
20
+ - Apply a uniform scoring rubric across the batch (consistency over absolute correctness)
21
+ - Produce `<session>/scores/iter-<k>-scores.json` matching the schema in specs/ant-output-schema.md
22
+ - Provide a one-line `rationale` per ant
23
+ - Use a different model from the ant if possible (configured via maestro delegate) to reduce same-source bias
24
+
25
+ ### MUST NOT
26
+ - Modify ant artifacts
27
+ - Score ants outside the target iteration
28
+ - Use self_score as a starting reference (introduces anchoring bias) — score blind first, compare second
29
+ - Assign scores without grounding in evidence claimed by the ant
30
+
31
+ ## Phase 2: Context Loading
32
+
33
+ | Input | Source | Required |
34
+ |-------|--------|----------|
35
+ | Target iteration | Task description (`Iteration to score: <k>`) | Yes |
36
+ | Objective | `<session>/swarm-config.json#ant_prompt.objective` | Yes |
37
+ | Scoring rubric | `<session>/swarm-config.json#scoring.rubric` (if defined) | Optional |
38
+ | Ant artifacts | `<session>/artifacts/ant-<k>-*.json` | Yes |
39
+ | Task space | `<session>/task-space.json` (for context) | Optional |
40
+
41
+ Workflow:
42
+ 1. Extract `k` from task description
43
+ 2. `Glob("<session>/artifacts/ant-<k>-*.json")` -> N artifacts
44
+ 3. Read all N artifacts in parallel
45
+ 4. Read swarm-config.json -> capture objective + rubric
46
+
47
+ ## Phase 3: Blind Batch Scoring
48
+
49
+ ### 3.1 Build rubric
50
+
51
+ If `config.scoring.rubric` provided, use verbatim. Otherwise default rubric:
52
+
53
+ | Dimension | Weight |
54
+ |-----------|--------|
55
+ | Path relevance to objective | 0.35 |
56
+ | Evidence strength (count + specificity) | 0.30 |
57
+ | Candidate solution quality | 0.25 |
58
+ | Path coherence (decisions follow logical chain) | 0.10 |
59
+
60
+ ### 3.2 Score each artifact
61
+
62
+ For each ant artifact (process them blind to self_score order):
63
+
64
+ 1. Extract: `path`, `path_decisions[].rationale`, `evidence`, `candidate_solution`
65
+ 2. **Do NOT read** `self_score` / `self_confidence` until after scoring
66
+ 3. Apply rubric:
67
+ - Each dimension -> 0.0..1.0
68
+ - Weighted sum -> `verified_score`
69
+ 4. One-line rationale: which dimensions drove the score
70
+ 5. Append to scores dict
71
+
72
+ ### 3.3 Calibrate across batch
73
+
74
+ After all individual scores:
75
+ - Compute mean + std of verified_scores
76
+ - If all scores within ±0.05 (compressed range) -> spread them apart by re-ranking with finer rubric application
77
+ - If exactly one is 1.0 and rest are < 0.3 -> double-check the outlier
78
+
79
+ ### 3.4 Compose scores file
80
+
81
+ ```json
82
+ {
83
+ "iteration": <k>,
84
+ "scorer_type": "llm",
85
+ "rubric_used": "default | custom_from_config",
86
+ "scores": {
87
+ "ANT-<k>-1": { "verified_score": <float>, "rationale": "<one-line>" },
88
+ "ANT-<k>-2": { "verified_score": <float>, "rationale": "<one-line>" },
89
+ ...
90
+ },
91
+ "calibration": {
92
+ "mean": <float>,
93
+ "std": <float>,
94
+ "min": <float>,
95
+ "max": <float>
96
+ },
97
+ "computed_at": "<iso8601>"
98
+ }
99
+ ```
100
+
101
+ ## Phase 4: Verify + Publish
102
+
103
+ ### Behavioral Traits
104
+
105
+ #### Accuracy
106
+ - Every `verified_score` in [0.0, 1.0]
107
+ - Every `ANT-<k>-i` in the input set has a score entry
108
+ - `rationale` references at least one dimension of the rubric
109
+
110
+ #### Feedback Contract
111
+ | Field | Required | Content |
112
+ |-------|----------|---------|
113
+ | artifacts_written | Always | `<session>/scores/iter-<k>-scores.json` |
114
+ | n_ants_scored | Always | int |
115
+ | verification_method | Always | "blind_then_calibrated + range_check" |
116
+
117
+ #### Quality Gate
118
+ - All N ant artifacts must have a score entry — partial scoring is NOT acceptable
119
+ - If a single artifact is unparseable -> assign verified_score = 0.0 with rationale "artifact_invalid", continue
120
+ - Validation fails -> retry Phase 3 once
121
+
122
+ ### Verification Steps
123
+
124
+ 1. Re-read the scores file via Read
125
+ 2. Parse JSON, validate schema
126
+ 3. Confirm `len(scores) == n_ants_in_iteration`
127
+ 4. Confirm score range
128
+ 5. Write hallucination delta to wisdom for coordinator visibility:
129
+ - For each ant, compute `delta = |self_score - verified_score|`
130
+ - If `delta > 0.4` for >50% of ants in this iter -> append warning to `<session>/wisdom/issues.md`
131
+
132
+ ### State Update
133
+
134
+ ```json
135
+ {
136
+ "task_id": "SCORE-<k>",
137
+ "role": "scorer",
138
+ "status": "completed",
139
+ "iteration": <k>,
140
+ "n_ants_scored": <N>,
141
+ "mean_verified_score": <float>,
142
+ "artifact_path": "<session>/scores/iter-<k>-scores.json",
143
+ "verification": "blind_scored + schema_validated"
144
+ }
145
+ ```
146
+
147
+ ## Error Handling
148
+
149
+ | Scenario | Resolution |
150
+ |----------|------------|
151
+ | No artifacts found for iteration | Report error - coordinator either misrouted or ants all failed |
152
+ | Artifact parse fails | Score = 0.0, rationale = "artifact_invalid", continue |
153
+ | Rubric ambiguous for a path | Default to 0.5 with rationale "rubric_uncertain", lower confidence in calibration |
154
+ | All scores identical | Force differentiation via secondary tiebreaker (path length, evidence count) |
155
+ | Scores file write fails | Retry; on second failure report blocker |