aether-colony 5.0.0 → 5.2.1

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