aether-colony 1.1.0

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 (207) hide show
  1. package/.aether/CONTEXT.md +160 -0
  2. package/.aether/QUEEN.md +84 -0
  3. package/.aether/aether-utils.sh +7749 -0
  4. package/.aether/docs/QUEEN-SYSTEM.md +211 -0
  5. package/.aether/docs/README.md +68 -0
  6. package/.aether/docs/caste-system.md +48 -0
  7. package/.aether/docs/disciplines/DISCIPLINES.md +93 -0
  8. package/.aether/docs/disciplines/coding-standards.md +197 -0
  9. package/.aether/docs/disciplines/debugging.md +207 -0
  10. package/.aether/docs/disciplines/learning.md +254 -0
  11. package/.aether/docs/disciplines/tdd.md +257 -0
  12. package/.aether/docs/disciplines/verification-loop.md +167 -0
  13. package/.aether/docs/disciplines/verification.md +116 -0
  14. package/.aether/docs/error-codes.md +268 -0
  15. package/.aether/docs/known-issues.md +233 -0
  16. package/.aether/docs/pheromones.md +205 -0
  17. package/.aether/docs/queen-commands.md +97 -0
  18. package/.aether/exchange/colony-registry.xml +11 -0
  19. package/.aether/exchange/pheromone-xml.sh +575 -0
  20. package/.aether/exchange/pheromones.xml +87 -0
  21. package/.aether/exchange/queen-wisdom.xml +14 -0
  22. package/.aether/exchange/registry-xml.sh +273 -0
  23. package/.aether/exchange/wisdom-xml.sh +319 -0
  24. package/.aether/midden/approach-changes.md +5 -0
  25. package/.aether/midden/build-failures.md +5 -0
  26. package/.aether/midden/test-failures.md +5 -0
  27. package/.aether/model-profiles.yaml +100 -0
  28. package/.aether/rules/aether-colony.md +134 -0
  29. package/.aether/schemas/aether-types.xsd +255 -0
  30. package/.aether/schemas/colony-registry.xsd +309 -0
  31. package/.aether/schemas/example-prompt-builder.xml +234 -0
  32. package/.aether/schemas/pheromone.xsd +163 -0
  33. package/.aether/schemas/prompt.xsd +416 -0
  34. package/.aether/schemas/queen-wisdom.xsd +325 -0
  35. package/.aether/schemas/worker-priming.xsd +276 -0
  36. package/.aether/templates/QUEEN.md.template +79 -0
  37. package/.aether/templates/colony-state-reset.jq.template +22 -0
  38. package/.aether/templates/colony-state.template.json +35 -0
  39. package/.aether/templates/constraints.template.json +9 -0
  40. package/.aether/templates/crowned-anthill.template.md +36 -0
  41. package/.aether/templates/handoff-build-error.template.md +30 -0
  42. package/.aether/templates/handoff-build-success.template.md +39 -0
  43. package/.aether/templates/handoff.template.md +40 -0
  44. package/.aether/templates/learning-observations.template.json +6 -0
  45. package/.aether/templates/midden.template.json +7 -0
  46. package/.aether/templates/pheromones.template.json +6 -0
  47. package/.aether/templates/session.template.json +9 -0
  48. package/.aether/utils/atomic-write.sh +219 -0
  49. package/.aether/utils/chamber-compare.sh +193 -0
  50. package/.aether/utils/chamber-utils.sh +297 -0
  51. package/.aether/utils/colorize-log.sh +132 -0
  52. package/.aether/utils/error-handler.sh +212 -0
  53. package/.aether/utils/file-lock.sh +158 -0
  54. package/.aether/utils/queen-to-md.xsl +395 -0
  55. package/.aether/utils/semantic-cli.sh +413 -0
  56. package/.aether/utils/spawn-tree.sh +428 -0
  57. package/.aether/utils/spawn-with-model.sh +56 -0
  58. package/.aether/utils/state-loader.sh +215 -0
  59. package/.aether/utils/swarm-display.sh +268 -0
  60. package/.aether/utils/watch-spawn-tree.sh +253 -0
  61. package/.aether/utils/xml-compose.sh +253 -0
  62. package/.aether/utils/xml-convert.sh +273 -0
  63. package/.aether/utils/xml-core.sh +186 -0
  64. package/.aether/utils/xml-query.sh +201 -0
  65. package/.aether/utils/xml-utils.sh +110 -0
  66. package/.aether/workers.md +765 -0
  67. package/.claude/agents/ant/aether-ambassador.md +264 -0
  68. package/.claude/agents/ant/aether-archaeologist.md +322 -0
  69. package/.claude/agents/ant/aether-auditor.md +266 -0
  70. package/.claude/agents/ant/aether-builder.md +187 -0
  71. package/.claude/agents/ant/aether-chaos.md +268 -0
  72. package/.claude/agents/ant/aether-chronicler.md +304 -0
  73. package/.claude/agents/ant/aether-gatekeeper.md +325 -0
  74. package/.claude/agents/ant/aether-includer.md +373 -0
  75. package/.claude/agents/ant/aether-keeper.md +271 -0
  76. package/.claude/agents/ant/aether-measurer.md +317 -0
  77. package/.claude/agents/ant/aether-probe.md +210 -0
  78. package/.claude/agents/ant/aether-queen.md +325 -0
  79. package/.claude/agents/ant/aether-route-setter.md +173 -0
  80. package/.claude/agents/ant/aether-sage.md +353 -0
  81. package/.claude/agents/ant/aether-scout.md +142 -0
  82. package/.claude/agents/ant/aether-surveyor-disciplines.md +416 -0
  83. package/.claude/agents/ant/aether-surveyor-nest.md +354 -0
  84. package/.claude/agents/ant/aether-surveyor-pathogens.md +288 -0
  85. package/.claude/agents/ant/aether-surveyor-provisions.md +359 -0
  86. package/.claude/agents/ant/aether-tracker.md +265 -0
  87. package/.claude/agents/ant/aether-watcher.md +244 -0
  88. package/.claude/agents/ant/aether-weaver.md +247 -0
  89. package/.claude/commands/ant/archaeology.md +341 -0
  90. package/.claude/commands/ant/build.md +1160 -0
  91. package/.claude/commands/ant/chaos.md +349 -0
  92. package/.claude/commands/ant/colonize.md +270 -0
  93. package/.claude/commands/ant/continue.md +1070 -0
  94. package/.claude/commands/ant/council.md +309 -0
  95. package/.claude/commands/ant/dream.md +265 -0
  96. package/.claude/commands/ant/entomb.md +487 -0
  97. package/.claude/commands/ant/feedback.md +78 -0
  98. package/.claude/commands/ant/flag.md +139 -0
  99. package/.claude/commands/ant/flags.md +155 -0
  100. package/.claude/commands/ant/focus.md +58 -0
  101. package/.claude/commands/ant/help.md +122 -0
  102. package/.claude/commands/ant/history.md +137 -0
  103. package/.claude/commands/ant/init.md +409 -0
  104. package/.claude/commands/ant/interpret.md +267 -0
  105. package/.claude/commands/ant/lay-eggs.md +201 -0
  106. package/.claude/commands/ant/maturity.md +102 -0
  107. package/.claude/commands/ant/memory-details.md +77 -0
  108. package/.claude/commands/ant/migrate-state.md +165 -0
  109. package/.claude/commands/ant/oracle.md +387 -0
  110. package/.claude/commands/ant/organize.md +227 -0
  111. package/.claude/commands/ant/pause-colony.md +247 -0
  112. package/.claude/commands/ant/phase.md +126 -0
  113. package/.claude/commands/ant/plan.md +544 -0
  114. package/.claude/commands/ant/redirect.md +58 -0
  115. package/.claude/commands/ant/resume-colony.md +182 -0
  116. package/.claude/commands/ant/resume.md +363 -0
  117. package/.claude/commands/ant/seal.md +306 -0
  118. package/.claude/commands/ant/status.md +272 -0
  119. package/.claude/commands/ant/swarm.md +361 -0
  120. package/.claude/commands/ant/tunnels.md +425 -0
  121. package/.claude/commands/ant/update.md +209 -0
  122. package/.claude/commands/ant/verify-castes.md +95 -0
  123. package/.claude/commands/ant/watch.md +238 -0
  124. package/.opencode/agents/aether-ambassador.md +140 -0
  125. package/.opencode/agents/aether-archaeologist.md +108 -0
  126. package/.opencode/agents/aether-auditor.md +144 -0
  127. package/.opencode/agents/aether-builder.md +184 -0
  128. package/.opencode/agents/aether-chaos.md +115 -0
  129. package/.opencode/agents/aether-chronicler.md +122 -0
  130. package/.opencode/agents/aether-gatekeeper.md +116 -0
  131. package/.opencode/agents/aether-includer.md +117 -0
  132. package/.opencode/agents/aether-keeper.md +177 -0
  133. package/.opencode/agents/aether-measurer.md +128 -0
  134. package/.opencode/agents/aether-probe.md +133 -0
  135. package/.opencode/agents/aether-queen.md +286 -0
  136. package/.opencode/agents/aether-route-setter.md +130 -0
  137. package/.opencode/agents/aether-sage.md +106 -0
  138. package/.opencode/agents/aether-scout.md +101 -0
  139. package/.opencode/agents/aether-surveyor-disciplines.md +386 -0
  140. package/.opencode/agents/aether-surveyor-nest.md +324 -0
  141. package/.opencode/agents/aether-surveyor-pathogens.md +259 -0
  142. package/.opencode/agents/aether-surveyor-provisions.md +329 -0
  143. package/.opencode/agents/aether-tracker.md +137 -0
  144. package/.opencode/agents/aether-watcher.md +174 -0
  145. package/.opencode/agents/aether-weaver.md +130 -0
  146. package/.opencode/commands/ant/archaeology.md +338 -0
  147. package/.opencode/commands/ant/build.md +1200 -0
  148. package/.opencode/commands/ant/chaos.md +346 -0
  149. package/.opencode/commands/ant/colonize.md +202 -0
  150. package/.opencode/commands/ant/continue.md +938 -0
  151. package/.opencode/commands/ant/council.md +305 -0
  152. package/.opencode/commands/ant/dream.md +262 -0
  153. package/.opencode/commands/ant/entomb.md +367 -0
  154. package/.opencode/commands/ant/feedback.md +80 -0
  155. package/.opencode/commands/ant/flag.md +137 -0
  156. package/.opencode/commands/ant/flags.md +153 -0
  157. package/.opencode/commands/ant/focus.md +56 -0
  158. package/.opencode/commands/ant/help.md +124 -0
  159. package/.opencode/commands/ant/history.md +127 -0
  160. package/.opencode/commands/ant/init.md +337 -0
  161. package/.opencode/commands/ant/interpret.md +256 -0
  162. package/.opencode/commands/ant/lay-eggs.md +141 -0
  163. package/.opencode/commands/ant/maturity.md +92 -0
  164. package/.opencode/commands/ant/memory-details.md +77 -0
  165. package/.opencode/commands/ant/migrate-state.md +153 -0
  166. package/.opencode/commands/ant/oracle.md +338 -0
  167. package/.opencode/commands/ant/organize.md +224 -0
  168. package/.opencode/commands/ant/pause-colony.md +220 -0
  169. package/.opencode/commands/ant/phase.md +123 -0
  170. package/.opencode/commands/ant/plan.md +531 -0
  171. package/.opencode/commands/ant/redirect.md +67 -0
  172. package/.opencode/commands/ant/resume-colony.md +178 -0
  173. package/.opencode/commands/ant/resume.md +363 -0
  174. package/.opencode/commands/ant/seal.md +247 -0
  175. package/.opencode/commands/ant/status.md +272 -0
  176. package/.opencode/commands/ant/swarm.md +357 -0
  177. package/.opencode/commands/ant/tunnels.md +406 -0
  178. package/.opencode/commands/ant/update.md +191 -0
  179. package/.opencode/commands/ant/verify-castes.md +85 -0
  180. package/.opencode/commands/ant/watch.md +220 -0
  181. package/.opencode/opencode.json +3 -0
  182. package/CHANGELOG.md +325 -0
  183. package/DISCLAIMER.md +74 -0
  184. package/LICENSE +21 -0
  185. package/README.md +258 -0
  186. package/bin/cli.js +2436 -0
  187. package/bin/generate-commands.sh +291 -0
  188. package/bin/lib/caste-colors.js +57 -0
  189. package/bin/lib/colors.js +76 -0
  190. package/bin/lib/errors.js +255 -0
  191. package/bin/lib/event-types.js +190 -0
  192. package/bin/lib/file-lock.js +695 -0
  193. package/bin/lib/init.js +454 -0
  194. package/bin/lib/logger.js +242 -0
  195. package/bin/lib/model-profiles.js +445 -0
  196. package/bin/lib/model-verify.js +288 -0
  197. package/bin/lib/nestmate-loader.js +130 -0
  198. package/bin/lib/proxy-health.js +253 -0
  199. package/bin/lib/spawn-logger.js +266 -0
  200. package/bin/lib/state-guard.js +602 -0
  201. package/bin/lib/state-sync.js +516 -0
  202. package/bin/lib/telemetry.js +441 -0
  203. package/bin/lib/update-transaction.js +1454 -0
  204. package/bin/npx-install.js +178 -0
  205. package/bin/sync-to-runtime.sh +6 -0
  206. package/bin/validate-package.sh +88 -0
  207. package/package.json +70 -0
@@ -0,0 +1,1160 @@
1
+ ---
2
+ name: ant:build
3
+ description: "🔨🐜🏗️🐜🔨 Build a phase with pure emergence - colony self-organizes and completes tasks"
4
+ ---
5
+
6
+ You are the **Queen**. You DIRECTLY spawn multiple workers — do not delegate to a single Prime Worker.
7
+
8
+ The phase to build is: `$ARGUMENTS`
9
+
10
+ ## Instructions
11
+
12
+ <failure_modes>
13
+ ### Wave Failure Mid-Build
14
+ If a worker fails during a build wave:
15
+ - Do NOT continue to next wave (failed dependencies will cascade)
16
+ - Report which worker failed, what task it was on, and what was attempted
17
+ - Options: (1) Retry the failed task, (2) Skip and continue with remaining tasks, (3) Abort build
18
+
19
+ ### Partial File Writes
20
+ If a builder crashes mid-write:
21
+ - Check git status for uncommitted partial changes
22
+ - If partial changes exist, offer: (1) Review and keep, (2) Revert with git checkout, (3) Stash for later
23
+
24
+ ### State Corruption
25
+ If COLONY_STATE.json becomes invalid during build:
26
+ - STOP all workers immediately
27
+ - Do not attempt to fix state automatically
28
+ - Report the issue and offer to restore from last known good state
29
+ </failure_modes>
30
+
31
+ <success_criteria>
32
+ Command is complete when:
33
+ - All waves executed in order with no skipped dependencies
34
+ - Each worker's task output is verified (files exist, tests pass)
35
+ - COLONY_STATE.json reflects completed phase progress
36
+ - Build summary reports all workers' outcomes
37
+ </success_criteria>
38
+
39
+ <read_only>
40
+ Do not touch during build:
41
+ - .aether/dreams/ (user notes)
42
+ - .aether/chambers/ (archived colonies)
43
+ - .env* files
44
+ - .claude/settings.json
45
+ - .github/workflows/
46
+ - Other agents' config files (only modify files assigned to the current build task)
47
+ </read_only>
48
+
49
+ ### Step 0: Version Check (Non-blocking)
50
+
51
+ Run using the Bash tool with description "Checking colony version...": `bash .aether/aether-utils.sh version-check-cached 2>/dev/null || true`
52
+
53
+ If the command succeeds and the JSON result contains a non-empty string, display it as a one-line notice. Proceed regardless of outcome.
54
+
55
+ ### Step 0.6: Verify LiteLLM Proxy
56
+
57
+ Check that the LiteLLM proxy is running for model routing:
58
+
59
+ Run using the Bash tool with description "Checking model proxy...":
60
+ ```bash
61
+ curl -s http://localhost:4000/health | grep -q "healthy" && echo "Proxy healthy" || echo "Proxy not running - workers will use default model"
62
+ ```
63
+
64
+ If proxy is not healthy, log a warning but continue (workers will fall back to default routing).
65
+
66
+ ### Step 0.5: Load Colony State
67
+
68
+ Run using the Bash tool with description "Loading colony state...": `bash .aether/aether-utils.sh load-state`
69
+
70
+ If the command fails (non-zero exit or JSON has ok: false):
71
+ 1. Parse error JSON
72
+ 2. If error code is E_FILE_NOT_FOUND: "No colony initialized. Run /ant:init first." and stop
73
+ 3. If validation error: Display error details with recovery suggestion and stop
74
+ 4. For other errors: Display generic error and suggest /ant:status for diagnostics
75
+
76
+ If successful:
77
+ 1. Parse the state JSON from result field
78
+ 2. Check if goal is null - if so: "No colony initialized. Run /ant:init first." and stop
79
+ 3. Extract current_phase and phase name from plan.phases[current_phase - 1].name
80
+ 4. Display brief resumption context:
81
+ ```
82
+ 🔄 Resuming: Phase X - Name
83
+ ```
84
+ (If HANDOFF.md exists, this provides orientation before the build proceeds)
85
+
86
+ After displaying context, run using the Bash tool with description "Releasing colony lock...": `bash .aether/aether-utils.sh unload-state` to release the lock.
87
+
88
+ ### Step 1: Validate + Read State
89
+
90
+ **Parse $ARGUMENTS:**
91
+ 1. Extract the phase number (first argument)
92
+ 2. Check remaining arguments for flags:
93
+ - If contains `--verbose` or `-v`: set `verbose_mode = true`
94
+ - If contains `--no-visual`: set `visual_mode = false` (visual is ON by default)
95
+ - If contains `--model <name>` or `-m <name>`: set `cli_model_override = <name>`
96
+ - Otherwise: set `visual_mode = true` (visual is default)
97
+
98
+ If the phase number is empty or not a number:
99
+
100
+ ```
101
+ Usage: /ant:build <phase_number> [--verbose|-v] [--no-visual] [--model <model>|-m <model>]
102
+
103
+ Options:
104
+ --verbose, -v Show full completion details (spawn tree, TDD, patterns)
105
+ --no-visual Disable real-time visual display (visual is on by default)
106
+ --model, -m <name> Override model for this build (one-time)
107
+
108
+ Examples:
109
+ /ant:build 1 Build Phase 1 (with visual display)
110
+ /ant:build 1 --verbose Build Phase 1 (full details + visual)
111
+ /ant:build 1 --no-visual Build Phase 1 without visual display
112
+ /ant:build 1 --model glm-5 Build Phase 1 with glm-5 for all workers
113
+ ```
114
+
115
+ Stop here.
116
+
117
+ **Validate CLI model override (if provided):**
118
+ If `cli_model_override` is set:
119
+ 1. Run using the Bash tool with description "Validating model override...": `bash .aether/aether-utils.sh model-profile validate "$cli_model_override"`
120
+ 2. Parse JSON result - if `.result.valid` is false:
121
+ - Display: `Error: Invalid model "$cli_model_override"`
122
+ - Display: `Valid models: {list from .result.models}`
123
+ - Stop here
124
+ 3. If valid: Display `Using override model: {model}`
125
+
126
+ **Auto-upgrade old state:**
127
+ If `version` field is missing, "1.0", or "2.0":
128
+ 1. Preserve: `goal`, `state`, `current_phase`, `plan.phases`
129
+ 2. Write upgraded v3.0 state (same structure as /ant:init but preserving data)
130
+ 3. Output: `State auto-upgraded to v3.0`
131
+ 4. Continue with command.
132
+
133
+ Extract:
134
+ - `goal`, `state`, `current_phase` from top level
135
+ - `plan.phases` for phase data
136
+ - `errors.records` for error context
137
+ - `memory` for decisions/learnings
138
+
139
+ **Validate:**
140
+ - If `plan.phases` is empty -> output `No project plan. Run /ant:plan first.` and stop.
141
+ - Find the phase matching the requested ID. If not found -> output `Phase {id} not found.` and stop.
142
+ - If the phase status is `"completed"` -> output `Phase {id} already completed.` and stop.
143
+
144
+ ### Step 1.5: Blocker Advisory (Non-blocking)
145
+
146
+ Check for unresolved blocker flags on the requested phase:
147
+
148
+ Run using the Bash tool with description "Checking for blockers...":
149
+ ```bash
150
+ bash .aether/aether-utils.sh flag-check-blockers {phase_number}
151
+ ```
152
+
153
+ Parse the JSON result (`.result.blockers`):
154
+
155
+ - **If blockers == 0:** Display nothing (or optionally a brief `No active blockers for Phase {id}.` line). Proceed to Step 2.
156
+ - **If blockers > 0:** Retrieve blocker details:
157
+ Run using the Bash tool with description "Loading blocker details...":
158
+ ```bash
159
+ bash .aether/aether-utils.sh flag-list --type blocker --phase {phase_number}
160
+ ```
161
+ Parse `.result.flags` and display an advisory warning:
162
+ ```
163
+ ⚠️ BLOCKER ADVISORY: {blockers} unresolved blocker(s) for Phase {id}
164
+ {for each flag in result.flags:}
165
+ - [{flag.id}] {flag.title}
166
+ {end for}
167
+
168
+ Consider reviewing with /ant:flags or auto-fixing with /ant:swarm before building.
169
+ Proceeding anyway...
170
+ ```
171
+ **This is advisory only — do NOT stop.** Continue to Step 2 regardless.
172
+
173
+ ### Step 2: Update State
174
+
175
+ Read then update `.aether/data/COLONY_STATE.json`:
176
+ - Set `state` to `"EXECUTING"`
177
+ - Set `current_phase` to the phase number
178
+ - Set the phase's `status` to `"in_progress"` in `plan.phases[N]`
179
+ - Add `build_started_at` field with current ISO-8601 UTC timestamp
180
+ - Append to `events`: `"<timestamp>|phase_started|build|Phase <id>: <name> started"`
181
+
182
+ If `events` exceeds 100 entries, keep only the last 100.
183
+
184
+ Write COLONY_STATE.json.
185
+
186
+ Validate the state file:
187
+ Run using the Bash tool with description "Validating colony state...":
188
+ ```bash
189
+ bash .aether/aether-utils.sh validate-state colony
190
+ ```
191
+
192
+ ### Step 3: Git Checkpoint
193
+
194
+ Create a git checkpoint for rollback capability.
195
+
196
+ Run using the Bash tool with description "Checking git repository...":
197
+ ```bash
198
+ git rev-parse --git-dir 2>/dev/null
199
+ ```
200
+
201
+ - **If succeeds** (is a git repo):
202
+ 1. Check for changes in Aether-managed directories only: `.aether .claude/commands/ant .claude/commands/st .opencode bin`
203
+ 2. **If changes exist**: Run using the Bash tool with description "Creating git checkpoint...": `git stash push -m "aether-checkpoint: pre-phase-$PHASE_NUMBER" -- .aether .claude/commands/ant .claude/commands/st .opencode bin`
204
+ - IMPORTANT: Never use `--include-untracked` — it stashes ALL files including user work!
205
+ - Run using the Bash tool with description "Verifying checkpoint...": `git stash list | head -1 | grep "aether-checkpoint"` — warn if empty
206
+ - Store checkpoint as `{type: "stash", ref: "aether-checkpoint: pre-phase-$PHASE_NUMBER"}`
207
+ 3. **If clean working tree**: Run using the Bash tool with description "Recording HEAD position...": `git rev-parse HEAD`
208
+ - Store checkpoint as `{type: "commit", ref: "$HEAD_HASH"}`
209
+ - **If fails** (not a git repo): Set checkpoint to `{type: "none", ref: "(not a git repo)"}`.
210
+
211
+ Rollback procedure: `git stash pop` (if type is "stash") or `git reset --hard $ref` (if type is "commit").
212
+
213
+ Output header:
214
+
215
+ ```
216
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
217
+ B U I L D I N G P H A S E {id}
218
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
219
+
220
+ 📍 Phase {id}: {name}
221
+ 💾 Git checkpoint saved
222
+ ```
223
+
224
+ ### Step 4: Load Colony Context (colony-prime)
225
+
226
+ Call `colony-prime` to get unified worker context (wisdom + signals + instincts):
227
+
228
+ Run using the Bash tool with description "Loading colony context...":
229
+ ```bash
230
+ prime_result=$(bash .aether/aether-utils.sh colony-prime 2>/dev/null)
231
+ ```
232
+
233
+ **Parse the JSON response:**
234
+ - If `.ok` is false: This is a FAIL HARD error - display the error message and stop the build
235
+ - If successful: Extract from `.result`:
236
+ - `signal_count` - number of active pheromone signals
237
+ - `instinct_count` - number of filtered instincts
238
+ - `prompt_section` - the formatted markdown to inject into worker prompts
239
+ - `log_line` - status message for display
240
+
241
+ Display after constraints:
242
+ ```
243
+ {log_line from colony-prime}
244
+ ```
245
+
246
+ **Store for worker injection:** The `prompt_section` variable contains the complete formatted context (QUEEN wisdom + pheromone signals) ready for injection.
247
+
248
+ ### Step 4.0: Load Territory Survey
249
+
250
+ Check if territory survey exists and load relevant documents:
251
+
252
+ Run using the Bash tool with description "Loading territory survey...":
253
+ ```bash
254
+ bash .aether/aether-utils.sh survey-load "{phase_name}" 2>/dev/null
255
+ ```
256
+
257
+ **Parse the JSON response:**
258
+ - If `.ok` is false: Set `survey_docs = null` and skip survey loading
259
+ - If successful: Extract `.docs` (comma-separated list) and `.dir`
260
+
261
+ **Determine phase type from phase name:**
262
+ | Phase Contains | Documents to Load |
263
+ |----------------|-------------------|
264
+ | UI, frontend, component, button, page | DISCIPLINES.md, CHAMBERS.md |
265
+ | API, endpoint, backend, route | BLUEPRINT.md, DISCIPLINES.md |
266
+ | database, schema, model, migration | BLUEPRINT.md, PROVISIONS.md |
267
+ | test, spec, coverage | SENTINEL-PROTOCOLS.md, DISCIPLINES.md |
268
+ | integration, external, client | TRAILS.md, PROVISIONS.md |
269
+ | refactor, cleanup, debt | PATHOGENS.md, BLUEPRINT.md |
270
+ | setup, config, initialize | PROVISIONS.md, CHAMBERS.md |
271
+ | *default* | PROVISIONS.md, BLUEPRINT.md |
272
+
273
+ **Read the relevant survey documents** from `.aether/data/survey/`:
274
+ - Extract key patterns to follow
275
+ - Note file locations for new code
276
+ - Identify known concerns to avoid
277
+
278
+ **Display summary:**
279
+ ```
280
+ ━━━ 🗺️🐜 S U R V E Y L O A D E D ━━━
281
+ {for each doc loaded}
282
+ {emoji} {filename} — {brief description}
283
+ {/for}
284
+
285
+ {if no survey}
286
+ (No territory survey — run /ant:colonize for deeper context)
287
+ {/if}
288
+ ```
289
+
290
+ **Store for builder injection:**
291
+ - `survey_patterns` — patterns to follow
292
+ - `survey_locations` — where to place files
293
+ - `survey_concerns` — concerns to avoid
294
+
295
+ ### Step 4.1: Archaeologist Pre-Build Scan
296
+
297
+ **Conditional step — only fires when the phase modifies existing files.**
298
+
299
+ 1. **Detect existing-file modification:**
300
+ Examine each task in the phase. Look at task descriptions, constraints, and hints for signals:
301
+ - Keywords: "update", "modify", "add to", "integrate into", "extend", "change", "refactor", "fix"
302
+ - References to existing file paths (files that already exist in the repo)
303
+ - Task type: if a task is purely "create new file X" with no references to existing code, it is new-file-only
304
+
305
+ **If ALL tasks are new-file-only** (no existing files will be modified):
306
+ - Skip this step silently — produce no output, no spawn
307
+ - Proceed directly to Step 5
308
+
309
+ 2. **If existing code modification detected — spawn Archaeologist Scout:**
310
+
311
+ Generate archaeologist name and dispatch:
312
+ Run using the Bash tool with description "Naming archaeologist...": `bash .aether/aether-utils.sh generate-ant-name "archaeologist"` (store as `{archaeologist_name}`)
313
+ Run using the Bash tool with description "Dispatching archaeologist...": `bash .aether/aether-utils.sh spawn-log "Queen" "scout" "{archaeologist_name}" "Pre-build archaeology scan" && bash .aether/aether-utils.sh swarm-display-update "{archaeologist_name}" "scout" "excavating" "Pre-build archaeology scan" "Queen" '{"read":0,"grep":0,"edit":0,"bash":0}' 0 "fungus_garden" 15`
314
+
315
+ Display:
316
+ ```
317
+ 🏺🐜 Archaeologist {archaeologist_name} spawning
318
+ Scanning history of files to be modified...
319
+ ```
320
+
321
+ Spawn a Scout (using Task tool with `subagent_type="aether-archaeologist"`, include `description: "🏺 Archaeologist {archaeologist_name}: Pre-build history scan"`) with this prompt:
322
+ # FALLBACK: If "Agent type not found", use general-purpose and inject role: "You are an Archaeologist Ant - git historian that excavates why code exists."
323
+
324
+ ```
325
+ You are {Archaeologist-Name}, a 🏺🐜 Archaeologist Ant.
326
+
327
+ Mission: Pre-build archaeology scan
328
+
329
+ Files: {list of existing files that will be modified}
330
+
331
+ Work:
332
+ 1. Read each file to understand current state
333
+ 2. Run: git log --oneline -15 -- "{file_path}" for history
334
+ 3. Run: git log --all --grep="fix\|bug\|workaround\|hack\|revert" --oneline -- "{file_path}" for incident history
335
+ 4. Run: git blame "{file_path}" | head -40 for authorship
336
+ 5. Note TODO/FIXME/HACK markers
337
+
338
+ Log activity: bash .aether/aether-utils.sh activity-log "READ" "{Ant-Name}" "description"
339
+
340
+ Report (plain text):
341
+ - WHY key code sections exist (from commits)
342
+ - Known workarounds/hacks to preserve
343
+ - Key architectural decisions
344
+ - Areas of caution (high churn, reverts, emergencies)
345
+ - Stable bedrock vs volatile sand sections
346
+ ```
347
+
348
+ **Wait for results** (blocking — use TaskOutput with `block: true`).
349
+
350
+ Log completion and update swarm display:
351
+ Run using the Bash tool with description "Recording archaeologist findings...": `bash .aether/aether-utils.sh spawn-complete "{archaeologist_name}" "completed" "Pre-build archaeology scan" && bash .aether/aether-utils.sh swarm-display-update "{archaeologist_name}" "scout" "completed" "Pre-build archaeology scan" "Queen" '{"read":8,"grep":5,"edit":0,"bash":2}' 100 "fungus_garden" 100`
352
+
353
+ 3. **Store and display findings:**
354
+
355
+ Store the archaeologist's output as `archaeology_context`.
356
+
357
+ Display summary:
358
+ ```
359
+ ━━━ 🏺🐜 A R C H A E O L O G Y ━━━
360
+ {summary of findings from archaeologist}
361
+ ```
362
+
363
+ 4. **Injection into builder prompts:**
364
+ The `archaeology_context` will be injected into builder prompts in Step 5.1 (see below).
365
+ If this step was skipped (no existing files modified), the archaeology section is omitted from builder prompts.
366
+
367
+ ---
368
+
369
+ ### Step 5: Initialize Swarm Display and Analyze Tasks
370
+
371
+ **YOU (the Queen) will spawn workers directly. Do NOT delegate to a single Prime Worker.**
372
+
373
+ **Initialize visual swarm tracking:**
374
+ Run using the Bash tool with description "Initializing build display...":
375
+ ```bash
376
+ # Generate unique build ID
377
+ build_id="build-$(date +%s)"
378
+
379
+ # Initialize swarm display for this build
380
+ bash .aether/aether-utils.sh swarm-display-init "$build_id"
381
+
382
+ # Log phase start
383
+ bash .aether/aether-utils.sh activity-log "EXECUTING" "Queen" "Phase {id}: {name} - Queen dispatching workers"
384
+
385
+ # Display animated header
386
+ bash .aether/aether-utils.sh swarm-display-update "Queen" "prime" "excavating" "Phase {id}: {name}" "Colony" '{"read":0,"grep":0,"edit":0,"bash":0}' 10 "fungus_garden" 0
387
+ ```
388
+
389
+ **Show real-time display header:**
390
+ ```
391
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
392
+ Phase {id}: {name} — {N} waves, {M} tasks
393
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
394
+ ```
395
+
396
+ Where N = number of builder waves (excluding watcher/chaos) and M = total builder tasks.
397
+
398
+ Record `build_started_at_epoch=$(date +%s)` — this epoch integer is used by the BUILD SUMMARY block in Step 7 to calculate elapsed time.
399
+
400
+ Analyze the phase tasks:
401
+
402
+ Analyze the phase tasks:
403
+
404
+ 1. **Group tasks by dependencies:**
405
+ - **Wave 1:** Tasks with `depends_on: "none"` or `depends_on: []` (can run in parallel)
406
+ - **Wave 2:** Tasks depending on Wave 1 tasks
407
+ - **Wave 3+:** Continue until all tasks assigned
408
+
409
+ 2. **Assign castes:**
410
+ - Implementation tasks → 🔨🐜 Builder
411
+ - Research/docs tasks → 🔍🐜 Scout
412
+ - Testing/validation → 👁️🐜 Watcher (ALWAYS spawn at least one)
413
+ - Resilience testing → 🎲🐜 Chaos (ALWAYS spawn one after Watcher)
414
+
415
+ 3. **Generate ant names for each worker:**
416
+
417
+ Run using the Bash tool with description "Naming builder ant...": `bash .aether/aether-utils.sh generate-ant-name "builder"`
418
+ Run using the Bash tool with description "Naming watcher ant...": `bash .aether/aether-utils.sh generate-ant-name "watcher"`
419
+ Run using the Bash tool with description "Naming chaos ant...": `bash .aether/aether-utils.sh generate-ant-name "chaos"`
420
+
421
+ Display spawn plan with caste emojis:
422
+ ```
423
+ ━━━ 🐜 S P A W N P L A N ━━━
424
+
425
+ Wave 1 — Parallel
426
+ 🔨🐜 {Builder-Name} Task {id} {description}
427
+ 🔨🐜 {Builder-Name} Task {id} {description}
428
+
429
+ Wave 2 — After Wave 1
430
+ 🔨🐜 {Builder-Name} Task {id} {description}
431
+
432
+ Verification
433
+ 👁️🐜 {Watcher-Name} Verify all work independently
434
+ 🎲🐜 {Chaos-Name} Resilience testing (after Watcher)
435
+
436
+ Total: {N} Builders + 1 Watcher + 1 Chaos = {N+2} spawns
437
+ ```
438
+
439
+ **Caste Emoji Legend:**
440
+ - 🔨🐜 Builder (cyan if color enabled)
441
+ - 👁️🐜 Watcher (green if color enabled)
442
+ - 🎲🐜 Chaos (red if color enabled)
443
+ - 🔍🐜 Scout (yellow if color enabled)
444
+ - 🏺🐜 Archaeologist (magenta if color enabled)
445
+ - 🥚 Queen/Prime
446
+
447
+ **Every spawn must show its caste emoji.**
448
+
449
+ ### Step 5.0.5: Select and Announce Workflow Pattern
450
+
451
+ Examine the phase name and task descriptions. Select the first matching pattern:
452
+
453
+ | Phase contains | Pattern |
454
+ |----------------|---------|
455
+ | "bug", "fix", "error", "broken", "failing" | Investigate-Fix |
456
+ | "research", "oracle", "explore", "investigate" | Deep Research |
457
+ | "refactor", "restructure", "clean", "reorganize" | Refactor |
458
+ | "security", "audit", "compliance", "accessibility", "license" | Compliance |
459
+ | "docs", "documentation", "readme", "guide" | Documentation Sprint |
460
+ | (default) | SPBV |
461
+
462
+ Display the selected pattern:
463
+ ```
464
+ ━━ Pattern: {pattern_name} ━━
465
+ {announce_line from Queen's Workflow Patterns definition}
466
+ ```
467
+
468
+ Store `selected_pattern` for inclusion in the BUILD SUMMARY (Step 7).
469
+
470
+ ### Step 5.1: Spawn Wave 1 Workers (Parallel)
471
+
472
+ **CRITICAL: Spawn ALL Wave 1 workers in a SINGLE message using multiple Task tool calls.**
473
+
474
+ **Announce the wave before spawning:**
475
+
476
+ Display the spawn announcement immediately before firing Task calls:
477
+
478
+ For single-caste waves (typical — all builders):
479
+ ```
480
+ ──── 🔨🐜 Spawning {N} Builders in parallel ────
481
+ ```
482
+
483
+ For mixed-caste waves (uncommon):
484
+ ```
485
+ ──── 🐜 Spawning {N} workers ({X} 🔨 Builder, {Y} 🔍 Scout) ────
486
+ ```
487
+
488
+ For a single worker:
489
+ ```
490
+ ──── 🔨🐜 Spawning {ant_name} — {task_summary} ────
491
+ ```
492
+
493
+ **First, mark build start in context:**
494
+ Run using the Bash tool with description "Marking build start...": `bash .aether/aether-utils.sh context-update build-start {phase_id} {wave_1_worker_count} {wave_1_task_count}`
495
+
496
+ For each Wave 1 task, use Task tool with `subagent_type="aether-builder"`, include `description: "🔨 Builder {Ant-Name}: {task_description}"` (DO NOT use run_in_background - multiple Task calls in a single message run in parallel and block until complete):
497
+
498
+ **PER WORKER:** Run using the Bash tool with description "Preparing worker {name}...": `bash .aether/aether-utils.sh spawn-log "Queen" "builder" "{ant_name}" "{task_description}" && bash .aether/aether-utils.sh swarm-display-update "{ant_name}" "builder" "excavating" "{task_description}" "Queen" '{"read":0,"grep":0,"edit":0,"bash":0}' 0 "fungus_garden" 10 && bash .aether/aether-utils.sh context-update worker-spawn "{ant_name}" "builder" "{task_description}"`
499
+
500
+ **Builder Worker Prompt (CLEAN OUTPUT):**
501
+ ```
502
+ You are {Ant-Name}, a 🔨🐜 Builder Ant.
503
+
504
+ Task {id}: {description}
505
+
506
+ Goal: "{colony_goal}"
507
+
508
+ { archaeology_context if exists }
509
+
510
+ { prompt_section }
511
+
512
+ **IMPORTANT:** When using the Bash tool for activity calls, always include a description parameter:
513
+ - activity-log calls → "Logging {action}..."
514
+ - swarm-display-update calls → "Updating build display..."
515
+ - pheromone-read calls → "Checking colony signals..."
516
+ - spawn-can-spawn calls → "Checking spawn budget..."
517
+ - generate-ant-name calls → "Naming sub-worker..."
518
+ - spawn-log calls → "Dispatching sub-worker..."
519
+
520
+ Use colony-flavored language, 4-8 words, trailing ellipsis.
521
+
522
+ Work:
523
+ 1. Read .aether/workers.md for Builder discipline
524
+ 2. Implement task, write tests
525
+ 3. Log activity using Bash tool with description
526
+ 4. Update display using Bash tool with description
527
+ 5. At natural breakpoints (between tasks, after errors): Check for new signals using Bash tool with description
528
+
529
+ **Approach Change Logging:**
530
+ If you try an approach that doesn't work and switch to a different approach, log it:
531
+ ```bash
532
+ colony_name=$(jq -r '.session_id | split("_")[1] // "unknown"' .aether/data/COLONY_STATE.json 2>/dev/null || echo "unknown")
533
+ phase_num=$(jq -r '.phase.number // "unknown"' .aether/data/COLONY_STATE.json 2>/dev/null || echo "unknown")
534
+
535
+ cat >> .aether/midden/approach-changes.md << EOF
536
+ - timestamp: "$(date -u +%Y-%m-%dT%H:%M:%SZ)"
537
+ phase: ${phase_num}
538
+ colony: "${colony_name}"
539
+ worker: "{Ant-Name}"
540
+ task: "{task_id}"
541
+ tried: "initial approach that failed"
542
+ why_it_failed: "reason it didn't work"
543
+ switched_to: "new approach that worked"
544
+ EOF
545
+ ```
546
+
547
+ Spawn sub-workers ONLY if 3x complexity:
548
+ - Check spawn budget using Bash tool with description
549
+ - Generate name using Bash tool with description
550
+ - Announce: "🐜 Spawning {child_name} for {reason}"
551
+ - Log spawn using Bash tool with description
552
+
553
+ Count your total tool calls (Read + Grep + Edit + Bash + Write) and report as tool_count.
554
+
555
+ Return ONLY this JSON (no other text):
556
+ {"ant_name": "{Ant-Name}", "task_id": "{id}", "status": "completed|failed|blocked", "summary": "What you did", "tool_count": 0, "files_created": [], "files_modified": [], "tests_written": [], "blockers": []}
557
+ ```
558
+
559
+ ### Step 5.2: Process Wave 1 Results
560
+
561
+ **Task calls return results directly (no TaskOutput needed).**
562
+
563
+ **As each worker result arrives, IMMEDIATELY display a single completion line — do not wait for other workers:**
564
+
565
+ For successful workers:
566
+ ```
567
+ 🔨 {Ant-Name}: {task_description} ({tool_count} tools) ✓
568
+ ```
569
+
570
+ For failed workers:
571
+ ```
572
+ 🔨 {Ant-Name}: {task_description} ✗ ({failure_reason} after {tool_count} tools)
573
+ ```
574
+
575
+ Where `tool_count` comes from the worker's returned JSON `tool_count` field, and `failure_reason` is extracted from the first item in the worker's `blockers` array or "unknown error" if empty.
576
+
577
+ **Log failure to midden and record observation (MEM-02):**
578
+
579
+ After displaying a failed worker, run using the Bash tool with description "Logging failure to midden...":
580
+ ```bash
581
+ colony_name=$(jq -r '.session_id | split("_")[1] // "unknown"' .aether/data/COLONY_STATE.json 2>/dev/null || echo "unknown")
582
+ phase_num=$(jq -r '.phase.number // "unknown"' .aether/data/COLONY_STATE.json 2>/dev/null || echo "unknown")
583
+
584
+ # Append to build-failures.md
585
+ cat >> .aether/midden/build-failures.md << EOF
586
+ - timestamp: "$(date -u +%Y-%m-%dT%H:%M:%SZ)"
587
+ phase: ${phase_num}
588
+ colony: "${colony_name}"
589
+ worker: "${ant_name}"
590
+ task: "${task_id}"
591
+ what_failed: "${blockers[0]:-$failure_reason}"
592
+ why: "worker returned failed status"
593
+ what_worked: null
594
+ error_type: "worker_failure"
595
+ EOF
596
+
597
+ # Record observation for potential promotion
598
+ bash .aether/aether-utils.sh learning-observe \
599
+ "Builder ${ant_name} failed on task ${task_id}: ${blockers[0]:-$failure_reason}" \
600
+ "failure" \
601
+ "${colony_name}" 2>/dev/null || true
602
+ ```
603
+
604
+ **PER WORKER:** Run using the Bash tool with description "Recording {name} completion...": `bash .aether/aether-utils.sh spawn-complete "{ant_name}" "completed" "{summary}" && bash .aether/aether-utils.sh swarm-display-update "{ant_name}" "builder" "completed" "{task_description}" "Queen" '{"read":5,"grep":3,"edit":2,"bash":1}' 100 "fungus_garden" 100 && bash .aether/aether-utils.sh context-update worker-complete "{ant_name}" "completed"`
605
+
606
+ **Check for total wave failure:**
607
+
608
+ After processing all worker results in this wave, check if EVERY worker returned `status: "failed"`. If ALL workers in the wave failed:
609
+
610
+ Display a prominent halt alert:
611
+ ```
612
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
613
+ ⚠ WAVE FAILURE — BUILD HALTED
614
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
615
+
616
+ All {N} workers in Wave {X} failed. Something is fundamentally wrong.
617
+
618
+ Failed workers:
619
+ {for each failed worker in this wave:}
620
+ {caste_emoji} {Ant-Name}: {task_description} ✗ ({failure_reason} after {tool_count} tools)
621
+ {end for}
622
+
623
+ Next steps:
624
+ /ant:flags Review blockers
625
+ /ant:swarm Auto-repair mode
626
+ ```
627
+
628
+ Then STOP — do not proceed to subsequent waves, Watcher, or Chaos. Skip directly to Step 5.9 synthesis with `status: "failed"`.
629
+
630
+ **Partial wave failure — escalation path:**
631
+
632
+ If SOME (but not all) workers in the wave failed:
633
+ 1. For each failed worker, attempt Tier 3 escalation: Queen spawns a different caste for the same task
634
+ 2. If Tier 3 succeeds: continue to next wave
635
+ 3. If Tier 3 fails: display the Tier 4 ESCALATION banner (from Queen agent definition):
636
+
637
+ ```
638
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
639
+ ⚠ ESCALATION — QUEEN NEEDS YOU
640
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
641
+
642
+ Task: {failed task description}
643
+ Phase: {phase number} — {phase name}
644
+
645
+ Tried:
646
+ • Worker retry (2 attempts) — {what failed}
647
+ • Parent tried alternate approach — {what failed}
648
+ • Queen reassigned to {other caste} — {what failed}
649
+
650
+ Options:
651
+ A) {recommended option} — RECOMMENDED
652
+ B) {alternate option}
653
+ C) Skip and continue — this task will be marked blocked
654
+
655
+ Awaiting your choice.
656
+ ```
657
+
658
+ Log escalation as flag:
659
+ Run using the Bash tool with description "Logging escalation...": `bash .aether/aether-utils.sh flag-add "blocker" "{task title}" "{failure summary}" "escalation" {phase_number}`
660
+
661
+ If at least one worker succeeded, continue normally to the next wave.
662
+
663
+ **Parse each worker's JSON output to collect:** status, files_created, files_modified, blockers
664
+
665
+ **Visual Mode: Render live display (tmux only):**
666
+ If `visual_mode` is true AND the build is running inside a tmux session (`$TMUX` environment variable is set), run using the Bash tool with description "Rendering build progress...": `bash .aether/aether-utils.sh swarm-display-text "$build_id"`
667
+
668
+ If `$TMUX` is not set, skip this call entirely — do not attempt it. Chat users see the structured completion lines above instead.
669
+
670
+ ### Step 5.3: Spawn Wave 2+ Workers (Sequential Waves)
671
+
672
+ **Before each subsequent wave, display a wave separator:**
673
+ ```
674
+ ━━━ 🐜 Wave {X} of {N} ━━━
675
+ ```
676
+ Then display the spawn announcement (same format as Step 5.1).
677
+
678
+ Repeat Step 5.1-5.2 for each subsequent wave, waiting for previous wave to complete.
679
+
680
+ ### Step 5.4: Spawn Watcher for Verification
681
+
682
+ **MANDATORY: Always spawn a Watcher — testing must be independent.**
683
+
684
+ **Announce the verification wave:**
685
+ ```
686
+ ━━━ 👁️🐜 V E R I F I C A T I O N ━━━
687
+ ──── 👁️🐜 Spawning {watcher_name} ────
688
+ ```
689
+
690
+ Spawn the Watcher using Task tool with `subagent_type="aether-watcher"`, include `description: "👁️ Watcher {Watcher-Name}: Independent verification"` (DO NOT use run_in_background - task blocks until complete):
691
+
692
+ Run using the Bash tool with description "Dispatching watcher...": `bash .aether/aether-utils.sh spawn-log "Queen" "watcher" "{watcher_name}" "Independent verification" && bash .aether/aether-utils.sh swarm-display-update "{watcher_name}" "watcher" "observing" "Verification in progress" "Queen" '{"read":0,"grep":0,"edit":0,"bash":0}' 0 "nursery" 50`
693
+
694
+ **Watcher Worker Prompt (CLEAN OUTPUT):**
695
+ ```
696
+ You are {Watcher-Name}, a 👁️🐜 Watcher Ant.
697
+
698
+ Verify all work done by Builders in Phase {id}.
699
+
700
+ Files to verify:
701
+ - Created: {list from builder results}
702
+ - Modified: {list from builder results}
703
+
704
+ { prompt_section }
705
+
706
+ **IMPORTANT:** When using the Bash tool for activity calls, always include a description parameter:
707
+ - activity-log calls → "Logging {action}..."
708
+ - swarm-display-update calls → "Updating build display..."
709
+ - pheromone-read calls → "Checking colony signals..."
710
+ - spawn-log calls → "Dispatching sub-worker..."
711
+
712
+ Use colony-flavored language, 4-8 words, trailing ellipsis.
713
+
714
+ Verification:
715
+ 1. Check files exist (Read each)
716
+ 2. Run build/type-check
717
+ 3. Run tests if they exist
718
+ 4. Check success criteria: {list}
719
+
720
+ Spawn sub-workers if needed:
721
+ - Log spawn using Bash tool with description
722
+ - Announce: "🐜 Spawning {child} to investigate {issue}"
723
+
724
+ Count your total tool calls (Read + Grep + Edit + Bash + Write) and report as tool_count.
725
+
726
+ Return ONLY this JSON:
727
+ {"ant_name": "{Watcher-Name}", "verification_passed": true|false, "files_verified": [], "issues_found": [], "quality_score": N, "tool_count": 0, "recommendation": "proceed|fix_required"}
728
+ ```
729
+
730
+ ### Step 5.5: Process Watcher Results
731
+
732
+ **Task call returns results directly (no TaskOutput needed).**
733
+
734
+ **Parse the Watcher's JSON response:** verification_passed, issues_found, quality_score, recommendation
735
+
736
+ **Display Watcher completion line:**
737
+
738
+ For successful verification:
739
+ ```
740
+ 👁️ {Watcher-Name}: Independent verification ({tool_count} tools) ✓
741
+ ```
742
+
743
+ For failed verification:
744
+ ```
745
+ 👁️ {Watcher-Name}: Independent verification ✗ ({issues_found count} issues after {tool_count} tools)
746
+ ```
747
+
748
+ **Store results for synthesis in Step 5.7**
749
+
750
+ **Update swarm display when Watcher completes:**
751
+ Run using the Bash tool with description "Recording watcher completion...": `bash .aether/aether-utils.sh swarm-display-update "{watcher_name}" "watcher" "completed" "Verification complete" "Queen" '{"read":3,"grep":2,"edit":0,"bash":1}' 100 "nursery" 100`
752
+
753
+ ### Step 5.6: Spawn Chaos Ant for Resilience Testing
754
+
755
+ **After the Watcher completes, spawn a Chaos Ant to probe the phase work for edge cases and boundary conditions.**
756
+
757
+ Generate a chaos ant name and dispatch:
758
+ Run using the Bash tool with description "Naming chaos ant...": `bash .aether/aether-utils.sh generate-ant-name "chaos"` (store as `{chaos_name}`)
759
+ Run using the Bash tool with description "Loading existing flags...": `bash .aether/aether-utils.sh flag-list --phase {phase_number}`
760
+ Parse the result and extract unresolved flag titles into a list: `{existing_flag_titles}` (comma-separated titles from `.result.flags[].title`). If no flags exist, set `{existing_flag_titles}` to "None".
761
+ Run using the Bash tool with description "Dispatching chaos ant...": `bash .aether/aether-utils.sh spawn-log "Queen" "chaos" "{chaos_name}" "Resilience testing of Phase {id} work" && bash .aether/aether-utils.sh swarm-display-update "{chaos_name}" "chaos" "probing" "Resilience testing" "Queen" '{"read":0,"grep":0,"edit":0,"bash":0}' 0 "refuse_pile" 75`
762
+
763
+ **Announce the resilience testing wave:**
764
+ ```
765
+ ──── 🎲🐜 Spawning {chaos_name} — resilience testing ────
766
+ ```
767
+
768
+ Spawn the Chaos Ant using Task tool with `subagent_type="aether-chaos"`, include `description: "🎲 Chaos {Chaos-Name}: Resilience testing"` (DO NOT use run_in_background - task blocks until complete):
769
+ # FALLBACK: If "Agent type not found", use general-purpose and inject role: "You are a Chaos Ant - resilience tester that probes edge cases and boundary conditions."
770
+
771
+ **Chaos Ant Prompt (CLEAN OUTPUT):**
772
+ ```
773
+ You are {Chaos-Name}, a 🎲🐜 Chaos Ant.
774
+
775
+ Test Phase {id} work for edge cases and boundary conditions.
776
+
777
+ Files to test:
778
+ - {list from builder results}
779
+
780
+ Skip these known issues: {existing_flag_titles}
781
+
782
+ **IMPORTANT:** When using the Bash tool for activity calls, always include a description parameter:
783
+ - activity-log calls → "Logging {action}..."
784
+ - swarm-display-update calls → "Updating build display..."
785
+ - pheromone-read calls → "Checking colony signals..."
786
+
787
+ Use colony-flavored language, 4-8 words, trailing ellipsis.
788
+
789
+ Rules:
790
+ - Max 5 scenarios
791
+ - Read-only (don't modify code)
792
+ - Focus: edge cases, boundaries, error handling
793
+
794
+ Count your total tool calls (Read + Grep + Edit + Bash + Write) and report as tool_count.
795
+
796
+ Return ONLY this JSON:
797
+ {"ant_name": "{Chaos-Name}", "scenarios_tested": 5, "findings": [{"id": 1, "category": "edge_case|boundary|error_handling", "severity": "critical|high|medium|low", "title": "...", "description": "..."}], "overall_resilience": "strong|moderate|weak", "tool_count": 0, "summary": "..."}
798
+ ```
799
+
800
+ ### Step 5.7: Process Chaos Ant Results
801
+
802
+ **Task call returns results directly (no TaskOutput needed).**
803
+
804
+ **Parse the Chaos Ant's JSON response:** findings, overall_resilience, summary
805
+
806
+ **Display Chaos completion line:**
807
+ ```
808
+ 🎲 {Chaos-Name}: Resilience testing ({tool_count} tools) ✓
809
+ ```
810
+
811
+ **Store results for synthesis in Step 5.9**
812
+
813
+ **Flag critical/high findings:**
814
+
815
+ If any findings have severity `"critical"` or `"high"`:
816
+ Run using the Bash tool with description "Flagging {finding.title}...": `bash .aether/aether-utils.sh flag-add "blocker" "{finding.title}" "{finding.description}" "chaos-testing" {phase_number} && bash .aether/aether-utils.sh activity-log "FLAG" "Chaos" "Created blocker: {finding.title}"`
817
+
818
+ **Log resilience finding to midden (MEM-02):**
819
+
820
+ For each critical/high finding, run using the Bash tool with description "Logging resilience finding...":
821
+ ```bash
822
+ colony_name=$(jq -r '.session_id | split("_")[1] // "unknown"' .aether/data/COLONY_STATE.json 2>/dev/null || echo "unknown")
823
+ phase_num=$(jq -r '.phase.number // "unknown"' .aether/data/COLONY_STATE.json 2>/dev/null || echo "unknown")
824
+
825
+ # Append to build-failures.md
826
+ cat >> .aether/midden/build-failures.md << EOF
827
+ - timestamp: "$(date -u +%Y-%m-%dT%H:%M:%SZ)"
828
+ phase: ${phase_num}
829
+ colony: "${colony_name}"
830
+ worker: "${chaos_name}"
831
+ test_context: "resilience"
832
+ what_failed: "${finding.title}"
833
+ why: "${finding.description}"
834
+ what_worked: null
835
+ severity: "${finding.severity}"
836
+ EOF
837
+
838
+ # Record as observation
839
+ bash .aether/aether-utils.sh learning-observe \
840
+ "Resilience issue found: ${finding.title} (${finding.severity})" \
841
+ "failure" \
842
+ "${colony_name}" 2>/dev/null || true
843
+ ```
844
+
845
+ Log chaos ant completion and update swarm display:
846
+ Run using the Bash tool with description "Recording chaos completion...": `bash .aether/aether-utils.sh spawn-complete "{chaos_name}" "completed" "{summary}" && bash .aether/aether-utils.sh swarm-display-update "{chaos_name}" "chaos" "completed" "Resilience testing done" "Queen" '{"read":2,"grep":1,"edit":0,"bash":0}' 100 "refuse_pile" 100`
847
+
848
+ ### Step 5.8: Create Flags for Verification Failures
849
+
850
+ If the Watcher reported `verification_passed: false` or `recommendation: "fix_required"`:
851
+
852
+ For each issue in `issues_found`:
853
+ Run using the Bash tool with description "Flagging {issue_title}...": `bash .aether/aether-utils.sh flag-add "blocker" "{issue_title}" "{issue_description}" "verification" {phase_number} && bash .aether/aether-utils.sh activity-log "FLAG" "Watcher" "Created blocker: {issue_title}"`
854
+
855
+ **Log verification failure to midden (MEM-02):**
856
+
857
+ After flagging each issue, run using the Bash tool with description "Logging verification failure...":
858
+ ```bash
859
+ colony_name=$(jq -r '.session_id | split("_")[1] // "unknown"' .aether/data/COLONY_STATE.json 2>/dev/null || echo "unknown")
860
+ phase_num=$(jq -r '.phase.number // "unknown"' .aether/data/COLONY_STATE.json 2>/dev/null || echo "unknown")
861
+
862
+ # Append to test-failures.md
863
+ cat >> .aether/midden/test-failures.md << EOF
864
+ - timestamp: "$(date -u +%Y-%m-%dT%H:%M:%SZ)"
865
+ phase: ${phase_num}
866
+ colony: "${colony_name}"
867
+ worker: "${watcher_name}"
868
+ test_context: "verification"
869
+ what_failed: "${issue_title}"
870
+ why: "${issue_description}"
871
+ what_worked: null
872
+ severity: "high"
873
+ EOF
874
+
875
+ # Record as observation
876
+ bash .aether/aether-utils.sh learning-observe \
877
+ "Verification failed: ${issue_title} - ${issue_description}" \
878
+ "failure" \
879
+ "${colony_name}" 2>/dev/null || true
880
+ ```
881
+
882
+ This ensures verification failures are persisted as blockers that survive context resets. Chaos Ant findings are flagged in Step 5.7.
883
+
884
+ ### Step 5.9: Synthesize Results
885
+
886
+ **This step runs after all worker tasks have completed (Builders, Watcher, Chaos).**
887
+
888
+ Collect all worker outputs and create phase summary:
889
+
890
+ ```json
891
+ {
892
+ "status": "completed" | "failed" | "blocked",
893
+ "summary": "...",
894
+ "tasks_completed": [...],
895
+ "tasks_failed": [...],
896
+ "files_created": [...],
897
+ "files_modified": [...],
898
+ "spawn_metrics": {
899
+ "spawn_count": {total workers spawned, including archaeologist if Step 4.5 fired},
900
+ "builder_count": {N},
901
+ "watcher_count": 1,
902
+ "chaos_count": 1,
903
+ "archaeologist_count": {0 or 1, conditional on Step 4.5},
904
+ "parallel_batches": {number of waves}
905
+ },
906
+ "spawn_tree": {
907
+ "{Archaeologist-Name}": {"caste": "archaeologist", "task": "pre-build history scan", "status": "completed"},
908
+ "{Builder-Name}": {"caste": "builder", "task": "...", "status": "completed"},
909
+ "{Watcher-Name}": {"caste": "watcher", "task": "verify", "status": "completed"},
910
+ "{Chaos-Name}": {"caste": "chaos", "task": "resilience testing", "status": "completed"}
911
+ },
912
+ "verification": {from Watcher output},
913
+ "resilience": {from Chaos Ant output},
914
+ "archaeology": {from Archaeologist output, or null if Step 4.5 was skipped},
915
+ "quality_notes": "..."
916
+ }
917
+ ```
918
+
919
+ **Graveyard Recording:**
920
+ For each worker that returned `status: "failed"`:
921
+ For each file in that worker's `files_modified` or `files_created`:
922
+ Run using the Bash tool with description "Recording failure grave...": `bash .aether/aether-utils.sh grave-add "{file}" "{ant_name}" "{task_id}" {phase} "{first blocker or summary}" && bash .aether/aether-utils.sh activity-log "GRAVE" "Queen" "Grave marker placed at {file} — {ant_name} failed: {summary}"`
923
+
924
+ **Error Handoff Update:**
925
+ If workers failed, update handoff with error context for recovery:
926
+
927
+ Resolve the build error handoff template path:
928
+ Check ~/.aether/system/templates/handoff-build-error.template.md first,
929
+ then .aether/templates/handoff-build-error.template.md.
930
+
931
+ If no template found: output "Template missing: handoff-build-error.template.md. Run aether update to fix." and stop.
932
+
933
+ Read the template file. Fill all {{PLACEHOLDER}} values:
934
+ - {{PHASE_NUMBER}} → current phase number
935
+ - {{PHASE_NAME}} → current phase name
936
+ - {{BUILD_TIMESTAMP}} → current ISO-8601 UTC timestamp
937
+ - {{FAILED_WORKERS}} → formatted list of failed workers (one "- {ant_name}: {failure_summary}" per line)
938
+ - {{GRAVE_MARKERS}} → formatted list of grave markers (one "- {file}: {caution_level} caution" per line)
939
+
940
+ Remove the HTML comment lines at the top of the template.
941
+ Write the result to .aether/HANDOFF.md using the Write tool.
942
+
943
+ Only fires when workers fail. Zero impact on successful builds.
944
+
945
+ --- SPAWN TRACKING ---
946
+
947
+ The spawn tree will be visible in `/ant:watch` because each spawn is logged.
948
+
949
+ --- OUTPUT FORMAT ---
950
+
951
+ Return JSON:
952
+ {
953
+ "status": "completed" | "failed" | "blocked",
954
+ "summary": "What the phase accomplished",
955
+ "tasks_completed": ["1.1", "1.2"],
956
+ "tasks_failed": [],
957
+ "files_created": ["path1", "path2"],
958
+ "files_modified": ["path3"],
959
+ "spawn_metrics": {
960
+ "spawn_count": 6,
961
+ "watcher_count": 1,
962
+ "chaos_count": 1,
963
+ "archaeologist_count": 1,
964
+ "builder_count": 3,
965
+ "parallel_batches": 2,
966
+ "sequential_tasks": 1
967
+ },
968
+ "spawn_tree": {
969
+ "Relic-8": {"caste": "archaeologist", "task": "pre-build history scan", "status": "completed", "children": {}},
970
+ "Hammer-42": {"caste": "builder", "task": "...", "status": "completed", "children": {}},
971
+ "Vigil-17": {"caste": "watcher", "task": "...", "status": "completed", "children": {}},
972
+ "Entropy-9": {"caste": "chaos", "task": "resilience testing", "status": "completed", "children": {}}
973
+ },
974
+ "verification": {
975
+ "build": {"command": "npm run build", "exit_code": 0, "passed": true},
976
+ "tests": {"command": "npm test", "passed": 24, "failed": 0, "total": 24},
977
+ "success_criteria": [
978
+ {"criterion": "API endpoint exists", "evidence": "GET /api/users returns 200", "passed": true},
979
+ {"criterion": "Tests cover happy path", "evidence": "3 tests in users.test.ts", "passed": true}
980
+ ]
981
+ },
982
+ "debugging": {
983
+ "issues_encountered": 0,
984
+ "issues_resolved": 0,
985
+ "fix_attempts": 0,
986
+ "architectural_concerns": []
987
+ },
988
+ "tdd": {
989
+ "cycles_completed": 5,
990
+ "tests_added": 5,
991
+ "tests_total": 47,
992
+ "coverage_percent": 85,
993
+ "all_passing": true
994
+ },
995
+ "learning": {
996
+ "patterns_observed": [
997
+ {
998
+ "type": "success",
999
+ "trigger": "when implementing API endpoints",
1000
+ "action": "use repository pattern with DI",
1001
+ "evidence": "All tests passed first try"
1002
+ }
1003
+ ],
1004
+ "instincts_applied": ["instinct_123"],
1005
+ "instinct_outcomes": [
1006
+ {"id": "instinct_123", "success": true}
1007
+ ]
1008
+ },
1009
+ "quality_notes": "Any concerns or recommendations",
1010
+ "ui_touched": true | false
1011
+ }
1012
+ ```
1013
+
1014
+ ### Step 6: Visual Checkpoint (if UI touched)
1015
+
1016
+ Parse synthesis result. If `ui_touched` is true:
1017
+
1018
+ ```
1019
+ ━━━ 🖼️🐜 V I S U A L C H E C K P O I N T ━━━
1020
+
1021
+ UI changes detected. Verify appearance before continuing.
1022
+
1023
+ Files touched:
1024
+ {list files from files_created + files_modified that match UI patterns}
1025
+
1026
+ Options:
1027
+ 1. Approve - UI looks correct
1028
+ 2. Reject - needs changes (describe issues)
1029
+ 3. Skip - defer visual review
1030
+ ```
1031
+
1032
+ Use AskUserQuestion to get approval. Record in events:
1033
+ - If approved: `"<timestamp>|visual_approved|build|Phase {id} UI approved"`
1034
+ - If rejected: `"<timestamp>|visual_rejected|build|Phase {id} UI rejected: {reason}"`
1035
+
1036
+ ### Step 6.5: Update Handoff Document
1037
+
1038
+ After synthesis is complete, update the handoff document with current state for session recovery:
1039
+
1040
+ ```bash
1041
+ # Update handoff with build results
1042
+ jq -n \
1043
+ --arg timestamp "$(date -u +%Y-%m-%dT%H:%M:%SZ)" \
1044
+ --arg goal "$(jq -r '.goal' .aether/data/COLONY_STATE.json)" \
1045
+ --arg phase "$(jq -r '.current_phase' .aether/data/COLONY_STATE.json)" \
1046
+ --arg phase_name "{phase_name}" \
1047
+ --arg status "{synthesis.status}" \
1048
+ --arg summary "{synthesis.summary}" \
1049
+ --argjson tasks_completed '{synthesis.tasks_completed | length}' \
1050
+ --argjson tasks_failed '{synthesis.tasks_failed | length}' \
1051
+ --arg next_action "{if synthesis.status == "completed" then "/ant:continue" else "/ant:flags" end}" \
1052
+ '{
1053
+ "last_updated": $timestamp,
1054
+ "goal": $goal,
1055
+ "current_phase": $phase,
1056
+ "phase_name": $phase_name,
1057
+ "build_status": $status,
1058
+ "summary": $summary,
1059
+ "tasks_completed": $tasks_completed,
1060
+ "tasks_failed": $tasks_failed,
1061
+ "next_recommended_action": $next_action,
1062
+ "can_resume": true,
1063
+ "note": "Phase build completed. Run /ant:continue to advance if verification passed."
1064
+ }' > .aether/data/last-build-result.json
1065
+ ```
1066
+
1067
+ Resolve the build success handoff template path:
1068
+ Check ~/.aether/system/templates/handoff-build-success.template.md first,
1069
+ then .aether/templates/handoff-build-success.template.md.
1070
+
1071
+ If no template found: output "Template missing: handoff-build-success.template.md. Run aether update to fix." and stop.
1072
+
1073
+ Read the template file. Fill all {{PLACEHOLDER}} values:
1074
+ - {{GOAL}} → colony goal (from COLONY_STATE.json)
1075
+ - {{PHASE_NUMBER}} → current phase number
1076
+ - {{PHASE_NAME}} → current phase name
1077
+ - {{BUILD_STATUS}} → synthesis.status
1078
+ - {{BUILD_TIMESTAMP}} → current ISO-8601 UTC timestamp
1079
+ - {{BUILD_SUMMARY}} → synthesis summary
1080
+ - {{TASKS_COMPLETED}} → count of completed tasks
1081
+ - {{TASKS_FAILED}} → count of failed tasks
1082
+ - {{FILES_CREATED}} → count of created files
1083
+ - {{FILES_MODIFIED}} → count of modified files
1084
+ - {{SESSION_NOTE}} → "Build succeeded — ready to advance." if status is completed, else "Build completed with issues — review before continuing."
1085
+
1086
+ Remove the HTML comment lines at the top of the template.
1087
+ Write the result to .aether/HANDOFF.md using the Write tool.
1088
+
1089
+ This ensures the handoff always reflects the latest build state, even if the session crashes before explicit pause.
1090
+
1091
+ ### Step 6.5: Update Context Document
1092
+
1093
+ Log this build activity to `.aether/CONTEXT.md`:
1094
+
1095
+ Run using the Bash tool with description "Updating build context...": `bash .aether/aether-utils.sh context-update activity "build {phase_id}" "{synthesis.status}" "{files_created_count + files_modified_count}" && bash .aether/aether-utils.sh context-update build-complete "{synthesis.status}" "{synthesis.status == 'completed' ? 'success' : 'failed'}"`
1096
+
1097
+ Also update safe-to-clear status:
1098
+ - If build completed successfully: `context-update safe-to-clear "YES" "Build complete, ready to continue"`
1099
+ - If build failed: `context-update safe-to-clear "NO" "Build failed — run /ant:swarm or /ant:flags"`
1100
+
1101
+ ### Step 7: Display Results
1102
+
1103
+ **This step runs ONLY after synthesis is complete. All values come from actual worker results.**
1104
+
1105
+ **Update swarm display state (always) and render (tmux only):**
1106
+ Run using the Bash tool with description "Recording build completion...": `bash .aether/aether-utils.sh swarm-display-update "Queen" "prime" "completed" "Phase {id} complete" "Colony" '{"read":10,"grep":5,"edit":5,"bash":2}' 100 "fungus_garden" 100`
1107
+
1108
+ If `$TMUX` is set, also run using the Bash tool with description "Rendering final swarm display...": `bash .aether/aether-utils.sh swarm-display-text "$build_id"`
1109
+
1110
+ **Display BUILD SUMMARY (always shown, replaces compact/verbose split):**
1111
+
1112
+ Calculate `total_tools` by summing `tool_count` from all worker return JSONs (builders + watcher + chaos).
1113
+ Calculate `elapsed` using `build_started_at_epoch` (epoch integer captured at Step 5 start by Plan 01): `$(( $(date +%s) - build_started_at_epoch ))` formatted as Xm Ys.
1114
+
1115
+ ```
1116
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
1117
+ B U I L D S U M M A R Y
1118
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
1119
+ Phase {id}: {name}
1120
+ Pattern: {selected_pattern}
1121
+
1122
+ Workers: {pass_count} passed {fail_count} failed ({total} total)
1123
+ Tools: {total_tools} calls across all workers
1124
+ Duration: {elapsed}
1125
+
1126
+ {if fail_count > 0:}
1127
+ Failed:
1128
+ {for each failed worker:}
1129
+ {caste_emoji} {Ant-Name}: {task_description} ✗ ({failure_reason} after {tool_count} tools)
1130
+ {end for}
1131
+
1132
+ Retry: /ant:swarm to auto-repair failed tasks, or /ant:flags to review blockers
1133
+ {end if}
1134
+ ```
1135
+
1136
+ **If verbose_mode is true**, additionally show the spawn tree and TDD details after the BUILD SUMMARY block (keep the existing verbose-only sections: Colony Work Tree, Tasks Completed, TDD, Patterns Learned, Debugging, Model Routing). Prepend with:
1137
+ ```
1138
+ ━━ Details (--verbose) ━━
1139
+ ```
1140
+
1141
+ After displaying the BUILD SUMMARY (and optional verbose details), call the Next Up helper by running using the Bash tool with description "Displaying next steps...":
1142
+ ```bash
1143
+ state=$(jq -r '.state // "IDLE"' .aether/data/COLONY_STATE.json 2>/dev/null || echo "IDLE")
1144
+ current_phase=$(jq -r '.current_phase // 0' .aether/data/COLONY_STATE.json 2>/dev/null || echo "0")
1145
+ total_phases=$(jq -r '.plan.phases | length' .aether/data/COLONY_STATE.json 2>/dev/null || echo "0")
1146
+ bash .aether/aether-utils.sh print-next-up "$state" "$current_phase" "$total_phases"
1147
+ ```
1148
+
1149
+ **Routing Note:** The state-based Next Up block above routes based on colony state. If verification failed or blockers exist, review `/ant:flags` before continuing.
1150
+
1151
+ **IMPORTANT:** Build does NOT update task statuses or advance state. Run `/ant:continue` to:
1152
+ - Mark tasks as completed
1153
+ - Extract learnings
1154
+ - Advance to next phase
1155
+
1156
+ ### Step 8: Update Session
1157
+
1158
+ Update the session tracking file to enable `/ant:resume` after context clear:
1159
+
1160
+ Run using the Bash tool with description "Saving build session...": `bash .aether/aether-utils.sh session-update "/ant:build {phase_id}" "/ant:continue" "Phase {phase_id} build completed: {synthesis.status}"`