aether-colony 5.0.0 → 5.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 (312) hide show
  1. package/.aether/aether-utils.sh +3150 -3349
  2. package/.aether/agents-claude/aether-ambassador.md +265 -0
  3. package/.aether/agents-claude/aether-archaeologist.md +327 -0
  4. package/.aether/agents-claude/aether-architect.md +236 -0
  5. package/.aether/agents-claude/aether-auditor.md +271 -0
  6. package/.aether/agents-claude/aether-builder.md +224 -0
  7. package/.aether/agents-claude/aether-chaos.md +269 -0
  8. package/.aether/agents-claude/aether-chronicler.md +305 -0
  9. package/.aether/agents-claude/aether-gatekeeper.md +330 -0
  10. package/.aether/agents-claude/aether-includer.md +374 -0
  11. package/.aether/agents-claude/aether-keeper.md +272 -0
  12. package/.aether/agents-claude/aether-measurer.md +322 -0
  13. package/.aether/agents-claude/aether-oracle.md +237 -0
  14. package/.aether/agents-claude/aether-probe.md +211 -0
  15. package/.aether/agents-claude/aether-queen.md +330 -0
  16. package/.aether/agents-claude/aether-route-setter.md +178 -0
  17. package/.aether/agents-claude/aether-sage.md +418 -0
  18. package/.aether/agents-claude/aether-scout.md +179 -0
  19. package/.aether/agents-claude/aether-surveyor-disciplines.md +417 -0
  20. package/.aether/agents-claude/aether-surveyor-nest.md +355 -0
  21. package/.aether/agents-claude/aether-surveyor-pathogens.md +289 -0
  22. package/.aether/agents-claude/aether-surveyor-provisions.md +360 -0
  23. package/.aether/agents-claude/aether-tracker.md +270 -0
  24. package/.aether/agents-claude/aether-watcher.md +280 -0
  25. package/.aether/agents-claude/aether-weaver.md +248 -0
  26. package/.aether/commands/archaeology.yaml +653 -0
  27. package/.aether/commands/build.yaml +1221 -0
  28. package/.aether/commands/chaos.yaml +653 -0
  29. package/.aether/commands/colonize.yaml +438 -0
  30. package/.aether/commands/continue.yaml +1484 -0
  31. package/.aether/commands/council.yaml +304 -0
  32. package/.aether/commands/data-clean.yaml +80 -0
  33. package/.aether/commands/dream.yaml +275 -0
  34. package/.aether/commands/entomb.yaml +863 -0
  35. package/.aether/commands/export-signals.yaml +64 -0
  36. package/.aether/commands/feedback.yaml +158 -0
  37. package/.aether/commands/flag.yaml +160 -0
  38. package/.aether/commands/flags.yaml +177 -0
  39. package/.aether/commands/focus.yaml +112 -0
  40. package/.aether/commands/help.yaml +167 -0
  41. package/.aether/commands/history.yaml +137 -0
  42. package/.aether/commands/import-signals.yaml +79 -0
  43. package/.aether/commands/init.yaml +469 -0
  44. package/.aether/commands/insert-phase.yaml +98 -0
  45. package/.aether/commands/interpret.yaml +285 -0
  46. package/.aether/commands/lay-eggs.yaml +224 -0
  47. package/.aether/commands/maturity.yaml +122 -0
  48. package/.aether/commands/memory-details.yaml +74 -0
  49. package/.aether/commands/migrate-state.yaml +174 -0
  50. package/.aether/commands/oracle.yaml +1224 -0
  51. package/.aether/commands/organize.yaml +446 -0
  52. package/.aether/commands/patrol.yaml +621 -0
  53. package/.aether/commands/pause-colony.yaml +424 -0
  54. package/.aether/commands/phase.yaml +124 -0
  55. package/.aether/commands/pheromones.yaml +153 -0
  56. package/.aether/commands/plan.yaml +1313 -0
  57. package/.aether/commands/preferences.yaml +63 -0
  58. package/.aether/commands/redirect.yaml +123 -0
  59. package/.aether/commands/resume-colony.yaml +373 -0
  60. package/.aether/commands/resume.yaml +398 -0
  61. package/.aether/commands/run.yaml +193 -0
  62. package/.aether/commands/seal.yaml +1205 -0
  63. package/.aether/commands/skill-create.yaml +337 -0
  64. package/.aether/commands/status.yaml +364 -0
  65. package/.aether/commands/swarm.yaml +352 -0
  66. package/.aether/commands/tunnels.yaml +814 -0
  67. package/.aether/commands/update.yaml +131 -0
  68. package/.aether/commands/verify-castes.yaml +159 -0
  69. package/.aether/commands/watch.yaml +454 -0
  70. package/.aether/docs/INCIDENT_TEMPLATE.md +32 -0
  71. package/.aether/docs/QUEEN-SYSTEM.md +11 -11
  72. package/.aether/docs/README.md +32 -2
  73. package/.aether/docs/command-playbooks/README.md +23 -0
  74. package/.aether/docs/command-playbooks/build-complete.md +349 -0
  75. package/.aether/docs/command-playbooks/build-context.md +282 -0
  76. package/.aether/docs/command-playbooks/build-full.md +1682 -0
  77. package/.aether/docs/command-playbooks/build-prep.md +283 -0
  78. package/.aether/docs/command-playbooks/build-verify.md +405 -0
  79. package/.aether/docs/command-playbooks/build-wave.md +749 -0
  80. package/.aether/docs/command-playbooks/continue-advance.md +524 -0
  81. package/.aether/docs/command-playbooks/continue-finalize.md +447 -0
  82. package/.aether/docs/command-playbooks/continue-full.md +1724 -0
  83. package/.aether/docs/command-playbooks/continue-gates.md +686 -0
  84. package/.aether/docs/command-playbooks/continue-verify.md +406 -0
  85. package/.aether/docs/context-continuity.md +84 -0
  86. package/.aether/docs/disciplines/DISCIPLINES.md +9 -7
  87. package/.aether/docs/error-codes.md +1 -1
  88. package/.aether/docs/known-issues.md +34 -173
  89. package/.aether/docs/pheromones.md +86 -6
  90. package/.aether/docs/plans/pheromone-display-plan.md +257 -0
  91. package/.aether/docs/queen-commands.md +10 -9
  92. package/.aether/docs/source-of-truth-map.md +132 -0
  93. package/.aether/docs/xml-utilities.md +47 -0
  94. package/.aether/rules/aether-colony.md +23 -13
  95. package/.aether/scripts/incident-test-add.sh +47 -0
  96. package/.aether/scripts/weekly-audit.sh +79 -0
  97. package/.aether/skills/.index.json +649 -0
  98. package/.aether/skills/colony/.manifest.json +16 -0
  99. package/.aether/skills/colony/build-discipline/SKILL.md +78 -0
  100. package/.aether/skills/colony/colony-interaction/SKILL.md +56 -0
  101. package/.aether/skills/colony/colony-lifecycle/SKILL.md +77 -0
  102. package/.aether/skills/colony/colony-visuals/SKILL.md +112 -0
  103. package/.aether/skills/colony/context-management/SKILL.md +80 -0
  104. package/.aether/skills/colony/error-presentation/SKILL.md +99 -0
  105. package/.aether/skills/colony/pheromone-protocol/SKILL.md +79 -0
  106. package/.aether/skills/colony/pheromone-visibility/SKILL.md +81 -0
  107. package/.aether/skills/colony/state-safety/SKILL.md +84 -0
  108. package/.aether/skills/colony/worker-priming/SKILL.md +82 -0
  109. package/.aether/skills/domain/.manifest.json +24 -0
  110. package/.aether/skills/domain/README.md +33 -0
  111. package/.aether/skills/domain/django/SKILL.md +49 -0
  112. package/.aether/skills/domain/docker/SKILL.md +52 -0
  113. package/.aether/skills/domain/golang/SKILL.md +52 -0
  114. package/.aether/skills/domain/graphql/SKILL.md +51 -0
  115. package/.aether/skills/domain/html-css/SKILL.md +48 -0
  116. package/.aether/skills/domain/nextjs/SKILL.md +45 -0
  117. package/.aether/skills/domain/nodejs/SKILL.md +53 -0
  118. package/.aether/skills/domain/postgresql/SKILL.md +53 -0
  119. package/.aether/skills/domain/prisma/SKILL.md +59 -0
  120. package/.aether/skills/domain/python/SKILL.md +50 -0
  121. package/.aether/skills/domain/rails/SKILL.md +52 -0
  122. package/.aether/skills/domain/react/SKILL.md +45 -0
  123. package/.aether/skills/domain/rest-api/SKILL.md +58 -0
  124. package/.aether/skills/domain/svelte/SKILL.md +47 -0
  125. package/.aether/skills/domain/tailwind/SKILL.md +45 -0
  126. package/.aether/skills/domain/testing/SKILL.md +53 -0
  127. package/.aether/skills/domain/typescript/SKILL.md +58 -0
  128. package/.aether/skills/domain/vue/SKILL.md +49 -0
  129. package/.aether/templates/QUEEN.md.template +23 -41
  130. package/.aether/templates/colony-state-reset.jq.template +1 -0
  131. package/.aether/templates/colony-state.template.json +4 -0
  132. package/.aether/templates/learning-observations.template.json +6 -0
  133. package/.aether/templates/midden.template.json +13 -0
  134. package/.aether/templates/pheromones.template.json +6 -0
  135. package/.aether/templates/session.template.json +9 -0
  136. package/.aether/utils/atomic-write.sh +63 -17
  137. package/.aether/utils/chamber-utils.sh +145 -2
  138. package/.aether/utils/emoji-audit.sh +166 -0
  139. package/.aether/utils/error-handler.sh +21 -7
  140. package/.aether/utils/file-lock.sh +182 -27
  141. package/.aether/utils/flag.sh +267 -0
  142. package/.aether/utils/hive.sh +572 -0
  143. package/.aether/utils/learning.sh +1928 -0
  144. package/.aether/utils/midden.sh +342 -0
  145. package/.aether/utils/oracle/oracle.md +168 -0
  146. package/.aether/utils/oracle/oracle.sh +1023 -0
  147. package/.aether/utils/pheromone.sh +2029 -0
  148. package/.aether/utils/queen.sh +1698 -0
  149. package/.aether/utils/scan.sh +860 -0
  150. package/.aether/utils/semantic-cli.sh +10 -8
  151. package/.aether/utils/session.sh +552 -0
  152. package/.aether/utils/skills.sh +509 -0
  153. package/.aether/utils/spawn-tree.sh +103 -271
  154. package/.aether/utils/spawn.sh +260 -0
  155. package/.aether/utils/state-api.sh +199 -0
  156. package/.aether/utils/state-loader.sh +8 -6
  157. package/.aether/utils/suggest.sh +611 -0
  158. package/.aether/utils/swarm-display.sh +10 -1
  159. package/.aether/utils/swarm.sh +1004 -0
  160. package/.aether/utils/watch-spawn-tree.sh +11 -2
  161. package/.aether/utils/xml-compose.sh +2 -2
  162. package/.aether/utils/xml-convert.sh +9 -5
  163. package/.aether/utils/xml-core.sh +5 -9
  164. package/.aether/utils/xml-query.sh +4 -4
  165. package/.aether/workers.md +86 -67
  166. package/.claude/agents/ant/aether-ambassador.md +2 -1
  167. package/.claude/agents/ant/aether-archaeologist.md +6 -1
  168. package/.claude/agents/ant/aether-architect.md +236 -0
  169. package/.claude/agents/ant/aether-auditor.md +6 -1
  170. package/.claude/agents/ant/aether-builder.md +38 -1
  171. package/.claude/agents/ant/aether-chaos.md +2 -1
  172. package/.claude/agents/ant/aether-chronicler.md +1 -0
  173. package/.claude/agents/ant/aether-gatekeeper.md +6 -1
  174. package/.claude/agents/ant/aether-includer.md +1 -0
  175. package/.claude/agents/ant/aether-keeper.md +1 -0
  176. package/.claude/agents/ant/aether-measurer.md +6 -1
  177. package/.claude/agents/ant/aether-oracle.md +237 -0
  178. package/.claude/agents/ant/aether-probe.md +2 -1
  179. package/.claude/agents/ant/aether-queen.md +6 -1
  180. package/.claude/agents/ant/aether-route-setter.md +6 -1
  181. package/.claude/agents/ant/aether-sage.md +68 -3
  182. package/.claude/agents/ant/aether-scout.md +38 -1
  183. package/.claude/agents/ant/aether-surveyor-disciplines.md +2 -1
  184. package/.claude/agents/ant/aether-surveyor-nest.md +2 -1
  185. package/.claude/agents/ant/aether-surveyor-pathogens.md +2 -1
  186. package/.claude/agents/ant/aether-surveyor-provisions.md +2 -1
  187. package/.claude/agents/ant/aether-tracker.md +6 -1
  188. package/.claude/agents/ant/aether-watcher.md +37 -1
  189. package/.claude/agents/ant/aether-weaver.md +2 -1
  190. package/.claude/commands/ant/archaeology.md +1 -8
  191. package/.claude/commands/ant/build.md +43 -1159
  192. package/.claude/commands/ant/chaos.md +1 -14
  193. package/.claude/commands/ant/colonize.md +1 -14
  194. package/.claude/commands/ant/continue.md +40 -1026
  195. package/.claude/commands/ant/council.md +9 -16
  196. package/.claude/commands/ant/data-clean.md +81 -0
  197. package/.claude/commands/ant/dream.md +12 -9
  198. package/.claude/commands/ant/entomb.md +62 -87
  199. package/.claude/commands/ant/export-signals.md +57 -0
  200. package/.claude/commands/ant/feedback.md +18 -0
  201. package/.claude/commands/ant/flag.md +12 -0
  202. package/.claude/commands/ant/flags.md +22 -8
  203. package/.claude/commands/ant/focus.md +18 -0
  204. package/.claude/commands/ant/help.md +40 -8
  205. package/.claude/commands/ant/history.md +3 -0
  206. package/.claude/commands/ant/import-signals.md +71 -0
  207. package/.claude/commands/ant/init.md +316 -191
  208. package/.claude/commands/ant/insert-phase.md +101 -0
  209. package/.claude/commands/ant/interpret.md +11 -0
  210. package/.claude/commands/ant/lay-eggs.md +167 -158
  211. package/.claude/commands/ant/maturity.md +22 -11
  212. package/.claude/commands/ant/memory-details.md +77 -0
  213. package/.claude/commands/ant/migrate-state.md +6 -0
  214. package/.claude/commands/ant/oracle.md +317 -62
  215. package/.claude/commands/ant/organize.md +10 -5
  216. package/.claude/commands/ant/patrol.md +620 -0
  217. package/.claude/commands/ant/pause-colony.md +8 -22
  218. package/.claude/commands/ant/phase.md +26 -37
  219. package/.claude/commands/ant/pheromones.md +156 -0
  220. package/.claude/commands/ant/plan.md +175 -52
  221. package/.claude/commands/ant/preferences.md +65 -0
  222. package/.claude/commands/ant/redirect.md +18 -0
  223. package/.claude/commands/ant/resume-colony.md +34 -20
  224. package/.claude/commands/ant/resume.md +51 -7
  225. package/.claude/commands/ant/run.md +195 -0
  226. package/.claude/commands/ant/seal.md +497 -78
  227. package/.claude/commands/ant/skill-create.md +286 -0
  228. package/.claude/commands/ant/status.md +127 -1
  229. package/.claude/commands/ant/swarm.md +11 -23
  230. package/.claude/commands/ant/tunnels.md +1 -0
  231. package/.claude/commands/ant/update.md +58 -135
  232. package/.claude/commands/ant/verify-castes.md +90 -42
  233. package/.claude/commands/ant/watch.md +1 -0
  234. package/.opencode/agents/aether-ambassador.md +1 -1
  235. package/.opencode/agents/aether-architect.md +133 -0
  236. package/.opencode/agents/aether-builder.md +3 -3
  237. package/.opencode/agents/aether-oracle.md +137 -0
  238. package/.opencode/agents/aether-queen.md +1 -1
  239. package/.opencode/agents/aether-route-setter.md +1 -1
  240. package/.opencode/agents/aether-scout.md +1 -1
  241. package/.opencode/agents/aether-surveyor-disciplines.md +6 -1
  242. package/.opencode/agents/aether-surveyor-nest.md +6 -1
  243. package/.opencode/agents/aether-surveyor-pathogens.md +6 -1
  244. package/.opencode/agents/aether-surveyor-provisions.md +6 -1
  245. package/.opencode/agents/aether-tracker.md +1 -1
  246. package/.opencode/agents/aether-watcher.md +1 -1
  247. package/.opencode/agents/aether-weaver.md +1 -1
  248. package/.opencode/commands/ant/archaeology.md +7 -14
  249. package/.opencode/commands/ant/build.md +54 -88
  250. package/.opencode/commands/ant/chaos.md +7 -24
  251. package/.opencode/commands/ant/colonize.md +8 -17
  252. package/.opencode/commands/ant/continue.md +595 -66
  253. package/.opencode/commands/ant/council.md +11 -22
  254. package/.opencode/commands/ant/data-clean.md +77 -0
  255. package/.opencode/commands/ant/dream.md +15 -17
  256. package/.opencode/commands/ant/entomb.md +28 -18
  257. package/.opencode/commands/ant/export-signals.md +54 -0
  258. package/.opencode/commands/ant/feedback.md +24 -5
  259. package/.opencode/commands/ant/flag.md +16 -4
  260. package/.opencode/commands/ant/flags.md +24 -10
  261. package/.opencode/commands/ant/focus.md +22 -5
  262. package/.opencode/commands/ant/help.md +41 -8
  263. package/.opencode/commands/ant/history.md +9 -0
  264. package/.opencode/commands/ant/import-signals.md +68 -0
  265. package/.opencode/commands/ant/init.md +365 -156
  266. package/.opencode/commands/ant/insert-phase.md +107 -0
  267. package/.opencode/commands/ant/interpret.md +16 -0
  268. package/.opencode/commands/ant/lay-eggs.md +184 -112
  269. package/.opencode/commands/ant/maturity.md +18 -2
  270. package/.opencode/commands/ant/memory-details.md +83 -0
  271. package/.opencode/commands/ant/migrate-state.md +12 -0
  272. package/.opencode/commands/ant/oracle.md +322 -67
  273. package/.opencode/commands/ant/organize.md +14 -12
  274. package/.opencode/commands/ant/patrol.md +626 -0
  275. package/.opencode/commands/ant/pause-colony.md +12 -29
  276. package/.opencode/commands/ant/phase.md +30 -40
  277. package/.opencode/commands/ant/pheromones.md +162 -0
  278. package/.opencode/commands/ant/plan.md +184 -56
  279. package/.opencode/commands/ant/preferences.md +71 -0
  280. package/.opencode/commands/ant/redirect.md +22 -5
  281. package/.opencode/commands/ant/resume-colony.md +38 -27
  282. package/.opencode/commands/ant/resume.md +71 -20
  283. package/.opencode/commands/ant/run.md +201 -0
  284. package/.opencode/commands/ant/seal.md +230 -25
  285. package/.opencode/commands/ant/skill-create.md +63 -0
  286. package/.opencode/commands/ant/status.md +124 -31
  287. package/.opencode/commands/ant/swarm.md +3 -345
  288. package/.opencode/commands/ant/tunnels.md +3 -9
  289. package/.opencode/commands/ant/update.md +63 -127
  290. package/.opencode/commands/ant/verify-castes.md +96 -42
  291. package/.opencode/commands/ant/watch.md +7 -0
  292. package/CHANGELOG.md +278 -1
  293. package/README.md +188 -340
  294. package/bin/cli.js +236 -429
  295. package/bin/generate-commands.js +186 -0
  296. package/bin/generate-commands.sh +128 -89
  297. package/bin/lib/spawn-logger.js +0 -15
  298. package/bin/lib/update-transaction.js +285 -35
  299. package/bin/npx-install.js +178 -0
  300. package/bin/validate-package.sh +85 -3
  301. package/package.json +7 -3
  302. package/.aether/CONTEXT.md +0 -160
  303. package/.aether/docs/QUEEN.md +0 -84
  304. package/.aether/exchange/colony-registry.xml +0 -11
  305. package/.aether/exchange/pheromones.xml +0 -87
  306. package/.aether/exchange/queen-wisdom.xml +0 -14
  307. package/.aether/model-profiles.yaml +0 -100
  308. package/.aether/utils/spawn-with-model.sh +0 -56
  309. package/bin/lib/model-profiles.js +0 -445
  310. package/bin/lib/model-verify.js +0 -288
  311. package/bin/lib/proxy-health.js +0 -253
  312. package/bin/lib/telemetry.js +0 -441
@@ -0,0 +1,1724 @@
1
+ ---
2
+ name: ant:continue
3
+ description: "➡️🐜🚪🐜➡️ Detect build completion, reconcile state, and advance to next phase"
4
+ ---
5
+
6
+ You are the **Queen Ant Colony**. Reconcile completed work and advance to the next phase.
7
+
8
+ ## Instructions
9
+
10
+ Parse `$ARGUMENTS`:
11
+ - If contains `--no-visual`: set `visual_mode = false` (visual is ON by default)
12
+ - Otherwise: set `visual_mode = true`
13
+
14
+ ### Step 1: Read State
15
+
16
+ Read `.aether/data/COLONY_STATE.json`.
17
+
18
+ **Auto-upgrade old state:**
19
+ If `version` field is missing, "1.0", or "2.0":
20
+ 1. Preserve: `goal`, `state`, `current_phase`, `plan.phases`
21
+ 2. Write upgraded v3.0 state (same structure as /ant:init but preserving data)
22
+ 3. Output: `State auto-upgraded to v3.0`
23
+ 4. Continue with command.
24
+
25
+ Extract: `goal`, `state`, `current_phase`, `plan.phases`, `errors`, `memory`, `events`, `build_started_at`.
26
+
27
+ **Validation:**
28
+ - If `goal: null` -> output "No colony initialized. Run /ant:init first." and stop.
29
+ - If `plan.phases` is empty -> output "No project plan. Run /ant:plan first." and stop.
30
+
31
+ ### Step 1.5: Load State and Show Resumption Context
32
+
33
+ Run using the Bash tool with description "Loading colony state...": `bash .aether/aether-utils.sh load-state`
34
+
35
+ If successful and goal is not null:
36
+ 1. Extract current_phase from state
37
+ 2. Get phase name from plan.phases[current_phase - 1].name (or "(unnamed)")
38
+ 3. Display brief resumption context:
39
+ ```
40
+ 🔄 Resuming: Phase X - Name
41
+ ```
42
+
43
+ If .aether/HANDOFF.md exists (detected in load-state output):
44
+ - Display "Resuming from paused session"
45
+ - Read .aether/HANDOFF.md for additional context
46
+ - Remove .aether/HANDOFF.md after display (cleanup)
47
+
48
+ Run using the Bash tool with description "Releasing colony lock...": `bash .aether/aether-utils.sh unload-state` to release lock.
49
+
50
+ **Error handling:**
51
+ - If E_FILE_NOT_FOUND: "No colony initialized. Run /ant:init first." and stop
52
+ - If validation error: Display error details with recovery suggestion and stop
53
+ - For other errors: Display generic error and suggest /ant:status for diagnostics
54
+
55
+ **Completion Detection:**
56
+
57
+ If `state == "EXECUTING"`:
58
+ 1. Check if `build_started_at` exists
59
+ 2. Look for phase completion evidence:
60
+ - Activity log entries showing task completion
61
+ - Files created/modified matching phase tasks
62
+ 3. If no evidence and build started > 30 min ago:
63
+ - Display "Stale EXECUTING state. Build may have been interrupted."
64
+ - Offer: continue anyway or rollback to git checkpoint
65
+ - Rollback procedure: `git stash list | grep "aether-checkpoint"` to find ref, then `git stash pop <ref>` to restore
66
+
67
+ If `state != "EXECUTING"`:
68
+ - Normal continue flow (no build to reconcile)
69
+
70
+ ### Step 1.5: Verification Loop Gate (MANDATORY)
71
+
72
+ **The Iron Law:** No phase advancement without fresh verification evidence.
73
+
74
+ Before ANY phase can advance, execute the 6-phase verification loop. See `.aether/docs/disciplines/verification-loop.md` for full reference.
75
+
76
+ #### 1. Command Resolution (Priority Chain)
77
+
78
+ Resolve each command (build, test, types, lint) using this priority chain. Stop at the first source that provides a value for each command:
79
+
80
+ **Priority 1 — CLAUDE.md (System Context):**
81
+ Check the CLAUDE.md instructions already loaded in your system context for explicit build, test, type-check, or lint commands. These are authoritative and override all other sources.
82
+
83
+ **Priority 2 — codebase.md `## Commands`:**
84
+ Read `.aether/data/codebase.md` and look for the `## Commands` section. Use any commands listed there for slots not yet filled by Priority 1.
85
+
86
+ **Priority 3 — Fallback Heuristic Table:**
87
+ For any commands still unresolved, check for these files in order, use first match:
88
+
89
+ | File | Build | Test | Types | Lint |
90
+ |------|-------|------|-------|------|
91
+ | `package.json` | `npm run build` | `npm test` | `npx tsc --noEmit` | `npm run lint` |
92
+ | `Cargo.toml` | `cargo build` | `cargo test` | (built-in) | `cargo clippy` |
93
+ | `go.mod` | `go build ./...` | `go test ./...` | `go vet ./...` | `golangci-lint run` |
94
+ | `pyproject.toml` | `python -m build` | `pytest` | `pyright .` | `ruff check .` |
95
+ | `Makefile` | `make build` | `make test` | (check targets) | `make lint` |
96
+
97
+ If no build system detected, skip build/test/type/lint checks but still verify success criteria.
98
+
99
+ #### 2. Run 6-Phase Verification Loop
100
+
101
+ Execute all applicable phases and capture output:
102
+
103
+ ```
104
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
105
+ 👁️🐜 V E R I F I C A T I O N L O O P
106
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
107
+ Phase {id} — Checking colony work...
108
+ ```
109
+
110
+ **Phase 1: Build Check** (if command exists):
111
+ Run using the Bash tool with description "Running build check...": `{build_command} 2>&1 | tail -30`
112
+ Record: exit code, any errors. **STOP if fails.**
113
+
114
+ **Phase 2: Type Check** (if command exists):
115
+ Run using the Bash tool with description "Running type check...": `{type_command} 2>&1 | head -30`
116
+ Record: error count. Report all type errors.
117
+
118
+ **Phase 3: Lint Check** (if command exists):
119
+ Run using the Bash tool with description "Running lint check...": `{lint_command} 2>&1 | head -30`
120
+ Record: warning count, error count.
121
+
122
+ **Phase 4: Test Check** (if command exists):
123
+ Run using the Bash tool with description "Running test suite...": `{test_command} 2>&1 | tail -50`
124
+ Record: pass count, fail count, exit code. **STOP if fails.**
125
+
126
+ **Coverage Check** (if coverage command exists):
127
+ Run using the Bash tool with description "Checking test coverage...": `{coverage_command} # e.g., npm run test:coverage`
128
+ Record: coverage percentage (target: 80%+ for new code)
129
+
130
+ #### Step 1.5.1: Probe Coverage Agent (Conditional)
131
+
132
+ **Test coverage improvement — runs when coverage < 80% AND tests pass.**
133
+
134
+ 1. **Check coverage threshold condition:**
135
+ - Coverage data is already available from Phase 4 coverage check
136
+ - If tests failed: Skip Probe silently (coverage data unreliable)
137
+ - If coverage_percent >= 80%: Skip Probe silently, continue to Phase 5
138
+ - If coverage_percent < 80% AND tests passed: Proceed to spawn Probe
139
+
140
+ 2. **If skipping Probe:**
141
+ ```
142
+ 🧪🐜 Probe: Coverage at {coverage_percent}% — {reason_for_skip}
143
+ ```
144
+ Continue to Phase 5: Secrets Scan.
145
+
146
+ 3. **If spawning Probe:**
147
+
148
+ a. Generate Probe name and dispatch:
149
+ Run using the Bash tool with description "Generating Probe name...": `probe_name=$(bash .aether/aether-utils.sh generate-ant-name "probe" | jq -r '.result') && bash .aether/aether-utils.sh spawn-log "Queen" "probe" "$probe_name" "Coverage improvement: ${coverage_percent}%" && echo "{\"name\":\"$probe_name\"}"`
150
+
151
+
152
+ c. Display: `🧪🐜 Probe {probe_name} spawning — Coverage at {coverage_percent}%, generating tests for uncovered paths...`
153
+
154
+ d. Determine uncovered files:
155
+ Run using the Bash tool with description "Getting modified source files...": `modified_source_files=$(git diff --name-only HEAD~1 2>/dev/null || git diff --name-only) && source_files=$(echo "$modified_source_files" | grep -v "\.test\." | grep -v "\.spec\." | grep -v "__tests__") && echo "$source_files"`
156
+
157
+ e. Spawn Probe agent:
158
+
159
+ Use the Task tool with subagent_type="aether-probe" (if available; otherwise use general-purpose and inject the Probe role from `.opencode/agents/aether-probe.md`):
160
+
161
+ ```xml
162
+ <mission>
163
+ Improve test coverage for uncovered code paths in the modified files.
164
+ </mission>
165
+
166
+ <work>
167
+ 1. Analyze the modified source files for uncovered branches and edge cases
168
+ 2. Identify which paths lack test coverage
169
+ 3. Generate test cases that exercise uncovered code paths
170
+ 4. Run the new tests to verify they pass
171
+ 5. Report coverage improvements and edge cases discovered
172
+ </work>
173
+
174
+ <context>
175
+ Current coverage: {coverage_percent}%
176
+ Target coverage: 80%
177
+ Modified source files: {modified_source_files}
178
+ </context>
179
+
180
+ <constraints>
181
+ - Test files ONLY — never modify source code
182
+ - Follow existing test conventions in the codebase
183
+ - Do NOT delete or modify existing tests
184
+ </constraints>
185
+
186
+ <output>
187
+ Provide JSON output matching this schema:
188
+ {
189
+ "ant_name": "your probe name",
190
+ "caste": "probe",
191
+ "status": "completed" | "failed" | "blocked",
192
+ "summary": "Brief summary of coverage improvements",
193
+ "coverage": {
194
+ "lines": 0,
195
+ "branches": 0,
196
+ "functions": 0
197
+ },
198
+ "tests_added": ["file1.test.js", "file2.test.js"],
199
+ "edge_cases_discovered": ["edge case 1", "edge case 2"],
200
+ "mutation_score": 0,
201
+ "weak_spots": [],
202
+ "blockers": []
203
+ }
204
+ </output>
205
+ ```
206
+
207
+ f. Parse Probe JSON output and log completion:
208
+ Extract: `tests_added`, `coverage.lines`, `coverage.branches`, `coverage.functions`, `edge_cases_discovered`, `mutation_score`
209
+
210
+ Run using the Bash tool with description "Logging Probe completion...": `bash .aether/aether-utils.sh spawn-complete "$probe_name" "completed" "{\"tests_added\":${#tests_added[@]},\"coverage\":{\"lines\":${coverage_lines},\"branches\":${coverage_branches},\"functions\":${coverage_functions}}}"`
211
+
212
+ g. Log findings to midden:
213
+ Run using the Bash tool with description "Logging Probe findings to midden...": `bash .aether/aether-utils.sh midden-write "coverage" "Probe generated tests, coverage: ${coverage_lines}%/${coverage_branches}%/${coverage_functions}%" "probe"`
214
+
215
+ If edge cases found:
216
+ Run using the Bash tool with description "Logging edge cases to midden...": `bash .aether/aether-utils.sh midden-write "edge_cases" "Found ${#edge_cases_discovered[@]} edge cases" "probe"`
217
+
218
+ 4. **NON-BLOCKING continuation:**
219
+ Display Probe findings summary:
220
+ ```
221
+ 🧪🐜 Probe complete — Findings logged to midden, continuing verification...
222
+ Tests added: {count}
223
+ Edge cases discovered: {count}
224
+ ```
225
+
226
+ **CRITICAL:** ALWAYS continue to Phase 5 (Secrets Scan) regardless of Probe results. Probe is strictly non-blocking — phase advancement continues even if Probe cannot improve coverage.
227
+
228
+ 5. **Record Probe status for verification report:**
229
+ Set `probe_status = "ACTIVE"` and store tests_added count and edge_cases count for the verification report.
230
+
231
+ **Phase 5: Secrets Scan** (basic grep-based secret detection):
232
+ Run using the Bash tool with description "Scanning for exposed secrets...": `grep -rn "sk-\|api_key\|password\s*=" --include="*.ts" --include="*.js" --include="*.py" src/ 2>/dev/null | head -10`
233
+ Run using the Bash tool with description "Scanning for debug artifacts...": `grep -rn "console\.log\|debugger" --include="*.ts" --include="*.tsx" --include="*.js" src/ 2>/dev/null | head -10`
234
+ Record: potential secrets (critical), debug artifacts (warning).
235
+
236
+ Note: Professional security scanning happens in Step 1.8 (Gatekeeper for CVEs) and Step 1.9 (Auditor for code quality).
237
+
238
+ **Phase 6: Diff Review**:
239
+ Run using the Bash tool with description "Reviewing file changes...": `git diff --stat`
240
+ Review changed files for unintended modifications.
241
+
242
+ **Success Criteria Check:**
243
+ Read phase success criteria from `plan.phases[current].success_criteria`.
244
+ For EACH criterion:
245
+ 1. Identify what proves it (file exists? test passes? output shows X?)
246
+ 2. Run the check
247
+ 3. Record evidence or gap
248
+
249
+ Display:
250
+ ```
251
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
252
+ 👁️🐜 V E R I F I C A T I O N R E P O R T
253
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
254
+
255
+ 🔨 Build [PASS/FAIL/SKIP]
256
+ 🔍 Types [PASS/FAIL/SKIP] (X errors)
257
+ 🧹 Lint [PASS/FAIL/SKIP] (X warnings)
258
+ 🧪 Tests [PASS/FAIL/SKIP] (X/Y passed)
259
+ Coverage {percent}% (target: 80%)
260
+ 🧪 Probe [ACTIVE/SKIP] (tests added: X, edge cases: Y)
261
+ 🔒 Secrets [PASS/FAIL] (X issues)
262
+ 📦 Gatekeeper [PASS/WARN/SKIP] (X critical, X high)
263
+ 👥 Auditor [PASS/FAIL] (score: X/100)
264
+ 📋 Diff [X files changed]
265
+
266
+ ──────────────────────────────────────────────────
267
+ 🐜 Success Criteria
268
+ ──────────────────────────────────────────────────
269
+ ✅ {criterion 1}: {specific evidence}
270
+ ✅ {criterion 2}: {specific evidence}
271
+ ❌ {criterion 3}: {what's missing}
272
+
273
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
274
+ Overall: READY / NOT READY
275
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
276
+ ```
277
+
278
+ #### 3. Gate Decision
279
+
280
+ **If NOT READY (any of: build fails, tests fail, critical security issues, success criteria unmet):**
281
+
282
+ ```
283
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
284
+ ⛔🐜 V E R I F I C A T I O N F A I L E D
285
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
286
+
287
+ Phase {id} cannot advance until issues are resolved.
288
+
289
+ 🚨 Issues Found:
290
+ {list each failure with specific evidence}
291
+
292
+ 🔧 Required Actions:
293
+ 1. Fix the issues listed above
294
+ 2. Run /ant:continue again to re-verify
295
+
296
+ The phase will NOT advance until verification passes.
297
+ ```
298
+
299
+ **CRITICAL:** Do NOT proceed to Step 2. Do NOT advance the phase.
300
+ Do NOT offer workarounds. Verification is mandatory.
301
+
302
+ Use AskUserQuestion to confirm they understand what needs to be fixed:
303
+ - Show the specific failures
304
+ - Ask if they want to fix now or need help
305
+
306
+ **If READY (all checks pass with evidence):**
307
+
308
+ ```
309
+ ✅🐜 VERIFICATION PASSED
310
+
311
+ All checks completed with evidence:
312
+ {list each check and its evidence}
313
+
314
+ Proceeding to gate checks...
315
+ ```
316
+
317
+ Continue to Step 1.6.
318
+
319
+ ### Step 1.6: Spawn Enforcement Gate (MANDATORY)
320
+
321
+ **The Iron Law:** No phase advancement without worker spawning for non-trivial phases.
322
+
323
+ Read `.aether/data/spawn-tree.txt` to count spawns for this phase.
324
+
325
+ Run using the Bash tool with description "Verifying spawn requirements...": `spawn_count=$(grep -c "spawned" .aether/data/spawn-tree.txt 2>/dev/null || echo "0") && watcher_count=$(grep -c "watcher" .aether/data/spawn-tree.txt 2>/dev/null || echo "0") && echo "{\"spawn_count\": $spawn_count, \"watcher_count\": $watcher_count}"`
326
+
327
+ **HARD REJECTION - If spawn_count == 0 and phase had 3+ tasks:**
328
+
329
+ ```
330
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
331
+ ⛔🐜 S P A W N G A T E F A I L E D
332
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
333
+
334
+ This phase had {task_count} tasks but spawn_count: 0
335
+ The Prime Worker violated the spawn protocol.
336
+
337
+ 🐜 The colony requires actual parallelism:
338
+ - Prime Worker MUST spawn specialists for non-trivial work
339
+ - A single agent doing everything is NOT a colony
340
+ - "Justifications" for not spawning are not accepted
341
+
342
+ 🔧 Required Actions:
343
+ 1. Run /ant:build {phase} again
344
+ 2. Prime Worker MUST spawn at least 1 specialist
345
+ 3. Re-run /ant:continue after spawns complete
346
+
347
+ The phase will NOT advance until spawning occurs.
348
+ ```
349
+
350
+ **CRITICAL:** Do NOT proceed to Step 1.7. Do NOT advance the phase.
351
+ Log the violation:
352
+ ```bash
353
+ bash .aether/aether-utils.sh activity-log "BLOCKED" "colony" "Spawn gate failed: {task_count} tasks, 0 spawns"
354
+ bash .aether/aether-utils.sh error-flag-pattern "no-spawn-violation" "Prime Worker completed phase without spawning specialists" "critical"
355
+ ```
356
+
357
+ **HARD REJECTION - If watcher_count == 0 (no testing separation):**
358
+
359
+ ```
360
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
361
+ ⛔👁️🐜 W A T C H E R G A T E F A I L E D
362
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
363
+
364
+ No Watcher ant was spawned for testing/verification.
365
+ Testing MUST be performed by a separate agent, not the builder.
366
+
367
+ 🐜 Why this matters:
368
+ - Builders verify their own work = confirmation bias
369
+ - Independent Watchers catch bugs builders miss
370
+ - "Build passing" ≠ "App working"
371
+
372
+ 🔧 Required Actions:
373
+ 1. Run /ant:build {phase} again
374
+ 2. Prime Worker MUST spawn at least 1 Watcher
375
+ 3. Watcher must independently verify the work
376
+
377
+ The phase will NOT advance until a Watcher validates.
378
+ ```
379
+
380
+ **CRITICAL:** Do NOT proceed. Log the violation.
381
+
382
+ **If spawn_count >= 1 AND watcher_count >= 1:**
383
+
384
+ ```
385
+ ✅🐜 SPAWN GATE PASSED — {spawn_count} workers | {watcher_count} watchers
386
+ ```
387
+
388
+ Continue to Step 1.7.
389
+
390
+ ### Step 1.7: Anti-Pattern Gate
391
+
392
+ Scan all modified/created files for known anti-patterns. This catches recurring bugs before they reach production.
393
+
394
+ For each file, run using the Bash tool with description "Scanning for anti-patterns...": `bash .aether/aether-utils.sh check-antipattern "{file_path}"`
395
+
396
+ Run for each file in `files_created` and `files_modified` from Prime Worker output.
397
+
398
+ **Anti-Pattern Report:**
399
+
400
+ ```
401
+ 🔍🐜 Anti-Pattern Scan — {count} files scanned
402
+
403
+ {if critical issues:}
404
+ 🛑 CRITICAL (must fix):
405
+ {list each with file:line and description}
406
+
407
+ {if warnings:}
408
+ ⚠️ WARNINGS:
409
+ {list each with file:line and description}
410
+
411
+ {if clean:}
412
+ ✅🐜 No anti-patterns detected
413
+ ```
414
+
415
+ **CRITICAL issues block phase advancement:**
416
+ - Swift didSet infinite recursion
417
+ - Exposed secrets/credentials
418
+ - SQL injection patterns
419
+ - Known crash patterns
420
+
421
+ **WARNINGS are logged but don't block:**
422
+ - TypeScript `any` usage
423
+ - Console.log in production code
424
+ - TODO/FIXME comments
425
+
426
+ If CRITICAL issues found, display:
427
+
428
+ ```
429
+ ⛔🐜 ANTI-PATTERN GATE FAILED
430
+
431
+ Critical anti-patterns detected:
432
+ {list issues with file paths}
433
+
434
+ Run /ant:build {phase} again after fixing.
435
+ ```
436
+
437
+ Do NOT proceed to Step 2.
438
+
439
+ If no CRITICAL issues, continue to Step 1.7.1.
440
+
441
+ ### Step 1.7.1: Proactive Refactoring Gate (Conditional)
442
+
443
+ **Complexity-based refactoring — runs when code exceeds maintainability thresholds.**
444
+
445
+ 1. **Get modified/created files from recent work:**
446
+ Run using the Bash tool with description "Getting modified files for complexity check...": `modified_files=$(git diff --name-only HEAD~1 2>/dev/null || git diff --name-only) && echo "$modified_files"`
447
+
448
+ 2. **Check complexity thresholds for each file:**
449
+
450
+ For each file, check:
451
+ - Line count > 300 lines
452
+ - Long functions > 50 lines (simplified heuristic)
453
+ - Directory density > 10 new files
454
+
455
+ Run using the Bash tool with description "Checking complexity thresholds...":
456
+ ```bash
457
+ modified_files=$(git diff --name-only HEAD~1 2>/dev/null || git diff --name-only)
458
+
459
+ complexity_trigger=false
460
+ files_needing_refactor=""
461
+
462
+ for file in $modified_files; do
463
+ if [[ -f "$file" ]]; then
464
+ # Check line count
465
+ line_count=$(wc -l < "$file" 2>/dev/null || echo "0")
466
+ if [[ "$line_count" -gt 300 ]]; then
467
+ complexity_trigger=true
468
+ files_needing_refactor="$files_needing_refactor $file"
469
+ continue
470
+ fi
471
+
472
+ # Check for long functions (simplified heuristic)
473
+ long_funcs=$(grep -c "^[[:space:]]*[a-zA-Z_][a-zA-Z0-9_]*[[:space:]]*(" "$file" 2>/dev/null || echo "0")
474
+ if [[ "$long_funcs" -gt 50 ]]; then
475
+ complexity_trigger=true
476
+ files_needing_refactor="$files_needing_refactor $file"
477
+ fi
478
+ fi
479
+ done
480
+
481
+ # Check directory density
482
+ if [[ -n "$modified_files" ]]; then
483
+ dir_counts=$(echo "$modified_files" | xargs -I {} dirname {} 2>/dev/null | sort | uniq -c | sort -rn)
484
+ high_density_dir=$(echo "$dir_counts" | awk '$1 > 10 {print $2}' | head -1)
485
+ if [[ -n "$high_density_dir" ]]; then
486
+ complexity_trigger=true
487
+ fi
488
+ fi
489
+
490
+ echo "{\"complexity_trigger\": \"$complexity_trigger\", \"files_needing_refactor\": \"$files_needing_refactor\"}"
491
+ ```
492
+
493
+ 3. **If complexity thresholds NOT exceeded:**
494
+ ```
495
+ 🔄🐜 Weaver: Complexity thresholds not exceeded — skipping proactive refactoring
496
+ ```
497
+ Continue to Step 1.8.
498
+
499
+ 4. **If complexity thresholds exceeded:**
500
+
501
+ a. **Establish test baseline before refactoring:**
502
+ Run using the Bash tool with description "Establishing test baseline...": `test_output_before=$(npm test 2>&1 || echo "TEST_FAILED") && tests_passing_before=$(echo "$test_output_before" | grep -oE '[0-9]+ passing' | grep -oE '[0-9]+' || echo "0") && echo "Baseline: $tests_passing_before tests passing"`
503
+
504
+ b. **Generate Weaver name and dispatch:**
505
+ Run using the Bash tool with description "Generating Weaver name...": `weaver_name=$(bash .aether/aether-utils.sh generate-ant-name "weaver" | jq -r '.result') && bash .aether/aether-utils.sh spawn-log "Queen" "weaver" "$weaver_name" "Proactive refactoring" && echo "{\"name\":\"$weaver_name\"}"`
506
+
507
+
508
+ d. **Display:** `🔄🐜 Weaver {weaver_name} spawning — Refactoring complex code...`
509
+
510
+ e. **Spawn Weaver agent:**
511
+
512
+ Use the Task tool with subagent_type="aether-weaver" (if available; otherwise use general-purpose and inject the Weaver role from `.opencode/agents/aether-weaver.md`):
513
+
514
+ ```xml
515
+ <mission>
516
+ Refactor complex code to improve maintainability while preserving behavior.
517
+ </mission>
518
+
519
+ <work>
520
+ 1. Analyze target files for complexity issues
521
+ 2. Plan incremental refactoring steps
522
+ 3. Execute one step at a time
523
+ 4. Run tests after each step
524
+ 5. If tests pass, continue; if fail, revert and try smaller step
525
+ 6. Report all changes made
526
+ </work>
527
+
528
+ <context>
529
+ Target Files: {files_needing_refactor}
530
+ Test Baseline: {tests_passing_before} tests passing (MUST maintain after refactor)
531
+
532
+ Refactoring Guidelines:
533
+ - Extract methods/functions over 50 lines
534
+ - Split files over 300 lines
535
+ - Remove duplication (DRY)
536
+ - Improve naming for clarity
537
+ - Apply Single Responsibility Principle
538
+ </context>
539
+
540
+ <constraints>
541
+ - NEVER change behavior — only structure
542
+ - Run tests after each refactoring step
543
+ - If tests fail, revert immediately
544
+ - Do NOT modify test expectations to make tests pass
545
+ - Do NOT modify .aether/ system files
546
+ </constraints>
547
+
548
+ <output>
549
+ Provide JSON output matching this schema:
550
+ {
551
+ "ant_name": "your weaver name",
552
+ "caste": "weaver",
553
+ "status": "completed" | "failed" | "blocked",
554
+ "summary": "Brief summary of refactoring",
555
+ "files_refactored": [],
556
+ "complexity_before": 0,
557
+ "complexity_after": 0,
558
+ "duplication_eliminated": 0,
559
+ "methods_extracted": [],
560
+ "patterns_applied": [],
561
+ "tests_all_passing": true,
562
+ "next_recommendations": [],
563
+ "blockers": []
564
+ }
565
+ </output>
566
+ ```
567
+
568
+ f. **Parse Weaver JSON output and verify tests:**
569
+ Extract: `files_refactored`, `tests_all_passing`, `complexity_before`, `complexity_after`
570
+
571
+ Run using the Bash tool with description "Verifying tests after refactoring...":
572
+ ```bash
573
+ test_output_after=$(npm test 2>&1 || echo "TEST_FAILED")
574
+ tests_passing_after=$(echo "$test_output_after" | grep -oE '[0-9]+ passing' | grep -oE '[0-9]+' || echo "0")
575
+
576
+ if [[ "$tests_passing_after" -lt "$tests_passing_before" ]]; then
577
+ echo "REVERT_NEEDED: Tests failed after refactoring"
578
+ git checkout -- $files_needing_refactor
579
+ weaver_status="reverted"
580
+ else
581
+ echo "PASSING: Tests passing after refactoring ($tests_passing_after)"
582
+ weaver_status="completed"
583
+ fi
584
+ ```
585
+
586
+ g. **Log completion:**
587
+ Run using the Bash tool with description "Logging Weaver completion...": `bash .aether/aether-utils.sh spawn-complete "$weaver_name" "$weaver_status" "Refactoring $weaver_status"`
588
+
589
+
590
+ i. **Log to midden:**
591
+ Run using the Bash tool with description "Logging refactoring activity to midden...": `bash .aether/aether-utils.sh midden-write "refactoring" "Weaver refactored files, complexity before/after: ${complexity_before}/${complexity_after}" "weaver"`
592
+
593
+ 5. **Display completion:**
594
+ ```
595
+ 🔄🐜 Weaver: Proactive refactoring {weaver_status}
596
+ Files refactored: {count} | Complexity: {before} → {after}
597
+ ```
598
+
599
+ 6. **NON-BLOCKING continuation:**
600
+ The Weaver step is NON-BLOCKING — continue to Step 1.8 regardless of refactoring results.
601
+
602
+ Continue to Step 1.8.
603
+
604
+ ### Step 1.8: Gatekeeper Security Gate (Conditional)
605
+
606
+ **Supply chain security audit — runs only when package.json exists.**
607
+
608
+ First, check for package.json:
609
+ Run using the Bash tool with description "Checking for package.json...": `test -f package.json && echo "exists" || echo "missing"`
610
+
611
+ **If package.json is missing:**
612
+ ```
613
+ 📦🐜 Gatekeeper: No package.json found — skipping supply chain audit
614
+ ```
615
+ Continue to Step 1.9.
616
+
617
+ **If package.json exists:**
618
+
619
+ 1. Generate Gatekeeper name and log spawn:
620
+ Run using the Bash tool with description "Generating Gatekeeper name...": `gatekeeper_name=$(bash .aether/aether-utils.sh generate-ant-name "gatekeeper" | jq -r '.result') && bash .aether/aether-utils.sh spawn-log "Queen" "gatekeeper" "$gatekeeper_name" "Supply chain security audit" && echo "{\"name\":\"$gatekeeper_name\"}"`
621
+
622
+ 2. Display: `📦🐜 Gatekeeper {name} spawning — Scanning dependencies for CVEs and license compliance...`
623
+
624
+ 4. Spawn Gatekeeper agent:
625
+
626
+ Use the Task tool with subagent_type="aether-gatekeeper" (if available; otherwise use general-purpose and inject the Gatekeeper role from `.opencode/agents/aether-gatekeeper.md`):
627
+
628
+ ```xml
629
+ <mission>
630
+ Perform supply chain security audit on this codebase.
631
+ </mission>
632
+
633
+ <work>
634
+ 1. Inventory all dependencies from package.json
635
+ 2. Scan for known CVEs using npm audit or equivalent
636
+ 3. Check license compliance for all packages
637
+ 4. Assess dependency health (outdated, deprecated, maintenance status)
638
+ 5. Report findings with severity levels
639
+ </work>
640
+
641
+ <output>
642
+ Provide JSON output matching this schema:
643
+ {
644
+ "ant_name": "your gatekeeper name",
645
+ "caste": "gatekeeper",
646
+ "status": "completed" | "failed" | "blocked",
647
+ "summary": "Brief summary of findings",
648
+ "security": {
649
+ "critical": 0,
650
+ "high": 0,
651
+ "medium": 0,
652
+ "low": 0
653
+ },
654
+ "licenses": {},
655
+ "outdated_packages": [],
656
+ "recommendations": [],
657
+ "blockers": []
658
+ }
659
+ </output>
660
+ ```
661
+
662
+ 5. Parse Gatekeeper JSON output and log completion:
663
+ Extract: `security.critical`, `security.high`, `status`
664
+
665
+ Run using the Bash tool with description "Logging Gatekeeper completion...": `bash .aether/aether-utils.sh spawn-complete "$gatekeeper_name" "completed" "{\"security\":{\"critical\":$critical_count,\"high\":$high_count}}"`
666
+
667
+ **Gate Decision Logic:**
668
+
669
+ - **If `security.critical > 0`:**
670
+ ```
671
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
672
+ ⛔📦🐜 G A T E K E E P E R G A T E F A I L E D
673
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
674
+
675
+ Critical security vulnerabilities detected: {critical_count}
676
+
677
+ 🚨 CRITICAL CVEs must be fixed before phase advancement.
678
+
679
+ 🔧 Required Actions:
680
+ 1. Run `npm audit` to see full details
681
+ 2. Fix or update vulnerable dependencies
682
+ 3. Run /ant:continue again after resolving
683
+
684
+ The phase will NOT advance with critical CVEs.
685
+ ```
686
+ **CRITICAL:** Do NOT proceed to Step 1.9. Stop here.
687
+
688
+ - **If `security.high > 0`:**
689
+ ```
690
+ ⚠️📦🐜 Gatekeeper: {high_count} high-severity issues found
691
+
692
+ Security warnings logged to midden for later review.
693
+ Proceeding with caution...
694
+ ```
695
+ Run using the Bash tool with description "Logging high-severity warnings...": `bash .aether/aether-utils.sh midden-write "security" "High CVEs found: $high_count" "gatekeeper"`
696
+ Continue to Step 1.9.
697
+
698
+ - **If clean (no critical or high):**
699
+ ```
700
+ ✅📦🐜 Gatekeeper: No critical security issues found
701
+ ```
702
+ Continue to Step 1.9.
703
+
704
+ ### Step 1.9: Auditor Quality Gate (MANDATORY)
705
+
706
+ **Code quality audit — runs on every `/ant:continue` for consistent coverage.**
707
+
708
+ 1. Generate Auditor name and log spawn:
709
+ Run using the Bash tool with description "Generating Auditor name...": `auditor_name=$(bash .aether/aether-utils.sh generate-ant-name "auditor" | jq -r '.result') && bash .aether/aether-utils.sh spawn-log "Queen" "auditor" "$auditor_name" "Code quality audit" && echo "{\"name\":\"$auditor_name\"}"`
710
+
711
+ 2. Display: `👥🐜 Auditor {name} spawning — Reviewing code with multi-lens analysis...`
712
+
713
+ 4. Get modified files for audit context:
714
+ Run using the Bash tool with description "Getting modified files...": `modified_files=$(git diff --name-only HEAD~1 2>/dev/null || git diff --name-only) && echo "$modified_files"`
715
+
716
+ 5. Spawn Auditor agent:
717
+
718
+ Use the Task tool with subagent_type="aether-auditor" (if available; otherwise use general-purpose and inject the Auditor role from `.opencode/agents/aether-auditor.md`):
719
+
720
+ ```xml
721
+ <mission>
722
+ Perform comprehensive code quality audit on this codebase.
723
+ </mission>
724
+
725
+ <work>
726
+ 1. Review all modified files from the recent commit(s)
727
+ 2. Apply all 4 audit lenses: security, performance, quality, maintainability
728
+ 3. Score each finding by severity (CRITICAL/HIGH/MEDIUM/LOW/INFO)
729
+ 4. Calculate overall quality score (0-100)
730
+ 5. Document specific issues with file:line references and fix suggestions
731
+ </work>
732
+
733
+ <context>
734
+ Phase: {current_phase}
735
+ Modified files: {modified_files}
736
+ </context>
737
+
738
+ <output>
739
+ Provide JSON output matching this schema:
740
+ {
741
+ "ant_name": "your auditor name",
742
+ "caste": "auditor",
743
+ "status": "completed" | "failed" | "blocked",
744
+ "summary": "Brief summary of findings",
745
+ "dimensions_audited": ["security", "performance", "quality", "maintainability"],
746
+ "findings": {
747
+ "critical": 0,
748
+ "high": 0,
749
+ "medium": 0,
750
+ "low": 0,
751
+ "info": 0
752
+ },
753
+ "issues": [
754
+ {"severity": "HIGH", "location": "file:line", "issue": "description", "fix": "suggestion"}
755
+ ],
756
+ "overall_score": 75,
757
+ "recommendation": "Top priority fix",
758
+ "blockers": []
759
+ }
760
+ </output>
761
+ ```
762
+
763
+ 6. Parse Auditor JSON output and log completion:
764
+ Extract: `findings.critical`, `findings.high`, `findings.medium`, `findings.low`, `findings.info`, `overall_score`, `dimensions_audited`
765
+
766
+ Run using the Bash tool with description "Logging Auditor completion...": `bash .aether/aether-utils.sh spawn-complete "$auditor_name" "completed" "{\"findings\":{\"critical\":$critical_count,\"high\":$high_count,\"medium\":$medium_count,\"low\":$low_count,\"info\":$info_count},\"score\":$overall_score}"`
767
+
768
+ **Gate Decision Logic:**
769
+
770
+ - **If `findings.critical > 0`:**
771
+ ```
772
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
773
+ ⛔👥🐜 A U D I T O R G A T E F A I L E D
774
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
775
+
776
+ Critical code quality issues detected: {critical_count}
777
+
778
+ 🚨 CRITICAL findings must be fixed before phase advancement.
779
+
780
+ 🔧 Required Actions:
781
+ 1. Review the critical issues listed below
782
+ 2. Fix each critical finding
783
+ 3. Run /ant:continue again after resolving
784
+
785
+ Critical Findings:
786
+ {list each critical finding with file:line and description}
787
+
788
+ The phase will NOT advance with critical quality issues.
789
+ ```
790
+ Run using the Bash tool with description "Logging critical quality block...": `bash .aether/aether-utils.sh error-flag-pattern "auditor-critical-findings" "$critical_count critical quality issues found" "critical"`
791
+ **CRITICAL:** Do NOT proceed to Step 1.10. Stop here.
792
+
793
+ - **Else if `overall_score < 60`:**
794
+ ```
795
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
796
+ ⛔👥🐜 A U D I T O R G A T E F A I L E D
797
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
798
+
799
+ Code quality score below threshold: {overall_score}/100 (threshold: 60)
800
+
801
+ 🚨 Quality score must reach 60+ before phase advancement.
802
+
803
+ 🔧 Required Actions:
804
+ 1. Address the top issues preventing score improvement:
805
+ {list top 3-5 issues with severity and location}
806
+ 2. Focus on HIGH severity items first
807
+ 3. Run /ant:continue again after improving quality
808
+
809
+ The phase will NOT advance with quality score below 60.
810
+ ```
811
+ Run using the Bash tool with description "Logging quality score block...": `bash .aether/aether-utils.sh error-flag-pattern "auditor-quality-score" "Score $overall_score below threshold 60" "critical"`
812
+ **CRITICAL:** Do NOT proceed to Step 1.10. Stop here.
813
+
814
+ - **Else if `findings.high > 0`:**
815
+ ```
816
+ ⚠️👥🐜 Auditor: Quality score {overall_score}/100 — PASSED with warnings
817
+
818
+ {high_count} high-severity quality issues found:
819
+ {list high findings}
820
+
821
+ Quality warnings logged to midden for later review.
822
+ Proceeding with caution...
823
+ ```
824
+ Run using the Bash tool with description "Logging high-quality warnings...": `bash .aether/aether-utils.sh midden-write "quality" "High severity issues: $high_count (score: $overall_score)" "auditor"`
825
+ Continue to Step 1.10.
826
+
827
+ - **If clean (score >= 60, no critical):**
828
+ ```
829
+ ✅👥🐜 Auditor: Quality score {overall_score}/100 — PASSED
830
+ ```
831
+ Continue to Step 1.10.
832
+
833
+ ### Step 1.10: TDD Evidence Gate (MANDATORY)
834
+
835
+ **The Iron Law:** No TDD claims without actual test files.
836
+
837
+ If Prime Worker reported TDD metrics (tests_added, tests_total, coverage_percent), verify test files exist:
838
+
839
+ Run using the Bash tool with description "Locating test files...": `find . -name "*.test.*" -o -name "*_test.*" -o -name "*Tests.swift" -o -name "test_*.py" 2>/dev/null | head -10`
840
+
841
+ **If Prime Worker claimed tests_added > 0 but no test files found:**
842
+
843
+ ```
844
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
845
+ ⛔🧪🐜 T D D G A T E F A I L E D
846
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
847
+
848
+ Prime Worker claimed:
849
+ tests_added: {claimed_count}
850
+ tests_total: {claimed_total}
851
+ coverage: {claimed_coverage}%
852
+
853
+ But no test files were found in the codebase.
854
+
855
+ 🚨 CRITICAL violation — fabricated TDD metrics.
856
+
857
+ 🔧 Required Actions:
858
+ 1. Run /ant:build {phase} again
859
+ 2. Actually write test files (not just claim them)
860
+ 3. Tests must exist and be runnable
861
+
862
+ The phase will NOT advance with fabricated metrics.
863
+ ```
864
+
865
+ **CRITICAL:** Do NOT proceed. Log the violation:
866
+ ```bash
867
+ bash .aether/aether-utils.sh error-flag-pattern "fabricated-tdd" "Prime Worker reported TDD metrics without creating test files" "critical"
868
+ ```
869
+
870
+ **If tests_added == 0 or test files exist matching claims:**
871
+
872
+ Continue to Step 1.11.
873
+
874
+ ### Step 1.11: Runtime Verification Gate (MANDATORY)
875
+
876
+ **The Iron Law:** Build passing ≠ App working.
877
+
878
+ Before advancing, the user must confirm the application actually runs.
879
+
880
+ Use AskUserQuestion:
881
+
882
+ ```
883
+ ──────────────────────────────────────────────────
884
+ 🐜 Runtime Verification Required
885
+ ──────────────────────────────────────────────────
886
+
887
+ Build checks passed — but does the app actually work?
888
+
889
+ Have you tested the application at runtime?
890
+ ```
891
+
892
+ Options:
893
+ 1. **Yes, tested and working** - App runs correctly, features work
894
+ 2. **Yes, tested but has issues** - App runs but has bugs (describe)
895
+ 3. **No, haven't tested yet** - Need to test before continuing
896
+ 4. **Skip (not applicable)** - No runnable app in this phase (e.g., library code)
897
+
898
+ **If "Yes, tested and working":**
899
+ ```
900
+ ✅🐜 RUNTIME VERIFIED — User confirmed app works.
901
+ ```
902
+ Continue to Step 1.12.
903
+
904
+ **If "Yes, tested but has issues":**
905
+ ```
906
+ ⛔🐜 RUNTIME GATE FAILED — User reported issues.
907
+
908
+ Please describe the issues so they can be addressed:
909
+ ```
910
+
911
+ Use AskUserQuestion to get issue details. Log to errors.records:
912
+ ```bash
913
+ bash .aether/aether-utils.sh error-add "runtime" "critical" "{user_description}" {phase}
914
+ ```
915
+
916
+ Do NOT proceed to Step 2.
917
+
918
+ **If "No, haven't tested yet":**
919
+ ```
920
+ ⏸️🐜 RUNTIME PENDING — Test the app, then run /ant:continue again.
921
+
922
+ - [ ] App launches without crashing
923
+ - [ ] Core features work as expected
924
+ - [ ] UI responds to user interaction
925
+ - [ ] No freezes or hangs
926
+ ```
927
+
928
+ Do NOT proceed to Step 2.
929
+
930
+ **If "Skip (not applicable)":**
931
+
932
+ Only valid for phases that don't produce runnable code (e.g., documentation, config files, library code with no entry point).
933
+
934
+ ```
935
+ ⏭️ RUNTIME CHECK SKIPPED
936
+
937
+ User indicated no runnable app for this phase.
938
+ Proceeding to phase advancement.
939
+ ```
940
+
941
+ Continue to Step 1.12.
942
+
943
+ ### Step 1.12: Flags Gate (MANDATORY)
944
+
945
+ **The Iron Law:** No phase advancement with unresolved blockers.
946
+
947
+ First, auto-resolve any flags eligible for resolution now that verification has passed:
948
+ Run using the Bash tool with description "Auto-resolving flags...": `bash .aether/aether-utils.sh flag-auto-resolve "build_pass"`
949
+
950
+ Then check for remaining blocking flags:
951
+ Run using the Bash tool with description "Checking for blockers...": `bash .aether/aether-utils.sh flag-check-blockers {current_phase}`
952
+
953
+ Parse result for `blockers`, `issues`, and `notes` counts.
954
+
955
+ **If blockers > 0:**
956
+
957
+ ```
958
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
959
+ ⛔🚩🐜 F L A G S G A T E F A I L E D
960
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
961
+
962
+ {blockers} blocker(s) must be resolved first.
963
+
964
+ 🚩 Active Blockers:
965
+ {list each blocker flag with ID, title, and description}
966
+
967
+ 🔧 Required Actions:
968
+ 1. Fix the issues described in each blocker
969
+ 2. Resolve flags: /ant:flags --resolve {flag_id} "resolution message"
970
+ 3. Run /ant:continue again after resolving all blockers
971
+ ```
972
+
973
+ **CRITICAL:** Do NOT proceed to Step 2. Do NOT advance the phase.
974
+
975
+ **If blockers == 0 but issues > 0:**
976
+
977
+ ```
978
+ ⚠️🐜 FLAGS: {issues} issue(s) noted (non-blocking)
979
+
980
+ {list each issue flag}
981
+
982
+ Use /ant:flags to review.
983
+ ```
984
+
985
+ Continue to Step 2.
986
+
987
+ **If all clear (no blockers or issues):**
988
+
989
+ ```
990
+ ✅🐜 FLAGS GATE PASSED — No blockers.
991
+ ```
992
+
993
+ Continue to Step 2.
994
+
995
+ ### Step 2: Update State
996
+
997
+ Find current phase in `plan.phases`.
998
+ Determine next phase (`current_phase + 1`).
999
+
1000
+ **If no next phase (all complete):** Skip to Step 2.4 (commit suggestion), then Step 2.7 (completion).
1001
+
1002
+ Update COLONY_STATE.json:
1003
+
1004
+ 1. **Mark current phase completed:**
1005
+ - Set `plan.phases[current].status` to `"completed"`
1006
+ - Set all tasks in phase to `"completed"`
1007
+
1008
+ 2. **Extract learnings (with validation status):**
1009
+
1010
+ **CRITICAL: Learnings start as HYPOTHESES until verified.**
1011
+
1012
+ A learning is only "validated" if:
1013
+ - The code was actually run and tested
1014
+ - The feature works in practice, not just in theory
1015
+ - User has confirmed the behavior
1016
+
1017
+ Append to `memory.phase_learnings`:
1018
+ ```json
1019
+ {
1020
+ "id": "learning_<unix_timestamp>",
1021
+ "phase": <phase_number>,
1022
+ "phase_name": "<name>",
1023
+ "learnings": [
1024
+ {
1025
+ "claim": "<specific actionable learning>",
1026
+ "status": "hypothesis",
1027
+ "tested": false,
1028
+ "evidence": "<what observation led to this>",
1029
+ "disproven_by": null
1030
+ }
1031
+ ],
1032
+ "timestamp": "<ISO-8601>"
1033
+ }
1034
+ ```
1035
+
1036
+ **Status values:**
1037
+ - `hypothesis` - Recorded but not verified (DEFAULT)
1038
+ - `validated` - Tested and confirmed working
1039
+ - `disproven` - Found to be incorrect
1040
+
1041
+ **Do NOT record a learning if:**
1042
+ - It wasn't actually tested
1043
+ - It's stating the obvious
1044
+ - There's no evidence it works
1045
+
1046
+ 2.5. **Capture learnings through memory pipeline:**
1047
+
1048
+ For each learning extracted, run the memory pipeline (observation + auto-pheromone + auto-promotion check).
1049
+
1050
+ Run using the Bash tool with description "Recording learning observations...":
1051
+ ```bash
1052
+ # Get learnings from the current phase
1053
+ current_phase_learnings=$(jq -r --argjson phase "$current_phase" '.memory.phase_learnings[] | select(.phase == $phase)' .aether/data/COLONY_STATE.json 2>/dev/null || echo "")
1054
+
1055
+ if [[ -n "$current_phase_learnings" ]]; then
1056
+ echo "$current_phase_learnings" | jq -r '.learnings[]?.claim // empty' 2>/dev/null | while read -r claim; do
1057
+ if [[ -n "$claim" ]]; then
1058
+ bash .aether/aether-utils.sh memory-capture "learning" "$claim" "pattern" "worker:continue"
1059
+ fi
1060
+ done
1061
+ echo "Recorded observations for threshold tracking"
1062
+ else
1063
+ echo "No learnings to record"
1064
+ fi
1065
+ ```
1066
+
1067
+ This records each learning in `learning-observations.json` with:
1068
+ - Content hash for deduplication (same claim across phases increments count)
1069
+ - Observation count (increments if seen before)
1070
+ - Colony name for cross-colony tracking
1071
+
1072
+ **memory-capture behavior (per learning):**
1073
+ - **Pheromone:** Emits ONE FEEDBACK pheromone per captured learning (emitted here, not again in Step 2.1a)
1074
+ - **Auto-promotion:** Attempts promotion via `learning-promote-auto` using **higher thresholds** (philosophy: 3, pattern/stack/redirect/failure: 2, decree: 0) — only promotes if high-confidence recurrence detected
1075
+ - **Does NOT perform final promotion** — high-threshold auto-promotion is opportunistic; final promotion happens in Step 2.1.5
1076
+
1077
+ **Step 2.1a vs this step:** Step 2.1a emits ONE summary FEEDBACK for the entire phase outcome (different purpose); this step emits per-learning FEEDBACK for each captured observation (captures the individual learning).
1078
+
1079
+ **Step 2.1.5 relationship:** Step 2.1.5 uses **lower thresholds** (all types: 1, decree: 0) to generate promotion proposals and presents them via tick-to-approve UX (`learning-check-promotion` + `learning-approve-proposals`). The higher thresholds here mean auto-promotion only fires for well-established patterns; most promotions go through Step 2.1.5's review flow.
1080
+
1081
+ 3. **Extract instincts from patterns:**
1082
+
1083
+ Read activity.log for patterns from this phase's build.
1084
+
1085
+ For each pattern observed (success, error_resolution, user_feedback):
1086
+
1087
+ **If pattern matches existing instinct:**
1088
+ - Update confidence: +0.1 for success outcome, -0.1 for failure
1089
+ - Increment applications count
1090
+ - Update last_applied timestamp
1091
+
1092
+ **If new pattern:**
1093
+ - Create new instinct with initial confidence:
1094
+ - success: 0.7 (base; calibrate with observation count)
1095
+ - error_resolution: 0.8
1096
+ - user_feedback: 0.9
1097
+ - When a learning has observation_count data in learning-observations.json, use formula: min(0.7 + (count-1)*0.05, 0.9) to override the base value.
1098
+
1099
+ Append to `memory.instincts`:
1100
+ ```json
1101
+ {
1102
+ "id": "instinct_<unix_timestamp>",
1103
+ "trigger": "<when X>",
1104
+ "action": "<do Y>",
1105
+ "confidence": 0.5,
1106
+ "status": "hypothesis",
1107
+ "domain": "<testing|architecture|code-style|debugging|workflow>",
1108
+ "source": "phase-<id>",
1109
+ "evidence": ["<specific observation that led to this>"],
1110
+ "tested": false,
1111
+ "created_at": "<ISO-8601>",
1112
+ "last_applied": null,
1113
+ "applications": 0,
1114
+ "successes": 0,
1115
+ "failures": 0
1116
+ }
1117
+ ```
1118
+
1119
+ **Instinct confidence updates:**
1120
+ - Success when applied: +0.1, increment `successes`
1121
+ - Failure when applied: -0.15, increment `failures`
1122
+ - If `failures` >= 2 and `successes` == 0: mark `status: "disproven"`
1123
+ - If `successes` >= 2 and tested: mark `status: "validated"`
1124
+
1125
+ Cap: Keep max 30 instincts (remove lowest confidence when exceeded).
1126
+
1127
+ 4. **Advance state:**
1128
+ - Set `current_phase` to next phase number
1129
+ - Set `state` to `"READY"`
1130
+ - Set `build_started_at` to null
1131
+ - Append event: `"<timestamp>|phase_advanced|continue|Completed Phase <id>, advancing to Phase <next>"`
1132
+
1133
+ 5. **Cap enforcement:**
1134
+ - Keep max 20 phase_learnings
1135
+ - Keep max 30 decisions
1136
+ - Keep max 30 instincts (remove lowest confidence)
1137
+ - Keep max 100 events
1138
+
1139
+ Write COLONY_STATE.json.
1140
+
1141
+ Validate the state file:
1142
+ Run using the Bash tool with description "Validating colony state...": `bash .aether/aether-utils.sh validate-state colony`
1143
+
1144
+ ### Step 2.1: Auto-Emit Phase Pheromones (SILENT)
1145
+
1146
+ **This entire step produces NO user-visible output.** All pheromone operations run silently — learnings are deposited in the background. If any pheromone call fails, log the error and continue. Phase advancement must never fail due to pheromone errors.
1147
+
1148
+ #### 2.1a: Auto-emit FEEDBACK pheromone for phase outcome
1149
+
1150
+ After learning extraction completes in Step 2, auto-emit a FEEDBACK signal summarizing the phase:
1151
+
1152
+ ```bash
1153
+ # phase_id and phase_name come from Step 2 state update
1154
+ # Take the top 1-3 learnings by evidence strength from memory.phase_learnings
1155
+ # Compress into a single summary sentence
1156
+
1157
+ # If learnings were extracted, build a brief summary from them (first 1-3 claims)
1158
+ # Otherwise use the minimal fallback
1159
+ phase_feedback="Phase $phase_id ($phase_name) completed. Key patterns: {brief summary of 1-3 learnings from Step 2}"
1160
+ # Fallback if no learnings: "Phase $phase_id ($phase_name) completed without notable patterns."
1161
+
1162
+ bash .aether/aether-utils.sh pheromone-write FEEDBACK "$phase_feedback" \
1163
+ --strength 0.6 \
1164
+ --source "worker:continue" \
1165
+ --reason "Auto-emitted on phase advance: captures what worked and what was learned" \
1166
+ --ttl "30d" 2>/dev/null || true
1167
+ ```
1168
+
1169
+ The strength is 0.6 (auto-emitted = lower than user-emitted 0.7). Source is "worker:continue" to distinguish from user-emitted feedback. TTL is 30d so it survives phase transitions and can guide subsequent work.
1170
+
1171
+ #### 2.1b: Auto-emit FEEDBACK for phase decisions (PHER-01)
1172
+
1173
+ Extract recent decisions from CONTEXT.md "Recent Decisions" table and emit FEEDBACK pheromones for each. This ensures key decisions propagate as signals to guide future phases.
1174
+
1175
+ ```bash
1176
+ decisions=$(awk '
1177
+ /^## .*Recent Decisions/ { in_section=1; next }
1178
+ in_section && /^\| Date / { next }
1179
+ in_section && /^\|[-]+/ { next }
1180
+ in_section && /^---/ { exit }
1181
+ in_section && /^\| [0-9]{4}-[0-9]{2}/ {
1182
+ split($0, fields, "|")
1183
+ decision = fields[3]
1184
+ gsub(/^[[:space:]]+|[[:space:]]+$/, "", decision)
1185
+ if (decision != "") print decision
1186
+ }
1187
+ ' .aether/CONTEXT.md 2>/dev/null || echo "")
1188
+
1189
+ if [[ -n "$decisions" ]]; then
1190
+ emit_count=0
1191
+ while IFS= read -r dec && [[ $emit_count -lt 3 ]]; do
1192
+ [[ -z "$dec" ]] && continue
1193
+ # Deduplication: check if auto:decision or system:decision pheromone with this text already exists
1194
+ existing=$(jq -r --arg text "$dec" '
1195
+ [.signals[] | select(.active == true and (.source == "auto:decision" or .source == "system:decision") and (.content.text | contains($text)))] | length
1196
+ ' .aether/data/pheromones.json 2>/dev/null || echo "0")
1197
+ if [[ "$existing" == "0" ]]; then
1198
+ bash .aether/aether-utils.sh pheromone-write FEEDBACK \
1199
+ "[decision] $dec" \
1200
+ --strength 0.6 \
1201
+ --source "auto:decision" \
1202
+ --reason "Auto-emitted from phase decision during continue" \
1203
+ --ttl "30d" 2>/dev/null || true
1204
+ emit_count=$((emit_count + 1))
1205
+ fi
1206
+ done <<< "$decisions"
1207
+ fi
1208
+ ```
1209
+
1210
+ Strength is 0.6 (auto-emitted = lower than user-emitted). Source is `"auto:decision"` to distinguish from manual pheromones. Cap: max 3 decision pheromones per continue run. Both `context-update decision` and Step 2.1b now use the same format (`[decision] ...`, source `auto:decision`, strength 0.6), so the dedup `contains()` check reliably catches signals emitted by either path. The dedup query also checks `system:decision` for backward compatibility with any pre-existing signals from before the format alignment.
1211
+
1212
+ #### 2.1c: Auto-emit REDIRECT for midden error patterns (PHER-02)
1213
+
1214
+ Query the actual failure store (`midden.json`) for recurring error categories. Categories with 3+ occurrences indicate persistent issues that should steer workers away from known failure modes.
1215
+
1216
+ ```bash
1217
+ midden_result=$(bash .aether/aether-utils.sh midden-recent-failures 50 2>/dev/null || echo '{"count":0,"failures":[]}')
1218
+ midden_count=$(echo "$midden_result" | jq '.count // 0')
1219
+
1220
+ if [[ "$midden_count" -gt 0 ]]; then
1221
+ # Group by category, find categories with 3+ occurrences
1222
+ recurring_categories=$(echo "$midden_result" | jq -r '
1223
+ [.failures[] | .category]
1224
+ | group_by(.)
1225
+ | map(select(length >= 3))
1226
+ | map({category: .[0], count: length})
1227
+ | .[]
1228
+ | @base64
1229
+ ' 2>/dev/null || echo "")
1230
+
1231
+ emit_count=0
1232
+ for encoded in $recurring_categories; do
1233
+ [[ $emit_count -ge 3 ]] && break
1234
+ [[ -z "$encoded" ]] && continue
1235
+ category=$(echo "$encoded" | base64 -d | jq -r '.category')
1236
+ count=$(echo "$encoded" | base64 -d | jq -r '.count')
1237
+
1238
+ # Deduplication check
1239
+ existing=$(jq -r --arg cat "$category" '
1240
+ [.signals[] | select(.active == true and .source == "auto:error" and (.content.text | contains($cat)))] | length
1241
+ ' .aether/data/pheromones.json 2>/dev/null || echo "0")
1242
+
1243
+ if [[ "$existing" == "0" ]]; then
1244
+ bash .aether/aether-utils.sh pheromone-write REDIRECT \
1245
+ "[error-pattern] Category \"$category\" recurring ($count occurrences)" \
1246
+ --strength 0.7 \
1247
+ --source "auto:error" \
1248
+ --reason "Auto-emitted: midden error pattern recurred 3+ times" \
1249
+ --ttl "30d" 2>/dev/null || true
1250
+ emit_count=$((emit_count + 1))
1251
+
1252
+ # Capture as resolution candidate for promotion tracking
1253
+ bash .aether/aether-utils.sh memory-capture \
1254
+ "resolution" \
1255
+ "Recurring error pattern: $category ($count occurrences)" \
1256
+ "pattern" \
1257
+ "worker:continue" 2>/dev/null || true
1258
+ fi
1259
+ done
1260
+ fi
1261
+ ```
1262
+
1263
+ REDIRECT strength is 0.7 (higher than auto FEEDBACK 0.6 — anti-patterns produce stronger signals). Source is `"auto:error"`. Cap: max 3 error pattern pheromones per continue run. Uses `midden-recent-failures` subcommand (actual failure store) instead of `errors.flagged_patterns` (which may be empty). Threshold is 3+ occurrences for high confidence in recurrence.
1264
+
1265
+ #### 2.1d: Auto-emit FEEDBACK for recurring success criteria (PHER-03)
1266
+
1267
+ Compare success criteria text across all completed phases. Criteria appearing in 2+ completed phases indicate recurring quality patterns worth reinforcing as signals.
1268
+
1269
+ ```bash
1270
+ recurring_criteria=$(jq -r '
1271
+ [.plan.phases[]
1272
+ | select(.status == "completed")
1273
+ | .id as $phase_id
1274
+ | (
1275
+ (.success_criteria // [])[] ,
1276
+ (.tasks // [] | .[].success_criteria // [])[]
1277
+ )
1278
+ | {phase: $phase_id, text: (. | ascii_downcase | gsub("^\\s+|\\s+$"; ""))}
1279
+ ]
1280
+ | group_by(.text)
1281
+ | map(select(length >= 2))
1282
+ | map({text: .[0].text, phases: [.[].phase] | unique, count: length})
1283
+ | .[:2]
1284
+ | .[]
1285
+ | @base64
1286
+ ' .aether/data/COLONY_STATE.json 2>/dev/null || echo "")
1287
+
1288
+ for encoded in $recurring_criteria; do
1289
+ [[ -z "$encoded" ]] && continue
1290
+ text=$(echo "$encoded" | base64 -d | jq -r '.text')
1291
+ count=$(echo "$encoded" | base64 -d | jq -r '.count')
1292
+ phases=$(echo "$encoded" | base64 -d | jq -r '.phases | join(", ")')
1293
+
1294
+ # Deduplication check
1295
+ existing=$(jq -r --arg text "$text" '
1296
+ [.signals[] | select(.active == true and .source == "auto:success" and (.content.text | ascii_downcase | contains($text)))] | length
1297
+ ' .aether/data/pheromones.json 2>/dev/null || echo "0")
1298
+
1299
+ if [[ "$existing" == "0" ]]; then
1300
+ bash .aether/aether-utils.sh pheromone-write FEEDBACK \
1301
+ "[success-pattern] \"$text\" recurs across phases $phases" \
1302
+ --strength 0.6 \
1303
+ --source "auto:success" \
1304
+ --reason "Auto-emitted: success criteria pattern recurred across $count phases" \
1305
+ --ttl "30d" 2>/dev/null || true
1306
+ fi
1307
+ done
1308
+ ```
1309
+
1310
+ Strength is 0.6 (auto-emitted). Source is `"auto:success"`. Cap: max 2 success criteria pheromones per continue run (enforced by `.[:2]` in the jq query). Extracts from both phase-level `.success_criteria` and task-level `.tasks[].success_criteria` across all completed phases. Normalizes text with `ascii_downcase` and whitespace trimming for reliable matching.
1311
+
1312
+ #### 2.1e: Expire phase_end signals and archive to midden
1313
+
1314
+ After auto-emission, expire all signals with `expires_at == "phase_end"`. The FEEDBACK from 2.1a uses a 30d TTL and is not affected by this step.
1315
+
1316
+ Run using the Bash tool with description "Maintaining pheromone memory...": `bash .aether/aether-utils.sh pheromone-expire --phase-end-only 2>/dev/null && bash .aether/aether-utils.sh eternal-init 2>/dev/null`
1317
+
1318
+ This is idempotent — runs every time continue fires but only creates the directory/file once.
1319
+
1320
+ ### Step 2.1.5: Check for Promotion Proposals (PHER-EVOL-02)
1321
+
1322
+ After extracting learnings, check for observations that have met promotion thresholds and present the tick-to-approve UX.
1323
+
1324
+ **Check for --deferred flag:**
1325
+
1326
+ If `$ARGUMENTS` contains `--deferred`:
1327
+ ```bash
1328
+ if [[ "$ARGUMENTS" == *"--deferred"* ]] && [[ -f .aether/data/learning-deferred.json ]]; then
1329
+ echo "📦 Reviewing deferred proposals..."
1330
+ bash .aether/aether-utils.sh learning-approve-proposals --deferred ${verbose:+--verbose}
1331
+ fi
1332
+ ```
1333
+
1334
+ **Normal proposal flow (MEM-01: Silent skip if empty):**
1335
+
1336
+ 1. **Check for proposals:**
1337
+ ```bash
1338
+ proposals=$(bash .aether/aether-utils.sh learning-check-promotion 2>/dev/null || echo '{"proposals":[]}')
1339
+ proposal_count=$(echo "$proposals" | jq '.proposals | length')
1340
+ ```
1341
+
1342
+ 2. **If proposals exist, invoke the approval workflow:**
1343
+
1344
+ Only show the approval UI when there are actual proposals to review:
1345
+
1346
+ ```bash
1347
+ if [[ "$proposal_count" -gt 0 ]]; then
1348
+ verbose_flag=""
1349
+ [[ "$ARGUMENTS" == *"--verbose"* ]] && verbose_flag="--verbose"
1350
+ bash .aether/aether-utils.sh learning-approve-proposals $verbose_flag
1351
+ fi
1352
+ # If no proposals, silently skip without notice (per user decision)
1353
+ ```
1354
+
1355
+ The learning-approve-proposals function handles:
1356
+ - Displaying proposals with checkbox UI
1357
+ - Capturing user selection
1358
+ - Executing batch promotions via queen-promote
1359
+ - Deferring unselected proposals
1360
+ - Offering undo after successful promotions
1361
+ - Logging PROMOTED activity
1362
+
1363
+ **Skip conditions:**
1364
+ - learning-check-promotion returns empty or fails
1365
+ - No proposals to review (silent skip - no output)
1366
+ - QUEEN.md does not exist
1367
+
1368
+ ### Step 2.1.6: Batch Wisdom Auto-Promotion (QUEEN-01)
1369
+
1370
+ After learnings extraction and auto-emission, sweep all recorded observations and auto-promote any that meet the higher recurrence thresholds (pattern=2, philosophy=3, etc.) to QUEEN.md. The learning-promote-auto subcommand has an internal grep guard that skips content already in QUEEN.md, so this is safe to run even after memory-capture in Step 2.5 already attempted promotion.
1371
+
1372
+ ```bash
1373
+ # === Batch Wisdom Auto-Promotion (QUEEN-01) ===
1374
+ # Sweep all observations and auto-promote any that crossed auto thresholds.
1375
+ # The grep guard inside learning-promote-auto prevents double-promotion
1376
+ # for observations already promoted by memory-capture in Step 2.5.
1377
+
1378
+ obs_file=".aether/data/learning-observations.json"
1379
+ if [[ -f "$obs_file" ]]; then
1380
+ obs_count=$(jq '.observations | length' "$obs_file" 2>/dev/null || echo "0")
1381
+ promoted_count=0
1382
+
1383
+ if [[ "$obs_count" -gt 0 ]]; then
1384
+ for encoded in $(jq -r '.observations[] | @base64' "$obs_file" 2>/dev/null); do
1385
+ content=$(echo "$encoded" | base64 -d | jq -r '.content // empty')
1386
+ wisdom_type=$(echo "$encoded" | base64 -d | jq -r '.wisdom_type // "pattern"')
1387
+ colony=$(echo "$encoded" | base64 -d | jq -r '.colonies[0] // "unknown"')
1388
+ [[ -z "$content" ]] && continue
1389
+
1390
+ result=$(bash .aether/aether-utils.sh learning-promote-auto "$wisdom_type" "$content" "$colony" "learning" 2>/dev/null || echo '{}')
1391
+ was_promoted=$(echo "$result" | jq -r '.result.promoted // false' 2>/dev/null || echo "false")
1392
+ if [[ "$was_promoted" == "true" ]]; then
1393
+ promoted_count=$((promoted_count + 1))
1394
+ fi
1395
+ done
1396
+ fi
1397
+ fi
1398
+ # === END Batch Wisdom Auto-Promotion ===
1399
+ ```
1400
+
1401
+ ### Step 2.2: Update Handoff Document
1402
+
1403
+ After advancing the phase, update the handoff document with the new current state:
1404
+
1405
+ ```bash
1406
+ # Determine if there's a next phase
1407
+ next_phase_id=$((current_phase + 1))
1408
+ has_next_phase=$(jq --arg next "$next_phase_id" '.plan.phases | map(select(.id == ($next | tonumber))) | length' .aether/data/COLONY_STATE.json)
1409
+
1410
+ # Write updated handoff
1411
+ cat > .aether/HANDOFF.md << 'HANDOFF_EOF'
1412
+ # Colony Session — Phase Advanced
1413
+
1414
+ ## Quick Resume
1415
+ Run `/ant:build {next_phase_id}` to start working on the current phase.
1416
+
1417
+ ## State at Advancement
1418
+ - Goal: "$(jq -r '.goal' .aether/data/COLONY_STATE.json)"
1419
+ - Completed Phase: {completed_phase_id} — {completed_phase_name}
1420
+ - Current Phase: {next_phase_id} — {next_phase_name}
1421
+ - State: READY
1422
+ - Updated: $(date -u +%Y-%m-%dT%H:%M:%SZ)
1423
+
1424
+ ## What Was Completed
1425
+ - Phase {completed_phase_id} marked as completed
1426
+ - Learnings extracted: {learning_count}
1427
+ - Instincts updated: {instinct_count}
1428
+ - Wisdom promoted to QUEEN.md: {promoted_count}
1429
+
1430
+ ## Current Phase Tasks
1431
+ $(jq -r '.plan.phases[] | select(.id == next_phase_id) | .tasks[] | "- [ ] \(.id): \(.description)"' .aether/data/COLONY_STATE.json)
1432
+
1433
+ ## Next Steps
1434
+ - Build current phase: `/ant:build {next_phase_id}`
1435
+ - Review phase details: `/ant:phase {next_phase_id}`
1436
+ - Pause colony: `/ant:pause-colony`
1437
+
1438
+ ## Session Note
1439
+ Phase advanced successfully. Colony is READY to build Phase {next_phase_id}.
1440
+ HANDOFF_EOF
1441
+ ```
1442
+
1443
+ This handoff reflects the post-advancement state, allowing seamless resumption even if the session is lost.
1444
+
1445
+ ### Step 2.3: Update Changelog
1446
+
1447
+ **MANDATORY: Append a changelog entry for the completed phase. This step is never skipped.**
1448
+
1449
+ If no `CHANGELOG.md` exists, `changelog-append` creates one automatically.
1450
+
1451
+ **Step 2.3.1: Collect plan data**
1452
+
1453
+ ```bash
1454
+ bash .aether/aether-utils.sh changelog-collect-plan-data "{phase_identifier}" "{plan_number}"
1455
+ ```
1456
+
1457
+ Parse the returned JSON to extract `files`, `decisions`, `worked`, and `requirements` arrays.
1458
+
1459
+ - `{phase_identifier}` is the full phase name (e.g., `36-memory-capture`)
1460
+ - `{plan_number}` is the plan number (e.g., `01`)
1461
+
1462
+ If the command fails (e.g., no plan file found), fall back to collecting data manually:
1463
+ - Files: from `git diff --stat` of the completed phase
1464
+ - Decisions: from COLONY_STATE.json `memory.decisions` (last 5)
1465
+ - Worked/requirements: leave empty
1466
+
1467
+ **Step 2.3.2: Append changelog entry**
1468
+
1469
+ ```bash
1470
+ bash .aether/aether-utils.sh changelog-append \
1471
+ "$(date +%Y-%m-%d)" \
1472
+ "{phase_identifier}" \
1473
+ "{plan_number}" \
1474
+ "{files_csv}" \
1475
+ "{decisions_semicolon_separated}" \
1476
+ "{worked_semicolon_separated}" \
1477
+ "{requirements_csv}"
1478
+ ```
1479
+
1480
+ This atomically writes the entry. If the project already has a Keep a Changelog format, it adds a "Colony Work Log" separator section to keep both formats clean.
1481
+
1482
+ **Error handling:** If `changelog-append` fails, log to midden and continue — changelog failure never blocks phase advancement.
1483
+
1484
+ ### Step 2.4: Commit Suggestion (Optional)
1485
+
1486
+ **This step is non-blocking. Skipping does not affect phase advancement or any subsequent steps. Failure to commit has zero consequences.**
1487
+
1488
+ After the phase is advanced and changelog updated, suggest a commit to preserve the milestone.
1489
+
1490
+ #### Step 2.4.1: Capture AI Description
1491
+
1492
+ **As the AI, briefly describe what was accomplished in this phase.**
1493
+
1494
+ Look at:
1495
+ 1. The phase PLAN.md `<objective>` section (what we set out to do)
1496
+ 2. Tasks that were marked complete
1497
+ 3. Files that were modified (from git diff --stat)
1498
+ 4. Any patterns or decisions recorded
1499
+
1500
+ **Provide a brief, memorable description** (10-15 words, imperative mood):
1501
+ - Good: "Implement task-based model routing with keyword detection and precedence chain"
1502
+ - Good: "Fix build timing by removing background execution from worker spawns"
1503
+ - Bad: "Phase complete" (too vague)
1504
+ - Bad: "Modified files in bin/lib" (too mechanical)
1505
+
1506
+ Store this as `ai_description` for the commit message.
1507
+
1508
+ #### Step 2.4.2: Generate Enhanced Commit Message
1509
+
1510
+ ```bash
1511
+ bash .aether/aether-utils.sh generate-commit-message "contextual" {phase_id} "{phase_name}" "{ai_description}" {plan_number}
1512
+ ```
1513
+
1514
+ Parse the returned JSON to extract:
1515
+ - `message` - the commit subject line
1516
+ - `body` - structured metadata (Scope, Files)
1517
+ - `files_changed` - file count
1518
+ - `subsystem` - derived subsystem name
1519
+ - `scope` - phase.plan format
1520
+
1521
+ **Check files changed:**
1522
+ ```bash
1523
+ git diff --stat HEAD 2>/dev/null | tail -5
1524
+ ```
1525
+ If not in a git repo or no changes detected, skip this step silently.
1526
+
1527
+ **Display the enhanced suggestion:**
1528
+ ```
1529
+ ──────────────────────────────────────────────────
1530
+ Commit Suggestion
1531
+ ──────────────────────────────────────────────────
1532
+
1533
+ AI Description: {ai_description}
1534
+
1535
+ Formatted Message:
1536
+ {message}
1537
+
1538
+ Metadata:
1539
+ Scope: {scope}
1540
+ Files: {files_changed} files changed
1541
+ Preview: {first 5 lines of git diff --stat}
1542
+
1543
+ ──────────────────────────────────────────────────
1544
+ ```
1545
+
1546
+ **Use AskUserQuestion:**
1547
+ ```
1548
+ Commit this milestone?
1549
+
1550
+ 1. Yes, commit with this message
1551
+ 2. Yes, but let me edit the description
1552
+ 3. No, I'll commit later
1553
+ ```
1554
+
1555
+ **If option 1 ("Yes, commit with this message"):**
1556
+ ```bash
1557
+ git add -A && git commit -m "{message}" -m "{body}"
1558
+ ```
1559
+ Display: `Committed: {message} ({files_changed} files)`
1560
+
1561
+ **If option 2 ("Yes, but let me edit"):**
1562
+ Use AskUserQuestion to get the user's custom description:
1563
+ ```
1564
+ Enter your description (or press Enter to keep: '{ai_description}'):
1565
+ ```
1566
+ Then regenerate the commit message with the new description and commit.
1567
+
1568
+ **If option 3 ("No, I'll commit later"):**
1569
+ Display: `Skipped. Your changes are saved on disk but not committed.`
1570
+
1571
+ **Record the suggestion to prevent double-prompting:**
1572
+ Set `last_commit_suggestion_phase` to `{phase_id}` in COLONY_STATE.json (add the field at the top level if it does not exist).
1573
+
1574
+ **Error handling:** If any git command fails (not a repo, merge conflict, pre-commit hook rejection), display the error output and continue to the next step. The commit suggestion is advisory only -- it never blocks the flow.
1575
+
1576
+ Continue to Step 2.5 (Context Clear Suggestion), then to Step 2.7 (Project Completion) or Step 3 (Display Result).
1577
+
1578
+ ### Step 2.5: Context Clear Suggestion (Optional)
1579
+
1580
+ **This step is non-blocking. Skipping does not affect phase advancement.**
1581
+
1582
+ After committing (or skipping commit), suggest clearing context to refresh before the next phase.
1583
+
1584
+ 1. **Display the suggestion:**
1585
+ ```
1586
+ ──────────────────────────────────────────────────
1587
+ Context Refresh
1588
+ ──────────────────────────────────────────────────
1589
+
1590
+ State is fully persisted and committed.
1591
+ Phase {next_id} is ready to build.
1592
+
1593
+ ──────────────────────────────────────────────────
1594
+ ```
1595
+
1596
+ 2. **Use AskUserQuestion:**
1597
+ ```
1598
+ Clear context now?
1599
+
1600
+ 1. Yes, clear context then run /ant:build {next_id}
1601
+ 2. No, continue in current context
1602
+ ```
1603
+
1604
+ 3. **If option 1 ("Yes, clear context"):**
1605
+
1606
+ **IMPORTANT:** Claude Code does not support programmatic /clear. Display instructions:
1607
+ ```
1608
+ Please type: /clear
1609
+
1610
+ Then run: /ant:build {next_id}
1611
+ ```
1612
+
1613
+ Record the suggestion: Set `context_clear_suggested` to `true` in COLONY_STATE.json.
1614
+
1615
+ 4. **If option 2 ("No, continue in current context"):**
1616
+ Display: `Continuing in current context. State is saved.`
1617
+
1618
+ Continue to Step 2.7 (Project Completion) or Step 3 (Display Result).
1619
+
1620
+ ### Step 2.6: Update Context Document
1621
+
1622
+ After phase advancement is complete, update `.aether/CONTEXT.md`:
1623
+
1624
+ **Log the activity:**
1625
+ ```bash
1626
+ bash .aether/aether-utils.sh context-update activity "continue" "Phase {prev_id} completed, advanced to {next_id}" "—"
1627
+ ```
1628
+
1629
+ **Update the phase:**
1630
+ ```bash
1631
+ bash .aether/aether-utils.sh context-update update-phase {next_id} "{next_phase_name}" "YES" "Phase advanced, ready to build"
1632
+ ```
1633
+
1634
+ **Log any decisions from this session:**
1635
+ If any architectural decisions were made during verification, also run:
1636
+ ```bash
1637
+ bash .aether/aether-utils.sh context-update decision "{decision_description}" "{rationale}" "Queen"
1638
+ ```
1639
+
1640
+ ### Step 2.7: Project Completion
1641
+
1642
+ Runs ONLY when all phases complete.
1643
+
1644
+ 1. Read activity.log and errors.records
1645
+ 2. Display tech debt report:
1646
+
1647
+ ```
1648
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
1649
+ 🎉 P R O J E C T C O M P L E T E 🎉
1650
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
1651
+
1652
+ 👑 Goal Achieved: {goal}
1653
+ 📍 Phases Completed: {total}
1654
+
1655
+ {if flagged_patterns:}
1656
+ ⚠️ Persistent Issues:
1657
+ {list any flagged_patterns}
1658
+ {end if}
1659
+
1660
+ 🧠 Colony Learnings:
1661
+ {condensed learnings from memory.phase_learnings}
1662
+
1663
+ 👑 Wisdom Added to QUEEN.md:
1664
+ {count} patterns/redirects/philosophies promoted across all phases
1665
+
1666
+ 🐜 The colony rests. Well done!
1667
+ ```
1668
+
1669
+ 3. Write summary to `.aether/data/completion-report.md`
1670
+ 4. Display next commands and stop.
1671
+
1672
+ ### Step 3: Display Result
1673
+
1674
+ Output:
1675
+
1676
+ ```
1677
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
1678
+ P H A S E A D V A N C E M E N T
1679
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
1680
+
1681
+ ✅ Phase {prev_id}: {prev_name} -- COMPLETED
1682
+
1683
+ 🧠 Learnings Extracted:
1684
+ {list learnings added}
1685
+
1686
+ 👑 Wisdom Promoted to QUEEN.md:
1687
+ {for each promoted learning:}
1688
+ [{type}] {brief claim}
1689
+ {end for}
1690
+
1691
+ 🐜 Instincts Updated:
1692
+ {for each instinct created or updated:}
1693
+ [{confidence}] {domain}: {action}
1694
+ {end for}
1695
+
1696
+ ─────────────────────────────────────────────────────
1697
+
1698
+ ➡️ Advancing to Phase {next_id}: {next_name}
1699
+ {next_description}
1700
+ 📋 Tasks: {task_count}
1701
+ 📊 State: READY
1702
+
1703
+ ──────────────────────────────────────────────────
1704
+ 🐜 Next Up
1705
+ ──────────────────────────────────────────────────
1706
+ /ant:build {next_id} 🔨 Build next phase
1707
+ /ant:status 📊 Check progress
1708
+
1709
+ 💾 State persisted — context clear suggested above
1710
+
1711
+ 📋 Context document updated at `.aether/CONTEXT.md`
1712
+ ```
1713
+
1714
+ **IMPORTANT:** In the "Next Steps" section above, substitute the actual phase number for `{next_id}` (calculated in Step 2 as `current_phase + 1`). For example, if advancing to phase 4, output `/ant:build 4` not `/ant:build {next_id}`.
1715
+
1716
+ ### Step 4: Update Session
1717
+
1718
+ Update the session tracking file to enable `/ant:resume` after context clear:
1719
+
1720
+ ```bash
1721
+ bash .aether/aether-utils.sh session-update "/ant:continue" "/ant:build {next_id}" "Phase {prev_id} completed, advanced to Phase {next_id}"
1722
+ ```
1723
+
1724
+ Run using the Bash tool with description "Saving session state...": `bash .aether/aether-utils.sh session-update "/ant:continue" "/ant:build {next_id}" "Phase {prev_id} completed, advanced to Phase {next_id}"`