@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
@@ -0,0 +1,95 @@
1
+ /**
2
+ * The shape of a planned commit, and the checks every planner shares (gene-bank spec 7.1 steps
3
+ * 3-5, 11.3; I-10, I-12).
4
+ *
5
+ * ASCII ONLY - the whole `gene/` tree is in `glyphs.test.ts::inScope`.
6
+ *
7
+ * PLAN, THEN EXECUTE. A planner runs INSIDE the scope lock but only READS: it loads the head,
8
+ * applies the checks (basis, fence, budgets, names) and returns a `CommitPlan` - the exact files
9
+ * to write, in order. `commit-exec.ts` then performs steps 6-8 mechanically. Splitting the two
10
+ * keeps every decision in one place that can be tested without a disk (a plan is a value) and
11
+ * every write in one place that the crash tests can interrupt step by step.
12
+ *
13
+ * THE BASIS CHECK (I-10). A write based on `expect.version` / `expect.rev` is refused with
14
+ * `GENE_STALE_BASIS` when the head has moved. It is NEVER retried-and-overwritten: the caller
15
+ * (the curator) re-reads and re-decides once. Non-human writers MUST carry `expect.version` for
16
+ * any change to an existing gene, so "a curator that forgot to pass a basis" fails loudly rather
17
+ * than becoming a blind overwrite.
18
+ */
19
+ import type { GeneEvidence, GeneHead, GeneResult, GeneScope, GeneType, GeneVersion } from '@aragon-agent/tui/model/gene/types';
20
+ import type { CommitOutcome, GeneActor, GeneExpect, GeneOp, GeneRunLogEntry, GeneServiceLimits, InvalidationNotice } from './commit-types.js';
21
+ import type { NewTombstone, TombstoneStore } from './tombstones.js';
22
+ import type { ExtendedCounts, GeneStore, VersionWriteMode } from './store.js';
23
+ import type { ScopeRowsView } from './store-rows.js';
24
+ import type { HeadRead } from './store-port.js';
25
+ export type HeadMove = 'write' | 'archive' | 'restore' | 'trash';
26
+ export interface PlannedVersion {
27
+ version: GeneVersion;
28
+ mode: VersionWriteMode;
29
+ }
30
+ /** What happens after the lock is released (7.1 step 10). */
31
+ export interface PostEffects {
32
+ event?: GeneRunLogEntry['ev'];
33
+ detail?: string;
34
+ proposalId?: string;
35
+ invalidate?: InvalidationNotice['cause'];
36
+ /** A human changed the gene: proposals with a basis below this are superseded. */
37
+ supersedeBelow?: number;
38
+ /** The gene is going away: cancel its proposals. */
39
+ cancelReason?: string;
40
+ }
41
+ export interface CommitPlan {
42
+ op: GeneOp;
43
+ id: string;
44
+ type: GeneType;
45
+ scope: GeneScope;
46
+ before: {
47
+ head: GeneHead;
48
+ location: 'live' | 'archive';
49
+ } | null;
50
+ /** The head after the commit; null when the gene leaves `genes/` for the trash. */
51
+ head: GeneHead | null;
52
+ move: HeadMove;
53
+ trashFrom?: 'live' | 'archive';
54
+ evidence: GeneEvidence[];
55
+ /** Written BEFORE the head (step 6): new versions, and a candidate that becomes current. */
56
+ versionsBefore: PlannedVersion[];
57
+ /** Written AFTER the head (best effort): demotions (superseded / rejected). */
58
+ versionsAfter: PlannedVersion[];
59
+ tombstones: NewTombstone[];
60
+ /** `head.latestVersion` before this commit; new version numbers must be above it. */
61
+ knownLatest: number;
62
+ noop: boolean;
63
+ outcome: Pick<CommitOutcome, 'version' | 'needsHuman' | 'also'>;
64
+ effects: PostEffects;
65
+ }
66
+ export interface PlanEnv {
67
+ store: GeneStore;
68
+ rows: ScopeRowsView;
69
+ tombstones: TombstoneStore;
70
+ limits: GeneServiceLimits;
71
+ now: number;
72
+ }
73
+ /** What a planner receives. `counts` is this scope's `counts.json` as read at step 3. */
74
+ export interface PlanInput<C> {
75
+ env: PlanEnv;
76
+ change: C;
77
+ actor: GeneActor;
78
+ expect?: GeneExpect;
79
+ counts: ExtendedCounts;
80
+ }
81
+ export declare function basePlan(op: GeneOp, head: GeneHead, before: CommitPlan['before'], move: HeadMove): CommitPlan;
82
+ export declare function noopPlan(op: GeneOp, read: HeadRead, location?: 'live' | 'archive'): CommitPlan;
83
+ export declare function notFound(detail: string): GeneResult<never>;
84
+ export declare function loadLive(env: PlanEnv, scope: GeneScope, id: string): Promise<GeneResult<HeadRead>>;
85
+ /** I-10: compare the caller's basis with the head; non-humans must bring one. */
86
+ export declare function checkBasis(actor: GeneActor, expect: GeneExpect | undefined, read: HeadRead, basisRequired?: boolean): GeneResult<void>;
87
+ /** 11.3 / I-12: only a human writes an oversight gene. */
88
+ export declare function fenceOversight(actor: GeneActor, head: GeneHead): GeneResult<void>;
89
+ /** Names are unique among PUBLISHED genes of a (scope, type) (6.1); best effort, via the index. */
90
+ export declare function checkNameFree(env: PlanEnv, input: {
91
+ scope: GeneScope;
92
+ type: GeneType;
93
+ name: string;
94
+ selfId: string;
95
+ }): Promise<GeneResult<void>>;
@@ -0,0 +1,68 @@
1
+ import { geneFail, geneOk } from './gene-errors.js';
2
+ export function basePlan(op, head, before, move) {
3
+ return {
4
+ op,
5
+ id: head.id,
6
+ type: head.type,
7
+ scope: head.scope,
8
+ before,
9
+ head,
10
+ move,
11
+ evidence: [],
12
+ versionsBefore: [],
13
+ versionsAfter: [],
14
+ tombstones: [],
15
+ knownLatest: before?.head.latestVersion ?? 0,
16
+ noop: false,
17
+ outcome: {},
18
+ effects: {},
19
+ };
20
+ }
21
+ export function noopPlan(op, read, location = 'live') {
22
+ const plan = basePlan(op, read.head, { head: read.head, location }, 'write');
23
+ const version = read.head.currentVersion ?? read.head.latestVersion;
24
+ return { ...plan, noop: true, outcome: { version } };
25
+ }
26
+ // ---------------------------------------------------------------------------
27
+ // Shared checks
28
+ // ---------------------------------------------------------------------------
29
+ export function notFound(detail) {
30
+ return geneFail('GENE_NOT_FOUND', 'The gene was not found in that state.', detail);
31
+ }
32
+ export async function loadLive(env, scope, id) {
33
+ const read = await env.store.readHead(scope, id);
34
+ return read === null ? notFound('missing') : geneOk(read);
35
+ }
36
+ /** I-10: compare the caller's basis with the head; non-humans must bring one. */
37
+ export function checkBasis(actor, expect, read, basisRequired = true) {
38
+ if (actor.kind !== 'user' && basisRequired && expect?.version === undefined) {
39
+ const message = 'A non-human write must carry the version it is based on.';
40
+ return geneFail('GENE_STALE_BASIS', message, 'expect_required');
41
+ }
42
+ if (expect?.version !== undefined && expect.version !== read.head.latestVersion) {
43
+ return geneFail('GENE_STALE_BASIS', 'The gene changed since it was read.', 'version');
44
+ }
45
+ if (expect?.rev !== undefined && expect.rev !== read.rev) {
46
+ return geneFail('GENE_STALE_BASIS', 'The gene changed since it was read.', 'rev');
47
+ }
48
+ return geneOk(undefined);
49
+ }
50
+ /** 11.3 / I-12: only a human writes an oversight gene. */
51
+ export function fenceOversight(actor, head) {
52
+ if (head.class === 'oversight' && actor.kind !== 'user') {
53
+ return geneFail('GENE_OVERSIGHT_HUMAN_ONLY', 'Only a person may change an oversight gene.');
54
+ }
55
+ return geneOk(undefined);
56
+ }
57
+ /** Names are unique among PUBLISHED genes of a (scope, type) (6.1); best effort, via the index. */
58
+ export async function checkNameFree(env, input) {
59
+ const rows = await env.rows.rows(input.scope);
60
+ const clash = rows.find((row) => row.id !== input.selfId &&
61
+ row.type === input.type &&
62
+ row.status === 'published' &&
63
+ row.brief.name === input.name);
64
+ if (clash === undefined)
65
+ return geneOk(undefined);
66
+ const message = 'A published gene of this type already has that name.';
67
+ return geneFail('GENE_AMBIGUOUS_NAME', message, 'name_taken');
68
+ }
@@ -0,0 +1,63 @@
1
+ /**
2
+ * Step 1 of the commit protocol: everything that can be refused BEFORE a lock is taken or a
3
+ * byte is written (gene-bank spec 7.1 step 1, 11.2, 11.3, 11.5; I-12, I-14, I-16, I-25).
4
+ *
5
+ * ASCII ONLY - the whole `gene/` tree is in `glyphs.test.ts::inScope`.
6
+ *
7
+ * WHAT IS CHECKED HERE, AND WHY HERE. Content validation, the secret screen, the oversight fence
8
+ * and the evidence budget are pure functions of the request. Doing them first means a bad
9
+ * request never contends for a lock, never leaves an orphan version file and never costs a model
10
+ * token downstream (the curator only validates what already passed this gate).
11
+ *
12
+ * THE SECRET SCREEN REFUSES; THE EVIDENCE SCRUB REDACTS (11.5). A secret in a writable field
13
+ * (name, purpose, trigger, body, tags, locale hints, payload prose, the reason) is
14
+ * `GENE_SECRET_DETECTED` with no "save anyway". Evidence keeps the human's original wording, so
15
+ * it is redacted instead (`[redacted:<kind>]`, `[email]`, `[phone]`) and flagged `redacted`.
16
+ * The configured provider keys are always passed as `knownSecrets` (RV-18).
17
+ *
18
+ * `risk` IS A FLOOR, NEVER A CLAIM. A tool's declared `risk` is whatever the model wrote; the
19
+ * static screen (`screenToolExec`) is the authority, so a lower declared value is raised to the
20
+ * computed one before the content is hashed. A script whose text cannot be read is `high`.
21
+ */
22
+ import type { GeneContent, GeneEvidence, GeneResult, GeneType } from '@aragon-agent/tui/model/gene/types';
23
+ import { type GeneIssue, type ValidateContext } from '@aragon-agent/tui/model/gene/validate';
24
+ import type { EvidenceInput, GeneActor } from './commit-types.js';
25
+ export interface PreparedContent {
26
+ type: GeneType;
27
+ content: GeneContent;
28
+ /** Evidence files to write with this commit (redacted, refs minted). */
29
+ evidence: GeneEvidence[];
30
+ }
31
+ export interface PrepareInput {
32
+ type: GeneType;
33
+ content: GeneContent;
34
+ scope: ValidateContext['scope'];
35
+ actor: GeneActor;
36
+ geneId: string;
37
+ evidence?: EvidenceInput[];
38
+ /** Refs and total bytes of evidence the gene already has (an edit adds to them). */
39
+ existingRefs?: string[];
40
+ existingEvidenceBytes?: number;
41
+ /** For a script tool without new impl evidence: the stored implementation text. */
42
+ storedScriptText?: string;
43
+ knownSecrets: readonly string[];
44
+ now: number;
45
+ random: (n: number) => number;
46
+ class?: ValidateContext['class'];
47
+ }
48
+ /** The `ValidateContext.actor` an automation kind maps to. A migration is an import. */
49
+ export declare function validateActorOf(actor: GeneActor): ValidateContext['actor'];
50
+ /** A violation of the issue list that outranks the rest, then the first issue (11.3, 11.5). */
51
+ export declare function issuesToFailure(issues: GeneIssue[]): GeneResult<never>;
52
+ /** Trimmed, English, length-bounded, secret-free (the `reason` of a version). */
53
+ export declare function cleanReason(reason: unknown, knownSecrets: readonly string[]): GeneResult<string>;
54
+ /** Mint refs, redact, bound. Refuses (never truncates) over-long text or an over-budget gene. */
55
+ export declare function buildEvidence(input: PrepareInput): GeneResult<GeneEvidence[]>;
56
+ /** Raise a tool's declared risk to the statically computed one; never lower it. */
57
+ export declare function applyRiskFloor(content: GeneContent, scriptText: string | undefined): GeneContent;
58
+ /**
59
+ * Validate and finalise the content of a write: evidence minted and merged into
60
+ * `content.evidence`, the tool risk floor applied, then `validateGeneContent` with the secret
61
+ * screen and the actor's authority. Returns the content that will actually be hashed.
62
+ */
63
+ export declare function prepareContent(input: PrepareInput): GeneResult<PreparedContent>;
@@ -0,0 +1,159 @@
1
+ import { GENE_LIMITS } from '@aragon-agent/tui/model/gene/limits';
2
+ import { isValidEvidenceRef, mintEvidenceRef } from '@aragon-agent/tui/model/gene/ids';
3
+ import { validateGeneContent, } from '@aragon-agent/tui/model/gene/validate';
4
+ import { checkText } from '@aragon-agent/tui/model/gene/validate-base';
5
+ import { geneFail, geneOk } from './gene-errors.js';
6
+ import { geneLooksLikeSecret, redactSecrets } from './secrets.js';
7
+ import { screenToolExec } from './tool-screen.js';
8
+ const RISK_RANK = { read_only: 0, workspace_write: 1, high: 2 };
9
+ /** The `ValidateContext.actor` an automation kind maps to. A migration is an import. */
10
+ export function validateActorOf(actor) {
11
+ if (actor.kind === 'user')
12
+ return 'user';
13
+ return actor.kind === 'curator' ? 'agent' : 'import';
14
+ }
15
+ /** A violation of the issue list that outranks the rest, then the first issue (11.3, 11.5). */
16
+ export function issuesToFailure(issues) {
17
+ const order = [
18
+ 'GENE_OVERSIGHT_HUMAN_ONLY',
19
+ 'GENE_SCOPE_FORBIDDEN',
20
+ 'GENE_SECRET_DETECTED',
21
+ ];
22
+ const outranking = order.map((code) => issues.find((i) => i.code === code));
23
+ const chosen = outranking.find((i) => i !== undefined) ?? issues[0];
24
+ if (chosen === undefined)
25
+ return geneFail('GENE_INVALID_CONTENT', 'The content is not valid.');
26
+ return geneFail(chosen.code, `${chosen.path}: ${chosen.message}`, chosen.detail);
27
+ }
28
+ /** Trimmed, English, length-bounded, secret-free (the `reason` of a version). */
29
+ export function cleanReason(reason, knownSecrets) {
30
+ const issues = [];
31
+ const rule = { path: 'reason', max: GENE_LIMITS.reasonMax, english: true, required: true };
32
+ const text = checkText(reason, rule, issues);
33
+ if (issues.length > 0 || text === undefined)
34
+ return issuesToFailure(issues);
35
+ if (geneLooksLikeSecret(text, knownSecrets)) {
36
+ return geneFail('GENE_SECRET_DETECTED', 'reason looks like it contains a secret.');
37
+ }
38
+ return geneOk(text);
39
+ }
40
+ function defaultEvidenceTrust(kind) {
41
+ if (kind === 'user_statement')
42
+ return 'user';
43
+ return kind === 'url' ? 'untrusted' : 'agent';
44
+ }
45
+ function evidenceTextMax(kind) {
46
+ return kind === 'impl' ? GENE_LIMITS.evidenceImplMax : GENE_LIMITS.evidenceTextMax;
47
+ }
48
+ /** Mint refs, redact, bound. Refuses (never truncates) over-long text or an over-budget gene. */
49
+ export function buildEvidence(input) {
50
+ const inputs = input.evidence ?? [];
51
+ const taken = new Set(input.existingRefs ?? []);
52
+ const out = [];
53
+ let bytes = input.existingEvidenceBytes ?? 0;
54
+ for (const item of inputs) {
55
+ if ([...item.text].length > evidenceTextMax(item.kind)) {
56
+ return geneFail('GENE_INVALID_CONTENT', 'An evidence entry is too long.', 'too_long');
57
+ }
58
+ const ref = chooseRef(item.ref, taken, input.random);
59
+ if (ref === null) {
60
+ return geneFail('GENE_INVALID_CONTENT', 'An evidence ref is not valid.', 'bad_schema');
61
+ }
62
+ taken.add(ref);
63
+ const scrubbed = redactSecrets(item.text, input.knownSecrets);
64
+ bytes += Buffer.byteLength(scrubbed.text);
65
+ out.push({
66
+ schema: 1,
67
+ ref,
68
+ geneId: input.geneId,
69
+ capturedAt: input.now,
70
+ kind: item.kind,
71
+ trust: item.trust ?? defaultEvidenceTrust(item.kind),
72
+ source: item.source ?? {},
73
+ text: scrubbed.text,
74
+ redacted: scrubbed.redacted,
75
+ });
76
+ }
77
+ if (bytes > GENE_LIMITS.evidenceTotalKB * 1024) {
78
+ return geneFail('GENE_INVALID_CONTENT', 'The gene has more evidence than allowed.', 'too_long');
79
+ }
80
+ return geneOk(out);
81
+ }
82
+ function chooseRef(wanted, taken, random) {
83
+ if (wanted !== undefined)
84
+ return isValidEvidenceRef(wanted) && !taken.has(wanted) ? wanted : null;
85
+ for (let attempt = 0; attempt < 8; attempt += 1) {
86
+ const ref = mintEvidenceRef(random);
87
+ if (!taken.has(ref))
88
+ return ref;
89
+ }
90
+ return null;
91
+ }
92
+ /** Raise a tool's declared risk to the statically computed one; never lower it. */
93
+ export function applyRiskFloor(content, scriptText) {
94
+ const payload = content.payload;
95
+ if (payload.exec === undefined || typeof payload.risk !== 'string')
96
+ return content;
97
+ const computed = screenToolExec(payload.exec, scriptText).risk;
98
+ if (RISK_RANK[computed] <= RISK_RANK[payload.risk])
99
+ return content;
100
+ return { ...content, payload: { ...content.payload, risk: computed } };
101
+ }
102
+ function scriptTextOf(content, evidence, stored) {
103
+ const exec = content.payload.exec;
104
+ if (exec === undefined || exec.kind !== 'script')
105
+ return undefined;
106
+ return evidence.find((e) => e.ref === exec.evidence)?.text ?? stored;
107
+ }
108
+ /**
109
+ * `class` belongs to the HEAD, not the content. A content that carries one anyway is either a
110
+ * mistake or an attempt to smuggle `oversight` past the fence (11.3): automation naming
111
+ * `oversight` is refused as such, and any disagreement with the head's class is a schema error.
112
+ */
113
+ function checkStrayClass(input) {
114
+ const stray = input.content.class;
115
+ if (stray === undefined)
116
+ return geneOk(undefined);
117
+ if (stray === 'oversight' && input.actor.kind !== 'user') {
118
+ const message = 'Only a person may write an oversight gene.';
119
+ return geneFail('GENE_OVERSIGHT_HUMAN_ONLY', message, 'class');
120
+ }
121
+ return stray === (input.class ?? 'standard')
122
+ ? geneOk(undefined)
123
+ : geneFail('GENE_INVALID_CONTENT', 'The content must not carry its own class.', 'bad_schema');
124
+ }
125
+ function stripClass(content) {
126
+ const copy = { ...content };
127
+ delete copy.class;
128
+ return copy;
129
+ }
130
+ /**
131
+ * Validate and finalise the content of a write: evidence minted and merged into
132
+ * `content.evidence`, the tool risk floor applied, then `validateGeneContent` with the secret
133
+ * screen and the actor's authority. Returns the content that will actually be hashed.
134
+ */
135
+ export function prepareContent(input) {
136
+ const classCheck = checkStrayClass(input);
137
+ if (!classCheck.ok)
138
+ return classCheck;
139
+ const evidence = buildEvidence(input);
140
+ if (!evidence.ok)
141
+ return evidence;
142
+ const refs = [...new Set([...input.content.evidence, ...evidence.value.map((e) => e.ref)])];
143
+ let content = { ...stripClass(input.content), evidence: refs };
144
+ if (input.type === 'tool') {
145
+ const script = scriptTextOf(content, evidence.value, input.storedScriptText);
146
+ content = applyRiskFloor(content, script);
147
+ }
148
+ const ctx = {
149
+ scope: input.scope,
150
+ actor: validateActorOf(input.actor),
151
+ secretCheck: (text) => geneLooksLikeSecret(text, input.knownSecrets),
152
+ };
153
+ if (input.class !== undefined)
154
+ ctx.class = input.class;
155
+ const verdict = validateGeneContent(input.type, content, ctx);
156
+ if (!verdict.ok)
157
+ return issuesToFailure(verdict.issues);
158
+ return geneOk({ type: input.type, content, evidence: evidence.value });
159
+ }
@@ -0,0 +1,234 @@
1
+ /**
2
+ * Shapes of the Gene Bank write protocol (gene-bank spec 7.1, 7.6, 11.3).
3
+ *
4
+ * ASCII ONLY - the whole `gene/` tree is in `glyphs.test.ts::inScope`. TYPES (and two tiny
5
+ * guards) ONLY: the behaviour lives in `version-service.ts` and its helpers.
6
+ *
7
+ * `GeneChange` is the PUBLIC vocabulary of `GeneVersionService.commit`: the UI, the curator, the
8
+ * importer and the migration all speak it. A few operations the service performs for itself
9
+ * (a rollback or a preference confirmation is an edit that publishes directly; a merge's first
10
+ * step is the same) are NOT in this union on purpose: a `direct` flag on a public change would
11
+ * be a way for the background curator to skip the candidate stage.
12
+ *
13
+ * THE THREE PORTS (`DependentsResolver`, `ProposalFence`, `GeneRunLog`) are how the service
14
+ * reaches the parts of the library that other modules own - the catalog, the proposal queue and
15
+ * the run log. Each has a harmless default, so the service works (and is testable) alone.
16
+ */
17
+ import type { GeneClass, GeneContent, GeneEvidenceInput, GeneHead, GenePinReason, GeneNeedsHuman, GeneRunRecord, GeneScope, GeneStatus, GeneType, GeneValidation, GeneHealth } from '@aragon-agent/tui/model/gene/types';
18
+ /** `user` is a human at a keyboard; every other kind is automation (I-10, I-12). */
19
+ export type GeneActorKind = 'user' | 'curator' | 'import' | 'migration';
20
+ export interface GeneActor {
21
+ kind: GeneActorKind;
22
+ /** Free-form, short, English; recorded on the version (`author.label`). */
23
+ label?: string;
24
+ }
25
+ export declare function isUserActor(actor: GeneActor): boolean;
26
+ /**
27
+ * The basis a writer saw (I-10). `version` is compared with `head.latestVersion`, `rev` with the
28
+ * head file's `rev`. A mismatch is `GENE_STALE_BASIS` and NEVER a retry-and-overwrite.
29
+ */
30
+ export interface GeneExpect {
31
+ version?: number;
32
+ rev?: string;
33
+ }
34
+ interface Target {
35
+ scope: GeneScope;
36
+ id: string;
37
+ }
38
+ /**
39
+ * Evidence as the curator hands it over. A `ref` is optional: a script tool must name its
40
+ * implementation evidence (`exec.evidence`) before the service has seen it, so the caller may
41
+ * pre-mint refs with `mintEvidenceRef`; without one the service mints it.
42
+ */
43
+ export type EvidenceInput = GeneEvidenceInput & {
44
+ ref?: string;
45
+ };
46
+ interface WithEvidence {
47
+ /** Raw evidence; the service redacts and stores it and lists the refs in the content. */
48
+ evidence?: EvidenceInput[];
49
+ proposalId?: string;
50
+ /** Appended to the written version's `validation` (curator checks, user probe approval). */
51
+ validation?: GeneValidation;
52
+ }
53
+ export interface CreateChange extends WithEvidence {
54
+ op: 'create';
55
+ type: GeneType;
56
+ scope: GeneScope;
57
+ content: GeneContent;
58
+ reason: string;
59
+ class?: GeneClass;
60
+ /** import / migration only: keep the id of the source library. Ignored otherwise. */
61
+ id?: string;
62
+ pinned?: boolean;
63
+ pinReason?: GenePinReason;
64
+ /** The user confirmed a `risk: high` tool in the editor (7.6). */
65
+ confirmHighRisk?: boolean;
66
+ needsHuman?: GeneNeedsHuman;
67
+ }
68
+ /** `edit` and `revise` are the same operation; the ACTOR decides what comes out. */
69
+ export interface EditChange extends WithEvidence, Target {
70
+ op: 'edit' | 'revise';
71
+ content: GeneContent;
72
+ reason: string;
73
+ confirmHighRisk?: boolean;
74
+ }
75
+ export interface PublishCandidateChange extends Target {
76
+ op: 'publishCandidate';
77
+ reason?: string;
78
+ validation?: GeneValidation;
79
+ proposalId?: string;
80
+ }
81
+ export interface RejectCandidateChange extends Target {
82
+ op: 'rejectCandidate';
83
+ reason: string;
84
+ validation?: GeneValidation;
85
+ }
86
+ export interface SetPinnedChange extends Target {
87
+ op: 'setPinned';
88
+ pinned: boolean;
89
+ pinReason?: GenePinReason;
90
+ }
91
+ export interface ArchiveChange extends Target {
92
+ op: 'archive';
93
+ reason: string;
94
+ /** Set by a merge: the survivor, recorded on the archived gene's current version. */
95
+ mergedInto?: string;
96
+ proposalId?: string;
97
+ }
98
+ export interface RestoreChange extends Target {
99
+ op: 'restore';
100
+ reason?: string;
101
+ }
102
+ export interface RollbackChange extends Target {
103
+ op: 'rollback';
104
+ toVersion: number;
105
+ }
106
+ export interface DeleteChange extends Target {
107
+ op: 'delete';
108
+ }
109
+ export interface ForgetChange extends Target {
110
+ op: 'forget';
111
+ /** Tombstone in every scope kind instead of only the gene's own scope. */
112
+ allScopes?: boolean;
113
+ }
114
+ export interface ConfirmPreferenceChange extends Target {
115
+ op: 'confirmPreference';
116
+ }
117
+ export interface PromoteChange extends Target {
118
+ op: 'promote';
119
+ to: GeneScope;
120
+ /** Promote unmet `requires` along with the gene instead of refusing. */
121
+ withDependencies?: boolean;
122
+ }
123
+ export interface SetHealthChange extends Target {
124
+ op: 'setHealth';
125
+ health: GeneHealth;
126
+ healthReason?: string;
127
+ }
128
+ export interface SetNeedsHumanChange extends Target {
129
+ op: 'setNeedsHuman';
130
+ /** `null` clears the flag. */
131
+ needsHuman: GeneNeedsHuman | null;
132
+ }
133
+ export interface RevokeChange extends Target {
134
+ op: 'revoke';
135
+ reason: string;
136
+ /** Also write a `revoked_harmful` tombstone so the same idea is not learned again. */
137
+ harmful?: boolean;
138
+ }
139
+ export interface MergeChange extends WithEvidence {
140
+ op: 'merge';
141
+ scope: GeneScope;
142
+ into: string;
143
+ from: string[];
144
+ content: GeneContent;
145
+ reason: string;
146
+ /** REQUIRED: the tag that lets a crashed merge be resumed (7.6). */
147
+ proposalId: string;
148
+ /** The `latestVersion` of each `from` gene the proposal was based on (I-10). */
149
+ fromBasis?: Record<string, number>;
150
+ }
151
+ export type GeneChange = CreateChange | EditChange | PublishCandidateChange | RejectCandidateChange | SetPinnedChange | ArchiveChange | RestoreChange | RollbackChange | DeleteChange | ForgetChange | ConfirmPreferenceChange | PromoteChange | SetHealthChange | SetNeedsHumanChange | RevokeChange | MergeChange;
152
+ export type GeneOp = GeneChange['op'];
153
+ export interface CommitOutcome {
154
+ id: string;
155
+ scope: GeneScope;
156
+ op: GeneOp;
157
+ /** The version this commit wrote or served (undefined for metadata-only commits). */
158
+ version?: number;
159
+ /** The head AS WRITTEN (a copy; absent when the gene left `genes/`). */
160
+ head?: GeneHead;
161
+ rev?: string;
162
+ /** True when the commit changed nothing and wrote nothing. */
163
+ noop?: boolean;
164
+ /** A non-human write would have lowered a human gene's trust; a person must decide (7.4.3). */
165
+ needsHuman?: boolean;
166
+ /** Other genes this commit wrote (promote with dependencies, merge survivors). */
167
+ also?: string[];
168
+ /** Genes archived by the capacity check before this commit published (7.2). */
169
+ evicted?: string[];
170
+ /** Pending proposals this commit marked superseded (7.6). */
171
+ supersededProposals?: number;
172
+ }
173
+ export interface DependentRef {
174
+ id: string;
175
+ scope: GeneScope;
176
+ /** Eviction only counts PUBLISHED dependents; propagation skips rejected and revoked ones. */
177
+ status: GeneStatus;
178
+ }
179
+ /**
180
+ * Who `requires` a gene (10.9). DIRECT dependents only: a gene is broken by what it names, not
181
+ * by what its dependencies name. The default implementation scans the index rows of every scope
182
+ * on disk; the catalog can supply a cheaper one.
183
+ */
184
+ export interface DependentsResolver {
185
+ dependentsOf(id: string, options: {
186
+ cap: number;
187
+ }): Promise<{
188
+ refs: DependentRef[];
189
+ truncated: boolean;
190
+ }>;
191
+ }
192
+ /** The proposal queue (another module owns it). Both calls are best-effort. */
193
+ export interface ProposalFence {
194
+ /** Mark pending / claimed proposals on `geneId` with a basis below `basisBelow` superseded. */
195
+ supersedeStale(input: {
196
+ geneId: string;
197
+ scope: GeneScope;
198
+ basisBelow: number;
199
+ }): Promise<number>;
200
+ /** Cancel every pending / claimed proposal targeting `geneId` (archive, delete, forget). */
201
+ cancelForGene(input: {
202
+ geneId: string;
203
+ scope: GeneScope;
204
+ reason: string;
205
+ }): Promise<number>;
206
+ }
207
+ /** What the run log needs from the version service; `t`, `seq` and `by` are the logger's. */
208
+ export type GeneRunLogEntry = Pick<GeneRunRecord, 'ev' | 'proposalId' | 'geneId' | 'version' | 'scope' | 'type' | 'detail'>;
209
+ export interface GeneRunLog {
210
+ record(entry: GeneRunLogEntry): void | Promise<void>;
211
+ }
212
+ export type InvalidationKind = 'archived' | 'deleted' | 'revoked' | 'broken' | 'interface';
213
+ /**
214
+ * Handed to `InvalidateHook` after dependency propagation (7.1 step 10) so the queue can enqueue
215
+ * one `recheck` proposal per marked dependent (or one `maintenance` when `truncated`).
216
+ */
217
+ export interface InvalidationNotice {
218
+ cause: {
219
+ id: string;
220
+ version: number;
221
+ kind: InvalidationKind;
222
+ };
223
+ dependents: DependentRef[];
224
+ truncated: boolean;
225
+ }
226
+ export type InvalidateHook = (notice: InvalidationNotice) => void | Promise<void>;
227
+ export interface GeneServiceLimits {
228
+ capPerType: number;
229
+ pinnedMax: number;
230
+ candidateMax: number;
231
+ versionsKept: number;
232
+ archiveMaxMB: number;
233
+ }
234
+ export {};
@@ -0,0 +1,3 @@
1
+ export function isUserActor(actor) {
2
+ return actor.kind === 'user';
3
+ }