@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,243 @@
|
|
|
1
|
+
# Daemon
|
|
2
|
+
|
|
3
|
+
The device daemon and its kernel side (decision 7): **pairing** a device to a person (or a service principal) in an organisation, **custody** of the device credential, a **loopback relay** that exposes Eloxiv actions to local clients and local agent harnesses without ever showing them a kernel credential, **local agent harnesses** (Claude Code and Codex) running turns on the person's own subscriptions, and a **headless runner** that serves turns addressed to it from the browser and from scheduled jobs.
|
|
4
|
+
|
|
5
|
+
- Kind: kernel service. Version 1.1.0 (1.0.0: before LocalClient and the `desktop-app` client kind, decision 14).
|
|
6
|
+
- Schema: [`packages/contracts/schema/contracts/Daemon.json`](../../packages/contracts/schema/contracts/Daemon.json) (source [`Daemon.ts`](../../packages/contracts/src/contracts/Daemon.ts); records in [`Devices.ts`](../../packages/contracts/src/Devices.ts)).
|
|
7
|
+
- Kernel side: [`packages/kernel/src/devices/`](../../packages/kernel/src/devices): `Devices.ts` (pairing, device authentication, the turn queue, management operations), `Http.ts` (routes), `Flow.ts` (the turn workflow and its reactions), `module.ts` (the kernel-provided `devices` module); the device credential in [`Identity.ts`](../../packages/kernel/src/Identity.ts). Tables: `eloxiv.device`, `eloxiv.device_pairing`, `eloxiv.device_session` and `eloxiv.agent_session.device_id` (kernel migration `0023_devices`); `eloxiv_devices.device`, `turn`, `turn_event` (the module's).
|
|
8
|
+
- Daemon: [`packages/daemon/`](../../packages/daemon) (`@eloxiv/daemon`), shipped as a Bun-compiled sidecar (`build:sidecar`).
|
|
9
|
+
- Kit: `@eloxiv/testing/conformance/Daemon` ([source](../../packages/testing/src/conformance/Daemon.ts)), against the workshop app ([`conformance/workshop`](../../packages/testing/src/conformance/workshop)) with the reference harness [`DaemonReference.ts`](../../packages/testing/src/conformance/DaemonReference.ts), run by [`packages/testing/test/daemon.test.ts`](../../packages/testing/test/daemon.test.ts). [DeviceControl](device-control.md) extends it.
|
|
10
|
+
|
|
11
|
+
## Installing
|
|
12
|
+
|
|
13
|
+
An app that pairs devices installs the kernel's `devicesModule`, and `inboxModules` (its `devices.sendTurn` is consent-marked); scheduled jobs that address a runner need `schedulerModule`:
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import { devicesModule, inboxModules, schedulerModule, type KernelApp } from "@eloxiv/kernel"
|
|
17
|
+
|
|
18
|
+
export const app: KernelApp = { name: "my-app", modules: [...myModules, devicesModule, schedulerModule, ...inboxModules] }
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Without `devicesModule`, every device route answers 404.
|
|
22
|
+
|
|
23
|
+
## Pairing
|
|
24
|
+
|
|
25
|
+
RFC 8628's shape, between the daemon and the kernel:
|
|
26
|
+
|
|
27
|
+
0. The kernel URL must be `https`, or `http` on loopback only: the daemon refuses a plain-http kernel elsewhere, which would see the credential in clear. A daemon that is paired refuses to pair with any kernel (`409 AlreadyPaired`) until its pairing is revoked or removed (`eloxiv-daemon unpair`).
|
|
28
|
+
1. The daemon calls `startPairing` (`POST /kernel/device/pair/start`, no credential; at most `ELOXIV_DEVICE_PAIRING_LIMIT` (20) per source address per 10 minutes) with its name, kind (`desktop` or `runner`), platform and capabilities (the harnesses it found). It gets a **user code** (`XXXX-XXXX`, 20 letters without look-alikes), a `verificationUri`, and a **poll secret** (`elxp_...`) only it holds. Codes expire after `ELOXIV_DEVICE_PAIRING_TTL_S` (600 s).
|
|
29
|
+
2. The daemon shows the code only to the person at the machine: in `eloxiv-daemon pair`'s output, on the terminal a headless daemon started with `--kernel` runs on (when its stderr is one), through `eloxiv-daemon pairing-code` (which reads it from the running daemon with the control secret), and in `/status` for the host and its local clients. **Never in its log**: logs are collected centrally, and whoever reads a live code first can confirm it under their own account and receive the device. The log says only that a pairing is waiting and where to read its code.
|
|
30
|
+
3. A **signed-in person** confirms the code: `confirmPairing` (`POST /kernel/devices/confirmPairing`, a Better Auth session, never a machine credential) in the organisation they act in. The device acts for them; with `principalId` (and `eloxiv.machine.manage`) it acts for an organisation's service principal, as a runner for jobs. `denyPairing` refuses it. Both are audited (`eloxiv.devices.confirmPairing`, `eloxiv.devices.denyPairing`).
|
|
31
|
+
The pairings one address starts are counted the same atomic way (`ELOXIV_DEVICE_PAIRING_LIMIT`, 20 per 10 minutes).
|
|
32
|
+
4. The daemon's next `pollPairing` (`POST /kernel/device/pair/poll`, every `interval` seconds) creates the device and returns its **credential** (`elxv_...`, 256 random bits) **once**.
|
|
33
|
+
|
|
34
|
+
| Refused | How |
|
|
35
|
+
| --- | --- |
|
|
36
|
+
| A wrong code | `InvalidInput` ("No pairing with this code"). Every decision first takes a use of the person's budget (`ELOXIV_DEVICE_CODE_ATTEMPTS`, 10 per 10 minutes) in one atomic statement outside the decision's transaction, and a decision that succeeds gives it back: past the budget the person is refused (`Forbidden`), also when the guesses arrive in parallel |
|
|
37
|
+
| An expired code | `InvalidInput` ("expired") to the person; `{ status: "expired" }` to the daemon |
|
|
38
|
+
| A reused code | `InvalidInput` ("already used") |
|
|
39
|
+
| A second claim of the credential | Within a minute of the first, once (the daemon's answer may have been lost): a **new** credential, and the first one stops working, so no credential is ever valid twice. After that, `InvalidInput` ("already used") |
|
|
40
|
+
| A wrong poll secret | `InvalidInput` ("Unknown pairing") |
|
|
41
|
+
| A service principal without `eloxiv.machine.manage` | `Forbidden` |
|
|
42
|
+
|
|
43
|
+
The kernel stores codes, poll secrets and credentials only as SHA-256 hashes.
|
|
44
|
+
|
|
45
|
+
## Custody
|
|
46
|
+
|
|
47
|
+
The daemon keeps the device credential in the operating system's secure storage through a small `SecretStore` ([`Secrets.ts`](../../packages/daemon/src/Secrets.ts)): **libsecret** (`secret-tool`) on Linux, **Keychain** (`security`) on macOS, **Credential Manager** (PowerShell and `CredRead`/`CredWrite`) on Windows, or a **file** fallback, `<state dir>/secrets.json`, mode 0600 in a 0700 directory, written atomically. `--secret-store auto` (the default) uses the platform's store when a probe (store, read back, delete a throwaway secret) works and falls back to the file otherwise; `/status` says which store is in use. The key is per state directory, so two daemons on one machine never share a credential. Secrets are passed to the tools on stdin or in the environment, never in argv.
|
|
48
|
+
|
|
49
|
+
Everything else the daemon persists is in `<state dir>/state.json` (0600): the kernel pairing (URL, device, organisation, subject; never the credential), the local clients it paired (their tokens only as SHA-256 hashes) and the turn a runner is working on. The state directory defaults to `$XDG_STATE_HOME/eloxiv/daemon` (`~/.local/state`), `~/Library/Application Support/Eloxiv/daemon` or `%APPDATA%\Eloxiv\daemon`, and is `--state-dir` / `ELOXIV_DAEMON_STATE_DIR`.
|
|
50
|
+
|
|
51
|
+
**A second identity: the person session (LocalClient, decision 14).** An app's own sidecar, composed with a `clientApp`, also holds the **person's session** for a native desktop host ([LocalClient](local-client.md)): obtained by desktop sign-in through the daemon's own loopback callback, kept in the same secret store under a key of its own (`person-session-<hash of the state directory>`, `personSessionKey` in [`Client.ts`](../../packages/daemon/src/Client.ts)), never in `state.json`. It is not the device credential and changes nothing about it: the device credential still pairs, relays and runs turns as before, and the person session is used only by `/client/v1` (the replica, the native app's calls). Signing out revokes the person session at the kernel and forgets it; unpairing or revoking the device leaves it alone, and the reverse. A desktop sign-in opens the app's approval page in the system browser: `clientApp.signInPage`, else `ELOXIV_SIGN_IN_PAGE`, else the web shell's `/desktop/sign-in` at `clientApp.shellUrl` or `ELOXIV_SHELL_URL` (default `http://localhost:5173`; `signInPageOf` in `Client.ts`).
|
|
52
|
+
|
|
53
|
+
**The daemon never hands a kernel credential to a local client or a harness.** This holds for LocalClient too: its answers, events and pages carry neither the person session nor the device credential (each is scrubbed of both, as defence in depth). The relay adds it to requests it forwards; responses to local clients are the kernel's body (scrubbed of any credential, as defence in depth), never its headers. Harnesses get a loopback token for one turn; the kernel session behind it stays in the daemon. That is what the daemon gives out; what a harness with **workspace tools** can read on its own, as the daemon's OS user, is listed under [what a harness can still reach](#harness-turns).
|
|
54
|
+
|
|
55
|
+
## Revocation
|
|
56
|
+
|
|
57
|
+
`revokeDevice` ([DeviceControl](device-control.md)) by the device's person, the person who paired it, or `eloxiv.machine.manage`: the credential is refused (401) from the device's **next request**, on the device endpoints and on every action surface; every agent session issued to the device is revoked with it (and refused anyway, since an agent session bound to a revoked device does not authenticate); its unfinished turns fail. When a request is refused with 401, the daemon checks once more (`GET /kernel/device/me`); only if the kernel refuses the device itself does it record the revocation, delete its credential, stop its runner and answer `401 DeviceNotPaired` to relayed calls (`/status` shows `revoked`). A 401 for anything else (an expired relay session, say) leaves the pairing alone.
|
|
58
|
+
|
|
59
|
+
## The loopback relay
|
|
60
|
+
|
|
61
|
+
The daemon listens on `127.0.0.1` only (`--port`, default 4191). Every request except `GET /health` is checked for:
|
|
62
|
+
|
|
63
|
+
- **Host**: `127.0.0.1:<port>`, `localhost:<port>` or `[::1]:<port>`, else 403 (DNS rebinding);
|
|
64
|
+
- **Origin**, when present: one of the trusted origins (`ELOXIV_TRUSTED_ORIGINS`; by default the Tauri webview's, plus the Vite dev server's `http://localhost:5173` only when the daemon runs from source: the compiled sidecar is a release build and does not trust it), else 403, not just a missing CORS header;
|
|
65
|
+
- **a local client token**, per client:
|
|
66
|
+
- the **host** (the Tauri app that started the sidecar) holds a per-launch secret given to the daemon in `ELOXIV_DAEMON_HOST_SECRET` (at least 32 characters);
|
|
67
|
+
- **local clients** (a CLI, a browser extension, the shell in a browser) pair once, and a code alone is never enough:
|
|
68
|
+
1. the client asks, `POST /local/pair/start` (`{ clientName, kind }`), and gets a pairing id, never the code;
|
|
69
|
+
2. the **host approves** the request: the desktop app's prompt (`GET /local/pairings`, `POST /local/pairings/<id>/approve`, with the host secret), or the person at the machine with `eloxiv-daemon approve-client [<id>]`, which acts as the host through a control secret the daemon writes to its state directory (0600) at each start. The approval shows the person the code: ten symbols of Crockford's base 32 (`XXXXX-XXXXX`, 50 bits);
|
|
70
|
+
3. the person types the code into the client, which exchanges it with `POST /local/pair/confirm` for a token (`elxl_...`). Case and the dash do not matter.
|
|
71
|
+
|
|
72
|
+
Against guessing: an unapproved pairing is refused even with the right code (`PairingNotApproved`); three wrong codes discard a pairing; every wrong code, on any pairing, counts against one budget (3), past which every confirmation is locked out (`429 PairingLocked`) for 2 s, doubling with each further wrong code up to an hour, until a pairing succeeds; at most 5 pairings start per 10 minutes (`429 PairingRateLimited`). Codes expire after 5 minutes, work once, and are **never logged**: the log says only that a client asks to pair and how to approve it;
|
|
73
|
+
- **harnesses** get a token valid only for the relay and MCP, only while their turn runs.
|
|
74
|
+
- a local client pairs with a **kind** (`shell`, `cli`, `browser-extension`, `computer-use`, or `desktop-app`: a native desktop app, the only kind besides the host that may use LocalClient). The kind is the one the host approved: a confirmation naming another kind is refused (`403 PairingKindMismatch`) and discards the pairing.
|
|
75
|
+
|
|
76
|
+
| Route | Who | What |
|
|
77
|
+
| --- | --- | --- |
|
|
78
|
+
| `GET /health` | anyone | `DaemonHealth` |
|
|
79
|
+
| `GET /status` | a local client | `DaemonStatus`: mode, kernel pairing state (with the user code while pairing), secret store, harnesses |
|
|
80
|
+
| `POST /local/pair/start`, `/local/pair/confirm` | anyone (see above) | ask to pair; exchange an approved pairing's code for a token |
|
|
81
|
+
| `GET /local/pairings`, `POST /local/pairings/<id>/approve` | the host | pending requests with their codes; approve one |
|
|
82
|
+
| `POST /kernel-pairing/start` | the host, a shell or a CLI | start pairing with a kernel (`{ kernelUrl, name? }`); `409 AlreadyPaired` while paired, 400 for a plain-http kernel off loopback |
|
|
83
|
+
| `POST /relay/actions/<action>` | any client | the action through the kernel's HTTP surface: as the **person** (the device credential) for local clients, as the person's **agent** (the turn's agent session) for a harness. `idempotency-key` is passed on |
|
|
84
|
+
| `POST`, `GET`, `DELETE /mcp` | any client | the kernel's MCP tools with an **agent session** (for a harness, its turn's; for other clients, a short-lived one per client). The kernel's OAuth challenge is never passed on |
|
|
85
|
+
| `GET /harnesses` | a local client | the harness CLIs, versions and sign-in state (`?refresh=1`) |
|
|
86
|
+
| `POST /turns` | a local client | run a harness turn now ([below](#harness-turns)), as server-sent events (`started`, `harness`, `result`); closing the request cancels it |
|
|
87
|
+
| `GET /sessions`, `GET /capabilities`, `GET /computer-use` | a local client | [DeviceControl](device-control.md) |
|
|
88
|
+
| `POST /companion/commands/next`, `/companion/commands/<id>/result` | a `browser-extension` or `computer-use` client | browser and computer commands ([DeviceControl](device-control.md#device-commands)) |
|
|
89
|
+
| `/terminals`, `/terminals/<id>[/stream\|/input\|/resize]` | the host, the shell or a CLI | terminals ([DeviceControl](device-control.md#terminals)) |
|
|
90
|
+
| `POST /push` | the host, the shell or a CLI | the host's push subscription ([DeviceControl](device-control.md#push)) |
|
|
91
|
+
| `/client/v1/...` | the host and paired `desktop-app` clients | [LocalClient](local-client.md), when the sidecar was composed with a `clientApp` (else `404 ClientNotConfigured`): `GET hello`, `GET session`, `POST sign-in`, `POST org`, `POST sign-out`, `GET events` (server-sent events), `POST subscriptions`, `DELETE subscriptions/<id>`, `POST writes`, `POST actions/<name>`. Refusals are `{ _tag, message, ...fields }`; a harness, companion, shell or CLI token is `403 Forbidden` |
|
|
92
|
+
| `GET /client/v1/sign-in/callback?code&state` | the browser (no token, no Origin check) | LocalClient's sign-in callback: the state the daemon issued, once, within 60 s; else 400 and nothing redeemed |
|
|
93
|
+
|
|
94
|
+
A harness limited to some actions (a turn's `actions`) may call only those: the relay refuses any other with `403 ToolNotAllowed`, and answers an MCP `tools/call` for any other with a JSON-RPC error without forwarding it.
|
|
95
|
+
|
|
96
|
+
Relayed calls go through the kernel's one invocation path. A call with the device credential is **person-originated** (audited as the person; the credential's session is `device:<id>`). A harness's calls use an **agent session** the kernel issued to the device (`issueRelaySession`, `POST /kernel/device/relay-session`, at most 24 hours, bound to the device), so they are **agent-originated** on every surface: consent holds a destructive one until the person decides ([ActionConsent](action-consent.md)), and the audit shows the person on the agent's surface (`mcp`). A turn carries the authority of the call that queued it (`devices.sendTurn`: its credential's scope and its chain of authorities, [Invocation](invocation.md#authority)): the session the runner asks for a turn (`turnId`) carries that chain and the device, so the harness's calls stay within the scope and are refused once any link no longer holds, and a turn whose chain no longer holds when a runner claims it, or that was queued before chains were recorded (migration `devices/0002_authority`), fails without running. A relay session asked for **without** a turn is the device's own: its chain is the device, so it acts with the device's person's authority while the device stands. A session issued before chains were recorded (its authority NULL, as migration 0032 leaves it) is refused (401). A device's reports of a turn (`turns/events`, `turns/complete`) are taken only while the turn's chain holds, asserted (links locked) before the turn's row: once it does not, the turn fails without them (`stop: true` for events, `settled: false` for a result), and its sender hears. A claim asserts the chain the same way before taking the turn. That is consistent with a paired device being fully trusted (its own credential is the person's); turn scoping relies on the runner asking for the turn's session, and does not confine a runner that does not.
|
|
97
|
+
|
|
98
|
+
## Harness turns
|
|
99
|
+
|
|
100
|
+
[`Harness.ts`](../../packages/daemon/src/Harness.ts) has an adapter per harness, each running one turn: a prompt, the Eloxiv actions as MCP tools through the relay, a working directory (default `<state dir>/workspace`, or `--workspace`), an optional model and a time limit.
|
|
101
|
+
|
|
102
|
+
| | Claude Code | Codex |
|
|
103
|
+
| --- | --- | --- |
|
|
104
|
+
| Command | `claude -p --output-format stream-json --verbose --mcp-config <file> --strict-mcp-config --tools "" --setting-sources "" --allowedTools mcp__eloxiv --no-session-persistence [--model m] -- <prompt>` | `codex exec --json --skip-git-repo-check --ignore-user-config --ephemeral --sandbox read-only --disable shell_tool -C <cwd> -c mcp_servers.eloxiv.url=... -c mcp_servers.eloxiv.bearer_token_env_var="ELOXIV_MCP_TOKEN" -c mcp_servers.eloxiv.default_tools_approval_mode="approve" -c approval_policy="never" [-m m] -- <prompt>` |
|
|
105
|
+
| With `workspaceTools` | `--tools Bash,Read,Edit,Write,Glob,Grep`, the same in `--allowedTools` | `--sandbox workspace-write`, the shell enabled |
|
|
106
|
+
| The turn's token | in the MCP config file (0600, in a private temporary directory, removed after the turn) | in `ELOXIV_MCP_TOKEN` |
|
|
107
|
+
| Stream | `system/init`, `assistant` (text, `tool_use`), `user` (`tool_result`), `result` (answer, usage, cost) | `thread.started`, `item.started`/`item.completed` (`mcp_tool_call`, `agent_message`, `command_execution`), `turn.completed` (usage), `turn.failed`, `error` |
|
|
108
|
+
| Sign-in check | `claude auth status --json` | `codex login status` |
|
|
109
|
+
| Override | `ELOXIV_DAEMON_CLAUDE_COMMAND` | `ELOXIV_DAEMON_CODEX_COMMAND` (a path, or a JSON array) |
|
|
110
|
+
|
|
111
|
+
**ACP agents.** `opencode` (`opencode acp`, or `ELOXIV_DAEMON_OPENCODE_COMMAND`) and `acp` (any agent the person names in `ELOXIV_DAEMON_ACP_COMMAND`, a JSON array: Gemini CLI's `gemini --experimental-acp`, an ACP bridge for Claude Code or Pi) speak the Agent Client Protocol ([`Acp.ts`](../../packages/daemon/src/Acp.ts)): the daemon is the client, starts a session (`session/new`, or `session/load` for a follow-up, whose replayed history is not reported as the turn's) with the Eloxiv tools as an HTTP MCP server (the relay, the turn's token in a header), sends `session/prompt`, maps `session/update` (message chunks, `tool_call`, `tool_call_update`) to the events below, and cancels with `session/cancel` before signalling the process group. It offers the agent no file system or terminal of its own (such requests are refused) and rejects any permission request for a tool that is not Eloxiv's unless the turn has workspace tools. But an agent can run code without asking: its own tools, or configuration and plugins it discovers in the working directory (OpenCode loads a repository's `.opencode/plugins/*.ts` before any permission request). So **only an agent the person declares tools-only** (`ELOXIV_DAEMON_ACP_TOOLS_ONLY=1`, for a configured agent whose own configuration they control) runs a turn without workspace tools; any other, **OpenCode included**, runs only turns that ask for workspace tools, and any other turn fails without starting it. OpenCode still gets `OPENCODE_CONFIG_CONTENT` with its permissions (every tool allowed with workspace tools), as defence in depth. ACP agents keep their own sign-in, which the daemon does not inspect (`loggedIn: null`), and report no usage.
|
|
112
|
+
|
|
113
|
+
**The tools-only profile.** `--tools-only` (or `ELOXIV_DAEMON_TOOLS_ONLY=1`) is the configuration for a hosted or shared runner: a turn asking for workspace tools fails without starting the harness, the terminal and files commands cannot be enabled (start-up refuses), and the device reports `toolsOnly: true` in its capabilities. Independently, an organisation's administrator can refuse turns with workspace tools for all its devices (setting `devices.workspaceTools`, default on: `devices.sendTurn` answers `Forbidden`), and a deployment can set either default (settings' app level).
|
|
114
|
+
|
|
115
|
+
Events are normalised (`HarnessEvent`: `started`, `text`, `tool-call`, `tool-result`, `usage`, `error`, `finished`); raw CLI output never leaves the machine, and neither does a built-in tool's output (a file Claude Code read, a command's output): their `tool-result` carries `[output of a built-in tool: not forwarded]`, only the Eloxiv tools' results are forwarded. Usage is the CLI's own figure (`inputTokens` including cached and cache-creation tokens, `outputTokens`, `cachedInputTokens`, `costUsd` when Claude Code reports it). The CLI runs in its own process group. Cancellation and the time limit signal the whole group (SIGTERM, then SIGKILL after 3 s) and stop waiting for its output after the grace, and when the turn ends for any reason (also when the CLI exits while something it started holds its output open, once its output has been quiet for 2 s) whatever is left of the group is killed: nothing a turn started outlives it. The harness runs with the person's environment (so it finds its own sign-in) minus the daemon's variables (`ELOXIV_*`) and the markers of a parent Claude Code session; the daemon never reads the CLIs' credentials, and nothing of them is sent to the kernel.
|
|
116
|
+
|
|
117
|
+
**Tools.** By default a turn has **only the Eloxiv tools**: Claude Code gets no built-in tools (`--tools ""`) and none of the person's user or project settings (`--setting-sources ""`: no hooks, plugins or permission rules of theirs), and Codex runs without its shell (`--disable shell_tool`), in a read-only sandbox, ignoring the person's config (`--ignore-user-config`: their other MCP servers do not start; their sign-in still applies). The flags were checked against Claude Code 2.1.317 (offline: an isolated config and an unreachable API endpoint, so no model was called) and Codex 0.166.0. A turn may ask for **workspace tools** (`workspaceTools: true` on `devices.sendTurn` or `/turns`): the file and shell tools, in the turn's working directory.
|
|
118
|
+
|
|
119
|
+
**The working directory** is the turn's `cwd`, else `--workspace`, else a **fresh, empty temporary directory** created for the turn and removed after it. It is never the state directory or inside it (`--workspace` there is refused at start-up).
|
|
120
|
+
|
|
121
|
+
**Follow-up turns.** By default a turn keeps nothing: Claude Code runs with `--no-session-persistence`, Codex with `--ephemeral`. A turn sent with `resumable: true` (`devices.sendTurn`, `POST /turns`, or `agent.send`'s `device`) keeps its harness session: the CLI keeps its transcript (in the person's home directory, as it does for their own sessions), and a turn that named no directory gets one under `$TMPDIR/eloxiv-sessions-<hash>` that outlives the turn. The runner reports the session id with the turn's result (`CompleteTurn.sessionId`), and the daemon records it in `state.json` (`harnessSessions`, at most 50, the least recently used forgotten with the directories it created). `devices.sendTurn` with `followUp: <turn id>` continues it: the kernel accepts only a settled, resumable turn on the same device whose subject is the caller, and only the latest turn of its session (a turn that already has a follow-up is refused, naming that follow-up: two follow-ups of one turn, even sent at once, never fork its session; the followed turn's row is locked while the follow-up is recorded), and the follow-up runs the same harness in the same directory (`claude --resume <id>`; `codex exec resume ... -- <id> <prompt>`, with the sandbox as `-c sandbox_mode=...`), and is resumable in turn. **The daemon resumes only a session it kept**: a session id it has no record of (for that harness) fails the turn without starting the CLI. Revoking or unpairing the device forgets every kept session and removes the directories the daemon created for them. A local client resumes with `POST /turns` and `resume: <session id>` (the `sessionId` of a resumable turn's result). Two follow-ups of one turn running at once each continue the same session (the CLIs then fork it); nothing serialises them.
|
|
122
|
+
|
|
123
|
+
**What a harness can still reach.** Without workspace tools, a harness can do only what the Eloxiv tools let the person's agent do, through the relay, under consent. With workspace tools it runs a shell **as the daemon's OS user**: Claude Code's Bash is not sandboxed, and Codex's workspace-write sandbox limits writes, not reads. Such a shell can read whatever that user can, including the daemon's state directory: the **file secret store** (`secrets.json`, the device credential, when no OS store is used), the control secret, `state.json` (0600, but the same user), and the OS keyring through `secret-tool` or `security` when it is unlocked. It can also reach the daemon's loopback port, but needs a token for it (local client tokens are stored only as hashes). It cannot read the host's secret from the daemon's environment (`ELOXIV_DAEMON_HOST_SECRET` is removed once read, so nothing the daemon starts inherits it; the operating system may still show a process's initial environment to the same user). So **workspace tools are for machines and people who already trust that harness with that OS user**: give a runner its own user, or use OS secure storage and accept that the keyring is reachable while unlocked.
|
|
124
|
+
|
|
125
|
+
## Work that runs later keeps its origin
|
|
126
|
+
|
|
127
|
+
An agent must not get through a schedule or a runner what it could not do directly. So the actions that make other actions run later need the person's consent when an agent calls them: `scheduler.create` and `scheduler.resume` (a schedule's runs), and `devices.sendTurn` (another agent's turn). And what an agent set up keeps the agent's origin: a schedule records its `origin` (`agent` when an agent created or resumed it), and its runs act as the person's **agent** (an execution identity with `agentSession: "schedule:<id>"`), so a run's consent-marked call is held for the person, bound to that schedule, exactly as the agent's own call would have been. A turn records its `source`, and its tool calls go through the relay as the person's agent anyway. In an app with the kernel's scheduler but without the consent module, an agent's call to these actions is refused (`Forbidden`) rather than run unasked.
|
|
128
|
+
|
|
129
|
+
The other indirections were checked: business approvals run the exact call an agent's request was consented to (consent is checked before the approval rules); event triggers and kernel workflows are declared in manifests, not created by calls; sharing has no action surface; consent decisions are refused to agent-originated callers, including a schedule's runs.
|
|
130
|
+
|
|
131
|
+
## The headless runner
|
|
132
|
+
|
|
133
|
+
`eloxiv-daemon --headless [--kernel <url>]` on an always-on machine serves turns addressed to it. Pair it first (`eloxiv-daemon pair --kernel <url> --runner`, which prints the code to confirm and waits), or pass `--kernel` and confirm the code it prints on its terminal, or that `eloxiv-daemon pairing-code` reads from it.
|
|
134
|
+
|
|
135
|
+
**Addressing a runner.** `devices.sendTurn` is an action, so every surface reaches it the same way: the typed client from the browser (`makeClient({ modules: [devicesContract, ...] }).call("devices.sendTurn", { deviceId, prompt, harness?, cwd?, model?, timeoutMs? })`), HTTP, MCP, agent tools (consent-marked: an agent asking a device to run an agent needs the person's consent) and **scheduled jobs**: a runtime schedule (`scheduler.create`, target `{ kind: "action", action: "devices.sendTurn", input }`) runs as its owner, so a person's schedule addresses their runner. **Only the device's subject may address it**: the module's policy requires the turn's subject (the device's person or service principal) to be the caller; anyone else gets `Forbidden`, and a revoked device is refused. The turn records its `source` (`person`, `agent`, or `system` for jobs and workflows). `devices.cancelTurn` cancels one; `getTurn` (`POST /kernel/devices/getTurn`, the requester or the device's subject) reads it with its events.
|
|
136
|
+
|
|
137
|
+
**The queue.**
|
|
138
|
+
|
|
139
|
+
1. `devices.sendTurn` stores the turn (`queued`) and `devices.turnRequested` in one transaction; a kernel reaction starts the durable workflow `eloxiv.device-turn` (keyed by the turn id, as the requester) and its deadline timer (`eloxiv.device-turn-deadline`: a turn unfinished after its time limit plus `ELOXIV_DEVICE_QUEUE_TTL_MS`, a day, fails).
|
|
140
|
+
2. The runner long-polls `nextTurn` (`POST /kernel/device/turns/next`, up to 30 s) and claims the oldest queued turn addressed to it: `running`, `attempt + 1`, a new **lease**, valid `ELOXIV_DEVICE_LEASE_MS` (60 s).
|
|
141
|
+
3. It runs the turn with the harness, streaming events with `appendTurnEvents` (batched every 300 ms; idempotent by attempt and sequence number) and renewing the lease with each call (an empty call is a heartbeat). `stop: true` (the turn was cancelled) stops the harness. Before the relay forwards a call of the turn's harness (an action, or an MCP `tools/call`), the runner asks the kernel the same way at once; a cancelled turn's harness is stopped and the call refused (`TurnCancelled`, or a JSON-RPC error), so nothing the harness asks for runs after a cancellation the kernel has committed.
|
|
142
|
+
4. It settles the turn once with `completeTurn`: the outcome, the answer, usage and error, under its lease, in one transaction with `devices.turnSettled`, whose reaction signals the workflow; the workflow reads the outcome back and finishes with it.
|
|
143
|
+
|
|
144
|
+
**Exactly once across restarts.** A runner that restarts (SIGKILL, a crash, a reboot) calls `nextTurn` with `fresh: true` first: the turns it held go back to the queue and are claimed again at once as a new attempt (a lease that runs out without a heartbeat does the same for a runner that never comes back). The request is never lost: it is a row and a workflow, not a message. A finished turn's result is **kept in `state.json` until the kernel takes it**: it is reported with backoff (up to 30 s between attempts, without a cap on attempts) until the kernel settles the turn, says the attempt lost its lease, or refuses the device, and a restarted runner reports it **before** it asks for work (a fresh claim would put the turn back in the queue and run it again). Every kernel request has a time limit (30 s; the long poll its wait plus 30 s; relayed calls 10 minutes). Events go out in pages of at most 200 (the kernel refuses more than 500 in one call rather than dropping any); a page the kernel did not take stays pending, in order. It is never reported twice: `completeTurn` settles only a `running` turn under its current lease; the same report again is answered `duplicate: true` and changes nothing, and a report from a superseded attempt is `TurnLeaseLost` (409). A re-run attempt's tool calls do not repeat side effects: the relay keys each `tools/call` of a runner turn with `device-turn:<turn>:<hash of tool and input>:<occurrence>` (`_meta["io.eloxiv/idempotency-key"]`), so the same call in the next attempt returns the original's replay receipt. A harness whose daemon died exits (the fake harness watches its parent; a real CLI's later calls to the relay are refused, since its token died with the process).
|
|
145
|
+
|
|
146
|
+
## Operations
|
|
147
|
+
|
|
148
|
+
| Operation | Where | Input | Output | Errors |
|
|
149
|
+
| --- | --- | --- | --- | --- |
|
|
150
|
+
| `startPairing` | `POST /kernel/device/pair/start` | `PairingRequest` | `PairingStarted` | `InvalidInput`, `Forbidden` (rate limit) |
|
|
151
|
+
| `pollPairing` | `POST /kernel/device/pair/poll` | `pairingId`, `pollSecret` | `PairingPollResult`: `pending`, `denied`, `expired`, or `paired` with the credential (once) | `InvalidInput` |
|
|
152
|
+
| `confirmPairing` / `denyPairing` | `POST /kernel/devices/<op>` (a person) | `userCode`, `principalId?` | `pairingId`, `status`, `deviceId` | `Unauthenticated`, `Forbidden`, `InvalidInput` |
|
|
153
|
+
| `deviceStatus` | `GET /kernel/device/me` (the device) | | `DeviceInfo` | `Unauthenticated` |
|
|
154
|
+
| `issueRelaySession` | `POST /kernel/device/relay-session` (the device) | `purpose`, `ttlSeconds?`, `turnId?` (a running turn the device holds: the session carries the turn's authority) | `id`, `token`, `expiresAt` | `Unauthenticated`, `Forbidden` (also: no such running turn, or its credential no longer valid) |
|
|
155
|
+
| `sendTurn` | action `devices.sendTurn` | `SendTurn` | `turnId` | the standard error set, `ConsentRequired` |
|
|
156
|
+
| `cancelTurn` | action `devices.cancelTurn` | `id` | `id`, `status` | the standard error set |
|
|
157
|
+
| `getTurn` | `POST /kernel/devices/getTurn` (a person) | `id` | `TurnView` (the turn and its events) | `Unauthenticated`, `InvalidInput` |
|
|
158
|
+
| `nextTurn` | `POST /kernel/device/turns/next` (the device) | `waitMs?`, `fresh?` | `turn`: a `ClaimedTurn` or null | `Unauthenticated` |
|
|
159
|
+
| `appendTurnEvents` | `POST /kernel/device/turns/events` (the device) | `turnId`, `lease`, `events` | `accepted`, `stop` | `Unauthenticated`, `TurnLeaseLost` |
|
|
160
|
+
| `completeTurn` | `POST /kernel/device/turns/complete` (the device) | `CompleteTurn` | `settled`, `duplicate` | `Unauthenticated`, `TurnLeaseLost` |
|
|
161
|
+
| `health`, `status`, `startLocalPairing`, `approveLocalPairing`, `confirmLocalPairing`, `startKernelPairing`, `relayAction`, `mcp`, `harnesses`, `runTurn` | the daemon's loopback routes ([above](#the-loopback-relay)) | | | |
|
|
162
|
+
|
|
163
|
+
Device endpoints answer `{ _tag, message }` with 400, 401 (with a bearer challenge), 403 or 409.
|
|
164
|
+
|
|
165
|
+
## The daemon's command line
|
|
166
|
+
|
|
167
|
+
```
|
|
168
|
+
eloxiv-daemon [serve] [--port <n>] [--stdin-lifeline] [--headless] [--kernel <url>] [--name <name>]
|
|
169
|
+
[--state-dir <dir>] [--secret-store auto|file|libsecret|keychain|wincred] [--workspace <dir>]
|
|
170
|
+
[--allow-commands terminal,files,browser,computer] [--tools-only]
|
|
171
|
+
eloxiv-daemon pair --kernel <url> [--name <name>] [--runner] [--state-dir <dir>] [--secret-store <kind>]
|
|
172
|
+
eloxiv-daemon status [--state-dir <dir>]
|
|
173
|
+
eloxiv-daemon unpair [--state-dir <dir>]
|
|
174
|
+
eloxiv-daemon approve-client [<pairing id>] [--port <n>] [--state-dir <dir>]
|
|
175
|
+
eloxiv-daemon pairing-code [--port <n>] [--state-dir <dir>]
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
`approve-client` talks to the running daemon: without an id it lists the local clients waiting to pair; with one it approves it and prints the code to type into the client. `pairing-code` also talks to the running daemon (through the control secret) and prints the kernel pairing code it is waiting on, to confirm on the kernel.
|
|
179
|
+
|
|
180
|
+
`serve` (the default) is what the Tauri host runs (`--port <n> --stdin-lifeline`); it prints `ELOXIV_DAEMON_READY port=<n>` on stdout once listening, and everything else on stderr.
|
|
181
|
+
|
|
182
|
+
## Guarantees
|
|
183
|
+
|
|
184
|
+
1. A device is paired only by a signed-in person confirming the code it shows; a code works once, within its lifetime; the credential is issued once and stored on the kernel only as a hash.
|
|
185
|
+
2. The daemon keeps the credential in OS secure storage when it can, else in a 0600 file, and never in its state file; it never hands a kernel credential to a local client or a harness (a harness given workspace tools runs as the same OS user and can read that user's files: see above).
|
|
186
|
+
3. Revoking a device refuses its credential and its agent sessions from their next request; a call in flight that holds them finishes first, and nothing runs under them after the revocation commits. The revocation takes the agent sessions, then the device, then its turns (the global order of authority links), so it never deadlocks with a turn's call.
|
|
187
|
+
4. The daemon answers only on loopback, only to requests naming it by a loopback host, from a trusted origin when an origin is given, with a per-client token; a local client gets a token only for a pairing the host approved, with its code, under a global budget of wrong codes.
|
|
188
|
+
5. Relayed calls go through the invocation path as the device's subject: person-originated for local clients, agent-originated for harnesses (consent applies).
|
|
189
|
+
6. An agent cannot get through a schedule or a turn what consent would refuse it directly: setting either up needs consent, and what it set up runs as the agent.
|
|
190
|
+
7. Only the device's subject may address turns to it; a turn request is durable, and a runner's restart neither loses it nor settles it twice, and a re-run attempt's identical tool calls replay instead of acting again.
|
|
191
|
+
8. Harness adapters never expose the person's subscription credentials to the kernel, and forward no built-in tool's output; a turn has only the Eloxiv tools unless it asks for workspace tools (an ACP agent that cannot be limited runs no turn without them), and nothing it started outlives it.
|
|
192
|
+
9. A follow-up turn resumes only a session a resumable turn of the same person kept on that device, and the daemon resumes only sessions it kept.
|
|
193
|
+
10. A tools-only daemon never gives a harness workspace tools; an organisation that turned workspace tools off gets no such turn queued.
|
|
194
|
+
11. LocalClient (`/client/v1`) is served only by a sidecar composed with an app, only to the host and paired `desktop-app` clients; its person session is a separate secret, its callback is state-checked and single use, and its answers and events carry no kernel credential ([LocalClient](local-client.md#guarantees)).
|
|
195
|
+
|
|
196
|
+
## How an implementation is checked
|
|
197
|
+
|
|
198
|
+
`daemonConformance(harness)` registers (besides what follows) a follow-up turn of each harness resuming its resumable turn's session (and a follow-up of the follow-up), a turn that kept no session and another person's follow-up refused, an unknown session failing without starting the harness; an OpenCode turn without workspace tools refused without starting it, a configured ACP agent declared tools-only (the fake ACP agent) calling an Eloxiv tool with its built-in tool refused and no built-in output forwarded, its follow-up, and OpenCode with workspace tools, its own tool allowed; pairing confirmed by a person (credential in the secret store, not the state file, hashed on the kernel; listed for its person); wrong, expired and reused codes, a second claim, a wrong poll secret and a denied pairing refused; a service-principal pairing refused without `eloxiv.machine.manage`; revocation cutting a running daemon off at its next relayed call, its agent sessions revoked; loopback only, no token, unknown token, foreign Origin and a rebound Host refused, the host secret and a local pairing (code shown only to the host) accepted; a local client's relayed call made as the person, and no response to a local client carrying a device credential or agent session; a fake-harness turn of each stream format calling `workshop.write` through the MCP relay (the note's origin `agent`, the audit's actor the person on surface `mcp`); consent holding a destructive relayed call (and the person's own relayed call not held); a runner serving a turn sent with the typed client from a browser-side SDK (a stranger refused, the workflow finishing `succeeded`), a turn sent by a scheduled job (source `system`, requested by the schedule's owner), and a runner SIGKILLed after its turn's tool call committed and restarted: the turn settles once on attempt 2, with one note, one settlement event and the workflow's outcome.
|
|
199
|
+
|
|
200
|
+
[`packages/daemon/test/`](../../packages/daemon/test) checks the daemon alone: configuration, loopback and per-client authentication, local pairing (wrong, expired, reused codes), the secret stores (file, and libsecret where `secret-tool` works), the stream parsers against the **recorded output of real runs** ([`fixtures/recorded/`](../../packages/daemon/fixtures/recorded)), the fake harness ([`fixtures/fake-harness.mjs`](../../packages/daemon/fixtures/fake-harness.mjs)) against the same formats, cancellation and the time limit, and the compiled sidecar (health, `status`, `unpair`, SIGTERM, the stdin lifeline).
|
|
201
|
+
|
|
202
|
+
**Review regressions** (each seen failing before its fix): [`packages/daemon/test/review.test.ts`](../../packages/daemon/test/review.test.ts) (approval-only local pairing, code format, the global lockout and the start cap, no code in the log, re-pairing and plain-http kernels refused, a 401 not erasing the credential, tool restriction, redaction, the workspace, the host secret, the process group, request timeouts, the kept result across a restart, paged events, release origins), [`daemon-review.test.ts`](../../packages/testing/test/daemon-review.test.ts) (consent through a schedule, consent-marked indirection, parallel wrong codes, a lost pairing answer, stale leases and duplicates, oversized batches, cancelling and revoking mid-turn, a service-principal runner), [`daemon-limits.test.ts`](../../packages/testing/test/daemon-limits.test.ts) (the kernel's limits at their real values, and a turn's deadline) and [`scheduler-consent.test.ts`](../../packages/testing/test/scheduler-consent.test.ts) (an agent's schedule without the consent module).
|
|
203
|
+
|
|
204
|
+
**Real harnesses.** [`packages/testing/test/daemon-real.test.ts`](../../packages/testing/test/daemon-real.test.ts) runs one real Claude Code turn and one real Codex turn through the adapters and the relay, each calling `workshop.write` as the person's agent; then the same through a **headless runner**, as an always-on machine serves them: a real Claude Code turn sent with the client SDK (`devices.sendTurn`, as the browser sends it) and a real Codex turn sent by a scheduled job (`scheduler.create`, source `system`, requested by the schedule's owner), each settling `succeeded` with its tool call and the note written as the person's agent. It needs the CLIs signed in and runs only with `ELOXIV_DAEMON_REAL_HARNESS=1` (`ELOXIV_DAEMON_RECORD_DIR=<dir>` records their raw streams; `ELOXIV_DAEMON_REAL_CLAUDE_MODEL` picks Claude Code's model, default `opus`). It is local by nature: CI has no subscription, so the default suite proves the same paths with the fake harness, which speaks the recorded formats. Each CLI is started through a probe that records the environment it was given: the test fails if any key, token or routing variable (set as canaries in the daemon's environment) reached it, if Claude Code reports an API key or Codex a sign-in other than ChatGPT, or if a CLI is not signed in, so a pass means the person's own subscription served the turn. Claude Code counts only with `apiProvider` `firstParty` and `authMethod` `claude.ai` (its login) or `oauth_token` (a first-party subscription OAuth token, from its credential store or `CLAUDE_CODE_OAUTH_TOKEN`; the person's subscription, not an API key, so the test sets no canary for it and passes a set one by name, as the person would with `ELOXIV_DAEMON_HARNESS_PASS_ENV`), and with `apiKeySource` `none` in its stream. The harness status reports both (`signed in (<authMethod>, <apiProvider>)`). This proof runs locally at each release, not in CI (owner decision, 2026-11-16).
|
|
205
|
+
|
|
206
|
+
**The harness's environment** is an allow-list of the daemon's (`harnessEnv` and `passesToHarness` in [`Harness.ts`](../../packages/daemon/src/Harness.ts)), names compared case-insensitively as Windows does, plus the turn's own (Codex's relay token):
|
|
207
|
+
|
|
208
|
+
| Passed | Variables |
|
|
209
|
+
| --- | --- |
|
|
210
|
+
| The system | `PATH`, `HOME`, `USER`, `LOGNAME`, `SHELL`, `LANG`, `LANGUAGE`, `LC_*`, `TZ`, `TERM`, `COLORTERM`, `NO_COLOR`, `TMPDIR`, `TMP`, `TEMP`, `XDG_*`, `DBUS_SESSION_BUS_ADDRESS` (a keyring), `EDITOR`, `VISUAL`, `PAGER` |
|
|
211
|
+
| Git, SSH and signing | `SSH_AUTH_SOCK`, `SSH_AGENT_PID`, `GIT_*` (`GIT_SSH_COMMAND`, `GIT_CONFIG_*`, `GIT_SSL_CAINFO`, ...), `GPG_TTY`, `GNUPGHOME` |
|
|
212
|
+
| The network | `HTTP_PROXY`, `HTTPS_PROXY`, `NO_PROXY`, `ALL_PROXY`, `NODE_EXTRA_CA_CERTS`, `NODE_TLS_REJECT_UNAUTHORIZED`, `SSL_CERT_FILE`, `SSL_CERT_DIR`, `REQUESTS_CA_BUNDLE`, `CURL_CA_BUNDLE`; Claude Code's certificate store and mTLS client certificate (`CLAUDE_CODE_CERT_STORE`, `CLAUDE_CODE_CLIENT_CERT`, `CLAUDE_CODE_CLIENT_KEY`, `CLAUDE_CODE_CLIENT_KEY_PASSPHRASE`); Codex's `CODEX_CA_CERTIFICATE` |
|
|
213
|
+
| The CLIs' settings | every variable Claude Code documents ([environment variables](https://code.claude.com/docs/en/env-vars), [network configuration](https://code.claude.com/docs/en/network-config)): `CLAUDE_*` (`CLAUDE_CONFIG_DIR`, `CLAUDE_CODE_GIT_BASH_PATH`, `CLAUDE_CODE_SHELL`, ...), `ANTHROPIC_*` model and request settings, and its `DISABLE_*`, `ENABLE_*`, `FORCE_*`, `MAX_*`, `MCP_*`, `OTEL_*`, `BASH_*`, `API_*`, `VERTEX_REGION_*` and unprefixed ones (`DEBUG`, `DO_NOT_TRACK`, `PIP_INDEX_URL`, ...); Codex's `CODEX_*` (`CODEX_HOME`) and `RUST_LOG` |
|
|
214
|
+
| Windows | `SYSTEMROOT`, `WINDIR`, `SYSTEMDRIVE`, `USERPROFILE`, `USERNAME`, `USERDOMAIN`, `HOMEDRIVE`, `HOMEPATH`, `APPDATA`, `LOCALAPPDATA`, `PROGRAMDATA`, `ALLUSERSPROFILE`, `PUBLIC`, the `PROGRAMFILES` and `COMMONPROGRAMFILES` variants, `COMSPEC`, `PATHEXT`, `PSMODULEPATH`, `COMPUTERNAME`, `OS`, `PROCESSOR_ARCHITECTURE`, `NUMBER_OF_PROCESSORS` |
|
|
215
|
+
|
|
216
|
+
**Not passed**, even under a passed prefix:
|
|
217
|
+
|
|
218
|
+
- **Credentials**: any API key, auth, access, refresh, OAuth, ID or bearer token, secret or password (`ANTHROPIC_API_KEY`, `ANTHROPIC_AUTH_TOKEN`, `CLAUDE_CODE_OAUTH_TOKEN`, `OPENAI_API_KEY`, `CODEX_API_KEY`, `CODEX_ACCESS_TOKEN`, `AWS_SECRET_ACCESS_KEY`, `AWS_BEARER_TOKEN_BEDROCK`, `GITHUB_TOKEN`, `NPM_TOKEN`, `MCP_CLIENT_SECRET`, ...), request headers that carry them (`ANTHROPIC_CUSTOM_HEADERS`, `OTEL_EXPORTER_OTLP_HEADERS`, `CLAUDE_CODE_GATEWAY_HINT_HEADERS`), and anything outside the list (`DATABASE_URL`, `GOOGLE_APPLICATION_CREDENTIALS`, `NODE_OPTIONS`, ...). A key would bill the turn to it instead of the person's subscription, and a turn given workspace tools could read it.
|
|
219
|
+
- **Another provider**: base URLs (`ANTHROPIC_BASE_URL`, `ANTHROPIC_*_BASE_URL`, `OPENAI_BASE_URL`), the cloud providers' switches (`CLAUDE_CODE_USE_BEDROCK`, `_VERTEX`, `_FOUNDRY`, `_MANTLE`, `_ANTHROPIC_AWS`), skipping a provider's sign-in (`CLAUDE_CODE_SKIP_*_AUTH`), a provider's resource (`ANTHROPIC_FOUNDRY_RESOURCE`, `ANTHROPIC_VERTEX_PROJECT_ID`): they take the turn off the person's subscription.
|
|
220
|
+
- **Never, named or not**: the daemon's own (`ELOXIV_*`) and a parent Claude Code or Codex session's variables (`CLAUDECODE`, `CLAUDE_CODE_SESSION_ID`, `CLAUDE_CODE_MESSAGING_*`, `CODEX_SESSION_ID`, ...).
|
|
221
|
+
|
|
222
|
+
`CLAUDE_CODE_CLIENT_KEY_PASSPHRASE` is a secret passed **deliberately**: it unlocks the mTLS client key `CLAUDE_CODE_CLIENT_KEY` names, and a network that requires mutual TLS refuses the CLI without it; it identifies the machine to the network, not a billed account, and the key file is already readable by the person's user. An `SSH_AUTH_SOCK` lets a turn with workspace tools use the person's SSH agent, as their own shell does. **`ELOXIV_DAEMON_HARNESS_PASS_ENV`** (comma-separated names) passes more on purpose, a credential included, for a person who points their CLI somewhere (a gateway and its key); such a turn is then not on their subscription. [`harness.test.ts`](../../packages/daemon/test/harness.test.ts) checks every variable Claude Code documents (a fixture of the 407, [`claude-code-env-vars.txt`](../../packages/daemon/fixtures/claude-code-env-vars.txt)) against the expected passed and refused sets, Codex's and the system's settings, and the environment a started CLI really receives.
|
|
223
|
+
|
|
224
|
+
## Integrating with the agent runtime
|
|
225
|
+
|
|
226
|
+
The kernel's agent runtime (AgentRuntime, ModelProvider) runs its own model loop; a harness runs a whole loop of its own on the person's subscription, so it plugs in as an alternative **run executor**, not a ModelProvider (which returns tool calls unexecuted). It is wired ([`agent/Run.ts`](../../packages/kernel/src/agent/Run.ts), proven end to end with the fake harness in [`agent-device.test.ts`](../../packages/testing/test/agent-device.test.ts)):
|
|
227
|
+
|
|
228
|
+
- `agent.send` with `device` (`{ deviceId, harness?, model?, cwd?, timeoutMs?, workspaceTools? }`) starts a run that executes on that device instead of the deployment's model. The run's journalled steps: `device/call` (the person's message and the device's options), `device/send` (`devices.sendTurn` as the person's agent, through the conversation's agent session: the person's consent applies, and a held call suspends the run as a tool call's does, then `device/send/decided` sends it once), `device/wait`, `device/result`.
|
|
229
|
+
- The turn records its parent run (`eloxiv_devices.turn.parent_run_id`, module migration `0001_parent_run`), set by the run in the same transaction as its wait, holding the turn's row: a settlement committed first is seen there, one committed after finds the parent and the wait. `getTurn` shows it (`parentRunId`), and the run's events name the turn: its `devices.sendTurn` call's `tool-result` carries `result.output.turnId` (`agent-device.test.ts`).
|
|
230
|
+
- The `devices.settled` reaction signals `eloxiv.device-turn` and then the waiting parent run (`wakeRunForTurn`). A cancelled run cancels its turn (`devices.cancelTurn`, as the person's agent, not refused by the guard that refuses a cancelled run's tool calls), and nothing more of the turn runs (`agent-device.test.ts`).
|
|
231
|
+
- Turn events map to run events (`text` to a `model-step`'s text, `tool-call` and `tool-result` to the run's, each marked `device: true`), the turn's result is the run's reply (an assistant message in the conversation) and its result, and `TurnUsage` is the run's usage and a Metering usage record with provider `device:<harness>`, recorded once per turn. Subscription turns consume the person's subscription, not the deployment's model budget: no budget counts `device:` usage.
|
|
232
|
+
- The turn's tool calls already go through the invocation path as the person's agent, with idempotency per turn.
|
|
233
|
+
|
|
234
|
+
## Not yet guaranteed
|
|
235
|
+
|
|
236
|
+
- **Approval on the host side needs a UI** in the desktop host (the template does not show pairing requests yet); `eloxiv-daemon approve-client` works everywhere.
|
|
237
|
+
- **The Tauri template does not yet pass a host secret** (`ELOXIV_DAEMON_HOST_SECRET`) or show local pairing codes: the shell in the desktop app pairs as a local client, approved with `eloxiv-daemon approve-client`. Generating the secret per launch and handing it to the webview (with `eloxiv_daemon`) is the template's next change.
|
|
238
|
+
- **Keychain and Credential Manager** are implemented but exercised only on their platforms, which CI does not run; libsecret and the file store are tested here.
|
|
239
|
+
- **A real CLI orphaned by a SIGKILLed daemon** keeps running until it next writes (the daemon, killed, cannot kill its group); its relay token died with the daemon, so it can no longer act. A daemon that stops or ends a turn normally kills the whole group.
|
|
240
|
+
- **Pairing UI**: the kernel's verification page only explains where to confirm the code; the confirmation screen is registry UI (not built). People confirm with `confirmPairing` from the shell or the API.
|
|
241
|
+
- **Audit records have no origin column**: an agent's relayed call is recognisable by its surface (`mcp`) or, on HTTP, by its credential (an agent session), not by a field.
|
|
242
|
+
- **Turns on a desktop daemon** run only from local clients (`POST /turns`); a desktop daemon does not poll the turn queue unless started `--headless` (it does serve device commands once paired, when enabled).
|
|
243
|
+
- **Real ACP turns** have not been run with a signed-in OpenCode or another ACP agent: the adapter is proven against the fake ACP agent ([`fixtures/fake-acp-agent.mjs`](../../packages/daemon/fixtures/fake-acp-agent.mjs)), and OpenCode's handshake was checked offline. OpenCode is not counted as tools-only: isolating its configuration and plugin discovery would be needed first.
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# Db/Tx
|
|
2
|
+
|
|
3
|
+
The database transaction an action handler (or an outbox subscriber) runs in, and the roles it runs as. Module isolation (decision "Module isolation is enforced by the database") and decision 2's enforcement live here: a handler gets SQL on the invocation's own transaction, as its module's runtime role, under row-level security generated from the compiled Cedar policy.
|
|
4
|
+
|
|
5
|
+
- Kind: kernel service. Version 1.0.0.
|
|
6
|
+
- Schema: [`packages/contracts/schema/contracts/DbTx.json`](../../packages/contracts/schema/contracts/DbTx.json) (source [`DbTx.ts`](../../packages/contracts/src/contracts/DbTx.ts)).
|
|
7
|
+
- Implementation: `HandlerContext` and `SubscriberContext` in [`packages/kernel/src/Module.ts`](../../packages/kernel/src/Module.ts); the role switch and write-log checks in [`Invocation.ts`](../../packages/kernel/src/Invocation.ts) and [`Outbox.ts`](../../packages/kernel/src/Outbox.ts); roles, policies, triggers and setup's refusals in [`db/Bootstrap.ts`](../../packages/kernel/src/db/Bootstrap.ts), [`db/KernelSchema.ts`](../../packages/kernel/src/db/KernelSchema.ts) and [`policy/Rls.ts`](../../packages/kernel/src/policy/Rls.ts).
|
|
8
|
+
- Kit: `@eloxiv/testing/conformance/DbTx` ([source](../../packages/testing/src/conformance/DbTx.ts)).
|
|
9
|
+
|
|
10
|
+
## Operations
|
|
11
|
+
|
|
12
|
+
### `sql`
|
|
13
|
+
|
|
14
|
+
Run a statement in the invocation's transaction, as the module's runtime role. Input `SqlStatement` (`text` with `$1` placeholders, `params`); output the rows. Errors: `Forbidden` when the database refuses the statement (row-level security or privileges), `ActionFailed` for anything else the handler does not handle. In TypeScript it is `ctx.sql`, an Effect `SqlClient`.
|
|
15
|
+
|
|
16
|
+
### `emit`
|
|
17
|
+
|
|
18
|
+
Write an event to the outbox in the same transaction (`ctx.emit(event, payload)`). Input `EmittedEvent` (`type`, encoded `payload`). It exists exactly when the call commits; see [Outbox](outbox.md). A module emits only the events its manifest declares, encoded by the declared payload schema: emitting any other (another module's) fails the call as a defect, so no module can start another's triggers as if that module had emitted the event.
|
|
19
|
+
|
|
20
|
+
## Records
|
|
21
|
+
|
|
22
|
+
- **`HandlerContext`**: `actor` (user, organisation, email, roles, groups, permissions) and `invocationId`, besides the handler's decoded input.
|
|
23
|
+
- **`SubscriberContext`**: `eventId` (subscribers deduplicate effects outside the database on it) and `orgId`.
|
|
24
|
+
- **`ModuleRoles`**: each module owns a Postgres `schema` (default: its name) and two NOLOGIN roles: `eloxiv_mod_<module>`, the **runtime role** handlers and subscribers run as, with `SELECT, INSERT, UPDATE, DELETE` on its own tables only; and `eloxiv_own_<module>`, the **owner**, which owns the schema and tables and is used only by migrations. The kernel's own role can switch into runtime roles but inherits nothing from them and is not a member of owner roles.
|
|
25
|
+
- **`InvocationContext`**: who acts in the current transaction (`actor`, `org`, `action`; `$system` and `$subscriber` for subscribers), keyed by the top-level transaction. The generated policies read it; module roles cannot write it.
|
|
26
|
+
- **`WriteLogEntry`**: one row a transaction inserted, updated or deleted in a module table (`schema`, `table`, `pk`, `op`), recorded by a trigger, savepoints included. The invocation path checks it before commit.
|
|
27
|
+
|
|
28
|
+
## Guarantees
|
|
29
|
+
|
|
30
|
+
1. **The invocation's transaction.** A handler's statements run in the same transaction as the idempotency claim, the record checks, the audit record and the outbox events. If the call fails, everything the handler wrote and emitted is rolled back.
|
|
31
|
+
2. **The module's runtime role.** The kernel runs the handler after `SET LOCAL ROLE eloxiv_mod_<module>`. A handler that leaves another role in place fails as `Forbidden` ("The handler changed its database role") and is rolled back. The kernel's helpers never switch the role while the handler runs, since a switch would also apply to the handler's concurrent statements on the same transaction: `ctx.settings` and `ctx.flags` read what the runtime role cannot through the platform read functions (`eloxiv_platform.*`, `SECURITY DEFINER`, owned by `eloxiv_platform_read`, for the caller the invocation context records; [Settings](settings.md#operations)), `ctx.queryView` reads as the runtime role it already has, `ctx.references` reads another module's record as its owner's role inside one statement (a `DO` block that switches and switches back; [Invocation](invocation.md#entity-references)), and `ctx.workItems` and `ctx.notify` buffer until the handler returns. The helpers that must switch the connection's role while they run (`ctx.files`, `ctx.ingestion`, `ctx.sharing`, `ctx.history`, and `ctx.workItems.put`, which takes the record's lock as the kernel) run exclusively: while the handler runs, every statement it sends through `ctx.sql` takes the call's one permit (a stream, for as long as it is read), and a helper holds that permit for its whole run on the same connection and transaction, so no statement of the handler's runs as the kernel's or another module's role (`db/HandlerGate.ts`; [`handler-gate.test.ts`](../../packages/testing/test/handler-gate.test.ts), with `ctx.files.list`). `ctx.connections` is run the same way. The helpers that only buffer (`ctx.notify`, `ctx.progress`, `ctx.analytics`) or read without switching (`ctx.settings`, `ctx.flags`, `ctx.queryView`, `ctx.references`) are not, so a handler may call them while it reads a stream of its own. A role-switching helper called while the handler reads a stream waits for the stream to end, as any statement on the connection already does (the driver holds the connection for a stream's whole read).
|
|
32
|
+
3. **Row-level security on every statement.** Every module table has forced row-level security generated from the compiled policy: reads see what the caller may read or what the current action may act on; inserts and updates must satisfy the current action's filter for the new row (`WITH CHECK`), updates and deletes for the old row. Policies see which one through the context attribute `row` (`"old"` or `"new"`, declared for every action in the generated Cedar schema): a policy that does not test it is the same for both, one that does can grant the authority to change a record from its current state alone and constrain separately what the change leaves behind. The kernel's own checks use the same split: targets are locked and authorised with `"old"`, the rows an action wrote with `"new"`, and a call is denied up front only if both are constant `false`. A statement that would pass through a forbidden state is refused when it runs, even if a later statement restores the row. Exact targeted actions may insert or update only their declared targets (`eloxiv_ctx.is_target`).
|
|
33
|
+
4. **The write log is checked.** A write to a table no entity contract governs is refused; so is any write outside the action contract (see [Invocation](invocation.md), guarantees 3 to 6).
|
|
34
|
+
5. **What a handler may not do.** Read or write another module's schema, the kernel's tables or the auth tables; create objects outside its schema, or any table, function or trigger inside it; `TRUNCATE`; disable row-level security or change policies; change a primary key. Setup refuses module migrations that install deferred triggers, `SECURITY DEFINER` functions, rules, unsafe views, foreign keys with `CASCADE`, `SET NULL` or `SET DEFAULT` actions, `BEFORE UPDATE` row triggers other than the kernel's key guard, casts to or from the module's types or through its functions, foreign tables, base types with their own input and output functions, or default privileges, and re-installs the generated policies on every table.
|
|
35
|
+
6. **Subscribers.** Each delivery runs in its own savepoint, as the subscribing module's runtime role, acting as `$system` limited to the event's organisation: row-level security lets it read and write only that organisation's rows.
|
|
36
|
+
|
|
37
|
+
## How an implementation is checked
|
|
38
|
+
|
|
39
|
+
`dbTxConformance(start)` registers, against the fixture app:
|
|
40
|
+
|
|
41
|
+
- *the transaction a handler sees*: the handler's `current_user` is the module's runtime role, each call has its own transaction, a handler that crashes after writing and emitting leaves nothing, unreadable rows are filtered out of the handler's reads;
|
|
42
|
+
- *what a handler may not do*: leave its role, pass through a forbidden state, install a deferred trigger, truncate;
|
|
43
|
+
- *subscribers*: run as their own module's role, in the event's organisation;
|
|
44
|
+
- *module isolation by database role* (`moduleIsolationConformance`, also exported on its own): each runtime role uses its own schema, cannot read or write the other module's or the kernel's private tables (those the subject names in `privateTables`: for the Eloxiv kernel, its `eloxiv` tables and the auth tables), cannot create objects elsewhere or run `TRUNCATE`, DDL, triggers or policy changes; and the role the kernel's own pool actually connects as (`kernelRole()`, its `current_user`) is no superuser, does not bypass row-level security and reaches no module table.
|
|
45
|
+
|
|
46
|
+
The Eloxiv kernel runs it in `packages/testing/test/dbtx.test.ts`; `registry/test/isolation.test.ts` runs the isolation checks against the registry's `hello` and `notes` modules. Setup's refusals are proven in `packages/testing/test/setup.test.ts`, and the row-level-security and policy agreement in `packages/testing/test/policy.test.ts`.
|
|
47
|
+
|
|
48
|
+
## Not yet guaranteed
|
|
49
|
+
|
|
50
|
+
- **Module code runs without the kernel's services.** Guaranteed: an action's handler, a subscriber, a module workflow's body and step bodies (however the workflow was started: directly, by an event trigger, by Ingress or by a schedule), a connector's `identify` and capability operations, and every decode and encode of a module-declared schema (action input and output, event payloads, workflow input, output, step results and signals) run with the kernel's services (`@eloxiv/kernel/*`), the database client itself, the cluster and workflow engine, the HTTP request, the kernel's Scope and its layer memo map removed from their context; each gets a scope of its own, closed under that same context, so its finalizers see no more. `yield* Secrets` in module code is a missing service. The kernel's own modules (`defineKernelModule`, not exported) run the handler functions the kernel recorded, whatever the module object holds later. Synchronous module functions (`handler.input`, `classify`, `oauth`, `make`, a connector's request objects) cannot reach a context at all.
|
|
51
|
+
- **What this is not.** Registry and app modules, and connectors, are the app's own code: trusted. Running them without the kernel's services protects against mistakes (a handler reaching for `Secrets` because it is there), not against code written to get round it: in-process JavaScript can import what it likes, read the environment and open its own database connection, and a handler can `RESET ROLE` on the kernel's. Untrusted, agent-made (MAKE) modules run in the sandbox (backlog 3); the sandbox is the boundary for untrusted code. Not guaranteed: protection from a handler that deliberately runs `RESET ROLE`, acts as the kernel and switches back (only a role left changed is caught), from code that captures a context through means the kernel does not run (a global it sets up itself), or from anything outside the kernel's API.
|
|
52
|
+
- **Constraint side channels** (backlog 1): closed but for two stated limits: a key the caller names discloses whether a record holds it, and deleting a referenced record fails while any record references it, readable or not ([Invocation](invocation.md#not-yet-guaranteed)).
|
|
53
|
+
- **Atomic migrate-and-harden** (backlog 11): each module's migrations commit on its owner's session, with the module closed, before the hardening transaction; a failure in between leaves the module closed (never open) until a setup succeeds ([Release](release.md), guarantee 2).
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
# Delegation
|
|
2
|
+
|
|
3
|
+
Sub-agents of the one agent: a run hands a self-contained task to a child run with a narrower toolset and its own, smaller limits, as a child durable execution; the child's final answer returns to the parent as the tool's result. A run can also start a team: several such sub-agents (seats) at once, which message each other and their lead through the run while the lead waits for all or any of them. There is no agent-to-agent protocol between modules: a sub-agent is a seat of the same agent, acting as the same person.
|
|
4
|
+
|
|
5
|
+
- Kind: kernel service. Version 1.2.0 (1.1.0: delegation depth, `maxDelegationDepth`; custom agent profiles, `profile`; a sub-agent runs in its parent's mode. 1.2.0: teams, the `team` tool; a sub-agent whose parent has ended stops).
|
|
6
|
+
- Schema: [`packages/contracts/schema/contracts/Delegation.json`](../../packages/contracts/schema/contracts/Delegation.json) (source [`Delegation.ts`](../../packages/contracts/src/contracts/Delegation.ts)).
|
|
7
|
+
- Implementation: `startChild` and the `delegate/<i>/<call>` step in [`packages/kernel/src/agent/Run.ts`](../../packages/kernel/src/agent/Run.ts); teams in its "teams" section (`teamCall`, the `team/<i>/<call>[/<k>]` steps); the `agent.child` and `agent.team` reactions.
|
|
8
|
+
- Kit: `@eloxiv/testing/conformance/Delegation` ([source](../../packages/testing/src/conformance/Delegation.ts)), run by [`packages/testing/test/agent-delegation.test.ts`](../../packages/testing/test/agent-delegation.test.ts).
|
|
9
|
+
|
|
10
|
+
## Operations
|
|
11
|
+
|
|
12
|
+
| Operation | Input | Output | Errors |
|
|
13
|
+
| --- | --- | --- | --- |
|
|
14
|
+
| `delegate` | the agent's `delegate` tool: `task`, `tools` (tool names, from the choices its schema lists; may be left out with a `profile`), optional `profile` (a custom agent's name), optional `limits` (`maxSteps`, `maxTokens`, `maxWallMs`) | `runId` (the child's), `status`, `result` | `ToolNotAllowed`, `InvalidInput` (a token limit too small for one model call, an unknown profile, neither tools nor a profile), `LimitReached` (as the tool's result) |
|
|
15
|
+
| `team` | the agent's `team` tool: `action` `spawn` (with `task`, `tools`, `profile`, `limits` as for `delegate`, and a `name`), `wait` (optional `seats`, `until`: `all` or `any`), `send` (`to`: a seat's id or `lead`, `text`) or `list` | `spawn`: the seat's id, name and limits; the others: `finished` (seats' answers, each with what it `spent`), `messages` (`from`, `name`, `text`), and `running` (`wait`), `sent` (`send`) or the team (`list`: `lead`, `seats`, `team`) | as for `delegate`; `InvalidInput` (an unknown action or seat, a message to someone outside the team or who has finished) |
|
|
16
|
+
| `children` | `runId` (`GET /agent/runs/<id>/children`) | the child runs (a run's seats too) | `UnknownRun` |
|
|
17
|
+
|
|
18
|
+
## What happens
|
|
19
|
+
|
|
20
|
+
The tool's schema lists the names a sub-agent may be given (`tools.items.enum`): exactly the other tools offered to the model in that call, so never an action the policy hides from the person (the app's or an organisation's MAKE module's: the offered tools are filtered by `reach`, which covers both), and its description says what the limits count. (A real model, offered free-form names, wrote `functions.notebook_write`; another asked for `maxTokens: 1500`.)
|
|
21
|
+
|
|
22
|
+
1. The parent's `delegate/<i>/<call>` step checks the request: every tool must be one the parent may use, never `tool_search`, and `delegate` only while the child would still be within the deployment's depth (below). Otherwise the model gets `ToolNotAllowed` and no child exists. With a `profile` and no `tools`, the child gets the profile's tools that the parent may use.
|
|
23
|
+
2. The child's limits are the requested ones capped at what the parent has left: steps (`maxSteps` minus every model call the parent has spent so far, its own, its compactions' and earlier sub-agents'; default at most 8), tokens (`maxTokens` minus everything spent so far) and wall time. A token limit that cannot hold one model call's worst case (the deployment's `maxOutputTokens` alone) creates no child: the model gets `InvalidInput` saying so when its own request was too small, or `LimitReached` when the parent has too little left.
|
|
24
|
+
3. In one transaction, with the parent's row locked (a parent cancelled meanwhile starts no child): the child run (`kind: subagent`, `parentRunId`, its `tools` and `limits`), its own conversation (sharing the parent conversation's agent session), the task as its first message, the parent marked `waiting`, a `delegated` event, and `agent.runRequested` in the outbox. The child's id is derived from the parent's step, so a re-run of the step finds it.
|
|
25
|
+
4. The child runs as any run (its own journalled steps), offered only its tools; a call to anything else is refused with `ToolNotAllowed` and nothing runs.
|
|
26
|
+
5. When the child finishes it emits `agent.runFinished`; a kernel reaction signals the parent, whose `tool/<run>/<i>/<call>` step stores `{ runId, status, result }` as the tool's result and records what the child spent (its model calls and tokens, with its own sub-agents' at any depth), which the parent's limits then count. Cancelling a run cancels its whole subtree: every sub-agent below it, at any depth, reads every ancestor's flag (holding their rows, the oldest first) wherever it reads its own, and the kernel's reaction records the flag on each of them and wakes each one that waits.
|
|
27
|
+
|
|
28
|
+
## Depth and custom agents
|
|
29
|
+
|
|
30
|
+
`KernelApp.agent.maxDelegationDepth` (default 1, at most 4) is how deep delegation goes: the person's run is at depth 0, its sub-agents at 1, theirs at 2. A run at depth d may delegate while d is below the maximum, and may give its sub-agent the `delegate` tool only while d + 1 is too. With the default, sub-agents do not delegate further. Each run records its depth when it is queued (`run.options`), so the limit holds across restarts; the delegate tool's choices include `delegate` only when it could be given.
|
|
31
|
+
|
|
32
|
+
`KernelApp.agent.profiles` declares custom agents: a `name`, a `description` (shown to the model in the delegate tool's description, and its `profile` choices), `instructions` (given to the sub-agent after the kernel's own) and default `tools`. A sub-agent started with a profile records it and runs with its instructions; its tools are always narrowed to the delegating run's, so a profile never widens what a sub-agent can do. A sub-agent runs in its parent's mode: a plan-mode run's sub-agents plan too ([AgentRuntime](agent-runtime.md#plan-mode)).
|
|
33
|
+
|
|
34
|
+
The parent's `delegated` event carries the child's `depth` and `profile`, and the children route lists them: what a client shows as a live delegation (its status is the child run's, followed like any run).
|
|
35
|
+
|
|
36
|
+
## Teams
|
|
37
|
+
|
|
38
|
+
The `team` tool is offered wherever `delegate` is. `spawn` starts a seat exactly as `delegate` starts a sub-agent (the same checks of its tools, profile and depth, the same transaction, as the same person under the same authority, in the run's mode), except that the run does not wait: the seat's id is the tool's result at once, and the seat's limits are reserved from the run's until it collects the seat's answer. The run keeps one model call of its own, so a seat gets at most what the run has left less one; without `limits`, up to 8 model calls but at most half of those, and half the tokens left. The parent's `seat-spawned` event carries the seat's id, `name`, task, tools, limits and depth.
|
|
39
|
+
|
|
40
|
+
A seat runs as any sub-agent, with the `team` tool always offered for its messages (`wait`, `send`, `list`); it starts seats of its own only when it was given `team`, within the depth. A run may give `team` to a sub-agent (and is offered it as a choice) only when it may start seats itself, so a seat's messaging tool never becomes a sub-agent's way to start seats. Its instructions say it is a seat and that its answer goes to its lead.
|
|
41
|
+
|
|
42
|
+
- `send` records the message on the sender's stream (`team-message`: `to`, `text`), holding the recipient's row, and the kernel wakes the recipient if it waits. A run may message its lead (`"lead"`), its own seats and its lead's other seats, while they run.
|
|
43
|
+
- `wait` is a journalled step that, holding the run's row, reads its seats and the messages addressed to it: when `all` (the default) or `any` of the seats it watches (its own, or those in `seats`) finished, or a message arrived, it returns; otherwise it records the wait (`wait.team`) and waits durably for a signal: a seat's end (the `agent.child` reaction) or a message (`agent.teamWake`). A message or an end that committed before the step is seen by it; one after finds the recorded wait. A seat with no seats of its own waits for a message. A run with no seats and no messages returns at once.
|
|
44
|
+
- Every `team` result carries the messages not yet delivered to the run and the answers of its seats not yet collected, each with what the seat is charged with everything below it: the run's limits then count that instead of the reservation. A run below the seat that has not ended, or still has a model call open (a reply in flight, or one lost to a crash and not yet metered), is charged its whole limits, so what it may still spend stays reserved and a late or abandoned call never takes the lead past its limits; a delegated sub-agent's answer is charged the same way. Which messages and answers were delivered follows from the run's journalled results alone, and a step re-run after its result committed returns the stored result, so nothing is delivered twice or lost. A `send` re-run after its message committed returns its success (also when its recipient has finished since) and publishes no second wake.
|
|
45
|
+
- When a run ends (answered, stopped, failed or cancelled) with seats still running, they are cancelled with it: the transaction that records its end asks for its subtree's cancellation (`agent.cancelRequested`), and every sub-agent reads that an ancestor has ended wherever it reads a cancellation, so a seat left running, also one resumed after a restart, stops at its next check (a reply in flight is metered and discarded). A run should wait for its seats before it answers; the tool's description says so.
|
|
46
|
+
|
|
47
|
+
## Guarantees
|
|
48
|
+
|
|
49
|
+
1. A sub-agent can use only the tools it was given, each one its parent may use.
|
|
50
|
+
2. A sub-agent acts as the same person through the same agent session, under its parent's chain of authorities ([Invocation](invocation.md#authority)), asserted as it is created and at every call: the invocation path applies the person's permissions and consent to its calls, so it can never do more than its parent could, nor outlive what its parent was asked under.
|
|
51
|
+
3. A sub-agent's limits never exceed what its parent has left, and what it spends, with everything below it, counts against its parent's limits: a run and its whole subtree together never pass the run's `maxSteps` or `maxTokens`. Seats running at once share what is left: each one's limits are reserved from its lead's until its answer is collected.
|
|
52
|
+
4. The child is a durable execution of its own; the parent waits durably and resumes with its answer, also across restarts. A lead waiting on its team resumes across restarts too, and collects each seat's answer and each message once.
|
|
53
|
+
5. Delegation never goes deeper than `maxDelegationDepth`, and a profile never gives a sub-agent a tool its parent could not use.
|
|
54
|
+
6. Cancelling a run cancels its whole subtree, every seat of every team in it, wherever each waits; a run that ends ends its seats still running, also those a restart left running.
|
|
55
|
+
|
|
56
|
+
## How an implementation is checked
|
|
57
|
+
|
|
58
|
+
`delegationConformance(start)`: the delegate tool's choices are the other tools offered (never `notebook_seal`, which the policy hides); a sub-agent given `notebook_write` writes a page (offered exactly that tool; audited as the person on the `agent` surface) and its answer reaches the parent; a sub-agent's call outside its set is refused and nothing runs; a request for a tool the parent lacks, or for `delegate`, creates no child; a sub-agent given `notebook_seal` is refused by policy, as the person would be; requested limits are capped; a token limit too small for one call creates no child and tells the model why. With a real model ([`registry/test/agent-real-model.test.ts`](../../registry/test/agent-real-model.test.ts)): the model delegates on its own, the child is offered only its tool, writes the page as the person on the `agent` surface, and its answer returns to the parent.
|
|
59
|
+
|
|
60
|
+
Teams ([`agent-teams.test.ts`](../../packages/testing/test/agent-teams.test.ts)): two seats run at once, one waiting while the other messages it and then the lead, and the lead collects both answers; `wait` with `until: any` returns with the first, and the lead's answer ends the seat still running (its late reply discarded, its write never run); a seat's tool the lead lacks starts no seat, a seat's call outside its set is refused, and its write is audited as the person on the `agent` surface; cancelling the lead cancels a seat waiting for a message and one waiting for consent (a late approval runs nothing); a seat's reservation leaves a second seat nothing, and the run with its team makes exactly its 12 model calls; a seat collected while its own seat's model call is held in flight leaves that one's steps and tokens reserved, so the run, its seat and the late call stay within the run's steps and tokens; a seat given only `delegate` cannot hand a sub-agent `team`, nor is it offered as a choice. Across SIGKILL ([`agent-restart.test.ts`](../../packages/testing/test/agent-restart.test.ts)): a team killed while its lead waits on a seat whose model call is in flight completes after the restart with both answers, each page written once (a send whose result a crash lost, its recipient finished before the replay, returns its success with one message and one wake) and every other model call made once; a seat still running when its lead ended, killed in flight, ends cancelled after the restart without another model call.
|
|
61
|
+
|
|
62
|
+
Depth and profiles ([`agent-policies.test.ts`](../../packages/testing/test/agent-policies.test.ts)): cancelling the person's run ends a sub-agent's sub-agent waiting for consent, and a late approval runs nothing; a sub-agent's sub-agent's model calls count against the person's run's step limit; a sub-agent given `delegate` within the depth delegates once more, its own sub-agent is refused `delegate` and never offered it; a profile's sub-agent gets the profile's instructions and its tools narrowed to the parent's, and cannot delegate without the tool.
|
|
63
|
+
|
|
64
|
+
## Limits
|
|
65
|
+
|
|
66
|
+
- Seats that wait on each other's messages, or a lead that waits on seats that wait for its own message, wait until one of them is cancelled (or the person cancels the run): a wait has no deadline of its own, as a consent wait has none.
|
|
67
|
+
- What a run below a collected seat had left when it was charged its whole limits is never given back to the lead, even once that run ends.
|
|
68
|
+
- A seat's answer is collected by the lead's next `team` call; one still running when its lead ends is cancelled, never collected, and its reservation stays counted against the ended run.
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
# DeviceControl
|
|
2
|
+
|
|
3
|
+
Paired devices and what runs on them, extending [Daemon](daemon.md): the organisation's devices, listed to their person and its administrators and revoked by them; the **sessions** on each device (the shell, a browser extension, a computer-use helper or a CLI connected to its daemon, harness turns, terminals); **device commands** (one operation on the device's terminal, the files of its workspace, a browser or the computer); what each device **offers** now; and the **push subscription** of the host beside it.
|
|
4
|
+
|
|
5
|
+
- Kind: kernel service. Version 1.3.0 (1.2.0: before the `desktop-app` session kind, decision 14).
|
|
6
|
+
- Schema: [`packages/contracts/schema/contracts/DeviceControl.json`](../../packages/contracts/schema/contracts/DeviceControl.json) (source [`DeviceControl.ts`](../../packages/contracts/src/contracts/DeviceControl.ts); records in [`Devices.ts`](../../packages/contracts/src/Devices.ts)).
|
|
7
|
+
- Implementation: the management, command, capability and push operations in [`packages/kernel/src/devices/Devices.ts`](../../packages/kernel/src/devices/Devices.ts) (tables `eloxiv.device_session`, `eloxiv.device_push` (kernel migration `0105_device_push`), `eloxiv_devices.command` (devices migration `0004_commands`)); the actions in [`module.ts`](../../packages/kernel/src/devices/module.ts); the daemon's side in [`Daemon.ts`](../../packages/daemon/src/Daemon.ts), [`Commands.ts`](../../packages/daemon/src/Commands.ts) and [`Terminals.ts`](../../packages/daemon/src/Terminals.ts).
|
|
8
|
+
- Kit: `@eloxiv/testing/conformance/DeviceControl` ([source](../../packages/testing/src/conformance/DeviceControl.ts)), sharing the Daemon kit's harness, run by [`packages/testing/test/daemon.test.ts`](../../packages/testing/test/daemon.test.ts).
|
|
9
|
+
|
|
10
|
+
## Operations
|
|
11
|
+
|
|
12
|
+
| Operation | Where | Who | What |
|
|
13
|
+
| --- | --- | --- | --- |
|
|
14
|
+
| `listDevices` | `POST /kernel/devices/listDevices` | a signed-in person | their devices (paired to them, or confirmed by them); with `eloxiv.machine.manage`, all of the organisation's. `DeviceInfo`: id, subject and its kind, who paired it, name, kind, platform, capabilities, created, last seen, revoked, whether it registered push. Never a credential or a push token |
|
|
15
|
+
| `revokeDevice` | `POST /kernel/devices/revokeDevice` | the device's subject, the person who paired it, or `eloxiv.machine.manage` | revokes it (see [Daemon, revocation](daemon.md#revocation)): its unfinished turns and commands fail and its push subscription is deleted; audited as `eloxiv.devices.revokeDevice` |
|
|
16
|
+
| `reportSessions` | `POST /kernel/device/sessions` | the device credential | the device's sessions, replacing its last report (sessions it no longer lists are ended); at most 100 |
|
|
17
|
+
| `listSessions` | `POST /kernel/devices/listSessions` | as `revokeDevice` | the sessions the device reported, open ones first |
|
|
18
|
+
| `sendCommand` | action `devices.sendCommand` (every surface) | the device's subject | queue one command (below); an agent's call needs consent |
|
|
19
|
+
| `getCommand` | action `devices.getCommand` | whoever sent it, or the device's subject | the command, its status and its result |
|
|
20
|
+
| `cancelCommand` | action `devices.cancelCommand` | whoever sent it, or the device's subject | cancel it ([below](#cancellation)) |
|
|
21
|
+
| `devices.listDevices` | action (every surface, agents included) | a person | their own devices that are not revoked, with their harnesses and the command kinds they offer now |
|
|
22
|
+
| `nextCommand` | `POST /kernel/device/commands/next` | the device credential | take the oldest queued command of the kinds the device serves now (a long poll, at most 30 s) |
|
|
23
|
+
| `completeCommand` | `POST /kernel/device/commands/complete` | the device credential, the command's lease | settle it once with its result |
|
|
24
|
+
| `checkCommand` | `POST /kernel/device/commands/check` | the device credential, the command's lease | whether a command it took should stop: a cancellation was asked, or it no longer holds it |
|
|
25
|
+
| `reportCapabilities` | `POST /kernel/device/capabilities` | the device credential | what the device offers now (harnesses, command kinds, tools-only), replacing its last report |
|
|
26
|
+
| `registerPush` | `POST /kernel/device/push` | the device credential | the host's push subscription (Web Push, APNs or FCM), or null to remove it; one per device |
|
|
27
|
+
| `availability` | `GET /capabilities` on the daemon | a local client | each command kind's availability (enabled, available, why not), whether terminals get a PTY, the tools-only profile |
|
|
28
|
+
| `computerUse` | `GET /computer-use` on the daemon | a local client | `{ available, reason }`: available while a computer-use companion is connected and computer commands are enabled |
|
|
29
|
+
|
|
30
|
+
Management needs a Better Auth session: device credentials, API tokens, OAuth tokens and agent sessions are refused (401), so a device cannot list or revoke devices. Machine credentials are the same: [MachineIdentity](machine-identity.md)'s rule. The kernel exposes the push subscriptions of a person's devices that are not revoked to kernel code (`Devices.pushSubscriptions`), for a push [NotificationChannel](notification-channel.md) that a host provides.
|
|
31
|
+
|
|
32
|
+
## Sessions
|
|
33
|
+
|
|
34
|
+
`DeviceSession`: `id`, `kind` (`shell`, `browser-extension`, `cli`, `computer-use`, `harness`, `terminal`), `label`, `startedAt`, `endedAt`, `detail` (a companion's origin while it is connected, a harness's kind, a terminal's `pty` or `pipes`). The daemon reports a session for each paired local client (open until it is unpaired), for each harness turn (ended when the turn ends) and for each terminal (ended when it closes), plus the last 20 ended ones, whenever they change; it also serves them at `GET /sessions` to its local clients.
|
|
35
|
+
|
|
36
|
+
## Device commands
|
|
37
|
+
|
|
38
|
+
A command is one operation on a paired device, sent by its person (or their agent, with consent) and run there at most once:
|
|
39
|
+
|
|
40
|
+
| Kind | Operations | Served by |
|
|
41
|
+
| --- | --- | --- |
|
|
42
|
+
| `terminal` | `terminal.exec` (`command`, `cwd?`): one shell command; the result is its exit code, stdout and stderr (64 KiB each at most) | the daemon, in its workspace |
|
|
43
|
+
| `files` | `files.read`, `files.write`, `files.edit` (`oldText` must occur once), `files.list`, `files.search` (a literal string; 200 matches at most) | the daemon, in its workspace |
|
|
44
|
+
| `browser` | `browser.observe`, `browser.navigate`, `browser.click`, `browser.type`, `browser.scroll` | a paired `browser-extension` companion |
|
|
45
|
+
| `computer` | `computer.observe`, `computer.click`, `computer.type`, `computer.key`, `computer.scroll` | a paired `computer-use` companion |
|
|
46
|
+
|
|
47
|
+
Each operation's input is a schema (`COMMAND_INPUTS`), checked when the command is sent. **A kind runs only where everything allows it**, each checked separately: the daemon was started with it (`--allow-commands terminal,files,browser,computer`; none by default; terminal and files need `--workspace` and are refused under `--tools-only`), it reports the kind as offered (for a browser or the computer, only while a companion is connected), the kernel accepts it only for a device that offers it, the organisation's setting `devices.commands` (an administrator's switch, default on) allows commands, and the sender is the device's subject (an agent's call is held for the person's [consent](action-consent.md), which approves the exact operation and input). A daemon handed a kind it was not started with fails the command without running it.
|
|
48
|
+
|
|
49
|
+
**The workspace.** Paths are relative to the daemon's workspace; a path that resolves outside it (by `..`, an absolute path or a symbolic link, judged by the nearest existing ancestor's real path) or inside the state directory is refused; a link that leads nowhere is refused too (never followed by a write). The state directory may be inside the workspace (a home directory as the workspace, with the default state under `~/.local/state`): file commands exclude it by its real path (a symbolic link to it changes nothing): reading, writing, listing or searching in it is refused, a listing of its parent leaves it out, and a recursive search skips it. (The workspace itself may not be inside the state directory: the daemon refuses to start.) A shell command runs as the daemon's OS user with the harnesses' environment allow-list (no credentials) in its own process group, killed at the command's deadline. **Terminal commands, once the person enables them, can read anything that user can**, the state directory included (the control secret, and with the file store the device credential): no path rule confines a shell, which is why the terminal is off by default and is for machines whose person trusts their agents with that user, like a harness with workspace tools ([Daemon, what a harness can still reach](daemon.md#harness-turns)). The file commands' exclusions above hold only for the file commands.
|
|
50
|
+
|
|
51
|
+
**Lifecycle.** `devices.sendCommand` stores the command (`queued`, with the authority of the call, and expiring if no device takes it within two minutes) and emits `devices.commandRequested`. The device takes it with `nextCommand` (the chain of authority it was sent with is asserted first; one that no longer holds fails instead), which gives it a lease and a deadline (`timeoutMs`, default 60 s, at most 10 minutes). It reports once with `completeCommand` before the deadline plus 10 s: the same report again is a duplicate, a late one or one under another lease is refused. A command is never handed out twice: one taken but not reported in time reads as `failed`, one never taken as `expired` (`devices.getCommand` computes both). Revoking the device fails what is queued or running. Results are at most 2 MB of JSON.
|
|
52
|
+
|
|
53
|
+
### Recovery without timers
|
|
54
|
+
|
|
55
|
+
Nothing about commands needs a periodic job or a process timer. A command's status is computed when it is read and claimed: one no device took before `expires_at` reads `expired` and is never handed out; one taken but not reported before its deadline plus the grace reads `failed`, its late report refused; a command is never handed out twice, so nothing is retried (an operation on a terminal, a browser or a computer must not run again unasked). The daemon retries only its report, with backoff, until the deadline. (Turns recover through their durable deadline workflow and lease reclaim, [Daemon](daemon.md#the-headless-runner); push delivery retries through the Notifications outbox.) The stored row of an expired or abandoned command keeps `queued` or `running`; readers go through `devices.getCommand`.
|
|
56
|
+
|
|
57
|
+
### Cancellation
|
|
58
|
+
|
|
59
|
+
`devices.cancelCommand` (the sender or the device's subject) never claims that something done was undone. What it does depends on where the command is:
|
|
60
|
+
|
|
61
|
+
| Where | What happens | The command ends |
|
|
62
|
+
| --- | --- | --- |
|
|
63
|
+
| queued (not expired) | cancelled at once, and never handed to a device | `cancelled` ("it never ran") |
|
|
64
|
+
| taken, not yet acted on | the daemon asks the kernel just before it acts (`checkCommand`) and every second while it waits (for a companion to ask for it, say): it then does not act | `cancelled`, reported by the device (`completeCommand` with outcome `cancelled`, taken only after a cancellation was asked) |
|
|
65
|
+
| a shell command running | stopped: its process group is killed | `failed`, interrupted: its output so far, and the error says what it did before it stopped was not undone |
|
|
66
|
+
| a file operation, or a browser or computer operation a companion already took | runs to its end (a file operation is instant; a companion is not interrupted) | as it really ended, `succeeded` or `failed` |
|
|
67
|
+
| finished (or expired) | nothing | unchanged |
|
|
68
|
+
|
|
69
|
+
`cancelRequestedAt` records the request on every command it reached in time. A device that no longer answers is judged at the deadline as before (`failed`).
|
|
70
|
+
|
|
71
|
+
**Companions.** A browser extension or a computer-use helper pairs with the daemon as a local client (`kind: "browser-extension"` or `"computer-use"`; its origin must be a trusted one) and asks for work: `POST /companion/commands/next` (`waitMs`, a long poll) hands it the oldest command of its kind, and `POST /companion/commands/<id>/result` (`outcome`, `result`, `error`) reports it; only the companion that took a command may report it. A companion counts as connected for 35 s after its last request: the device then offers the kind, and reports it to the kernel. Other clients are refused (403), and so is a companion whose kind is not enabled.
|
|
72
|
+
|
|
73
|
+
**A browser companion's protocol, in full.** Pair (`/local/pair/start`, the host's approval and code, `/local/pair/confirm`); serve browser commands as above; and exchange context and chat with the person's agent through the relay as the person: `POST /relay/actions/agent.send` with the page's context in the message, and the conversation read the same way. That is everything a packaged extension needs; the extension itself is a product decision 12 defers.
|
|
74
|
+
|
|
75
|
+
## Terminals
|
|
76
|
+
|
|
77
|
+
The person's local clients (the host, the shell, a CLI; never a companion or a harness) open interactive shells when the terminal is enabled: `POST /terminals` (`cols`, `rows`, `cwd` in the workspace) answers `{ id, pty }`; `GET /terminals/<id>/stream` streams its output as server-sent events (`output`, then `exit`; the last 64 KiB again for a client that attaches later); `POST /terminals/<id>/input` (`data`), `POST /terminals/<id>/resize`, `DELETE /terminals/<id>`; `GET /terminals` lists the caller's. A terminal belongs to the client that opened it: anyone else gets 404. On Bun the shell runs in a pseudo-terminal; on Node, which has none built in, with pipes (`pty: false`). At most 8 are open; one no client has watched for ten minutes is closed, and all close with the daemon.
|
|
78
|
+
|
|
79
|
+
## Push
|
|
80
|
+
|
|
81
|
+
The host beside the daemon (the desktop app) registers its push subscription through the daemon (`POST /push` on the daemon, the host, the shell or a CLI; `{ subscription }` or `{ subscription: null }`), which forwards it with the device credential. Listings say only whether a device registered push. Revocation deletes it.
|
|
82
|
+
|
|
83
|
+
## Guarantees
|
|
84
|
+
|
|
85
|
+
1. Devices are listed only to their person (or the person who paired them) and the organisation's administrators, and never with a credential or a push token.
|
|
86
|
+
2. Only those may revoke a device; revocation is audited, takes effect at the device's next request, fails its unfinished commands and removes its push subscription.
|
|
87
|
+
3. Sessions are recorded per device as the device reports them, readable by those who may manage it.
|
|
88
|
+
4. A command reaches a device only from its subject (an agent's only with the person's consent), only of a kind the device offers and the organisation allows, and runs at most once; a kind the daemon was not started with never runs.
|
|
89
|
+
5. File commands never act on a path outside the workspace or inside the state directory, and never list or search the state directory; terminal commands start in the workspace but, like any shell, are not confined to it.
|
|
90
|
+
6. Browser and computer commands go only to a companion of their kind paired with that daemon, and only the companion that took one may report it.
|
|
91
|
+
7. A terminal is opened only with the terminal enabled, only by the host, the shell or a CLI, and is read and written only by the client that opened it.
|
|
92
|
+
8. A cancelled command that was still queued, or taken but not yet acted on, never runs; one cancelled while it ran is reported as it really ended (a shell command stopped and `failed`), never as undone.
|
|
93
|
+
|
|
94
|
+
## How an implementation is checked
|
|
95
|
+
|
|
96
|
+
`deviceControlConformance(harness)`: a device listed to its person and an administrator but not another member, no credential in listings, a device credential refused for management, an administrator revoking another person's device (audited); a device reporting a CLI client's session and a harness turn's (ended), both listed for its person and refused to another member; terminal and files commands in the workspace (a shell command's output and directory, write, edit, read, search, list) and refused outside it by a relative, an absolute and a symbolic-link path and through dangling links, a state directory inside the workspace (named through a symbolic link) skipped by a search of the whole workspace, left out of its listing and refused to reading, writing, listing and searching, a kind the device does not offer refused; another person's command refused and their reading it refused, an agent's command held for consent, a queued command failed by revocation; a browser command handed to the browser-extension companion and its answer back, a CLI refused as a companion and as the reporter, computer commands refused without their companion, the extension's session with its origin; a command never taken reading expired and never handed out, one taken but never reported reading failed at its deadline; a queued command cancelled never run (and a finished one left as it was, another member refused), a command taken but not yet acted on cancelled and withdrawn from its companion, a running shell command cancelled stopped and reported failed with its effects standing; a terminal refused when not enabled and to a companion, its input and output for its client only, closed with its session ended; availability before pairing, a push subscription registered (listed without its token) and deleted by revocation; the tools-only profile (no terminal, no workspace tools, reported), and an organisation turning commands and workspace tools off.
|
|
97
|
+
|
|
98
|
+
## Not yet guaranteed
|
|
99
|
+
|
|
100
|
+
- **No packaged browser extension or computer-use helper** exists: they are products (decision 12 defers the browser extension); this contract is the protocol they implement, tested with a client standing in for them.
|
|
101
|
+
- **No push NotificationChannel** delivers to the registered subscriptions yet: a host provides delivery ([NotificationChannel](notification-channel.md)).
|
|
102
|
+
- Sessions are what the device reports: a device that is offline keeps its last report.
|
|
103
|
+
- People cannot rename a device.
|