@aragon-agent/cli 0.6.54 → 0.6.56

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 (346) hide show
  1. package/CHANGELOG.md +2912 -2838
  2. package/README.md +4226 -4042
  3. package/dist/agent/controller.d.ts +119 -0
  4. package/dist/agent/controller.js +365 -2
  5. package/dist/agent/governance-wiring.js +8 -1
  6. package/dist/agent/redteam-prompt.d.ts +47 -0
  7. package/dist/agent/redteam-prompt.js +161 -0
  8. package/dist/agent/redteam-wiring.d.ts +159 -0
  9. package/dist/agent/redteam-wiring.js +349 -0
  10. package/dist/agent/system-prompt.d.ts +39 -0
  11. package/dist/agent/system-prompt.js +18 -0
  12. package/dist/app/App.d.ts +10 -1
  13. package/dist/app/App.js +233 -24
  14. package/dist/app/use-redteam-mode.d.ts +56 -0
  15. package/dist/app/use-redteam-mode.js +121 -0
  16. package/dist/cli.js +82 -4
  17. package/dist/commands/builtins.js +43 -1
  18. package/dist/commands/catalog.js +5 -0
  19. package/dist/commands/index-build.js +2 -1
  20. package/dist/commands/redteam-command.d.ts +22 -0
  21. package/dist/commands/redteam-command.js +141 -0
  22. package/dist/commands/registry.d.ts +8 -0
  23. package/dist/config/app-paths.d.ts +10 -0
  24. package/dist/config/app-paths.js +12 -0
  25. package/dist/config/cli-commands.d.ts +29 -0
  26. package/dist/config/cli-commands.js +76 -1
  27. package/dist/config/env.d.ts +3 -1
  28. package/dist/config/env.js +23 -1
  29. package/dist/config/load.d.ts +22 -0
  30. package/dist/config/load.js +22 -2
  31. package/dist/config/redteam-launch.d.ts +77 -0
  32. package/dist/config/redteam-launch.js +58 -0
  33. package/dist/config/store.js +21 -1
  34. package/dist/config/ui-state.d.ts +44 -0
  35. package/dist/config/ui-state.js +38 -0
  36. package/dist/exec/bridge/server.d.ts +7 -0
  37. package/dist/exec/bridge/server.js +6 -2
  38. package/dist/exec/cli-commands.js +4 -0
  39. package/dist/exec/index.js +2 -0
  40. package/dist/exec/options.d.ts +11 -0
  41. package/dist/exec/options.js +21 -1
  42. package/dist/gene/block.d.ts +33 -0
  43. package/dist/gene/block.js +51 -0
  44. package/dist/gene/capacity.d.ts +74 -0
  45. package/dist/gene/capacity.js +169 -0
  46. package/dist/gene/catalog-reconcile.d.ts +13 -0
  47. package/dist/gene/catalog-reconcile.js +105 -0
  48. package/dist/gene/catalog-stats.d.ts +27 -0
  49. package/dist/gene/catalog-stats.js +89 -0
  50. package/dist/gene/catalog-sync.d.ts +82 -0
  51. package/dist/gene/catalog-sync.js +324 -0
  52. package/dist/gene/catalog.d.ts +160 -0
  53. package/dist/gene/catalog.js +433 -0
  54. package/dist/gene/cli-commands.d.ts +50 -0
  55. package/dist/gene/cli-commands.js +500 -0
  56. package/dist/gene/command-report.d.ts +40 -0
  57. package/dist/gene/command-report.js +246 -0
  58. package/dist/gene/command.d.ts +29 -0
  59. package/dist/gene/command.js +561 -0
  60. package/dist/gene/commit-apply-types.d.ts +13 -0
  61. package/dist/gene/commit-apply-types.js +1 -0
  62. package/dist/gene/commit-compound.d.ts +34 -0
  63. package/dist/gene/commit-compound.js +212 -0
  64. package/dist/gene/commit-counts.d.ts +41 -0
  65. package/dist/gene/commit-counts.js +70 -0
  66. package/dist/gene/commit-exec.d.ts +42 -0
  67. package/dist/gene/commit-exec.js +134 -0
  68. package/dist/gene/commit-head.d.ts +52 -0
  69. package/dist/gene/commit-head.js +97 -0
  70. package/dist/gene/commit-plan.d.ts +95 -0
  71. package/dist/gene/commit-plan.js +68 -0
  72. package/dist/gene/commit-prepare.d.ts +63 -0
  73. package/dist/gene/commit-prepare.js +159 -0
  74. package/dist/gene/commit-types.d.ts +234 -0
  75. package/dist/gene/commit-types.js +3 -0
  76. package/dist/gene/curator/agent.d.ts +137 -0
  77. package/dist/gene/curator/agent.js +203 -0
  78. package/dist/gene/curator/budget.d.ts +69 -0
  79. package/dist/gene/curator/budget.js +131 -0
  80. package/dist/gene/curator/conflicts.d.ts +54 -0
  81. package/dist/gene/curator/conflicts.js +143 -0
  82. package/dist/gene/curator/curator.d.ts +170 -0
  83. package/dist/gene/curator/curator.js +617 -0
  84. package/dist/gene/curator/deps.d.ts +34 -0
  85. package/dist/gene/curator/deps.js +48 -0
  86. package/dist/gene/curator/deterministic.d.ts +62 -0
  87. package/dist/gene/curator/deterministic.js +287 -0
  88. package/dist/gene/curator/executors.d.ts +36 -0
  89. package/dist/gene/curator/executors.js +379 -0
  90. package/dist/gene/curator/lanes.d.ts +52 -0
  91. package/dist/gene/curator/lanes.js +99 -0
  92. package/dist/gene/curator/lease.d.ts +76 -0
  93. package/dist/gene/curator/lease.js +171 -0
  94. package/dist/gene/curator/library.d.ts +36 -0
  95. package/dist/gene/curator/library.js +169 -0
  96. package/dist/gene/curator/lifecycle.d.ts +52 -0
  97. package/dist/gene/curator/lifecycle.js +109 -0
  98. package/dist/gene/curator/maintenance.d.ts +71 -0
  99. package/dist/gene/curator/maintenance.js +213 -0
  100. package/dist/gene/curator/probation.d.ts +51 -0
  101. package/dist/gene/curator/probation.js +71 -0
  102. package/dist/gene/curator/probe.d.ts +131 -0
  103. package/dist/gene/curator/probe.js +534 -0
  104. package/dist/gene/curator/prompt.d.ts +18 -0
  105. package/dist/gene/curator/prompt.js +128 -0
  106. package/dist/gene/curator/publish.d.ts +64 -0
  107. package/dist/gene/curator/publish.js +113 -0
  108. package/dist/gene/curator/recheck.d.ts +55 -0
  109. package/dist/gene/curator/recheck.js +103 -0
  110. package/dist/gene/curator/run-events.d.ts +63 -0
  111. package/dist/gene/curator/run-events.js +55 -0
  112. package/dist/gene/curator/similarity.d.ts +13 -0
  113. package/dist/gene/curator/similarity.js +46 -0
  114. package/dist/gene/curator/switches.d.ts +78 -0
  115. package/dist/gene/curator/switches.js +146 -0
  116. package/dist/gene/curator/task-context.d.ts +93 -0
  117. package/dist/gene/curator/task-context.js +63 -0
  118. package/dist/gene/curator/task-runner.d.ts +56 -0
  119. package/dist/gene/curator/task-runner.js +257 -0
  120. package/dist/gene/curator/tool-support.d.ts +112 -0
  121. package/dist/gene/curator/tool-support.js +197 -0
  122. package/dist/gene/curator/toolkit.d.ts +49 -0
  123. package/dist/gene/curator/toolkit.js +104 -0
  124. package/dist/gene/curator/tools-read.d.ts +4 -0
  125. package/dist/gene/curator/tools-read.js +177 -0
  126. package/dist/gene/curator/tools-release.d.ts +73 -0
  127. package/dist/gene/curator/tools-release.js +287 -0
  128. package/dist/gene/curator/tools-verify.d.ts +47 -0
  129. package/dist/gene/curator/tools-verify.js +202 -0
  130. package/dist/gene/curator/tools-write.d.ts +26 -0
  131. package/dist/gene/curator/tools-write.js +394 -0
  132. package/dist/gene/curator/tools.d.ts +23 -0
  133. package/dist/gene/curator/tools.js +21 -0
  134. package/dist/gene/curator/validate/common.d.ts +87 -0
  135. package/dist/gene/curator/validate/common.js +132 -0
  136. package/dist/gene/curator/validate/evidence-tokens.d.ts +36 -0
  137. package/dist/gene/curator/validate/evidence-tokens.js +139 -0
  138. package/dist/gene/curator/validate/index.d.ts +23 -0
  139. package/dist/gene/curator/validate/index.js +62 -0
  140. package/dist/gene/curator/validate/knowledge.d.ts +25 -0
  141. package/dist/gene/curator/validate/knowledge.js +216 -0
  142. package/dist/gene/curator/validate/live-check.d.ts +14 -0
  143. package/dist/gene/curator/validate/live-check.js +144 -0
  144. package/dist/gene/curator/validate/ports.d.ts +67 -0
  145. package/dist/gene/curator/validate/ports.js +1 -0
  146. package/dist/gene/curator/validate/prompts.d.ts +41 -0
  147. package/dist/gene/curator/validate/prompts.js +161 -0
  148. package/dist/gene/curator/validate/skill.d.ts +15 -0
  149. package/dist/gene/curator/validate/skill.js +251 -0
  150. package/dist/gene/curator/validate/tool.d.ts +6 -0
  151. package/dist/gene/curator/validate/tool.js +217 -0
  152. package/dist/gene/curator/validate/types.d.ts +90 -0
  153. package/dist/gene/curator/validate/types.js +1 -0
  154. package/dist/gene/curator/validator-ports.d.ts +38 -0
  155. package/dist/gene/curator/validator-ports.js +29 -0
  156. package/dist/gene/diag.d.ts +209 -0
  157. package/dist/gene/diag.js +549 -0
  158. package/dist/gene/env.d.ts +10 -0
  159. package/dist/gene/env.js +214 -0
  160. package/dist/gene/eval-recorder.d.ts +84 -0
  161. package/dist/gene/eval-recorder.js +222 -0
  162. package/dist/gene/explain-transport.d.ts +3 -0
  163. package/dist/gene/explain-transport.js +39 -0
  164. package/dist/gene/explain.d.ts +96 -0
  165. package/dist/gene/explain.js +293 -0
  166. package/dist/gene/fs.d.ts +39 -0
  167. package/dist/gene/fs.js +139 -0
  168. package/dist/gene/fsck.d.ts +68 -0
  169. package/dist/gene/fsck.js +134 -0
  170. package/dist/gene/gc-library-sweeps.d.ts +9 -0
  171. package/dist/gene/gc-library-sweeps.js +220 -0
  172. package/dist/gene/gc-rejected-set.d.ts +15 -0
  173. package/dist/gene/gc-rejected-set.js +63 -0
  174. package/dist/gene/gc-safe.d.ts +12 -0
  175. package/dist/gene/gc-safe.js +74 -0
  176. package/dist/gene/gc-scope-sweeps.d.ts +18 -0
  177. package/dist/gene/gc-scope-sweeps.js +297 -0
  178. package/dist/gene/gc-types.d.ts +55 -0
  179. package/dist/gene/gc-types.js +26 -0
  180. package/dist/gene/gc.d.ts +42 -0
  181. package/dist/gene/gc.js +129 -0
  182. package/dist/gene/gene-errors.d.ts +23 -0
  183. package/dist/gene/gene-errors.js +29 -0
  184. package/dist/gene/hints.d.ts +91 -0
  185. package/dist/gene/hints.js +394 -0
  186. package/dist/gene/hub.d.ts +149 -0
  187. package/dist/gene/hub.js +371 -0
  188. package/dist/gene/import-plan.d.ts +80 -0
  189. package/dist/gene/import-plan.js +294 -0
  190. package/dist/gene/import-proposal.d.ts +23 -0
  191. package/dist/gene/import-proposal.js +101 -0
  192. package/dist/gene/import-skill-port.d.ts +6 -0
  193. package/dist/gene/import-skill-port.js +53 -0
  194. package/dist/gene/import-sources.d.ts +48 -0
  195. package/dist/gene/import-sources.js +140 -0
  196. package/dist/gene/index-writer.d.ts +36 -0
  197. package/dist/gene/index-writer.js +101 -0
  198. package/dist/gene/learn/learn-call.d.ts +63 -0
  199. package/dist/gene/learn/learn-call.js +157 -0
  200. package/dist/gene/learn/learn-prompt.d.ts +51 -0
  201. package/dist/gene/learn/learn-prompt.js +245 -0
  202. package/dist/gene/learn/learner.d.ts +181 -0
  203. package/dist/gene/learn/learner.js +426 -0
  204. package/dist/gene/learn/ledger.d.ts +220 -0
  205. package/dist/gene/learn/ledger.js +394 -0
  206. package/dist/gene/learn/proposal-build.d.ts +83 -0
  207. package/dist/gene/learn/proposal-build.js +211 -0
  208. package/dist/gene/learn/proposal-guard.d.ts +43 -0
  209. package/dist/gene/learn/proposal-guard.js +37 -0
  210. package/dist/gene/learn/signals-port.d.ts +47 -0
  211. package/dist/gene/learn/signals-port.js +86 -0
  212. package/dist/gene/maintenance-paths.d.ts +7 -0
  213. package/dist/gene/maintenance-paths.js +20 -0
  214. package/dist/gene/maintenance-probation.d.ts +33 -0
  215. package/dist/gene/maintenance-probation.js +127 -0
  216. package/dist/gene/maintenance-proposals.d.ts +24 -0
  217. package/dist/gene/maintenance-proposals.js +68 -0
  218. package/dist/gene/maintenance-runner.d.ts +92 -0
  219. package/dist/gene/maintenance-runner.js +262 -0
  220. package/dist/gene/maintenance-tasks.d.ts +37 -0
  221. package/dist/gene/maintenance-tasks.js +95 -0
  222. package/dist/gene/manager-actions.d.ts +12 -0
  223. package/dist/gene/manager-actions.js +279 -0
  224. package/dist/gene/manager-approve.d.ts +29 -0
  225. package/dist/gene/manager-approve.js +84 -0
  226. package/dist/gene/manager-context.d.ts +90 -0
  227. package/dist/gene/manager-context.js +201 -0
  228. package/dist/gene/manager-detail.d.ts +17 -0
  229. package/dist/gene/manager-detail.js +313 -0
  230. package/dist/gene/manager-gc.d.ts +13 -0
  231. package/dist/gene/manager-gc.js +81 -0
  232. package/dist/gene/manager-library.d.ts +39 -0
  233. package/dist/gene/manager-library.js +90 -0
  234. package/dist/gene/manager-list.d.ts +27 -0
  235. package/dist/gene/manager-list.js +170 -0
  236. package/dist/gene/manager-queue.d.ts +16 -0
  237. package/dist/gene/manager-queue.js +124 -0
  238. package/dist/gene/manager-stats.d.ts +28 -0
  239. package/dist/gene/manager-stats.js +53 -0
  240. package/dist/gene/manager-view.d.ts +27 -0
  241. package/dist/gene/manager-view.js +124 -0
  242. package/dist/gene/manager.d.ts +56 -0
  243. package/dist/gene/manager.js +179 -0
  244. package/dist/gene/orphan-scopes.d.ts +37 -0
  245. package/dist/gene/orphan-scopes.js +150 -0
  246. package/dist/gene/paths.d.ts +73 -0
  247. package/dist/gene/paths.js +239 -0
  248. package/dist/gene/plan-content.d.ts +73 -0
  249. package/dist/gene/plan-content.js +522 -0
  250. package/dist/gene/plan-lifecycle.d.ts +29 -0
  251. package/dist/gene/plan-lifecycle.js +310 -0
  252. package/dist/gene/policy.d.ts +71 -0
  253. package/dist/gene/policy.js +313 -0
  254. package/dist/gene/project-learning.d.ts +25 -0
  255. package/dist/gene/project-learning.js +54 -0
  256. package/dist/gene/propagation.d.ts +48 -0
  257. package/dist/gene/propagation.js +45 -0
  258. package/dist/gene/queue-lock.d.ts +22 -0
  259. package/dist/gene/queue-lock.js +99 -0
  260. package/dist/gene/queue-record.d.ts +57 -0
  261. package/dist/gene/queue-record.js +145 -0
  262. package/dist/gene/queue.d.ts +235 -0
  263. package/dist/gene/queue.js +764 -0
  264. package/dist/gene/read.d.ts +61 -0
  265. package/dist/gene/read.js +252 -0
  266. package/dist/gene/runlog.d.ts +101 -0
  267. package/dist/gene/runlog.js +404 -0
  268. package/dist/gene/schema-lite.d.ts +24 -0
  269. package/dist/gene/schema-lite.js +159 -0
  270. package/dist/gene/scope-guard.d.ts +23 -0
  271. package/dist/gene/scope-guard.js +9 -0
  272. package/dist/gene/scope-lock.d.ts +48 -0
  273. package/dist/gene/scope-lock.js +222 -0
  274. package/dist/gene/scope-verify.d.ts +63 -0
  275. package/dist/gene/scope-verify.js +123 -0
  276. package/dist/gene/secrets.d.ts +43 -0
  277. package/dist/gene/secrets.js +161 -0
  278. package/dist/gene/service-context.d.ts +43 -0
  279. package/dist/gene/service-context.js +79 -0
  280. package/dist/gene/service-prepare.d.ts +25 -0
  281. package/dist/gene/service-prepare.js +219 -0
  282. package/dist/gene/service-types.d.ts +196 -0
  283. package/dist/gene/service-types.js +1 -0
  284. package/dist/gene/service-view.d.ts +41 -0
  285. package/dist/gene/service-view.js +69 -0
  286. package/dist/gene/service.d.ts +114 -0
  287. package/dist/gene/service.js +761 -0
  288. package/dist/gene/session-start.d.ts +36 -0
  289. package/dist/gene/session-start.js +212 -0
  290. package/dist/gene/store-port.d.ts +88 -0
  291. package/dist/gene/store-port.js +10 -0
  292. package/dist/gene/store-rows.d.ts +36 -0
  293. package/dist/gene/store-rows.js +72 -0
  294. package/dist/gene/store.d.ts +125 -0
  295. package/dist/gene/store.js +622 -0
  296. package/dist/gene/tombstones.d.ts +47 -0
  297. package/dist/gene/tombstones.js +61 -0
  298. package/dist/gene/tool-runner.d.ts +47 -0
  299. package/dist/gene/tool-runner.js +154 -0
  300. package/dist/gene/tool-screen.d.ts +41 -0
  301. package/dist/gene/tool-screen.js +227 -0
  302. package/dist/gene/tools.d.ts +112 -0
  303. package/dist/gene/tools.js +539 -0
  304. package/dist/gene/transfer.d.ts +85 -0
  305. package/dist/gene/transfer.js +433 -0
  306. package/dist/gene/ui-hints.d.ts +15 -0
  307. package/dist/gene/ui-hints.js +67 -0
  308. package/dist/gene/usage-fold-cursor.d.ts +24 -0
  309. package/dist/gene/usage-fold-cursor.js +115 -0
  310. package/dist/gene/usage-fold.d.ts +49 -0
  311. package/dist/gene/usage-fold.js +397 -0
  312. package/dist/gene/usage.d.ts +67 -0
  313. package/dist/gene/usage.js +231 -0
  314. package/dist/gene/version-service.d.ts +118 -0
  315. package/dist/gene/version-service.js +453 -0
  316. package/dist/gene/wiring-events.d.ts +43 -0
  317. package/dist/gene/wiring-events.js +113 -0
  318. package/dist/gene/wiring-models.d.ts +46 -0
  319. package/dist/gene/wiring-models.js +81 -0
  320. package/dist/gene/wiring.d.ts +200 -0
  321. package/dist/gene/wiring.js +764 -0
  322. package/dist/governance/prompts/orchestrator-block.js +3 -2
  323. package/dist/host/controller-factory.d.ts +8 -0
  324. package/dist/host/controller-factory.js +7 -0
  325. package/dist/host/gene.d.ts +26 -0
  326. package/dist/host/gene.js +24 -0
  327. package/dist/host/index.d.ts +1 -0
  328. package/dist/host/index.js +1 -0
  329. package/dist/session/checkpoint.d.ts +15 -0
  330. package/dist/session/checkpoint.js +18 -0
  331. package/dist/session/persist.d.ts +21 -0
  332. package/dist/session/persist.js +10 -0
  333. package/dist/session/startup-session.d.ts +11 -2
  334. package/dist/session/startup-session.js +12 -2
  335. package/dist/session/validate-session.js +31 -0
  336. package/dist/team/runtime.d.ts +16 -0
  337. package/dist/team/runtime.js +29 -0
  338. package/dist/team/subagent.d.ts +55 -0
  339. package/dist/team/subagent.js +46 -2
  340. package/dist/tools/index.d.ts +60 -2
  341. package/dist/tools/index.js +68 -10
  342. package/package.json +3 -3
  343. package/skills/project-indexer/SKILL.md +275 -147
  344. package/skills/project-indexer/templates/artifact-hygiene-template.md +14 -0
  345. package/skills/project-indexer/templates/config-template.md +12 -0
  346. package/skills/project-indexer/templates/index-template.md +4 -0
@@ -67,8 +67,9 @@ function powersSection() {
67
67
  '',
68
68
  'Your tools: gov_run, gov_dispatch, ask_user, todo_write, and every tool that only reads',
69
69
  '(read_file, list_dir, glob, grep, skill, skill_find, bash_output, job_wait, job_list).',
70
- 'write_file, edit_file, bash, bash_kill, skill_install, skill_create, memory_write and task are',
71
- 'refused in this mode on purpose: all implementation happens through dispatched agents.',
70
+ 'write_file, edit_file, bash, bash_kill, skill_install, skill_create, memory_write, gene_run',
71
+ 'and task are refused in this mode on purpose: all implementation happens through dispatched',
72
+ 'agents.',
72
73
  ];
73
74
  }
74
75
  function startSteps(maxWorkPackages) {
@@ -87,6 +87,14 @@ export declare function makeController(flags: CliFlags, opts?: {
87
87
  * Absent for every caller except a bridge run's `makeExecController`.
88
88
  */
89
89
  hookRunner?: ToolHookRunner;
90
+ /**
91
+ * `--redteam`: build this session ARMED (red-team-security-mode 4.8).
92
+ *
93
+ * SET BY `runInteractive` ONLY, from the launch decision `validateRedTeamLaunch` produced.
94
+ * Absent everywhere else - `-p`, `aragon exec`, every subcommand - which is what keeps those
95
+ * sessions' prompts and tools byte-identical (I-1).
96
+ */
97
+ redTeamArmed?: boolean;
90
98
  }): {
91
99
  controller: AgentController;
92
100
  confirmBridge: ConfirmBridge;
@@ -120,6 +120,10 @@ export function makeController(flags, opts = { interactive: true }) {
120
120
  ? { structuredResultBlock: opts.structuredResultBlock }
121
121
  : {}),
122
122
  ...(opts.hookRunner ? { hookRunner: opts.hookRunner } : {}),
123
+ // `--redteam` (red-team-security-mode 4.8). SPREAD, so a launch without the flag builds the
124
+ // deps bag it always did; the value is already the output of `validateRedTeamLaunch`, which
125
+ // is the only place allowed to refuse it.
126
+ ...(opts.redTeamArmed === true ? { redTeamArmed: true } : {}),
123
127
  });
124
128
  return { controller, confirmBridge, humanInputBridge };
125
129
  }
@@ -143,6 +147,9 @@ export function createSessionWriter(input) {
143
147
  readAcceptance: () => controller.getAcceptanceItems(),
144
148
  // Mounts and switches only - ids, never text (agent-memory I-18).
145
149
  readMemory: () => controller.getMemoryService()?.exportState(),
150
+ // The armed flag and the waiver version, read at write time: a user can arm or disarm
151
+ // between two checkpoints (red-team-security-mode 4.10).
152
+ readRedTeam: () => controller.getRedTeamSessionState(),
146
153
  // READ AT WRITE TIME: `/model` rebuilds the config, and a checkpoint that
147
154
  // recorded the model from launch would name the wrong one after a switch.
148
155
  readModel: () => {
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Gene Bank facade: the one surface a GUI host (the Electron desktop app) may depend on for the
3
+ * gene library (gene-bank spec 12.6, 15.3).
4
+ *
5
+ * Same contract as `memory.ts`: a RE-EXPORT, on purpose. The manager is the very object the
6
+ * terminal overlay is handed, so the desktop reads and writes the same library through the same
7
+ * version service; a wrapper that re-implemented any of that would drift.
8
+ *
9
+ * ASCII ONLY - the whole `gene/` tree and its facade are in `glyphs.test.ts::inScope`.
10
+ *
11
+ * Nothing re-exported may pull `ink`, `react` or `@aragon-agent/tui/ui/**` into the import
12
+ * closure (layering rule L9): a host process has no TTY. `verify:layering` checks it.
13
+ *
14
+ * - `createGeneManager` the `GeneManagerPort` implementation (per session: cwd + session id).
15
+ * - `redactSecrets` the main process runs evidence text through it a second time before
16
+ * the text crosses to the renderer (defence in depth, spec 16.6).
17
+ * - `getGeneDir` the library root, for the subscription-scoped change watcher.
18
+ * - `isValidGeneId` / `isValidScope` the id shapes the main process restates at its IPC edge;
19
+ * a test compares the restated shapes against these.
20
+ */
21
+ export { createGeneManager } from '../gene/manager.js';
22
+ export type { GeneManagerOptions } from '../gene/manager.js';
23
+ export { redactSecrets } from '../gene/secrets.js';
24
+ export type { Redaction } from '../gene/secrets.js';
25
+ export { getGeneDir } from '../gene/paths.js';
26
+ export { isValidGeneId, isValidScope } from '@aragon-agent/tui/model/gene/ids';
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Gene Bank facade: the one surface a GUI host (the Electron desktop app) may depend on for the
3
+ * gene library (gene-bank spec 12.6, 15.3).
4
+ *
5
+ * Same contract as `memory.ts`: a RE-EXPORT, on purpose. The manager is the very object the
6
+ * terminal overlay is handed, so the desktop reads and writes the same library through the same
7
+ * version service; a wrapper that re-implemented any of that would drift.
8
+ *
9
+ * ASCII ONLY - the whole `gene/` tree and its facade are in `glyphs.test.ts::inScope`.
10
+ *
11
+ * Nothing re-exported may pull `ink`, `react` or `@aragon-agent/tui/ui/**` into the import
12
+ * closure (layering rule L9): a host process has no TTY. `verify:layering` checks it.
13
+ *
14
+ * - `createGeneManager` the `GeneManagerPort` implementation (per session: cwd + session id).
15
+ * - `redactSecrets` the main process runs evidence text through it a second time before
16
+ * the text crosses to the renderer (defence in depth, spec 16.6).
17
+ * - `getGeneDir` the library root, for the subscription-scoped change watcher.
18
+ * - `isValidGeneId` / `isValidScope` the id shapes the main process restates at its IPC edge;
19
+ * a test compares the restated shapes against these.
20
+ */
21
+ export { createGeneManager } from '../gene/manager.js';
22
+ export { redactSecrets } from '../gene/secrets.js';
23
+ export { getGeneDir } from '../gene/paths.js';
24
+ export { isValidGeneId, isValidScope } from '@aragon-agent/tui/model/gene/ids';
@@ -17,6 +17,7 @@ export * from './interaction.js';
17
17
  export * from './logging.js';
18
18
  export * from './prompts.js';
19
19
  export * from './memory.js';
20
+ export * from './gene.js';
20
21
  export * from './sessions.js';
21
22
  export * from './settings.js';
22
23
  export * from './commands.js';
@@ -17,6 +17,7 @@ export * from './interaction.js';
17
17
  export * from './logging.js';
18
18
  export * from './prompts.js';
19
19
  export * from './memory.js';
20
+ export * from './gene.js';
20
21
  export * from './sessions.js';
21
22
  export * from './settings.js';
22
23
  export * from './commands.js';
@@ -73,6 +73,16 @@ export interface CheckpointDeps {
73
73
  * so a session that never touched memory writes no key and a file identical to today's.
74
74
  */
75
75
  readMemory?(): MemorySessionState | undefined;
76
+ /**
77
+ * Red team mode's armed state and the waiver version it was armed under
78
+ * (red-team-security-mode 4.10). OPTIONAL for the reason `readMemory` is: a caller that has no
79
+ * red team chain writes no key at all, and every existing test double keeps compiling.
80
+ *
81
+ * NOT IN THE CHANGE PLAN, AND HAS TO BE HERE ANYWAY: the spec expected `saveSession` to be one
82
+ * call site, but the TUI's route to it is this writer. Recorded in the spec's
83
+ * implementation findings.
84
+ */
85
+ readRedTeam?(): RedTeamSessionState | undefined;
76
86
  readModel(): ModelRef;
77
87
  /** `meta.cwd`; read at every write because `/cwd` can change it. */
78
88
  readCwd(): string;
@@ -280,3 +290,8 @@ export declare class SessionCheckpointWriter {
280
290
  */
281
291
  private fingerprint;
282
292
  }
293
+ /** The armed half of the red team posture, as `saveSession` wants it. */
294
+ export interface RedTeamSessionState {
295
+ armed: boolean;
296
+ waiverVersion?: number;
297
+ }
@@ -328,6 +328,10 @@ export class SessionCheckpointWriter {
328
328
  ? { acceptance: this.deps.readAcceptance() }
329
329
  : {}),
330
330
  ...memoryField(this.deps.readMemory?.()),
331
+ // The red team posture travels with the checkpoint (red-team-security-mode 4.10), read at
332
+ // WRITE TIME because a user can arm or disarm between two checkpoints. Absent - the whole
333
+ // object - for a session without the chain, so those files are byte-identical to today's.
334
+ ...redTeamField(this.deps.readRedTeam?.()),
331
335
  meta: this.buildMeta(input),
332
336
  };
333
337
  try {
@@ -552,3 +556,17 @@ function followUpFingerprint(followUp) {
552
556
  function memoryField(state) {
553
557
  return state === undefined ? {} : { memory: state };
554
558
  }
559
+ /**
560
+ * `{ redTeam, redTeamWaiverVersion }` only while ARMED, so a session that never used the mode
561
+ * writes neither key and its file is byte-identical to one from before the feature (4.10).
562
+ */
563
+ function redTeamField(state) {
564
+ if (state?.armed !== true)
565
+ return {};
566
+ return {
567
+ redTeam: true,
568
+ ...(typeof state.waiverVersion === 'number'
569
+ ? { redTeamWaiverVersion: state.waiverVersion }
570
+ : {}),
571
+ };
572
+ }
@@ -145,6 +145,21 @@ export interface SavedSession {
145
145
  * one, and is told apart from an exec file by `meta.origin`.
146
146
  */
147
147
  meta?: SessionMeta;
148
+ /**
149
+ * Red team mode was ARMED at save time (red-team-security-mode 4.10).
150
+ *
151
+ * ADDITIVE AND OPTIONAL, so `SESSION_VERSION` stays 1 for the fifth time: an older file
152
+ * simply yields `undefined`, which restores as disarmed - the right answer for a session that
153
+ * predates the feature. It is a BOOLEAN and not the whole mode: the scope is deliberately
154
+ * absent (D-9 - a target name can itself be the sensitive part of an engagement), and the
155
+ * waiver lives in `state.json` because it is a machine fact (D-3).
156
+ */
157
+ redTeam?: boolean;
158
+ /**
159
+ * The waiver version this session was armed under, for the reconciliation `/resume` does
160
+ * (4.10 / I-12): a file written under version 1 must not silently re-arm under version 2.
161
+ */
162
+ redTeamWaiverVersion?: number;
148
163
  }
149
164
  /** Resolve a `/save` target: absolute/relative path, or a name in the data dir. */
150
165
  export declare function resolveSessionPath(nameOrPath: string | undefined, cwd: string): string;
@@ -175,6 +190,12 @@ export declare function saveSession(filePath: string, data: {
175
190
  /** Omitted when every memory setting is at its default, so such a file is byte-identical. */
176
191
  memory?: MemorySessionState;
177
192
  meta?: SessionMeta;
193
+ /**
194
+ * Red team mode's armed state, ADDED TO `data` AND NOT AS TWO MORE PARAMETERS (RV-14):
195
+ * `saveSession(filePath, data)` takes two positional arguments, the second one this object.
196
+ */
197
+ redTeam?: boolean;
198
+ redTeamWaiverVersion?: number;
178
199
  }): void;
179
200
  /**
180
201
  * Settle any team entry that was saved mid-dispatch (team-subagents §5.3 / P1-5),
@@ -144,6 +144,16 @@ export function saveSession(filePath, data) {
144
144
  : {}),
145
145
  ...(data.memory ? { memory: data.memory } : {}),
146
146
  ...(data.meta ? { meta: data.meta } : {}),
147
+ // WRITTEN ONLY WHEN ARMED, so a session that never used the mode produces a file
148
+ // byte-identical to today's (4.10). The version rides with the flag for the same reason.
149
+ ...(data.redTeam === true
150
+ ? {
151
+ redTeam: true,
152
+ ...(typeof data.redTeamWaiverVersion === 'number'
153
+ ? { redTeamWaiverVersion: data.redTeamWaiverVersion }
154
+ : {}),
155
+ }
156
+ : {}),
147
157
  };
148
158
  writeFileSync(filePath, `${JSON.stringify(payload, null, 2)}\n`, 'utf-8');
149
159
  }
@@ -62,6 +62,15 @@ export interface SessionRestorePort {
62
62
  * compiling, and a headless controller (no memory service) ignores it.
63
63
  */
64
64
  restoreMemory?(state: unknown): void;
65
+ /**
66
+ * The saved red team posture (red-team-security-mode 4.10). OPTIONAL on the port for the same
67
+ * reason the two above are, and it RETURNS WHAT TO TELL THE USER: a session that comes back
68
+ * disarmed because the waiver changed has to say so, or the user will assume the mode stuck.
69
+ */
70
+ restoreRedTeam?(state: {
71
+ armed?: boolean;
72
+ waiverVersion?: number;
73
+ }): string | null;
65
74
  setModel(providerId: string, modelId: string, baseUrl?: string): void;
66
75
  }
67
76
  export type StartupSessionResolution = {
@@ -71,7 +80,7 @@ export type StartupSessionResolution = {
71
80
  notice?: string;
72
81
  /** The file this session was branched from, if any. */
73
82
  saved?: SavedSession;
74
- apply(port: SessionRestorePort): void;
83
+ apply(port: SessionRestorePort): string | null;
75
84
  } | {
76
85
  ok: false;
77
86
  exitCode: 2;
@@ -92,7 +101,7 @@ export type StartupSessionResolution = {
92
101
  */
93
102
  export declare function applyRestoredSession(port: SessionRestorePort, saved: SavedSession, opts?: {
94
103
  skipModel?: boolean;
95
- }): void;
104
+ }): string | null;
96
105
  /**
97
106
  * Work out which session this process is, and what it starts from.
98
107
  *
@@ -47,9 +47,19 @@ export function applyRestoredSession(port, saved, opts = {}) {
47
47
  // Absence means "defaults", exactly as absent todos mean "clear": the file says what the
48
48
  // session had, and a file that predates memory had nothing mounted.
49
49
  port.restoreMemory?.(saved.memory);
50
+ // THE POSTURE, AND THE NOTICE IT MAY PRODUCE (4.10 / I-12). A file that says `redTeam: true`
51
+ // restores the mode only while the waiver it was armed under is still current; otherwise the
52
+ // port answers with the sentence explaining that, which the caller shows.
53
+ const redTeamNotice = port.restoreRedTeam?.({
54
+ ...(saved.redTeam === true ? { armed: true } : {}),
55
+ ...(typeof saved.redTeamWaiverVersion === 'number'
56
+ ? { waiverVersion: saved.redTeamWaiverVersion }
57
+ : {}),
58
+ }) ?? null;
50
59
  if (!opts.skipModel && saved.model?.providerId && saved.model?.modelId) {
51
60
  port.setModel(saved.model.providerId, saved.model.modelId, saved.model.baseUrl);
52
61
  }
62
+ return redTeamNotice;
53
63
  }
54
64
  /**
55
65
  * Work out which session this process is, and what it starts from.
@@ -84,7 +94,7 @@ function resolveFresh(saveAs) {
84
94
  identity: { id: saveAs, kind: 'named', pinned: true },
85
95
  initialEntries: [],
86
96
  notice: `Session ${saveAs} (pinned). Resume it from any terminal: aragon --resume ${saveAs}`,
87
- apply: () => { },
97
+ apply: () => null,
88
98
  };
89
99
  }
90
100
  // A collision is not a failure for an auto-minted id: another process took the
@@ -97,7 +107,7 @@ function resolveFresh(saveAs) {
97
107
  if (fate === 'unwritable')
98
108
  return unwritable(id);
99
109
  if (fate === 'ok') {
100
- return { ok: true, identity: { id, kind: 'fresh' }, initialEntries: [], apply: () => { } };
110
+ return { ok: true, identity: { id, kind: 'fresh' }, initialEntries: [], apply: () => null };
101
111
  }
102
112
  }
103
113
  return {
@@ -302,9 +302,40 @@ export function validateSession(value) {
302
302
  // small enums survive; the service drops ids that no longer exist when it restores.
303
303
  if (source.memory !== undefined)
304
304
  prepared.memory = sanitizeMemoryState(source.memory);
305
+ // TWO NAMED CASES, NOT A GLOBAL LOOSENING (RV-5 / C-4). `shape()` above does not declare these
306
+ // two fields at all, so a wrong TYPE would ride the spread untouched; the alternative - declaring
307
+ // them as `boolean`/`number` - makes a hand-edited `redTeam: "yes"` throw
308
+ // `Invalid session file: ... must be a boolean`, and `loadSession` then refuses the WHOLE
309
+ // conversation. For a session POSTURE that is a punishment out of all proportion to the mistake:
310
+ // losing a mode costs one keystroke, losing the conversation costs the work. So each field is
311
+ // read on its own and dropped if it cannot be read; every other field's strictness is unchanged.
312
+ const armed = readTolerantBoolean(source.redTeam);
313
+ if (armed === undefined)
314
+ delete prepared.redTeam;
315
+ else
316
+ prepared.redTeam = armed;
317
+ const waiver = readTolerantCount(source.redTeamWaiverVersion);
318
+ if (waiver === undefined)
319
+ delete prepared.redTeamWaiverVersion;
320
+ else
321
+ prepared.redTeamWaiverVersion = waiver;
305
322
  prepared.entries = sanitizeGovernanceEntries(sanitizeEntryAcceptance(prepared.entries));
306
323
  return prepared;
307
324
  }
325
+ /** A boolean, or `undefined`. Anything else reads as "the file did not say". */
326
+ function readTolerantBoolean(value) {
327
+ if (value === true)
328
+ return true;
329
+ if (value === false)
330
+ return false;
331
+ return undefined;
332
+ }
333
+ /** A non-negative integer, or `undefined`. Anything else reads as "the file did not say". */
334
+ function readTolerantCount(value) {
335
+ if (typeof value !== 'number' || !Number.isFinite(value) || value < 0)
336
+ return undefined;
337
+ return Math.floor(value);
338
+ }
308
339
  /**
309
340
  * `meta`, repaired field by field - and `meta.followUp` in particular (desktop-follow-up-panel
310
341
  * 8.3).
@@ -65,6 +65,17 @@ export interface TeamRuntimeDeps {
65
65
  sourceNames: string[];
66
66
  }) => void;
67
67
  humanQueue?: TeamHumanQueue;
68
+ /**
69
+ * The lead's red team bypass predicate and its audit sink, forwarded to every child
70
+ * (red-team-security-mode D-16 / RV-2).
71
+ *
72
+ * ABSENT ON EVERY NON-RED-TEAM SESSION, which keeps `SubagentDeps` the object it was - the
73
+ * conditional-spread discipline the four lines below record, applied to a security control.
74
+ */
75
+ confirmBypass?: SubagentDeps['confirmBypass'];
76
+ onConfirmBypass?: SubagentDeps['onConfirmBypass'];
77
+ /** The child's trimmed `<redteam_mode>` block, forwarded; absent means no block. */
78
+ redteamBlock?: SubagentDeps['redteamBlock'];
68
79
  /**
69
80
  * The lead's caller-approval gate, one instance per child (headless-host-bridge
70
81
  * section 2.3.7). Absent outside bridge mode, which is what keeps a dispatch's
@@ -112,6 +123,11 @@ export interface TeamRuntimeDeps {
112
123
  * as before.
113
124
  */
114
125
  imageSupportFor?: SubagentDeps['imageSupportFor'];
126
+ /**
127
+ * The gene library for children, passed straight through to `SubagentDeps` (gene-bank 9.7).
128
+ * ABSENT when the library is off, which leaves every child built as before.
129
+ */
130
+ geneTools?: SubagentDeps['geneTools'];
115
131
  }
116
132
  export declare class TeamRuntime {
117
133
  private readonly deps;
@@ -405,6 +405,20 @@ export class TeamRuntime {
405
405
  this.quietNotified.clear();
406
406
  this.overseerDegraded = false;
407
407
  this.overseerDegradedTicks = 0;
408
+ // THE GENE ZONES ARE PLANNED HERE, ONCE, BEFORE ANY CHILD EXISTS (gene-bank 9.6): planning is
409
+ // asynchronous and a child's system prompt is built synchronously, so the awaiting has to
410
+ // happen first. `busy` is already latched, so a second dispatch cannot interleave. A retry
411
+ // (F-4) rebuilds a child from the SAME `subDeps` and so reads the same text - "computed once".
412
+ // The hook never throws; the catch is for a host closure that breaks that promise.
413
+ const planned = this.deps.geneTools?.prepare !== undefined;
414
+ if (this.deps.geneTools?.prepare) {
415
+ try {
416
+ await this.deps.geneTools.prepare(specs);
417
+ }
418
+ catch {
419
+ // No zone for this dispatch; the children are built without one.
420
+ }
421
+ }
408
422
  // THE SUPERVISOR IS CREATED PER DISPATCH (R-P0-2): provider wired AND
409
423
  // policy on. `TeamOverseer.isActive()` re-checks the provider per
410
424
  // inspection and per tick, so a mid-dispatch `/fast off` degrades the
@@ -501,6 +515,12 @@ export class TeamRuntime {
501
515
  : {}),
502
516
  confirmTools: config.confirmTools,
503
517
  ...(this.deps.humanQueue ? { humanQueue: this.deps.humanQueue } : {}),
518
+ // SITE TWO OF TWO for the red team predicate, in the shape every line around it records:
519
+ // declared on `TeamRuntimeDeps` and forgotten here, a child would keep its own bypass
520
+ // closed (or worse, the lead's open) with nothing to report it (RV-2 / R-5).
521
+ ...(this.deps.confirmBypass ? { confirmBypass: this.deps.confirmBypass } : {}),
522
+ ...(this.deps.onConfirmBypass ? { onConfirmBypass: this.deps.onConfirmBypass } : {}),
523
+ ...(this.deps.redteamBlock ? { redteamBlock: this.deps.redteamBlock } : {}),
504
524
  // Site two of two, in the same shape as the policy and compaction lines
505
525
  // around it: declaring it on `TeamRuntimeDeps` and forgetting this line
506
526
  // type-checks and forwards nothing, and the failure is silent - every child
@@ -531,6 +551,10 @@ export class TeamRuntime {
531
551
  // others): declared above and not forwarded here, it type-checks and every child keeps
532
552
  // the pre-feature `read_file`, with no error anywhere.
533
553
  ...(this.deps.imageSupportFor ? { imageSupportFor: this.deps.imageSupportFor } : {}),
554
+ // Site two of three for the gene library (the controller and `TeamRuntimeDeps` are the
555
+ // others): declared above and not forwarded here, it type-checks and every child quietly runs
556
+ // without the library, with nothing to say so.
557
+ ...(this.deps.geneTools ? { geneTools: this.deps.geneTools } : {}),
534
558
  // Same conditional-spread rule: a dispatch without a supervisor builds
535
559
  // the exact pre-feature `SubagentDeps`, and the child's idle watchdog
536
560
  // keeps its un-lengthened ceiling (team-overseer §3.6).
@@ -581,6 +605,11 @@ export class TeamRuntime {
581
605
  // than a consequence of signal plumbing three modules away.
582
606
  const onAbort = () => this.abortAll();
583
607
  signal?.addEventListener('abort', onAbort, { once: true });
608
+ // An abort that arrived while the gene zones were being planned fired before the listener
609
+ // existed; a listener added to an already-aborted signal never runs. Only when planning
610
+ // actually awaited, so every other dispatch behaves exactly as it did.
611
+ if (planned && signal?.aborted === true)
612
+ onAbort();
584
613
  // The dispatch ceiling has to be enforced HERE as well as through
585
614
  // `toolTimeoutOverrides.task`: the executor's timeout is COOPERATIVE (I-2),
586
615
  // so the override only bites because `task` listens to `ctx.signal` — and a
@@ -15,6 +15,8 @@ import { type AgentConfig, type AgentEvent, type AgentTool, type Message, type M
15
15
  import type { AgentMode } from '@aragon-agent/tui/model/agent/agent-mode';
16
16
  import type { ChildContextManagerProvider } from '../compaction/child.js';
17
17
  import type { ImageSupport } from '../agent/image-support.js';
18
+ import type { GeneHintEngine } from '../gene/hints.js';
19
+ import { type GeneToolAccess } from '../gene/tools.js';
18
20
  import type { ToolGate } from '../tools/tool-gate.js';
19
21
  import type { CliConfig } from '@aragon-agent/tui/model/config/schema';
20
22
  import type { ToolPermission } from '../exec/permission.js';
@@ -97,6 +99,27 @@ export interface SubagentDeps {
97
99
  sourceNames: string[];
98
100
  }) => void;
99
101
  confirmTools: boolean;
102
+ /**
103
+ * The lead's red team bypass predicate, passed DOWN rather than shared
104
+ * (red-team-security-mode D-16 / RV-2).
105
+ *
106
+ * IT CANNOT BE INHERITED AUTOMATICALLY, and v1 assumed it could: this module builds its OWN
107
+ * `confirm` closure two fields above (`humanQueue.request`), not the lead's, so "the same
108
+ * wrapper is in place" is false. Without this predicate one `task` call walks around the arm
109
+ * state, and a child that writes files then runs with a permission the session says it has
110
+ * switched off - a hole rather than a switch (R-5).
111
+ */
112
+ confirmBypass?: () => boolean;
113
+ /** The audit sink for a bypassed child call; same contract as the lead's. */
114
+ onConfirmBypass?: (tool: string) => void;
115
+ /**
116
+ * The child's trimmed `<redteam_mode>` block, or `''` (D-8 / D-16).
117
+ *
118
+ * A FUNCTION because the block changes with the posture and the scope, and a child is built
119
+ * per dispatch. Absent on every session without the mode, which is what keeps a child's
120
+ * system prompt byte-identical to today's (I-1).
121
+ */
122
+ redteamBlock?: () => string;
100
123
  /** Present only when `--confirm` is on AND a human channel exists. */
101
124
  humanQueue?: TeamHumanQueue;
102
125
  agentFactory: SubagentAgentFactory;
@@ -176,6 +199,38 @@ export interface SubagentDeps {
176
199
  * forgetting another type-checks and forwards nothing.
177
200
  */
178
201
  imageSupportFor?: (ref: ModelRef) => ImageSupport;
202
+ /**
203
+ * The gene library for a child (gene-bank 9.6 / 9.7). ABSENT unless the library is on, and a
204
+ * child is then built exactly as it was: no gene tool, no rules block, no context zone (I-20).
205
+ * Three sites forward it, like every dep above: `TeamRuntimeDeps`, the `SubagentDeps` literal
206
+ * in `runtime.ts`, and the controller.
207
+ *
208
+ * The children SHARE the process's one `GeneService` (one index, one usage recorder) and keep
209
+ * their own task context; what differs per child is the `GeneActor` the host's closure builds
210
+ * from `spec.label` (the `agent` tag on usage events) and the context zone, which is computed
211
+ * ONCE at dispatch from the task brief and never refreshed mid-run (9.3).
212
+ */
213
+ geneTools?: SubagentGeneDeps;
214
+ }
215
+ export interface SubagentGeneDeps {
216
+ /**
217
+ * Called once per dispatch BEFORE any child is built, so the static `<gene_context>` of every
218
+ * spec can be planned (the plan is asynchronous, a child's system prompt is not). Never
219
+ * throws; a failure just leaves the zone empty.
220
+ */
221
+ prepare?: (specs: readonly SubagentSpec[]) => Promise<void>;
222
+ /**
223
+ * The child's gene tools. `access` reads the child's FINAL tool array lazily: its `bash` is
224
+ * the fully gated (and, for a governed inspector, restricted) one, which is what `gene_run`
225
+ * must delegate to. `[]` means this child gets none.
226
+ */
227
+ toolsFor: (spec: SubagentSpec, access: GeneToolAccess) => AgentTool[];
228
+ /** The child's stage-hint engine, if any; decorates the child's built-in tools. */
229
+ hintsFor?: (spec: SubagentSpec) => GeneHintEngine | undefined;
230
+ /** The `<gene_library>` rules block for the child's final tool names; '' when it cannot use it. */
231
+ rulesBlock: (toolNames: readonly string[]) => string;
232
+ /** The static `<gene_context>` zone planned for this label by `prepare`; '' when none. */
233
+ contextFor: (label: string) => string;
179
234
  }
180
235
  export interface SubagentHooks {
181
236
  /** Coalesced at the source (§5.2); phase transitions always pass. */
@@ -16,6 +16,7 @@ import { buildSystemPrompt } from '../agent/system-prompt.js';
16
16
  import { buildImageInputBlock } from '../agent/image-input-prompt.js';
17
17
  import { makeImageProjection } from '../agent/image-history.js';
18
18
  import { buildFastBlock } from '../fast/prompt.js';
19
+ import { createToolAccess, withoutOrphanGeneRun } from '../gene/tools.js';
19
20
  import { createBuiltinTools, gatedToolTimeouts, } from '../tools/index.js';
20
21
  import { ledgerPathKey, normalizeLedgerPath } from './report.js';
21
22
  import { describeToolActivity, pickActivityArgs, sanitizeActivity } from '@aragon-agent/tui/model/team/activity';
@@ -88,9 +89,18 @@ getModel) {
88
89
  ];
89
90
  const extras = deps.extraToolsFor?.(spec) ?? [];
90
91
  const imageSupportFor = deps.imageSupportFor;
92
+ // The gene tools delegate to this child's own FINAL `bash`, which does not exist yet: the holder
93
+ // is filled in at the end of this function and read lazily at call time.
94
+ const finalTools = { current: [] };
95
+ const geneTools = deps.geneTools?.toolsFor(spec, createToolAccess(() => finalTools.current)) ?? [];
96
+ const geneHints = deps.geneTools?.hintsFor?.(spec);
91
97
  const built = createBuiltinTools({
92
98
  getCwd: deps.getCwd,
93
99
  confirmTools: deps.confirmTools,
100
+ // THE EXPLICIT HAND-OVER (RV-2): the child's own confirm closure is built below, so the
101
+ // bypass has to be passed as a PREDICATE, not assumed to arrive with the wrapper.
102
+ ...(deps.confirmBypass ? { confirmBypass: deps.confirmBypass } : {}),
103
+ ...(deps.onConfirmBypass ? { onConfirmBypass: deps.onConfirmBypass } : {}),
94
104
  // Only when BOTH halves exist; either missing and the child's `read_file` is the old one.
95
105
  ...(imageSupportFor && getModel
96
106
  ? {
@@ -174,6 +184,11 @@ getModel) {
174
184
  // Role tools ride the same slot as the comm tools (governance-mode 14.3). A spread
175
185
  // only when a governed dispatch supplied some, so every other child is unchanged.
176
186
  teamTools: extras.length > 0 ? [...commTools, ...extras] : commTools,
187
+ // Spread only for a child that was handed the library, so every other child's options bag (and
188
+ // therefore its tool array) is the one it always was. The tools join INSIDE the factory so the
189
+ // plan gate, the ceiling and the permission filter wrap `gene_run` exactly like `bash`.
190
+ ...(geneTools.length > 0 ? { geneTools } : {}),
191
+ ...(geneHints ? { geneHints } : {}),
177
192
  // `spec.readOnly` forces the plan gate on for this child even in a BUILD
178
193
  // session. TIGHTENING ONLY (D-13): there is no field anywhere that gives a
179
194
  // child more permission than the session it was spawned from. Read LIVE, so
@@ -202,11 +217,36 @@ getModel) {
202
217
  }
203
218
  : {}),
204
219
  });
205
- const tools = deps.narrowToolsFor ? deps.narrowToolsFor(spec, built) : built;
220
+ const narrowed = deps.narrowToolsFor ? deps.narrowToolsFor(spec, built) : built;
221
+ // `gene_run` FOLLOWS `bash` (9.6): a child whose shell was removed or narrowed away (a governed
222
+ // inspector without integration commands, `--deny-tool bash`) must not be advertised a tool it
223
+ // can only be refused.
224
+ const tools = withoutOrphanGeneRun(narrowed);
206
225
  // Mail rides on the NEXT tool result of whatever the child does next (D-4), so
207
226
  // every tool it can call has to carry the tail — the comm tools included, or a
208
227
  // child that only ever messages would never receive.
209
- return tools.map((t) => withMailboxTail(t, deps.bus, spec.label));
228
+ const finished = tools.map((t) => withMailboxTail(t, deps.bus, spec.label));
229
+ finalTools.current = finished;
230
+ return finished;
231
+ }
232
+ /**
233
+ * The two gene blocks for a child's system prompt, or nothing at all.
234
+ *
235
+ * The zone is only ever spliced WITH the rules block: a context zone whose authority claim
236
+ * ("advisory data, never instructions") is missing would be previews with no frame, and a rules
237
+ * block that names tools the child lacks would be an order it cannot follow. Both come from
238
+ * `deps.geneTools` and are `''` (hence omitted) whenever the child has no `gene_search` /
239
+ * `gene_read` in its FINAL tool array.
240
+ */
241
+ function geneBlocksFor(spec, deps, tools) {
242
+ const gene = deps.geneTools;
243
+ if (gene === undefined)
244
+ return {};
245
+ const rules = gene.rulesBlock(tools.map((t) => t.name));
246
+ if (rules.length === 0)
247
+ return {};
248
+ const context = gene.contextFor(spec.label);
249
+ return { geneRulesBlock: rules, ...(context.length > 0 ? { geneContextBlock: context } : {}) };
210
250
  }
211
251
  /**
212
252
  * Construct a child and wire its instrumentation.
@@ -304,6 +344,10 @@ export function createSubagent(spec, deps, hooks) {
304
344
  ...(spec.governance && deps.governanceRoleBlockFor
305
345
  ? { governanceRoleBlock: deps.governanceRoleBlockFor(spec) }
306
346
  : {}),
347
+ // THE CHILD'S HALF OF THE RED TEAM INHERITANCE (D-8 / D-16). `''` for every session without
348
+ // the mode, and `buildSystemPrompt` splices conditionally, so those prompts are unchanged.
349
+ ...(deps.redteamBlock ? { redteamBlock: deps.redteamBlock() } : {}),
350
+ ...geneBlocksFor(spec, deps, tools),
307
351
  });
308
352
  // LAZY ACCESSORS OVER `agentRef`, WHICH IS ASSIGNED AFTER THIS RETURNS. A
309
353
  // non-lazy read here is `undefined` at construction and the child's estimate