@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.
- package/LICENSE +21 -0
- package/README.md +12 -2
- package/dist/AgentSkills.d.ts +51 -0
- package/dist/AgentSkills.d.ts.map +1 -0
- package/dist/AgentSkills.js +264 -0
- package/dist/AgentSkills.js.map +1 -0
- package/dist/AgentWeb.d.ts +83 -0
- package/dist/AgentWeb.d.ts.map +1 -0
- package/dist/AgentWeb.js +436 -0
- package/dist/AgentWeb.js.map +1 -0
- package/dist/App.d.ts +213 -0
- package/dist/App.d.ts.map +1 -0
- package/dist/App.js +357 -0
- package/dist/App.js.map +1 -0
- package/dist/Blueprint.d.ts +47 -0
- package/dist/Blueprint.d.ts.map +1 -0
- package/dist/Blueprint.js +241 -0
- package/dist/Blueprint.js.map +1 -0
- package/dist/Brand.d.ts +42 -0
- package/dist/Brand.d.ts.map +1 -0
- package/dist/Brand.js +370 -0
- package/dist/Brand.js.map +1 -0
- package/dist/Changelog.d.ts +22 -0
- package/dist/Changelog.d.ts.map +1 -0
- package/dist/Changelog.js +117 -0
- package/dist/Changelog.js.map +1 -0
- package/dist/Cli.d.ts +17 -0
- package/dist/Cli.d.ts.map +1 -0
- package/dist/Cli.js +810 -0
- package/dist/Cli.js.map +1 -0
- package/dist/DbAdmin.d.ts +18 -0
- package/dist/DbAdmin.d.ts.map +1 -0
- package/dist/DbAdmin.js +91 -0
- package/dist/DbAdmin.js.map +1 -0
- package/dist/Dependencies.d.ts +53 -0
- package/dist/Dependencies.d.ts.map +1 -0
- package/dist/Dependencies.js +132 -0
- package/dist/Dependencies.js.map +1 -0
- package/dist/Deploy.d.ts +39 -0
- package/dist/Deploy.d.ts.map +1 -0
- package/dist/Deploy.js +458 -0
- package/dist/Deploy.js.map +1 -0
- package/dist/Docs.d.ts +71 -0
- package/dist/Docs.d.ts.map +1 -0
- package/dist/Docs.js +240 -0
- package/dist/Docs.js.map +1 -0
- package/dist/Doctor.d.ts +56 -0
- package/dist/Doctor.d.ts.map +1 -0
- package/dist/Doctor.js +368 -0
- package/dist/Doctor.js.map +1 -0
- package/dist/Dossier.d.ts +23 -0
- package/dist/Dossier.d.ts.map +1 -0
- package/dist/Dossier.js +92 -0
- package/dist/Dossier.js.map +1 -0
- package/dist/Emit.d.ts +26 -0
- package/dist/Emit.d.ts.map +1 -0
- package/dist/Emit.js +51 -0
- package/dist/Emit.js.map +1 -0
- package/dist/Errors.d.ts +26 -0
- package/dist/Errors.d.ts.map +1 -0
- package/dist/Errors.js +17 -0
- package/dist/Errors.js.map +1 -0
- package/dist/Evals.d.ts +52 -0
- package/dist/Evals.d.ts.map +1 -0
- package/dist/Evals.js +126 -0
- package/dist/Evals.js.map +1 -0
- package/dist/Files.d.ts +47 -0
- package/dist/Files.d.ts.map +1 -0
- package/dist/Files.js +145 -0
- package/dist/Files.js.map +1 -0
- package/dist/Generate.d.ts +80 -0
- package/dist/Generate.d.ts.map +1 -0
- package/dist/Generate.js +310 -0
- package/dist/Generate.js.map +1 -0
- package/dist/Guards.d.ts +45 -0
- package/dist/Guards.d.ts.map +1 -0
- package/dist/Guards.js +530 -0
- package/dist/Guards.js.map +1 -0
- package/dist/Inspect.d.ts +125 -0
- package/dist/Inspect.d.ts.map +1 -0
- package/dist/Inspect.js +270 -0
- package/dist/Inspect.js.map +1 -0
- package/dist/Keychain.d.ts +57 -0
- package/dist/Keychain.d.ts.map +1 -0
- package/dist/Keychain.js +73 -0
- package/dist/Keychain.js.map +1 -0
- package/dist/Lock.d.ts +13 -0
- package/dist/Lock.d.ts.map +1 -0
- package/dist/Lock.js +145 -0
- package/dist/Lock.js.map +1 -0
- package/dist/Mcp.d.ts +91 -0
- package/dist/Mcp.d.ts.map +1 -0
- package/dist/Mcp.js +128 -0
- package/dist/Mcp.js.map +1 -0
- package/dist/Merge.d.ts +18 -0
- package/dist/Merge.d.ts.map +1 -0
- package/dist/Merge.js +43 -0
- package/dist/Merge.js.map +1 -0
- package/dist/Migrate.d.ts +78 -0
- package/dist/Migrate.d.ts.map +1 -0
- package/dist/Migrate.js +288 -0
- package/dist/Migrate.js.map +1 -0
- package/dist/Plugins.d.ts +36 -0
- package/dist/Plugins.d.ts.map +1 -0
- package/dist/Plugins.js +304 -0
- package/dist/Plugins.js.map +1 -0
- package/dist/Postgres.d.ts +73 -0
- package/dist/Postgres.d.ts.map +1 -0
- package/dist/Postgres.js +294 -0
- package/dist/Postgres.js.map +1 -0
- package/dist/Publish.d.ts +23 -0
- package/dist/Publish.d.ts.map +1 -0
- package/dist/Publish.js +59 -0
- package/dist/Publish.js.map +1 -0
- package/dist/Registry.d.ts +539 -0
- package/dist/Registry.d.ts.map +1 -0
- package/dist/Registry.js +340 -0
- package/dist/Registry.js.map +1 -0
- package/dist/Remote.d.ts +90 -0
- package/dist/Remote.d.ts.map +1 -0
- package/dist/Remote.js +1006 -0
- package/dist/Remote.js.map +1 -0
- package/dist/Run.d.ts +120 -0
- package/dist/Run.d.ts.map +1 -0
- package/dist/Run.js +477 -0
- package/dist/Run.js.map +1 -0
- package/dist/SyncGen.d.ts +118 -0
- package/dist/SyncGen.d.ts.map +1 -0
- package/dist/SyncGen.js +392 -0
- package/dist/SyncGen.js.map +1 -0
- package/dist/Update.d.ts +301 -0
- package/dist/Update.d.ts.map +1 -0
- package/dist/Update.js +627 -0
- package/dist/Update.js.map +1 -0
- package/dist/bin.d.ts +3 -0
- package/dist/bin.d.ts.map +1 -0
- package/dist/bin.js +42 -0
- package/dist/bin.js.map +1 -0
- package/dist/docs/backlog.md +56 -0
- package/dist/docs/ci.md +277 -0
- package/dist/docs/cli.md +696 -0
- package/dist/docs/connectors/google.md +115 -0
- package/dist/docs/connectors/http-openapi.md +7 -0
- package/dist/docs/connectors/mcp.md +8 -0
- package/dist/docs/connectors/microsoft-graph.md +75 -0
- package/dist/docs/connectors/openai.md +25 -0
- package/dist/docs/connectors/slack.md +162 -0
- package/dist/docs/connectors/workos.md +39 -0
- package/dist/docs/contracts/README.md +173 -0
- package/dist/docs/contracts/action-consent.md +92 -0
- package/dist/docs/contracts/action-registry.md +85 -0
- package/dist/docs/contracts/actor.md +100 -0
- package/dist/docs/contracts/agent-resources.md +90 -0
- package/dist/docs/contracts/agent-runtime.md +257 -0
- package/dist/docs/contracts/approvals.md +126 -0
- package/dist/docs/contracts/audit.md +75 -0
- package/dist/docs/contracts/auth-provider.md +74 -0
- package/dist/docs/contracts/calendar-provider.md +46 -0
- package/dist/docs/contracts/client-sdk.md +245 -0
- package/dist/docs/contracts/collab-document.md +151 -0
- package/dist/docs/contracts/command.md +44 -0
- package/dist/docs/contracts/connections.md +235 -0
- package/dist/docs/contracts/context-accounting.md +50 -0
- package/dist/docs/contracts/daemon.md +243 -0
- package/dist/docs/contracts/db-tx.md +53 -0
- package/dist/docs/contracts/delegation.md +68 -0
- package/dist/docs/contracts/device-control.md +103 -0
- package/dist/docs/contracts/directory-provider.md +36 -0
- package/dist/docs/contracts/directory.md +161 -0
- package/dist/docs/contracts/document-source.md +33 -0
- package/dist/docs/contracts/files.md +115 -0
- package/dist/docs/contracts/flags.md +83 -0
- package/dist/docs/contracts/host.md +68 -0
- package/dist/docs/contracts/http-api.md +43 -0
- package/dist/docs/contracts/ingestion.md +130 -0
- package/dist/docs/contracts/ingress.md +141 -0
- package/dist/docs/contracts/invocation.md +260 -0
- package/dist/docs/contracts/local-client.md +110 -0
- package/dist/docs/contracts/locale.md +56 -0
- package/dist/docs/contracts/machine-identity.md +117 -0
- package/dist/docs/contracts/mail-provider.md +49 -0
- package/dist/docs/contracts/memory.md +53 -0
- package/dist/docs/contracts/messaging.md +40 -0
- package/dist/docs/contracts/metering.md +139 -0
- package/dist/docs/contracts/model-provider.md +84 -0
- package/dist/docs/contracts/module-manifest.md +213 -0
- package/dist/docs/contracts/notification-channel.md +90 -0
- package/dist/docs/contracts/notifications.md +123 -0
- package/dist/docs/contracts/outbox.md +80 -0
- package/dist/docs/contracts/privacy.md +110 -0
- package/dist/docs/contracts/progress.md +52 -0
- package/dist/docs/contracts/query-surface.md +108 -0
- package/dist/docs/contracts/readiness.md +63 -0
- package/dist/docs/contracts/release.md +142 -0
- package/dist/docs/contracts/result-rendering.md +61 -0
- package/dist/docs/contracts/sandbox.md +186 -0
- package/dist/docs/contracts/scheduler.md +148 -0
- package/dist/docs/contracts/screen-context.md +81 -0
- package/dist/docs/contracts/search.md +120 -0
- package/dist/docs/contracts/secrets.md +74 -0
- package/dist/docs/contracts/settings.md +109 -0
- package/dist/docs/contracts/sharing.md +77 -0
- package/dist/docs/contracts/slot.md +48 -0
- package/dist/docs/contracts/space.md +67 -0
- package/dist/docs/contracts/storage-adapter.md +45 -0
- package/dist/docs/contracts/storage-backend.md +56 -0
- package/dist/docs/contracts/sync.md +213 -0
- package/dist/docs/contracts/telemetry.md +80 -0
- package/dist/docs/contracts/theme-tokens.md +50 -0
- package/dist/docs/contracts/tool-source.md +58 -0
- package/dist/docs/contracts/versioning.md +99 -0
- package/dist/docs/contracts/view.md +65 -0
- package/dist/docs/contracts/work-items.md +99 -0
- package/dist/docs/contracts/workflow.md +82 -0
- package/dist/docs/decisions.md +163 -0
- package/dist/docs/example-app.md +192 -0
- package/dist/docs/getting-started.md +927 -0
- package/dist/docs/goal.md +54 -0
- package/dist/docs/parity.md +29 -0
- package/dist/docs/performance.md +129 -0
- package/dist/docs/registry/README.md +74 -0
- package/dist/docs/registry/app.md +38 -0
- package/dist/docs/registry/approvals-ui-foldkit.md +28 -0
- package/dist/docs/registry/calendar-ui-foldkit.md +27 -0
- package/dist/docs/registry/calendar.md +35 -0
- package/dist/docs/registry/chat-ui-foldkit.md +30 -0
- package/dist/docs/registry/desktop-rune.md +50 -0
- package/dist/docs/registry/desktop.md +32 -0
- package/dist/docs/registry/eloxiv-action.md +25 -0
- package/dist/docs/registry/eloxiv-connector.md +25 -0
- package/dist/docs/registry/eloxiv-module.md +25 -0
- package/dist/docs/registry/eloxiv-policy.md +25 -0
- package/dist/docs/registry/eloxiv-view.md +25 -0
- package/dist/docs/registry/hello-ui-foldkit.md +29 -0
- package/dist/docs/registry/hello.md +39 -0
- package/dist/docs/registry/home-ui-foldkit.md +27 -0
- package/dist/docs/registry/home.md +29 -0
- package/dist/docs/registry/inbox-ui-foldkit.md +27 -0
- package/dist/docs/registry/mail-ui-foldkit.md +27 -0
- package/dist/docs/registry/mail.md +34 -0
- package/dist/docs/registry/meeting-prep.md +26 -0
- package/dist/docs/registry/members-ui-foldkit.md +28 -0
- package/dist/docs/registry/mobile.md +37 -0
- package/dist/docs/registry/notes-ui-foldkit.md +27 -0
- package/dist/docs/registry/notes.md +26 -0
- package/dist/docs/registry/people-ui-foldkit.md +28 -0
- package/dist/docs/registry/people.md +38 -0
- package/dist/docs/registry/shell-foldkit.md +35 -0
- package/dist/docs/registry/theme.md +25 -0
- package/dist/docs/registry/ui-conformance.md +30 -0
- package/dist/docs/release.md +100 -0
- package/dist/docs/scaffold.md +826 -0
- package/dist/docs/security/threat-model.md +299 -0
- package/dist/docs/upstream/zero-cache-socket-handoff.md +105 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -0
- package/package.json +48 -3
- package/src/AgentSkills.ts +329 -0
- package/src/AgentWeb.ts +507 -0
- package/src/App.ts +435 -0
- package/src/Blueprint.ts +276 -0
- package/src/Brand.ts +415 -0
- package/src/Changelog.ts +136 -0
- package/src/Cli.ts +1458 -0
- package/src/DbAdmin.ts +115 -0
- package/src/Dependencies.ts +170 -0
- package/src/Deploy.ts +563 -0
- package/src/Docs.ts +309 -0
- package/src/Doctor.ts +424 -0
- package/src/Dossier.ts +148 -0
- package/src/Emit.ts +68 -0
- package/src/Errors.ts +18 -0
- package/src/Evals.ts +153 -0
- package/src/Files.ts +152 -0
- package/src/Generate.ts +402 -0
- package/src/Guards.ts +541 -0
- package/src/Inspect.ts +358 -0
- package/src/Keychain.ts +107 -0
- package/src/Lock.ts +174 -0
- package/src/Mcp.ts +159 -0
- package/src/Merge.ts +70 -0
- package/src/Migrate.ts +331 -0
- package/src/Plugins.ts +347 -0
- package/src/Postgres.ts +353 -0
- package/src/Publish.ts +64 -0
- package/src/Registry.ts +405 -0
- package/src/Remote.ts +1158 -0
- package/src/Run.ts +541 -0
- package/src/SyncGen.ts +570 -0
- package/src/Update.ts +873 -0
- package/src/bin.ts +46 -0
- package/src/index.ts +7 -0
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
# Sandbox
|
|
2
|
+
|
|
3
|
+
Running untrusted code: the handlers and views of MAKE modules, made by a person or the agent at runtime. Sandboxed code has no ambient authority. It computes with the language's built-ins and reaches the rest of the app only through the host functions its caller grants, each checked against the code's **capability profile**. This page also documents MAKE itself: the module source the sandbox runs, its lifecycle (draft, preview, approve, install, version, roll back), and the view runtime.
|
|
4
|
+
|
|
5
|
+
- Kind: kernel service. Version 2.3.0 (1.1.0: `CapabilityProfile.subscribe`, subscribers delivered, the view call's `key`, the MAKE RPCs; 1.2.0: a view's `slots`, and `make.slots`; 2.0.0: a view is code, not markup (`MakeCodeView`: an ES module run in the sandbox whose `render(state)` returns a view tree the shell draws in a frame where nothing runs or loads, `make.renderView`); an HTML view (`MakeHtmlView`) still loads but is no longer accepted in a draft nor rendered; 2.1.0, made on two branches at once: a source may leave out `manifest.events` and the profile's `emit`, `call`, `settings` and `view` when it has none, decoded as empty (build/make-authoring), and read programs, the kernel's `data` module's `data.run` and `data.status` (build/sandbox-data); 2.2.0: both together; 2.3.0: a MAKE action may declare `title`, what people see it called, one line of at most 80 characters, never shown where a person decides on a call).
|
|
6
|
+
- Schema: [`packages/contracts/schema/contracts/Sandbox.json`](../../packages/contracts/schema/contracts/Sandbox.json) (source [`Sandbox.ts`](../../packages/contracts/src/contracts/Sandbox.ts)).
|
|
7
|
+
- Implementation: the engine in [`packages/kernel/src/sandbox/Sandbox.ts`](../../packages/kernel/src/sandbox/Sandbox.ts) (QuickJS compiled to WebAssembly: `quickjs-emscripten-core` 0.32.0 with `@jitl/quickjs-wasmfile-release-sync` 0.32.0, exact-pinned; the same build runs on Bun and Node); MAKE in [`packages/kernel/src/make/`](../../packages/kernel/src/make): the source checks (`Manifest.ts`, `Validate.ts`), the SQL guard (`SqlGuard.ts`), a call (`Execute.ts`), the runtime (`Runtime.ts`), the lifecycle (`Lifecycle.ts`, the kernel's `make` module in `module.ts`) and the HTTP route (`Http.ts`); the shell's view host in the registry's shell item ([`shell-foldkit/src/makeView.ts`](../../registry/app/shell-foldkit/src/makeView.ts)) and its MAKE screen ([`src/make.ts`](../../registry/app/shell-foldkit/src/make.ts)).
|
|
8
|
+
- Kit: `@eloxiv/testing/conformance/Sandbox` ([source](../../packages/testing/src/conformance/Sandbox.ts)).
|
|
9
|
+
|
|
10
|
+
## Operations
|
|
11
|
+
|
|
12
|
+
| Operation | Input | Output | Errors | What it does |
|
|
13
|
+
| --- | --- | --- | --- | --- |
|
|
14
|
+
| `run` | `SandboxRun`: `code` (an ES module), `entry` (an export, or a dotted path into one: `actions.add`), `args` (JSON), `capabilities` (host function names), `limits` | `SandboxResult`: `value` (JSON; `null` for `undefined`) and `usage` (`wallMs`, `steps`, `hostCalls`) | `SandboxLimitExceeded`, `SandboxCodeFailed`, `SandboxCapabilityRefused` | Evaluates the module in a fresh interpreter and calls the entry; the granted host functions are `eloxiv.<name>(...args)` |
|
|
15
|
+
| `check` | `{ code }` | `{ exports }`: export names and, for exported objects, their function members | `SandboxLimitExceeded`, `SandboxCodeFailed` | Compiles and evaluates the module with nothing granted |
|
|
16
|
+
|
|
17
|
+
The kernel's engine (`runSandboxed`, `checkSandboxed`, the `Sandbox` service) runs each interpreter **off the kernel's event loop**, in a worker thread of a small pool ([`worker.ts`](../../packages/kernel/src/sandbox/worker.ts)): each worker has its own stack and, on Node, its own heap limits (`resourceLimits`; Bun does not enforce them, so there the host-call caps below are what bound a worker's heap), and a wall-clock kill (a run still going a second past its deadline has its worker terminated). A worker is discarded after any run that does not succeed and replaced as needed. The caller's host functions are Effects (run in the kernel) that answer JSON, refuse with `SandboxCapabilityRefused`, or fail with the caller's own error.
|
|
18
|
+
|
|
19
|
+
## Records and limits
|
|
20
|
+
|
|
21
|
+
- **`SandboxLimits`** (each a ceiling the run is stopped at): `timeMs` (wall time of the whole run, host calls included; default 2 s, at most 10 s), `memoryBytes` (the interpreter's heap; 16 MiB, at most 64 MiB: each run's interpreter is its own WebAssembly instance whose memory cannot grow past the build's 16 MiB base plus this, since QuickJS's own accounting cannot see allocation sizes under WebAssembly and once let a 2 MiB run reach 600 MiB of 4 KiB strings), `stackBytes` (256 KiB, also the ceiling: a deeper interpreter stack can overflow Node's own under WebAssembly), `steps` (the interpreter's interrupt checks, about one per few thousand bytecode operations, which bound computation whatever the clock does; 20 000, at most 200 000), `hostCalls` (200, at most 1 000), `outputBytes` (the JSON of the arguments, the result and each host call's arguments and answer, in UTF-8 bytes; 1 MiB, at most 4 MiB). `SANDBOX_DEFAULT_LIMITS` and `SANDBOX_MAX_LIMITS` publish them.
|
|
22
|
+
- **`SandboxLimitExceeded`** `{ limit: time | memory | stack | steps | hostCalls | output, message }`; **`SandboxCodeFailed`** `{ message }` (does not compile, threw, rejected, no such entry, never settled, a result that is not JSON); **`SandboxCapabilityRefused`** `{ capability, message }`; **`SandboxBusy`** `{ message }` (every interpreter stayed busy as long as the run could wait).
|
|
23
|
+
|
|
24
|
+
## Guarantees
|
|
25
|
+
|
|
26
|
+
1. **No ambient authority.** The interpreter has the ECMAScript built-ins and nothing else: no `fetch`, `XMLHttpRequest`, `WebSocket`, timers, `require`, `process`, file system or module loader (an `import` cannot resolve), and the native bridge is removed from the global object before the code runs. Its only way out is the frozen `eloxiv` object, whose functions are exactly the granted ones.
|
|
27
|
+
2. **Values cross only as JSON**, parsed on the other side, so no object of either side is shared; prototype pollution and globals stay in the run.
|
|
28
|
+
3. **Every run is fresh**: its runtime and context are created for it and disposed after it, so nothing passes between calls or callers.
|
|
29
|
+
4. **Every limit stops the run** at the first one reached, including a host call that outlives the time limit and code that awaits something that never settles.
|
|
30
|
+
5. **A refusal fails the run, even if the code caught it.** The first refusal (or caller error) of any host call is the run's outcome; nothing the code does afterwards turns it into a success. So does a run that returns while host calls it made still wait: none of them runs.
|
|
31
|
+
6. **A hostile run stops only itself, and never blocks its host.** Host calls are refused where the code makes them, before anything of them reaches the host, when the function was not granted, when more than 16 would wait, when their bytes would pass `outputBytes`, or when their arguments nest deeper than 64. Deep native recursion (`JSON.parse`, `JSON.stringify`, regular expressions), memory exhaustion and anything else that stops the interpreter end only that run, whose worker is replaced; the next run is unaffected, and the host answers throughout.
|
|
32
|
+
|
|
33
|
+
## Read programs (the kernel's `data` module)
|
|
34
|
+
|
|
35
|
+
A person, or their agent, runs JavaScript of their own in the sandbox to orchestrate reads: call module actions, read providers over their Connections, and keep what they found as bounded datasets to query again later. Install `dataModule` in `KernelApp.modules`; its actions are on every surface through the one invocation path, each audited. Implementation: [`data/Programs.ts`](../../packages/kernel/src/data/Programs.ts) and [`data/module.ts`](../../packages/kernel/src/data/module.ts); schemas in [`Data.ts`](../../packages/contracts/src/Data.ts).
|
|
36
|
+
|
|
37
|
+
| Operation | Input | Output | What it does |
|
|
38
|
+
| --- | --- | --- | --- |
|
|
39
|
+
| `runProgram`: `data.run` | `RunProgram`: `code` (an ES module, at most 64 KiB), `entry` (default `main`), `input` (JSON), `actions` (the read actions granted), `connections` (the person's Connections granted), `background` | `ProgramRun`: `runId`, `status` (`running`, `succeeded`, `failed`, `lost`), `value`, `error`, `usage`, `startedAt`, `finishedAt` | Runs the program under the sandbox's default limits with only these host functions: `eloxiv.read(action, input)`, `eloxiv.fetch(connectionId, request)`, `eloxiv.stage(name, rows)`, `eloxiv.staged(name)` and `eloxiv.query(name, sql)`. In the call, it answers when the program ends; in the background it answers `running` at once |
|
|
40
|
+
| `programStatus`: `data.status` | `{ runId }` | `ProgramRun` | How one of the caller's runs stands (a background run still `running` a minute after it started, cut off by a restart, is `lost`) |
|
|
41
|
+
|
|
42
|
+
- **Granted reads only, within what its caller may call.** `eloxiv.read` calls an action the run was granted, and its caller's scope covers (an agent limited to some tools grants a program none beyond them: the agent runtime writes a run's tools into the scope its calls act under), that is a module's (never a kernel module's: governance, consent, MAKE, `data` itself), read-only, and needs no consent; it runs through the invocation path as the person, under the authority of the call that started the run (bound with `bindDeferred`, never its session) and with its provenance, policy and audit as any call. `eloxiv.fetch` reads over one of the granted Connections (when the caller's scope covers `connections.apiRead`) with `connections.apiRead` as the person (their own Connection, `GET` or a reading `POST`, at most 5 pages). Anything else is refused, and a refusal fails the run (guarantee 5 above).
|
|
43
|
+
- **Reusable staged results.** `eloxiv.stage`, `eloxiv.staged` and `eloxiv.query` are the person's staged datasets ([Ingestion, "Staged datasets"](ingestion.md#staged-datasets)), so a later run, `data.query` or the person's agent reads what an earlier run kept without asking the provider again. In the call, stages commit with the call; in the background, each operation runs under the run's recorded authority, asserted in a transaction of its own and confirmed at its commit (`Authority.within`), so once a link no longer holds (a revoked token or agent session, a member removed) the program reads and stages nothing more. A query's result is measured in Postgres as it streams and refused past its limits before the kernel holds it.
|
|
44
|
+
- **Status.** Every run is recorded (`eloxiv.data_run`, migration `0160_sandbox_data`: status, value of at most 256 KiB, error, usage), for its person only, and kept a week.
|
|
45
|
+
- **Quotas.** At most `RUNS_PER_HOUR` (60) runs an hour per person and organisation, and `BACKGROUND_RUNS` (3) in the background at once, counted under the person's lock; past either, `Forbidden`.
|
|
46
|
+
|
|
47
|
+
## MAKE
|
|
48
|
+
|
|
49
|
+
A MAKE module uses **the same manifest as built-in modules**, in its language-neutral JSON form (what `moduleToJson` publishes), plus a capability profile, a sandbox and a lifecycle.
|
|
50
|
+
|
|
51
|
+
### The module source (`MakeModuleSource`)
|
|
52
|
+
|
|
53
|
+
- **`manifest`** (`MakeManifest`): `name` (`mk_<name>`: the module, its schema and its roles; unique in the app), `version` (semver), `cedarNamespace`, `entities` (each with `cedarType`, `table` `<module>.<table>`, `primaryKey`, `columns`, `policyAttributes`, `row` as JSON Schema, and optional `storage`: each field's column declaration as the JSON manifest form publishes an entity's, `{ column, type, nullable, sqlType }`, a field left out being `text`, `boolean`, `bigint`, `double precision` or `jsonb` by its row type and nullable unless required; setup holds the database to these declarations as it holds a built-in module to its Drizzle tables (decision 9), and a MAKE entity is never synced); and, for the Privacy contract, `dataSubjects` by entity name in the JSON manifest form (`{ fields, erase: delete | anonymise with `set` | retain with a `reason`, export?, notPersonal? }` or `{ none: reason, notPersonal? }`), checked as a built-in module's and required for every entity when the privacy module is installed, with every string, JSON or user-typed field (but the primary key and the organisation) classified in `fields` or `notPersonal`; data-subject requests export and erase those records with the kernel's statements run as the module's runtime role ([privacy.md](privacy.md#requests)), `actions` (by name `<module>.<action>`: `title` (one line, at most 80 characters; the module's own, untrusted words: where a person decides on a call, in consent and approval requests and their work items, notifications, push and email, the kernel shows its label of the action's id instead, the module first and never cut, `mk_todos: Urgent`, never the authored title, and every client computes it from the id for stored requests and events too), `description`, `writes`, `target`, `actsOn`, `organisationWide`, `bestEffort`, `hints`, `consent`, and `input`/`output` as JSON Schema) and `events` (`<module>.<event>`: `payload`).
|
|
54
|
+
- **`policy`**: the module's Cedar policy, in its own namespace.
|
|
55
|
+
- **`capabilities`** (`CapabilityProfile`): `sql.read` and `sql.write` (its own entities), `emit` (its own events), `call` (other app or MAKE modules' **read-only** actions that need no consent; never a kernel module's), `settings` (settings it reads), `view` (its own actions its view may ask for), `subscribe` (other modules' events its subscribers may handle: app modules', or MAKE modules' of its own organisation, never a kernel module's; optional, its own events need no listing), and optional `limits` within the kernel's ceilings.
|
|
56
|
+
- **`migrations`**: `{ name, sql }` in order (statements separated by `--> statement-breakpoint`).
|
|
57
|
+
- **`code`**: an ES module exporting `actions`, one async function per action: `async add(input, ctx)`, where `ctx` is `{ actor: { userId, orgId }, origin, invocationId }` (`origin`: `person`, `agent` or `system`, as the invocation path decided), and the host functions are `eloxiv.sql(text, params)`, `eloxiv.emit(type, payload)`, `eloxiv.call(action, input)` and `eloxiv.setting(key)`, each present only if the profile grants it.
|
|
58
|
+
- **`view`** (optional): `{ title, code, slots? }`, an ES module that runs in the sandbox and returns a view tree, drawn only by the view runtime below. A view written as HTML (`{ title, html }`, before views were code) is refused in a draft; one installed before still loads but no longer renders.
|
|
59
|
+
- **`sample`** (optional): rows per entity for the preview.
|
|
60
|
+
- **`subscribers`** (optional, at most 20): `{ id: <module>.<id>, event, entry: subscribers.<name> }`, each handling one of the module's own events or one its profile lists in `subscribe`. The code exports `subscribers`, one async function per entry: `async onAdded(payload, ctx)`, where `ctx` is `{ eventId, event, module, orgId, invocationId, attempt, origin: "system" }` (`attempt` counts its earlier failed attempts at this event). See [Subscribers](#subscribers).
|
|
61
|
+
|
|
62
|
+
### Checks at install
|
|
63
|
+
|
|
64
|
+
A source is checked twice: when it is drafted and again when its install runs (against what is installed then). Everything below is refused with the problem named:
|
|
65
|
+
|
|
66
|
+
- **The kernel's own checks of every module**, run unchanged on the module the source builds (the same `ModuleContract` and `KernelModule` a built-in module has): the manifests together with the app's (`manifestProblems`: names, namespaces, declarations), schemas and names (`moduleSchemaProblems`), durable ids, Cedar's strict validation, the policy scope rule (no action may reach records not tied to the actor), and the permissions a policy tests. A MAKE module's policy is validated, scoped and compiled **alone**: nothing it says can reach another module.
|
|
67
|
+
- **What only MAKE needs**: the `mk_` name and an entity table in the module's own schema; policy attributes are columns of Cedar primitives or of `Eloxiv::User`, `Eloxiv::Org` and `Eloxiv::Group` (never another module's records, never sharing sets); JSON Schemas import without patterns (an untrusted regular expression would run in the kernel's process); no table is named `pg_*`; the profile names only the module's own entities, events and actions, read-only actions of other installed app or MAKE modules that need no consent (a kernel module's action, such as `approvals.approve`, `make.install`, `consent.approve` or `sharing.grant`, is refused: the module's code would act on it as whoever calls the module, a confused deputy), declared settings, and limits within the ceilings; every event `subscribe` names is another installed app module's, or a MAKE module's of the same organisation (a kernel module's event, such as `approvals.requested`, is refused: it is the kernel's own business, and its payload is not the module's to read); every subscriber is named for the module, handles one of its own events or one `subscribe` lists, and has an entry `subscribers.<name>`; every action's key (after `<module>.`) is an identifier; the code loads in the sandbox and exports `actions.<name>` for every action and every subscriber's entry. A rollback runs the same checks of the earlier version against what is installed then. **A MAKE module is checked with the app's modules and its own organisation's MAKE modules only** (its agent and MCP tool names are resolved per caller's organisation), so another organisation's module never refuses it and its problems never name one; what is global, a module's name (its schema and roles) and its Cedar namespace, is refused as "unavailable", naming nothing else.
|
|
68
|
+
- **Migrations are additive and rollback-safe**, checked with PostgreSQL's grammar: only `CREATE TABLE`, `ALTER TABLE ... ADD COLUMN` and `CREATE [UNIQUE] INDEX` (columns only, btree) in the module's schema, with column types from an allowlist, constraints `NOT NULL`, `DEFAULT`, `CHECK`, `PRIMARY KEY`, `UNIQUE` and foreign keys within the schema with `NO ACTION`/`RESTRICT`; defaults built from constants, operators and `now()`/`gen_random_uuid()`; checks from constants and operators only (no function and no clock: a check that holds today and not tomorrow would make every later write fail). An added column is nullable or has a default, is never a key, and its check reads only it (the previous version's writes do not know it). A unique index is built only on a table the same version creates (over an earlier version's rows it could fail, or refuse that version's writes after a rollback). `COMMENT` and every other statement are refused. A new version's list starts with the previous version's migrations, unchanged, and its version is greater.
|
|
69
|
+
|
|
70
|
+
### A call
|
|
71
|
+
|
|
72
|
+
Every call of a MAKE action goes through the one invocation path: identity, policy (the module's own, compiled for the actor), consent, business approval, idempotency, execution, audit and the outbox. A MAKE module serves only the organisation that installed it. Then (`Execute.ts`):
|
|
73
|
+
|
|
74
|
+
1. **Its own session.** A connection of the module's own pool, logged in as the module's runtime role (never the kernel's connection: there is no more privileged role a statement could `RESET` to), begins a transaction. The kernel records, keyed by that transaction's id and committed on its own connection (the runtime role cannot write them): the invocation context (actor, organisation, action) row-level security reads, an exact action's targets, and the call itself (`eloxiv.make_call`: its invocation, its module, and the hash of a one-time ticket only the kernel holds). The session's search path is `pg_catalog` then the module's schema; it has statement, lock and idle-in-transaction timeouts.
|
|
75
|
+
2. **Idempotency.** With a key, the call claims it in this transaction (`eloxiv_ctx.make_claim`); a key another call holds (a concurrent claim waits for it) is answered with that call's receipt.
|
|
76
|
+
3. **Targets** are locked and authorised by the action's compiled filter before the code runs.
|
|
77
|
+
4. **The code** runs in the sandbox with the host functions its profile grants. `sql` sends one statement after the SQL guard accepts it (`SqlGuard.ts`, from PostgreSQL's parse tree): exactly one `SELECT`, `INSERT`, `UPDATE` or `DELETE` with its values as parameters, reading and writing only the entity tables the profile names, every node of an allowlisted kind, every function an allowlisted built-in, every cast to an allowlisted type, every qualified column reference a column of the module's tables (`b.to_jsonb`, functional notation for `to_jsonb(b)`, is refused); every table is then qualified with the module's schema before the statement is sent. `SET`/`RESET` (and so `RESET ROLE`, `SET ROLE`, `SET SESSION AUTHORIZATION`), `set_config`, `current_setting`, `pg_sleep`, `COPY`, `DO`, DDL, `WITH`, `SELECT ... INTO`, functions in `FROM`, session functions and names outside the module's schema are refused. **Results are capped in the database**: a statement that returns rows is wrapped so that at most 1 000 rows and `outputBytes` of their JSON come back, counted where they are produced; over either, no row is sent and the call fails. `emit` takes the module's own declared events (decoded with their schema); `call` runs another module's read-only action through the invocation path as the caller, **with the call's provenance** (its origin and agent session), in a transaction of its own (it writes nothing, so whether this call then commits changes nothing of it); `setting` reads a declared setting for the caller.
|
|
78
|
+
5. **Its output** is decoded with the action's output schema, and every row the transaction wrote (its write log, read inside the transaction through `eloxiv_ctx.transaction_writes()`) is held to the action contract exactly as a built-in handler's: only the module's entity tables, targets as declared, deletes of targets only, surviving rows satisfying the policy for the new row; an action hinted read-only writes nothing.
|
|
79
|
+
6. **One commit.** The kernel's records of the call (its receipt, its `succeeded` audit record, its events) are written in the same transaction by `eloxiv_ctx.make_finish`, which runs as the kernel role, only for the transaction's own call and with its ticket, taking the actor, organisation and action from the kernel's context row (never from its arguments) and refusing events of other modules' types; the receipt it commits names, by reference, every outbox row of the invocation (the events written just before it, and any the kernel published for the call), as an ordinary call's receipt does; then the transaction commits once. So the module's writes never commit without the kernel's audit record and events, nor the reverse; no prepared transaction, superuser or `max_prepared_transactions` is involved (Neon's default of 0 works). A commit whose answer was lost is decided by the database (`pg_xact_status` of the call's transaction). The functions are executable only by MAKE modules' runtime roles, and a session without the call's ticket gets nothing from them.
|
|
80
|
+
|
|
81
|
+
Anything else that goes wrong while the code runs is the call's failure (`ActionFailed`, with the invocation's reference), logged, and never answered with a kernel stack trace.
|
|
82
|
+
|
|
83
|
+
**Load.** No kernel transaction is open while a call runs: the kernel's connections are taken for single statements (the context and call records, a setting read in a transaction of its own), and an agent run's cancellation guard holds one from just before the commit until it is answered. A call holds one interpreter and one connection of its module's pool. Before it takes any of them it is admitted (`MAKE_CALL_LIMITS` in [`Runtime.ts`](../../packages/kernel/src/make/Runtime.ts)): one call per interpreter at once in a kernel process, an organisation at most half of them while another organisation's calls wait (alone, all of them), waiting calls admitted in turn across organisations, a wait of at most 10 s behind at most 32 others of the organisation, past which the call is refused as busy (`ActionFailed`), and at most 120 calls a minute per person and module (per process). A MAKE module serves one organisation, so its bound is its organisation's. Waiting is bounded everywhere: the kernel's pool (30 s, `KERNEL_POOL_WAIT_MS`), a module's pool (5 s), an interpreter (10 s, `SANDBOX_WAIT_MS`; `SandboxBusy` past it). A nested call (a MAKE call's code calling another MAKE module's read-only action) runs within its caller's admission and only if an interpreter is free at once, so nested calls never wait on each other. Drafts, previews and view steps (`make.renderView`, which runs a view's code in the sandbox) are admitted the same way before their transaction (two at once per process, one per organisation while another waits), and their per-person rate limit is counted under a transaction-scoped lock, in every process. The kernel's records of a call that a crash left behind (context, targets, call rows of transactions no longer running) are swept at start and every five minutes.
|
|
84
|
+
|
|
85
|
+
### Subscribers
|
|
86
|
+
|
|
87
|
+
The outbox dispatcher delivers an event to every subscriber of the MAKE modules **installed in the event's organisation** that handles its type, at the version each module runs now (read on every delivery, so a rollback to a version without the subscriber, or a new version, takes effect at once), beside the built-in subscribers, triggers and kernel reactions (`MakeSubscriptions` in [`Outbox.ts`](../../packages/kernel/src/Outbox.ts), [`Subscribe.ts`](../../packages/kernel/src/make/Subscribe.ts)). A delivery runs like a call, with what a built-in subscriber has and nothing more:
|
|
88
|
+
|
|
89
|
+
1. **Its own session**, the module's runtime role, in a transaction. The kernel records, keyed by that transaction and committed on its own connection, the context row-level security reads: the system actor, the event's organisation and the subscriber branch (`$subscriber`), as for every built-in subscriber, so the module's policies let it read and write only rows of that organisation; and the delivery (`eloxiv.make_call`, with the hash of a one-time ticket, the event and the subscriber).
|
|
90
|
+
2. **The code** runs in the sandbox under the module's limits, with `eloxiv.sql` only (the tables its profile names, the SQL guard, results capped in the database). A subscriber emits no event, calls no action and reads no setting: it acts as the system, so it starts no further work of its own, and there is nothing to bind to an authority (`bindDeferred` is for deferred work a call starts; a subscriber starts none).
|
|
91
|
+
3. **Its writes** are held to the module's entity tables.
|
|
92
|
+
4. **Exactly once.** `eloxiv_ctx.make_deliver` records the delivery's success (`outbox_delivery`, as `make:<subscriber id>`: MAKE subscribers' delivery records are a namespace of their own, and no app module's subscriber may be named `mk_*` or take the `make:` form) in the module's transaction, for the event and subscriber the kernel wrote on the delivery's record, with its ticket (a call's ticket never answers it, nor a delivery's the call functions); then the transaction commits once. The module's writes and the record that the event reached the subscriber commit together, so a subscriber runs once per event, however often the dispatcher passes; a failure (the code's, a limit, a refusal) rolls everything back and the delivery is retried under the default delivery policy (backoff, at most 20 attempts, then a dead letter its organisation's administrators can retry or discard). The dispatcher claims events `FOR NO KEY UPDATE`, which the delivery record's reference to its event does not wait for.
|
|
93
|
+
|
|
94
|
+
Deliveries are admitted like calls (as the organisation's system actor).
|
|
95
|
+
|
|
96
|
+
**What a subscriber sees, and acts as, said plainly.** Once an administrator approves a module whose profile lists an event in `subscribe` (or that subscribes to its own events), its subscribers:
|
|
97
|
+
|
|
98
|
+
- act with **the organisation's system authority**, not any person's: row-level security's subscriber branch lets them read and write the module's rows of the event's organisation, whoever caused the event;
|
|
99
|
+
- receive **every such event's whole payload**, with no per-person filter: an event a person's call emitted reaches the subscriber with everything its payload holds, whether or not that person could have shown it to whoever made the module;
|
|
100
|
+
- are delivered **in no guaranteed order**: events of one type, or of one record, may reach a subscriber in another order than they were emitted, and a retried delivery after later ones;
|
|
101
|
+
- start no further work (no `emit`, `call` or `setting`).
|
|
102
|
+
|
|
103
|
+
`make.draft` answers a module with subscribers with its **subscriptions notice** (`subscriptions`: the events, and the three facts above, in one sentence); `make.install` must repeat it exactly, so the approval request the administrator decides shows it beside the hash and the profile. An install that leaves it out, or changes it, installs nothing.
|
|
104
|
+
|
|
105
|
+
**Fan-out.** At most `MAKE_SUBSCRIBERS_PER_EVENT` (20) subscribers per event type across the MAKE modules of one organisation (each module at most 20 in all), checked at draft, install and rollback, counted within the organisation only; the dispatcher delivers to no more.
|
|
106
|
+
|
|
107
|
+
**Versions change under no delivery or call.** An install, a version bump and a rollback take the module's version lock (`MAKE_VERSION_LOCK`, per module) exclusively, in their own transaction. A delivery, once admitted, holds it shared in the dispatcher's transaction and only then reads the version the module runs, its subscribers and its capability profile: a subscriber that version no longer has (or that no longer handles or may read the event) is recorded as delivered and never run, and while a change runs the attempt fails and is retried. A call holds it shared in the kernel transaction that encloses the module's and is refused (`ActionFailed`, "changed version") when a change replaced the version it looked up while it was admitted or waited; a nested call never waits for it (refused as busy). So no version's code or profile runs after a change of version has returned, and none commits after one began. A view's steps run the code of the version installed when each step runs, so a rollback changes an open view at its next step.
|
|
108
|
+
|
|
109
|
+
### The lifecycle (the kernel's `make` module)
|
|
110
|
+
|
|
111
|
+
| Action | Who | What it does |
|
|
112
|
+
| --- | --- | --- |
|
|
113
|
+
| `make.draft` `{ source }` | members (and their agent), at most 20 a minute each | Stores the source with its hash and every problem the checks find; a draft with problems is kept so the drafter can fix it in a new one. Its description (what an agent reads) leads with a worked example, a notes module that drafts, previews and installs as printed (`MAKE_EXAMPLE_SOURCE`, [`Example.ts`](../../packages/kernel/src/make/Example.ts)). A source is read as its author meant it before it is decoded ([`Repair.ts`](../../packages/kernel/src/make/Repair.ts)): given as JSON text, it is that JSON; with one closing brace misplaced, a key the source or its manifest requires but lacks (`manifest`, `policy`, `capabilities`, `migrations`, `code`; `name`, `version`, `cedarNamespace`, `entities`, `actions`) is taken from the one place it landed in, never from inside a JSON Schema, the columns, a migration, the view or the sample data. Nothing is guessed or dropped: a required key found in more than one place, or a module-level key (`policy`, `capabilities`, `migrations`, `code`, `view`, `entities`, `actions` and the rest) anywhere but its own place, is refused (`InvalidInput`) with every place named, since decoding would otherwise drop it unseen by the approver (an empty one, most often an `events: {}` past a misplaced brace, is answered "leave it out"; the example leaves out what it has none of, so there is nothing after its actions to misplace). The result is checked as any source and is what is hashed, previewed and approved. A source that still does not decode is refused (`InvalidInput`) with every problem at once, each naming its path, what was given and what belongs there, from the source schema (`["source"]["manifest"]["actions"]["x.add"] is a string: write an object with description, input, output (optional: …) there`; `… ["description"] is missing: write a string there`) |
|
|
114
|
+
| `make.preview` `{ draftId, calls }` (at least one call) | members, at most 10 a minute each | Sets the draft up in a preview database of its own (a scratch database with the kernel's schemas and the draft's module, set up exactly as an install sets it up), inserts its sample data (the organisation and the person filled in), runs the calls as the caller there (the same execution as a real call; `call` and `setting` are refused in a preview) and reports each call's output or error, the rows left and the events emitted. Only the kernel and the module's runtime role may connect to the preview's database; it is dropped afterwards, with the module's roles when the module is not installed (previews, installs and rollbacks of one module are serialised across the cluster, and every setup holds the module's role lock from creating its roles until it has used them, so a preview elsewhere never drops a role a setup has just made: `packages/testing/test/make-role-race.test.ts`). Only a draft without problems |
|
|
115
|
+
| `make.install` `{ draftId, module, version, hash, capabilities }` | members ask; **an organisation administrator approves** (the module's approval rule, never the requester), seeing the source hash and the capability profile in the request | Installs a draft with a successful preview, only if the request names the draft's own module, version, hash and capability profile, as its module's next version (its first, or a version bump with its new migrations) by running setup with it, then records the version as the one the module runs. Runs once, by the approval workflow, when approved |
|
|
116
|
+
| `make.rollback` `{ module }` | organisation administrators (an agent's call needs the person's consent) | Runs the version installed before the current one again, by setup |
|
|
117
|
+
| `make.slots` | members | The organisation's MAKE views contributed to the app's slots: each installed module's current version's `view.slots` (`{ slot, order? }`, each a slot an installed module declares with `accepts: "view"`; a draft naming another, a command slot, or a slot twice has problems), as `{ slot, module, version, title, order }` in the [Slot](slot.md) order (`order` ascending, unordered after, then installation order: when each module was first installed, kept across version bumps and rollbacks). A slot the app no longer declares is left out. `makeSlot(contributions, slot)` (`@eloxiv/client`) gives one slot's entries, its ties in the order `make.slots` answered; a shell shows each with `make.view` and `make.renderView` |
|
|
118
|
+
| `make.list`, `make.view` | members | The organisation's modules (the version each runs, every version) and drafts; a module's view (its title; none for a view written as HTML) and the actions it may call |
|
|
119
|
+
| `make.renderView` `{ module, version, state, message }` | members, admitted like drafts and previews | One step of a module's view (below): its code in the sandbox, `init()` (no message) or `update(state, message)`, then `render(state)`; answers `{ state, calls, tree }`. `version` is the one `make.view` answered: once another is installed the step is refused (`InvalidInput`), so a view's code never runs against another version's list of the actions it may call, and the shell stops the view (open it again) |
|
|
120
|
+
|
|
121
|
+
**Install is setup.** The kernel runs the same setup an app's release runs, in its own process, with the module's new version among the installed MAKE modules, so its schema, its owner and runtime roles, its migrations (on a session logged in as its owner), its hardening (row-level security generated from its own policy, privileges, the write log and the key guard) and its recorded security state are exactly a built-in module's. Every later setup of the app includes the installed MAKE modules too (read from the database) and holds them to that state. A MAKE module's runtime role logs in, with a password derived (HKDF-SHA-256) from the deployment's MAKE role key (`ELOXIV_MAKE_ROLE_KEY`, required in production; in development derived from `ELOXIV_AUTH_SECRET`) and the role's name, set by every setup as a SCRAM verifier and stored nowhere (on a host that takes only plaintext passwords, such as Neon, as the password itself: [Release, Database hosts](release.md#database-hosts)). MAKE modules are not synced to replicas. Installs and rollbacks are serialised across kernel processes.
|
|
122
|
+
|
|
123
|
+
**What install needs of the setup role.** Install, rollback and preview run setup, which uses the deployment's setup connection (`ELOXIV_ADMIN_DATABASE_URL`) for what setup always needs it for: creating and holding the module's two roles (attributes, memberships, passwords), owner sessions' one-time logins, the module's schema, privileges and row-level security, the migration lease, and (for a preview) creating and dropping a database and writing its sample rows past row-level security. All of it is behind one interface, `MakeSetup` (`install`, `preview`) in [`Lifecycle.ts`](../../packages/kernel/src/make/Lifecycle.ts), built in `Server.ts`. The setup role need not be a superuser: on a managed host (Neon's `neondb_owner`, with `CREATEROLE`, `CREATEDB` and `BYPASSRLS`) setup works as [Release, Database hosts](release.md#database-hosts) describes, and MAKE's install, rollback and preview with it (`make-lifecycle.test.ts` runs on the emulation of Neon's privilege model in CI; the catalogue functions Neon leaves to PUBLIC are refused by MAKE's guard and migration rules, `managed-postgres.test.ts`). Calls of installed modules need none of it.
|
|
124
|
+
|
|
125
|
+
**Versions and rollback.** Versions are additive (above), so a rollback restores the previous version's code, policy and capability profile **over the same schema**: no down-migration runs and no data is lost. The columns the newer version added stay (nullable or defaulted, so the older code's writes succeed); the tables it added stay with their rows, but no entity of the older version governs them, so its runtime role has no policy on them and reaches nothing in them (the guard refuses them too). Its migrations stay recorded. Installing the newer version again (the same content, or a later version) finds them as they were. A version number, once installed, keeps its content.
|
|
126
|
+
|
|
127
|
+
### The view runtime
|
|
128
|
+
|
|
129
|
+
A MAKE view is untrusted code, and it never runs in the browser (decisions: "No iframes, except sandboxed MAKE views"; MAKE's sandbox is QuickJS-WASM). Threat SB-7 (a view sending out what its actions return by navigating its own frame) is closed by keeping the code out of the frame altogether:
|
|
130
|
+
|
|
131
|
+
- **The code runs in the sandbox.** `make.renderView` (members of the installing organisation) runs the view's ES module in a fresh interpreter with nothing granted: no host function (no SQL, events, calls or settings), and the sandbox has no DOM, network, timers or modules. A step runs `init()` (the first, with no message) or `update(state, message)`, then `render(state)` (`ViewStep.ts`). `init` and `update` return `{ state?, calls? }`: the view's next state (JSON, kept by the shell and passed back with the next step) and the calls of its module's own actions it asks for (`{ id, action, input, key? }`). `message` is an event of its tree (`{ type: "event", name, data?, value?, fields }`) or a call's result (`{ type: "result", id, ok, result | error }`). Everything it returns is decoded against the contract (`MakeViewStep`, with a property or key the contract does not name refused, never dropped) and held to at most 5,000 nodes 64 deep; anything else fails the step.
|
|
132
|
+
- **What reaches the browser is a tree.** A node is text (a string or number), nothing (`null`, `false`), or `{ tag, props?, children?, on?, data? }`, with `tag` one of `MAKE_VIEW_TAGS` (text and layout elements, tables, `label`, `form`, `button`, `link`, `input`, `textarea`, `select`, `option`) and `props` among `MAKE_VIEW_PROPS` (`class`, `title`, `style`, `placeholder`, `value`, `checked`, `selected`, `disabled`, `name`, `type`, `min`, `max`, `step`, `rows`, `colspan`, `rowspan`, `ariaLabel`): none names a URL.
|
|
133
|
+
- **The shell draws it where nothing runs and nothing loads** (`mountMakeView`, `shell-foldkit` 0.4.0): an iframe sandboxed with `allow-same-origin` only (`MAKE_VIEW_SANDBOX`: no scripts, forms, popups or navigation of the shell; `allow-same-origin` lets the host, never the frame, draw into the frame's document and read its fields), under the view CSP (`MAKE_VIEW_CSP`, as the document's `<meta>` and the iframe's `csp` attribute): no script, image, media, font, frame, object, connection, form submission or base URL; inline style only. The host draws only the tree's elements and properties, text as text nodes, an input's `type` among `MAKE_VIEW_INPUT_TYPES` (never `file`, `image`, `submit` or `reset`), `style` held to a few CSS properties with plain values (no `url()`, escapes or quotes) of at most 200 characters each (4,000 in all), read in one linear pass, a `form` as a group of fields that is never submitted.
|
|
134
|
+
- **Controls are the host's.** A `button` or `link` with `on` is a link to a fragment of the frame's own document (`about:srcdoc#e-<n>`, the host's own counter, never the view's text): activating it (a click, or Enter) is a same-document fragment change that sends nothing anywhere; the host reads the frame's fragment from its own side, resets it, and sends the view's `update` the event with its `data` and the values of the named fields of its form (or the whole view outside one). A field with `on` is reported when its value changes, with `value`. The host registers no listener in the frame: an engine with scripts off in a frame runs none there (WebKit, the desktop hosts' engine).
|
|
135
|
+
- **Calls are the shell's.** The host makes a call the view asks for only for an action its capability profile lists (`capabilities.view`, from `make.view`), as the signed-in person through the invocation path (the kernel authorises it like any call), under an idempotency key, and refuses any other without a request (the view's `update` gets a `Forbidden` result). **`key`** (1 to 128 URL-safe characters, `MAKE_VIEW_KEY`) is the view's own, the same on every retry of one request and **unique per call** (two calls that reuse a key with the same action and input share one receipt): a retry after a lost answer is answered with the first call's result. The host namespaces it by the mount (`make-view:<instance>:<key>`, the instance new each time it mounts the view), so two tabs or two mounts never share a receipt; a call without one gets a fresh key. **A view key is an idempotency key, not authority.** Each result goes back to the view's `update` through the kernel, never to code in the browser.
|
|
136
|
+
|
|
137
|
+
So nothing of a view's runs in the browser, and nothing in its frame can navigate it or load a URL: what its listed actions return can reach only the person's own screen.
|
|
138
|
+
|
|
139
|
+
The shell item provides the host (`mountMakeView`) and the MAKE screen at `/make/<module>`: a Foldkit Submodel whose Command reads `make.view` as the signed-in session in the selected organisation, and nothing else; its Mount runs `mountMakeView` on the screen's container for that element's lifetime (the view's steps through `make.renderView`, its calls as the session in that organisation), so the frame goes when the screen is discarded (another route, organisation or session); a view that fails is reported to the screen. **Opening a view runs only its `init`**, in the sandbox; the calls it asks for there are its own, made like any other. The session is a handle into the shell's credentials; the token is read only when a request is made.
|
|
140
|
+
|
|
141
|
+
### Native hosts
|
|
142
|
+
|
|
143
|
+
A native host draws the same tree with its own controls, with no web engine at all; the registry's Rune host is one ([`desktop-rune`](../registry/desktop-rune.md), [`app/src/make/`](../../registry/app/desktop-rune/app/src/make)). The view's code runs where it always does, in the kernel's sandbox (`make.renderView`, reached through the daemon's LocalClient `actions` route as the signed-in person in the selected organisation), and the contract is the one above: the tree decoded against `MakeViewStep` (its types generated from the code generation bundle [`codegen/Sandbox.json`](../../packages/contracts/schema/codegen/Sandbox.json), which names the tree's node, element, props and calls: `MakeViewNode`, `MakeViewElement`, `MakeViewProps`, `MakeViewPropValue`, `MakeViewCall`) and held to 5,000 nodes and 64 levels, steps one at a time from the state the last one returned, calls only of the actions `make.view` listed (any other answered `Forbidden` with no request) under `make-view:<mount>:<key>`, the messages `{ type: "event", name, data?, value?, fields }` and `{ type: "result", id, ok, result | error }`, fields collected by name from the control's nearest `form` or the whole view exactly as the web host collects them, and every answer for a view that is gone dropped. The closed vocabulary is what makes this safe without a frame: no element or prop names a URL, so the host has nothing to load or open, and it executes nothing.
|
|
144
|
+
|
|
145
|
+
What a native host draws differently, by design (the Rune host's scope, in its README):
|
|
146
|
+
|
|
147
|
+
- **`style`**: the web host's filter first, then only a documented subset is drawn (colours, font weight, style and size, text alignment, margins and padding, one border width, colour and radius, `display: flex` with direction, gap and alignment, sizes in `px`, `rem`, `em` or `100%`, opacity); `calc()` and the other functions, other percentages and the remaining properties are ignored. `class` is inert, as on the web.
|
|
148
|
+
- **Tables** are rows of equal-width cells: `colspan` and `rowspan` are ignored.
|
|
149
|
+
- **Inputs**: `date`, `time`, `datetime-local` and `color` are text fields; `number` keeps to a number's characters; `select` is an inline list box whose option values are their text (as the web host draws them).
|
|
150
|
+
- **Layout** is a column of blocks with paragraphs of text-level runs, not CSS's inline formatting: inline controls sit on their own lines.
|
|
151
|
+
|
|
152
|
+
## How an implementation is checked
|
|
153
|
+
|
|
154
|
+
Read programs are proven in [`registry/test/data-programs.test.ts`](../../registry/test/data-programs.test.ts), on Bun and Node, against a records protocol fake: only granted read actions (not an ungranted one, a write or a kernel module's, even caught); only the person's own granted Connections; staged results reused by a later run in the background without reading the provider again, with a status no other person or organisation reads; the hourly and background quotas, per person; a sub-agent limited to `data_run` granting a program nothing beyond it; a background program reading and staging nothing more once its person leaves the organisation; and a query result too large refused in Postgres before the kernel holds it.
|
|
155
|
+
|
|
156
|
+
`sandboxConformance(subject)` registers, with a subject that runs code with kit-written host functions: an entry called with JSON arguments reaching only the granted functions; no `fetch`, `XMLHttpRequest`, `WebSocket`, `setTimeout`, `setInterval`, `require`, `process`, `Bun`, `Deno`, native bridge or host globals; static and dynamic imports, the network, the file system, the process and timers unreachable; an ungranted host function absent and the `eloxiv` object frozen; a caught refusal still failing the run; each limit (time for busy loops and slow host calls, steps, memory, stack, host calls, output and host arguments); nothing shared between runs or with the host; only JSON passed out; throws, rejections and missing entries reported; and `check`. The Eloxiv kernel runs it in `packages/testing/test/sandbox.test.ts`.
|
|
157
|
+
|
|
158
|
+
MAKE is proven against the kernel in:
|
|
159
|
+
|
|
160
|
+
- `packages/testing/src/conformance/Sandbox.ts` also proves a hostile run stops only itself: deep `JSON.parse`, `JSON.stringify`, regular expressions and host-call arguments fail that run and the next one runs, 25 hostile runs leave the engine healthy, queued unawaited host calls are refused where they are made, a run returning with calls still waiting runs none of them, redefining promises does not break the result, and the host's timers keep running (no stall over 250 ms) while code loops.
|
|
161
|
+
- `make-sandbox.test.ts`: a hostile module whose action tries 28 ways out (`RESET ROLE`, `SET ROLE`, `SET LOCAL ROLE`, `SET SESSION AUTHORIZATION`, `set_config` plain and qualified, `current_setting`, `CURRENT_USER`, another module's, the kernel's, Better Auth's and the catalogue's tables, forging the invocation context, file reads, `pg_sleep`, `dblink`, two statements, a data-modifying CTE, `COPY`, `DO`, DDL, a `regclass` cast, a function in `FROM`, a write its profile does not grant, a foreign event, an action outside its profile, a governance action) and each is `Forbidden`; a read-only action that writes is `Forbidden`; a call of another module's read-only action runs as the caller with the call's provenance (`person` over HTTP, `agent` from the agent); the kernel's health route answers within 750 ms throughout a busy loop, deep host-call arguments, a 40 MB result and a result past the row limit, each of which fails without a stack trace; 15 drafts whose code crashes the interpreter leave later calls working; rows of another organisation or person refused by row-level security; settings, the network and an endless loop fail the call; a caught refusal followed by a write commits nothing; another organisation cannot call it; refusals are audited; and a session logged in directly as its runtime role is that role after `RESET ROLE`, cannot `SET ROLE` or `set_config('role', ...)`, reaches no other module's, kernel's or Better Auth's table, cannot write the invocation context or run DDL or `TRUNCATE`, and sees none of its own rows without a context the kernel wrote. Its receipts (ledger C-004): a keyed call that emits an event commits a receipt naming that outbox row by reference (never its payload), and a replay returns exactly that receipt; a call that fails after emitting leaves neither event nor receipt.
|
|
162
|
+
- `make-lifecycle.test.ts`: the agent (scripted model) drafts, previews and asks to install a module, every step audited as the agent's; the requester cannot approve; an administrator's approval installs it once with its own schema and roles, hardened; its actions run with policy, targets, events, idempotent replays and audit, for its organisation only; the agent uses them as tools; its view runs in the sandbox (`make.renderView`: `init`'s tree and calls, a result through `update` into the tree), no view document is served, and a draft with an HTML view is refused; its agent tool descriptions are marked as the module's untrusted text, shortened and flattened; a version bump runs its migrations and new code; only an administrator rolls back, and the previous version runs over the same schema with the newer one's column and rows kept and its table closed; installing the newer version again finds them; drafts with problems or without a preview are not installed; a preview must call something; an install that names other capabilities or another hash than its draft's does not install, and the approval request shows the hash and the profile; drafts are rate limited; another organisation cannot take the name; and one commit: no prepared transactions (`max_prepared_transactions` is 0), concurrent retries with one key run once (one row, one receipt, one success record, three replays), a failed call leaves no row, receipt or success record, and a session logged in as the runtime role cannot call `make_finish` or `make_claim` without the ticket nor write the audit log or the outbox.
|
|
163
|
+
- `make-authoring.test.ts`: the worked example in `make.draft`'s description drafts, previews and installs as printed, and its policy keeps one member's notes from another; a source with one closing brace misplaced, or given as JSON text, drafts as the same source (its hash); a key in two places (a permit in one action and a forbid in another, no policy at the top) or left where it is not read is refused, every place named, and nothing is drafted; one missing what cannot be found is refused with every problem at once; a value of the wrong kind or a missing key is refused with its path, what was given and what belongs there (never a bare `Expected object` or `Missing key`, backlog 50); a source leaving out its events and its empty profile lists drafts and installs with them empty. `registry/test/make-real-model.test.ts` (the `model live` workflow's `make-live` job, Bun and Node) is the same lifecycle authored from a task on a real model.
|
|
164
|
+
- `make-manifest.test.ts`: the source checks (each refusal above) and the SQL guard's verdicts, without a database.
|
|
165
|
+
- `packages/kernel/test/sandbox-gc.test.ts`, driving the interpreter thread directly with the pool's worker limits and reading its output: 30 ways a run ends (results, host calls, refusals, failures, every limit and interrupt, checks) each free their runtime with nothing alive (no QuickJS assertion in the thread's output) and the thread keeps serving; deep `JSON.parse`, `JSON.stringify` and host-call arguments, under the pool's limits and a 2 MiB thread stack, are each the run's stack limit, never abort, and the next run works (through the pool too, on Bun and Node alike); 13 ways the code's own JavaScript runs while the host reads what it threw or returned (getters, `toString`, `valueOf`, `Symbol.toPrimitive`, `toJSON`, Proxy traps; at the top level, from the entry, in a check) never abort either; a 2 MiB run of 4 KiB strings stops at its memory limit within 18 MiB; collected and idle after a 48 MiB run, the thread retains less than 16 MiB more than before it; output, host-call arguments, the kernel's arguments and host answers are counted in UTF-8 bytes; and one thread over 2,380 runs keeps each within its cap, its memory within 256 MiB of its warm-up peak, and, idle after a last 48 MiB run, retains nothing of them.
|
|
166
|
+
- `make-subscribers.test.ts`: a subscriber handles its own event exactly once (a failed first attempt rolled back and retried, further passes running it no more, one delivery record), under the module's limits (a busy loop stopped) with `sql` only (no `emit`); another module's event its profile lists reaches it, and a rollback to a version without that subscriber stops it at once; a draft whose subscriber handles an event its profile does not list, a kernel module's event, or another organisation's module's event is refused.
|
|
167
|
+
- `registry/test/make-real-model.test.ts` (with `ELOXIV_MODEL_OPENAI_API_KEY` and `ELOXIV_MODEL_LIVE=1`, in the `model live` workflow; up to three attempts, each a fresh module, under 300k tokens and 25 steps a run): the whole lifecycle on a real model, the model writing the module from a task: the agent drafts, previews and asks to install; an administrator approves; the agent uses the action; a version bump; a rollback; a draft naming a kernel module's action refused, and its install too.
|
|
168
|
+
- `make-surfaces.test.ts`: MAKE actions on MCP's `tools/list` and the typed RPC client's `make.actions()` for the organisation's members, with descriptions marked untrusted (flattened), to no other organisation, and to a token scoped to them but not to one scoped to other actions; calls through the invocation path (a scoped token refused, an agent's call of a consent action held for consent, a non-MAKE action refused on `$make.call`); a rollback takes the newer version's actions out of both listings at once.
|
|
169
|
+
- `make-load.test.ts`: 50 concurrent calls across two organisations while a third organisation's built-in calls answer within 3 s, every MAKE call answered (served, or refused as busy), both organisations served, no connection left idle in a transaction, the per-person call limit, concurrent drafts answered promptly within the person's limit while built-in calls stay prompt, the sweep of a crashed call's records, and a clean shutdown; `gate.test.ts`: the admission gate's turns across keys, its bounded wait and queue, an interrupted waiter, and the sandbox refusing at once a run that may not wait.
|
|
170
|
+
- `packages/testing/test/make-view-step.test.ts`: a view's step in the sandbox: `init`, then `update` with a call's result and with an event, the tree drawn each time; no `fetch`, `XMLHttpRequest`, `WebSocket`, `location`, `document`, `navigator`, timers or host function; a tree with another element (`script`, `img`, `iframe`), a URL property (`href`, `src`, `action`), an event handler property or too many nodes refused.
|
|
171
|
+
- `e2e/make-view.spec.ts` (threat SB-7): the shell's view host in Chromium: the frame sandboxed without scripts or forms, under the view CSP; a button clicked, a link activated by Enter, a form's fields and a watched checkbox each reaching the view, what the person typed kept across redraws, no script in the frame; **a tree that puts what the view's listed action returned into every URL-bearing element and property** (images, scripts, frames, meta refresh, links, forms, image and submit inputs, CSS `url()` plain and escaped, `cursor` and `list-style` URLs, event handler properties, markup in text), with every control activated and Enter pressed in every field, **sends not one request to the attacker's server**, never moves the frame or the page, and leaves no such element, no URL but the host's own fragments and no `url()` in the frame; elements put into the frame behind the host's back (an image, a CSS URL, a script, a frame) load and run nothing either; only listed actions are called (an unlisted one answered `Forbidden` without a request), under the view's keys within its mount. In the shell itself (`/make/<module>`): the frame is sandboxed under the view CSP, the view's steps run through `make.renderView` and its listed action is called as the signed-in person in the selected organisation (the unlisted one making no request), another organisation opens the view afresh (the old frame is gone), and leaving the route removes it. `registry/test/shell-foldkit-slots.test.ts` holds the MAKE screen's Story and Scene tests (the Command's arguments carry a session handle, never a token; stale results dropped; the Mount released when the frame closes), and `registry/test/shell-foldkit-isolation.test.ts` proves opening a view reads `make.view` only (a destructive action listed first is never called).
|
|
172
|
+
|
|
173
|
+
## Not yet guaranteed
|
|
174
|
+
|
|
175
|
+
- **MAKE modules have no jobs, workflows, ingress sources, query views, skills, settings of their own or sync**; their subscribers have `sql` only.
|
|
176
|
+
- **Names**: `mk_` is MAKE's: no app module may be named `mk_*` (setup refuses it), so the surfaces tell a MAKE action from an app's by its name: MCP's tools (`<module>-<key>`, and the authentication gate audits a refused tool call by its action's canonical name, `<module>.<key>`, as every surface does), the RPC and HTTP routes for MAKE actions, and the CLI (`eloxiv call mk_<module>.<action>` goes to `/make/actions`, audited as `cli`).
|
|
177
|
+
- **Agent tool groups**: every MAKE action is in the group `make-modules` (`MAKE_MODULES_TOOL_GROUP`) and its module's own (`mk_<name>`); `KernelApp.agentTools.disabledGroups` may name either (a module's before it is made), closing those actions to agents on every surface, as for the app's groups.
|
|
178
|
+
- **Surfaces**: MAKE actions are served on HTTP (`/make/actions/*`), to the agent, on MCP (tools named `<module>-<key>`, each one action's and so one organisation's, registered as modules are installed, listed and called by `Invocation.reach` and the invocation path; refusals encoded through `InvocationError`, message included), on the typed RPC client (`$make.actions` lists the ones the caller reaches, `$make.call` calls one; the client's `make.actions()` and `make.call()`), and through the client SDK's `makeModuleClient`; not yet in the OpenAPI document.
|
|
179
|
+
- **The preview's directory**: a preview database holds the organisation but not its members, roles or groups, so policies that test them see none there.
|
|
180
|
+
- **One organisation per module name**: MAKE modules are installed for the organisation that made them; another organisation must choose another name.
|
|
181
|
+
- **Install runs setup in the kernel's process** with the deployment's setup connection (`ELOXIV_ADMIN_DATABASE_URL`, behind `MakeSetup`; see above): a superuser, or a managed host's administrative role; a deployment that cannot give the kernel one cannot install or preview MAKE modules.
|
|
182
|
+
- **Bun's workers have no heap limit, nor a stack size**: there a worker's heap is bounded by the interpreter's own limit and the host-call caps, not by `resourceLimits`; and its smaller native stack can overflow inside the WebAssembly under deep `JSON.parse` or `JSON.stringify` before QuickJS's own stack check (Node's 16 MiB worker stack does not). That run fails as a stack limit; its interpreter is dropped without being freed, and the worker discarded, as after any failed run (`packages/kernel/test/sandbox-gc.test.ts`).
|
|
183
|
+
- **What a view can draw**: the tree's elements and properties only: no images, media, links to anywhere, file inputs, custom fonts, scripts of its own or stylesheets (inline `style` with a few properties), and a form is never submitted (its button sends the view its fields; Enter in a field does nothing). A view written as HTML before 0.4.0 of the shell no longer renders: its module's next version must give it as code. The desktop hosts' webviews are not separately tested; the routing the host relies on (a fragment link activated in a script-less frame, read from the parent) was tried in WebKitGTK and Chromium.
|
|
184
|
+
- **A cluster shared by several apps**: a MAKE module's roles are named for the module (`eloxiv_mod_<name>`, `eloxiv_own_<name>`), cluster-wide, and setup sets the runtime role's password from this deployment's key: two apps on one cluster must not make modules of the same name (a setup or preview of one would reset the other's role's password). Neither loses the roles to the other's preview: setup holds the module's role lock (`MAKE_ROLE_LOCK`) from creating them until it has used them. Roles named per app (or per install) are a later option; they would need the catalogue functions that bind a session's role to its module by name (`record_migration`, `make_call_of`) to read that binding elsewhere.
|
|
185
|
+
- **Limits are per kernel process**: the admission bounds and the per-person call limit count one process's calls; the draft and preview limits count every process's.
|
|
186
|
+
- **Runtime roles and other databases**: a MAKE module's runtime role can log in, and PostgreSQL lets every role connect to a database whose `CONNECT` privilege PUBLIC holds; it holds no privilege there. Restrict `eloxiv_mod_mk_%` to the app's database in `pg_hba.conf`. Preview databases revoke `CONNECT` from PUBLIC.
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
# Scheduler
|
|
2
|
+
|
|
3
|
+
Cron and interval jobs with a time zone and an execution identity, event triggers, and recovery sweeps.
|
|
4
|
+
|
|
5
|
+
- Kind: kernel service. Version 1.4.0 (1.1.0: delivery policies and dead letters for event triggers; 1.2.0: a schedule records its creator's provenance and credential scope; 1.3.0: a person's own session is a link of a schedule's authority, never recorded for it; run outcomes and history, no-op runs, failure streaks, run now, one-off runs and shared operation; 1.4.0: a run, schedule or automation the system actor asked for within a narrowed scope, a tool-limited agent run's, runs within it; requests queued before 1.4.0 carry no narrowed system scope and run as recorded).
|
|
6
|
+
- Schema: [`packages/contracts/schema/contracts/Scheduler.json`](../../packages/contracts/schema/contracts/Scheduler.json) (source: [`packages/contracts/src/contracts/Scheduler.ts`](../../packages/contracts/src/contracts/Scheduler.ts); records in [`Durable.ts`](../../packages/contracts/src/Durable.ts))
|
|
7
|
+
- Kernel implementation: [`packages/kernel/src/Scheduler.ts`](../../packages/kernel/src/Scheduler.ts), due-time arithmetic in [`durable/Schedule.ts`](../../packages/kernel/src/durable/Schedule.ts), runtime schedules in the [`scheduler` module](../../packages/kernel/src/scheduler/module.ts)
|
|
8
|
+
- Conformance kit: [`packages/testing/src/conformance/Scheduler.ts`](../../packages/testing/src/conformance/Scheduler.ts), run by [`packages/testing/test/scheduler.test.ts`](../../packages/testing/test/scheduler.test.ts); time zone and DST unit tests in [`packages/kernel/test/schedule.test.ts`](../../packages/kernel/test/schedule.test.ts)
|
|
9
|
+
- Restart proofs: [`packages/testing/test/durable-restart.test.ts`](../../packages/testing/test/durable-restart.test.ts)
|
|
10
|
+
|
|
11
|
+
## Schedules
|
|
12
|
+
|
|
13
|
+
A schedule is a `ScheduleSpec`, a target, an identity and a catch-up policy.
|
|
14
|
+
|
|
15
|
+
- `{ kind: "cron", expression, timeZone }`: five fields, or six with seconds first, evaluated in an IANA time zone. Cron runs once per matching **local** time. A local time that a DST change skips runs once, shifted by the length of the gap (02:30 on a day when 02:00 jumps to 03:00 runs at 03:30). A local time that a DST change repeats runs once, at its earlier occurrence. Use an interval for "every N minutes of absolute time".
|
|
16
|
+
- `{ kind: "interval", everyMs }`: every `everyMs` milliseconds of absolute time from the schedule's anchor, the moment the kernel first saw it.
|
|
17
|
+
- Target: `{ kind: "action", action, input }` (the kernel's `eloxiv.scheduled-action` workflow invokes it in one step) or `{ kind: "workflow", workflow, input }`. A runtime schedule may target only a workflow defined with `schedulable: true`: a workflow can act as the system actor or trust its input, so letting every member start one is its module's decision. Due runs of a runtime schedule that targets any other workflow are not started (a warning is logged).
|
|
18
|
+
- Catch-up (`CatchUp`), for due times older than the grace period (`ELOXIV_SCHEDULER_GRACE_MS`, default 30 s) when a sweep sees them, that is, runs missed while no kernel was running: `once` (default) runs only the latest missed time, `all` runs each, `skip` runs none. Due times within the grace period always run.
|
|
19
|
+
- A sweep starts at most 100 runs of one schedule, oldest first. When more are due (a long backlog under `all`), the schedule's cursor stops at the last run started and the scheduler sweeps again at once, until the backlog is done: the bound delays runs, it never drops one.
|
|
20
|
+
|
|
21
|
+
### Manifest jobs
|
|
22
|
+
|
|
23
|
+
A module declares jobs in its contract (`defineModuleContract({ jobs })`), by id:
|
|
24
|
+
|
|
25
|
+
```ts
|
|
26
|
+
jobs: {
|
|
27
|
+
digest: {
|
|
28
|
+
description: "Send the daily digest",
|
|
29
|
+
schedule: { kind: "cron", expression: "0 8 * * 1-5", timeZone: "Europe/London" },
|
|
30
|
+
action: "mail.sendDigest",
|
|
31
|
+
input: {},
|
|
32
|
+
identity: "system",
|
|
33
|
+
catchUp: "once",
|
|
34
|
+
},
|
|
35
|
+
}
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
A job runs for every organisation, as that organisation's system actor (`$system`), with the key `job:<module>.<job>:<org>`. Its action must exist and accept its input, and its id must not contain `:`, or the kernel refuses to start. Module names are unique in an app (the kernel refuses two modules with one name), so job keys are too.
|
|
39
|
+
|
|
40
|
+
### Runtime schedules
|
|
41
|
+
|
|
42
|
+
Install the kernel's `schedulerModule` in the app (`KernelApp.modules`). Its actions run on the one invocation path, so they are authorised by its Cedar policy, audited, idempotent and on every surface:
|
|
43
|
+
|
|
44
|
+
| Operation | Action | Who may |
|
|
45
|
+
| --- | --- | --- |
|
|
46
|
+
| `create` | `scheduler.create` (`name`, `schedule`, `target`, `catchUp?`, `share?`) | any member: the schedule runs as its creator, in the organisation they act in, and their membership is checked again at every run. `share` (members, groups or the organisation, for `view` or `operate`; never a link) is granted in the same transaction: the schedule and its grants exist together, or the call fails and neither does |
|
|
47
|
+
| `pause` | `scheduler.pause` (`id`) | the owner, its operators, holders of `scheduler.manage`. No run starts while it is paused |
|
|
48
|
+
| `resume` | `scheduler.resume` (`id`) | the owner only (resuming binds the schedule to the resuming call's authority). Runs start again from the first due time after the resume, and the failure streak starts again |
|
|
49
|
+
| `runNow` | `scheduler.runNow` (`id`) → `{ id, key }` | the owner, its operators, holders of `scheduler.manage`: one run now, outside the schedule (also while paused), as the schedule's own identity |
|
|
50
|
+
| `delete` | `scheduler.delete` (`id`) | the owner, holders of `scheduler.manage`. Runs already started continue |
|
|
51
|
+
| `share` | `sharing.grant` on the `schedule` entity, permission `view` or `operate` | the owner ([Sharing](sharing.md)) |
|
|
52
|
+
| `run` | `scheduler.run` (`target`) → `{ id, key }` | any member: the target once, now, as themselves (key `run:<id>`); a workflow target must be schedulable |
|
|
53
|
+
| `list` | `scheduler.list` → `ScheduleSummary[]` | what the caller may see: name, schedule, target, paused (and why), failure streak, last run, next due time |
|
|
54
|
+
| `runs` | `scheduler.runs` (`id`, `limit?`) → `RunRecord[]` | the runs of a schedule the caller may see, or of a one-off run they asked for, newest first |
|
|
55
|
+
| `catalog` | `scheduler.catalog` → `AutomationCatalog` | any member: every module action, the schedulable workflows and the declared event types. Listing is not authorisation: every run is checked as it runs |
|
|
56
|
+
| `health` | `scheduler.health` → `SchedulerHealth` | any member: `down` when no kernel swept within five ticks (at least ten seconds), `degraded` when recorded runs have waited longer than the grace period to start, `ok` otherwise |
|
|
57
|
+
|
|
58
|
+
`scheduler.create`, `resume`, `runNow` and `run` are consent-marked (an agent's call needs the person's consent).
|
|
59
|
+
|
|
60
|
+
Pausing ends a schedule's catch-up: when it is resumed, due times up to the resume time that had not started never run, whatever its catch-up policy. That holds also when no sweep saw the schedule paused (it was paused and resumed while no kernel was running, or within one scheduler tick), because the resume records its time (`resumed_at`) and the next sweep moves the schedule's cursor to it. It includes due times from just before the pause that no sweep had started yet (for example, missed while no kernel ran): pausing means no run starts until the resume.
|
|
61
|
+
|
|
62
|
+
A runtime schedule's key is `schedule:<id>`.
|
|
63
|
+
|
|
64
|
+
### Who sees and operates a schedule
|
|
65
|
+
|
|
66
|
+
Who may see or operate a schedule is separate from whose authority it runs under, which is always its creator's and never changes. Its owner sees and does everything. A member the owner shares it with ([Sharing](sharing.md), the `schedule` entity's sharing permissions) for `view` sees it and its runs; for `operate`, also pauses it and runs it by hand. Holders of `scheduler.manage` see every schedule of their organisation and may pause, run by hand and delete them. A run an operator asks for still runs as the owner, under the authority the owner set the schedule up with; only the owner resumes (resuming re-binds the schedule to the resuming call's authority). There are no public links: a link grant is for members of the organisation, like every grant.
|
|
67
|
+
|
|
68
|
+
### Runs by hand and one-off runs
|
|
69
|
+
|
|
70
|
+
`scheduler.runNow` and `scheduler.run` record a request in the module's own table (`run_request`), in the call's transaction. The scheduler's next sweep (within a tick) records each request as a run and marks it recorded in one transaction, then starts it like a due run, so a request is never lost and runs once, also across a crash. A schedule's run by hand is recorded in the schedule's history under a key of its own request (`<schedule key>#manual:<request id>`, so no two runs by hand, nor one and a due run, share a record), with `requestedBy` set, only while the authority of the call that asked for it still holds (bound with `bindDeferred` and asserted when the sweep records it: a credential revoked or a member removed meanwhile records the run `refused`), and acts under the schedule's own; a one-off run under `run:<id>`, as its requester (an agent's, as the person's agent, its agent session `run:<id>`), under the authority of the call that asked. A request whose target members may not start (a workflow that is not schedulable, or one the app does not have) is recorded `refused`, with the reason.
|
|
71
|
+
|
|
72
|
+
### Run history, outcomes and failure streaks
|
|
73
|
+
|
|
74
|
+
Every run's record (`RunRecord`) says how it ended: `pending` (recorded, not handed to the engine yet), `running`, `succeeded`, `noop`, `failed` (with its error tag, never its message, which can carry what the work was about), `cancelled` or `refused` (with the reason). The execution records its end itself (kernel migration `0070_run_outcomes`). A **no-op** is a run that did nothing on purpose: a workflow declares it with `ctx.noop(reason, evidence)` ([Workflow](workflow.md)); an action a schedule runs returns `noOp(reason, evidence)` (`NoOpOutcome` in `@eloxiv/contracts`) as its output; the call's replay receipt carries it too, so a run whose step ran again after a crash (and got the receipt, not the output) still ends a no-op. It is never a failure and never a plain success.
|
|
75
|
+
|
|
76
|
+
A schedule's **failure streak** is how many of its due runs recorded since its last resume failed (or were refused) in a row; runs by hand never count, either way. The scheduler settles a schedule's finished runs together, oldest first, each from the state the one before left (so two failures settled in one sweep alert once, at the first). The scheduler settles each finished run once (claiming it, `settled_at`, together with what follows, in one transaction): when a runtime schedule's streak starts (its first failure after anything else), its owner gets a notification (category `scheduler.failures`, in-app and by their preferences, the email template `scheduler.failed`, with the one-click unsubscribe link every system email carries); when the streak reaches `ELOXIV_SCHEDULER_PAUSE_AFTER` (default 5; 0 never pauses) the kernel pauses the schedule (`pausedReason: "failures"`) and tells the owner again. Runs between are not alerted. A manifest job has no owner and is never paused: its failed runs are logged, and when its streak starts the organisation's operators (members holding `scheduler.manage`, through their roles) get the same notification; with none, the failure is only logged.
|
|
77
|
+
|
|
78
|
+
## Kernel operations
|
|
79
|
+
|
|
80
|
+
| Operation | What it does |
|
|
81
|
+
| --- | --- |
|
|
82
|
+
| `schedules` | Every schedule the scheduler runs: manifest jobs per organisation, then runtime schedules (`ScheduleRecord`) |
|
|
83
|
+
| `sweep` | Starts every run due at `now` (default: the current time) that has not started, applying catch-up policies, and returns the runs it started (`ScheduledRun`: key, scheduled time, execution id, missed) |
|
|
84
|
+
| `preview` | The next `count` due times of a schedule after `after`; `InvalidInput` for an invalid expression or time zone |
|
|
85
|
+
|
|
86
|
+
## Guarantees
|
|
87
|
+
|
|
88
|
+
- **One execution per run, and every run recorded.** Each due time starts a workflow execution keyed by (schedule key, scheduled time): `<key>@<ISO time>`. A sweep records its runs in `eloxiv.schedule_run` and advances the schedule's cursor (`eloxiv.schedule_state`) in one transaction, and only then starts them. A sweep cut off before that transaction commits started nothing and plans again on the next start; a recorded run that a crash kept from starting is started by the next sweep, joining the execution if the engine already had it. So a run that ran is always recorded, and a recorded run always runs, whatever the catch-up policy (a policy that passes over missed times never applies to a run already recorded). A run's record is history and is never removed. When the engine refuses a run's start (the app no longer has the workflow, or its input no longer decodes), the run is not retried and its record stays. If an earlier attempt reached the engine before the kernel died, the record stays linked to that execution; otherwise it is marked `refused`, with the reason, and a warning is logged.
|
|
89
|
+
- **Never lost, never repeated.** The run's steps have the Workflow contract's guarantees: a run killed mid-step resumes after a restart and its action returns the replay receipt instead of acting twice.
|
|
90
|
+
- **Recovery sweep.** The kernel's first sweep after it starts finds the runs that came due while it was down and applies each schedule's catch-up policy. A schedule seen for the first time never back-fills runs from before it existed.
|
|
91
|
+
- **One scheduler.** Sweeps run in an Effect cluster singleton: one kernel at a time schedules, fenced by its shard lock, and another takes over when it dies. The loop wakes when the next run is due, and at least every `ELOXIV_SCHEDULER_TICK_MS` (default 1000) to pick up new runtime schedules.
|
|
92
|
+
|
|
93
|
+
## Event triggers
|
|
94
|
+
|
|
95
|
+
An outbox event type can start a workflow, once per event: `defineModule({ triggers: [{ id, event, workflow }] })` (or `KernelApp.triggers`). A module's trigger ids are namespaced by the module, like jobs (`echo` in module `ledger` is the trigger `ledger.echo`); an app's are used as given. Trigger ids are unique across the app, and a trigger must start a workflow the app defines on an event type an installed module declares: otherwise the kernel refuses to start. The dispatcher delivers each event to each trigger on its type like to a subscriber, matching on both the trigger and the event type, so an event never starts another trigger's workflow: it starts the workflow with the key `event:<trigger>:<event id>`, as the event organisation's system actor, with the input `{ eventId, type, payload }`, and records the delivery as `trigger:<id>`. The execution journals only the event's id and type: the kernel reads the payload from the outbox each time the work runs, so a person's erasure, which scrubs the events naming them, reaches it (work that runs again after one fails on input that no longer decodes). A module's trigger starts only its own workflows; only the emitting module's own triggers continue the emitting call's [Progress](progress.md) tasks. Delivery is at-least-once, and a redelivered event joins the execution its first delivery started, so the workflow starts at most once per event. A trigger may declare `delivery`, a [delivery policy](outbox.md#delivery-policies): a start that keeps failing is retried under it and then dead-lettered (by default after 20 attempts), never retried forever, and listed with the subscribers' dead letters.
|
|
96
|
+
|
|
97
|
+
## Event automations
|
|
98
|
+
|
|
99
|
+
A runtime schedule whose `schedule` is `{ kind: "event", event, condition? }` is a member's **event automation**: its action (event automations run actions) runs for each event of that type, once per event, as the automation's owner (as the owner's agent, for one an agent set up), on the one invocation path. Every management action above applies to it (pause, resume, share, list, runs, delete); it has no due times, and it is not run by hand. A string value of the target's input that is exactly `{{event.<path>}}` is replaced by that field of the event's payload (null when missing).
|
|
100
|
+
|
|
101
|
+
Only an event that names its record can start an automation: `defineEvent(type, payload, { record: { entity, id } })`, the module's entity and the payload field holding its id (`scheduler.catalog` marks such events `automatable`; the kernel refuses to start on an entity the module does not declare). Each automatable type has a kernel reaction (`kernel:automations:<type>`) that records a run for every unpaused automation on it in the event's organisation (`schedule:<id>#event:<event id>`, timed at the event's occurrence, so a redelivered event records nothing more) in the delivery's transaction; the scheduler's next sweep starts it like any recorded run, so nothing is lost or repeated across a crash. Its run (the kernel workflow `eloxiv.event-automation`) first decides, in one journalled step, whether to act; when it does not, the run ends a no-op whose reason names nothing of the record.
|
|
102
|
+
|
|
103
|
+
Two rules govern what an automation sees (decided at the coordinator's direction as the safe default, 2026-11-14; the owner may overrule):
|
|
104
|
+
|
|
105
|
+
1. **An automation sees only events on records its owner may read, evaluated at delivery time.** When the run decides, the owner must still be a member of the organisation, and the event's record must pass that record's own read policy for the owner, now (the same check Files and Search make: the entity's compiled `read` filter, as its module role under row-level security). Otherwise the run is a no-op ("Its owner may not read the event's record") and neither the condition nor the action sees the event.
|
|
106
|
+
2. **A natural-language condition sends the model only that event, and only what its owner may read, through the app's ModelProvider with metering, never other organisations' data.** `condition: { kind: "prompt", prompt }` is judged by the organisation's model (`AgentRuntime.complete`, metered for the owner, after the owner's authority is asserted) from the prompt and the event's type and payload, asked only once rule 1 held, so the payload is of a record the owner may read; nothing else of the organisation, and nothing of any other organisation (an automation sees only its own organisation's events), is sent. Only the model's verdict is kept (journalled, so a resumed run does not ask again): a condition that does not hold records the fixed reason "The condition does not hold", never the model's explanation, since the run's history is read by whoever may see the automation, not by the event record's readers. An app without the agent cannot run such a condition: the run fails, visibly. `condition: { kind: "match", all }` instead tests the payload with the approval rules' comparisons (dot paths, `eq`, `ne`, `gt`, `gte`, `lt`, `lte`, `in`, `exists`, never coerced); no condition always acts.
|
|
107
|
+
|
|
108
|
+
The action's input is built from the payload each time the run acts (never journalled), so a person's erasure that scrubs the event reaches it. Its runs appear in the automation's history like a schedule's due runs, and count towards its failure streak, alerts and pause.
|
|
109
|
+
|
|
110
|
+
**Stated limit.** A run's tool limit governs what the run itself calls. Automations and event triggers that react to its events run with their own owner's authority.
|
|
111
|
+
|
|
112
|
+
## Agent runs a job starts
|
|
113
|
+
|
|
114
|
+
An agent run that a manifest job or a runtime schedule starts (`agent.send` with the system origin, run kind `job`) is offered one more tool, `no_op` (`{ reason }`): calling it ends the run `succeeded` with stop reason `noop` and the reason as its result, and the run's execution ends a typed no-op ([Workflow](workflow.md)), distinct from a run that finished its work. People's own runs never see the tool.
|
|
115
|
+
|
|
116
|
+
## Schedules an agent sets up
|
|
117
|
+
|
|
118
|
+
`scheduler.create` and `scheduler.resume` are consent-marked: an agent's call needs the person's consent ([ActionConsent](action-consent.md)). A schedule records its `origin`; one an agent created (or resumed) runs as the person's **agent**, with the execution identity's `agentSession` set to `schedule:<id>`, so its consent-marked calls are held for the person, bound to that schedule, and the agent tool groups the app disabled stay closed to it. A schedule also records the `scope` of the credential that created it (an API token's, an OAuth grant's), and the chain of authorities it was created under (`authority`: the credential, the agent session of a run that created it, the consent that let an agent create it; [Invocation](invocation.md#authority)): every run acts within the scope and only while every link holds, asserted inside each call; a run with a link revoked or expired is refused (`Unauthenticated`, or `Forbidden` for consent, audited). A schedule is bound to the authority of the call that creates it, and again to the authority of the call that resumes it (re-enabling is setting it up again: it never runs on under the chain it was paused with). Its record is marked recurring: a one-time consent authorises the call that set it up, not its runs, so an agent's schedule runs only under a remembered permission (`remember: "session"` or `"always"`), whose revocation stops it; one set up under a one-time consent alone is refused at every run. A schedule created before chains were recorded (migration `scheduler/0003_authority` leaves it NULL) never runs: its calls are refused and audited. A person's own session is not kept: their schedule runs while they are a member. The provenance holds however the creation ran: a `scheduler.create` held for a business approval executes as the call was made, so an agent's approved schedule is still the agent's ([Approvals](approvals.md), guarantee 4a). An app with the scheduler but without the consent module refuses an agent's call to them. See [Daemon](daemon.md#work-that-runs-later-keeps-its-origin).
|
|
119
|
+
|
|
120
|
+
## Local interval jobs
|
|
121
|
+
|
|
122
|
+
`startIntervalJob(run, { everyMs, timeoutMs?, leading?, onError? })` (`@eloxiv/kernel`) runs caller-owned repeating work in one process: nothing starts until it is called; `run(signal)` runs at once (or after one interval with `leading: false`) and then `everyMs` after each run ended, so runs never overlap; each run's `AbortSignal` aborts past `timeoutMs` (default `everyMs`) or when the job stops; a failure or timeout goes to `onError` and the job continues; `stop()` aborts the run in progress and settles once it ended. A run that ignores its signal holds the job until it ends. It is for work that may be lost with the process (polling a local resource, refreshing a cache); work that must run once, survive a restart or run on one kernel of several is a manifest job or a runtime schedule. Tests: [`packages/kernel/test/interval-job.test.ts`](../../packages/kernel/test/interval-job.test.ts).
|
|
123
|
+
|
|
124
|
+
## Kernel maintenance
|
|
125
|
+
|
|
126
|
+
`Retention` ([`Retention.ts`](../../packages/kernel/src/Retention.ts)) runs in a cluster singleton beside the scheduler (one kernel at a time), a minute after start and then hourly, deleting in batches: settled outbox events older than `ELOXIV_OUTBOX_RETENTION_DAYS` (default 30; 0 keeps them) with their delivery records, never one with a dead letter or a retrying delivery, nor one whose triggered workflow has not finished (it reads the event's payload whenever it runs); and audit records older than `ELOXIV_AUDIT_RETENTION_DAYS`, only when it is set (by default the audit log is kept for ever); and it clears the saved provider answers of external effects whose module was never told (a refused callback, or one that failed every attempt) once `ELOXIV_EFFECT_ANSWER_RETENTION_DAYS` (default 7; 0 clears them at the next sweep) have passed since the effect ended, keeping the outcome (`result_cleared = 'expired'`; [Invocation, "External effects"](invocation.md#external-effects)). An event is also kept while an event automation's run recorded for it has not finished (waiting to start, or running), however long that takes (`schedule_run.event_id`, migration `0210_run_events`). Each sweep first reconciles executions that ended before migration `0070` (which records each end): it asks the engine how each one older than an hour with no recorded end finished, a batch at a time, and records it, so their schedules' streaks count them and the events they read can go; one still running is asked again at the next sweep. Scheduled runs' records are history and are not pruned. Tests: [`packages/testing/test/retention.test.ts`](../../packages/testing/test/retention.test.ts).
|
|
127
|
+
|
|
128
|
+
## Local time
|
|
129
|
+
|
|
130
|
+
`scheduler.create` takes `timeZone: "local"` on a cron schedule: the schedule is stored in its creator's time zone preference (`settings.timeZone`, [Settings](settings.md#preferences)) as it is when created, or UTC without one; a later change of the preference does not move it.
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
## Recovery backstops
|
|
134
|
+
|
|
135
|
+
agent-native runs periodic timers on long-lived processes to recover work a crash or a lost process left behind. Eloxiv owns each kept case explicitly, and most need no timer: the work is a durable execution on the cluster's fenced shards (one kernel runs a shard at a time, under its advisory lock; another takes the shards of a kernel that died once its registration expires), a durable timer per item, or the outbox's delivery policy. Where a sweep remains, it is a named kernel loop (a cluster singleton or a `Layer` loop), started only on a runner.
|
|
136
|
+
|
|
137
|
+
| agent-native backstop | Eloxiv | Proven by |
|
|
138
|
+
| --- | --- | --- |
|
|
139
|
+
| Drain queued automations (30 s) | The scheduler's singleton sweep starts every recorded run a crash kept from starting (`startPending`) and records runs asked for by hand, each tick | `packages/testing/test/scheduler.test.ts` "keeps a run's record when a retried start is refused, linked to its execution or marked refused"; `durable-restart.test.ts` "neither loses nor repeats a scheduled run killed in the middle" |
|
|
140
|
+
| Redispatch unclaimed chat runs (20 s, 2 min) | An agent run is a durable execution: the kernel that takes its shard resumes it from its last journalled step, never two at once | `agent-restart.test.ts` "resumes a run killed between a tool's commit and the step's record, with the tool's effect exactly once", "never advances one run in two kernels on one database"; `durable-restart.test.ts` "never runs one execution in two kernels on one database, and hands a dead kernel's work to the other" |
|
|
141
|
+
| Reconcile orphaned agent teams (2 min) | A sub-agent is a durable execution of its own, its parent waits for its answer durably; both resume after a crash and finish once | `agent-restart.test.ts` "finishes a delegating run and its sub-agent once after the kernel dies mid-delegation" |
|
|
142
|
+
| Recover sandbox executions (2 min) | There are no background sandbox executions: MAKE code runs inside one call, in one commit (a crash leaves nothing), in a worker the kernel replaces when it dies; an agent's call to it is a tool step, replayed by its receipt | `make-sandbox.test.ts` "keeps serving calls after drafts whose code crashes the interpreter", "leaves no prepared transaction behind"; the agent-restart tool test above |
|
|
143
|
+
| Stuck-task retry (60 s) | Inbound deliveries are accepted durably and the ingress sweep starts any that has no execution | `ingress.test.ts` "starts an execution for an accepted delivery that has none (the sweep)" |
|
|
144
|
+
| Remote-command retry (60 s) | Nothing on the device side needs a job or timer. A device turn is held under a lease: one whose runner restarts is taken back and completed once; one its runner abandoned, or nobody took, is failed by its own durable deadline (`eloxiv.device-turn-deadline`). A device command is recovered when it is read or claimed: never taken, it reads `expired` unrun; taken but never reported, it fails at its deadline ([DeviceControl](device-control.md), "Recovery without timers", with build/daemon-2) | `Daemon` kit "a runner SIGKILLed mid-turn and restarted completes the turn exactly once"; `daemon-limits.test.ts` "fails a turn its runner claimed and abandoned once its deadline passes", "fails a turn nobody ran once its deadline passes, and its workflow ends with it" |
|
|
145
|
+
| Remote-push delivery (60 s) | The daemon delivers nothing itself. Notification deliveries (push, email) are outbox deliveries: retried with backoff under the delivery policy, recorded failed when permanent or out of attempts; a host's push channel targets the person's devices (`Devices.pushSubscriptions(orgId, userId)`) | `Notifications` kit "retries a temporary failure through the outbox, and records the attempts"; `NotificationChannel` kit "reports a temporary failure as retryable, and delivers on the retry" |
|
|
146
|
+
| Connector retries | A connector's external effect is claimed before the provider is called, waits out a rate limit durably (`not_before`), and is sent once across a crash | `registry/test/effects.test.ts` "runs a send the provider rate-limited again, no earlier than its retry time: sent once, succeeded"; `registry/test/effects-restart.test.ts` "killed after the effect went back to pending and before the step was recorded: the restarted kernel sends it once, no earlier than not_before" |
|
|
147
|
+
| A2A continuation recovery | Deferred with A2A itself (external agents, decisions.md: later) | — |
|
|
148
|
+
| Google Docs comment polling (30 s) | Deferred with the comments product (decision 12); a connector that needs polling declares a job, not a process timer | — |
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
# ScreenContext
|
|
2
|
+
|
|
3
|
+
What the person is looking at (the view, the record in focus, the records visible and selected), exposed to their agent so that "this one" and "these" mean something, under privacy rules the person and the app control.
|
|
4
|
+
|
|
5
|
+
- Kind: shell contract. Version 1.1.0 (1.1.0 adds the durable state and agent commands).
|
|
6
|
+
- Schema: [`packages/contracts/schema/contracts/ScreenContext.json`](../../packages/contracts/schema/contracts/ScreenContext.json) (source [`ScreenContext.ts`](../../packages/contracts/src/contracts/ScreenContext.ts)).
|
|
7
|
+
- Implementation: `makeScreenContext(shell, rules)` in `@eloxiv/shell-core` ([`ScreenContext.ts`](../../packages/shell-core/src/ScreenContext.ts)); the kernel's `agent.send` takes the snapshot as `screen` ([AgentRuntime](agent-runtime.md)) and shows it to the model with the message ([`agent/Context.ts`](../../packages/kernel/src/agent/Context.ts), `screenLines`). Durable state and commands: the kernel-provided `app_state` module (`appStateModule`, [`appState/module.ts`](../../packages/kernel/src/appState/module.ts)), the client SDK's `appStateClient`, `commandConsumer` and `consumeCommands` ([`AppState.ts`](../../packages/client/src/AppState.ts)), and shell-core's `screenCommandHandler` ([`ScreenCommands.ts`](../../packages/shell-core/src/ScreenCommands.ts)).
|
|
8
|
+
- Kit: `@eloxiv/testing/conformance/ScreenContext` ([source](../../packages/testing/src/conformance/ScreenContext.ts)).
|
|
9
|
+
|
|
10
|
+
```ts
|
|
11
|
+
const screen = makeScreenContext(shell, { privateViews: ["mail.compose"], privateEntities: ["people.salary"] })
|
|
12
|
+
// The shell reports as the person navigates
|
|
13
|
+
screen.update({ view: "crm.deals", focus: { module: "crm", entity: "deal", id }, selection })
|
|
14
|
+
// and sends what the rules let through with each message
|
|
15
|
+
await agent.send({ text: "Summarise these", screen: screen.snapshot() ?? undefined })
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Operations
|
|
19
|
+
|
|
20
|
+
| Operation | Input | Output | What it does |
|
|
21
|
+
| --- | --- | --- | --- |
|
|
22
|
+
| `update` | `ScreenState` | `{}` | Reports the screen: `view` (id or `null`), `focus?`, `visible?`, `selection?` (entity references) |
|
|
23
|
+
| `snapshot` | `{}` | `ScreenSnapshot` or `null` | What the agent may see now, after the rules; `null` while sharing is off, on a private view, with no view open, or on a view no installed module declares |
|
|
24
|
+
| `privacy` | `{}` | `ScreenPrivacy` | The rules in force |
|
|
25
|
+
| `setSharing` | `{ sharing }` | `ScreenPrivacy` | The person's switch |
|
|
26
|
+
| `readState` | `{ keys, tabId? }` | `{ entries }` | `app_state.get`: the person's entries for up to 50 keys: with a tab, its entries and the shared ones; without (the agent, a headless client), the shared ones and every tab's |
|
|
27
|
+
| `writeState` | `{ key, value, tabId?, expectedVersion?, writer? }` | `{ written, version }` | `app_state.write`: set an entry for a tab or shared; with `expectedVersion` only at that version (0: only if none), else `written: false` and the version now |
|
|
28
|
+
| `removeState` | `{ key, tabId?, expectedVersion? }` | `{ removed, version }` | `app_state.remove`: clear an entry (it reads as none afterwards) |
|
|
29
|
+
| `issueCommand` | `{ id, command, tabId? }` | `{ id, issued }` | `app_state.issue`: a command for the person's screen, once under the issuer's `id` |
|
|
30
|
+
| `pendingCommands` | `{ tabId? }` | `{ commands }` | `app_state.pending`: the commands no tab has acknowledged, for this tab or any, oldest first |
|
|
31
|
+
| `commandOutcome` | `{ id }` | `{ id, state, outcome, detail }` | `app_state.outcome`: a command's state (`pending`, `acknowledged`, `unknown`), and once acknowledged its outcome and detail |
|
|
32
|
+
| `acknowledgeCommand` | `{ id, outcome, detail?, tabId? }` | `{ acknowledged, outcome }` | `app_state.acknowledge`: a tab handled it (`done`, `refused`, `failed`); the first counts |
|
|
33
|
+
|
|
34
|
+
## Records
|
|
35
|
+
|
|
36
|
+
- **`ScreenState`**: as above; references are `{ module, entity, id }` ([WorkItems](work-items.md)'s `EntityReference`).
|
|
37
|
+
- **`ScreenSnapshot`**: `view` (`{ id, title, route }`), `focus` (a reference or `null`), `selection`, `visible` (at most 50 references in all, the focus counted), `withheld` (how many references the rules held back).
|
|
38
|
+
- **`ScreenPrivacy`**: `sharing`, `privateViews`, `privateEntities` (`<module>.<entity>`), `maxReferences` (0 to 50).
|
|
39
|
+
|
|
40
|
+
## Guarantees
|
|
41
|
+
|
|
42
|
+
1. **References only.** A snapshot names records by module, entity and id and the view by id, title and route; nothing else the screen reported leaves (a title beside a reference is dropped).
|
|
43
|
+
2. **Off means nothing**: no snapshot while sharing is off.
|
|
44
|
+
3. **Private views yield nothing**; references to private entities and to entities no installed module declares are withheld, counted in `withheld` and never named.
|
|
45
|
+
4. **Bounded**: at most `maxReferences` (never more than 50) references in all, filled focus first, then selection, then visible, each reference once.
|
|
46
|
+
5. **Never trusted for authorisation.** The kernel validates the snapshot's shape and bounds (`agent.send` refuses one beyond them with `InvalidInput`), stores it with the message, and shows the model the references (`[Screen: view ...]`, `[Screen focus: crm.deal "…"]`); the agent reads the records only through its tools, under the person's policy.
|
|
47
|
+
|
|
48
|
+
## Durable state and agent commands
|
|
49
|
+
|
|
50
|
+
The snapshot above travels with a message. Durable state lets the agent (or a headless client) see what a tab shows between messages, and lets it ask the screen to do something, through the kernel-provided `app_state` module: install `appStateModule` in the app (and `appStateTables` and `appStateQueries` from `@eloxiv/client/sync` for a live replica of it).
|
|
51
|
+
|
|
52
|
+
```ts
|
|
53
|
+
const tabId = tabIdentity("my-app", webTabEnvironment()) // once per page load (ClientSDK)
|
|
54
|
+
const state = appStateClient({ baseUrl, token, orgId, tabId })
|
|
55
|
+
await state.publishScreen(screen.snapshot()) // after the rules; null when sharing is off
|
|
56
|
+
const commands = consumeCommands(state, screenCommandHandler(shell, { navigate, openSettings }), { visibility: webVisibility() })
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
- **Entries** are keyed (`screen`, `route`, `mail.compose`: letters, digits and `._:/-`), per tab (the client's `tabIdentity`) or shared by every tab, at most 16 KiB of JSON each and 200 per person and organisation; past that the oldest per-tab entries are cleared to make room (tabs come and go), and a new shared key is refused. Each has a version (one more on every write) for compare-and-set, and records the tab that wrote it so that tab can ignore its own echo (`isOwnPublication`). Reads go out in the client's read batches (`makeReader`); a write can use `keepalive` so the last screen goes out as the page goes away.
|
|
60
|
+
- **The screen** is published per tab under `screen`, as the snapshot the rules let through (so only references, never field values); `null` removes it. The agent reads it with `app_state.get` (`{ keys: ["screen"] }`).
|
|
61
|
+
- **Commands** are `{ kind, ... }` objects: the module stores them and does not interpret them. Shell-core's `screenCommandHandler` knows `navigate { route }` (a path an installed view serves, never a URL), `open-view { view, record?, params? }`, `open-record { module, entity, id }` (the first view that shows the entity, [View](view.md#navigation-conveniences)), `open-settings { section? }`, `set-search { params }` and `ask { question, options? }` (a structured question for the person, at most 500 characters and 10 options; their answer is the command's detail, and one they dismiss, or outside the options, is refused) and refuses anything else, with why. The agent reads how a command went with `app_state.outcome({ id })`: `pending`, or `acknowledged` with its outcome and detail (an ask's answer); another person's command is `unknown`. `commandConsumer` hands each pending command to the handler once per page load and acknowledges it only after the handler finished (a handler that throws is `failed`); an acknowledgement whose answer was lost is sent again without handling the command again; a command whose page went away before acknowledging is still pending, and the next page handles it. Feed it the replica's `app_state.pending` query, or let `consumeCommands` poll (paused while hidden).
|
|
62
|
+
|
|
63
|
+
Guarantees (each in the kit, against the kernel's module and the agent conformance kernel):
|
|
64
|
+
|
|
65
|
+
6. **A person's own.** Entries and commands are readable and writable by their person alone, in their organisation (row-level security, synced the same way); their agent acts as them. Another member reads none of them and cannot acknowledge them.
|
|
66
|
+
7. **Per tab, with compare-and-set.** A tab's entries are its own; shared entries are every tab's; a write with `expectedVersion` writes only at that version, and a late writer is told the version now. A version is opaque and never repeats for a key: a new entry's is the time it is written (seconds since 2020), then one more on each write.
|
|
67
|
+
8. **Delivered until handled, issued once.** A command is pending until a tab acknowledges it; a command for a tab is only that tab's; issuing the same id again issues nothing; the first acknowledgement counts and later ones are told its outcome. At most 50 are pending.
|
|
68
|
+
9. **Not trusted.** A command only asks: the shell's handler opens only what the installed views serve. Neither the published screen nor a command grants the agent any read: it reads records only through its tools, under the person's policy.
|
|
69
|
+
|
|
70
|
+
## How an implementation is checked
|
|
71
|
+
|
|
72
|
+
`screenContextConformance({ make, agent })` builds the implementation over the shell fixture ([`atlas/contract.ts`](../../packages/testing/src/conformance/atlas/contract.ts)) and checks each rule, the budget order as a property over 200 generated screens, and the bound; with `agent` (a kernel with the agent module and a scripted model), that the model is shown the view and references `agent.send` was given and that an oversized snapshot is refused. With `durable` (a kernel with the `app_state` module and the agent, two members and a scripted agent call), it checks guarantees 6 to 8 and that the agent reads a published screen and issues a command for a tab, recorded as the agent's. The Eloxiv implementation runs it in [`screen-context.test.ts`](../../packages/testing/test/screen-context.test.ts); the consumer and the shell's handler are checked in [`screen-commands.test.ts`](../../packages/testing/test/screen-commands.test.ts).
|
|
73
|
+
|
|
74
|
+
## Retention
|
|
75
|
+
|
|
76
|
+
A runner deletes removed entries (their value cleared) and acknowledged commands once they are older than a day (`ELOXIV_APP_STATE_RETENTION_MS`), every hour (`ELOXIV_APP_STATE_SWEEP_MS`), in every organisation, as the module's system actor (`packages/kernel/src/appState/Sweep.ts`). A removed entry goes only once its version is below the cutoff time as well, so a key written again after the sweep starts above every version it had, and a writer still holding an old one is refused ("never gives a key a version it had before, even written again after its removed entry was swept"). Live entries and pending commands are never swept; an acknowledged command's id is remembered for the retention, so a retried issue within it still issues nothing new. Checked by [`app-state-sweep.test.ts`](../../packages/testing/test/app-state-sweep.test.ts).
|
|
77
|
+
|
|
78
|
+
## Not yet guaranteed
|
|
79
|
+
|
|
80
|
+
- **No text selection or field values**, by design; an app that wants the agent to see a draft must attach it explicitly.
|
|
81
|
+
- **The rules are the shell's**: a client that ignores them can send any references (still only references, still bounded); the agent's access is what policy allows either way.
|