@eloxiv/cli 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (294) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +12 -2
  3. package/dist/AgentSkills.d.ts +51 -0
  4. package/dist/AgentSkills.d.ts.map +1 -0
  5. package/dist/AgentSkills.js +264 -0
  6. package/dist/AgentSkills.js.map +1 -0
  7. package/dist/AgentWeb.d.ts +83 -0
  8. package/dist/AgentWeb.d.ts.map +1 -0
  9. package/dist/AgentWeb.js +436 -0
  10. package/dist/AgentWeb.js.map +1 -0
  11. package/dist/App.d.ts +213 -0
  12. package/dist/App.d.ts.map +1 -0
  13. package/dist/App.js +357 -0
  14. package/dist/App.js.map +1 -0
  15. package/dist/Blueprint.d.ts +47 -0
  16. package/dist/Blueprint.d.ts.map +1 -0
  17. package/dist/Blueprint.js +241 -0
  18. package/dist/Blueprint.js.map +1 -0
  19. package/dist/Brand.d.ts +42 -0
  20. package/dist/Brand.d.ts.map +1 -0
  21. package/dist/Brand.js +370 -0
  22. package/dist/Brand.js.map +1 -0
  23. package/dist/Changelog.d.ts +22 -0
  24. package/dist/Changelog.d.ts.map +1 -0
  25. package/dist/Changelog.js +117 -0
  26. package/dist/Changelog.js.map +1 -0
  27. package/dist/Cli.d.ts +17 -0
  28. package/dist/Cli.d.ts.map +1 -0
  29. package/dist/Cli.js +810 -0
  30. package/dist/Cli.js.map +1 -0
  31. package/dist/DbAdmin.d.ts +18 -0
  32. package/dist/DbAdmin.d.ts.map +1 -0
  33. package/dist/DbAdmin.js +91 -0
  34. package/dist/DbAdmin.js.map +1 -0
  35. package/dist/Dependencies.d.ts +53 -0
  36. package/dist/Dependencies.d.ts.map +1 -0
  37. package/dist/Dependencies.js +132 -0
  38. package/dist/Dependencies.js.map +1 -0
  39. package/dist/Deploy.d.ts +39 -0
  40. package/dist/Deploy.d.ts.map +1 -0
  41. package/dist/Deploy.js +458 -0
  42. package/dist/Deploy.js.map +1 -0
  43. package/dist/Docs.d.ts +71 -0
  44. package/dist/Docs.d.ts.map +1 -0
  45. package/dist/Docs.js +240 -0
  46. package/dist/Docs.js.map +1 -0
  47. package/dist/Doctor.d.ts +56 -0
  48. package/dist/Doctor.d.ts.map +1 -0
  49. package/dist/Doctor.js +368 -0
  50. package/dist/Doctor.js.map +1 -0
  51. package/dist/Dossier.d.ts +23 -0
  52. package/dist/Dossier.d.ts.map +1 -0
  53. package/dist/Dossier.js +92 -0
  54. package/dist/Dossier.js.map +1 -0
  55. package/dist/Emit.d.ts +26 -0
  56. package/dist/Emit.d.ts.map +1 -0
  57. package/dist/Emit.js +51 -0
  58. package/dist/Emit.js.map +1 -0
  59. package/dist/Errors.d.ts +26 -0
  60. package/dist/Errors.d.ts.map +1 -0
  61. package/dist/Errors.js +17 -0
  62. package/dist/Errors.js.map +1 -0
  63. package/dist/Evals.d.ts +52 -0
  64. package/dist/Evals.d.ts.map +1 -0
  65. package/dist/Evals.js +126 -0
  66. package/dist/Evals.js.map +1 -0
  67. package/dist/Files.d.ts +47 -0
  68. package/dist/Files.d.ts.map +1 -0
  69. package/dist/Files.js +145 -0
  70. package/dist/Files.js.map +1 -0
  71. package/dist/Generate.d.ts +80 -0
  72. package/dist/Generate.d.ts.map +1 -0
  73. package/dist/Generate.js +310 -0
  74. package/dist/Generate.js.map +1 -0
  75. package/dist/Guards.d.ts +45 -0
  76. package/dist/Guards.d.ts.map +1 -0
  77. package/dist/Guards.js +530 -0
  78. package/dist/Guards.js.map +1 -0
  79. package/dist/Inspect.d.ts +125 -0
  80. package/dist/Inspect.d.ts.map +1 -0
  81. package/dist/Inspect.js +270 -0
  82. package/dist/Inspect.js.map +1 -0
  83. package/dist/Keychain.d.ts +57 -0
  84. package/dist/Keychain.d.ts.map +1 -0
  85. package/dist/Keychain.js +73 -0
  86. package/dist/Keychain.js.map +1 -0
  87. package/dist/Lock.d.ts +13 -0
  88. package/dist/Lock.d.ts.map +1 -0
  89. package/dist/Lock.js +145 -0
  90. package/dist/Lock.js.map +1 -0
  91. package/dist/Mcp.d.ts +91 -0
  92. package/dist/Mcp.d.ts.map +1 -0
  93. package/dist/Mcp.js +128 -0
  94. package/dist/Mcp.js.map +1 -0
  95. package/dist/Merge.d.ts +18 -0
  96. package/dist/Merge.d.ts.map +1 -0
  97. package/dist/Merge.js +43 -0
  98. package/dist/Merge.js.map +1 -0
  99. package/dist/Migrate.d.ts +78 -0
  100. package/dist/Migrate.d.ts.map +1 -0
  101. package/dist/Migrate.js +288 -0
  102. package/dist/Migrate.js.map +1 -0
  103. package/dist/Plugins.d.ts +36 -0
  104. package/dist/Plugins.d.ts.map +1 -0
  105. package/dist/Plugins.js +304 -0
  106. package/dist/Plugins.js.map +1 -0
  107. package/dist/Postgres.d.ts +73 -0
  108. package/dist/Postgres.d.ts.map +1 -0
  109. package/dist/Postgres.js +294 -0
  110. package/dist/Postgres.js.map +1 -0
  111. package/dist/Publish.d.ts +23 -0
  112. package/dist/Publish.d.ts.map +1 -0
  113. package/dist/Publish.js +59 -0
  114. package/dist/Publish.js.map +1 -0
  115. package/dist/Registry.d.ts +539 -0
  116. package/dist/Registry.d.ts.map +1 -0
  117. package/dist/Registry.js +340 -0
  118. package/dist/Registry.js.map +1 -0
  119. package/dist/Remote.d.ts +90 -0
  120. package/dist/Remote.d.ts.map +1 -0
  121. package/dist/Remote.js +1006 -0
  122. package/dist/Remote.js.map +1 -0
  123. package/dist/Run.d.ts +120 -0
  124. package/dist/Run.d.ts.map +1 -0
  125. package/dist/Run.js +477 -0
  126. package/dist/Run.js.map +1 -0
  127. package/dist/SyncGen.d.ts +118 -0
  128. package/dist/SyncGen.d.ts.map +1 -0
  129. package/dist/SyncGen.js +392 -0
  130. package/dist/SyncGen.js.map +1 -0
  131. package/dist/Update.d.ts +301 -0
  132. package/dist/Update.d.ts.map +1 -0
  133. package/dist/Update.js +627 -0
  134. package/dist/Update.js.map +1 -0
  135. package/dist/bin.d.ts +3 -0
  136. package/dist/bin.d.ts.map +1 -0
  137. package/dist/bin.js +42 -0
  138. package/dist/bin.js.map +1 -0
  139. package/dist/docs/backlog.md +56 -0
  140. package/dist/docs/ci.md +277 -0
  141. package/dist/docs/cli.md +696 -0
  142. package/dist/docs/connectors/google.md +115 -0
  143. package/dist/docs/connectors/http-openapi.md +7 -0
  144. package/dist/docs/connectors/mcp.md +8 -0
  145. package/dist/docs/connectors/microsoft-graph.md +75 -0
  146. package/dist/docs/connectors/openai.md +25 -0
  147. package/dist/docs/connectors/slack.md +162 -0
  148. package/dist/docs/connectors/workos.md +39 -0
  149. package/dist/docs/contracts/README.md +173 -0
  150. package/dist/docs/contracts/action-consent.md +92 -0
  151. package/dist/docs/contracts/action-registry.md +85 -0
  152. package/dist/docs/contracts/actor.md +100 -0
  153. package/dist/docs/contracts/agent-resources.md +90 -0
  154. package/dist/docs/contracts/agent-runtime.md +257 -0
  155. package/dist/docs/contracts/approvals.md +126 -0
  156. package/dist/docs/contracts/audit.md +75 -0
  157. package/dist/docs/contracts/auth-provider.md +74 -0
  158. package/dist/docs/contracts/calendar-provider.md +46 -0
  159. package/dist/docs/contracts/client-sdk.md +245 -0
  160. package/dist/docs/contracts/collab-document.md +151 -0
  161. package/dist/docs/contracts/command.md +44 -0
  162. package/dist/docs/contracts/connections.md +235 -0
  163. package/dist/docs/contracts/context-accounting.md +50 -0
  164. package/dist/docs/contracts/daemon.md +243 -0
  165. package/dist/docs/contracts/db-tx.md +53 -0
  166. package/dist/docs/contracts/delegation.md +68 -0
  167. package/dist/docs/contracts/device-control.md +103 -0
  168. package/dist/docs/contracts/directory-provider.md +36 -0
  169. package/dist/docs/contracts/directory.md +161 -0
  170. package/dist/docs/contracts/document-source.md +33 -0
  171. package/dist/docs/contracts/files.md +115 -0
  172. package/dist/docs/contracts/flags.md +83 -0
  173. package/dist/docs/contracts/host.md +68 -0
  174. package/dist/docs/contracts/http-api.md +43 -0
  175. package/dist/docs/contracts/ingestion.md +130 -0
  176. package/dist/docs/contracts/ingress.md +141 -0
  177. package/dist/docs/contracts/invocation.md +260 -0
  178. package/dist/docs/contracts/local-client.md +108 -0
  179. package/dist/docs/contracts/locale.md +56 -0
  180. package/dist/docs/contracts/machine-identity.md +117 -0
  181. package/dist/docs/contracts/mail-provider.md +49 -0
  182. package/dist/docs/contracts/memory.md +53 -0
  183. package/dist/docs/contracts/messaging.md +40 -0
  184. package/dist/docs/contracts/metering.md +139 -0
  185. package/dist/docs/contracts/model-provider.md +84 -0
  186. package/dist/docs/contracts/module-manifest.md +213 -0
  187. package/dist/docs/contracts/notification-channel.md +90 -0
  188. package/dist/docs/contracts/notifications.md +123 -0
  189. package/dist/docs/contracts/outbox.md +80 -0
  190. package/dist/docs/contracts/privacy.md +110 -0
  191. package/dist/docs/contracts/progress.md +52 -0
  192. package/dist/docs/contracts/query-surface.md +108 -0
  193. package/dist/docs/contracts/readiness.md +63 -0
  194. package/dist/docs/contracts/release.md +142 -0
  195. package/dist/docs/contracts/result-rendering.md +61 -0
  196. package/dist/docs/contracts/sandbox.md +186 -0
  197. package/dist/docs/contracts/scheduler.md +148 -0
  198. package/dist/docs/contracts/screen-context.md +81 -0
  199. package/dist/docs/contracts/search.md +120 -0
  200. package/dist/docs/contracts/secrets.md +74 -0
  201. package/dist/docs/contracts/settings.md +109 -0
  202. package/dist/docs/contracts/sharing.md +77 -0
  203. package/dist/docs/contracts/slot.md +48 -0
  204. package/dist/docs/contracts/space.md +67 -0
  205. package/dist/docs/contracts/storage-adapter.md +45 -0
  206. package/dist/docs/contracts/storage-backend.md +56 -0
  207. package/dist/docs/contracts/sync.md +213 -0
  208. package/dist/docs/contracts/telemetry.md +80 -0
  209. package/dist/docs/contracts/theme-tokens.md +50 -0
  210. package/dist/docs/contracts/tool-source.md +58 -0
  211. package/dist/docs/contracts/versioning.md +99 -0
  212. package/dist/docs/contracts/view.md +65 -0
  213. package/dist/docs/contracts/work-items.md +99 -0
  214. package/dist/docs/contracts/workflow.md +82 -0
  215. package/dist/docs/decisions.md +163 -0
  216. package/dist/docs/example-app.md +192 -0
  217. package/dist/docs/getting-started.md +927 -0
  218. package/dist/docs/goal.md +54 -0
  219. package/dist/docs/parity.md +29 -0
  220. package/dist/docs/performance.md +129 -0
  221. package/dist/docs/registry/README.md +74 -0
  222. package/dist/docs/registry/app.md +38 -0
  223. package/dist/docs/registry/approvals-ui-foldkit.md +28 -0
  224. package/dist/docs/registry/calendar-ui-foldkit.md +27 -0
  225. package/dist/docs/registry/calendar.md +35 -0
  226. package/dist/docs/registry/chat-ui-foldkit.md +30 -0
  227. package/dist/docs/registry/desktop-rune.md +49 -0
  228. package/dist/docs/registry/desktop.md +32 -0
  229. package/dist/docs/registry/eloxiv-action.md +25 -0
  230. package/dist/docs/registry/eloxiv-connector.md +25 -0
  231. package/dist/docs/registry/eloxiv-module.md +25 -0
  232. package/dist/docs/registry/eloxiv-policy.md +25 -0
  233. package/dist/docs/registry/eloxiv-view.md +25 -0
  234. package/dist/docs/registry/hello-ui-foldkit.md +29 -0
  235. package/dist/docs/registry/hello.md +39 -0
  236. package/dist/docs/registry/home-ui-foldkit.md +27 -0
  237. package/dist/docs/registry/home.md +29 -0
  238. package/dist/docs/registry/inbox-ui-foldkit.md +27 -0
  239. package/dist/docs/registry/mail-ui-foldkit.md +27 -0
  240. package/dist/docs/registry/mail.md +34 -0
  241. package/dist/docs/registry/meeting-prep.md +26 -0
  242. package/dist/docs/registry/members-ui-foldkit.md +28 -0
  243. package/dist/docs/registry/mobile.md +37 -0
  244. package/dist/docs/registry/notes-ui-foldkit.md +27 -0
  245. package/dist/docs/registry/notes.md +26 -0
  246. package/dist/docs/registry/people-ui-foldkit.md +28 -0
  247. package/dist/docs/registry/people.md +38 -0
  248. package/dist/docs/registry/shell-foldkit.md +34 -0
  249. package/dist/docs/registry/theme.md +25 -0
  250. package/dist/docs/registry/ui-conformance.md +30 -0
  251. package/dist/docs/release.md +100 -0
  252. package/dist/docs/scaffold.md +826 -0
  253. package/dist/docs/security/threat-model.md +299 -0
  254. package/dist/docs/upstream/zero-cache-socket-handoff.md +105 -0
  255. package/dist/index.d.ts +8 -0
  256. package/dist/index.d.ts.map +1 -0
  257. package/dist/index.js +8 -0
  258. package/dist/index.js.map +1 -0
  259. package/package.json +48 -3
  260. package/src/AgentSkills.ts +329 -0
  261. package/src/AgentWeb.ts +507 -0
  262. package/src/App.ts +435 -0
  263. package/src/Blueprint.ts +276 -0
  264. package/src/Brand.ts +415 -0
  265. package/src/Changelog.ts +136 -0
  266. package/src/Cli.ts +1458 -0
  267. package/src/DbAdmin.ts +115 -0
  268. package/src/Dependencies.ts +170 -0
  269. package/src/Deploy.ts +563 -0
  270. package/src/Docs.ts +309 -0
  271. package/src/Doctor.ts +424 -0
  272. package/src/Dossier.ts +148 -0
  273. package/src/Emit.ts +68 -0
  274. package/src/Errors.ts +18 -0
  275. package/src/Evals.ts +153 -0
  276. package/src/Files.ts +152 -0
  277. package/src/Generate.ts +402 -0
  278. package/src/Guards.ts +541 -0
  279. package/src/Inspect.ts +358 -0
  280. package/src/Keychain.ts +107 -0
  281. package/src/Lock.ts +174 -0
  282. package/src/Mcp.ts +159 -0
  283. package/src/Merge.ts +70 -0
  284. package/src/Migrate.ts +331 -0
  285. package/src/Plugins.ts +347 -0
  286. package/src/Postgres.ts +353 -0
  287. package/src/Publish.ts +64 -0
  288. package/src/Registry.ts +405 -0
  289. package/src/Remote.ts +1158 -0
  290. package/src/Run.ts +541 -0
  291. package/src/SyncGen.ts +570 -0
  292. package/src/Update.ts +873 -0
  293. package/src/bin.ts +46 -0
  294. package/src/index.ts +7 -0
@@ -0,0 +1,148 @@
1
+ # Scheduler
2
+
3
+ Cron and interval jobs with a time zone and an execution identity, event triggers, and recovery sweeps.
4
+
5
+ - Kind: kernel service. Version 1.4.0 (1.1.0: delivery policies and dead letters for event triggers; 1.2.0: a schedule records its creator's provenance and credential scope; 1.3.0: a person's own session is a link of a schedule's authority, never recorded for it; run outcomes and history, no-op runs, failure streaks, run now, one-off runs and shared operation; 1.4.0: a run, schedule or automation the system actor asked for within a narrowed scope, a tool-limited agent run's, runs within it; requests queued before 1.4.0 carry no narrowed system scope and run as recorded).
6
+ - Schema: [`packages/contracts/schema/contracts/Scheduler.json`](../../packages/contracts/schema/contracts/Scheduler.json) (source: [`packages/contracts/src/contracts/Scheduler.ts`](../../packages/contracts/src/contracts/Scheduler.ts); records in [`Durable.ts`](../../packages/contracts/src/Durable.ts))
7
+ - Kernel implementation: [`packages/kernel/src/Scheduler.ts`](../../packages/kernel/src/Scheduler.ts), due-time arithmetic in [`durable/Schedule.ts`](../../packages/kernel/src/durable/Schedule.ts), runtime schedules in the [`scheduler` module](../../packages/kernel/src/scheduler/module.ts)
8
+ - Conformance kit: [`packages/testing/src/conformance/Scheduler.ts`](../../packages/testing/src/conformance/Scheduler.ts), run by [`packages/testing/test/scheduler.test.ts`](../../packages/testing/test/scheduler.test.ts); time zone and DST unit tests in [`packages/kernel/test/schedule.test.ts`](../../packages/kernel/test/schedule.test.ts)
9
+ - Restart proofs: [`packages/testing/test/durable-restart.test.ts`](../../packages/testing/test/durable-restart.test.ts)
10
+
11
+ ## Schedules
12
+
13
+ A schedule is a `ScheduleSpec`, a target, an identity and a catch-up policy.
14
+
15
+ - `{ kind: "cron", expression, timeZone }`: five fields, or six with seconds first, evaluated in an IANA time zone. Cron runs once per matching **local** time. A local time that a DST change skips runs once, shifted by the length of the gap (02:30 on a day when 02:00 jumps to 03:00 runs at 03:30). A local time that a DST change repeats runs once, at its earlier occurrence. Use an interval for "every N minutes of absolute time".
16
+ - `{ kind: "interval", everyMs }`: every `everyMs` milliseconds of absolute time from the schedule's anchor, the moment the kernel first saw it.
17
+ - Target: `{ kind: "action", action, input }` (the kernel's `eloxiv.scheduled-action` workflow invokes it in one step) or `{ kind: "workflow", workflow, input }`. A runtime schedule may target only a workflow defined with `schedulable: true`: a workflow can act as the system actor or trust its input, so letting every member start one is its module's decision. Due runs of a runtime schedule that targets any other workflow are not started (a warning is logged).
18
+ - Catch-up (`CatchUp`), for due times older than the grace period (`ELOXIV_SCHEDULER_GRACE_MS`, default 30 s) when a sweep sees them, that is, runs missed while no kernel was running: `once` (default) runs only the latest missed time, `all` runs each, `skip` runs none. Due times within the grace period always run.
19
+ - A sweep starts at most 100 runs of one schedule, oldest first. When more are due (a long backlog under `all`), the schedule's cursor stops at the last run started and the scheduler sweeps again at once, until the backlog is done: the bound delays runs, it never drops one.
20
+
21
+ ### Manifest jobs
22
+
23
+ A module declares jobs in its contract (`defineModuleContract({ jobs })`), by id:
24
+
25
+ ```ts
26
+ jobs: {
27
+ digest: {
28
+ description: "Send the daily digest",
29
+ schedule: { kind: "cron", expression: "0 8 * * 1-5", timeZone: "Europe/London" },
30
+ action: "mail.sendDigest",
31
+ input: {},
32
+ identity: "system",
33
+ catchUp: "once",
34
+ },
35
+ }
36
+ ```
37
+
38
+ A job runs for every organisation, as that organisation's system actor (`$system`), with the key `job:<module>.<job>:<org>`. Its action must exist and accept its input, and its id must not contain `:`, or the kernel refuses to start. Module names are unique in an app (the kernel refuses two modules with one name), so job keys are too.
39
+
40
+ ### Runtime schedules
41
+
42
+ Install the kernel's `schedulerModule` in the app (`KernelApp.modules`). Its actions run on the one invocation path, so they are authorised by its Cedar policy, audited, idempotent and on every surface:
43
+
44
+ | Operation | Action | Who may |
45
+ | --- | --- | --- |
46
+ | `create` | `scheduler.create` (`name`, `schedule`, `target`, `catchUp?`, `share?`) | any member: the schedule runs as its creator, in the organisation they act in, and their membership is checked again at every run. `share` (members, groups or the organisation, for `view` or `operate`; never a link) is granted in the same transaction: the schedule and its grants exist together, or the call fails and neither does |
47
+ | `pause` | `scheduler.pause` (`id`) | the owner, its operators, holders of `scheduler.manage`. No run starts while it is paused |
48
+ | `resume` | `scheduler.resume` (`id`) | the owner only (resuming binds the schedule to the resuming call's authority). Runs start again from the first due time after the resume, and the failure streak starts again |
49
+ | `runNow` | `scheduler.runNow` (`id`) → `{ id, key }` | the owner, its operators, holders of `scheduler.manage`: one run now, outside the schedule (also while paused), as the schedule's own identity |
50
+ | `delete` | `scheduler.delete` (`id`) | the owner, holders of `scheduler.manage`. Runs already started continue |
51
+ | `share` | `sharing.grant` on the `schedule` entity, permission `view` or `operate` | the owner ([Sharing](sharing.md)) |
52
+ | `run` | `scheduler.run` (`target`) → `{ id, key }` | any member: the target once, now, as themselves (key `run:<id>`); a workflow target must be schedulable |
53
+ | `list` | `scheduler.list` → `ScheduleSummary[]` | what the caller may see: name, schedule, target, paused (and why), failure streak, last run, next due time |
54
+ | `runs` | `scheduler.runs` (`id`, `limit?`) → `RunRecord[]` | the runs of a schedule the caller may see, or of a one-off run they asked for, newest first |
55
+ | `catalog` | `scheduler.catalog` → `AutomationCatalog` | any member: every module action, the schedulable workflows and the declared event types. Listing is not authorisation: every run is checked as it runs |
56
+ | `health` | `scheduler.health` → `SchedulerHealth` | any member: `down` when no kernel swept within five ticks (at least ten seconds), `degraded` when recorded runs have waited longer than the grace period to start, `ok` otherwise |
57
+
58
+ `scheduler.create`, `resume`, `runNow` and `run` are consent-marked (an agent's call needs the person's consent).
59
+
60
+ Pausing ends a schedule's catch-up: when it is resumed, due times up to the resume time that had not started never run, whatever its catch-up policy. That holds also when no sweep saw the schedule paused (it was paused and resumed while no kernel was running, or within one scheduler tick), because the resume records its time (`resumed_at`) and the next sweep moves the schedule's cursor to it. It includes due times from just before the pause that no sweep had started yet (for example, missed while no kernel ran): pausing means no run starts until the resume.
61
+
62
+ A runtime schedule's key is `schedule:<id>`.
63
+
64
+ ### Who sees and operates a schedule
65
+
66
+ Who may see or operate a schedule is separate from whose authority it runs under, which is always its creator's and never changes. Its owner sees and does everything. A member the owner shares it with ([Sharing](sharing.md), the `schedule` entity's sharing permissions) for `view` sees it and its runs; for `operate`, also pauses it and runs it by hand. Holders of `scheduler.manage` see every schedule of their organisation and may pause, run by hand and delete them. A run an operator asks for still runs as the owner, under the authority the owner set the schedule up with; only the owner resumes (resuming re-binds the schedule to the resuming call's authority). There are no public links: a link grant is for members of the organisation, like every grant.
67
+
68
+ ### Runs by hand and one-off runs
69
+
70
+ `scheduler.runNow` and `scheduler.run` record a request in the module's own table (`run_request`), in the call's transaction. The scheduler's next sweep (within a tick) records each request as a run and marks it recorded in one transaction, then starts it like a due run, so a request is never lost and runs once, also across a crash. A schedule's run by hand is recorded in the schedule's history under a key of its own request (`<schedule key>#manual:<request id>`, so no two runs by hand, nor one and a due run, share a record), with `requestedBy` set, only while the authority of the call that asked for it still holds (bound with `bindDeferred` and asserted when the sweep records it: a credential revoked or a member removed meanwhile records the run `refused`), and acts under the schedule's own; a one-off run under `run:<id>`, as its requester (an agent's, as the person's agent, its agent session `run:<id>`), under the authority of the call that asked. A request whose target members may not start (a workflow that is not schedulable, or one the app does not have) is recorded `refused`, with the reason.
71
+
72
+ ### Run history, outcomes and failure streaks
73
+
74
+ Every run's record (`RunRecord`) says how it ended: `pending` (recorded, not handed to the engine yet), `running`, `succeeded`, `noop`, `failed` (with its error tag, never its message, which can carry what the work was about), `cancelled` or `refused` (with the reason). The execution records its end itself (kernel migration `0070_run_outcomes`). A **no-op** is a run that did nothing on purpose: a workflow declares it with `ctx.noop(reason, evidence)` ([Workflow](workflow.md)); an action a schedule runs returns `noOp(reason, evidence)` (`NoOpOutcome` in `@eloxiv/contracts`) as its output; the call's replay receipt carries it too, so a run whose step ran again after a crash (and got the receipt, not the output) still ends a no-op. It is never a failure and never a plain success.
75
+
76
+ A schedule's **failure streak** is how many of its due runs recorded since its last resume failed (or were refused) in a row; runs by hand never count, either way. The scheduler settles a schedule's finished runs together, oldest first, each from the state the one before left (so two failures settled in one sweep alert once, at the first). The scheduler settles each finished run once (claiming it, `settled_at`, together with what follows, in one transaction): when a runtime schedule's streak starts (its first failure after anything else), its owner gets a notification (category `scheduler.failures`, in-app and by their preferences, the email template `scheduler.failed`, with the one-click unsubscribe link every system email carries); when the streak reaches `ELOXIV_SCHEDULER_PAUSE_AFTER` (default 5; 0 never pauses) the kernel pauses the schedule (`pausedReason: "failures"`) and tells the owner again. Runs between are not alerted. A manifest job has no owner and is never paused: its failed runs are logged, and when its streak starts the organisation's operators (members holding `scheduler.manage`, through their roles) get the same notification; with none, the failure is only logged.
77
+
78
+ ## Kernel operations
79
+
80
+ | Operation | What it does |
81
+ | --- | --- |
82
+ | `schedules` | Every schedule the scheduler runs: manifest jobs per organisation, then runtime schedules (`ScheduleRecord`) |
83
+ | `sweep` | Starts every run due at `now` (default: the current time) that has not started, applying catch-up policies, and returns the runs it started (`ScheduledRun`: key, scheduled time, execution id, missed) |
84
+ | `preview` | The next `count` due times of a schedule after `after`; `InvalidInput` for an invalid expression or time zone |
85
+
86
+ ## Guarantees
87
+
88
+ - **One execution per run, and every run recorded.** Each due time starts a workflow execution keyed by (schedule key, scheduled time): `<key>@<ISO time>`. A sweep records its runs in `eloxiv.schedule_run` and advances the schedule's cursor (`eloxiv.schedule_state`) in one transaction, and only then starts them. A sweep cut off before that transaction commits started nothing and plans again on the next start; a recorded run that a crash kept from starting is started by the next sweep, joining the execution if the engine already had it. So a run that ran is always recorded, and a recorded run always runs, whatever the catch-up policy (a policy that passes over missed times never applies to a run already recorded). A run's record is history and is never removed. When the engine refuses a run's start (the app no longer has the workflow, or its input no longer decodes), the run is not retried and its record stays. If an earlier attempt reached the engine before the kernel died, the record stays linked to that execution; otherwise it is marked `refused`, with the reason, and a warning is logged.
89
+ - **Never lost, never repeated.** The run's steps have the Workflow contract's guarantees: a run killed mid-step resumes after a restart and its action returns the replay receipt instead of acting twice.
90
+ - **Recovery sweep.** The kernel's first sweep after it starts finds the runs that came due while it was down and applies each schedule's catch-up policy. A schedule seen for the first time never back-fills runs from before it existed.
91
+ - **One scheduler.** Sweeps run in an Effect cluster singleton: one kernel at a time schedules, fenced by its shard lock, and another takes over when it dies. The loop wakes when the next run is due, and at least every `ELOXIV_SCHEDULER_TICK_MS` (default 1000) to pick up new runtime schedules.
92
+
93
+ ## Event triggers
94
+
95
+ An outbox event type can start a workflow, once per event: `defineModule({ triggers: [{ id, event, workflow }] })` (or `KernelApp.triggers`). A module's trigger ids are namespaced by the module, like jobs (`echo` in module `ledger` is the trigger `ledger.echo`); an app's are used as given. Trigger ids are unique across the app, and a trigger must start a workflow the app defines on an event type an installed module declares: otherwise the kernel refuses to start. The dispatcher delivers each event to each trigger on its type like to a subscriber, matching on both the trigger and the event type, so an event never starts another trigger's workflow: it starts the workflow with the key `event:<trigger>:<event id>`, as the event organisation's system actor, with the input `{ eventId, type, payload }`, and records the delivery as `trigger:<id>`. The execution journals only the event's id and type: the kernel reads the payload from the outbox each time the work runs, so a person's erasure, which scrubs the events naming them, reaches it (work that runs again after one fails on input that no longer decodes). A module's trigger starts only its own workflows; only the emitting module's own triggers continue the emitting call's [Progress](progress.md) tasks. Delivery is at-least-once, and a redelivered event joins the execution its first delivery started, so the workflow starts at most once per event. A trigger may declare `delivery`, a [delivery policy](outbox.md#delivery-policies): a start that keeps failing is retried under it and then dead-lettered (by default after 20 attempts), never retried forever, and listed with the subscribers' dead letters.
96
+
97
+ ## Event automations
98
+
99
+ A runtime schedule whose `schedule` is `{ kind: "event", event, condition? }` is a member's **event automation**: its action (event automations run actions) runs for each event of that type, once per event, as the automation's owner (as the owner's agent, for one an agent set up), on the one invocation path. Every management action above applies to it (pause, resume, share, list, runs, delete); it has no due times, and it is not run by hand. A string value of the target's input that is exactly `{{event.<path>}}` is replaced by that field of the event's payload (null when missing).
100
+
101
+ Only an event that names its record can start an automation: `defineEvent(type, payload, { record: { entity, id } })`, the module's entity and the payload field holding its id (`scheduler.catalog` marks such events `automatable`; the kernel refuses to start on an entity the module does not declare). Each automatable type has a kernel reaction (`kernel:automations:<type>`) that records a run for every unpaused automation on it in the event's organisation (`schedule:<id>#event:<event id>`, timed at the event's occurrence, so a redelivered event records nothing more) in the delivery's transaction; the scheduler's next sweep starts it like any recorded run, so nothing is lost or repeated across a crash. Its run (the kernel workflow `eloxiv.event-automation`) first decides, in one journalled step, whether to act; when it does not, the run ends a no-op whose reason names nothing of the record.
102
+
103
+ Two rules govern what an automation sees (decided at the coordinator's direction as the safe default, 2026-11-14; the owner may overrule):
104
+
105
+ 1. **An automation sees only events on records its owner may read, evaluated at delivery time.** When the run decides, the owner must still be a member of the organisation, and the event's record must pass that record's own read policy for the owner, now (the same check Files and Search make: the entity's compiled `read` filter, as its module role under row-level security). Otherwise the run is a no-op ("Its owner may not read the event's record") and neither the condition nor the action sees the event.
106
+ 2. **A natural-language condition sends the model only that event, and only what its owner may read, through the app's ModelProvider with metering, never other organisations' data.** `condition: { kind: "prompt", prompt }` is judged by the organisation's model (`AgentRuntime.complete`, metered for the owner, after the owner's authority is asserted) from the prompt and the event's type and payload, asked only once rule 1 held, so the payload is of a record the owner may read; nothing else of the organisation, and nothing of any other organisation (an automation sees only its own organisation's events), is sent. Only the model's verdict is kept (journalled, so a resumed run does not ask again): a condition that does not hold records the fixed reason "The condition does not hold", never the model's explanation, since the run's history is read by whoever may see the automation, not by the event record's readers. An app without the agent cannot run such a condition: the run fails, visibly. `condition: { kind: "match", all }` instead tests the payload with the approval rules' comparisons (dot paths, `eq`, `ne`, `gt`, `gte`, `lt`, `lte`, `in`, `exists`, never coerced); no condition always acts.
107
+
108
+ The action's input is built from the payload each time the run acts (never journalled), so a person's erasure that scrubs the event reaches it. Its runs appear in the automation's history like a schedule's due runs, and count towards its failure streak, alerts and pause.
109
+
110
+ **Stated limit.** A run's tool limit governs what the run itself calls. Automations and event triggers that react to its events run with their own owner's authority.
111
+
112
+ ## Agent runs a job starts
113
+
114
+ An agent run that a manifest job or a runtime schedule starts (`agent.send` with the system origin, run kind `job`) is offered one more tool, `no_op` (`{ reason }`): calling it ends the run `succeeded` with stop reason `noop` and the reason as its result, and the run's execution ends a typed no-op ([Workflow](workflow.md)), distinct from a run that finished its work. People's own runs never see the tool.
115
+
116
+ ## Schedules an agent sets up
117
+
118
+ `scheduler.create` and `scheduler.resume` are consent-marked: an agent's call needs the person's consent ([ActionConsent](action-consent.md)). A schedule records its `origin`; one an agent created (or resumed) runs as the person's **agent**, with the execution identity's `agentSession` set to `schedule:<id>`, so its consent-marked calls are held for the person, bound to that schedule, and the agent tool groups the app disabled stay closed to it. A schedule also records the `scope` of the credential that created it (an API token's, an OAuth grant's), and the chain of authorities it was created under (`authority`: the credential, the agent session of a run that created it, the consent that let an agent create it; [Invocation](invocation.md#authority)): every run acts within the scope and only while every link holds, asserted inside each call; a run with a link revoked or expired is refused (`Unauthenticated`, or `Forbidden` for consent, audited). A schedule is bound to the authority of the call that creates it, and again to the authority of the call that resumes it (re-enabling is setting it up again: it never runs on under the chain it was paused with). Its record is marked recurring: a one-time consent authorises the call that set it up, not its runs, so an agent's schedule runs only under a remembered permission (`remember: "session"` or `"always"`), whose revocation stops it; one set up under a one-time consent alone is refused at every run. A schedule created before chains were recorded (migration `scheduler/0003_authority` leaves it NULL) never runs: its calls are refused and audited. A person's own session is not kept: their schedule runs while they are a member. The provenance holds however the creation ran: a `scheduler.create` held for a business approval executes as the call was made, so an agent's approved schedule is still the agent's ([Approvals](approvals.md), guarantee 4a). An app with the scheduler but without the consent module refuses an agent's call to them. See [Daemon](daemon.md#work-that-runs-later-keeps-its-origin).
119
+
120
+ ## Local interval jobs
121
+
122
+ `startIntervalJob(run, { everyMs, timeoutMs?, leading?, onError? })` (`@eloxiv/kernel`) runs caller-owned repeating work in one process: nothing starts until it is called; `run(signal)` runs at once (or after one interval with `leading: false`) and then `everyMs` after each run ended, so runs never overlap; each run's `AbortSignal` aborts past `timeoutMs` (default `everyMs`) or when the job stops; a failure or timeout goes to `onError` and the job continues; `stop()` aborts the run in progress and settles once it ended. A run that ignores its signal holds the job until it ends. It is for work that may be lost with the process (polling a local resource, refreshing a cache); work that must run once, survive a restart or run on one kernel of several is a manifest job or a runtime schedule. Tests: [`packages/kernel/test/interval-job.test.ts`](../../packages/kernel/test/interval-job.test.ts).
123
+
124
+ ## Kernel maintenance
125
+
126
+ `Retention` ([`Retention.ts`](../../packages/kernel/src/Retention.ts)) runs in a cluster singleton beside the scheduler (one kernel at a time), a minute after start and then hourly, deleting in batches: settled outbox events older than `ELOXIV_OUTBOX_RETENTION_DAYS` (default 30; 0 keeps them) with their delivery records, never one with a dead letter or a retrying delivery, nor one whose triggered workflow has not finished (it reads the event's payload whenever it runs); and audit records older than `ELOXIV_AUDIT_RETENTION_DAYS`, only when it is set (by default the audit log is kept for ever); and it clears the saved provider answers of external effects whose module was never told (a refused callback, or one that failed every attempt) once `ELOXIV_EFFECT_ANSWER_RETENTION_DAYS` (default 7; 0 clears them at the next sweep) have passed since the effect ended, keeping the outcome (`result_cleared = 'expired'`; [Invocation, "External effects"](invocation.md#external-effects)). An event is also kept while an event automation's run recorded for it has not finished (waiting to start, or running), however long that takes (`schedule_run.event_id`, migration `0210_run_events`). Each sweep first reconciles executions that ended before migration `0070` (which records each end): it asks the engine how each one older than an hour with no recorded end finished, a batch at a time, and records it, so their schedules' streaks count them and the events they read can go; one still running is asked again at the next sweep. Scheduled runs' records are history and are not pruned. Tests: [`packages/testing/test/retention.test.ts`](../../packages/testing/test/retention.test.ts).
127
+
128
+ ## Local time
129
+
130
+ `scheduler.create` takes `timeZone: "local"` on a cron schedule: the schedule is stored in its creator's time zone preference (`settings.timeZone`, [Settings](settings.md#preferences)) as it is when created, or UTC without one; a later change of the preference does not move it.
131
+
132
+
133
+ ## Recovery backstops
134
+
135
+ agent-native runs periodic timers on long-lived processes to recover work a crash or a lost process left behind. Eloxiv owns each kept case explicitly, and most need no timer: the work is a durable execution on the cluster's fenced shards (one kernel runs a shard at a time, under its advisory lock; another takes the shards of a kernel that died once its registration expires), a durable timer per item, or the outbox's delivery policy. Where a sweep remains, it is a named kernel loop (a cluster singleton or a `Layer` loop), started only on a runner.
136
+
137
+ | agent-native backstop | Eloxiv | Proven by |
138
+ | --- | --- | --- |
139
+ | Drain queued automations (30 s) | The scheduler's singleton sweep starts every recorded run a crash kept from starting (`startPending`) and records runs asked for by hand, each tick | `packages/testing/test/scheduler.test.ts` "keeps a run's record when a retried start is refused, linked to its execution or marked refused"; `durable-restart.test.ts` "neither loses nor repeats a scheduled run killed in the middle" |
140
+ | Redispatch unclaimed chat runs (20 s, 2 min) | An agent run is a durable execution: the kernel that takes its shard resumes it from its last journalled step, never two at once | `agent-restart.test.ts` "resumes a run killed between a tool's commit and the step's record, with the tool's effect exactly once", "never advances one run in two kernels on one database"; `durable-restart.test.ts` "never runs one execution in two kernels on one database, and hands a dead kernel's work to the other" |
141
+ | Reconcile orphaned agent teams (2 min) | A sub-agent is a durable execution of its own, its parent waits for its answer durably; both resume after a crash and finish once | `agent-restart.test.ts` "finishes a delegating run and its sub-agent once after the kernel dies mid-delegation" |
142
+ | Recover sandbox executions (2 min) | There are no background sandbox executions: MAKE code runs inside one call, in one commit (a crash leaves nothing), in a worker the kernel replaces when it dies; an agent's call to it is a tool step, replayed by its receipt | `make-sandbox.test.ts` "keeps serving calls after drafts whose code crashes the interpreter", "leaves no prepared transaction behind"; the agent-restart tool test above |
143
+ | Stuck-task retry (60 s) | Inbound deliveries are accepted durably and the ingress sweep starts any that has no execution | `ingress.test.ts` "starts an execution for an accepted delivery that has none (the sweep)" |
144
+ | Remote-command retry (60 s) | Nothing on the device side needs a job or timer. A device turn is held under a lease: one whose runner restarts is taken back and completed once; one its runner abandoned, or nobody took, is failed by its own durable deadline (`eloxiv.device-turn-deadline`). A device command is recovered when it is read or claimed: never taken, it reads `expired` unrun; taken but never reported, it fails at its deadline ([DeviceControl](device-control.md), "Recovery without timers", with build/daemon-2) | `Daemon` kit "a runner SIGKILLed mid-turn and restarted completes the turn exactly once"; `daemon-limits.test.ts` "fails a turn its runner claimed and abandoned once its deadline passes", "fails a turn nobody ran once its deadline passes, and its workflow ends with it" |
145
+ | Remote-push delivery (60 s) | The daemon delivers nothing itself. Notification deliveries (push, email) are outbox deliveries: retried with backoff under the delivery policy, recorded failed when permanent or out of attempts; a host's push channel targets the person's devices (`Devices.pushSubscriptions(orgId, userId)`) | `Notifications` kit "retries a temporary failure through the outbox, and records the attempts"; `NotificationChannel` kit "reports a temporary failure as retryable, and delivers on the retry" |
146
+ | Connector retries | A connector's external effect is claimed before the provider is called, waits out a rate limit durably (`not_before`), and is sent once across a crash | `registry/test/effects.test.ts` "runs a send the provider rate-limited again, no earlier than its retry time: sent once, succeeded"; `registry/test/effects-restart.test.ts` "killed after the effect went back to pending and before the step was recorded: the restarted kernel sends it once, no earlier than not_before" |
147
+ | A2A continuation recovery | Deferred with A2A itself (external agents, decisions.md: later) | — |
148
+ | Google Docs comment polling (30 s) | Deferred with the comments product (decision 12); a connector that needs polling declares a job, not a process timer | — |
@@ -0,0 +1,81 @@
1
+ # ScreenContext
2
+
3
+ What the person is looking at (the view, the record in focus, the records visible and selected), exposed to their agent so that "this one" and "these" mean something, under privacy rules the person and the app control.
4
+
5
+ - Kind: shell contract. Version 1.1.0 (1.1.0 adds the durable state and agent commands).
6
+ - Schema: [`packages/contracts/schema/contracts/ScreenContext.json`](../../packages/contracts/schema/contracts/ScreenContext.json) (source [`ScreenContext.ts`](../../packages/contracts/src/contracts/ScreenContext.ts)).
7
+ - Implementation: `makeScreenContext(shell, rules)` in `@eloxiv/shell-core` ([`ScreenContext.ts`](../../packages/shell-core/src/ScreenContext.ts)); the kernel's `agent.send` takes the snapshot as `screen` ([AgentRuntime](agent-runtime.md)) and shows it to the model with the message ([`agent/Context.ts`](../../packages/kernel/src/agent/Context.ts), `screenLines`). Durable state and commands: the kernel-provided `app_state` module (`appStateModule`, [`appState/module.ts`](../../packages/kernel/src/appState/module.ts)), the client SDK's `appStateClient`, `commandConsumer` and `consumeCommands` ([`AppState.ts`](../../packages/client/src/AppState.ts)), and shell-core's `screenCommandHandler` ([`ScreenCommands.ts`](../../packages/shell-core/src/ScreenCommands.ts)).
8
+ - Kit: `@eloxiv/testing/conformance/ScreenContext` ([source](../../packages/testing/src/conformance/ScreenContext.ts)).
9
+
10
+ ```ts
11
+ const screen = makeScreenContext(shell, { privateViews: ["mail.compose"], privateEntities: ["people.salary"] })
12
+ // The shell reports as the person navigates
13
+ screen.update({ view: "crm.deals", focus: { module: "crm", entity: "deal", id }, selection })
14
+ // and sends what the rules let through with each message
15
+ await agent.send({ text: "Summarise these", screen: screen.snapshot() ?? undefined })
16
+ ```
17
+
18
+ ## Operations
19
+
20
+ | Operation | Input | Output | What it does |
21
+ | --- | --- | --- | --- |
22
+ | `update` | `ScreenState` | `{}` | Reports the screen: `view` (id or `null`), `focus?`, `visible?`, `selection?` (entity references) |
23
+ | `snapshot` | `{}` | `ScreenSnapshot` or `null` | What the agent may see now, after the rules; `null` while sharing is off, on a private view, with no view open, or on a view no installed module declares |
24
+ | `privacy` | `{}` | `ScreenPrivacy` | The rules in force |
25
+ | `setSharing` | `{ sharing }` | `ScreenPrivacy` | The person's switch |
26
+ | `readState` | `{ keys, tabId? }` | `{ entries }` | `app_state.get`: the person's entries for up to 50 keys: with a tab, its entries and the shared ones; without (the agent, a headless client), the shared ones and every tab's |
27
+ | `writeState` | `{ key, value, tabId?, expectedVersion?, writer? }` | `{ written, version }` | `app_state.write`: set an entry for a tab or shared; with `expectedVersion` only at that version (0: only if none), else `written: false` and the version now |
28
+ | `removeState` | `{ key, tabId?, expectedVersion? }` | `{ removed, version }` | `app_state.remove`: clear an entry (it reads as none afterwards) |
29
+ | `issueCommand` | `{ id, command, tabId? }` | `{ id, issued }` | `app_state.issue`: a command for the person's screen, once under the issuer's `id` |
30
+ | `pendingCommands` | `{ tabId? }` | `{ commands }` | `app_state.pending`: the commands no tab has acknowledged, for this tab or any, oldest first |
31
+ | `commandOutcome` | `{ id }` | `{ id, state, outcome, detail }` | `app_state.outcome`: a command's state (`pending`, `acknowledged`, `unknown`), and once acknowledged its outcome and detail |
32
+ | `acknowledgeCommand` | `{ id, outcome, detail?, tabId? }` | `{ acknowledged, outcome }` | `app_state.acknowledge`: a tab handled it (`done`, `refused`, `failed`); the first counts |
33
+
34
+ ## Records
35
+
36
+ - **`ScreenState`**: as above; references are `{ module, entity, id }` ([WorkItems](work-items.md)'s `EntityReference`).
37
+ - **`ScreenSnapshot`**: `view` (`{ id, title, route }`), `focus` (a reference or `null`), `selection`, `visible` (at most 50 references in all, the focus counted), `withheld` (how many references the rules held back).
38
+ - **`ScreenPrivacy`**: `sharing`, `privateViews`, `privateEntities` (`<module>.<entity>`), `maxReferences` (0 to 50).
39
+
40
+ ## Guarantees
41
+
42
+ 1. **References only.** A snapshot names records by module, entity and id and the view by id, title and route; nothing else the screen reported leaves (a title beside a reference is dropped).
43
+ 2. **Off means nothing**: no snapshot while sharing is off.
44
+ 3. **Private views yield nothing**; references to private entities and to entities no installed module declares are withheld, counted in `withheld` and never named.
45
+ 4. **Bounded**: at most `maxReferences` (never more than 50) references in all, filled focus first, then selection, then visible, each reference once.
46
+ 5. **Never trusted for authorisation.** The kernel validates the snapshot's shape and bounds (`agent.send` refuses one beyond them with `InvalidInput`), stores it with the message, and shows the model the references (`[Screen: view ...]`, `[Screen focus: crm.deal "…"]`); the agent reads the records only through its tools, under the person's policy.
47
+
48
+ ## Durable state and agent commands
49
+
50
+ The snapshot above travels with a message. Durable state lets the agent (or a headless client) see what a tab shows between messages, and lets it ask the screen to do something, through the kernel-provided `app_state` module: install `appStateModule` in the app (and `appStateTables` and `appStateQueries` from `@eloxiv/client/sync` for a live replica of it).
51
+
52
+ ```ts
53
+ const tabId = tabIdentity("my-app", webTabEnvironment()) // once per page load (ClientSDK)
54
+ const state = appStateClient({ baseUrl, token, orgId, tabId })
55
+ await state.publishScreen(screen.snapshot()) // after the rules; null when sharing is off
56
+ const commands = consumeCommands(state, screenCommandHandler(shell, { navigate, openSettings }), { visibility: webVisibility() })
57
+ ```
58
+
59
+ - **Entries** are keyed (`screen`, `route`, `mail.compose`: letters, digits and `._:/-`), per tab (the client's `tabIdentity`) or shared by every tab, at most 16 KiB of JSON each and 200 per person and organisation; past that the oldest per-tab entries are cleared to make room (tabs come and go), and a new shared key is refused. Each has a version (one more on every write) for compare-and-set, and records the tab that wrote it so that tab can ignore its own echo (`isOwnPublication`). Reads go out in the client's read batches (`makeReader`); a write can use `keepalive` so the last screen goes out as the page goes away.
60
+ - **The screen** is published per tab under `screen`, as the snapshot the rules let through (so only references, never field values); `null` removes it. The agent reads it with `app_state.get` (`{ keys: ["screen"] }`).
61
+ - **Commands** are `{ kind, ... }` objects: the module stores them and does not interpret them. Shell-core's `screenCommandHandler` knows `navigate { route }` (a path an installed view serves, never a URL), `open-view { view, record?, params? }`, `open-record { module, entity, id }` (the first view that shows the entity, [View](view.md#navigation-conveniences)), `open-settings { section? }`, `set-search { params }` and `ask { question, options? }` (a structured question for the person, at most 500 characters and 10 options; their answer is the command's detail, and one they dismiss, or outside the options, is refused) and refuses anything else, with why. The agent reads how a command went with `app_state.outcome({ id })`: `pending`, or `acknowledged` with its outcome and detail (an ask's answer); another person's command is `unknown`. `commandConsumer` hands each pending command to the handler once per page load and acknowledges it only after the handler finished (a handler that throws is `failed`); an acknowledgement whose answer was lost is sent again without handling the command again; a command whose page went away before acknowledging is still pending, and the next page handles it. Feed it the replica's `app_state.pending` query, or let `consumeCommands` poll (paused while hidden).
62
+
63
+ Guarantees (each in the kit, against the kernel's module and the agent conformance kernel):
64
+
65
+ 6. **A person's own.** Entries and commands are readable and writable by their person alone, in their organisation (row-level security, synced the same way); their agent acts as them. Another member reads none of them and cannot acknowledge them.
66
+ 7. **Per tab, with compare-and-set.** A tab's entries are its own; shared entries are every tab's; a write with `expectedVersion` writes only at that version, and a late writer is told the version now. A version is opaque and never repeats for a key: a new entry's is the time it is written (seconds since 2020), then one more on each write.
67
+ 8. **Delivered until handled, issued once.** A command is pending until a tab acknowledges it; a command for a tab is only that tab's; issuing the same id again issues nothing; the first acknowledgement counts and later ones are told its outcome. At most 50 are pending.
68
+ 9. **Not trusted.** A command only asks: the shell's handler opens only what the installed views serve. Neither the published screen nor a command grants the agent any read: it reads records only through its tools, under the person's policy.
69
+
70
+ ## How an implementation is checked
71
+
72
+ `screenContextConformance({ make, agent })` builds the implementation over the shell fixture ([`atlas/contract.ts`](../../packages/testing/src/conformance/atlas/contract.ts)) and checks each rule, the budget order as a property over 200 generated screens, and the bound; with `agent` (a kernel with the agent module and a scripted model), that the model is shown the view and references `agent.send` was given and that an oversized snapshot is refused. With `durable` (a kernel with the `app_state` module and the agent, two members and a scripted agent call), it checks guarantees 6 to 8 and that the agent reads a published screen and issues a command for a tab, recorded as the agent's. The Eloxiv implementation runs it in [`screen-context.test.ts`](../../packages/testing/test/screen-context.test.ts); the consumer and the shell's handler are checked in [`screen-commands.test.ts`](../../packages/testing/test/screen-commands.test.ts).
73
+
74
+ ## Retention
75
+
76
+ A runner deletes removed entries (their value cleared) and acknowledged commands once they are older than a day (`ELOXIV_APP_STATE_RETENTION_MS`), every hour (`ELOXIV_APP_STATE_SWEEP_MS`), in every organisation, as the module's system actor (`packages/kernel/src/appState/Sweep.ts`). A removed entry goes only once its version is below the cutoff time as well, so a key written again after the sweep starts above every version it had, and a writer still holding an old one is refused ("never gives a key a version it had before, even written again after its removed entry was swept"). Live entries and pending commands are never swept; an acknowledged command's id is remembered for the retention, so a retried issue within it still issues nothing new. Checked by [`app-state-sweep.test.ts`](../../packages/testing/test/app-state-sweep.test.ts).
77
+
78
+ ## Not yet guaranteed
79
+
80
+ - **No text selection or field values**, by design; an app that wants the agent to see a draft must attach it explicitly.
81
+ - **The rules are the shell's**: a client that ignores them can send any references (still only references, still bounded); the agent's access is what policy allows either way.
@@ -0,0 +1,120 @@
1
+ # Search
2
+
3
+ Full-text and hybrid (full-text plus semantic) search over the records modules declare searchable, the names of the files attached to records, and the text [Ingestion](ingestion.md) extracts (decisions.md "Search: PostgreSQL full-text search; a Rust index later if relevance demands it"; ledger A-048, A-157, C-081, C-132; T964's W-04).
4
+
5
+ - Kind: kernel service. Version 1.1.0 (1.1.0: hybrid search, `mode` and `matched`).
6
+ - Schema: [`packages/contracts/schema/contracts/Search.json`](../../packages/contracts/schema/contracts/Search.json) (source [`Search.ts`](../../packages/contracts/src/contracts/Search.ts)).
7
+ - Implementation: the `Search` service in [`packages/kernel/src/search/Search.ts`](../../packages/kernel/src/search/Search.ts); the index's tracking in [`search/Sources.ts`](../../packages/kernel/src/search/Sources.ts) and migration `0029_files_search_ingestion` ([`KernelSchema.ts`](../../packages/kernel/src/db/KernelSchema.ts)); the kernel module `searchModule` ([`module.ts`](../../packages/kernel/src/search/module.ts)).
8
+ - Kit: `@eloxiv/testing/conformance/Search` ([source](../../packages/testing/src/conformance/Search.ts)).
9
+
10
+ ## Declaring a searchable entity
11
+
12
+ ```ts
13
+ import { defineEntity } from "@eloxiv/contracts/drizzle"
14
+
15
+ export const doc = defineEntity(tables.doc, {
16
+ // name, cedarType, policyAttributes ...
17
+ search: {
18
+ // Text columns of the table and their weights (A ranks highest).
19
+ fields: [
20
+ { column: tables.doc.title, weight: "A" },
21
+ { column: tables.doc.body, weight: "B" },
22
+ ],
23
+ title: tables.doc.title, // what a hit shows as its title (default: the first column weighted A)
24
+ language: "english", // a PostgreSQL text search configuration (default `simple`: no stemming)
25
+ },
26
+ })
27
+ ```
28
+
29
+ The entity needs exactly one organisation attribute (the index is kept per organisation). `language` is one of PostgreSQL's built-in configurations (`SEARCH_LANGUAGES`: `simple`, `arabic`, `english`, `french`, `german`, ...).
30
+
31
+ ## The index
32
+
33
+ The kernel keeps its own index, `eloxiv.search_document`: one document per record, per attached file's name (`file:<id>`) and per ingested chunk (`chunk:<item>:<seq>`), each keyed by the record it belongs to and carrying the record's organisation.
34
+
35
+ - **Never stale.** Setup puts the kernel's `eloxiv.track_record()` trigger (AFTER each row write, SECURITY DEFINER, executable by nobody else) on the table of every searchable entity: a record's document is written, replaced or removed in the same transaction as the record, so a write that rolls back leaves no trace and a committed one is searchable at once. A deleted record's documents (its file names and chunks too) go with it.
36
+ - **Versioned rebuilds.** Setup records each searchable entity's declaration (`eloxiv.record_source`); when it changes (fields, weights, language), setup rebuilds that entity's documents from its table, and moves its ingested chunks to the new language, in its own transaction, so the index is never built from an old declaration nor seen half rebuilt. While it rebuilds it holds the search lock (`eloxiv.search`, one lock whatever entity types it rebuilds), which the trigger takes shared before it reads the declaration: writes to tracked tables wait for the rebuild and then use the new declaration, and the rebuild waits for writes in flight, so none is missed, and a rebuild of several types never waits on a write that waits on it.
37
+ - **One lock order.** Every transaction that writes a record's documents, ingestion items or files takes its locks in one order: in work that acts on someone's behalf, its authority links first ([Invocation](invocation.md#authority): a call asserts them before its handler runs, a sync page before its data), then the search lock (shared), then the record's own lock (`eloxiv.record:<type>:<id>`), then rows (the file, the record's ingestion items in id order, its documents). A record deleted while one of its items is indexed or one of its files is settled waits for it instead of deadlocking.
38
+ - **Bounded.** Each field contributes at most 100,000 characters, a record at most 200,000.
39
+
40
+ ## Hybrid search
41
+
42
+ Where the app configures an embedding model, search also matches meaning:
43
+
44
+ ```ts
45
+ export const app: KernelApp = {
46
+ // ...
47
+ search: {
48
+ embeddings: {
49
+ model: { provider: "openai", model: "text-embedding-3-small" }, // a provider's embeddingModel serves it
50
+ providers: [openaiProvider()], // default: agent.providers (and agent.credentials)
51
+ minSimilarity: 0.35, // default
52
+ },
53
+ },
54
+ }
55
+ ```
56
+
57
+ - **The embeddings.** The kernel embeds each index document (title and body, at most 8,000 characters) by that model through [ModelProvider](model-provider.md) (`embed`, with the document's organisation's credentials), in the background on runners (every 2 seconds, up to 64 documents a pass, `KernelOptions.searchEmbeddingLoop`), into `eloxiv.search_embedding` (migration `0111_search_embeddings`), one unit vector per document with the hash of the text it embedded. A vector follows its document: deleted with it, and deleted in the same transaction as any change to its title or body (a trigger), so no vector of text a record no longer holds outlives the change; the next pass embeds the new text. An organisation whose provider fails is left alone for five minutes. The kernel refuses to start with a model no configured provider embeds with.
58
+ - **A hybrid query** (`mode: "hybrid"`, the default when embeddings are configured) embeds the query and fuses two rankings of the caller's organisation's documents of the requested entities, each its best 200, by reciprocal rank (k = 60): the full-text ranking, and cosine similarity to the query of the vectors of each document's current text, at least `minSimilarity`. The fused candidates then go through exactly the read-policy filter of a full-text query (guarantee 1), and each hit says what `matched`: `words`, `meaning` or `both`. When the query cannot be embedded (the provider failing), the search is full-text, with no error. `mode: "lexical"` is always full-text only.
59
+
60
+ ### Derived copies, and how each goes
61
+
62
+ A derived copy is anything the platform keeps that repeats a record's content outside the record's row: a search document, an ingested item, a work item's title. Each goes (or is rewritten) with what it was derived from, in the transaction that changes it, and none is made visible from content prepared before a change.
63
+
64
+ **One invalidation primitive: the record's generation.** Every tracked record (an entity declaring `search` or `files`) has a generation (`eloxiv.record_generation`, kernel migration `0042_record_generations`), moved under the record's lock by every write to its row (the tracking trigger, on insert, update and delete) and by every whole-record scrub (its deletion, a change to its personal data). A producer takes the generation before it prepares a copy, and makes the copy visible, under the record's lock, only if the generation has not moved: Ingestion's `submit` checks the basis the module took (`ctx.ingestion.basis`, required); Files' finalisation checks the generation a file captured when its upload began for the record (`eloxiv.file.record_generation`), and refuses the file (`rejected`, "Its record changed while the file was being uploaded") if it moved. Field hashes (`derivedFrom`) only spare re-ingesting when unrelated fields change; they are never the safety check.
65
+
66
+ An audit of every writer of `eloxiv.search_document` and of every copy of record text in the kernel and the registry's modules (2026-11-09) found these producers, and no other:
67
+
68
+ | Producer | Copy | Derived from | Rewritten or removed when |
69
+ | --- | --- | --- | --- |
70
+ | The record's own document (`eloxiv.index_record`, from the tracking trigger) | search document `''` | The row's declared `search` fields | Rewritten from the row in the same statement as every insert and update, so it always says what the row says (an anonymisation's new values included); removed with the record (`eloxiv.forget_record`); rebuilt by setup when the declaration changes |
71
+ | Ingested items and their chunks (Ingestion) | ingestion item; search documents `chunk:<item>:<n>` | A file's text, a module's text, an email, a drive's document; titled with the item's title | Stored only if the record's generation is still the basis's. Removed by the one scrub (`eloxiv.scrub_ingested`) whenever the item is: the record deleted, the record's personal data changed, a field the item was derived from changed (`derivedFrom`; an item with no hash counts as changed), its file deleted, or a newer version indexed |
72
+ | Attached files' names (Files, when a file becomes available) | search document `file:<id>` | The file's name | Made visible only if the record's generation has not moved since the upload began. Removed when the file is deleted (`forgetFile`), when the record is deleted, and when the record's personal data changes (the whole-record scrub, kernel migration `0041_derived_documents`). The file stays attached; its name is not indexed again |
73
+ | Work items (WorkItems) | the item's `title` | The record's text, as the module words it (mail's follow-ups: "Follow up: <subject>"; calendar's invitations: "Invitation: <title>") | Fenced like ingestion: a module takes the source record's generation (`ctx.workItems.basis`, under the record's lock) after writing it, and every `put` and `retitle` states the generation its title was prepared from; one whose record has changed since is skipped (a subscriber carries the generation its event was emitted at, so its write never lands after an erasure). Records of work-item sources that Search and Files do not track get a generation too (`eloxiv.track_generation`, kernel migration `0042`). The module retitles every item of a record (whatever its state, closed ones too) whenever the text changes or the record becomes a tombstone (mail on every message it syncs or checks, calendar on every event it syncs or removes). A module that words a source's titles in the kernel (`defineModule({ workItemTitles })`, from the source's title field: mail's follow-ups and queued drafts, calendar's invitations) has the kernel keep them too: after any action's writes, every item of a live record written takes the title the record gives as the write left it, in the call's transaction, whether or not the module retitled it; and every setup retitles every live record's items from it, so an item titled before titles followed their records is brought into step without waiting for the module to write the record. The kernel clears the titles of every item of a record that is gone or a tombstone (`defineModule({ tombstones })`) after any action's writes (`WorkItems.followRecords`) and of every record an erasure deletes or anonymises, and every setup clears those of records already gone or tombstoned. Mail's migration `0007` marks every message synced before checks existed to be checked once, which retitles its follow-ups from what the provider says. The kernel words a title only with the module's own wording (`workItemTitles`); without one it leaves titles to the module |
74
+ | Thread subjects (mail) | `mail.thread.subject` | The subject of the thread's first live message | Recomputed from the thread's live messages (tombstones excluded) whenever one of them is synced, checked or becomes a tombstone; emptied when none is left; deleted with the thread by an erasure (`dataSubjects`) |
75
+ | Change records' titles (calendar) | `calendar.change.title` | The event's title when the change was asked for | Rewritten from the event every time it is synced or brought up to date after a change; cleared when the event is gone from the calendar; deleted with the change by an erasure |
76
+ | Removed events (calendar) | `calendar.event` kept with `removed` | The provider's event | Cleared when the event is gone from the calendar (its title, description, location and attendees), keeping only what free/busy bookkeeping needs |
77
+
78
+ The modules add no producer of their own: `mail` declares `search` on its messages (record documents), ingests their bodies (chunks), derived from the subject, sender, preview and the provider's version, and puts follow-ups (titled from the subject); a message gone from the provider's mailbox is cleared to a tombstone (its document rewritten empty, its body scrubbed, its follow-up's title cleared). `calendar` declares no `search` and ingests nothing, and puts invitations (titled from the event's title). `people` has neither. Search's own operations only read the index; setup's rebuild only rewrites record documents from their rows and moves chunks to a new language.
79
+
80
+ **Other copies of record text, and why they are not kept in step.** These hold record text too, but are records of something that happened at a moment, not views of the record; each is covered by the privacy inventory instead (`packages/kernel/src/privacy/Inventory.ts`):
81
+
82
+ - **Notifications** (`eloxiv_notifications`): a message sent to someone at a moment, with the text the sender chose then (no registry module sends any today). Like a sent email, it is not rewritten when its source changes; it is erased with its recipient's data.
83
+ - **The audit log**: evidence of who did what, as it was. An erasure scrubs the entries that name the person and pseudonymises the actor; it is never rewritten from records.
84
+ - **Agent sessions and transcripts**: what an agent saw (tool results quoting records) when it saw it, readable only by the session's owner, erased with their owner. A record anonymised later is not rewritten in someone else's transcript (backlog item 15).
85
+ - **Agent memory and resources**: personal ones are their owner's, erased with them; **organisation-scoped** ones (`scope: "org"`, readable by every member of the organisation; `agent/module.ts`) can quote a person in their text, where no field names them: an erasure replaces the person's mentions there with `[erased person]`, in that organisation only (their exact email as a whole token, never part of a longer address, and their full name as whole words when it has two or more), purges the parts of earlier exports that copied such entries, and an export includes the entries that mention them (the `agent.orgMentions` source; [`privacy-org-memory.test.ts`](../../packages/testing/test/privacy-org-memory.test.ts)). Not found, by design: a one-word name and the words of a name used alone (they are ordinary words too often), a nickname, a paraphrase.
86
+ - **Saved provider results** (`eloxiv.connection_effect.result`): the provider's resource an external effect returned (an event with its attendees, a sent message's id), kept only while the module may still need it, the outcome (state, reconciled, error) always kept and saying why the answer is gone (`result_cleared`; `ctx.connections.effect` gives it as `cleared`): once the module's callback has run (`onDone`), cleared (`told`, `told_at`), so the answer lives only in the module's record, which erasure reaches by its subject, and a callback run again answers with what it recorded instead of reading the answer (calendar 0.2.3, mail 0.2.3; `calendar.test.ts`, `mail.test.ts`); an effect whose action names no callback, cleared as soon as its outcome is recorded (`no-callback`); one whose callback was refused for good (the authority it was bound to gone), kept for the module's own reconciling from the record for `ELOXIV_EFFECT_ANSWER_RETENTION_DAYS` after it ended (default 7), then cleared by the kernel's retention sweep (`expired`). Whatever the case, an erasure clears every answer still kept that mentions the person, whoever owns the effect (`erased`; the source `eloxiv.effectAnswers`, [Privacy](privacy.md)). Tests: `registry/test/effects.test.ts` (backlog item 14).
87
+ - **Sent mail records** (`mail.outgoing`: recipients and subject): a record of what was sent, like a sent folder, erased with its owner (backlog item 16).
88
+ - **Outbox event payloads, workflow journals and idempotency receipts**: a change's description in flight. An erasure scrubs outbox payloads that name the person; workflow journals are retained to finish or replay executions (modules keep personal data out of workflow inputs and signals); receipts hold ids and outcomes.
89
+ - **Record history** (Versioning): versions of a record, purged for every record an erasure deletes or anonymises.
90
+ - **Privacy exports**: a person's own export, deleted by any erasure whose subject it names.
91
+ - **Sync replicas**: they replicate rows, so a rewritten row (a tombstone, an anonymisation) reaches them through replication.
92
+
93
+ ## Operations
94
+
95
+ | Operation | What it does |
96
+ | --- | --- |
97
+ | `query` (action `search.query`) | `{ query, modules?, entities?, limit?, mode?, cursor? }` in the organisation the caller acts in. Web-search syntax: words (all must match, stemmed by each entity's language), `"a phrase"`, `or`, `-word`. Returns hits best first: the record (module, entity, id), where it matched (`record`, a `file` with its id, or a `chunk` with its ingestion item, file, position and character range), its title, a plain-text snippet with `[start, end)` highlight offsets, and the rank; `nextCursor` while more of the index remains. Unknown modules or entities, and a cursor that is not one, are `InvalidInput`. A cursor is **sealed** (AES-GCM, a key derived from the kernel's secret) and bound to the caller, the organisation and the query (its text and filters): what it holds, which may be a candidate the caller cannot read, is never visible, and it is refused for any other caller or query, altered or forged |
98
+
99
+ One action on every surface: the typed client, HTTP `POST /api/actions/search.query`, the MCP tool `search_query`, the agent's tool of the same name, and the CLI. Every call is audited.
100
+
101
+ ## Guarantees
102
+
103
+ 1. **No hit the caller cannot read.** Candidates are read from the index in rank order (rank, then the document's key: a total order a cursor resumes from) and each batch is filtered by the read policy of the records they belong to, for the caller, now: compiled from the entity's Cedar `read` policy and checked against the records as the entity's module role under its row-level security. Unreadable candidates are skipped without a trace: no count, no gap. A query scans at most 2,000 candidates; when it stops early it returns a cursor, so a page may hold fewer hits than asked for (even none) and still have a next one.
104
+ 2. Only the acting organisation's documents are ever candidates.
105
+ 3. The index follows every write in its transaction (above).
106
+ 4. Cursor pages neither repeat nor skip a readable hit; a cursor reveals nothing and works only for its caller and query.
107
+ 5. Ranking follows the declared weights (PostgreSQL's cover density ranking); snippets are plain text, never markup.
108
+ 6. **Hybrid search is confined as full-text search is:** only the acting organisation's vectors are compared, every fused candidate passes the read-policy filter, and a vector counts only for its document's current text (it is deleted when the text changes or the document goes). ([`search-hybrid.test.ts`](../../packages/testing/test/search-hybrid.test.ts), against a deterministic fake embedding model)
109
+
110
+ ## How an implementation is checked
111
+
112
+ `searchConformance(start)` takes a `FilesSubject` (see [Files](files.md)). Besides ranking, stemming, syntax, writes, rollbacks, modules, cursors, organisations and surfaces, it runs a **differential test against the read policy**: random documents with random owners, visibilities and `read`/`edit` grants, then random revocations, visibility changes and deletions; for every user and word, the hits must be exactly the documents the fixture's read policy (evaluated independently in the kit) admits, for record hits, for chunk hits (emails filed under documents) and for file hits (attached files' names). Another test pages past the scan limit (2,100 unreadable candidates) to exactly the readable hits and checks the cursors reveal and admit nothing else. The kernel's runner is [`search.test.ts`](../../packages/testing/test/search.test.ts).
113
+
114
+ ## Not yet guaranteed
115
+
116
+ - No typo tolerance or prefix matching; full-text relevance is PostgreSQL's.
117
+ - Semantic similarity is computed in SQL over the organisation's vectors, with no approximate-nearest-neighbour index (pgvector is not assumed): fine for some tens of thousands of documents per organisation, a scan beyond. A vector embedded concurrently with a change to its document's text may be stored after the change's trigger ran; it never matches (its text hash is checked at query time) and the next pass replaces it.
118
+ - Embedding happens in the background: a new or changed document is found by words at once and by meaning after the next pass.
119
+ - Ranks are comparable within one result list only.
120
+ - A rebuild runs in setup's transaction; a very large table makes setup take as long.
@@ -0,0 +1,74 @@
1
+ # Secrets
2
+
3
+ Scoped secret custody: values encrypted at rest with envelope encryption, reachable only through the kernel, every read and write audited by name and scope (never by value). Connections keep their tokens here; Ingress verifier secrets can move here later.
4
+
5
+ - Kind: kernel service. Version 1.1.0 (1.1.0: destinations, managed secrets, hints, the inventory and removal previews).
6
+ - Schema: [`packages/contracts/schema/contracts/Secrets.json`](../../packages/contracts/schema/contracts/Secrets.json) (source [`Secrets.ts`](../../packages/contracts/src/contracts/Secrets.ts)).
7
+ - Implementation: [`packages/kernel/src/connections/Secrets.ts`](../../packages/kernel/src/connections/Secrets.ts) (the service and `POST /kernel/secrets/*`), [`Crypto.ts`](../../packages/kernel/src/connections/Crypto.ts) (envelope encryption, `KeyEncryption`). Table `eloxiv.secret` (kernel migration `0022_connections`).
8
+ - Kit: `@eloxiv/testing/conformance/Secrets` ([source](../../packages/testing/src/conformance/Secrets.ts)), run by [`packages/testing/test/secrets.test.ts`](../../packages/testing/test/secrets.test.ts).
9
+
10
+ ## Scopes
11
+
12
+ A secret belongs to one scope and has a name (lower case letters, digits, `.`, `_`, `-`; at most 100 characters), unique in its scope:
13
+
14
+ | Scope | Holds | Managed by |
15
+ | --- | --- | --- |
16
+ | `{ kind: "org", orgId }` | the organisation's own secrets (an API key a module uses) | members with `eloxiv.secrets.manage` |
17
+ | `{ kind: "user", orgId, userId }` | a person's own secrets in the organisation | that person |
18
+ | `{ kind: "connection", orgId, connectionId }` | a Connection's `access_token` and `refresh_token` | Connections only |
19
+
20
+ ## Encryption at rest
21
+
22
+ Envelope encryption:
23
+
24
+ 1. Each write draws a fresh 256-bit **data key** and encrypts the value with AES-256-GCM (96-bit random nonce, 128-bit tag). The associated data is `eloxiv-secret:v1:<scope kind>:<org>:<subject>:<name>`, so a ciphertext copied into another secret's row does not decrypt.
25
+ 2. The data key is **wrapped** by a key-encryption key through `KeyEncryption` (`wrap`, `unwrap`, `currentKeyId`), with the same associated data. Only the wrapped key, the key's id and the ciphertext are stored. The data key is zeroed after use.
26
+ 3. The default `KeyEncryption` uses the deployment's keys from configuration: `ELOXIV_SECRETS_KEYS=<id>:<base64 32 bytes>,<id>:<base64 32 bytes>` (`KernelConfig.secrets.keys`), the first current, the rest kept to unwrap secrets not yet rotated. Without keys, a development key is derived from `ELOXIV_AUTH_SECRET` (key id `derived`) and a warning is logged; production deployments must set keys.
27
+ 4. A KMS plugs in as another `KeyEncryption` layer (`KernelOptions.keyEncryption`): wrap and unwrap are effects, so they may call a remote service.
28
+
29
+ ## Operations
30
+
31
+ | Operation | Where | What |
32
+ | --- | --- | --- |
33
+ | `put` | in process (`Secrets.put`); `POST /kernel/secrets/put` for a signed-in person | Store or replace a secret; returns its metadata (never the value). Audited `eloxiv.secrets.write` |
34
+ | `read` | in process only | The value and metadata; `SecretNotFound` or `SecretUnreadable`. Audited `eloxiv.secrets.read` with a purpose (`connection.request`, `connection.refresh`, ...). No surface reads a value |
35
+ | `delete` | in process; `POST /kernel/secrets/delete` | One secret, or every secret of a scope. Audited `eloxiv.secrets.delete` |
36
+ | `list` | in process; `POST /kernel/secrets/list` | Metadata of a scope's secrets (scope, name, key id, version, `allowedOrigins`, `managedBy`, `hint`, times) |
37
+ | `inventory` | `POST /kernel/secrets/inventory` | The caller's own secrets and, with `eloxiv.secrets.manage`, the organisation's, each with its `usages`; and every secret the app requires that is not put yet (metadata null) |
38
+ | `previewRemoval` | `POST /kernel/secrets/preview-removal` `{ scope, name }` | What deleting it would break (`usages`), and whether management may delete it (`deletable`: no feature manages it). Nothing is deleted |
39
+ | `usages` | in process | What uses a secret: each Connection that sends it (`as: credential`) or its OAuth client's secret (`client-secret`), and each requirement of the app naming it |
40
+ | `rotate` | in process | Re-encrypt every secret whose key is not the current one with a new data key and new ciphertext, each in a short locked transaction; a secret that does not decrypt is left and counted in `unreadable`. Audited `eloxiv.secrets.rotate` with the counts |
41
+
42
+ Over HTTP the caller must be a signed-in person (a Better Auth session; machine credentials are refused) acting in the scope's organisation: `user` scope only for themselves, `org` scope only with `eloxiv.secrets.manage` (granted to the built-in `admin` role), `connection` scope never. Refusals are audited as `denied`. An operation runs in one transaction that holds the person's session first (locked `FOR SHARE`, its expiry read again under the lock), so a sign-out waits for a change in flight, or commits first and refuses it (`401`). The HTTP routes answer `{ _tag, message }` with 401, 403 or 400.
43
+
44
+ ## What a secret carries besides its value
45
+
46
+ - **`allowedOrigins`** (given with `put`): the only origins it may be sent to. [Connections](connections.md#endpoint-connections) refuse to add, or to send a request over, an endpoint Connection naming the secret for any other origin. Null: wherever what uses it sends it (an endpoint Connection's own origin).
47
+ - **Reserved names**: a name under a prefix a feature reserves (`model.`, the agent's model keys) is neither created nor changed by management over HTTP.
48
+ - **`managedBy`** (in process, `put(..., { managedBy })`): the feature that owns it. Management over HTTP cannot replace or delete it (`Forbidden`, naming the feature), and deleting a whole scope leaves it: it is removed where it is managed.
49
+ - **`hint`**: `…` and its last four characters, for a value of at least 16 characters (null otherwise), so a person can tell which key is stored without reading it. Four characters of a long random key say little about it; the ciphertext guarantee below covers the value, not this hint.
50
+
51
+ **Requirements.** An app declares the secrets it needs in `KernelApp.secrets` (`{ scope: "org" | "user", name, feature, description }`); the inventory lists each, put or not, with the feature as a usage, so an administrator sees what is missing and what removing a key would break.
52
+
53
+ ## Errors
54
+
55
+ `SecretNotFound`, `SecretUnreadable` (an unknown or retired key, or tampered data), and for management `Unauthenticated`, `Forbidden`, `InvalidInput`.
56
+
57
+ ## Guarantees
58
+
59
+ 1. The database holds only ciphertext, wrapped data keys and key ids: no value in any encoding.
60
+ 2. A ciphertext decrypts only in its own scope and name.
61
+ 3. Every read, write, delete and rotation is audited (`eloxiv.secrets.<op>`), with the scope and name in `detail` and their hash as `input_hash`: never the value or a hash of it.
62
+ 4. Module roles have no privilege on the `eloxiv` schema, so no module handler or subscriber reaches the table; the kernel API is the only way to a value.
63
+ 5. Rotation re-encrypts under the current key; afterwards the retired key can be removed, and a kernel holding only the retired key cannot read.
64
+
65
+ ## How an implementation is checked
66
+
67
+ `secretsConformance(subject, keys)` registers: the inventory with usages, a managed secret refused to management and a removal preview naming what it would break; a secret's destinations recorded as origins; ciphertext only (the value, its base64, base64url and hex absent from every column); a ciphertext moved to another row refused with `SecretUnreadable` (and rotation then reporting it as unreadable); write, read and delete audited without the value or its SHA-256; a module runtime role without usage of the schema or any privilege on the table; rotation from one key to another (new ciphertext, version incremented, the retired key removable, a kernel with only the retired key refused); HTTP management (own secrets yes, the organisation's only with the permission, another person's and Connection secrets never, no read operation). The subject (`SecretsReference.ts`) starts kernels on one database with the keys each check needs.
68
+
69
+ ## Not yet guaranteed
70
+
71
+ - **Ingress verifier secrets** still come from configuration (`IngressSecrets`); moving them into Secrets is a follow-up.
72
+ - **Usages are Connections and declared requirements**: code that reads a secret in process by name (a model provider's credentials) is a usage only where it is declared as a requirement.
73
+ - **Substituting a secret into arbitrary requests** (agent-native's `web-request` with `{{secret}}` references) is not offered: a secret leaves the kernel only as an endpoint Connection's credential, to its endpoint.
74
+ - **A KMS adapter** is an interface only; none ships.