maestro-flow 0.4.18 → 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 (91) hide show
  1. package/.agents/skills/maestro-next/SKILL.md +147 -112
  2. package/.agents/skills/team-swarm/SKILL.md +180 -0
  3. package/.agents/skills/team-swarm/roles/analyst/role.md +187 -0
  4. package/.agents/skills/team-swarm/roles/ant/role.md +169 -0
  5. package/.agents/skills/team-swarm/roles/coordinator/commands/converge.md +146 -0
  6. package/.agents/skills/team-swarm/roles/coordinator/commands/init-swarm.md +136 -0
  7. package/.agents/skills/team-swarm/roles/coordinator/commands/iterate.md +232 -0
  8. package/.agents/skills/team-swarm/roles/coordinator/role.md +211 -0
  9. package/.agents/skills/team-swarm/roles/scorer/role.md +157 -0
  10. package/.agents/skills/team-swarm/scripts/aco.py +473 -0
  11. package/.agents/skills/team-swarm/scripts/pheromone.py +144 -0
  12. package/.agents/skills/team-swarm/scripts/scoring.py +92 -0
  13. package/.agents/skills/team-swarm/scripts/test_aco.py +475 -0
  14. package/.agents/skills/team-swarm/specs/ant-output-schema.md +119 -0
  15. package/.agents/skills/team-swarm/specs/convergence-criteria.md +106 -0
  16. package/.agents/skills/team-swarm/specs/pheromone-schema.md +123 -0
  17. package/.agents/skills/team-swarm/specs/swarm-config-template.json +71 -0
  18. package/.agents/skills/team-swarm/specs/swarm-protocol.md +117 -0
  19. package/.agy/skills/maestro-next/SKILL.md +147 -112
  20. package/.agy/skills/team-swarm/SKILL.md +176 -0
  21. package/.agy/skills/team-swarm/roles/analyst/role.md +183 -0
  22. package/.agy/skills/team-swarm/roles/ant/role.md +165 -0
  23. package/.agy/skills/team-swarm/roles/coordinator/commands/converge.md +134 -0
  24. package/.agy/skills/team-swarm/roles/coordinator/commands/init-swarm.md +136 -0
  25. package/.agy/skills/team-swarm/roles/coordinator/commands/iterate.md +202 -0
  26. package/.agy/skills/team-swarm/roles/coordinator/role.md +209 -0
  27. package/.agy/skills/team-swarm/roles/scorer/role.md +153 -0
  28. package/.agy/skills/team-swarm/scripts/aco.py +473 -0
  29. package/.agy/skills/team-swarm/scripts/pheromone.py +144 -0
  30. package/.agy/skills/team-swarm/scripts/scoring.py +92 -0
  31. package/.agy/skills/team-swarm/scripts/test_aco.py +475 -0
  32. package/.agy/skills/team-swarm/specs/ant-output-schema.md +119 -0
  33. package/.agy/skills/team-swarm/specs/convergence-criteria.md +106 -0
  34. package/.agy/skills/team-swarm/specs/pheromone-schema.md +123 -0
  35. package/.agy/skills/team-swarm/specs/swarm-config-template.json +71 -0
  36. package/.agy/skills/team-swarm/specs/swarm-protocol.md +117 -0
  37. package/.claude/commands/maestro-next.md +147 -112
  38. package/.claude/skills/team-swarm/SKILL.md +178 -0
  39. package/.claude/skills/team-swarm/roles/analyst/role.md +185 -0
  40. package/.claude/skills/team-swarm/roles/ant/role.md +167 -0
  41. package/.claude/skills/team-swarm/roles/coordinator/commands/converge.md +146 -0
  42. package/.claude/skills/team-swarm/roles/coordinator/commands/init-swarm.md +136 -0
  43. package/.claude/skills/team-swarm/roles/coordinator/commands/iterate.md +232 -0
  44. package/.claude/skills/team-swarm/roles/coordinator/role.md +209 -0
  45. package/.claude/skills/team-swarm/roles/scorer/role.md +155 -0
  46. package/.claude/skills/team-swarm/scripts/aco.py +473 -0
  47. package/.claude/skills/team-swarm/scripts/pheromone.py +144 -0
  48. package/.claude/skills/team-swarm/scripts/scoring.py +92 -0
  49. package/.claude/skills/team-swarm/scripts/test_aco.py +475 -0
  50. package/.claude/skills/team-swarm/specs/ant-output-schema.md +119 -0
  51. package/.claude/skills/team-swarm/specs/convergence-criteria.md +106 -0
  52. package/.claude/skills/team-swarm/specs/pheromone-schema.md +123 -0
  53. package/.claude/skills/team-swarm/specs/swarm-config-template.json +71 -0
  54. package/.claude/skills/team-swarm/specs/swarm-protocol.md +117 -0
  55. package/.codex/skills/maestro-next/SKILL.md +297 -0
  56. package/dist/src/commands/install.js +5 -1
  57. package/dist/src/commands/install.js.map +1 -1
  58. package/dist/src/i18n/locales/en.d.ts.map +1 -1
  59. package/dist/src/i18n/locales/en.js +9 -0
  60. package/dist/src/i18n/locales/en.js.map +1 -1
  61. package/dist/src/i18n/locales/zh.d.ts.map +1 -1
  62. package/dist/src/i18n/locales/zh.js +9 -0
  63. package/dist/src/i18n/locales/zh.js.map +1 -1
  64. package/dist/src/i18n/types.d.ts +3 -0
  65. package/dist/src/i18n/types.d.ts.map +1 -1
  66. package/dist/src/tui/install-ui/HooksConfig.d.ts +5 -1
  67. package/dist/src/tui/install-ui/HooksConfig.d.ts.map +1 -1
  68. package/dist/src/tui/install-ui/HooksConfig.js +5 -3
  69. package/dist/src/tui/install-ui/HooksConfig.js.map +1 -1
  70. package/dist/src/tui/install-ui/InstallConfirm.d.ts +2 -0
  71. package/dist/src/tui/install-ui/InstallConfirm.d.ts.map +1 -1
  72. package/dist/src/tui/install-ui/InstallConfirm.js +1 -1
  73. package/dist/src/tui/install-ui/InstallConfirm.js.map +1 -1
  74. package/dist/src/tui/install-ui/InstallExecution.d.ts +1 -0
  75. package/dist/src/tui/install-ui/InstallExecution.d.ts.map +1 -1
  76. package/dist/src/tui/install-ui/InstallExecution.js +26 -3
  77. package/dist/src/tui/install-ui/InstallExecution.js.map +1 -1
  78. package/dist/src/tui/install-ui/InstallFlow.d.ts +1 -1
  79. package/dist/src/tui/install-ui/InstallFlow.d.ts.map +1 -1
  80. package/dist/src/tui/install-ui/InstallFlow.js +76 -16
  81. package/dist/src/tui/install-ui/InstallFlow.js.map +1 -1
  82. package/dist/src/tui/install-ui/InstallHub.d.ts +2 -0
  83. package/dist/src/tui/install-ui/InstallHub.d.ts.map +1 -1
  84. package/dist/src/tui/install-ui/InstallHub.js +8 -0
  85. package/dist/src/tui/install-ui/InstallHub.js.map +1 -1
  86. package/dist/src/tui/install-ui/InstallResult.d.ts.map +1 -1
  87. package/dist/src/tui/install-ui/InstallResult.js +1 -1
  88. package/dist/src/tui/install-ui/InstallResult.js.map +1 -1
  89. package/dist/src/utils/update-notices.js +11 -0
  90. package/dist/src/utils/update-notices.js.map +1 -1
  91. package/package.json +1 -1
@@ -0,0 +1,185 @@
1
+ ---
2
+ role: analyst
3
+ prefix: ANALYST
4
+ inner_loop: false
5
+ output_tag: "[analyst]"
6
+ message_types:
7
+ success: analysis_ready
8
+ error: error
9
+ ---
10
+
11
+ # Analyst Role — Phase 2-4
12
+
13
+ Tag: `[analyst]` | Prefix: `ANALYST-*`
14
+ Responsibility: After swarm converges, synthesize the best solution + top trails + convergence curve into a human-readable `best-solution.md` report. Provides interpretation, not just data dump.
15
+
16
+ ## Boundaries
17
+
18
+ ### MUST
19
+ - Read `<session>/best.json`, `<session>/artifacts/swarm-report.json`, all `<session>/trails/*.jsonl`
20
+ - Produce `<session>/artifacts/best-solution.md` as the final deliverable
21
+ - Explain WHY the best path won (which decisions mattered, evidence chain)
22
+ - Compare best vs runner-ups to surface stability vs luck
23
+ - Document convergence story (entropy curve, when stagnation hit)
24
+
25
+ ### MUST NOT
26
+ - Re-score solutions (that is scorer's job — analyst takes verified_score as given)
27
+ - Modify best.json, trails, or pheromone state
28
+ - Generate solutions of its own — analyst synthesizes existing ant outputs
29
+ - Exceed ~150 lines in best-solution.md (be sharp, not verbose)
30
+
31
+ ## Phase 2: Context Loading
32
+
33
+ | Input | Source | Required |
34
+ |-------|--------|----------|
35
+ | Original objective | `<session>/swarm-config.json#ant_prompt.objective` | Yes |
36
+ | Best solution | `<session>/best.json` | Yes |
37
+ | Full swarm report | `<session>/artifacts/swarm-report.json` | Yes |
38
+ | All trails | `<session>/trails/*.jsonl` | Yes |
39
+ | Convergence reason | swarm-report.json or `aco.py converged` output | Yes |
40
+ | Best ant artifact | `<session>/artifacts/ant-<best.iteration>-<best.id>.json` (full evidence) | Yes |
41
+ | Issues log | `<session>/wisdom/issues.md` | Optional |
42
+
43
+ Workflow:
44
+ 1. Extract session path from task description
45
+ 2. Read swarm-config.json -> capture objective
46
+ 3. Read best.json -> identify best ant
47
+ 4. Read full swarm-report.json -> get top_k + convergence_curve
48
+ 5. Read the best ant's full artifact for evidence chain
49
+ 6. Read all trails/*.jsonl into a list (chronological)
50
+
51
+ ## Phase 3: Synthesis
52
+
53
+ ### 3.1 Structure the report
54
+
55
+ Layout for `best-solution.md`:
56
+
57
+ ```markdown
58
+ # Swarm Result — <objective_short_form>
59
+
60
+ ## Best Solution
61
+
62
+ **Path**: node_a → node_c → node_f
63
+ **Verified Score**: 0.82
64
+ **Iteration**: 3 of 5
65
+ **Ant**: ANT-3-2
66
+
67
+ ### Summary
68
+ <one paragraph — what the best solution proposes and why it answers the objective>
69
+
70
+ ### Evidence Chain
71
+ - `src/foo.ts:42` — <how this evidence supports the decision>
72
+ - `tests/foo.spec.ts:18` — <...>
73
+
74
+ ### Candidate Artifact
75
+ <extract from best.candidate_solution — quote or summarize, link to file if file_ref>
76
+
77
+ ## Why This Path Won
78
+
79
+ | Decision | Pheromone-guided? | Why it mattered |
80
+ |----------|-------------------|-----------------|
81
+ | start = node_a | weighted | <reason> |
82
+ | a → c | yes (0.45 hint) | <reason> |
83
+ | c → f | NO (deviation) | <reason> — this was the key call |
84
+
85
+ ## Runner-Up Solutions
86
+
87
+ | Rank | Ant | Path | Score | Diff from best |
88
+ |------|-----|------|-------|----------------|
89
+ | 2 | ANT-2-1 | a → b → e | 0.74 | -0.08; weaker evidence at e |
90
+ | 3 | ANT-4-3 | a → c → g | 0.71 | -0.11; valid but less specific |
91
+
92
+ ## Convergence Story
93
+
94
+ Iterations: 4 of 5 max
95
+ Trigger: stagnation (best unchanged for 2 iterations)
96
+
97
+ Entropy curve:
98
+ - iter 1: 3.21 (broad exploration)
99
+ - iter 2: 2.45 (narrowing on node_a region)
100
+ - iter 3: 1.85 (best emerges at ANT-3-2)
101
+ - iter 4: 1.72 (consensus around best, no improvement)
102
+
103
+ Interpretation: <2-3 sentences on whether the swarm converged on a genuine optimum or got stuck>
104
+
105
+ ## Caveats
106
+
107
+ - <e.g., 40% of ants in iter 2 flagged as hallucinations>
108
+ - <e.g., evidence for node_f is single-source — recommend manual verification>
109
+ - <e.g., search space had only N nodes — larger space may surface better solutions>
110
+
111
+ ## Reproducibility
112
+
113
+ - Config: `swarm-config.json` (pinned)
114
+ - Best path: `best.json`
115
+ - Full trails: `trails/<iter>.jsonl`
116
+ - Random seed: <if used>
117
+ ```
118
+
119
+ ### 3.2 Interpretation rules
120
+
121
+ - **Why-it-won analysis** is the highest-value content. Don't just describe the path — explain which decisions were pivotal.
122
+ - **Pheromone vs deviation**: track which steps followed pheromone hints vs deviated. Deviations that produced higher scores are the most interesting signal.
123
+ - **Runner-up diff**: surface why #2 lost — was it a weaker path or just unlucky evidence?
124
+ - **Caveats are mandatory**: every swarm result has limitations. List them honestly.
125
+
126
+ ### 3.3 Constraints
127
+
128
+ - Target ≤ 150 lines
129
+ - No prose padding — every section earns its place
130
+ - Quote evidence verbatim where possible (file:line refs)
131
+ - Don't editorialize beyond what evidence supports
132
+
133
+ ## Phase 4: Verify + Publish
134
+
135
+ ### Behavioral Traits
136
+
137
+ #### Accuracy
138
+ - Every cited path/score MUST match best.json or trails source
139
+ - Every evidence reference MUST be verifiable (Read to confirm if file_ref)
140
+ - Convergence curve numbers MUST match swarm-report.json#convergence_curve
141
+
142
+ #### Feedback Contract
143
+ | Field | Required | Content |
144
+ |-------|----------|---------|
145
+ | artifacts_written | Always | `<session>/artifacts/best-solution.md` |
146
+ | line_count | Always | int (target ≤ 150) |
147
+ | verification_method | Always | "cross_ref_with_best.json + evidence_verified" |
148
+
149
+ #### Quality Gate
150
+ - Final report file exists and parses as markdown
151
+ - All sections present (Best Solution / Why Won / Runner-Ups / Convergence / Caveats / Reproducibility)
152
+ - Line count ≤ 200 (hard cap — fail if exceeded, retry with sharper edit)
153
+
154
+ ### Verification Steps
155
+
156
+ 1. Read written best-solution.md back
157
+ 2. Cross-check best.score against best.json
158
+ 3. Confirm runner-up scores against trails
159
+ 4. If file_ref evidence in best.candidate_solution -> Read to confirm file exists
160
+ 5. Count lines — if > 200, condense and rewrite
161
+
162
+ ### State Update
163
+
164
+ ```json
165
+ {
166
+ "task_id": "ANALYST-1",
167
+ "role": "analyst",
168
+ "status": "completed",
169
+ "artifact_path": "<session>/artifacts/best-solution.md",
170
+ "best_score": <float>,
171
+ "best_ant_id": "<id>",
172
+ "line_count": <int>,
173
+ "verification": "cross_ref_pass + evidence_verified"
174
+ }
175
+ ```
176
+
177
+ ## Error Handling
178
+
179
+ | Scenario | Resolution |
180
+ |----------|------------|
181
+ | best.json missing | Pipeline produced no valid ant — write minimal report with `status: no_solution` |
182
+ | Trails empty | Same as above — no exploration data to analyze |
183
+ | Best ant artifact missing | Use only best.json fields; note as caveat |
184
+ | Cross-ref mismatch (score discrepancy) | Trust best.json; note discrepancy in caveats |
185
+ | Line count > 200 after rewrite | Hard-fail report; coordinator decides retry vs accept |
@@ -0,0 +1,167 @@
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
+
11
+ # Ant Role — Phase 2-4
12
+
13
+ Tag: `[ant]` | Prefix: `ANT-*`
14
+ Responsibility: Receive path-hints from ACO controller, explore the task space starting from assigned node, produce schema-locked JSON artifact with self-evaluation.
15
+
16
+ ## Boundaries
17
+
18
+ ### MUST
19
+ - Read assignment JSON from task description (start_node, edge_preferences, max_path_length)
20
+ - Load swarm-config.json to understand objective + task semantics
21
+ - Build a path of length 1..max_path_length starting from start_node
22
+ - Bias choices using `edge_preferences` (pheromone-derived) BUT may deviate when evidence supports it
23
+ - Output strict-schema JSON to `<session>/artifacts/ant-<iter>-<id>.json` (see specs/ant-output-schema.md)
24
+ - Self-validate output before reporting (JSON parses + required fields + node validity)
25
+ - Provide ≥ 1 evidence anchor per path
26
+
27
+ ### MUST NOT
28
+ - Modify pheromone state, best.json, trails/, or other ants' artifacts
29
+ - Skip path_decisions array (one entry per edge traversed)
30
+ - Report self_score > 0.9 without strong evidence (≥ 3 evidence anchors)
31
+ - Visit a node outside the task-space.json nodes list
32
+ - Loop back to a previously visited node in the same path (no cycles)
33
+
34
+ ## Phase 2: Context Loading
35
+
36
+ | Input | Source | Required |
37
+ |-------|--------|----------|
38
+ | Assignment | Task description (parse JSON block) | Yes |
39
+ | Objective | `<session>/swarm-config.json#ant_prompt.objective` | Yes |
40
+ | Task semantics | `<session>/swarm-config.json#ant_prompt` (full block) | Yes |
41
+ | Task space | `<session>/task-space.json` (valid nodes list) | Yes |
42
+ | Pheromone hints | `assignment.edge_preferences` (already passed in) | Yes |
43
+ | Wisdom from prior iters | `<session>/wisdom/learnings.md` (if exists) | Optional |
44
+
45
+ Workflow:
46
+ 1. Extract session path from task description
47
+ 2. Parse assignment JSON block from task description
48
+ 3. Read swarm-config.json -> capture `ant_prompt.objective`, `ant_prompt.evidence_requirements`, `task_space.max_path_length`
49
+ 4. Read task-space.json -> build valid_nodes set
50
+ 5. If `<session>/wisdom/learnings.md` exists -> read for prior-iteration insights
51
+
52
+ ## Phase 3: Exploration
53
+
54
+ **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.
55
+
56
+ Workflow:
57
+
58
+ ### 3.1 Initialize path
59
+ - `path = [assignment.start_node]`
60
+ - `path_decisions = []`
61
+ - `visited = {start_node}`
62
+ - `current = start_node`
63
+
64
+ ### 3.2 Per-step exploration loop (until len(path) reaches max_path_length OR ant decides to stop early)
65
+
66
+ For each step:
67
+
68
+ 1. **Compute candidate neighbors**: all nodes in task_space NOT in `visited`
69
+ 2. **Build choice weights**:
70
+ - For each candidate c: `weight = edge_preferences.get("<current>::<c>", baseline) * heuristic(c)`
71
+ - `heuristic(c)` = ant's own evidence-based judgment (1.0 if no opinion)
72
+ 3. **Investigate top candidates** using available tools:
73
+ - Tool selection: Read, Grep, Glob for code-based task spaces; or CLI delegate `--mode analysis` for richer analysis
74
+ - Gather evidence about each top candidate before committing
75
+ 4. **Choose next node**: weighted-random OR argmax (when high confidence)
76
+ 5. **Record decision**:
77
+ ```json
78
+ {
79
+ "from": "<current>",
80
+ "to": "<chosen>",
81
+ "rationale": "<one-line>",
82
+ "guided_by": "pheromone | heuristic | evidence",
83
+ "pheromone_weight": <edge_preferences value>,
84
+ "deviation_from_hint": <bool — true if chosen != argmax(edge_preferences)>
85
+ }
86
+ ```
87
+ 6. **Append to path**, update `visited`, `current = chosen`
88
+ 7. **Early-stop check**: if evidence shows objective achieved OR no productive next step exists -> stop
89
+
90
+ ### 3.3 Self-evaluate
91
+
92
+ After path is built:
93
+
94
+ 1. **self_score** (0..1): how well does this path satisfy the objective?
95
+ - Use `ant_prompt.evidence_requirements` as rubric
96
+ - Be conservative — penalize for missing evidence, weak rationale
97
+ 2. **self_confidence** (0..1): how sure of the self_score?
98
+ - Low confidence if evidence is sparse or contradictory
99
+ 3. **candidate_solution**: extract the actual deliverable along the path
100
+ - `type` ∈ {string, object, file_ref}
101
+ - `summary` — one-line
102
+ - `content` — actual artifact OR a path to a file written by the ant
103
+
104
+ ### 3.4 Compose artifact JSON
105
+
106
+ Build the full artifact matching specs/ant-output-schema.md. All required fields populated.
107
+
108
+ ## Phase 4: Verify + Publish
109
+
110
+ ### Behavioral Traits
111
+
112
+ #### Accuracy — outputs must be verifiable
113
+ - Every node in `path` MUST exist in task-space.json
114
+ - Every `path_decisions[i].from` MUST equal `path[i]` and `to` MUST equal `path[i+1]`
115
+ - Evidence references (e.g., `file:line`) MUST be valid (Read to confirm if file_ref)
116
+
117
+ #### Feedback Contract
118
+ | Field | Required | Content |
119
+ |-------|----------|---------|
120
+ | files_produced | If ant wrote any | `[artifact_path]` at minimum |
121
+ | artifacts_written | Always | `<session>/artifacts/ant-<iter>-<id>.json` |
122
+ | verification_method | Always | "schema_validated + node_validity_checked" |
123
+
124
+ #### Quality Gate
125
+ - Schema validation pass = REQUIRED before reporting completed
126
+ - Fails -> retry Phase 3 once (max 1 retry to bound cost)
127
+ - Still fails -> report `partial_completion` with `validation_errors` in state data
128
+
129
+ ### Verification Steps
130
+
131
+ 1. **Schema validation**:
132
+ - Parse the JSON via Read
133
+ - Confirm all required fields from specs/ant-output-schema.md
134
+ - Confirm numeric ranges (self_score, self_confidence ∈ [0,1])
135
+ - Confirm `len(path_decisions) == len(path) - 1`
136
+ 2. **Node validity**: every node in path ∈ task_space.json#nodes
137
+ 3. **Evidence check**: at least 1 evidence anchor present; if file_ref, Read to confirm existence
138
+ 4. **Write artifact**: `Write(<session>/artifacts/ant-<iter>-<id>.json, <json_string>)`
139
+ 5. **Re-read to confirm write**: Read it back, parse, sanity check
140
+
141
+ ### State Update
142
+
143
+ Set Phase 5 `team_msg.log` data:
144
+ ```json
145
+ {
146
+ "task_id": "ANT-<k>-<i>",
147
+ "role": "ant",
148
+ "status": "completed",
149
+ "iteration": <k>,
150
+ "self_score": <float>,
151
+ "self_confidence": <float>,
152
+ "path_length": <int>,
153
+ "artifact_path": "<session>/artifacts/ant-<k>-<i>.json",
154
+ "verification": "schema_pass + node_valid + evidence_present"
155
+ }
156
+ ```
157
+
158
+ ## Error Handling
159
+
160
+ | Scenario | Resolution |
161
+ |----------|------------|
162
+ | Assignment JSON malformed | Report error to coordinator via SendMessage, STOP |
163
+ | start_node not in task_space | Report error (config mismatch), STOP |
164
+ | No valid neighbors at step 1 | Build single-node path, self_score = 0, report |
165
+ | Schema validation fails twice | Report `partial_completion` with errors list |
166
+ | Evidence requirements unsatisfiable | Lower self_score; document blocker in artifact `notes` field |
167
+ | 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
+ Agent({
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 SendMessage.`
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 -> AskUserQuestion (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
+ AskUserQuestion({
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"; TeamDelete; output final summary |
135
+ | Keep Active | session.status = "paused"; output resume instructions |
136
+ | Export Best Solution | AskUserQuestion(target path); copy best-solution.md + best.json; then Archive & Clean |
137
+ | Run Another Round | AskUserQuestion(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 | AskUserQuestion 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 = Bash("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
+ TeamCreate({ 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 -> AskUserQuestion 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 | AskUserQuestion, regenerate, retry |
134
+ | `aco.py init` runtime error | Log to issues.md, retry once, then AskUserQuestion (abort/refine) |
135
+ | Directory creation fails | Check disk space / permissions, retry |
136
+ | TeamCreate fails | Check team name conflict (existing swarm session), prompt to clean or resume |