maestro-flow 0.4.17 → 0.4.19

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 (165) hide show
  1. package/.agents/skills/maestro/SKILL.md +1 -1
  2. package/.agents/skills/maestro-analyze/SKILL.md +5 -0
  3. package/.agents/skills/maestro-blueprint/SKILL.md +5 -0
  4. package/.agents/skills/maestro-brainstorm/SKILL.md +5 -0
  5. package/.agents/skills/maestro-next/SKILL.md +254 -0
  6. package/.agents/skills/team-swarm/SKILL.md +180 -0
  7. package/.agents/skills/team-swarm/roles/analyst/role.md +187 -0
  8. package/.agents/skills/team-swarm/roles/ant/role.md +169 -0
  9. package/.agents/skills/team-swarm/roles/coordinator/commands/converge.md +146 -0
  10. package/.agents/skills/team-swarm/roles/coordinator/commands/init-swarm.md +136 -0
  11. package/.agents/skills/team-swarm/roles/coordinator/commands/iterate.md +232 -0
  12. package/.agents/skills/team-swarm/roles/coordinator/role.md +211 -0
  13. package/.agents/skills/team-swarm/roles/scorer/role.md +157 -0
  14. package/.agents/skills/team-swarm/scripts/aco.py +473 -0
  15. package/.agents/skills/team-swarm/scripts/pheromone.py +144 -0
  16. package/.agents/skills/team-swarm/scripts/scoring.py +92 -0
  17. package/.agents/skills/team-swarm/scripts/test_aco.py +475 -0
  18. package/.agents/skills/team-swarm/specs/ant-output-schema.md +119 -0
  19. package/.agents/skills/team-swarm/specs/convergence-criteria.md +106 -0
  20. package/.agents/skills/team-swarm/specs/pheromone-schema.md +123 -0
  21. package/.agents/skills/team-swarm/specs/swarm-config-template.json +71 -0
  22. package/.agents/skills/team-swarm/specs/swarm-protocol.md +117 -0
  23. package/.agy/skills/maestro/SKILL.md +1 -1
  24. package/.agy/skills/maestro-analyze/SKILL.md +5 -0
  25. package/.agy/skills/maestro-blueprint/SKILL.md +5 -0
  26. package/.agy/skills/maestro-brainstorm/SKILL.md +5 -0
  27. package/.agy/skills/maestro-next/SKILL.md +250 -0
  28. package/.agy/skills/team-swarm/SKILL.md +176 -0
  29. package/.agy/skills/team-swarm/roles/analyst/role.md +183 -0
  30. package/.agy/skills/team-swarm/roles/ant/role.md +165 -0
  31. package/.agy/skills/team-swarm/roles/coordinator/commands/converge.md +134 -0
  32. package/.agy/skills/team-swarm/roles/coordinator/commands/init-swarm.md +136 -0
  33. package/.agy/skills/team-swarm/roles/coordinator/commands/iterate.md +202 -0
  34. package/.agy/skills/team-swarm/roles/coordinator/role.md +209 -0
  35. package/.agy/skills/team-swarm/roles/scorer/role.md +153 -0
  36. package/.agy/skills/team-swarm/scripts/aco.py +473 -0
  37. package/.agy/skills/team-swarm/scripts/pheromone.py +144 -0
  38. package/.agy/skills/team-swarm/scripts/scoring.py +92 -0
  39. package/.agy/skills/team-swarm/scripts/test_aco.py +475 -0
  40. package/.agy/skills/team-swarm/specs/ant-output-schema.md +119 -0
  41. package/.agy/skills/team-swarm/specs/convergence-criteria.md +106 -0
  42. package/.agy/skills/team-swarm/specs/pheromone-schema.md +123 -0
  43. package/.agy/skills/team-swarm/specs/swarm-config-template.json +71 -0
  44. package/.agy/skills/team-swarm/specs/swarm-protocol.md +117 -0
  45. package/.claude/commands/maestro-analyze.md +5 -0
  46. package/.claude/commands/maestro-blueprint.md +5 -0
  47. package/.claude/commands/maestro-brainstorm.md +5 -0
  48. package/.claude/commands/maestro-next.md +252 -0
  49. package/.claude/commands/maestro.md +1 -1
  50. package/.claude/skills/team-swarm/SKILL.md +178 -0
  51. package/.claude/skills/team-swarm/roles/analyst/role.md +185 -0
  52. package/.claude/skills/team-swarm/roles/ant/role.md +167 -0
  53. package/.claude/skills/team-swarm/roles/coordinator/commands/converge.md +146 -0
  54. package/.claude/skills/team-swarm/roles/coordinator/commands/init-swarm.md +136 -0
  55. package/.claude/skills/team-swarm/roles/coordinator/commands/iterate.md +232 -0
  56. package/.claude/skills/team-swarm/roles/coordinator/role.md +209 -0
  57. package/.claude/skills/team-swarm/roles/scorer/role.md +155 -0
  58. package/.claude/skills/team-swarm/scripts/aco.py +473 -0
  59. package/.claude/skills/team-swarm/scripts/pheromone.py +144 -0
  60. package/.claude/skills/team-swarm/scripts/scoring.py +92 -0
  61. package/.claude/skills/team-swarm/scripts/test_aco.py +475 -0
  62. package/.claude/skills/team-swarm/specs/ant-output-schema.md +119 -0
  63. package/.claude/skills/team-swarm/specs/convergence-criteria.md +106 -0
  64. package/.claude/skills/team-swarm/specs/pheromone-schema.md +123 -0
  65. package/.claude/skills/team-swarm/specs/swarm-config-template.json +71 -0
  66. package/.claude/skills/team-swarm/specs/swarm-protocol.md +117 -0
  67. package/.codex/skills/learn-decompose/SKILL.md +34 -3
  68. package/.codex/skills/learn-retro/SKILL.md +31 -1
  69. package/.codex/skills/learn-second-opinion/SKILL.md +34 -4
  70. package/.codex/skills/maestro-analyze/SKILL.md +44 -5
  71. package/.codex/skills/maestro-blueprint/SKILL.md +5 -0
  72. package/.codex/skills/maestro-brainstorm/SKILL.md +46 -0
  73. package/.codex/skills/maestro-execute/SKILL.md +61 -5
  74. package/.codex/skills/maestro-milestone-audit/SKILL.md +64 -13
  75. package/.codex/skills/maestro-milestone-complete/SKILL.md +12 -0
  76. package/.codex/skills/maestro-next/SKILL.md +297 -0
  77. package/.codex/skills/maestro-plan/SKILL.md +36 -1
  78. package/.codex/skills/maestro-player/SKILL.md +25 -6
  79. package/.codex/skills/maestro-ralph/SKILL.md +17 -10
  80. package/.codex/skills/maestro-ralph-execute/SKILL.md +2 -1
  81. package/.codex/skills/maestro-roadmap/SKILL.md +35 -4
  82. package/.codex/skills/maestro-ui-codify/SKILL.md +38 -10
  83. package/.codex/skills/maestro-verify/SKILL.md +40 -5
  84. package/.codex/skills/manage-codebase-rebuild/SKILL.md +52 -5
  85. package/.codex/skills/manage-issue-discover/SKILL.md +106 -15
  86. package/.codex/skills/quality-auto-test/SKILL.md +70 -16
  87. package/.codex/skills/quality-debug/SKILL.md +139 -28
  88. package/.codex/skills/quality-refactor/SKILL.md +61 -11
  89. package/.codex/skills/quality-review/SKILL.md +45 -9
  90. package/.codex/skills/quality-test/SKILL.md +58 -3
  91. package/.codex/skills/security-audit/SKILL.md +38 -0
  92. package/.codex/skills/spec-map/SKILL.md +65 -8
  93. package/.codex/skills/team-coordinate/SKILL.md +28 -11
  94. package/.codex/skills/team-coordinate/specs/role-catalog.md +20 -0
  95. package/.codex/skills/team-lifecycle-v4/SKILL.md +23 -7
  96. package/.codex/skills/team-lifecycle-v4/instructions/agent-instruction.md +20 -0
  97. package/.codex/skills/team-quality-assurance/SKILL.md +40 -2
  98. package/.codex/skills/team-review/SKILL.md +42 -2
  99. package/.codex/skills/team-tech-debt/SKILL.md +45 -2
  100. package/.codex/skills/team-testing/SKILL.md +42 -2
  101. package/dashboard/dist-server/dashboard/src/server/wiki/search.d.ts +6 -4
  102. package/dashboard/dist-server/dashboard/src/server/wiki/search.js +50 -8
  103. package/dashboard/dist-server/dashboard/src/server/wiki/search.js.map +1 -1
  104. package/dashboard/dist-server/dashboard/src/server/wiki/virtual-wiki-adapters.d.ts +32 -0
  105. package/dashboard/dist-server/dashboard/src/server/wiki/virtual-wiki-adapters.js +294 -0
  106. package/dashboard/dist-server/dashboard/src/server/wiki/virtual-wiki-adapters.js.map +1 -1
  107. package/dashboard/dist-server/dashboard/src/server/wiki/wiki-indexer.d.ts +1 -0
  108. package/dashboard/dist-server/dashboard/src/server/wiki/wiki-indexer.js +35 -1
  109. package/dashboard/dist-server/dashboard/src/server/wiki/wiki-indexer.js.map +1 -1
  110. package/dashboard/dist-server/dashboard/src/server/wiki/wiki-indexer.test.js +235 -0
  111. package/dashboard/dist-server/dashboard/src/server/wiki/wiki-indexer.test.js.map +1 -1
  112. package/dist/src/commands/install.js +5 -1
  113. package/dist/src/commands/install.js.map +1 -1
  114. package/dist/src/i18n/locales/en.d.ts.map +1 -1
  115. package/dist/src/i18n/locales/en.js +9 -0
  116. package/dist/src/i18n/locales/en.js.map +1 -1
  117. package/dist/src/i18n/locales/zh.d.ts.map +1 -1
  118. package/dist/src/i18n/locales/zh.js +9 -0
  119. package/dist/src/i18n/locales/zh.js.map +1 -1
  120. package/dist/src/i18n/types.d.ts +3 -0
  121. package/dist/src/i18n/types.d.ts.map +1 -1
  122. package/dist/src/ralph/cmd-check.js +1 -1
  123. package/dist/src/ralph/cmd-check.js.map +1 -1
  124. package/dist/src/ralph/cmd-complete.js +1 -1
  125. package/dist/src/ralph/cmd-complete.js.map +1 -1
  126. package/dist/src/ralph/cmd-next.d.ts.map +1 -1
  127. package/dist/src/ralph/cmd-next.js +12 -4
  128. package/dist/src/ralph/cmd-next.js.map +1 -1
  129. package/dist/src/ralph/cmd-session.js +2 -2
  130. package/dist/src/ralph/cmd-session.js.map +1 -1
  131. package/dist/src/ralph/status-store.d.ts +8 -1
  132. package/dist/src/ralph/status-store.d.ts.map +1 -1
  133. package/dist/src/ralph/status-store.js +12 -2
  134. package/dist/src/ralph/status-store.js.map +1 -1
  135. package/dist/src/tools/store-knowhow.d.ts.map +1 -1
  136. package/dist/src/tools/store-knowhow.js +51 -64
  137. package/dist/src/tools/store-knowhow.js.map +1 -1
  138. package/dist/src/tui/install-ui/HooksConfig.d.ts +5 -1
  139. package/dist/src/tui/install-ui/HooksConfig.d.ts.map +1 -1
  140. package/dist/src/tui/install-ui/HooksConfig.js +5 -3
  141. package/dist/src/tui/install-ui/HooksConfig.js.map +1 -1
  142. package/dist/src/tui/install-ui/InstallConfirm.d.ts +2 -0
  143. package/dist/src/tui/install-ui/InstallConfirm.d.ts.map +1 -1
  144. package/dist/src/tui/install-ui/InstallConfirm.js +1 -1
  145. package/dist/src/tui/install-ui/InstallConfirm.js.map +1 -1
  146. package/dist/src/tui/install-ui/InstallExecution.d.ts +1 -0
  147. package/dist/src/tui/install-ui/InstallExecution.d.ts.map +1 -1
  148. package/dist/src/tui/install-ui/InstallExecution.js +26 -3
  149. package/dist/src/tui/install-ui/InstallExecution.js.map +1 -1
  150. package/dist/src/tui/install-ui/InstallFlow.d.ts +1 -1
  151. package/dist/src/tui/install-ui/InstallFlow.d.ts.map +1 -1
  152. package/dist/src/tui/install-ui/InstallFlow.js +76 -16
  153. package/dist/src/tui/install-ui/InstallFlow.js.map +1 -1
  154. package/dist/src/tui/install-ui/InstallHub.d.ts +2 -0
  155. package/dist/src/tui/install-ui/InstallHub.d.ts.map +1 -1
  156. package/dist/src/tui/install-ui/InstallHub.js +8 -0
  157. package/dist/src/tui/install-ui/InstallHub.js.map +1 -1
  158. package/dist/src/tui/install-ui/InstallResult.d.ts.map +1 -1
  159. package/dist/src/tui/install-ui/InstallResult.js +1 -1
  160. package/dist/src/tui/install-ui/InstallResult.js.map +1 -1
  161. package/dist/src/utils/update-notices.js +23 -0
  162. package/dist/src/utils/update-notices.js.map +1 -1
  163. package/package.json +1 -1
  164. package/workflows/finish-work.md +119 -0
  165. package/workflows/milestone-complete.md +23 -1
@@ -0,0 +1,169 @@
1
+ ---
2
+ role: ant
3
+ prefix: ANT
4
+ inner_loop: false
5
+ output_tag: "[ant]"
6
+ message_types:
7
+ success: ant_complete
8
+ error: error
9
+ ---
10
+ <!-- Open-standard mirror generated by scripts/build-agents-standard.mjs — do not edit; re-run after editing .claude/ source. -->
11
+
12
+
13
+ # Ant Role — Phase 2-4
14
+
15
+ Tag: `[ant]` | Prefix: `ANT-*`
16
+ Responsibility: Receive path-hints from ACO controller, explore the task space starting from assigned node, produce schema-locked JSON artifact with self-evaluation.
17
+
18
+ ## Boundaries
19
+
20
+ ### MUST
21
+ - Read assignment JSON from task description (start_node, edge_preferences, max_path_length)
22
+ - Load swarm-config.json to understand objective + task semantics
23
+ - Build a path of length 1..max_path_length starting from start_node
24
+ - Bias choices using `edge_preferences` (pheromone-derived) BUT may deviate when evidence supports it
25
+ - Output strict-schema JSON to `<session>/artifacts/ant-<iter>-<id>.json` (see specs/ant-output-schema.md)
26
+ - Self-validate output before reporting (JSON parses + required fields + node validity)
27
+ - Provide ≥ 1 evidence anchor per path
28
+
29
+ ### MUST NOT
30
+ - Modify pheromone state, best.json, trails/, or other ants' artifacts
31
+ - Skip path_decisions array (one entry per edge traversed)
32
+ - Report self_score > 0.9 without strong evidence (≥ 3 evidence anchors)
33
+ - Visit a node outside the task-space.json nodes list
34
+ - Loop back to a previously visited node in the same path (no cycles)
35
+
36
+ ## Phase 2: Context Loading
37
+
38
+ | Input | Source | Required |
39
+ |-------|--------|----------|
40
+ | Assignment | Task description (parse JSON block) | Yes |
41
+ | Objective | `<session>/swarm-config.json#ant_prompt.objective` | Yes |
42
+ | Task semantics | `<session>/swarm-config.json#ant_prompt` (full block) | Yes |
43
+ | Task space | `<session>/task-space.json` (valid nodes list) | Yes |
44
+ | Pheromone hints | `assignment.edge_preferences` (already passed in) | Yes |
45
+ | Wisdom from prior iters | `<session>/wisdom/learnings.md` (if exists) | Optional |
46
+
47
+ Workflow:
48
+ 1. Extract session path from task description
49
+ 2. Parse assignment JSON block from task description
50
+ 3. Read swarm-config.json -> capture `ant_prompt.objective`, `ant_prompt.evidence_requirements`, `task_space.max_path_length`
51
+ 4. Read task-space.json -> build valid_nodes set
52
+ 5. If `<session>/wisdom/learnings.md` exists -> read for prior-iteration insights
53
+
54
+ ## Phase 3: Exploration
55
+
56
+ **Goal**: Build a path of nodes that maximizes likelihood of achieving the objective. The objective is task-defined (find buggy code, find best refactor target, etc.); ant is task-agnostic infrastructure.
57
+
58
+ Workflow:
59
+
60
+ ### 3.1 Initialize path
61
+ - `path = [assignment.start_node]`
62
+ - `path_decisions = []`
63
+ - `visited = {start_node}`
64
+ - `current = start_node`
65
+
66
+ ### 3.2 Per-step exploration loop (until len(path) reaches max_path_length OR ant decides to stop early)
67
+
68
+ For each step:
69
+
70
+ 1. **Compute candidate neighbors**: all nodes in task_space NOT in `visited`
71
+ 2. **Build choice weights**:
72
+ - For each candidate c: `weight = edge_preferences.get("<current>::<c>", baseline) * heuristic(c)`
73
+ - `heuristic(c)` = ant's own evidence-based judgment (1.0 if no opinion)
74
+ 3. **Investigate top candidates** using available tools:
75
+ - Tool selection: Read, Grep, Glob for code-based task spaces; or CLI delegate `--mode analysis` for richer analysis
76
+ - Gather evidence about each top candidate before committing
77
+ 4. **Choose next node**: weighted-random OR argmax (when high confidence)
78
+ 5. **Record decision**:
79
+ ```json
80
+ {
81
+ "from": "<current>",
82
+ "to": "<chosen>",
83
+ "rationale": "<one-line>",
84
+ "guided_by": "pheromone | heuristic | evidence",
85
+ "pheromone_weight": <edge_preferences value>,
86
+ "deviation_from_hint": <bool — true if chosen != argmax(edge_preferences)>
87
+ }
88
+ ```
89
+ 6. **Append to path**, update `visited`, `current = chosen`
90
+ 7. **Early-stop check**: if evidence shows objective achieved OR no productive next step exists -> stop
91
+
92
+ ### 3.3 Self-evaluate
93
+
94
+ After path is built:
95
+
96
+ 1. **self_score** (0..1): how well does this path satisfy the objective?
97
+ - Use `ant_prompt.evidence_requirements` as rubric
98
+ - Be conservative — penalize for missing evidence, weak rationale
99
+ 2. **self_confidence** (0..1): how sure of the self_score?
100
+ - Low confidence if evidence is sparse or contradictory
101
+ 3. **candidate_solution**: extract the actual deliverable along the path
102
+ - `type` ∈ {string, object, file_ref}
103
+ - `summary` — one-line
104
+ - `content` — actual artifact OR a path to a file written by the ant
105
+
106
+ ### 3.4 Compose artifact JSON
107
+
108
+ Build the full artifact matching specs/ant-output-schema.md. All required fields populated.
109
+
110
+ ## Phase 4: Verify + Publish
111
+
112
+ ### Behavioral Traits
113
+
114
+ #### Accuracy — outputs must be verifiable
115
+ - Every node in `path` MUST exist in task-space.json
116
+ - Every `path_decisions[i].from` MUST equal `path[i]` and `to` MUST equal `path[i+1]`
117
+ - Evidence references (e.g., `file:line`) MUST be valid (Read to confirm if file_ref)
118
+
119
+ #### Feedback Contract
120
+ | Field | Required | Content |
121
+ |-------|----------|---------|
122
+ | files_produced | If ant wrote any | `[artifact_path]` at minimum |
123
+ | artifacts_written | Always | `<session>/artifacts/ant-<iter>-<id>.json` |
124
+ | verification_method | Always | "schema_validated + node_validity_checked" |
125
+
126
+ #### Quality Gate
127
+ - Schema validation pass = REQUIRED before reporting completed
128
+ - Fails -> retry Phase 3 once (max 1 retry to bound cost)
129
+ - Still fails -> report `partial_completion` with `validation_errors` in state data
130
+
131
+ ### Verification Steps
132
+
133
+ 1. **Schema validation**:
134
+ - Parse the JSON via Read
135
+ - Confirm all required fields from specs/ant-output-schema.md
136
+ - Confirm numeric ranges (self_score, self_confidence ∈ [0,1])
137
+ - Confirm `len(path_decisions) == len(path) - 1`
138
+ 2. **Node validity**: every node in path ∈ task_space.json#nodes
139
+ 3. **Evidence check**: at least 1 evidence anchor present; if file_ref, Read to confirm existence
140
+ 4. **Write artifact**: `write_file(<session>/artifacts/ant-<iter>-<id>.json, <json_string>)`
141
+ 5. **Re-read to confirm write**: Read it back, parse, sanity check
142
+
143
+ ### State Update
144
+
145
+ Set Phase 5 `team_msg.log` data:
146
+ ```json
147
+ {
148
+ "task_id": "ANT-<k>-<i>",
149
+ "role": "ant",
150
+ "status": "completed",
151
+ "iteration": <k>,
152
+ "self_score": <float>,
153
+ "self_confidence": <float>,
154
+ "path_length": <int>,
155
+ "artifact_path": "<session>/artifacts/ant-<k>-<i>.json",
156
+ "verification": "schema_pass + node_valid + evidence_present"
157
+ }
158
+ ```
159
+
160
+ ## Error Handling
161
+
162
+ | Scenario | Resolution |
163
+ |----------|------------|
164
+ | Assignment JSON malformed | Report error to coordinator via send_message, STOP |
165
+ | start_node not in task_space | Report error (config mismatch), STOP |
166
+ | No valid neighbors at step 1 | Build single-node path, self_score = 0, report |
167
+ | Schema validation fails twice | Report `partial_completion` with errors list |
168
+ | Evidence requirements unsatisfiable | Lower self_score; document blocker in artifact `notes` field |
169
+ | Tool calls fail (Read/Grep) | Note in artifact `notes`; reduce self_confidence; proceed with available info |
@@ -0,0 +1,146 @@
1
+ # Command: converge
2
+
3
+ Phase 4 execution guide. Run after `aco.py converged` returns `true`.
4
+
5
+ ## Workflow
6
+
7
+ ### Step 1: Call aco.py report
8
+
9
+ ```
10
+ Bash: python <skill_root>/scripts/aco.py --session <session> report
11
+ ```
12
+
13
+ Parse stdout JSON. Expected:
14
+ ```json
15
+ {
16
+ "status": "ok",
17
+ "best": { ant_id, iteration, path, score, candidate_solution, evidence, ... },
18
+ "top_k": [<top 5 trails>],
19
+ "convergence_curve": [{iteration, entropy, tau_max, tau_mean}, ...],
20
+ "final_pheromone_stats": {...},
21
+ "iterations_completed": <int>
22
+ }
23
+ ```
24
+
25
+ Save full report to `<session>/artifacts/swarm-report.json` (raw data for analyst).
26
+
27
+ ### Step 2: Spawn analyst worker
28
+
29
+ ```
30
+ delegate_subagent({
31
+ subagent_type: "team-worker",
32
+ description: "Spawn analyst for swarm synthesis",
33
+ team_name: "swarm",
34
+ name: "analyst",
35
+ run_in_background: true,
36
+ prompt: `## Role Assignment
37
+ role: analyst
38
+ role_spec: <skill_root>/roles/analyst/role.md
39
+ session: <session_path>
40
+ session_id: <session_id>
41
+ team_name: swarm
42
+ requirement: synthesize swarm results into human-readable best-solution.md
43
+ inner_loop: false
44
+
45
+ ## Context
46
+ Report data: <session>/artifacts/swarm-report.json
47
+ Best solution: <session>/best.json
48
+ All trails: <session>/trails/*.jsonl
49
+ Original objective: <config.ant_prompt.objective>
50
+
51
+ ## Progress Milestones
52
+ Report via team_msg at: report loaded -> synthesis done -> verification done.
53
+ Report completion via team_msg type="task_complete" after final send_message.`
54
+ })
55
+ ```
56
+
57
+ STOP. Resume on analyst callback.
58
+
59
+ ### Step 3: On analyst callback
60
+
61
+ Verify `<session>/artifacts/best-solution.md` exists.
62
+
63
+ If missing -> ask_user (skip synthesis / retry analyst).
64
+
65
+ ### Step 4: Build completion summary
66
+
67
+ ```
68
+ [coordinator] ============================================
69
+ [coordinator] SWARM CONVERGED
70
+ [coordinator]
71
+ [coordinator] Iterations: <iterations_completed> / <max_iterations>
72
+ [coordinator] Trigger: <triggered_by[0]>
73
+ [coordinator] Total ants spawned: <iterations * n_ants>
74
+ [coordinator]
75
+ [coordinator] Best Solution:
76
+ [coordinator] ant_id: <best.ant_id>
77
+ [coordinator] iteration: <best.iteration>
78
+ [coordinator] path: <best.path joined with " -> ">
79
+ [coordinator] verified_score: <best.score>
80
+ [coordinator] summary: <best.candidate_solution.summary>
81
+ [coordinator]
82
+ [coordinator] Convergence curve (entropy):
83
+ [coordinator] iter 1: <e1> iter 2: <e2> iter 3: <e3> ...
84
+ [coordinator]
85
+ [coordinator] Deliverables:
86
+ [coordinator] - artifacts/best-solution.md (analyst synthesis)
87
+ [coordinator] - artifacts/swarm-report.json (raw data)
88
+ [coordinator] - best.json (canonical best)
89
+ [coordinator] - trails/*.jsonl (full exploration log)
90
+ [coordinator]
91
+ [coordinator] Session: <session_path>
92
+ [coordinator] ============================================
93
+ ```
94
+
95
+ ### Step 5: Update session state
96
+
97
+ ```
98
+ session.status = "completed"
99
+ session.converged_at = <iso8601>
100
+ session.convergence_reason = <triggered_by>
101
+ ```
102
+
103
+ Log state_update:
104
+ ```
105
+ team_msg.log({
106
+ type: "state_update",
107
+ summary: "Swarm pipeline complete: <iterations_completed> iters, best=<score>",
108
+ data: { ... }
109
+ })
110
+ ```
111
+
112
+ ### Step 6: Completion action (interactive)
113
+
114
+ ```
115
+ ask_user({
116
+ questions: [{
117
+ question: "Swarm pipeline complete. What would you like to do?",
118
+ header: "Completion",
119
+ multiSelect: false,
120
+ options: [
121
+ { label: "Archive & Clean (Recommended)", description: "Archive session, delete team" },
122
+ { label: "Keep Active", description: "Preserve for follow-up iteration" },
123
+ { label: "Export Best Solution", description: "Copy best-solution.md to target path" },
124
+ { label: "Run Another Round", description: "Reset convergence, run K more iterations from current pheromone" }
125
+ ]
126
+ }]
127
+ })
128
+ ```
129
+
130
+ ### Action Handlers
131
+
132
+ | Choice | Steps |
133
+ |--------|-------|
134
+ | Archive & Clean | session.status = "completed"; delete_team; output final summary |
135
+ | Keep Active | session.status = "paused"; output resume instructions |
136
+ | Export Best Solution | ask_user(target path); copy best-solution.md + best.json; then Archive & Clean |
137
+ | Run Another Round | ask_user(additional K); reset convergence counters; re-enter Phase 3 iterate.md |
138
+
139
+ ## Failure Cases
140
+
141
+ | Failure | Action |
142
+ |---------|--------|
143
+ | `aco.py report` fails | Read best.json directly + manual top-K from trails/ |
144
+ | Analyst worker crashes | Generate minimal best-solution.md from best.json template |
145
+ | best.json missing | Pipeline ran but no successful ant - report failure, keep session for inspection |
146
+ | Run Another Round chosen but max_iterations already at limit | ask_user to raise the cap before continuing |
@@ -0,0 +1,136 @@
1
+ # Command: init-swarm
2
+
3
+ Phase 2 execution guide for coordinator. Initializes swarm session and pheromone state.
4
+
5
+ ## Inputs
6
+
7
+ - `swarm-config.json` from Phase 1 (in-memory or already written to candidate session path)
8
+ - `session_id` already computed (`TS-<slug>-<date>`)
9
+ - `skill_root` = `<project>/.claude/skills/team-swarm`
10
+
11
+ ## Workflow
12
+
13
+ ### Step 1: Resolve paths
14
+
15
+ ```
16
+ project_root = shell("pwd")
17
+ skill_root = "<project_root>/.claude/skills/team-swarm"
18
+ session_path = "<project_root>/.workflow/.team/<session_id>"
19
+ ```
20
+
21
+ ### Step 2: Create session directory tree
22
+
23
+ ```
24
+ mkdir -p <session_path>/{pheromone/history,trails,scores,artifacts,wisdom,.msg}
25
+ ```
26
+
27
+ ### Step 3: Write swarm-config.json
28
+
29
+ Write the Phase 1-generated config to `<session_path>/swarm-config.json`.
30
+
31
+ Validate before write:
32
+ - `task_space.nodes` OR `task_space.auto_discover_from` present
33
+ - `swarm.n_ants` >= 2 (single-ant defeats swarm purpose)
34
+ - `convergence.max_iterations` >= 1
35
+
36
+ ### Step 4: Create team
37
+
38
+ ```
39
+ create_team({ name: "swarm" })
40
+ ```
41
+
42
+ ### Step 5: Write role-binding.json
43
+
44
+ ```json
45
+ {
46
+ "ant": "<skill_root>/roles/ant/role.md",
47
+ "scorer": "<skill_root>/roles/scorer/role.md",
48
+ "analyst": "<skill_root>/roles/analyst/role.md"
49
+ }
50
+ ```
51
+
52
+ Saved at `<session_path>/role-binding.json` — workers resolve their role.md from this file.
53
+
54
+ ### Step 6: Call aco.py init
55
+
56
+ ```
57
+ Bash: python <skill_root>/scripts/aco.py --session <session_path> init
58
+ ```
59
+
60
+ Parse stdout JSON. On `status: "error"`:
61
+ - exit_code 2 -> config validation error -> ask_user to fix
62
+ - exit_code 1 -> runtime error -> log to issues.md + retry once
63
+
64
+ On success, capture:
65
+ - `n_nodes` — search space size
66
+ - `n_edges` — initial edge count
67
+ - `pheromone_path` — confirm written
68
+
69
+ ### Step 7: Initialize team-session.json
70
+
71
+ ```json
72
+ {
73
+ "session_id": "<session-id>",
74
+ "task_description": "<user task>",
75
+ "status": "active",
76
+ "team_name": "swarm",
77
+ "skill": "team-swarm",
78
+ "iteration": 0,
79
+ "max_iterations": <config.convergence.max_iterations>,
80
+ "n_ants_per_iter": <config.swarm.n_ants>,
81
+ "config_path": "swarm-config.json",
82
+ "pheromone_path": "pheromone/current.json",
83
+ "roles": ["coordinator", "ant", "scorer", "analyst"],
84
+ "scoring_mode": "<config.scoring.mode>",
85
+ "active_workers": [],
86
+ "completed_iterations": [],
87
+ "completion_action": "interactive",
88
+ "created_at": "<iso8601>"
89
+ }
90
+ ```
91
+
92
+ ### Step 8: Initialize wisdom files
93
+
94
+ Create empty wisdom files with headers:
95
+ - `wisdom/learnings.md` — cross-iteration insights
96
+ - `wisdom/decisions.md` — config refinements made mid-pipeline
97
+ - `wisdom/issues.md` — errors and hallucinations log
98
+
99
+ ### Step 9: Log initialization state_update
100
+
101
+ ```
102
+ team_msg({
103
+ operation: "log",
104
+ session_id: "<session-id>",
105
+ from: "coordinator",
106
+ type: "state_update",
107
+ summary: "Swarm initialized: <n_nodes> nodes, <n_ants> ants/iter, max <K> iterations",
108
+ data: {
109
+ iteration: 0,
110
+ n_nodes: <n>,
111
+ n_ants: <n>,
112
+ max_iterations: <K>,
113
+ scoring_mode: "<mode>"
114
+ }
115
+ })
116
+ ```
117
+
118
+ ### Step 10: Proceed to Phase 3 (iterate.md)
119
+
120
+ Do NOT spawn any workers in this command. First spawn happens in iterate.md step 4.
121
+
122
+ ## Success Criteria
123
+
124
+ - `<session>/swarm-config.json` exists and validates
125
+ - `<session>/pheromone/current.json` exists with `iteration: 0`
126
+ - `<session>/task-space.json` exists with `n_nodes > 0`
127
+ - team-session.json initialized with `iteration: 0`
128
+
129
+ ## Failure Recovery
130
+
131
+ | Failure | Action |
132
+ |---------|--------|
133
+ | Config invalid | ask_user, regenerate, retry |
134
+ | `aco.py init` runtime error | Log to issues.md, retry once, then ask_user (abort/refine) |
135
+ | Directory creation fails | Check disk space / permissions, retry |
136
+ | create_team fails | Check team name conflict (existing swarm session), prompt to clean or resume |
@@ -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, ask_user (retry / abort).
47
+
48
+ ### Step 3: Create ant tasks
49
+
50
+ For each assignment:
51
+
52
+ ```
53
+ create_task({
54
+ subject: "ANT-<k>-<i>: explore from <start_node>",
55
+ description: "Session: <session_path>\nAssignment: <assignment JSON>\nObjective: <config.ant_prompt.objective>"
56
+ })
57
+ update_task({ 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
+ delegate_subagent({
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 send_message.
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
+ delegate_subagent({
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, ask_user |
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) |