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.
- package/.agents/skills/maestro-next/SKILL.md +147 -112
- package/.agents/skills/team-swarm/SKILL.md +180 -0
- package/.agents/skills/team-swarm/roles/analyst/role.md +187 -0
- package/.agents/skills/team-swarm/roles/ant/role.md +169 -0
- package/.agents/skills/team-swarm/roles/coordinator/commands/converge.md +146 -0
- package/.agents/skills/team-swarm/roles/coordinator/commands/init-swarm.md +136 -0
- package/.agents/skills/team-swarm/roles/coordinator/commands/iterate.md +232 -0
- package/.agents/skills/team-swarm/roles/coordinator/role.md +211 -0
- package/.agents/skills/team-swarm/roles/scorer/role.md +157 -0
- package/.agents/skills/team-swarm/scripts/aco.py +473 -0
- package/.agents/skills/team-swarm/scripts/pheromone.py +144 -0
- package/.agents/skills/team-swarm/scripts/scoring.py +92 -0
- package/.agents/skills/team-swarm/scripts/test_aco.py +475 -0
- package/.agents/skills/team-swarm/specs/ant-output-schema.md +119 -0
- package/.agents/skills/team-swarm/specs/convergence-criteria.md +106 -0
- package/.agents/skills/team-swarm/specs/pheromone-schema.md +123 -0
- package/.agents/skills/team-swarm/specs/swarm-config-template.json +71 -0
- package/.agents/skills/team-swarm/specs/swarm-protocol.md +117 -0
- package/.agy/skills/maestro-next/SKILL.md +147 -112
- package/.agy/skills/team-swarm/SKILL.md +176 -0
- package/.agy/skills/team-swarm/roles/analyst/role.md +183 -0
- package/.agy/skills/team-swarm/roles/ant/role.md +165 -0
- package/.agy/skills/team-swarm/roles/coordinator/commands/converge.md +134 -0
- package/.agy/skills/team-swarm/roles/coordinator/commands/init-swarm.md +136 -0
- package/.agy/skills/team-swarm/roles/coordinator/commands/iterate.md +202 -0
- package/.agy/skills/team-swarm/roles/coordinator/role.md +209 -0
- package/.agy/skills/team-swarm/roles/scorer/role.md +153 -0
- package/.agy/skills/team-swarm/scripts/aco.py +473 -0
- package/.agy/skills/team-swarm/scripts/pheromone.py +144 -0
- package/.agy/skills/team-swarm/scripts/scoring.py +92 -0
- package/.agy/skills/team-swarm/scripts/test_aco.py +475 -0
- package/.agy/skills/team-swarm/specs/ant-output-schema.md +119 -0
- package/.agy/skills/team-swarm/specs/convergence-criteria.md +106 -0
- package/.agy/skills/team-swarm/specs/pheromone-schema.md +123 -0
- package/.agy/skills/team-swarm/specs/swarm-config-template.json +71 -0
- package/.agy/skills/team-swarm/specs/swarm-protocol.md +117 -0
- package/.claude/commands/maestro-next.md +147 -112
- package/.claude/skills/team-swarm/SKILL.md +178 -0
- package/.claude/skills/team-swarm/roles/analyst/role.md +185 -0
- package/.claude/skills/team-swarm/roles/ant/role.md +167 -0
- package/.claude/skills/team-swarm/roles/coordinator/commands/converge.md +146 -0
- package/.claude/skills/team-swarm/roles/coordinator/commands/init-swarm.md +136 -0
- package/.claude/skills/team-swarm/roles/coordinator/commands/iterate.md +232 -0
- package/.claude/skills/team-swarm/roles/coordinator/role.md +209 -0
- package/.claude/skills/team-swarm/roles/scorer/role.md +155 -0
- package/.claude/skills/team-swarm/scripts/aco.py +473 -0
- package/.claude/skills/team-swarm/scripts/pheromone.py +144 -0
- package/.claude/skills/team-swarm/scripts/scoring.py +92 -0
- package/.claude/skills/team-swarm/scripts/test_aco.py +475 -0
- package/.claude/skills/team-swarm/specs/ant-output-schema.md +119 -0
- package/.claude/skills/team-swarm/specs/convergence-criteria.md +106 -0
- package/.claude/skills/team-swarm/specs/pheromone-schema.md +123 -0
- package/.claude/skills/team-swarm/specs/swarm-config-template.json +71 -0
- package/.claude/skills/team-swarm/specs/swarm-protocol.md +117 -0
- package/.codex/skills/maestro-next/SKILL.md +297 -0
- package/dist/src/commands/install.js +5 -1
- package/dist/src/commands/install.js.map +1 -1
- package/dist/src/i18n/locales/en.d.ts.map +1 -1
- package/dist/src/i18n/locales/en.js +9 -0
- package/dist/src/i18n/locales/en.js.map +1 -1
- package/dist/src/i18n/locales/zh.d.ts.map +1 -1
- package/dist/src/i18n/locales/zh.js +9 -0
- package/dist/src/i18n/locales/zh.js.map +1 -1
- package/dist/src/i18n/types.d.ts +3 -0
- package/dist/src/i18n/types.d.ts.map +1 -1
- package/dist/src/tui/install-ui/HooksConfig.d.ts +5 -1
- package/dist/src/tui/install-ui/HooksConfig.d.ts.map +1 -1
- package/dist/src/tui/install-ui/HooksConfig.js +5 -3
- package/dist/src/tui/install-ui/HooksConfig.js.map +1 -1
- package/dist/src/tui/install-ui/InstallConfirm.d.ts +2 -0
- package/dist/src/tui/install-ui/InstallConfirm.d.ts.map +1 -1
- package/dist/src/tui/install-ui/InstallConfirm.js +1 -1
- package/dist/src/tui/install-ui/InstallConfirm.js.map +1 -1
- package/dist/src/tui/install-ui/InstallExecution.d.ts +1 -0
- package/dist/src/tui/install-ui/InstallExecution.d.ts.map +1 -1
- package/dist/src/tui/install-ui/InstallExecution.js +26 -3
- package/dist/src/tui/install-ui/InstallExecution.js.map +1 -1
- package/dist/src/tui/install-ui/InstallFlow.d.ts +1 -1
- package/dist/src/tui/install-ui/InstallFlow.d.ts.map +1 -1
- package/dist/src/tui/install-ui/InstallFlow.js +76 -16
- package/dist/src/tui/install-ui/InstallFlow.js.map +1 -1
- package/dist/src/tui/install-ui/InstallHub.d.ts +2 -0
- package/dist/src/tui/install-ui/InstallHub.d.ts.map +1 -1
- package/dist/src/tui/install-ui/InstallHub.js +8 -0
- package/dist/src/tui/install-ui/InstallHub.js.map +1 -1
- package/dist/src/tui/install-ui/InstallResult.d.ts.map +1 -1
- package/dist/src/tui/install-ui/InstallResult.js +1 -1
- package/dist/src/tui/install-ui/InstallResult.js.map +1 -1
- package/dist/src/utils/update-notices.js +11 -0
- package/dist/src/utils/update-notices.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
# Convergence Criteria
|
|
2
|
+
|
|
3
|
+
When does the swarm stop iterating? Defines stop conditions computed by `aco.py converged`.
|
|
4
|
+
|
|
5
|
+
## Stop Conditions (any-of)
|
|
6
|
+
|
|
7
|
+
The swarm stops when **any** of the configured criteria triggers:
|
|
8
|
+
|
|
9
|
+
| Criterion | Default | Description |
|
|
10
|
+
|-----------|---------|-------------|
|
|
11
|
+
| `max_iterations` | 5 | Hard cap on iteration count |
|
|
12
|
+
| `stagnation` | patience = 2 | Best score unchanged for N iterations |
|
|
13
|
+
| `entropy_floor` | 0.5 | Pheromone Shannon entropy drops below threshold (matrix highly concentrated) |
|
|
14
|
+
| `budget_tokens` | 100000 | Total token cost exceeds budget |
|
|
15
|
+
| `target_score` | 0.95 | Best verified_score crosses target |
|
|
16
|
+
|
|
17
|
+
## Configuration
|
|
18
|
+
|
|
19
|
+
```json
|
|
20
|
+
{
|
|
21
|
+
"convergence": {
|
|
22
|
+
"max_iterations": 5,
|
|
23
|
+
"stagnation": { "enabled": true, "patience": 2, "min_delta": 0.01 },
|
|
24
|
+
"entropy_floor": { "enabled": true, "threshold": 0.5 },
|
|
25
|
+
"budget_tokens": { "enabled": false, "max": 100000 },
|
|
26
|
+
"target_score": { "enabled": true, "value": 0.95 }
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Output Schema (aco.py converged)
|
|
32
|
+
|
|
33
|
+
```json
|
|
34
|
+
{
|
|
35
|
+
"converged": true,
|
|
36
|
+
"iteration": 4,
|
|
37
|
+
"reason": "stagnation",
|
|
38
|
+
"metrics": {
|
|
39
|
+
"best_score": 0.78,
|
|
40
|
+
"mean_score": 0.62,
|
|
41
|
+
"entropy": 1.85,
|
|
42
|
+
"iterations_completed": 4,
|
|
43
|
+
"iterations_since_best_change": 2,
|
|
44
|
+
"total_tokens_used": 42000
|
|
45
|
+
},
|
|
46
|
+
"triggered_by": ["stagnation"],
|
|
47
|
+
"recommendation": "best solution is stable; recommend report"
|
|
48
|
+
}
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## Selection Logic
|
|
52
|
+
|
|
53
|
+
```
|
|
54
|
+
def check_convergence(history, config):
|
|
55
|
+
triggered = []
|
|
56
|
+
|
|
57
|
+
if iteration >= config.max_iterations:
|
|
58
|
+
triggered.append("max_iterations")
|
|
59
|
+
|
|
60
|
+
if config.stagnation.enabled:
|
|
61
|
+
recent = history[-config.stagnation.patience-1:]
|
|
62
|
+
if len(recent) > config.stagnation.patience:
|
|
63
|
+
deltas = [abs(recent[i].best - recent[i-1].best)
|
|
64
|
+
for i in range(1, len(recent))]
|
|
65
|
+
if all(d < config.stagnation.min_delta for d in deltas):
|
|
66
|
+
triggered.append("stagnation")
|
|
67
|
+
|
|
68
|
+
if config.entropy_floor.enabled and current_entropy < threshold:
|
|
69
|
+
triggered.append("entropy_floor")
|
|
70
|
+
|
|
71
|
+
if config.budget_tokens.enabled and total_tokens > config.budget_tokens.max:
|
|
72
|
+
triggered.append("budget_tokens")
|
|
73
|
+
|
|
74
|
+
if config.target_score.enabled and best_score >= config.target_score.value:
|
|
75
|
+
triggered.append("target_score")
|
|
76
|
+
|
|
77
|
+
return {"converged": len(triggered) > 0, "triggered_by": triggered}
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
## Entropy Calculation
|
|
81
|
+
|
|
82
|
+
Shannon entropy of normalized pheromone distribution:
|
|
83
|
+
|
|
84
|
+
```
|
|
85
|
+
p_i = tau_i / sum(tau) for each active edge
|
|
86
|
+
H = -sum(p_i * log2(p_i))
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
- High H → diverse exploration (early stage)
|
|
90
|
+
- Low H → concentrated on few paths (converging)
|
|
91
|
+
- H < threshold + best score plateau → safe to stop
|
|
92
|
+
|
|
93
|
+
## Why Multi-Criterion
|
|
94
|
+
|
|
95
|
+
Single criterion is fragile:
|
|
96
|
+
- `max_iterations` alone wastes budget if converged early
|
|
97
|
+
- `stagnation` alone may stop too early on noisy scoring
|
|
98
|
+
- `entropy_floor` alone may trigger before useful solutions emerge
|
|
99
|
+
|
|
100
|
+
Combination = early termination when safe, but always bounded by `max_iterations`.
|
|
101
|
+
|
|
102
|
+
## Anti-Patterns
|
|
103
|
+
|
|
104
|
+
- DO NOT use `stagnation` with `patience < 2` — noise will trigger false stops
|
|
105
|
+
- DO NOT disable `max_iterations` — runaway risk
|
|
106
|
+
- DO NOT set `target_score` without verified scoring — self_score is too optimistic
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
# Pheromone Schema
|
|
2
|
+
|
|
3
|
+
Pheromone matrix structure, update formula, evaporation rule. Authoritative spec for `pheromone/current.json` and history snapshots.
|
|
4
|
+
|
|
5
|
+
## File Layout
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
<session>/pheromone/
|
|
9
|
+
├── current.json # latest state, overwritten each iteration
|
|
10
|
+
├── history/
|
|
11
|
+
│ ├── 1.json # snapshot after iteration 1
|
|
12
|
+
│ ├── 2.json
|
|
13
|
+
│ └── ...
|
|
14
|
+
└── init.json # snapshot of initial state (immutable)
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Schema (pheromone/current.json)
|
|
18
|
+
|
|
19
|
+
```json
|
|
20
|
+
{
|
|
21
|
+
"version": "1.0",
|
|
22
|
+
"iteration": 3,
|
|
23
|
+
"n_nodes": 42,
|
|
24
|
+
"matrix_type": "edge_weighted_sparse",
|
|
25
|
+
"tau": {
|
|
26
|
+
"<node_a>::<node_b>": 0.85,
|
|
27
|
+
"<node_a>::<node_c>": 1.20,
|
|
28
|
+
"<node_x>::<node_y>": 0.13
|
|
29
|
+
},
|
|
30
|
+
"node_tau": {
|
|
31
|
+
"<node_a>": 0.92,
|
|
32
|
+
"<node_b>": 1.05
|
|
33
|
+
},
|
|
34
|
+
"metadata": {
|
|
35
|
+
"alpha": 1.0,
|
|
36
|
+
"beta": 2.0,
|
|
37
|
+
"rho": 0.2,
|
|
38
|
+
"q": 1.0,
|
|
39
|
+
"tau_init": 1.0,
|
|
40
|
+
"tau_min": 0.01,
|
|
41
|
+
"tau_max": 10.0
|
|
42
|
+
},
|
|
43
|
+
"stats": {
|
|
44
|
+
"mean": 0.91,
|
|
45
|
+
"max": 2.34,
|
|
46
|
+
"min": 0.05,
|
|
47
|
+
"entropy": 3.21,
|
|
48
|
+
"n_edges_active": 87
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### Field Semantics
|
|
54
|
+
|
|
55
|
+
| Field | Type | Meaning |
|
|
56
|
+
|-------|------|---------|
|
|
57
|
+
| `matrix_type` | enum | `edge_weighted_sparse` (default), `node_weighted`, `full_dense` |
|
|
58
|
+
| `tau` | dict | Edge pheromone, key `"a::b"` (undirected uses lexical order) |
|
|
59
|
+
| `node_tau` | dict | Node-level pheromone (used when matrix_type = node_weighted) |
|
|
60
|
+
| `metadata.alpha` | float | Pheromone weight in selection probability |
|
|
61
|
+
| `metadata.beta` | float | Heuristic weight in selection probability |
|
|
62
|
+
| `metadata.rho` | float | Evaporation rate (0..1), applied each iteration |
|
|
63
|
+
| `metadata.q` | float | Deposit constant |
|
|
64
|
+
| `metadata.tau_min/max` | float | MMAS bounds — prevents premature convergence/explosion |
|
|
65
|
+
| `stats.entropy` | float | Shannon entropy of normalized tau — convergence signal |
|
|
66
|
+
|
|
67
|
+
## Update Formula
|
|
68
|
+
|
|
69
|
+
After iteration k completes, for each ant a in iteration:
|
|
70
|
+
|
|
71
|
+
```
|
|
72
|
+
delta_tau_a(edge) = q * verified_score_a if edge in path_a, else 0
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
Then:
|
|
76
|
+
|
|
77
|
+
```
|
|
78
|
+
tau(edge) = (1 - rho) * tau(edge) + sum_over_ants(delta_tau_a(edge))
|
|
79
|
+
tau(edge) = clip(tau(edge), tau_min, tau_max)
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
**Elitist strategy** (always on): the best path of all time deposits extra `q * best_score` on its edges before clipping.
|
|
83
|
+
|
|
84
|
+
## Selection Probability (used in `aco.py select`)
|
|
85
|
+
|
|
86
|
+
For ant at node i choosing neighbor j from candidate set N(i):
|
|
87
|
+
|
|
88
|
+
```
|
|
89
|
+
p(i -> j) = (tau(i,j)^alpha * eta(i,j)^beta) / sum_{k in N(i)}(tau(i,k)^alpha * eta(i,k)^beta)
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
where `eta` is a heuristic value from config (e.g., inverse-distance, prior knowledge). Default `eta = 1.0` if not provided.
|
|
93
|
+
|
|
94
|
+
## Path-Hints vs Full-Path
|
|
95
|
+
|
|
96
|
+
`aco.py select` does NOT prescribe a complete path — it returns **path-hints**: weighted starting nodes + edge probabilities. The ant (LLM) then makes the actual node-by-node choices, with freedom to deviate based on its own evidence. This preserves LLM judgment while keeping search guided.
|
|
97
|
+
|
|
98
|
+
```json
|
|
99
|
+
{
|
|
100
|
+
"ant_id": "ANT-3-2",
|
|
101
|
+
"start_node": "node_a",
|
|
102
|
+
"edge_preferences": {
|
|
103
|
+
"node_a::node_b": 0.45,
|
|
104
|
+
"node_a::node_c": 0.30,
|
|
105
|
+
"node_a::node_d": 0.25
|
|
106
|
+
},
|
|
107
|
+
"max_path_length": 5
|
|
108
|
+
}
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
## Initialization
|
|
112
|
+
|
|
113
|
+
```
|
|
114
|
+
tau_init for all edges = config.aco.tau_init (default 1.0)
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
If `task_space.nodes` is `auto_discover_from: <glob>`, init.py discovers nodes by globbing and initializes a full uniform matrix.
|
|
118
|
+
|
|
119
|
+
## History & Reproducibility
|
|
120
|
+
|
|
121
|
+
- `init.json` — frozen snapshot of initial state (never overwritten)
|
|
122
|
+
- `history/k.json` — full pheromone state after iteration k (for convergence-curve analysis)
|
|
123
|
+
- All updates are deterministic given (prior state + ant artifacts + config)
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
{
|
|
2
|
+
"_comment": "User-facing config template. Coordinator generates this from task description in Phase 1. Fields prefixed with _ are documentation, omit from real config.",
|
|
3
|
+
|
|
4
|
+
"swarm": {
|
|
5
|
+
"_comment": "Top-level swarm parameters",
|
|
6
|
+
"n_ants": 5,
|
|
7
|
+
"max_iterations": 5,
|
|
8
|
+
"elite_keep": 3
|
|
9
|
+
},
|
|
10
|
+
|
|
11
|
+
"aco": {
|
|
12
|
+
"_comment": "ACO algorithm hyperparameters - defaults are sane",
|
|
13
|
+
"alpha": 1.0,
|
|
14
|
+
"beta": 2.0,
|
|
15
|
+
"rho": 0.2,
|
|
16
|
+
"q": 1.0,
|
|
17
|
+
"tau_init": 1.0,
|
|
18
|
+
"tau_min": 0.01,
|
|
19
|
+
"tau_max": 10.0
|
|
20
|
+
},
|
|
21
|
+
|
|
22
|
+
"task_space": {
|
|
23
|
+
"_comment": "Define the search space. Use EITHER 'nodes' (explicit) OR 'auto_discover_from' (glob).",
|
|
24
|
+
"type": "graph",
|
|
25
|
+
"nodes": ["node_a", "node_b", "node_c"],
|
|
26
|
+
"_alt_auto_discover": "auto_discover_from: 'src/**/*.ts'",
|
|
27
|
+
"max_path_length": 5,
|
|
28
|
+
"start_nodes": "any",
|
|
29
|
+
"edges": "complete"
|
|
30
|
+
},
|
|
31
|
+
|
|
32
|
+
"scoring": {
|
|
33
|
+
"_comment": "How verified_score is computed. mode = script | llm | fallback",
|
|
34
|
+
"mode": "fallback",
|
|
35
|
+
"_alt_script": "script_path: '../my-scoring-rule.py' (file must define def score(ant_artifact) -> float)",
|
|
36
|
+
"_alt_llm": "rubric: 'custom scoring rubric text for scorer role'",
|
|
37
|
+
"self_score_discount": 0.5
|
|
38
|
+
},
|
|
39
|
+
|
|
40
|
+
"ant_prompt": {
|
|
41
|
+
"_comment": "What the ant actually tries to achieve. This is the bridge between task semantics and ACO mechanics.",
|
|
42
|
+
"objective": "Find the file with the highest density of suspicious code patterns",
|
|
43
|
+
"evidence_requirements": [
|
|
44
|
+
"At least 1 file:line reference per node visited",
|
|
45
|
+
"Concrete code snippet showing the suspicious pattern"
|
|
46
|
+
],
|
|
47
|
+
"tools_hint": "Use Grep + Read for code-based exploration"
|
|
48
|
+
},
|
|
49
|
+
|
|
50
|
+
"convergence": {
|
|
51
|
+
"_comment": "Stop conditions - any-of triggers convergence",
|
|
52
|
+
"max_iterations": 5,
|
|
53
|
+
"stagnation": {
|
|
54
|
+
"enabled": true,
|
|
55
|
+
"patience": 2,
|
|
56
|
+
"min_delta": 0.01
|
|
57
|
+
},
|
|
58
|
+
"entropy_floor": {
|
|
59
|
+
"enabled": true,
|
|
60
|
+
"threshold": 0.5
|
|
61
|
+
},
|
|
62
|
+
"budget_tokens": {
|
|
63
|
+
"enabled": false,
|
|
64
|
+
"max": 100000
|
|
65
|
+
},
|
|
66
|
+
"target_score": {
|
|
67
|
+
"enabled": true,
|
|
68
|
+
"value": 0.95
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
# Swarm Protocol
|
|
2
|
+
|
|
3
|
+
Master protocol document for team-swarm: defines how the LLM coordinator and Python ACO controller interface, how ants explore the task space, and how exploration results flow back to update pheromone state.
|
|
4
|
+
|
|
5
|
+
## Design Philosophy
|
|
6
|
+
|
|
7
|
+
| Principle | Rationale |
|
|
8
|
+
|-----------|-----------|
|
|
9
|
+
| **Outer loop = script, inner loop = LLM** | Optimization math is cheap and deterministic; LLM evaluation is expensive and noisy. Separate them. |
|
|
10
|
+
| **Coordinator is a hybrid** | LLM coordinator translates user intent + dispatches workers; Python script makes all numeric decisions (selection, update, convergence). |
|
|
11
|
+
| **Schema-locked ant output** | LLM output → algorithm input bridge demands strict JSON contract. Free-text outputs cannot feed pheromone updates. |
|
|
12
|
+
| **Two-layer scoring** | `self_score` (LLM self-report) is fast but optimistic. `verified_score` (script or LLM scorer) is the only authoritative input to pheromone update. |
|
|
13
|
+
| **Universal task space** | Coordinator does not bake in any domain. User provides `swarm-config.json` with task space + scoring rule. |
|
|
14
|
+
|
|
15
|
+
## Three-Component Architecture
|
|
16
|
+
|
|
17
|
+
```
|
|
18
|
+
+-----------------------------------------------------+
|
|
19
|
+
| LLM Coordinator (roles/coordinator/role.md) |
|
|
20
|
+
| - Parses user task → emits swarm-config.json |
|
|
21
|
+
| - Phase 3 main loop: calls script, spawns workers |
|
|
22
|
+
| - Translates worker callbacks back into script ops |
|
|
23
|
+
+--------+--------------------------------------------+
|
|
24
|
+
| Bash subprocess
|
|
25
|
+
v
|
|
26
|
+
+-----------------------------------------------------+
|
|
27
|
+
| Python ACO Controller (scripts/aco.py) |
|
|
28
|
+
| - CLI subcommands: init/select/update/converged |
|
|
29
|
+
| - Owns pheromone matrix + elite tracker |
|
|
30
|
+
| - Pure functions of session state files |
|
|
31
|
+
+-----------------------------------------------------+
|
|
32
|
+
^ |
|
|
33
|
+
| reads artifacts/ant-*.json | writes pheromone/*.json
|
|
34
|
+
| v
|
|
35
|
+
+-----------------------------------------------------+
|
|
36
|
+
| LLM Workers (team-worker agents) |
|
|
37
|
+
| - ant: explores assigned path, writes JSON |
|
|
38
|
+
| - scorer: assigns verified_score (optional) |
|
|
39
|
+
| - analyst: final synthesis of elite solutions |
|
|
40
|
+
+-----------------------------------------------------+
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Iteration Lifecycle
|
|
44
|
+
|
|
45
|
+
```
|
|
46
|
+
[Coordinator] init phase
|
|
47
|
+
└─> python aco.py init --config <session>/swarm-config.json
|
|
48
|
+
└─> writes pheromone/current.json + task-space.json
|
|
49
|
+
|
|
50
|
+
[Coordinator] iteration k (k = 1..K):
|
|
51
|
+
├─> python aco.py select --iter k
|
|
52
|
+
│ └─> returns N ant assignments (paths to explore)
|
|
53
|
+
├─> create_task × N ant tasks
|
|
54
|
+
├─> spawn N × team-worker(ant) in background
|
|
55
|
+
└─> STOP (await all callbacks)
|
|
56
|
+
|
|
57
|
+
[Callback] all ants done → handleIterationComplete
|
|
58
|
+
├─> (optional) spawn scorer worker → verified_scores.json
|
|
59
|
+
├─> python aco.py update --iter k
|
|
60
|
+
│ └─> reads artifacts/ant-k-*.json + verified_scores
|
|
61
|
+
│ └─> updates pheromone + elite + history
|
|
62
|
+
├─> python aco.py converged
|
|
63
|
+
│ └─> {converged: true|false, reason: ...}
|
|
64
|
+
└─> converged → Phase 4; else → iteration k+1
|
|
65
|
+
|
|
66
|
+
[Coordinator] Phase 4: converge
|
|
67
|
+
├─> python aco.py report → best.json
|
|
68
|
+
├─> spawn analyst worker → best-solution.md
|
|
69
|
+
└─> completion action (Archive/Keep/Export)
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## Script ↔ Coordinator Contract
|
|
73
|
+
|
|
74
|
+
All scripts MUST:
|
|
75
|
+
- Read from `<session>/...` (session path passed via `--session` flag)
|
|
76
|
+
- Write JSON to stdout for coordinator parsing (no prose)
|
|
77
|
+
- Use exit code 0 = success, 1 = error, 2 = config invalid
|
|
78
|
+
- Be idempotent: calling `update` twice for same iteration is safe
|
|
79
|
+
|
|
80
|
+
| Subcommand | Input | Output (stdout JSON) | Side effects |
|
|
81
|
+
|------------|-------|---------------------|--------------|
|
|
82
|
+
| `init` | swarm-config.json | `{status, pheromone_path, n_nodes}` | writes pheromone/current.json, task-space.json |
|
|
83
|
+
| `select --iter k` | pheromone/current.json, swarm-config.json | `{iteration, assignments: [{ant_id, path_hints, ...}]}` | none |
|
|
84
|
+
| `update --iter k` | artifacts/ant-k-*.json, optional verified_scores.json | `{iteration, mean_score, best_score, delta, elite_updated}` | writes pheromone/current.json (overwrite) + pheromone/history/k.json + trails/k.jsonl + best.json |
|
|
85
|
+
| `converged` | history/, best.json, config | `{converged: bool, reason: str, metrics: {...}}` | none |
|
|
86
|
+
| `report` | best.json, history/ | full JSON: `{best, top_k, convergence_curve, ...}` | none |
|
|
87
|
+
|
|
88
|
+
## Data Flow Boundaries
|
|
89
|
+
|
|
90
|
+
| Boundary | Owner | Format |
|
|
91
|
+
|----------|-------|--------|
|
|
92
|
+
| User intent → config | LLM coordinator | swarm-config.json |
|
|
93
|
+
| Pheromone state | Python script | pheromone/current.json |
|
|
94
|
+
| Ant assignment → ant prompt | LLM coordinator (templated) | injected into role-spec at spawn |
|
|
95
|
+
| Ant exploration → artifact | LLM ant | artifacts/ant-k-id.json (schema-locked) |
|
|
96
|
+
| Artifact → pheromone update | Python script | reads artifacts, computes delta tau |
|
|
97
|
+
| Elite solutions → human report | LLM analyst | artifacts/best-solution.md |
|
|
98
|
+
|
|
99
|
+
## Why Hybrid Coordinator (Not Pure Script)
|
|
100
|
+
|
|
101
|
+
- User input is natural language → needs LLM to map to swarm-config
|
|
102
|
+
- Worker spawning, message routing, session management → all framework-bound to LLM coordinator
|
|
103
|
+
- Script as a sub-tool keeps the same team-* lifecycle (spawn-and-stop, callback-driven)
|
|
104
|
+
- Same pattern as `maestro delegate` — Bash-callable subprocess from inside an LLM role
|
|
105
|
+
|
|
106
|
+
## Universality
|
|
107
|
+
|
|
108
|
+
`team-swarm` is task-agnostic. Specialization happens via:
|
|
109
|
+
1. `swarm-config.json#task_space` — defines what nodes/edges/paths mean
|
|
110
|
+
2. `swarm-config.json#scoring` — defines how to compute verified_score
|
|
111
|
+
3. `swarm-config.json#ant_prompt` — defines what ant should actually do at each node
|
|
112
|
+
|
|
113
|
+
Example domains the same skill handles:
|
|
114
|
+
- Code exploration (nodes = files/modules, score = suspicious code density)
|
|
115
|
+
- Test case generation (nodes = code paths, score = coverage delta)
|
|
116
|
+
- Refactor strategy search (nodes = refactor moves, score = complexity reduction)
|
|
117
|
+
- Hyperparameter tuning (nodes = param choices, score = metric improvement)
|