@eloxiv/cli 0.0.0-stage → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (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 +110 -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 +50 -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 +35 -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,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.
@@ -0,0 +1,109 @@
1
+ # Settings
2
+
3
+ Scoped values that modules declare in their manifests, each with a value schema and a default, read one key at a time (decisions.md "Settings"; the ledger's keyed `getSetting`, A-002, A-043).
4
+
5
+ - Kind: kernel service. Version 1.0.0.
6
+ - Schema: [`packages/contracts/schema/contracts/Settings.json`](../../packages/contracts/schema/contracts/Settings.json) (source [`Settings.ts`](../../packages/contracts/src/contracts/Settings.ts)).
7
+ - Implementation: the `Settings` service in [`packages/kernel/src/Settings.ts`](../../packages/kernel/src/Settings.ts); the kernel module `settingsModule` ([`settings/module.ts`](../../packages/kernel/src/settings/module.ts)); the client's sync table and resolver in [`@eloxiv/client/sync`](../../packages/client/src/PlatformSync.ts).
8
+ - Kit: `@eloxiv/testing/conformance/Settings` ([source](../../packages/testing/src/conformance/Settings.ts)).
9
+
10
+ ## Declaring a setting
11
+
12
+ In the module manifest ([ModuleManifest](module-manifest.md)):
13
+
14
+ ```ts
15
+ settings: {
16
+ "hello.defaultVisibility": {
17
+ description: "Who sees a new greeting when the caller does not say.",
18
+ scope: "user", // user | org | app | module
19
+ schema: Visibility,
20
+ default: "org", // encoded (JSON); must decode against the schema
21
+ },
22
+ },
23
+ ```
24
+
25
+ **Secrets never go in settings.** A setting whose schema is marked sensitive (annotated `sensitive: true` or `writeOnly: true`, a `password` format, or an Effect `Redacted`, anywhere inside it) is refused when the app's manifests are loaded; secrets belong to the Secrets contract.
26
+
27
+ ## Levels and resolution
28
+
29
+ A value can live at four levels, narrowest first:
30
+
31
+ | Level | Where it lives | Who sets it |
32
+ | --- | --- | --- |
33
+ | `user` | `eloxiv_settings.value`, per person and organisation | the person (`settings.set`) |
34
+ | `org` | `eloxiv_settings.value`, per organisation | organisation administrators (`eloxiv.settings.manage`) |
35
+ | `app` | `KernelApp.settings.app`, overridden by `eloxiv.deployment_setting` | configuration, or a deployment administrator (`configure`) |
36
+ | `module` | `KernelApp.settings.module`, overridden by `eloxiv.deployment_setting` | configuration, or a deployment administrator |
37
+
38
+ A setting's declared **scope is the narrowest level it accepts**. A read resolves the levels from its scope outwards and takes the first that holds a value, else the default (`resolveSetting` in `@eloxiv/contracts`):
39
+
40
+ - `user`: the person's own value, the organisation's, the deployment's, the module installation's, the default;
41
+ - `org`: the organisation's, the deployment's, the module installation's, the default;
42
+ - `app`: the deployment's, the module installation's, the default;
43
+ - `module`: the module installation's, the default.
44
+
45
+ So an organisation administrator can give a user-scope setting an organisation-wide value that each person may override, and a deployment can set a default for every organisation.
46
+
47
+ Configured values (`KernelApp.settings`) are checked at startup: the key must be declared, the level must be one its scope reaches, and the value must decode against its schema; a problem stops the kernel like any manifest problem. A stored value that no longer decodes (a module changed the schema) is skipped with a warning, and the next level applies.
48
+
49
+ ## Operations
50
+
51
+ | Operation | As | Input | Output |
52
+ | --- | --- | --- | --- |
53
+ | `get` | the action `settings.get` (read-only, every member) | `{ key }` | `SettingRead`: `key`, the encoded `value`, and `source` (the level, or `default`) |
54
+ | `set` | the action `settings.set` | `SettingWrite`: `key`, `value` (encoded), optional `level` (`user` or `org`, default the setting's scope) | `SettingChanged`: `id`, `key`, `level` |
55
+ | `clear` | the action `settings.clear` | `{ key, level? }` | `SettingChanged` |
56
+ | `configure` | in process only, `Settings.configure` (operators: no surface reaches it) | `{ key, level: "app" \| "module", value }` (`null` removes it) | |
57
+
58
+ Handlers read settings through **`ctx.settings.get(key)`**, which resolves the key for the caller exactly as `settings.get` does and returns the value decoded with the setting's schema; an undeclared key is a defect.
59
+
60
+ **How a handler reads them.** On the handler's own connection and transaction, without ever switching its role: the handler's runtime role cannot read `eloxiv.deployment_setting` or the `settings` module's table, so both are read through the platform read functions setup creates in schema `eloxiv_platform` (`deployment_setting(key)` and `stored_setting(key)`). Each is `SECURITY DEFINER`, owned by the dedicated NOLOGIN role `eloxiv_platform_read`, with a fixed search path; it takes only the key, refuses a transaction with no invocation context, and returns only that key's values for the caller the context records (their own `user` value and their organisation's `org` value; the `app` and `module` values). Only module runtime roles may execute them. A role switch around the reads would also apply to statements the handler runs concurrently on the same transaction (`Effect.all` with concurrency), which would run as the kernel; none happens.
61
+
62
+ There is **no operation that lists settings**: every read names its key, on the action and on the sync query alike.
63
+
64
+ Errors: `InvalidInput` for an undeclared key, a level the setting's scope does not have, or a value that does not decode against its schema; `Forbidden` when the caller may not write that level (a member writing the organisation's value, anyone writing an `app` or `module` scope setting through an action); `Unauthenticated`.
65
+
66
+ ## Authorisation
67
+
68
+ The `settings` module's Cedar policy, enforced by the invocation path and row-level security:
69
+
70
+ - a person sets and clears their own `user`-level values, in the organisation they act in;
71
+ - organisation administrators (`eloxiv.settings.manage`, which the built-in `admin` role grants) set and clear `org`-level values of their organisation;
72
+ - members read their own `user`-level values and their organisation's `org`-level values;
73
+ - `app` and `module` levels are not writable through actions: they are configuration, or `configure`.
74
+
75
+ An agent acting for a person writes what the person may write.
76
+
77
+ ## Sync
78
+
79
+ The `settings` module's table syncs to each person's replica: their own `user`-level values and their organisation's `org`-level values, in the organisation they act in. Add `platformTables` and `platformQueries` from `@eloxiv/client/sync` to the app's sync configuration. The named query `settings.value` takes the key as its argument (`zero.query.settings.value("hello.defaultVisibility")`), so the replica too is read by key. A row's `value` is `{ v: <encoded value> }`, or `null` once cleared.
80
+
81
+ `settingFromReplica(declaration, rows, deployment?)` resolves the value locally as the kernel does, including skipping a value (synced or passed as `deployment`) that no longer decodes against the declaration's `schema`, so the next level applies. Deployment values (`app` and `module` levels) are configuration and are not in the replica: an app that sets them reads them once with `settings.get` and passes them as `deployment`.
82
+
83
+ ## Setup checklists
84
+
85
+ A module's (or app's) onboarding is a checklist kept in a setting (ledger B-067): `defineChecklist({ key, title, description, scope?, steps })` (`@eloxiv/contracts`) gives the setting to declare under its key (`settings: { [checklist.key]: checklist.setting }`), whose value is a `ChecklistState` (the steps done or dismissed, with when, and whether the list is collapsed or dismissed; empty by default). Because it is a setting, a `user` checklist's progress is the person's alone, in the organisation they act in, durable and on every device they sign in on (their replica holds it: `checklistFromReplica(checklist, rows)` over `settings.value`); an `org` checklist is one shared list that organisation administrators complete and every member reads.
86
+
87
+ The headless state is pure (`completeStep`, `dismissStep`, `reopenStep`, `collapseChecklist`, `dismissChecklist`; a step the checklist does not declare changes nothing), and `checklistSummary(checklist, state)` is what a screen or an agent shows: each declared step's status in order, the counts, `complete`, `collapsed` and `visible` (neither dismissed nor complete). A change is written as the next state through `settings.set` (`checklistWrite(checklist, state)` is its input), so it goes through the one invocation path, is audited, and the person's agent can make it as they could (`packages/testing/test/checklists.test.ts`).
88
+
89
+ **Limit, stated:** a write replaces the whole state, so two devices changing the same checklist at the same moment keep the later write (a tick can be lost and is made again); progress is never shared between people.
90
+
91
+ ## Audit
92
+
93
+ Every `set` and `clear` is an invocation, audited once ([Audit](audit.md)), with `detail` `{ key, level, subject, before, after }` (the encoded values; `subject` is the person or the organisation). Refused writes are audited as `denied` or `failed`. `configure` is audited as `eloxiv.settings.configure` with the same `detail` (`subject` is the operator).
94
+
95
+ ## Preferences
96
+
97
+ The kernel's `settings` module declares each person's preferences (`PREFERENCE_SETTINGS`, user scope): `settings.locale` (a BCP 47 tag, or null for the browser's), `settings.timeZone` (an IANA zone, or null for the device's) and `settings.theme` (`system`, `light` or `dark`; default `system`). They resolve like any user-scoped setting (the person's own value, else their organisation's, which administrators set, else the default), are checked against their schemas, and sync to the person's replica, so every device of theirs shows the same. In the client: `preferencesFromReplica(rowsOf)` reads them from the replica's `settings.value` rows as the kernel does; `savePreference(transport, "theme", "dark")` and `clearPreference` write the person's own value through `settings.set` and `settings.clear`. A cron schedule created with `timeZone: "local"` runs in its creator's time zone preference as it is then (UTC without one; [Scheduler](scheduler.md)). Tested in [`preferences.test.ts`](../../packages/testing/test/preferences.test.ts).
98
+
99
+ ## How an implementation is checked
100
+
101
+ `settingsConformance(start)` takes a `PlatformSubject` (see [QuerySurface](query-surface.md#how-an-implementation-is-checked)). The fixture's `crm` module declares `crm.pageSize` (user scope, an integer from 1 to 200, default 25), `crm.currency` (org, `USD`, `EUR` or `SAR`, default `USD`), `crm.region` (app, configured `me-central`) and `crm.limit` (module, configured 250), and its `crm.peek` action returns what `ctx.settings.get` gives.
102
+
103
+ The kit checks: keyed reads with their source, on several surfaces, and that no list operation exists; resolution through every level in order, including a deployment administrator's value over configuration and an app-level value under an organisation's; authorisation per level (members, administrators, another organisation's administrator, deployment scopes, an agent acting for a person); validation against the schema; each person's replica holding exactly their own values and their organisation's, per key, and nothing for another organisation or a non-member; the audit records of writes, refusals and `configure`; `ctx.settings.get` in a handler; and sensitive schemas refused. The Eloxiv kernel runs it in [`packages/testing/test/settings.test.ts`](../../packages/testing/test/settings.test.ts); a handler's role staying its own while `ctx.settings.get` and `ctx.flags.isEnabled` read, and the platform read functions' grants and answers, in [`handler-role.test.ts`](../../packages/testing/test/handler-role.test.ts); `settingFromReplica` in [`platform-sync.test.ts`](../../packages/testing/test/platform-sync.test.ts); the pure resolution and manifest checks are proven in [`packages/contracts/test/platform.test.ts`](../../packages/contracts/test/platform.test.ts).
104
+
105
+ ## Not yet guaranteed
106
+
107
+ - **Deployment values on the client**: `app` and `module` levels are not synced (they have no organisation); clients read them with `settings.get`.
108
+ - **Per-person values across organisations**: a person's `user`-level value belongs to the organisation they set it in.
109
+ - **No settings UI**: settings pages are registry code over these actions.
@@ -0,0 +1,77 @@
1
+ # Sharing
2
+
3
+ Per-record grants to a user, a group, the whole organisation or a link, and access requests (decisions.md, the Sharing row; decision 2). Grants compile into the same policy filters that row-level security, sync and the query views apply, evaluated for the acting principal only.
4
+
5
+ - Kind: kernel service. Version 1.0.0.
6
+ - Schema: [`packages/contracts/schema/contracts/Sharing.json`](../../packages/contracts/schema/contracts/Sharing.json) (source [`Sharing.ts`](../../packages/contracts/src/contracts/Sharing.ts)).
7
+ - Implementation: the kernel's [`Sharing`](../../packages/kernel/src/Sharing.ts) service (`forActor`, the trusted `grant` and `revoke`, the expiry `sweep`) and the kernel-provided [`sharing` module](../../packages/kernel/src/sharing/module.ts) (`sharingModule`), whose actions are the operations below; tables in kernel migration `0017_sharing` ([`KernelSchema.ts`](../../packages/kernel/src/db/KernelSchema.ts)) and the module's `eloxiv_sharing.access_request`.
8
+ - Kit: `@eloxiv/testing/conformance/Sharing` ([source](../../packages/testing/src/conformance/Sharing.ts)).
9
+
10
+ ## The model
11
+
12
+ **A shareable entity** declares one or more *sharing attributes* among its policy attributes: `{ kind: "sharing", permission }`, a `Set<Eloxiv::User>` in Cedar. The permissions it can be shared with are exactly those attributes' `permission` values (a book with `readers` (`read`) and `editors` (`edit`) can be shared with `read` or `edit`). A policy tests a grant with `resource.<attribute>.contains(principal)` (or `containsAny([principal])`): the acting principal holds a grant with that permission on the record.
13
+
14
+ **A grant** gives one permission on one record (by Cedar type and primary key) to one grantee, optionally until an instant. It is always in its **record's own organisation**, which the kernel reads from the record (its one `Eloxiv::Org` attribute, which every shareable entity must have; startup refuses one without), never from the acting context; it is made only by someone acting in that organisation, and it counts only for someone acting there:
15
+
16
+ | Grantee | Who holds it |
17
+ | --- | --- |
18
+ | `{ user }` | That user, while acting in the record's organisation (the user must be a member of it when the grant is made) |
19
+ | `{ group }` | Members of that group of the record's organisation, while they act in it and are in the group |
20
+ | `{ org }` | Every member of the record's organisation while acting in it (no other organisation) |
21
+ | `{ link: {} }` | Members of the record's organisation who redeemed the link's token, while acting in it |
22
+
23
+ **Links.** Creating a link returns its token (`eloxiv_link_` and 32 random bytes, base64url) exactly once; the kernel stores only its SHA-256. Presenting it (`redeemLink`) while signed in and acting in the organisation it was made in records the redemption; from then on the redeemer holds the grant. A link always expires (30 days by default, at most 365); revoking or expiring it removes it, and with it every redemption. *Decided here:* links are for members of the organisation, never anonymous: every read in Eloxiv is an authenticated actor's, and the replicas, row-level security and audit all key on one. Anonymous public access would need an anonymous principal model and is not offered.
24
+
25
+ **Who may share** is the record's entity's own Cedar policy for the action `share` in its module's namespace (for example `Library::Action::"share"`), which the kernel's schema declares on every shareable entity (module actions may not be named `share` or `read`). It decides sharing, listing and revoking a record's grants, and deciding access requests for it. The kernel checks it for the caller against the record, in the operation's transaction, at the moment of the operation, as the entity's module role (so the record's row-level security applies as well), and requires the record to be in the organisation the caller acts in. A record that does not exist, a record of another organisation and a record the caller may not share get the same answer. Startup refuses a `share` policy not tied to the actor (as for every action: by organisation, a user field, or a grant).
26
+
27
+ ## Operations
28
+
29
+ Every operation is an action of the `sharing` module: on every surface (RPC, HTTP, MCP, agent tools, CLI), on the one invocation path (identity, consent, idempotency, audit). `grant` is marked for consent: an agent acting for a person (agent tools, MCP, an agent session) is held with `ConsentRequired` until the person approves the exact call; `revoke` is destructive, so it is held as well. Handlers have the same operations, authorised the same way, as `ctx.sharing` (`share`, `unshare`, `listGrants`, `redeemLink`, `canShare`).
30
+
31
+ | Operation (action) | Input | Output | Effect |
32
+ | --- | --- | --- | --- |
33
+ | `grant` (`sharing.grant`) | `{ entity, id, grantee, permission, expiresAt? }` | `{ grantId, token, expiresAt }` | Grant `permission` on the record. The same grantee and permission, shared again in the same organisation, is the same grant, with the new expiry (a group is a group of the organisation the grant is made in, so the same group id shared from two organisations is two grants). `token` is set for a new link only. |
34
+ | `revoke` (`sharing.revoke`) | `{ grantId }` | `{ revoked }` | Revoke a grant of a record the caller may share. |
35
+ | `list` (`sharing.list`) | `{ entity, id }` | `{ grants: Grant[] }` | The record's unexpired grants (kind, grantee, permission, grantor, created, expires, a link's redemption count; never a token). Read-only. |
36
+ | `redeemLink` (`sharing.redeemLink`) | `{ token }` | `{ entity, id, permission }` | Redeem a link while acting in its organisation. |
37
+ | `access` (`sharing.access`) | `{ entity, id }` | `{ access, canShare, requests }` | For an access gate: `allowed` if the caller may read the record now (its entity's `read` policy, as its module role under row-level security, in the organisation they act in), else `unavailable`, the same answer for a record that does not exist or is another organisation's; `canShare` (false unless `allowed`); the caller's own access requests for the record, most recent first (`id`, `permission`, `status`, `updatedAt`). Read-only. |
38
+ | `requestAccess` (`sharing.requestAccess`) | `{ entity, id, permission, message? }` | `{ id, status }` | Ask for a permission. Every other member of the organisation who may share the record now (its *managers*, by the `share` policy) gets a work item (source `sharing.accessRequests`), a notification (category `sharing`) and the `decide` grant on the request, which lets them read and decide it. Asking again reopens the same request. The answer is the same whether or not the record exists or has managers. |
39
+ | `approveRequest` (`sharing.approveRequest`) | `{ id }` | `{ id, status, grantId }` | Grant the requester the permission, if the approver may still share the record; close every manager's item and notify the requester. |
40
+ | `denyRequest` (`sharing.denyRequest`) | `{ id }` | `{ id, status, grantId: null }` | Refuse; the same closing and notification. |
41
+
42
+ Errors are the standard invocation errors: `Forbidden` (the caller may not share the record, the grant or link is not theirs to manage or not valid, a decider is not one or may no longer share), `InvalidInput` (an entity that cannot be shared, a permission it does not declare, a grantee outside the record's organisation, an expiry in the past or a link's beyond a year, a decided request), `ConsentRequired` for an agent's `grant` or `revoke`.
43
+
44
+ The trusted kernel API `Sharing.grant` and `Sharing.revoke` (seeds, tests, the kernel's own approval flow) apply no policy and accept any grantee. `Sharing.grant` takes the record's organisation (`orgId`, required): a grant recorded in any other organisation, or in none, authorises no one, because every check compares it with the record's own column.
45
+
46
+ ## Records
47
+
48
+ `Grantee`, `SharedRecord` (`{ entity, id }`), `Grant`, `GrantKind`, `AccessRequest` (`id, orgId, requesterId, resourceType, resourceId, permission, message, status, decidedBy`), `AccessRequestStatus` (`pending`, `approved`, `denied`), `ShareGrantColumns` (the columns of `eloxiv.share_grant`: `id, resource_type, resource_id, grantee_kind, grantee_id, org_id, permission, expires_at`).
49
+
50
+ ## Guarantees
51
+
52
+ 1. **Grant checks answer only for the acting principal.** In SQL, `eloxiv_ctx.has_grant(type, id, permission, record_org)` (a `SECURITY DEFINER` function, the only way module roles reach grants) answers whether the principal of the transaction's invocation context holds the grant: its user grants, its groups' grants in the acting organisation, the acting organisation's grants, and links it redeemed there; and only where the record's organisation (`record_org`, which the compiled filter passes from the record's own column), the grant's and the acting organisation are one (migration `0018_sharing_organisation`). No form answers for another grantee, so module code cannot learn who holds a grant. A policy that tests a sharing set for any other user (`resource.editors.contains(Eloxiv::User::"bob")`) does not compile unless Bob is the bound principal; it fails closed.
53
+ 2. **The same grants everywhere.** Row-level security, the kernel's target checks, the query views and every replica's sync filter apply the same compiled predicate; a replica's filter tests grants live, as permission subqueries zero-cache evaluates over its replicated `eloxiv.share_grant`, `eloxiv.share_redemption` and directory facts, whose rows never reach a client ([Sync](sync.md), guarantee 7). A grant or revocation (of any kind, by any path) reaches a connected replica as soon as zero-cache replicates it, without reconnecting.
54
+ 3. **Expiry.** An expired grant authorises nothing in the database from the instant it expires. The kernel deletes expired grants every second (`ELOXIV_SHARE_SWEEP_MS`; `KernelOptions.sharingSweep`), which removes them from connected replicas; a replica's filter also ignores grants that had expired when its query was transformed. Bound: a connected replica can hold a record an expired grant admitted for at most the sweep interval plus replication lag.
55
+ 4. **Who may share is a policy**, checked at each operation against the record for the caller; nothing about a record the caller may not share is revealed (the same `Forbidden` as for a missing record; an access request answers the same either way).
56
+ 5. **In the record's organisation.** Every operation (grant, revoke, list, requesting, approving and denying access) acts on a record only while the caller acts in the record's organisation; a request made from another organisation reaches no one. Grantees are a member or group of that organisation, or the organisation; permissions are the entity's declared ones. Row-level security, the query views and sync count a grant only where the record's, the grant's and the acting organisation are one, so no grant (whoever made it) carries a record into another organisation.
57
+ 6. **Audited and consent-bound** like every action: one audit row per call (`succeeded`, or `denied`/`failed`/`approval-required` after rollback), with its surface.
58
+ 7. **Access requests reach managers** as work items and notifications in the request's transaction, and a decision is checked against the record's `share` policy for the decider at the moment of deciding.
59
+ 8. **An access gate reveals nothing.** `sharing.access` says only whether the caller may read the record now; a missing record, another organisation's and an unreadable one answer exactly alike, and the requests listed are the caller's own.
60
+
61
+ ## Clients
62
+
63
+ `@eloxiv/client/sharing` ([ClientSDK](client-sdk.md#collaboration-sharing-and-history-controllers)) has the headless controllers over these actions: `shareController` (a record's grants changed optimistically and reconciled, with a grant to the whole organisation held until confirmed), `wideningTransition` (the same confirmation for a module's own visibility change), `accessGate` (allowed, unavailable, signed out; requesting access and noticing its approval) and `decideAccessRequest`.
64
+
65
+ ## How an implementation is checked
66
+
67
+ `sharingConformance(start)` runs against an `InboxSubject` ([`InboxSubject.ts`](../../packages/testing/src/conformance/InboxSubject.ts)) serving the **sharing conformance app** ([`library/app.ts`](../../packages/testing/src/conformance/library/app.ts)): the `library` fixture (books with `read` and `edit` grants, shared by their owner or an editor; pages with `view` grants, readable through one hop to their book's owner) with the inbox modules and the sharing module. It checks user, group, organisation and link grants (by the sync filter and by actions), that a grant stays in its record's organisation (an editor who belongs to two organisations cannot share, list, revoke or have requested a record of one while acting in the other; a grant counts only acting in the record's organisation, and one recorded in another organisation for no one), who may share, permission and grantee validation, links (token once, never listed, redemption in the organisation only, revocation), expiry (refused at once, then deleted), every surface (RPC and HTTP share; agent tools and MCP are held for consent; audit rows per surface), access requests (managers by policy, work items, notifications, approval and denial, a manager who lost the right, a missing record), the access gate's answer (the same for a missing, another organisation's and an unreadable record; only the caller's own requests), and the sync filter (grants bound to the caller only; pages reached from a book filtered by their own policy).
68
+
69
+ The Eloxiv kernel runs it in [`packages/testing/test/sharing.test.ts`](../../packages/testing/test/sharing.test.ts). Live through zero-cache, [`sharing-live.test.ts`](../../packages/testing/test/sharing-live.test.ts) proves every grant kind and its revocation or expiry reaching a connected replica without reconnecting, and child queries (below). [`sync-property.test.ts`](../../packages/testing/test/sync-property.test.ts) proves, for generated policies, actors and data with grants of every kind, that a replica holds exactly what Cedar authorises.
70
+
71
+ ## Not yet guaranteed
72
+
73
+ - **Anonymous links** (public access without signing in): not offered, by design (above).
74
+ - **Sharing across organisations**: not offered, by design. A grant counts only in its record's organisation, so a user of another organisation must be a member of the record's organisation, acting in it, to hold one.
75
+ - **Shell screens** for sharing and access requests (registry UI, deferred by decision 11); the client SDK has the headless controllers above.
76
+ - **A trashed state**: records have no kernel trash state, so the gate has none; a module whose records can be trashed makes a trashed record unreadable by its `read` policy (the gate then says `unavailable`) or answers its own trash state.
77
+ - **Invitations**: grants are to members, groups and the organisation (above); bringing someone new into the organisation is the Directory's.
@@ -0,0 +1,48 @@
1
+ # Slot
2
+
3
+ Extension points modules declare, and the contributions other modules make to them, resolved across every installed module into one deterministic order. A home space's launcher, a record page's side panels and a toolbar's buttons are slots; the modules that fill them do not know about each other.
4
+
5
+ - Kind: shell contract. Version 1.0.0.
6
+ - Schema: [`packages/contracts/schema/contracts/Slot.json`](../../packages/contracts/schema/contracts/Slot.json) (source [`Slot.ts`](../../packages/contracts/src/contracts/Slot.ts)). Declared with the manifest's `slots` and `contributions` ([ModuleManifest](module-manifest.md)).
7
+ - Implementation: `shellRegistry(...).slots()` and `.slot(id)` in `@eloxiv/shell-core` ([`Navigation.ts`](../../packages/shell-core/src/Navigation.ts)).
8
+ - Kit: `@eloxiv/testing/conformance/Slot` ([source](../../packages/testing/src/conformance/Slot.ts)).
9
+
10
+ ```ts
11
+ // In a module's manifest
12
+ slots: { "home.launcher": { description: "Tiles on the home space", accepts: "view" } },
13
+ contributions: { "mail.launcherTile": { slot: "home.launcher", view: "mail.inbox", order: 10 } },
14
+
15
+ // In the shell
16
+ for (const entry of shell.slot("home.launcher")) render(entry.target) // { view } or { command }
17
+ ```
18
+
19
+ ## Operations
20
+
21
+ | Operation | Input | Output | What it does |
22
+ | --- | --- | --- | --- |
23
+ | `list` | `{}` | `SlotDescriptor[]` | Every slot, in module installation order, then by id |
24
+ | `resolve` | `{ slot }` | `SlotEntry[]` | The slot's contributions from every installed module, each resolved to the view's descriptor or the command's palette entry, in order. `UnknownSlot` if no module declares the slot |
25
+
26
+ ## Records
27
+
28
+ - **`SlotDescriptor`**: `id`, `module`, `description`, `accepts` (`view` or `command`).
29
+ - **`SlotEntry`**: `contribution` (its id), `module` (who contributed it), `order?`, `target` (`{ view: ViewDescriptor }` or `{ command: PaletteEntry }`).
30
+ - **Error**: `UnknownSlot { slot }`.
31
+
32
+ ## Guarantees
33
+
34
+ 1. **One deterministic order**: `order` ascending; entries without an `order` after every entry with one; then the contributing module's installation order; then contribution id. It does not depend on the order a manifest lists its contributions in.
35
+ 2. **Resolved targets only.** Each entry carries the view's descriptor (with its route) or the command's palette entry, never a dangling id.
36
+ 3. **Checked at startup.** The manifest check (`manifestProblems`, run by the kernel) refuses a contribution to a slot that does not exist, of a view or command that does not exist, or of the wrong kind (a view to a command slot).
37
+
38
+ ## MAKE views in slots
39
+
40
+ A MAKE module's view can be shown in the app's view slots too: its source names them (`view.slots`), and `make.slots` lists the organisation's installed ones in the same order rule ([Sandbox](sandbox.md#make)). They are the organisation's, not the app's, so they are not in `shellRegistry`'s static resolution: a shell adds them to a slot's entries at run time (`makeSlot`) and renders each in its sandboxed frame.
41
+
42
+ ## How an implementation is checked
43
+
44
+ `slotConformance(make)` builds the implementation over the shell fixture ([`atlas/contract.ts`](../../packages/testing/src/conformance/atlas/contract.ts): `atlas.panels` for views and `atlas.toolbar` for commands, filled by both modules, ordered and unordered) and checks the slots, the resolved order and targets, that reversing a manifest's contributions changes nothing while swapping installation order breaks ties the other way, `UnknownSlot`, and the manifest check's refusals. The Eloxiv implementation runs it in [`shell-navigation.test.ts`](../../packages/testing/test/shell-navigation.test.ts).
45
+
46
+ ## Not yet guaranteed
47
+
48
+ - **No filtering by policy or space**: a slot lists every contribution of the installed modules; the shell decides what to show of a view the person cannot use.
@@ -0,0 +1,67 @@
1
+ # Space
2
+
3
+ Curated entry points over several modules' views. The organisation defines its spaces as data, its roles grant them, and each person personalises within the spaces granted to them. The home space (launcher, inbox, agent, admin) is one such space, defined by the app.
4
+
5
+ - Kind: shell contract. Version 1.0.0.
6
+ - Schema: [`packages/contracts/schema/contracts/Space.json`](../../packages/contracts/schema/contracts/Space.json) (source [`Space.ts`](../../packages/contracts/src/contracts/Space.ts)).
7
+ - Implementation: the kernel-provided `spaces` module (`spacesModule`, [`packages/kernel/src/spaces/module.ts`](../../packages/kernel/src/spaces/module.ts)), its sync tables (`spacesTables`, `spacesRelationships` and `spacesQueries` in `@eloxiv/client/sync`, the tables generated from the module's Drizzle tables), and `resolveSpaces` in `@eloxiv/shell-core` ([`Spaces.ts`](../../packages/shell-core/src/Spaces.ts)).
8
+ - Kit: `@eloxiv/testing/conformance/Space` ([source](../../packages/testing/src/conformance/Space.ts)).
9
+
10
+ Install it by adding `spacesModule` to the app's modules and the three sync exports to its sync schema. Then:
11
+
12
+ ```ts
13
+ // An administrator (eloxiv.spaces.manage) defines a space
14
+ await client.call("spaces.define", {
15
+ id: "sales", title: "Sales", entries: [{ view: "crm.deals" }, { view: "mail.inbox" }],
16
+ audience: { roles: ["sales", "sales-lead"] },
17
+ })
18
+ // A member pins it and reorders it
19
+ await client.call("spaces.personalise", { space: "sales", pinned: true, entryOrder: ["mail.inbox", "crm.deals"] })
20
+ // The shell resolves the replica's rows against the installed views
21
+ const grants = await zero.run(spacesQueries.spaces.granted())
22
+ const prefs = await zero.run(spacesQueries.spaces.preferences())
23
+ const spaces = resolveSpaces(grants, prefs, shell) // ResolvedSpace[]
24
+ ```
25
+
26
+ ## Operations
27
+
28
+ | Operation | Action | Input | Output | What it does |
29
+ | --- | --- | --- | --- | --- |
30
+ | `define` | `spaces.define` | `SpaceDefinition` | `{ id }` | Defines or replaces a space of the acting organisation (holders of `eloxiv.spaces.manage`). Replacing it re-grants it: an audience no longer in it loses the space at once |
31
+ | `remove` | `spaces.remove` | `{ id }` | `{ id }` | Withdraws a space from everyone (`eloxiv.spaces.manage`) |
32
+ | `personalise` | `spaces.personalise` | `SpacePreference` | `{ id }` | Sets the caller's own preferences for a space granted to them; `Forbidden` for any other space, whether or not it exists |
33
+ | `reset` | `spaces.reset` | `{ id }` | `{ id }` | Drops the caller's preferences for a space |
34
+ | `mine` | (client) | `{ includeHidden? }` | `ResolvedSpace[]` | The caller's spaces, from their replica, resolved and ordered (`resolveSpaces`) |
35
+
36
+ ## Records
37
+
38
+ - **`SpaceDefinition`**: `id` (`^[a-z][a-z0-9-]{0,62}$`, unique per organisation), `title`, `description?`, `icon?` (a name the shell's icon set knows), `entries` (`{ view }`, at most 100), `audience` (`{ everyone: true }`, the only way to grant everyone, or `{ roles: [...] }`: 1 to 50 Directory role ids, `^[a-z0-9][a-z0-9_-]{0,62}$`, so a wildcard such as `*` is refused), `position?` (the organisation's order).
39
+ - **`SpacePreference`**: `space`, `pinned?`, `hidden?`, `position?`, `entryOrder?` and `hiddenEntries?` (view ids of the space's own entries).
40
+ - **`ResolvedSpace`**: `id`, `title`, `description?`, `icon?`, `pinned`, `hidden`, `position`, `entries` (`ViewDescriptor[]`, [View](view.md)).
41
+
42
+ ### Storage and sync
43
+
44
+ The module's schema is `eloxiv_spaces`:
45
+
46
+ - `space_grant`: one row per space and audience (`<org>/<space>/<audience>`, audience `*` for everyone or a role), with the definition, `withdrawn`, `updated_by`, `updated_at`. Read policy: in the organisation the member acts in, not withdrawn, and the audience is `*` or a role the member holds there (`principal.roles.contains(resource.audience)`: row-level security calls `eloxiv_ctx.has_role(audience)`, and sync tests the replicated directory facts live). Rows are withdrawn, never deleted, because `define` and `remove` name no target ([the action contract](../scaffold.md#the-action-contract)).
47
+ - `preference`: one row per member, space and grant it was set through (`<org>/<user>/<space>/<audience>`, `grant_id` referencing the grant row), readable and writable by that member only and only while that grant reaches them (the policy follows the reference: `resource.grant` not withdrawn, for everyone or a role the member holds). `personalise` writes a row for every grant that reaches the member, so a preference lasts while any of them does; the client takes the newest.
48
+
49
+ Queries: `spaces.granted` (`Spaces::Grant`) and `spaces.preferences` (`Spaces::Preference`).
50
+
51
+ ## Guarantees
52
+
53
+ 1. **Only managers define.** `define` and `remove` need `eloxiv.spaces.manage` in the acting organisation (the built-in `admin` role grants it; migration `0028_spaces_manage` gives it to existing administrators), act in that organisation only, and are audited like every call.
54
+ 2. **A replica holds exactly the granted spaces**: those granted to everyone in the organisation it acts in, or to a role its member holds there, never another organisation's, never a withdrawn one.
55
+ 3. **Live.** Gaining a role brings its spaces to the replica; losing it, a redefinition without it, or `remove` takes them away, while the replica stays connected.
56
+ 4. **Preferences are private and bounded by the grant.** A member reads and writes only their own, only for a space granted to them (a withdrawn grant takes them off the replica, and `reset` reaches none); `entryOrder` and `hiddenEntries` keep only the space's own entries, so personalising never adds one.
57
+ 5. **Resolution** (`resolveSpaces`): a space granted through several roles is one space (the newest row); entries naming views no installed module declares are dropped; the person's entry order comes first, then the space's remaining entries, minus their hidden entries; ordered pinned first, then position (the person's, else the organisation's), then title, then id; hidden spaces only with `includeHidden`.
58
+
59
+ ## How an implementation is checked
60
+
61
+ `spaceConformance({ kernel, resolve })` runs against a kernel serving the spaces conformance app ([`atlas/app.ts`](../../packages/testing/src/conformance/atlas/app.ts)) through `InboxSubject`: refusals without the permission (and success with a role granting only it), audit outcomes, wildcard and malformed roles refused, the sync endpoint's rows for members of different roles and organisations, a **connected replica** (the subject's sync server re-runs no query on its own) receiving a space and its preference as the member gains a role and losing both as they lose it, never receiving a later grant to the lost role, and unaffected by the same role held in another organisation, redefinition and withdrawal, and preferences (owner only, granted spaces only, foreign entries dropped, withdrawn with their grant, reset); and the client resolution rules above. The Eloxiv implementation runs it in [`space.test.ts`](../../packages/testing/test/space.test.ts). The compiler's support for a role named by a record is also covered by the Cedar differential tests ([`policy-compiler.test.ts`](../../packages/kernel/test/policy-compiler.test.ts), [`policy-sql.test.ts`](../../packages/testing/test/policy-sql.test.ts)).
62
+
63
+ ## Not yet guaranteed
64
+
65
+ - **Entries are not checked against the installed views by the kernel**; the client drops the ones it cannot resolve.
66
+ - **No group audiences** (roles and everyone only), and no per-person spaces (a person's own collections).
67
+ - **Withdrawn rows accumulate** (one per space and audience ever used); they are never synced.