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