@aragon-agent/cli 0.6.55 → 0.6.57

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 (319) hide show
  1. package/CHANGELOG.md +2935 -2864
  2. package/README.md +160 -45
  3. package/dist/agent/controller.d.ts +47 -0
  4. package/dist/agent/controller.js +153 -2
  5. package/dist/agent/governance-wiring.js +8 -1
  6. package/dist/agent/system-prompt.d.ts +26 -0
  7. package/dist/agent/system-prompt.js +11 -0
  8. package/dist/app/App.js +101 -3
  9. package/dist/cli.js +29 -1
  10. package/dist/commands/builtins.js +4 -0
  11. package/dist/commands/catalog.js +1 -0
  12. package/dist/commands/registry.d.ts +8 -0
  13. package/dist/config/app-paths.d.ts +10 -0
  14. package/dist/config/app-paths.js +12 -0
  15. package/dist/config/cli-commands.d.ts +29 -0
  16. package/dist/config/cli-commands.js +76 -1
  17. package/dist/config/env.d.ts +2 -1
  18. package/dist/config/env.js +12 -1
  19. package/dist/config/load.d.ts +10 -0
  20. package/dist/config/load.js +13 -2
  21. package/dist/config/store.js +11 -1
  22. package/dist/exec/bridge/server.d.ts +7 -0
  23. package/dist/exec/bridge/server.js +6 -2
  24. package/dist/exec/cli-commands.js +4 -0
  25. package/dist/exec/index.js +2 -0
  26. package/dist/exec/options.d.ts +11 -0
  27. package/dist/exec/options.js +21 -1
  28. package/dist/gene/block.d.ts +33 -0
  29. package/dist/gene/block.js +51 -0
  30. package/dist/gene/capacity.d.ts +74 -0
  31. package/dist/gene/capacity.js +169 -0
  32. package/dist/gene/catalog-reconcile.d.ts +13 -0
  33. package/dist/gene/catalog-reconcile.js +105 -0
  34. package/dist/gene/catalog-stats.d.ts +27 -0
  35. package/dist/gene/catalog-stats.js +89 -0
  36. package/dist/gene/catalog-sync.d.ts +82 -0
  37. package/dist/gene/catalog-sync.js +324 -0
  38. package/dist/gene/catalog.d.ts +160 -0
  39. package/dist/gene/catalog.js +433 -0
  40. package/dist/gene/cli-commands.d.ts +50 -0
  41. package/dist/gene/cli-commands.js +500 -0
  42. package/dist/gene/command-report.d.ts +40 -0
  43. package/dist/gene/command-report.js +246 -0
  44. package/dist/gene/command.d.ts +29 -0
  45. package/dist/gene/command.js +561 -0
  46. package/dist/gene/commit-apply-types.d.ts +13 -0
  47. package/dist/gene/commit-apply-types.js +1 -0
  48. package/dist/gene/commit-compound.d.ts +34 -0
  49. package/dist/gene/commit-compound.js +212 -0
  50. package/dist/gene/commit-counts.d.ts +41 -0
  51. package/dist/gene/commit-counts.js +70 -0
  52. package/dist/gene/commit-exec.d.ts +42 -0
  53. package/dist/gene/commit-exec.js +134 -0
  54. package/dist/gene/commit-head.d.ts +52 -0
  55. package/dist/gene/commit-head.js +97 -0
  56. package/dist/gene/commit-plan.d.ts +95 -0
  57. package/dist/gene/commit-plan.js +68 -0
  58. package/dist/gene/commit-prepare.d.ts +63 -0
  59. package/dist/gene/commit-prepare.js +159 -0
  60. package/dist/gene/commit-types.d.ts +234 -0
  61. package/dist/gene/commit-types.js +3 -0
  62. package/dist/gene/curator/agent.d.ts +137 -0
  63. package/dist/gene/curator/agent.js +203 -0
  64. package/dist/gene/curator/budget.d.ts +69 -0
  65. package/dist/gene/curator/budget.js +131 -0
  66. package/dist/gene/curator/conflicts.d.ts +54 -0
  67. package/dist/gene/curator/conflicts.js +143 -0
  68. package/dist/gene/curator/curator.d.ts +170 -0
  69. package/dist/gene/curator/curator.js +617 -0
  70. package/dist/gene/curator/deps.d.ts +34 -0
  71. package/dist/gene/curator/deps.js +48 -0
  72. package/dist/gene/curator/deterministic.d.ts +62 -0
  73. package/dist/gene/curator/deterministic.js +287 -0
  74. package/dist/gene/curator/executors.d.ts +36 -0
  75. package/dist/gene/curator/executors.js +379 -0
  76. package/dist/gene/curator/lanes.d.ts +52 -0
  77. package/dist/gene/curator/lanes.js +99 -0
  78. package/dist/gene/curator/lease.d.ts +76 -0
  79. package/dist/gene/curator/lease.js +171 -0
  80. package/dist/gene/curator/library.d.ts +36 -0
  81. package/dist/gene/curator/library.js +169 -0
  82. package/dist/gene/curator/lifecycle.d.ts +52 -0
  83. package/dist/gene/curator/lifecycle.js +109 -0
  84. package/dist/gene/curator/maintenance.d.ts +71 -0
  85. package/dist/gene/curator/maintenance.js +213 -0
  86. package/dist/gene/curator/probation.d.ts +51 -0
  87. package/dist/gene/curator/probation.js +71 -0
  88. package/dist/gene/curator/probe.d.ts +131 -0
  89. package/dist/gene/curator/probe.js +534 -0
  90. package/dist/gene/curator/prompt.d.ts +18 -0
  91. package/dist/gene/curator/prompt.js +128 -0
  92. package/dist/gene/curator/publish.d.ts +64 -0
  93. package/dist/gene/curator/publish.js +113 -0
  94. package/dist/gene/curator/recheck.d.ts +55 -0
  95. package/dist/gene/curator/recheck.js +104 -0
  96. package/dist/gene/curator/run-events.d.ts +63 -0
  97. package/dist/gene/curator/run-events.js +55 -0
  98. package/dist/gene/curator/similarity.d.ts +13 -0
  99. package/dist/gene/curator/similarity.js +46 -0
  100. package/dist/gene/curator/switches.d.ts +78 -0
  101. package/dist/gene/curator/switches.js +146 -0
  102. package/dist/gene/curator/task-context.d.ts +93 -0
  103. package/dist/gene/curator/task-context.js +63 -0
  104. package/dist/gene/curator/task-runner.d.ts +56 -0
  105. package/dist/gene/curator/task-runner.js +257 -0
  106. package/dist/gene/curator/tool-support.d.ts +112 -0
  107. package/dist/gene/curator/tool-support.js +206 -0
  108. package/dist/gene/curator/toolkit.d.ts +49 -0
  109. package/dist/gene/curator/toolkit.js +104 -0
  110. package/dist/gene/curator/tools-read.d.ts +4 -0
  111. package/dist/gene/curator/tools-read.js +177 -0
  112. package/dist/gene/curator/tools-release.d.ts +73 -0
  113. package/dist/gene/curator/tools-release.js +287 -0
  114. package/dist/gene/curator/tools-verify.d.ts +47 -0
  115. package/dist/gene/curator/tools-verify.js +243 -0
  116. package/dist/gene/curator/tools-write.d.ts +26 -0
  117. package/dist/gene/curator/tools-write.js +434 -0
  118. package/dist/gene/curator/tools.d.ts +23 -0
  119. package/dist/gene/curator/tools.js +21 -0
  120. package/dist/gene/curator/validate/common.d.ts +87 -0
  121. package/dist/gene/curator/validate/common.js +132 -0
  122. package/dist/gene/curator/validate/evidence-tokens.d.ts +24 -0
  123. package/dist/gene/curator/validate/evidence-tokens.js +217 -0
  124. package/dist/gene/curator/validate/index.d.ts +23 -0
  125. package/dist/gene/curator/validate/index.js +62 -0
  126. package/dist/gene/curator/validate/knowledge.d.ts +41 -0
  127. package/dist/gene/curator/validate/knowledge.js +255 -0
  128. package/dist/gene/curator/validate/live-check.d.ts +14 -0
  129. package/dist/gene/curator/validate/live-check.js +150 -0
  130. package/dist/gene/curator/validate/ports.d.ts +67 -0
  131. package/dist/gene/curator/validate/ports.js +1 -0
  132. package/dist/gene/curator/validate/prompts.d.ts +41 -0
  133. package/dist/gene/curator/validate/prompts.js +165 -0
  134. package/dist/gene/curator/validate/skill.d.ts +15 -0
  135. package/dist/gene/curator/validate/skill.js +251 -0
  136. package/dist/gene/curator/validate/tool.d.ts +6 -0
  137. package/dist/gene/curator/validate/tool.js +217 -0
  138. package/dist/gene/curator/validate/types.d.ts +90 -0
  139. package/dist/gene/curator/validate/types.js +1 -0
  140. package/dist/gene/curator/validator-ports.d.ts +38 -0
  141. package/dist/gene/curator/validator-ports.js +29 -0
  142. package/dist/gene/diag.d.ts +209 -0
  143. package/dist/gene/diag.js +549 -0
  144. package/dist/gene/env.d.ts +10 -0
  145. package/dist/gene/env.js +214 -0
  146. package/dist/gene/eval-recorder.d.ts +84 -0
  147. package/dist/gene/eval-recorder.js +222 -0
  148. package/dist/gene/explain-transport.d.ts +3 -0
  149. package/dist/gene/explain-transport.js +39 -0
  150. package/dist/gene/explain.d.ts +96 -0
  151. package/dist/gene/explain.js +293 -0
  152. package/dist/gene/fs.d.ts +39 -0
  153. package/dist/gene/fs.js +139 -0
  154. package/dist/gene/fsck.d.ts +68 -0
  155. package/dist/gene/fsck.js +134 -0
  156. package/dist/gene/gc-library-sweeps.d.ts +9 -0
  157. package/dist/gene/gc-library-sweeps.js +220 -0
  158. package/dist/gene/gc-rejected-set.d.ts +15 -0
  159. package/dist/gene/gc-rejected-set.js +63 -0
  160. package/dist/gene/gc-safe.d.ts +12 -0
  161. package/dist/gene/gc-safe.js +74 -0
  162. package/dist/gene/gc-scope-sweeps.d.ts +18 -0
  163. package/dist/gene/gc-scope-sweeps.js +297 -0
  164. package/dist/gene/gc-types.d.ts +55 -0
  165. package/dist/gene/gc-types.js +26 -0
  166. package/dist/gene/gc.d.ts +42 -0
  167. package/dist/gene/gc.js +129 -0
  168. package/dist/gene/gene-errors.d.ts +23 -0
  169. package/dist/gene/gene-errors.js +29 -0
  170. package/dist/gene/hints.d.ts +91 -0
  171. package/dist/gene/hints.js +394 -0
  172. package/dist/gene/hub.d.ts +149 -0
  173. package/dist/gene/hub.js +371 -0
  174. package/dist/gene/import-plan.d.ts +80 -0
  175. package/dist/gene/import-plan.js +294 -0
  176. package/dist/gene/import-proposal.d.ts +23 -0
  177. package/dist/gene/import-proposal.js +101 -0
  178. package/dist/gene/import-skill-port.d.ts +6 -0
  179. package/dist/gene/import-skill-port.js +53 -0
  180. package/dist/gene/import-sources.d.ts +48 -0
  181. package/dist/gene/import-sources.js +140 -0
  182. package/dist/gene/index-writer.d.ts +36 -0
  183. package/dist/gene/index-writer.js +101 -0
  184. package/dist/gene/learn/learn-call.d.ts +116 -0
  185. package/dist/gene/learn/learn-call.js +165 -0
  186. package/dist/gene/learn/learn-prompt.d.ts +58 -0
  187. package/dist/gene/learn/learn-prompt.js +254 -0
  188. package/dist/gene/learn/learner.d.ts +187 -0
  189. package/dist/gene/learn/learner.js +448 -0
  190. package/dist/gene/learn/ledger.d.ts +220 -0
  191. package/dist/gene/learn/ledger.js +394 -0
  192. package/dist/gene/learn/proposal-build.d.ts +83 -0
  193. package/dist/gene/learn/proposal-build.js +207 -0
  194. package/dist/gene/learn/proposal-guard.d.ts +43 -0
  195. package/dist/gene/learn/proposal-guard.js +37 -0
  196. package/dist/gene/learn/signals-port.d.ts +47 -0
  197. package/dist/gene/learn/signals-port.js +86 -0
  198. package/dist/gene/maintenance-paths.d.ts +7 -0
  199. package/dist/gene/maintenance-paths.js +20 -0
  200. package/dist/gene/maintenance-probation.d.ts +33 -0
  201. package/dist/gene/maintenance-probation.js +127 -0
  202. package/dist/gene/maintenance-proposals.d.ts +24 -0
  203. package/dist/gene/maintenance-proposals.js +68 -0
  204. package/dist/gene/maintenance-runner.d.ts +92 -0
  205. package/dist/gene/maintenance-runner.js +262 -0
  206. package/dist/gene/maintenance-tasks.d.ts +37 -0
  207. package/dist/gene/maintenance-tasks.js +95 -0
  208. package/dist/gene/manager-actions.d.ts +12 -0
  209. package/dist/gene/manager-actions.js +279 -0
  210. package/dist/gene/manager-approve.d.ts +29 -0
  211. package/dist/gene/manager-approve.js +84 -0
  212. package/dist/gene/manager-context.d.ts +90 -0
  213. package/dist/gene/manager-context.js +201 -0
  214. package/dist/gene/manager-detail.d.ts +17 -0
  215. package/dist/gene/manager-detail.js +313 -0
  216. package/dist/gene/manager-gc.d.ts +13 -0
  217. package/dist/gene/manager-gc.js +81 -0
  218. package/dist/gene/manager-library.d.ts +39 -0
  219. package/dist/gene/manager-library.js +90 -0
  220. package/dist/gene/manager-list.d.ts +27 -0
  221. package/dist/gene/manager-list.js +170 -0
  222. package/dist/gene/manager-queue.d.ts +16 -0
  223. package/dist/gene/manager-queue.js +124 -0
  224. package/dist/gene/manager-stats.d.ts +28 -0
  225. package/dist/gene/manager-stats.js +53 -0
  226. package/dist/gene/manager-view.d.ts +27 -0
  227. package/dist/gene/manager-view.js +124 -0
  228. package/dist/gene/manager.d.ts +56 -0
  229. package/dist/gene/manager.js +179 -0
  230. package/dist/gene/orphan-scopes.d.ts +37 -0
  231. package/dist/gene/orphan-scopes.js +150 -0
  232. package/dist/gene/paths.d.ts +73 -0
  233. package/dist/gene/paths.js +239 -0
  234. package/dist/gene/plan-content.d.ts +73 -0
  235. package/dist/gene/plan-content.js +522 -0
  236. package/dist/gene/plan-lifecycle.d.ts +29 -0
  237. package/dist/gene/plan-lifecycle.js +310 -0
  238. package/dist/gene/policy.d.ts +71 -0
  239. package/dist/gene/policy.js +313 -0
  240. package/dist/gene/project-learning.d.ts +25 -0
  241. package/dist/gene/project-learning.js +54 -0
  242. package/dist/gene/propagation.d.ts +48 -0
  243. package/dist/gene/propagation.js +45 -0
  244. package/dist/gene/queue-lock.d.ts +22 -0
  245. package/dist/gene/queue-lock.js +99 -0
  246. package/dist/gene/queue-record.d.ts +57 -0
  247. package/dist/gene/queue-record.js +145 -0
  248. package/dist/gene/queue.d.ts +235 -0
  249. package/dist/gene/queue.js +764 -0
  250. package/dist/gene/read.d.ts +61 -0
  251. package/dist/gene/read.js +252 -0
  252. package/dist/gene/runlog.d.ts +101 -0
  253. package/dist/gene/runlog.js +404 -0
  254. package/dist/gene/schema-lite.d.ts +24 -0
  255. package/dist/gene/schema-lite.js +159 -0
  256. package/dist/gene/scope-guard.d.ts +23 -0
  257. package/dist/gene/scope-guard.js +9 -0
  258. package/dist/gene/scope-lock.d.ts +48 -0
  259. package/dist/gene/scope-lock.js +222 -0
  260. package/dist/gene/scope-verify.d.ts +63 -0
  261. package/dist/gene/scope-verify.js +123 -0
  262. package/dist/gene/secrets.d.ts +43 -0
  263. package/dist/gene/secrets.js +161 -0
  264. package/dist/gene/service-context.d.ts +43 -0
  265. package/dist/gene/service-context.js +79 -0
  266. package/dist/gene/service-prepare.d.ts +25 -0
  267. package/dist/gene/service-prepare.js +219 -0
  268. package/dist/gene/service-types.d.ts +196 -0
  269. package/dist/gene/service-types.js +1 -0
  270. package/dist/gene/service-view.d.ts +41 -0
  271. package/dist/gene/service-view.js +69 -0
  272. package/dist/gene/service.d.ts +114 -0
  273. package/dist/gene/service.js +761 -0
  274. package/dist/gene/session-start.d.ts +36 -0
  275. package/dist/gene/session-start.js +212 -0
  276. package/dist/gene/store-port.d.ts +88 -0
  277. package/dist/gene/store-port.js +10 -0
  278. package/dist/gene/store-rows.d.ts +36 -0
  279. package/dist/gene/store-rows.js +72 -0
  280. package/dist/gene/store.d.ts +125 -0
  281. package/dist/gene/store.js +622 -0
  282. package/dist/gene/tombstones.d.ts +47 -0
  283. package/dist/gene/tombstones.js +61 -0
  284. package/dist/gene/tool-runner.d.ts +47 -0
  285. package/dist/gene/tool-runner.js +154 -0
  286. package/dist/gene/tool-screen.d.ts +41 -0
  287. package/dist/gene/tool-screen.js +227 -0
  288. package/dist/gene/tools.d.ts +112 -0
  289. package/dist/gene/tools.js +539 -0
  290. package/dist/gene/transfer.d.ts +85 -0
  291. package/dist/gene/transfer.js +433 -0
  292. package/dist/gene/ui-hints.d.ts +15 -0
  293. package/dist/gene/ui-hints.js +67 -0
  294. package/dist/gene/usage-fold-cursor.d.ts +24 -0
  295. package/dist/gene/usage-fold-cursor.js +115 -0
  296. package/dist/gene/usage-fold.d.ts +49 -0
  297. package/dist/gene/usage-fold.js +397 -0
  298. package/dist/gene/usage.d.ts +67 -0
  299. package/dist/gene/usage.js +231 -0
  300. package/dist/gene/version-service.d.ts +118 -0
  301. package/dist/gene/version-service.js +453 -0
  302. package/dist/gene/wiring-events.d.ts +43 -0
  303. package/dist/gene/wiring-events.js +113 -0
  304. package/dist/gene/wiring-models.d.ts +46 -0
  305. package/dist/gene/wiring-models.js +84 -0
  306. package/dist/gene/wiring.d.ts +200 -0
  307. package/dist/gene/wiring.js +764 -0
  308. package/dist/governance/prompts/orchestrator-block.js +3 -2
  309. package/dist/host/gene.d.ts +26 -0
  310. package/dist/host/gene.js +24 -0
  311. package/dist/host/index.d.ts +1 -0
  312. package/dist/host/index.js +1 -0
  313. package/dist/team/runtime.d.ts +5 -0
  314. package/dist/team/runtime.js +23 -0
  315. package/dist/team/subagent.d.ts +34 -0
  316. package/dist/team/subagent.js +39 -2
  317. package/dist/tools/index.d.ts +36 -2
  318. package/dist/tools/index.js +48 -7
  319. package/package.json +3 -3
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Approving a candidate: the person's path to publication (gene-bank spec 7.6, 10.7.2, 12.2, RV-1,
3
+ * I-25).
4
+ *
5
+ * ASCII ONLY - the whole `gene/` tree is in `glyphs.test.ts::inScope`.
6
+ *
7
+ * `approve` IS A PUBLICATION BY A PERSON, `trust: 'human'`, skipping the curator. For most
8
+ * candidates that is just `publishCandidate`. A TOOL gene is different: the background curator
9
+ * only ever probes a single read-only command on its own, so every other tool (a script, a
10
+ * composite, a command that writes, anything it rated `high`) reaches here still unprobed, with
11
+ * `needsHuman: probe_approval | high_risk_tool`. For those the person's click means
12
+ * "APPROVE AND PROBE": the example runs in the sandbox (`runApprovedProbe`), and only when it
13
+ * passes is the candidate published, with the approval - bound to this exact content hash - and
14
+ * the probe's checks written into its validation.
15
+ *
16
+ * WHAT MAKES THE APPROVAL MEAN SOMETHING. The person was shown the full argv or script
17
+ * (`candidates()` -> `probePreview`) before this is called; the port has no "I read it" field, so
18
+ * that is the UI's contract (the approve button stays disabled until the text was scrolled). What
19
+ * THIS file enforces: the approval carries the hash of the version it saw, so an edit after the
20
+ * click invalidates it (`approval_stale`); the commit carries `expectedVersion`, so a stale view
21
+ * is `GENE_STALE_BASIS`; a failed example publishes NOTHING and names the failing check codes.
22
+ */
23
+ import type { GeneActionOutcome } from '@aragon-agent/tui/model/gene/port';
24
+ import type { GeneResult } from '@aragon-agent/tui/model/gene/types';
25
+ import type { FoundGene, ManagerCore } from './manager-context.js';
26
+ import type { GeneActor, GeneExpect } from './commit-types.js';
27
+ export declare const MANAGER_ACTOR: GeneActor;
28
+ /** `approve`: publish the pending candidate as a person, probing a tool first when it needs it. */
29
+ export declare function approveCandidate(core: ManagerCore, found: FoundGene, expect: GeneExpect | undefined): Promise<GeneResult<GeneActionOutcome>>;
@@ -0,0 +1,84 @@
1
+ import { mergeApprovedProbe, runApprovedProbe, } from './curator/probe.js';
2
+ import { geneFail, geneOk } from './gene-errors.js';
3
+ import { screenToolExec } from './tool-screen.js';
4
+ export const MANAGER_ACTOR = { kind: 'user', label: 'manager' };
5
+ function toolPayloadOf(version) {
6
+ const payload = version.content.payload;
7
+ const isTool = payload.exec !== undefined && typeof payload.risk === 'string';
8
+ return isTool ? payload : null;
9
+ }
10
+ /** Does this candidate need a person-approved probe before it can be published? */
11
+ async function probePlanFor(core, found, candidate) {
12
+ const payload = toolPayloadOf(candidate);
13
+ if (payload === null)
14
+ return null;
15
+ const { scope, read } = found;
16
+ let scriptText;
17
+ if (payload.exec.kind === 'script') {
18
+ const impl = await core.lib.store.readEvidence(scope, read.head.id, payload.exec.evidence);
19
+ scriptText = impl?.text;
20
+ }
21
+ const why = read.head.needsHuman?.reason;
22
+ const flagged = why === 'probe_approval' || why === 'high_risk_tool';
23
+ const screened = screenToolExec(payload.exec, scriptText);
24
+ if (!flagged && screened.autoProbeEligible)
25
+ return null;
26
+ return scriptText === undefined ? { payload } : { payload, scriptText };
27
+ }
28
+ /** The checks that failed, as stable codes: output text never leaves the probe (I-19). */
29
+ function failingCodes(validation) {
30
+ const codes = validation.checks.filter((check) => !check.ok).map((check) => check.code);
31
+ return `probe_failed:${codes.length > 0 ? codes.join(',') : 'unknown'}`;
32
+ }
33
+ async function probeCandidate(core, found, candidate, plan) {
34
+ const approval = {
35
+ by: 'user',
36
+ at: core.now(),
37
+ contentHash: candidate.contentHash,
38
+ };
39
+ const outcome = await runApprovedProbe({ id: found.read.head.id }, candidate, approval, {
40
+ confirmHighRisk: true,
41
+ ...(plan.scriptText === undefined ? {} : { scriptText: plan.scriptText }),
42
+ ...core.options.probe,
43
+ });
44
+ if (!outcome.ok)
45
+ return geneFail(outcome.code, outcome.message, outcome.reason);
46
+ if (!outcome.validation.ok) {
47
+ const message = 'The tool failed its example run, so it was not published.';
48
+ return geneFail('GENE_TOOL_BROKEN', message, failingCodes(outcome.validation));
49
+ }
50
+ const base = candidate.validation ?? { at: core.now(), ok: true, checks: [] };
51
+ return geneOk(mergeApprovedProbe(base, outcome));
52
+ }
53
+ /** `approve`: publish the pending candidate as a person, probing a tool first when it needs it. */
54
+ export async function approveCandidate(core, found, expect) {
55
+ const { scope, read } = found;
56
+ const head = read.head;
57
+ if (found.archived || head.candidateVersion === null) {
58
+ return geneFail('GENE_NOT_FOUND', 'The gene has no candidate to approve.', 'no_candidate');
59
+ }
60
+ const candidate = await core.lib.store.readVersion(scope, head.id, head.candidateVersion);
61
+ if (candidate === null) {
62
+ return geneFail('GENE_NOT_FOUND', 'The candidate version is missing.', 'candidate_missing');
63
+ }
64
+ const plan = await probePlanFor(core, found, candidate);
65
+ let validation;
66
+ if (plan !== null) {
67
+ const probed = await probeCandidate(core, found, candidate, plan);
68
+ if (!probed.ok)
69
+ return probed;
70
+ validation = probed.value;
71
+ }
72
+ const committed = await core.lib.versions.commit({
73
+ op: 'publishCandidate',
74
+ scope,
75
+ id: head.id,
76
+ ...(validation === undefined ? {} : { validation }),
77
+ }, MANAGER_ACTOR, expect);
78
+ if (!committed.ok)
79
+ return committed;
80
+ const out = { id: head.id };
81
+ if (committed.value.version !== undefined)
82
+ out.version = committed.value.version;
83
+ return geneOk(out);
84
+ }
@@ -0,0 +1,90 @@
1
+ import { type GeneConfig } from '@aragon-agent/tui/model/config/schema';
2
+ import type { GeneTarget } from '@aragon-agent/tui/model/gene/port';
3
+ import type { EnvFingerprint, GeneCaller, GeneHead, GeneResult, GeneScope } from '@aragon-agent/tui/model/gene/types';
4
+ import { GeneCatalog } from './catalog.js';
5
+ import { type SharedLibrary } from './manager-library.js';
6
+ import type { ApprovedProbeOptions } from './curator/probe.js';
7
+ import type { ExplainSpend, ExplainTransport } from './explain.js';
8
+ import type { SkillSourcePort } from './import-sources.js';
9
+ import type { HeadRead } from './store-port.js';
10
+ export interface GeneManagerOptions {
11
+ /** Working directory of the session; decides which project scope is "visible". */
12
+ cwd: string;
13
+ sessionId: string;
14
+ /** External read-only team directory from `gene.teamPath`, or ''. */
15
+ teamPath?: string;
16
+ /** Library root override (tests). Defaults to `<home>/genes`. */
17
+ root?: string;
18
+ /** Live gene configuration; defaults to the persisted one, clamped and cached for 2 s. */
19
+ config?: () => GeneConfig;
20
+ /** The user's provider keys, so text holding one is scrubbed by value. Default: the registry. */
21
+ knownSecrets?: () => readonly string[];
22
+ /** Who is running the manager; goes on run records. Default `tui`. */
23
+ kind?: 'tui' | 'desktop' | 'exec';
24
+ /** Allow the one human-approved promotion into the team directory. Default false. */
25
+ teamWritable?: boolean;
26
+ now?: () => number;
27
+ /** The environment the "applies here" line is computed against (tests). */
28
+ env?: () => EnvFingerprint;
29
+ /** Test seams of the sandboxed probe a person approves. Production passes nothing. */
30
+ probe?: ApprovedProbeOptions;
31
+ /** The model an explanation uses. Default: the fast tier of the persisted configuration. */
32
+ explainTransport?: ExplainTransport;
33
+ /** Receives the spend of every explanation (a session routes it into its cost row). */
34
+ onExplainSpend?: (spend: ExplainSpend) => void;
35
+ /** The skills a cold-start import reads. Default: a read-only service over the configuration. */
36
+ skillSources?: () => SkillSourcePort | null;
37
+ /** Deadline of one explanation call in ms (a test seam; default 20 s). */
38
+ explainTimeoutMs?: number;
39
+ /** The terminal's locale string, for `explainLanguage: auto`. Default `LC_ALL` / `LANG`. */
40
+ locale?: () => string;
41
+ }
42
+ export interface ProjectInfo {
43
+ key: string;
44
+ root: string;
45
+ label: string;
46
+ }
47
+ /** The key of the team scope under `gene.teamPath` (the service uses the same default). */
48
+ export declare const TEAM_SCOPE_KEY = "team";
49
+ /** The catalogs built so far, keyed by their scope list; the oldest is dropped past six. */
50
+ export declare class CatalogPool {
51
+ private readonly lib;
52
+ private readonly now;
53
+ private readonly byKey;
54
+ constructor(lib: SharedLibrary, now: () => number);
55
+ /** A catalog over exactly `scopes`, caught up with the disk. Never rejects. */
56
+ acquire(scopes: readonly GeneScope[]): Promise<GeneCatalog>;
57
+ private evict;
58
+ dispose(): void;
59
+ }
60
+ export interface ManagerCore {
61
+ readonly options: GeneManagerOptions;
62
+ readonly lib: SharedLibrary;
63
+ readonly pool: CatalogPool;
64
+ config(): GeneConfig;
65
+ now(): number;
66
+ secrets(): readonly string[];
67
+ project(): ProjectInfo | null;
68
+ visibleScopes(): GeneScope[];
69
+ scopesOf(target: GeneTarget): Promise<GeneResult<GeneScope[]>>;
70
+ env(): EnvFingerprint;
71
+ /** A caller for score explanations: the session's scopes, role `main`, tools not checked. */
72
+ callerFor(scopes: GeneScope[], tools: readonly string[]): GeneCaller;
73
+ }
74
+ /** Build the shared state of one manager. Never throws. */
75
+ export declare function createManagerCore(options: GeneManagerOptions): ManagerCore;
76
+ export interface FoundGene {
77
+ scope: GeneScope;
78
+ read: HeadRead;
79
+ /** The head was in `archive/`, not `genes/`. */
80
+ archived: boolean;
81
+ }
82
+ /**
83
+ * Locate a gene by id among the scopes `target` addresses: live first, then archived. The id is
84
+ * validated before any path is built from it.
85
+ */
86
+ export declare function findGene(core: ManagerCore, target: GeneTarget, id: string): Promise<GeneResult<FoundGene>>;
87
+ /** The version number whose content a head serves: published, else the pending candidate. */
88
+ export declare function servedVersion(head: GeneHead): number;
89
+ /** Run a port method body so that nothing it throws escapes (I-24). */
90
+ export declare function guarded<T>(work: () => Promise<GeneResult<T>>): Promise<GeneResult<T>>;
@@ -0,0 +1,201 @@
1
+ /**
2
+ * What every part of the manager shares: the library handle, the session's identity, the scopes
3
+ * a request addresses and the catalogs built over them (gene-bank spec 11.1, 12.4, 16.6).
4
+ *
5
+ * ASCII ONLY - the whole `gene/` tree is in `glyphs.test.ts::inScope`.
6
+ *
7
+ * THE MANAGER IS THE ONE CONSUMER ALLOWED TO LOAD ANOTHER PROJECT'S SCOPE (11.1). An Agent's
8
+ * `GeneService` only ever loads user + its own project + team + its own task scope, so a filter
9
+ * bug cannot leak another project's genes into a prompt. Here a `GeneTarget` is resolved to an
10
+ * explicit scope list and a catalog is built over exactly that list; `allProjects` is the one
11
+ * target that reaches everything on disk, and it exists for the human-only "all projects" view.
12
+ *
13
+ * NO PATH CROSSES THIS FILE'S OUTPUT. A target names a scope by kind and key; the engine turns it
14
+ * into a directory (`paths.ts`), and nothing returned to a caller contains one.
15
+ */
16
+ import { isValidScope, isValidScopeKey, isValidGeneId, scopeId, } from '@aragon-agent/tui/model/gene/ids';
17
+ import { clampGeneConfig, DEFAULT_GENE_CONFIG, } from '@aragon-agent/tui/model/config/schema';
18
+ import { getSecrets } from '@aragon-agent/tui/model/logging/secret-registry';
19
+ import { readConfigFile } from '../config/store.js';
20
+ import { resolveProjectKey } from '../memory/paths.js';
21
+ import { GeneCatalog } from './catalog.js';
22
+ import { captureEnvFingerprint, makeGlobMatcher } from './env.js';
23
+ import { geneFail, geneOk, toGeneFailure } from './gene-errors.js';
24
+ import { getGeneLibrary, limitsFromConfig, } from './manager-library.js';
25
+ import { scopeKeyIsSafe } from './scope-guard.js';
26
+ /** The key of the team scope under `gene.teamPath` (the service uses the same default). */
27
+ export const TEAM_SCOPE_KEY = 'team';
28
+ const CONFIG_TTL_MS = 2000;
29
+ const ENV_TTL_MS = 60_000;
30
+ const MAX_CATALOGS = 6;
31
+ /** The catalogs built so far, keyed by their scope list; the oldest is dropped past six. */
32
+ export class CatalogPool {
33
+ lib;
34
+ now;
35
+ byKey = new Map();
36
+ constructor(lib, now) {
37
+ this.lib = lib;
38
+ this.now = now;
39
+ }
40
+ /** A catalog over exactly `scopes`, caught up with the disk. Never rejects. */
41
+ async acquire(scopes) {
42
+ const key = scopes.map(scopeId).sort().join('|');
43
+ let catalog = this.byKey.get(key);
44
+ if (catalog === undefined) {
45
+ catalog = new GeneCatalog({ reader: this.lib.store, now: this.now });
46
+ catalog.setScopes(scopes);
47
+ }
48
+ else {
49
+ this.byKey.delete(key);
50
+ }
51
+ this.byKey.set(key, catalog);
52
+ this.evict();
53
+ await catalog.catchUp();
54
+ return catalog;
55
+ }
56
+ evict() {
57
+ while (this.byKey.size > MAX_CATALOGS) {
58
+ const oldest = this.byKey.keys().next().value;
59
+ this.byKey.get(oldest)?.dispose();
60
+ this.byKey.delete(oldest);
61
+ }
62
+ }
63
+ dispose() {
64
+ for (const catalog of this.byKey.values())
65
+ catalog.dispose();
66
+ this.byKey.clear();
67
+ }
68
+ }
69
+ function persistedConfig() {
70
+ try {
71
+ return clampGeneConfig(readConfigFile().config?.gene);
72
+ }
73
+ catch {
74
+ return DEFAULT_GENE_CONFIG;
75
+ }
76
+ }
77
+ function cachedConfig(read, now) {
78
+ let held = null;
79
+ return () => {
80
+ const t = now();
81
+ if (held !== null && t >= held.at && t - held.at < CONFIG_TTL_MS)
82
+ return held.value;
83
+ held = { at: t, value: read() };
84
+ return held.value;
85
+ };
86
+ }
87
+ function identifyProject(cwd) {
88
+ try {
89
+ const identity = resolveProjectKey(cwd);
90
+ return isValidScopeKey('project', identity.key) ? identity : null;
91
+ }
92
+ catch {
93
+ return null;
94
+ }
95
+ }
96
+ /** Build the shared state of one manager. Never throws. */
97
+ export function createManagerCore(options) {
98
+ const now = options.now ?? Date.now;
99
+ const config = options.config ?? cachedConfig(persistedConfig, now);
100
+ const secrets = options.knownSecrets ?? getSecrets;
101
+ const teamPath = options.teamPath ?? config().teamPath;
102
+ const lib = getGeneLibrary({
103
+ ...(options.root === undefined ? {} : { root: options.root }),
104
+ teamPath,
105
+ ...(options.teamWritable ? { teamWritable: true } : {}),
106
+ kind: options.kind ?? 'tui',
107
+ now,
108
+ });
109
+ lib.tuning.limits = () => limitsFromConfig(config());
110
+ lib.tuning.knownSecrets = secrets;
111
+ const project = identifyProject(options.cwd);
112
+ let envHeld = null;
113
+ const env = () => {
114
+ if (options.env !== undefined)
115
+ return options.env();
116
+ const t = now();
117
+ if (envHeld === null || t < envHeld.at || t - envHeld.at > ENV_TTL_MS) {
118
+ envHeld = { at: t, value: captureEnvFingerprint(options.cwd) };
119
+ }
120
+ return envHeld.value;
121
+ };
122
+ const core = {
123
+ options,
124
+ lib,
125
+ pool: new CatalogPool(lib, now),
126
+ config,
127
+ now,
128
+ secrets,
129
+ project: () => project,
130
+ visibleScopes: () => visibleScopes(options, project, teamPath),
131
+ scopesOf: (target) => resolveScopes(core, target, teamPath),
132
+ env,
133
+ callerFor: (scopes, tools) => ({
134
+ role: 'main',
135
+ scopes,
136
+ tools: [...tools],
137
+ env: env(),
138
+ windowTokens: 0,
139
+ matchesGlob: makeGlobMatcher(options.cwd),
140
+ }),
141
+ };
142
+ return core;
143
+ }
144
+ function visibleScopes(options, project, teamPath) {
145
+ const scopes = [{ kind: 'user' }];
146
+ if (project !== null)
147
+ scopes.push({ kind: 'project', key: project.key });
148
+ if (teamPath.length > 0)
149
+ scopes.push({ kind: 'team', key: TEAM_SCOPE_KEY });
150
+ const session = options.sessionId;
151
+ if (isValidScopeKey('task', session))
152
+ scopes.push({ kind: 'task', key: session });
153
+ return scopes.filter((scope) => isValidScope(scope) && scopeKeyIsSafe(scope));
154
+ }
155
+ async function resolveScopes(core, target, teamPath) {
156
+ if (target.kind === 'visible')
157
+ return geneOk(core.visibleScopes());
158
+ if (target.kind === 'allProjects')
159
+ return geneOk(await core.lib.store.listScopes());
160
+ const scope = target.scope;
161
+ if (!isValidScope(scope) || !scopeKeyIsSafe(scope)) {
162
+ return geneFail('GENE_SCOPE_FORBIDDEN', 'That scope is not valid.', 'bad_scope');
163
+ }
164
+ if (scope.kind === 'team' && teamPath.length === 0) {
165
+ return geneFail('GENE_SCOPE_READONLY', 'No team directory is configured.', 'no_team');
166
+ }
167
+ return geneOk([scope]);
168
+ }
169
+ /**
170
+ * Locate a gene by id among the scopes `target` addresses: live first, then archived. The id is
171
+ * validated before any path is built from it.
172
+ */
173
+ export async function findGene(core, target, id) {
174
+ if (!isValidGeneId(id))
175
+ return geneFail('GENE_INVALID_ID', 'That gene id is not valid.');
176
+ const scopes = await core.scopesOf(target);
177
+ if (!scopes.ok)
178
+ return scopes;
179
+ for (const scope of scopes.value) {
180
+ const live = await core.lib.store.readHead(scope, id);
181
+ if (live !== null)
182
+ return geneOk({ scope, read: live, archived: false });
183
+ const kept = await core.lib.store.readArchivedHead(scope, id);
184
+ if (kept !== null)
185
+ return geneOk({ scope, read: kept, archived: true });
186
+ }
187
+ return geneFail('GENE_NOT_FOUND', 'No gene with that id was found.', 'missing');
188
+ }
189
+ /** The version number whose content a head serves: published, else the pending candidate. */
190
+ export function servedVersion(head) {
191
+ return head.currentVersion ?? head.candidateVersion ?? head.latestVersion;
192
+ }
193
+ /** Run a port method body so that nothing it throws escapes (I-24). */
194
+ export async function guarded(work) {
195
+ try {
196
+ return await work();
197
+ }
198
+ catch (error) {
199
+ return toGeneFailure(error);
200
+ }
201
+ }
@@ -0,0 +1,17 @@
1
+ import type { GeneDetailRequest, GeneDetailView, GeneDiffRequest, GeneEvidenceRequest, GeneEvidenceView, GeneUsageView } from '@aragon-agent/tui/model/gene/port';
2
+ import type { GeneDiff, GeneResult } from '@aragon-agent/tui/model/gene/types';
3
+ import { type ManagerCore } from './manager-context.js';
4
+ /** Why the proposal behind a version was made, when its queue file is still on disk. */
5
+ export declare function findProvenance(core: ManagerCore, proposalId: string): Promise<NonNullable<GeneDetailView['provenance']> | undefined>;
6
+ /** `get`: the served content plus everything a detail page shows. */
7
+ export declare function getGene(core: ManagerCore, req: GeneDetailRequest): Promise<GeneResult<GeneDetailView>>;
8
+ /** `evidence`: one piece, chunked, scrubbed a second time. */
9
+ export declare function getEvidence(core: ManagerCore, req: GeneEvidenceRequest): Promise<GeneResult<GeneEvidenceView>>;
10
+ /** `diff`: a structural comparison of two versions of one gene. */
11
+ export declare function diffVersions(core: ManagerCore, req: GeneDiffRequest): Promise<GeneResult<GeneDiff>>;
12
+ /** `usage`: the counters, the posterior mean and the latest events. */
13
+ export declare function usageOf(core: ManagerCore, req: GeneDetailRequest): Promise<GeneResult<GeneUsageView>>;
14
+ /** `why`: whether the gene is loaded for this session and how it scores (numbers and fields). */
15
+ export declare function whyLoaded(core: ManagerCore, req: GeneDetailRequest & {
16
+ query?: string;
17
+ }): Promise<GeneResult<string[]>>;