@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,927 @@
1
+ # Getting started
2
+
3
+ This guide takes you from an empty directory to a working Eloxiv app: assembled from the registry with the `eloxiv` CLI, then grown with a module of your own (an entity over a Drizzle table, actions, a policy, a sync query and an agent skill), your own screen on the client SDK's Foldkit adapter, and a chat screen of your own on the headless chat SDK. Every command and file below was run as written against the current code.
4
+
5
+ What you will have at the end:
6
+
7
+ - a kernel (the server: identity, policy, the action registry, sync), zero-cache (the sync server) and a web shell, running with `eloxiv dev`;
8
+ - the registry's `hello` module and its screen, installed and owned by your app;
9
+ - your own `tasks` module: each person's tasks, added and completed through actions anyone (a screen, the CLI, MCP, the agent) calls the same way, with a Cedar policy that decides both who may act and what each person's local replica holds;
10
+ - a Tasks screen that reads the replica live and writes optimistically, and an Assistant screen where the agent answers from your module's data.
11
+
12
+ Read [decisions.md](decisions.md) for why Eloxiv is shaped this way; this guide only shows how.
13
+
14
+ ## 1. What you need
15
+
16
+ - **Node.js 24.11 or later and pnpm 10** on your `PATH`. The CLI and your app run on Node, and the CLI refuses older versions (Node 22 will not work). With [mise](https://mise.jdx.dev), run `mise use -g node@24 pnpm@10` globally, or run `mise use node@24 pnpm@10 && mise trust` in a parent directory that will hold `~/my-app`. **Bun 1.4** is optional: the app's `package.json` scripts use it, but `eloxiv dev` does not need it.
17
+ - **PostgreSQL 17** started with `wal_level = logical` (zero-cache replicates through logical replication), on a server no other Eloxiv app uses: a module's database roles are named for the module and shared by the whole server ([Release](contracts/release.md#not-yet-guaranteed)). Below you start one of the app's own. `eloxiv setup` (and `eloxiv dev`, which runs it) creates the app's database and its login role from the URLs you give; nothing else needs to exist.
18
+ - For the chat in step 8: an OpenAI API key (or any OpenAI-compatible endpoint; see [the openai connector](connectors/openai.md)).
19
+
20
+ Everything comes from npm — both the `@eloxiv/*` packages and the registry items (`@eloxiv/registry`, bundled as a CLI dependency and recorded by `eloxiv init`) — so nothing below accesses GitHub. To use an unreleased checkout of Eloxiv instead, see [Working from a checkout](#working-from-a-checkout).
21
+
22
+ ```sh
23
+ node --version # v24.11.0 or later
24
+ pnpm --version # 10.x
25
+ ```
26
+
27
+ Put the settings every later step uses in one file and source it in each terminal you open. Change the ports if any are in use (the kernel, zero-cache — which also takes the next port after its own — and the shell):
28
+
29
+ ```sh
30
+ cat > ~/eloxiv.env <<'EOF'
31
+ export PGPORT=5432 # the PostgreSQL server you start below
32
+ export PGPASSWORD=postgres # its superuser's password (psql and @eloxiv/testing read it)
33
+ export ELOXIV_ADMIN_DATABASE_URL=postgres://postgres:$PGPASSWORD@localhost:$PGPORT/postgres
34
+ export ELOXIV_DATABASE_URL=postgres://my_app:my_app@localhost:$PGPORT/my_app # setup creates this role and database
35
+ export ELOXIV_PORT=4100 ELOXIV_ZERO_PORT=4848 ELOXIV_SHELL_PORT=5173
36
+ export ELOXIV_URL=http://localhost:${ELOXIV_PORT:-4100} # the kernel, for the CLI and scripts
37
+ EOF
38
+ . ~/eloxiv.env
39
+ ```
40
+
41
+ Put PostgreSQL 17's programs (`initdb`, `pg_ctl`, `psql`) on your `PATH`: your system's packages, or prebuilt binaries such as [theseus-rs/postgresql-binaries](https://github.com/theseus-rs/postgresql-binaries) (what Eloxiv's own repository installs through mise). Then start a server of the app's own (password authentication, logical replication, on `$PGPORT`):
42
+
43
+ ```sh
44
+ mkdir -p ~/eloxiv-pg && echo "$PGPASSWORD" > ~/eloxiv-pg/password
45
+ initdb -D ~/eloxiv-pg/data -U postgres --auth=scram-sha-256 --pwfile="$HOME/eloxiv-pg/password"
46
+ pg_ctl -D ~/eloxiv-pg/data -l ~/eloxiv-pg/server.log -w start \
47
+ -o "-p $PGPORT -c wal_level=logical -c listen_addresses=localhost -c unix_socket_directories=$HOME/eloxiv-pg"
48
+ psql "$ELOXIV_ADMIN_DATABASE_URL" -c 'SHOW wal_level' # logical
49
+ ```
50
+
51
+ `pg_ctl -D ~/eloxiv-pg/data stop` stops it when you are done. Every login needs its password (`scram-sha-256`), including the module roles setup creates; on a server that lets local logins in without one (`trust`), every start prints a warning that a module's owner role could log in that way, which is allowed in development and refused in production.
52
+
53
+ ## 2. Install the CLI
54
+
55
+ ```sh
56
+ npm install -g @eloxiv/cli
57
+ eloxiv --version # eloxiv v0.1.0
58
+ ```
59
+
60
+ `npx @eloxiv/cli <command>` runs it without installing. Every app `eloxiv init` creates also gets the CLI as a devDependency (`@eloxiv/cli` at `^` its own version), so in an app `pnpm exec eloxiv` runs the version the app pins, and the deployment recipes find it there.
61
+
62
+ You can safely ignore these pnpm warnings in the app:
63
+
64
+ - "Ignored build scripts" (`@rocicorp/zero-sqlite3`, `esbuild`, `protobufjs`): pnpm runs no package's install scripts unless allowed, and nothing in this guide needs them (zero-sqlite3 ships its binary prebuilt).
65
+ - "deprecated subdependencies found" (`@esbuild-kit/*`, OpenTelemetry's, `glob`, `uuid` and others, deep in the tools' trees): nothing to do in your app.
66
+ - "unmet peer effect@^4.1.4: found 4.1.2" (from `@foldkit/vite-plugin`'s Node platform packages, a build-time tool): Eloxiv pins Effect 4.1.2, and the plugin works with it.
67
+
68
+ ## 3. Assemble an app from the registry
69
+
70
+ ```sh
71
+ cd ~
72
+ eloxiv init my-app
73
+ cd my-app
74
+ eloxiv add app hello hello-ui-foldkit
75
+ eloxiv doctor
76
+ ```
77
+
78
+ `init` creates the app skeleton: `package.json` (with `@eloxiv/cli` as a devDependency), `tsconfig.json`, `eloxiv.json`, an empty `eloxiv.lock.json`, and the composition files. By default `eloxiv.json` points at `npm:@eloxiv/registry`, the items published with the CLI; pass `--registry` to use a local directory of built items or an HTTPS URL instead. `add` copies each item and its registry dependencies into your app, records versions and content hashes in `eloxiv.lock.json`, regenerates the composition files, and runs `pnpm install`:
79
+
80
+ | Item | What it is | Where it lands |
81
+ | --- | --- | --- |
82
+ | [`app`](registry/app.md) | the server entry: the kernel, set up and started with every installed module | `server/` |
83
+ | [`hello`](registry/hello.md) | a small module: one entity, two actions (`greet` and `wave`), a policy and sync queries | `modules/hello/` |
84
+ | [`hello-ui-foldkit`](registry/hello-ui-foldkit.md) | hello's screen, which brings the web shell and its theme | `shell-foldkit/src/screens/hello.ts` |
85
+ | [`shell-foldkit`](registry/shell-foldkit.md), [`theme`](registry/theme.md) | the web shell (Foldkit, StyleX, Vite): sign-in, routing, organisations | `shell-foldkit/`, `themes/` |
86
+
87
+ Everything an item installed is yours to edit; `eloxiv diff` shows your edits against what was installed, and `eloxiv update` merges the registry's newer versions into them ([the CLI](cli.md)). `eloxiv doctor` checks the assembly and should report no failed check. Before the first `eloxiv dev` one check is skipped, `replication slots: ... password authentication failed for user "my_app"`: the app's login role does not exist until setup creates it, which `eloxiv dev` does in the next step. [The registry](registry/README.md) lists every item you can add.
88
+
89
+ ## 4. Run it
90
+
91
+ ```sh
92
+ eloxiv dev
93
+ ```
94
+
95
+ It runs the kernel (setup, a demo seed, then serve), zero-cache once the kernel is up, and the shell's dev server, until Ctrl-C. The first start creates the database, the module's schema and roles, and seeds two organisations (Acme and Globex) and two people: `alice@example.com` and `bob@example.com`, both with the password `eloxiv-dev-password`.
96
+
97
+ Open <http://localhost:5173> (port 5173, or your `ELOXIV_SHELL_PORT`), sign in as Alice and open **Hello**: a greeting you post shows at once (the replica predicts it) and stays once the server confirms it.
98
+
99
+ Every action is also reachable from the command line. The CLI signs in with `eloxiv login` (a browser device flow), or takes a session token in `ELOXIV_TOKEN`. In a second terminal (`. ~/eloxiv.env` first, so `ELOXIV_URL` and the rest are set), in `my-app`, add a script that prints one; it signs in at `$ELOXIV_URL`:
100
+
101
+ ```ts title="scripts/sign-in.ts"
102
+ // Prints a session token for a person, for ELOXIV_TOKEN (the CLI's kernel commands accept one).
103
+ import { signIn } from "@eloxiv/client"
104
+
105
+ const [email = "alice@example.com", password = "eloxiv-dev-password"] = process.argv.slice(2)
106
+ const session = await signIn(process.env["ELOXIV_URL"] ?? "http://localhost:4100", { email, password })
107
+ console.log(session.token)
108
+ ```
109
+
110
+ ```sh
111
+ export ELOXIV_TOKEN=$(node scripts/sign-in.ts)
112
+ eloxiv whoami --url "$ELOXIV_URL"
113
+ eloxiv call hello.greet --url "$ELOXIV_URL" --input '{"message":"Hello from the CLI","visibility":"org"}'
114
+ ```
115
+
116
+ `whoami` lists Acme (admin) and Globex (member); `call` prints the result envelope, `{ "kind": "output", "output": { "id": ..., "message": "Hello from the CLI", "visibility": "org" } }`, and the greeting appears in the browser without a reload. `node` runs TypeScript directly (Node 24); `bun scripts/sign-in.ts` works too. `ELOXIV_TOKEN` lives only in this terminal: run the later steps' `eloxiv call` and `eloxiv agent` commands here (in a new terminal, export it again with the same line).
117
+
118
+ ## 5. A module of your own
119
+
120
+ A module is a code, schema and ownership boundary: its own PostgreSQL schema and database roles, reached by everything else only through its contract. You will write `tasks`: each person's own tasks in the organisation they act in. `eloxiv blueprint module --name tasks` prints the same plan for a coding agent. The files all go in `modules/tasks/`.
121
+
122
+ **The table.** The Drizzle table is the only place the module declares its fields (decision 9); every other shape (the entity's JSON Schema, the sync table, the row types your screen sees) is derived from it.
123
+
124
+ ```ts title="modules/tasks/schema.ts"
125
+ /** The tasks module's tables: the only place its fields are declared (decision 9). */
126
+ import { boolean, pgSchema, text, timestamp } from "drizzle-orm/pg-core"
127
+
128
+ export const tasksSchema = pgSchema("tasks")
129
+
130
+ export const task = tasksSchema.table("task", {
131
+ id: text("id").primaryKey(),
132
+ orgId: text("org_id").notNull(),
133
+ ownerId: text("owner_id").notNull(),
134
+ title: text("title").notNull(),
135
+ done: boolean("done").notNull().default(false),
136
+ createdAt: timestamp("created_at", { withTimezone: true, mode: "string" }).notNull().defaultNow(),
137
+ })
138
+ ```
139
+
140
+ ```ts title="modules/tasks/drizzle.config.ts"
141
+ import { defineConfig } from "drizzle-kit"
142
+
143
+ export default defineConfig({
144
+ dialect: "postgresql",
145
+ schema: "./schema.ts",
146
+ out: "./migrations",
147
+ schemaFilter: ["tasks"],
148
+ })
149
+ ```
150
+
151
+ **The contract.** The entity references the table's columns for what policy needs (`owner`, `org`); actions declare their input and output as Effect Schemas, the entity they write and the change a replica predicts before the server answers (`optimistic`). The skill is what the agent reads about the module; the query view is the read-only, policy-filtered SQL the agent may query. `views` names the screen route step 7 renders.
152
+
153
+ ```ts title="modules/tasks/contract.ts"
154
+ /** The tasks module's contract: what it stores, what callers may do, and what its agent skill says. */
155
+ import { defineAction, defineModuleContract, optimistic } from "@eloxiv/contracts"
156
+ import { defineEntity } from "@eloxiv/contracts/drizzle"
157
+ import { Schema } from "effect"
158
+ import * as tables from "./schema.ts"
159
+
160
+ /** A task. Its fields are the table's; the entity adds what policy and sync need, by the table's columns. */
161
+ export const task = defineEntity(tables.task, {
162
+ name: "task",
163
+ cedarType: "Tasks::Task",
164
+ policyAttributes: {
165
+ owner: { column: tables.task.ownerId, entity: "Eloxiv::User" },
166
+ org: { column: tables.task.orgId, entity: "Eloxiv::Org" },
167
+ },
168
+ })
169
+
170
+ const TaskRef = Schema.Struct({ id: Schema.String, title: Schema.String, done: Schema.Boolean })
171
+
172
+ export const add = defineAction({
173
+ name: "tasks.add",
174
+ description: "Add a task for the caller, in the organisation they act in.",
175
+ input: Schema.Struct({
176
+ title: Schema.String.check(Schema.isNonEmpty(), Schema.isMaxLength(200)),
177
+ key: Schema.optional(
178
+ Schema.String.annotate({ description: "Optional; the new task's key (a replica predicts it)." }),
179
+ ),
180
+ }),
181
+ output: TaskRef,
182
+ writes: "task",
183
+ // The replica shows the task at once; the server's row replaces it, or it goes if the call is refused.
184
+ optimistic: optimistic.insert({
185
+ key: "key",
186
+ values: {
187
+ orgId: optimistic.actor("orgId"),
188
+ ownerId: optimistic.actor("userId"),
189
+ title: optimistic.input("title"),
190
+ done: optimistic.value(false),
191
+ createdAt: optimistic.now(),
192
+ },
193
+ }),
194
+ })
195
+
196
+ export const complete = defineAction({
197
+ name: "tasks.complete",
198
+ description: "Mark one of the caller's tasks done.",
199
+ input: Schema.Struct({ id: Schema.String }),
200
+ output: TaskRef,
201
+ writes: "task",
202
+ target: { entity: "task", field: "id" },
203
+ optimistic: optimistic.update({ set: { done: optimistic.value(true) } }),
204
+ })
205
+
206
+ export const tasks = defineModuleContract({
207
+ name: "tasks",
208
+ version: "0.1.0",
209
+ cedarNamespace: "Tasks",
210
+ entities: { task },
211
+ actions: { add, complete },
212
+ events: {},
213
+ skills: {
214
+ "tasks.manage": {
215
+ description: "How to add tasks, mark them done and read a person's open tasks.",
216
+ content: { path: "skills/manage.md" },
217
+ evals: { path: "skills/manage.evals.json" },
218
+ },
219
+ },
220
+ views: {
221
+ "tasks.list": {
222
+ title: "Tasks",
223
+ description: "The person's open tasks.",
224
+ route: "/tasks",
225
+ shows: { entity: "task" },
226
+ },
227
+ },
228
+ queryViews: {
229
+ "tasks.open": {
230
+ description: "The person's open tasks (title, when added), each row filtered by the task's read policy.",
231
+ entity: "task",
232
+ sql: "SELECT t.id, t.title, t.created_at FROM tasks.task t WHERE NOT t.done",
233
+ row: Schema.Struct({ id: Schema.String, title: Schema.String, created_at: Schema.String }),
234
+ },
235
+ },
236
+ })
237
+ ```
238
+
239
+ **The policy.** One Cedar policy both authorises each action (compiled into a SQL check on the row it writes) and decides what syncs to each person (compiled into the replica's query filter). `read` is the kernel's action for reading records.
240
+
241
+ ```cedar title="modules/tasks/policy.cedar"
242
+ // Members add tasks in their own organisation, as themselves.
243
+ @id("tasks.add")
244
+ permit (principal, action == Tasks::Action::"add", resource is Tasks::Task)
245
+ when { resource.org == principal.org && resource.owner == principal };
246
+
247
+ // Only a task's owner completes it.
248
+ @id("tasks.complete")
249
+ permit (principal, action == Tasks::Action::"complete", resource is Tasks::Task)
250
+ when { resource.org == principal.org && resource.owner == principal };
251
+
252
+ // A person reads (and their replica holds) only their own tasks in the organisation they act in.
253
+ @id("tasks.read")
254
+ permit (principal, action == Tasks::Action::"read", resource is Tasks::Task)
255
+ when { resource.org == principal.org && resource.owner == principal };
256
+ ```
257
+
258
+ **The handlers.** Each handler runs in the call's transaction, after identity, policy, consent and idempotency, as the module's own database role: it can reach only its own schema.
259
+
260
+ ```ts title="modules/tasks/server.ts"
261
+ /** The tasks module's server half: its handlers, policy and migrations. */
262
+ import { InvalidInput } from "@eloxiv/contracts"
263
+ import { defineModule } from "@eloxiv/kernel"
264
+ import { Effect } from "effect"
265
+ import { tasks } from "./contract.ts"
266
+
267
+ export const tasksModule = defineModule(tasks, {
268
+ policy: new URL("./policy.cedar", import.meta.url),
269
+ migrationsDir: new URL("./migrations/", import.meta.url),
270
+ handlers: {
271
+ add: (input, ctx) =>
272
+ Effect.gen(function* () {
273
+ const id = input.key ?? crypto.randomUUID()
274
+ yield* ctx.sql`INSERT INTO tasks.task (id, org_id, owner_id, title)
275
+ VALUES (${id}, ${ctx.actor.orgId}, ${ctx.actor.userId}, ${input.title})`.pipe(Effect.orDie)
276
+ return { id, title: input.title, done: false }
277
+ }),
278
+ complete: (input, ctx) =>
279
+ Effect.gen(function* () {
280
+ const rows = yield* ctx.sql<{ id: string; title: string }>`UPDATE tasks.task SET done = true
281
+ WHERE id = ${input.id} RETURNING id, title`.pipe(Effect.orDie)
282
+ const row = rows[0]
283
+ if (row === undefined) return yield* new InvalidInput({ message: `No task ${input.id}` })
284
+ return { id: row.id, title: row.title, done: true }
285
+ }),
286
+ },
287
+ })
288
+ ```
289
+
290
+ **The sync query.** Named queries run on the replica; the kernel infers each one's entity from the table it reads and adds that entity's read policy on the server, so the replica holds only what the person may read. `sync.gen.ts` is generated below.
291
+
292
+ ```ts title="modules/tasks/sync.ts"
293
+ /** The tasks module's named queries: run on the replica, filtered by the task's read policy on the server. */
294
+ import { defineQuery, zql } from "./sync.gen.ts"
295
+
296
+ export const queries = {
297
+ open: defineQuery(() => zql.task.where("done", false).orderBy("createdAt", "desc")),
298
+ }
299
+ ```
300
+
301
+ **The agent skill**, and the eval cases that score it (step 6 runs them): each case is a prompt, the tool calls and answer it expects, the state it leaves in a query view, and a `script` the scripted model plays.
302
+
303
+ ```md title="modules/tasks/skills/manage.md"
304
+ # Managing tasks
305
+
306
+ - Add a task with `tasks.add` (the `tasks_add` tool): `title` is the person's words, 1 to 200 characters. Then tell the person the task's title as you added it.
307
+ - Mark one done with `tasks.complete` and its `id`; read the `tasks.open` view first to find the id.
308
+ - To say what is still open, read the `tasks.open` view with the query tool and answer from its rows.
309
+ ```
310
+
311
+ ```json title="modules/tasks/skills/manage.evals.json"
312
+ {
313
+ "skill": "tasks.manage",
314
+ "threshold": 1,
315
+ "cases": [
316
+ {
317
+ "name": "adds a task in the person's words",
318
+ "prompt": "Add a task: Book the venue",
319
+ "expect": {
320
+ "toolCalls": [{ "tool": "tasks_add", "input": { "title": "Book the venue" } }],
321
+ "answerIncludes": ["Book the venue"]
322
+ },
323
+ "state": [{ "view": "tasks.open", "contains": { "title": "Book the venue" } }],
324
+ "script": [
325
+ { "toolCalls": [{ "tool": "tasks_add", "input": { "title": "Book the venue" } }] },
326
+ { "text": "Added \"Book the venue\" to your tasks." }
327
+ ]
328
+ },
329
+ {
330
+ "name": "reads open tasks without adding one",
331
+ "prompt": "Which tasks do I have open?",
332
+ "expect": {
333
+ "toolCalls": [{ "tool": "query", "input": { "view": "tasks.open" } }],
334
+ "forbiddenTools": ["tasks_add", "tasks_complete"]
335
+ },
336
+ "script": [
337
+ { "toolCalls": [{ "tool": "query", "input": { "view": "tasks.open" } }] },
338
+ { "text": "You have no open tasks." }
339
+ ]
340
+ }
341
+ ]
342
+ }
343
+ ```
344
+
345
+ Now generate the migration from the table, list the module in `eloxiv.json` (an app's own modules are composed beside the installed ones; see [the app's own modules](cli.md#the-apps-own-modules)), and regenerate:
346
+
347
+ ```sh
348
+ (cd modules/tasks && ../../node_modules/.bin/drizzle-kit generate)
349
+ node -e 'const f="eloxiv.json",fs=require("fs"),c=JSON.parse(fs.readFileSync(f));c.modules=["tasks"];fs.writeFileSync(f,JSON.stringify(c,null,2)+"\n")'
350
+ eloxiv generate
351
+ eloxiv typecheck
352
+ ```
353
+
354
+ `drizzle-kit generate` writes `modules/tasks/migrations/`; `eloxiv generate` writes `modules/tasks/sync.gen.ts` (the Zero table, from the Drizzle table and the entity, and the optimistic mutators, from the actions) and adds the module to `eloxiv.modules.ts`, `eloxiv.server.ts`, `eloxiv.schema.ts` and `eloxiv.sync.ts`; `eloxiv typecheck` should print nothing.
355
+
356
+ **A prediction of your own.** `insert`, `update` and `delete` cover most writes. When an action changes something they cannot say (every done task reopened, a counter, a task moved under another parent), declare `optimistic: optimistic.custom()` on it and predict the change yourself in `modules/tasks/predictions.ts`: one function per such action, named like it, typed by the `Predictions` that `eloxiv generate` writes into `sync.gen.ts`. With such an action (on the next `eloxiv generate`), the module's mutators move to `mutators.gen.ts`, the only file that imports `predictions.ts`, and back into `sync.gen.ts` once none is left: clients load it through `eloxiv.sync.ts`, while the server imports `eloxiv.schema.ts` and never runs your prediction code. It reads what the replica holds and writes only the tables of the entities the action declares; the server still runs the handler, and its answer replaces the prediction ([Sync](contracts/sync.md#custom-predictions)). For example, an action `tasks.reopenAll` (`writes: "task"`, `optimistic: optimistic.custom()`) whose handler reopens the caller's done tasks, predicted as:
357
+
358
+ ```ts
359
+ // modules/tasks/predictions.ts
360
+ import type { Predictions } from "./sync.gen.ts"
361
+
362
+ /** Every done task of the caller's that the replica holds, reopened. */
363
+ export const reopenAll: Predictions["reopenAll"] = async ({ tx, ctx, zql }) => {
364
+ const done = await tx.run(zql.task.where("ownerId", ctx.userId).where("done", true))
365
+ for (const task of done) await tx.mutate.task.update({ id: task.id, done: false })
366
+ }
367
+ ```
368
+
369
+ Run `eloxiv generate` after adding it; it refuses a module whose actions declare `optimistic.custom()` without this file.
370
+
371
+ Stop `eloxiv dev` (Ctrl-C) and start it again: setup creates the `tasks` schema and roles and applies the migration. Then, in the second terminal:
372
+
373
+ ```sh
374
+ eloxiv call tasks.add --url "$ELOXIV_URL" --input '{"title":"Write the launch note"}'
375
+ # copy the "id" it prints
376
+ ELOXIV_TOKEN=$(node scripts/sign-in.ts bob@example.com) eloxiv call tasks.complete --url "$ELOXIV_URL" --input '{"id":"<the id>"}'
377
+ eloxiv call tasks.complete --url "$ELOXIV_URL" --input '{"id":"<the id>"}'
378
+ ```
379
+
380
+ Alice adds a task; Bob, in the same organisation, is refused (`{ "_tag": "Forbidden", "message": "The caller may not act on this record", ... }`, exit 1): the policy lets only its owner complete it; Alice completes it (`"done": true`). The same actions are MCP tools, HTTP routes (`POST /api/actions/tasks.add`) and agent tools, each going through the same checks.
381
+
382
+ ## 6. Prove it
383
+
384
+ **Stop `eloxiv dev` (Ctrl-C) before this step, and start it again after it.** The test's and the evals' kernels run setup on the same server, and setup gives the module roles the whole server shares (`eloxiv_mod_tasks`, ...) to its own login role, so a running app's every action would then fail ("The call failed unexpectedly"; the kernel's log names the role it may no longer take) until its next start takes them back. To keep the app running instead, give tests and evals a second server: `initdb` and `pg_ctl` as in step 1 with another directory and port, then run the commands below with that port in `PGPORT` and in `ELOXIV_ADMIN_DATABASE_URL`.
385
+
386
+ **A test.** `@eloxiv/testing` starts your app's own kernel for a test, on a database of its own: `startKernel({ app, database })` runs setup there as the superuser of the server on `$PGPORT` (with `PGPASSWORD`), then serves on a free port. Install it and Vitest:
387
+
388
+ ```sh
389
+ pnpm add -D vitest@5.0.5 "@eloxiv/testing@^0.1.0"
390
+ ```
391
+
392
+ ```ts title="tests/tasks.test.ts"
393
+ /**
394
+ * The tasks module through the typed client, on a kernel of its own: a person adds a task, another person of the
395
+ * same organisation may not complete it, its owner may. The test sets up its own database and drops it after.
396
+ */
397
+ import { makeClient, signIn } from "@eloxiv/client"
398
+ import { dropDatabase, startKernel } from "@eloxiv/testing"
399
+ import { afterAll, beforeAll, expect, it } from "vitest"
400
+ import { contracts } from "../eloxiv.modules.ts"
401
+ import { app } from "../server/main.ts"
402
+ import { DEMO_PASSWORD, seed } from "../server/seed.ts"
403
+
404
+ const database = `my_app_test_${process.pid}`
405
+ let kernel: Awaited<ReturnType<typeof startKernel>> | undefined
406
+
407
+ beforeAll(async () => {
408
+ kernel = await startKernel({ app, database }) // setup (schemas, roles, migrations), then serve on a free port
409
+ await kernel.run(seed) // the demo organisations and people
410
+ }, 120_000)
411
+
412
+ afterAll(async () => {
413
+ await kernel?.dispose()
414
+ await dropDatabase(database, process.cwd())
415
+ })
416
+
417
+ /** A typed client acting as `email` in Acme. */
418
+ const clientFor = async (email: string) => {
419
+ const session = await signIn(kernel!.url, { email, password: DEMO_PASSWORD })
420
+ return makeClient({ baseUrl: kernel!.url, modules: contracts, token: () => session.token, orgId: () => "acme" })
421
+ }
422
+
423
+ it("adds a task for its owner, and only the owner completes it", async () => {
424
+ const alice = await clientFor("alice@example.com")
425
+ const bob = await clientFor("bob@example.com")
426
+
427
+ const added = await alice.call("tasks.add", { title: "Write the launch note" })
428
+ expect(added).toMatchObject({ kind: "output", output: { title: "Write the launch note", done: false } })
429
+ const id = added.kind === "output" ? added.output.id : ""
430
+
431
+ await expect(bob.call("tasks.complete", { id })).rejects.toMatchObject({ _tag: "Forbidden" })
432
+ await expect(alice.call("tasks.complete", { id })).resolves.toMatchObject({ output: { id, done: true } })
433
+ }, 60_000)
434
+ ```
435
+
436
+ ```sh
437
+ pnpm exec vitest run
438
+ ```
439
+
440
+ It passes (`1 passed`) and drops its database afterwards (with `psql`, on your `PATH` since step 1). Loosen the policy (drop `&& resource.owner == principal` from `tasks.complete`) and it fails: `promise resolved ... instead of rejecting`. To also prove that a second person's replica never holds the first one's tasks, `startSystem` (same package) runs zero-cache beside the kernel, and the client SDK's `connectSync` opens a replica per person; see [Sync](contracts/sync.md) and [ClientSDK](contracts/client-sdk.md#how-an-implementation-is-checked).
441
+
442
+ **The skill's evals.** `eloxiv eval` runs each case through the real agent runtime on a kernel of its own (a scratch database, `eloxiv_evals`, dropped before and after) and scores the skill against its `threshold`:
443
+
444
+ ```sh
445
+ eloxiv eval --module tasks
446
+ ```
447
+
448
+ Without a model it plays each case's `script` (a regression test of the module, the skill's tools and the runtime): `PASS tasks / tasks.manage: 100% (threshold 100%)`. Once the app has the OpenAI connector (step 8), score it on a real model, again with `eloxiv dev` stopped: `OPENAI_API_KEY=sk-... eloxiv eval --module tasks --model openai:gpt-5-mini`. That is where evals earn their place: an earlier version of this skill did not tell the agent to repeat the task's title, the model answered "Done — task added", and the first case failed until the skill said so. See [eval](cli.md#eval).
449
+
450
+ ## 7. A screen on the client SDK
451
+
452
+ Start `eloxiv dev` again if you stopped it for step 6.
453
+
454
+ Screens are Foldkit programs (The Elm Architecture: a Schema-defined Model, Messages, a pure update returning Commands, Subscriptions) styled with StyleX. The shell discovers every file in `shell-foldkit/src/screens/` and gives each the route of the manifest view it names (`tasks.list` → `/tasks`). The client SDK's Foldkit adapter, `@eloxiv/client/foldkit`, carries the hard parts: `liveQuery` turns a named query's results into Messages for the replica the screen was created for (a late snapshot of another organisation's replica is never shown), and `writeOptimistic` applies a generated mutator's prediction at once and resolves when the server confirms it, or rolls it back with the typed refusal. The Model holds interaction state only; rows are typed by the generated sync table, never declared again.
455
+
456
+ ```ts title="shell-foldkit/src/screens/tasks.ts"
457
+ /**
458
+ * The app's own screen for its tasks module: open tasks live from the local replica, added and completed
459
+ * optimistically (each shows at once; the server's answer confirms it, or a refusal rolls it back with the reason).
460
+ * The Model holds interaction state only: the draft, the replica, the query's latest result and the last refusal.
461
+ */
462
+ import type { Row } from "@eloxiv/client"
463
+ import {
464
+ isSettled,
465
+ liveQuery,
466
+ QueryState,
467
+ QueryWaiting,
468
+ receive,
469
+ ReplicaKey,
470
+ rowsOf,
471
+ Snapshot,
472
+ WriteError,
473
+ writeOptimistic,
474
+ type ReplicaService,
475
+ } from "@eloxiv/client/foldkit"
476
+ import { Effect, Option, Schema } from "effect"
477
+ import { Command, Subscription, type Update } from "foldkit"
478
+ import type { Html, HtmlBuilder } from "foldkit/html"
479
+ import { defineMessageUnion } from "foldkit/message"
480
+ import { mutators, queries, type AppSchema } from "../../../eloxiv.sync.ts"
481
+ import { task } from "../../../modules/tasks/contract.ts"
482
+ import { defineScreen } from "../screen.ts"
483
+ import { styles, sx } from "../styles.ts"
484
+
485
+ /** A task as the replica delivers it: typed by the sync table generated from the Drizzle table. */
486
+ type Task = Row<AppSchema["tables"]["task"]>
487
+
488
+ const Model = Schema.Struct({
489
+ replica: ReplicaKey,
490
+ tasks: QueryState<Task>(task.row),
491
+ title: Schema.String,
492
+ refusal: Schema.Option(WriteError),
493
+ })
494
+ type Model = typeof Model.Type
495
+
496
+ const Message = defineMessageUnion({
497
+ ChangedTitle: { value: Schema.String },
498
+ Submitted: {},
499
+ ClickedDone: { id: Schema.String },
500
+ GotTasks: { snapshot: Snapshot<Task>(task.row) },
501
+ Confirmed: {},
502
+ Refused: { error: WriteError },
503
+ })
504
+ type Message = typeof Message.Type
505
+
506
+ /** A write through the generated mutator: predicted on the replica, then confirmed or refused by the server. */
507
+ const Write = Command.define("WriteTask", {
508
+ args: { replica: ReplicaKey, add: Schema.optional(Schema.String), complete: Schema.optional(Schema.String) },
509
+ messages: [Message.Confirmed, Message.Refused],
510
+ execute: ({ replica, add, complete }) =>
511
+ writeOptimistic(
512
+ replica,
513
+ add !== undefined ? mutators.tasks.add({ title: add }) : mutators.tasks.complete({ id: complete! }),
514
+ ).pipe(
515
+ Effect.as(Message.Confirmed()),
516
+ Effect.catch((error) => Effect.succeed(Message.Refused({ error }))),
517
+ ),
518
+ })
519
+
520
+ type Return = Update.Return<Model, Message, ReplicaService>
521
+
522
+ const update = (model: Model, message: Message): Return =>
523
+ Message.match<Return>(message, {
524
+ ChangedTitle: ({ value }) => ({ model: { ...model, title: value } }),
525
+ Submitted: () =>
526
+ model.title.trim() === ""
527
+ ? { model }
528
+ : {
529
+ model: { ...model, title: "", refusal: Option.none() },
530
+ commands: [Write({ replica: model.replica, add: model.title.trim() })],
531
+ },
532
+ ClickedDone: ({ id }) => ({ model, commands: [Write({ replica: model.replica, complete: id })] }),
533
+ // Only a snapshot of the replica this screen reads is kept (never one of a previous organisation's).
534
+ GotTasks: ({ snapshot }) => ({
535
+ model: { ...model, tasks: receive(model.tasks, { _tag: "Open", key: model.replica }, snapshot) },
536
+ }),
537
+ Confirmed: () => ({ model }),
538
+ Refused: ({ error }) => ({ model: { ...model, refusal: Option.some(error) } }),
539
+ })
540
+
541
+ const view = (model: Model, h: HtmlBuilder<Message>): Html =>
542
+ h.section(
543
+ [sx(styles.card), h.AriaLabelledBy("tasks-title")],
544
+ [
545
+ h.h1([h.Id("tasks-title"), sx(styles.cardTitle)], ["Tasks"]),
546
+ h.form(
547
+ [h.OnSubmit(Message.Submitted()), sx(styles.row)],
548
+ [
549
+ h.input([
550
+ h.AriaLabel("New task"),
551
+ h.Value(model.title),
552
+ h.OnInput((value) => Message.ChangedTitle({ value })),
553
+ sx(styles.input),
554
+ ]),
555
+ h.button([h.Type("submit"), sx(styles.button)], ["Add"]),
556
+ ],
557
+ ),
558
+ ...Option.match(model.refusal, {
559
+ onNone: () => [],
560
+ onSome: (error) => [h.p([h.Role("alert"), sx(styles.error)], [`Not saved (${error._tag}): ${error.message}`])],
561
+ }),
562
+ h.ul(
563
+ [
564
+ h.AriaLabel("Open tasks"),
565
+ h.DataAttribute("ready", isSettled(model.tasks) ? "true" : "false"),
566
+ sx(styles.list),
567
+ ],
568
+ rowsOf(model.tasks).map((t) =>
569
+ h.keyed("li")(
570
+ t.id,
571
+ [sx(styles.listItem)],
572
+ [
573
+ h.span([], [t.title]),
574
+ h.button([h.OnClick(Message.ClickedDone({ id: t.id })), sx(styles.button)], ["Done"]),
575
+ ],
576
+ ),
577
+ ),
578
+ ),
579
+ ],
580
+ )
581
+
582
+ const subscriptions = Subscription.make<Model, Message, ReplicaService>()(() => ({
583
+ tasks: liveQuery<Model, Message, Task>({
584
+ replica: (model) => Option.some(model.replica),
585
+ query: () => queries.tasks.open(),
586
+ toMessage: (snapshot) => Message.GotTasks({ snapshot }),
587
+ }),
588
+ }))
589
+
590
+ export const screen = defineScreen<Model, Message>({
591
+ view: "tasks.list",
592
+ init: ({ replica }) => ({ model: { replica, tasks: QueryWaiting, title: "", refusal: Option.none() } }),
593
+ update,
594
+ render: view,
595
+ subscriptions,
596
+ isReady: (model) => isSettled(model.tasks),
597
+ })
598
+ ```
599
+
600
+ ```sh
601
+ eloxiv typecheck
602
+ ```
603
+
604
+ The shell's dev server picks the file up. Open **Tasks** in the shell's navigation (<http://localhost:5173/tasks>: port 5173, or your `ELOXIV_SHELL_PORT`): add a task, and it shows before the server answers; **Done** removes it from the open list. Sign in as Bob in another browser: his list is empty, because the replica holds only his own tasks. The full [ClientSDK](contracts/client-sdk.md) page covers the adapter's other exports (connection state, collaborative documents, uploads, sessions, the account) and React Native.
605
+
606
+ ## 8. The agent
607
+
608
+ The agent works over every installed module through the same action registry, so your module is already its tools (`tasks_add`, `tasks_complete`), its skill and its query view. It needs a model: add the OpenAI model connector, which brings the kernel's agent module and its sync tables into the composition:
609
+
610
+ ```sh
611
+ eloxiv add openai
612
+ ```
613
+
614
+ Stop `eloxiv dev` and start it again with the model's key and the model to use:
615
+
616
+ ```sh
617
+ ELOXIV_MODEL_OPENAI_API_KEY=sk-... ELOXIV_AGENT_MODEL=openai:gpt-5-mini eloxiv dev
618
+ ```
619
+
620
+ `eloxiv agent "Which tasks do I have open?" --url "$ELOXIV_URL"` asks it from the terminal. A call that changes something on a person's behalf waits for that person's consent (an action marked `consent`, or destructive), and every call is audited like any other.
621
+
622
+ ## 9. A chat screen on the headless chat SDK
623
+
624
+ `@eloxiv/client/chat` is a chat's state and operations without any view: you feed it the replica's rows (`withMessages`, `withRuns`) and the active run's events (`withEvent`), and render what it derives (`transcript`, `canSend`, the pending `consents`). It keeps the guarantees that are easy to get wrong: a send is one send under its idempotency key, streamed text is shown per model step and never twice, only the active run changes the state, and consent is decided only by the person. The registry's `chat-ui-foldkit` is a fuller reference (conversations, outstanding sends that outlive the screen, paired devices); this one is the core of it:
625
+
626
+ ```ts title="shell-foldkit/src/screens/assistant.ts"
627
+ /**
628
+ * The app's own chat screen on the headless chat SDK (`@eloxiv/client/chat`): the SDK holds the conversation's state
629
+ * and its guarantees (one send per idempotency key, streamed text by model step, events only from the active run,
630
+ * consent decided only by the person); this file feeds it the replica's rows and the run's events, and renders it.
631
+ */
632
+ import * as Chat from "@eloxiv/client/chat"
633
+ import { liveQuery, ReplicaKey, rowsFrom, Snapshot, type ReplicaService } from "@eloxiv/client/foldkit"
634
+ import { Effect, Option, Schema, Stream } from "effect"
635
+ import { Command, Subscription, type Update } from "foldkit"
636
+ import type { Html, HtmlBuilder } from "foldkit/html"
637
+ import { defineMessageUnion } from "foldkit/message"
638
+ import { queries } from "../../../eloxiv.sync.ts"
639
+ import { defineScreen, sessionToken } from "../screen.ts"
640
+ import { styles, sx } from "../styles.ts"
641
+
642
+ /** A replica row of the agent's tables, read field by field into the SDK's records. */
643
+ const Row = Schema.Record(Schema.String, Schema.Unknown)
644
+ type Row = typeof Row.Type
645
+ const str = (row: Row, field: string) => (typeof row[field] === "string" ? (row[field] as string) : "")
646
+ const num = (row: Row, field: string) => (typeof row[field] === "number" ? (row[field] as number) : 0)
647
+ const opt = (row: Row, field: string) => (typeof row[field] === "string" ? (row[field] as string) : null)
648
+
649
+ const toMessages = (rows: ReadonlyArray<Row>): ReadonlyArray<Chat.ChatMessage> =>
650
+ rows.map((row) => ({
651
+ id: str(row, "id"),
652
+ conversationId: str(row, "conversationId"),
653
+ runId: opt(row, "runId"),
654
+ seq: num(row, "seq"),
655
+ role: str(row, "role") as Chat.ChatMessage["role"],
656
+ text: str(row, "text"),
657
+ }))
658
+ const toRuns = (rows: ReadonlyArray<Row>): ReadonlyArray<Chat.ChatRun> =>
659
+ rows
660
+ .filter((row) => str(row, "kind") === "turn")
661
+ .map((row) => ({
662
+ id: str(row, "id"),
663
+ conversationId: str(row, "conversationId"),
664
+ status: str(row, "status") as Chat.ChatRun["status"],
665
+ error: opt(row, "error"),
666
+ createdAt: num(row, "createdAt"),
667
+ }))
668
+
669
+ const Model = Schema.Struct({
670
+ replica: ReplicaKey,
671
+ session: Schema.String,
672
+ kernelUrl: Schema.String,
673
+ chat: Chat.ChatState,
674
+ messages: Schema.Array(Chat.ChatMessage),
675
+ runs: Schema.Array(Chat.ChatRun),
676
+ })
677
+ type Model = typeof Model.Type
678
+
679
+ const Message = defineMessageUnion({
680
+ ChangedDraft: { value: Schema.String },
681
+ Submitted: {},
682
+ MadeKey: { key: Schema.String },
683
+ Sent: { key: Schema.String, conversationId: Schema.String, runId: Schema.String },
684
+ Replayed: { key: Schema.String },
685
+ SendFailed: { key: Schema.String, error: Chat.ChatError },
686
+ GotMessages: { snapshot: Snapshot<Row>(Row) },
687
+ GotRuns: { snapshot: Snapshot<Row>(Row) },
688
+ GotEvent: { event: Schema.Unknown },
689
+ Decided: { consentId: Schema.String, decision: Schema.Literals(["approve", "reject"]) },
690
+ DecisionDone: {},
691
+ })
692
+ type Message = typeof Message.Type
693
+
694
+ /** The chat client, acting as the screen's session; the token is read only when a request is made. */
695
+ const client = (model: { session: string; kernelUrl: string; orgId: string }) =>
696
+ Chat.chatClient({ baseUrl: model.kernelUrl, token: () => sessionToken(model.session), orgId: model.orgId })
697
+ const Acting = { session: Schema.String, kernelUrl: Schema.String, orgId: Schema.String }
698
+ const acting = (model: Model) => ({ session: model.session, kernelUrl: model.kernelUrl, orgId: model.replica.orgId })
699
+
700
+ /** A fresh idempotency key: randomness belongs in a Command, so update stays pure. */
701
+ const MakeKey = Command.define("MakeKey", {
702
+ messages: [Message.MadeKey],
703
+ execute: Effect.sync(() => Message.MadeKey({ key: `chat-${crypto.randomUUID()}` })),
704
+ })
705
+
706
+ const Send = Command.define("Send", {
707
+ args: { ...Acting, send: Chat.OutstandingSend },
708
+ messages: [Message.Sent, Message.Replayed, Message.SendFailed],
709
+ execute: ({ send, ...who }) =>
710
+ client(who)
711
+ .send({ text: send.text, conversationId: send.conversationId, idempotencyKey: send.key })
712
+ .pipe(
713
+ Effect.map((result) =>
714
+ result.kind === "sent"
715
+ ? Message.Sent({ key: send.key, conversationId: result.conversationId, runId: result.runId })
716
+ : Message.Replayed({ key: send.key }),
717
+ ),
718
+ Effect.catch((error) => Effect.succeed(Message.SendFailed({ key: send.key, error }))),
719
+ ),
720
+ })
721
+
722
+ const Decide = Command.define("Decide", {
723
+ args: { ...Acting, consentId: Schema.String, decision: Schema.Literals(["approve", "reject"]) },
724
+ messages: [Message.DecisionDone],
725
+ execute: ({ consentId, decision, ...who }) =>
726
+ client(who)
727
+ .decideConsent(consentId, decision)
728
+ .pipe(
729
+ Effect.as(Message.DecisionDone()),
730
+ Effect.catch(() => Effect.succeed(Message.DecisionDone())),
731
+ ),
732
+ })
733
+
734
+ type Return = Update.Return<Model, Message, ReplicaService>
735
+
736
+ const update = (model: Model, message: Message): Return =>
737
+ Message.match<Return>(message, {
738
+ ChangedDraft: ({ value }) => ({ model: { ...model, chat: Chat.edit(model.chat, value) } }),
739
+ // A send whose answer was lost goes again under its own key; otherwise a new key first.
740
+ Submitted: () => {
741
+ if (!Chat.canSend(model.chat)) return { model }
742
+ const unresolved = Chat.unresolvedSend(model.chat)
743
+ return unresolved === undefined
744
+ ? { model, commands: [MakeKey()] }
745
+ : update(model, Message.MadeKey({ key: unresolved.key }))
746
+ },
747
+ MadeKey: ({ key }) => {
748
+ const { state, send } = Chat.submit(model.chat, key)
749
+ return send === undefined
750
+ ? { model }
751
+ : { model: { ...model, chat: state }, commands: [Send({ ...acting(model), send })] }
752
+ },
753
+ Sent: ({ key, ...result }) => ({
754
+ model: {
755
+ ...model,
756
+ chat: Chat.withRuns(Chat.withMessages(Chat.sent(model.chat, key, result), model.messages), model.runs),
757
+ },
758
+ }),
759
+ Replayed: ({ key }) => ({ model: { ...model, chat: Chat.replayed(model.chat, key) } }),
760
+ SendFailed: ({ key, error }) => ({ model: { ...model, chat: Chat.sendFailed(model.chat, key, error) } }),
761
+ GotMessages: ({ snapshot }) =>
762
+ Option.match(rowsFrom(model.replica, snapshot), {
763
+ onNone: () => ({ model }),
764
+ onSome: (rows) => {
765
+ const messages = toMessages(rows)
766
+ return { model: { ...model, messages, chat: Chat.withMessages(model.chat, messages) } }
767
+ },
768
+ }),
769
+ GotRuns: ({ snapshot }) =>
770
+ Option.match(rowsFrom(model.replica, snapshot), {
771
+ onNone: () => ({ model }),
772
+ onSome: (rows) => {
773
+ const runs = toRuns(rows)
774
+ return { model: { ...model, runs, chat: Chat.withRuns(model.chat, runs) } }
775
+ },
776
+ }),
777
+ GotEvent: ({ event }) => ({ model: { ...model, chat: Chat.withEvent(model.chat, event as never) } }),
778
+ Decided: ({ consentId, decision }) => ({ model, commands: [Decide({ ...acting(model), consentId, decision })] }),
779
+ DecisionDone: () => ({ model }),
780
+ })
781
+
782
+ const view = (model: Model, h: HtmlBuilder<Message>): Html =>
783
+ h.section(
784
+ [sx(styles.card), h.AriaLabelledBy("assistant-title")],
785
+ [
786
+ h.h1([h.Id("assistant-title"), sx(styles.cardTitle)], ["Assistant"]),
787
+ h.ol(
788
+ [h.AriaLabel("Transcript"), h.AriaLive("polite"), sx(styles.list)],
789
+ // Tool results are stored messages too; this screen shows only the person and the agent.
790
+ Chat.transcript(model.chat)
791
+ .filter((entry) => entry.role === "user" || entry.role === "assistant")
792
+ .map((entry) =>
793
+ h.keyed("li")(
794
+ entry.id,
795
+ [h.DataAttribute("role", entry.role), sx(styles.listItem)],
796
+ [h.span([sx(styles.badge)], [entry.role === "user" ? "You" : "Agent"]), " ", entry.text],
797
+ ),
798
+ ),
799
+ ),
800
+ // A tool call held for the person's consent: only they decide it.
801
+ ...model.chat.consents.map((consent) =>
802
+ h.div(
803
+ [h.Role("group"), sx(styles.row)],
804
+ [
805
+ h.span([], [`Your agent asks to run ${consent.action}.`]),
806
+ h.button(
807
+ [h.OnClick(Message.Decided({ consentId: consent.consentId, decision: "approve" })), sx(styles.button)],
808
+ ["Allow"],
809
+ ),
810
+ h.button(
811
+ [h.OnClick(Message.Decided({ consentId: consent.consentId, decision: "reject" })), sx(styles.button)],
812
+ ["Decline"],
813
+ ),
814
+ ],
815
+ ),
816
+ ),
817
+ h.form(
818
+ [h.OnSubmit(Message.Submitted()), sx(styles.row)],
819
+ [
820
+ h.input([
821
+ h.AriaLabel("Message"),
822
+ h.Value(model.chat.composer.draft),
823
+ h.OnInput((value) => Message.ChangedDraft({ value })),
824
+ sx(styles.input),
825
+ ]),
826
+ h.button([h.Type("submit"), h.Disabled(!Chat.canSend(model.chat)), sx(styles.button)], ["Send"]),
827
+ ],
828
+ ),
829
+ ...(model.chat.composer.error === null
830
+ ? []
831
+ : [h.p([h.Role("alert"), sx(styles.error)], [Chat.chatErrorMessage(model.chat.composer.error)])]),
832
+ ],
833
+ )
834
+
835
+ const subscriptions = Subscription.make<Model, Message, ReplicaService>()((entry) => ({
836
+ messages: liveQuery<Model, Message, Row>({
837
+ replica: (model) => Option.some(model.replica),
838
+ query: () => queries.agent.messages(),
839
+ toMessage: (snapshot) => Message.GotMessages({ snapshot }),
840
+ }),
841
+ runs: liveQuery<Model, Message, Row>({
842
+ replica: (model) => Option.some(model.replica),
843
+ query: () => queries.agent.runs(),
844
+ toMessage: (snapshot) => Message.GotRuns({ snapshot }),
845
+ }),
846
+ // The active run's events (streamed text, consent requests, its end), for as long as it is the active run.
847
+ events: entry(
848
+ { run: Schema.Option(Schema.Struct({ runId: Schema.String, ...Acting })) },
849
+ {
850
+ modelToDependencies: (model) => {
851
+ const active = Chat.activeRun(model.chat)
852
+ return { run: active === undefined ? Option.none() : Option.some({ runId: active.id, ...acting(model) }) }
853
+ },
854
+ dependenciesToStream: ({ run }) =>
855
+ Option.match(run, {
856
+ onNone: () => Stream.empty,
857
+ onSome: ({ runId, ...who }) =>
858
+ client(who)
859
+ .events(runId, -1)
860
+ .pipe(
861
+ Stream.map((event) => Message.GotEvent({ event })),
862
+ Stream.catch(() => Stream.empty),
863
+ ),
864
+ }),
865
+ },
866
+ ),
867
+ }))
868
+
869
+ export const screen = defineScreen<Model, Message>({
870
+ // A kernel-provided capability (the agent), so the screen names its own route and title.
871
+ view: "assistant",
872
+ route: "/assistant",
873
+ title: "Assistant",
874
+ init: ({ replica, session, kernelUrl }) => ({
875
+ model: { replica, session, kernelUrl, chat: Chat.initialChat(), messages: [], runs: [] },
876
+ }),
877
+ update,
878
+ render: view,
879
+ subscriptions,
880
+ isReady: () => true,
881
+ })
882
+ ```
883
+
884
+ ```sh
885
+ eloxiv typecheck
886
+ ```
887
+
888
+ Open `/assistant` on the shell (<http://localhost:5173/assistant>, or your `ELOXIV_SHELL_PORT`) and ask "Which tasks do I have open?": the answer streams in, read from your `tasks.open` view through the agent's query tool, filtered by your policy for the person asking. Ask it to add one, and the new task appears on the Tasks screen. The [chat SDK](contracts/client-sdk.md#the-chat-sdk) section lists every operation and guarantee, including staged context, references from other screens (`applyIntent`) and the inbox.
889
+
890
+ ## Working from a checkout
891
+
892
+ To build an app on Eloxiv's unreleased code (a branch, or your own change to the packages or the registry), install from a checkout of the repository instead of npm. In the checkout, build and pack the public packages:
893
+
894
+ ```sh
895
+ export ELOXIV_CHECKOUT=$HOME/src/eloxiv # where you cloned Eloxiv
896
+ cd "$ELOXIV_CHECKOUT" && mise install && mise run install
897
+ mise run release:pack # the tarballs: $ELOXIV_CHECKOUT/.eloxiv/release/eloxiv-<package>-<version>.tgz
898
+ ```
899
+
900
+ Use the checkout's CLI (`node "$ELOXIV_CHECKOUT/packages/cli/dist/bin.js"`, built by `release:pack`) in place of `eloxiv`, pass the checkout's registry to `init`, and point the app's `@eloxiv/*` dependencies at the local tarballs with pnpm `overrides` before the first `eloxiv add`:
901
+
902
+ ```sh
903
+ alias eloxiv="node $ELOXIV_CHECKOUT/packages/cli/dist/bin.js"
904
+ eloxiv init my-app --registry "$ELOXIV_CHECKOUT/registry/public/r"
905
+ cd my-app
906
+ node -e '
907
+ const fs = require("node:fs"), dir = process.env.ELOXIV_CHECKOUT + "/.eloxiv/release"
908
+ const pkg = JSON.parse(fs.readFileSync("package.json", "utf8"))
909
+ const overrides = {}
910
+ for (const file of fs.readdirSync(dir)) {
911
+ const name = /^eloxiv-(.+)-\d+\.\d+\.\d+.*\.tgz$/.exec(file)?.[1]
912
+ if (name) overrides["@eloxiv/" + name] = "file:" + dir + "/" + file
913
+ }
914
+ pkg.pnpm = { ...pkg.pnpm, overrides }
915
+ fs.writeFileSync("package.json", JSON.stringify(pkg, null, 2) + "\n")
916
+ '
917
+ eloxiv add app hello hello-ui-foldkit
918
+ ```
919
+
920
+ Run `mise run release:pack` again after changing the packages, then `pnpm install --force` in the app. Inside the checkout itself, the examples (`examples/`) link the workspace's packages directly ([the scaffold](scaffold.md)).
921
+
922
+ ## Where next
923
+
924
+ - [The registry](registry/README.md): every module, connector, screen, shell, desktop host, space, skill and tooling item, with what it needs and how to add it.
925
+ - [The CLI](cli.md): every command, including `diff`, `update` and `eject` for items you have changed, `build`, `start` and `deploy` for production.
926
+ - [Contracts](contracts/README.md): each kernel, capability and shell contract an app builds on, with its guarantees and limits; [ModuleManifest](contracts/module-manifest.md) is everything a module can declare (events, jobs, settings, workflows, slots, commands, work-item sources).
927
+ - `eloxiv docs search <words>` searches this documentation, as shipped with your CLI, from the terminal.