@eloxiv/cli 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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 +108 -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 +49 -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 +34 -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,43 @@
|
|
|
1
|
+
# HttpApi
|
|
2
|
+
|
|
3
|
+
Any HTTP API as a capability, described by an OpenAPI document or not: over a kernel [endpoint Connection](connections.md#endpoint-connections) whose endpoint is the API's base URL. The kernel carries the credential (none, a secret it holds and sends only to the base URL's origin, or an OAuth grant discovered from the API) and checks the address of every request and redirect; the connector keeps every request under the base URL's path, bounds what it returns, and tells reads from writes. It covers what no dedicated connector does (decisions.md, "Integrations have three layers").
|
|
4
|
+
|
|
5
|
+
- Kind: capability. Version 1.0.0.
|
|
6
|
+
- Schema: [`packages/contracts/schema/contracts/HttpApi.json`](../../packages/contracts/schema/contracts/HttpApi.json) (source [`HttpApi.ts`](../../packages/contracts/src/contracts/HttpApi.ts)).
|
|
7
|
+
- Implementations: the [`http-openapi`](../connectors/http-openapi.md) registry connector ([`registry/app/connectors/http-openapi`](../../registry/app/connectors/http-openapi)).
|
|
8
|
+
- Kit: `@eloxiv/testing/conformance/HttpApi` ([source](../../packages/testing/src/conformance/HttpApi.ts)), run by [`registry/test/connector-http-openapi.test.ts`](../../registry/test/connector-http-openapi.test.ts) against the HTTP API protocol fake ([`fakes/HttpApiFake.ts`](../../packages/testing/src/fakes/HttpApiFake.ts)).
|
|
9
|
+
|
|
10
|
+
Shared parts: [Capability contracts](README.md#capability-contracts).
|
|
11
|
+
|
|
12
|
+
## Records
|
|
13
|
+
|
|
14
|
+
- `ApiOperation`: `id` (the document's `operationId`, else `<METHOD> <path>`), `method`, `path`, `summary`, `readOnly`.
|
|
15
|
+
- `ApiResponse`: `status`, `contentType`, `body` (parsed JSON when the answer says it is JSON and fits, otherwise its text, or null when empty), `truncated` (cut at 256 KiB).
|
|
16
|
+
- `HttpApiFlags`: `openapi` (the connector reads an OpenAPI document the Connection names).
|
|
17
|
+
|
|
18
|
+
## Operations
|
|
19
|
+
|
|
20
|
+
| Operation | Scopes | What |
|
|
21
|
+
| --- | --- | --- |
|
|
22
|
+
| `catalog` | `api.read` | The OpenAPI document's operations (at most 500, `truncated` beyond), each with whether it only reads: GET and HEAD, and POSTs the Connection names as reading |
|
|
23
|
+
| `describe` | `api.read` | One operation by id: its description, parameters (path-level and its own) and request body, bounded |
|
|
24
|
+
| `read` | `api.read` | GET, HEAD, or a POST to a path the Connection names as reading (any other POST is `InvalidInput`, nothing sent). `maxPages` (at most 10) follows `Link: <...>; rel="next"` while it stays on the base URL's origin and path |
|
|
25
|
+
| `write` | `api.write` | POST, PUT, PATCH or DELETE. `effect: "external"`: never sent again after a 5xx |
|
|
26
|
+
|
|
27
|
+
Every request names a `path` under the base URL (`/items` and `items` both mean `<base>/items`); one that resolves elsewhere (`..`, `%2e%2e`, another origin, a scheme, `//host`, a backslash) is `InvalidInput` before anything is sent. Request headers may not name credentials, cookies, forwarding or hop-by-hop headers. A 4xx or 5xx answer is the standard capability error (404 `NotFound`, 400 and 422 `InvalidInput`, 401 and 403 by the Connection's rules, 429 and 503 backed off).
|
|
28
|
+
|
|
29
|
+
The Connection's options (`connections.add`'s `options`, checked by the connector): `openapi`, the path under the base URL of the document in JSON (OpenAPI 3 or Swagger 2; YAML is not read); `readOnlyPosts`, the paths (relative to the base URL) whose POST only reads.
|
|
30
|
+
|
|
31
|
+
## Exposure
|
|
32
|
+
|
|
33
|
+
The kernel's `connections` module exposes the operations on every surface as `connections.apiCatalog`, `connections.apiDescribe`, `connections.apiRead` and `connections.apiWrite`. `apiWrite` is marked `consent: "each-call"`: every write an agent asks for waits for the person's approval of that exact request.
|
|
34
|
+
|
|
35
|
+
## How an implementation is checked
|
|
36
|
+
|
|
37
|
+
`httpApiConformance(start)` starts the HTTP API fake (and a second server, "elsewhere") and a kernel allowing only their hosts, adds a Connection that sends a secret in `x-api-key`, and registers: the catalogue with reads told from writes, and an operation's parameters; reads carrying the secret, following next links up to the pages asked and not to another origin; paths escaping the base URL and credential headers refused with nothing sent; a redirect to another origin followed without the secret; a redirect to the cloud metadata address refused; a POST read only where named, a write only through `apiWrite`; every agent's write held for consent with nothing sent; an answer past the bound cut and marked.
|
|
38
|
+
|
|
39
|
+
## Not yet guaranteed
|
|
40
|
+
|
|
41
|
+
- **Proven against a protocol fake only.**
|
|
42
|
+
- **YAML OpenAPI documents**, request bodies other than JSON, and streaming answers.
|
|
43
|
+
- **Durable corpus collection** (ledger A-033: paginated collection checkpointed into staging) is not part of the contract: a module pages with `read` in a workflow of its own, through Ingestion.
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
# Ingestion
|
|
2
|
+
|
|
3
|
+
Pipelines that turn inbound content into extracted text and searchable chunks (decisions.md "Kernel contracts"; ledger A-049, C-043, C-056): files attached to records, documents from a [DocumentSource](document-source.md) connector over a Connection, emails and other text a module receives.
|
|
4
|
+
|
|
5
|
+
- Kind: kernel service. Version 1.2.0 (1.1.0: bulk runs, `ctx.ingestion.runs`; 1.2.0: staged datasets, `ctx.ingestion.datasets` and the `data` module's `data.stage`, `data.query`, `data.datasets`, `data.drop`; corpus collections, `ctx.ingestion.collect`, `ctx.ingestion.collection`, `data.collect`, `data.collection`).
|
|
6
|
+
- Schema: [`packages/contracts/schema/contracts/Ingestion.json`](../../packages/contracts/schema/contracts/Ingestion.json) (source [`Ingestion.ts`](../../packages/contracts/src/contracts/Ingestion.ts)).
|
|
7
|
+
- Implementation: the `Ingestion` service and the `eloxiv.ingest` workflow in [`packages/kernel/src/ingestion/Ingestion.ts`](../../packages/kernel/src/ingestion/Ingestion.ts); extraction in [`Extract.ts`](../../packages/kernel/src/ingestion/Extract.ts) (with [`Zip.ts`](../../packages/kernel/src/ingestion/Zip.ts) and [`Pdf.ts`](../../packages/kernel/src/ingestion/Pdf.ts)); chunking in [`Chunk.ts`](../../packages/kernel/src/ingestion/Chunk.ts); the kernel module `ingestionModule` ([`module.ts`](../../packages/kernel/src/ingestion/module.ts)).
|
|
8
|
+
- Kit: `@eloxiv/testing/conformance/Ingestion` ([source](../../packages/testing/src/conformance/Ingestion.ts)).
|
|
9
|
+
|
|
10
|
+
## Submitting
|
|
11
|
+
|
|
12
|
+
Every source item belongs to a record, whose read policy governs who finds its chunks through [Search](search.md). The record's entity must declare `search` or `files` (the kernel then follows its changes and its deletion; `submit` refuses any other with `Forbidden`).
|
|
13
|
+
|
|
14
|
+
### Every copy goes
|
|
15
|
+
|
|
16
|
+
What was ingested is removed one way, whatever removes it: the kernel's `eloxiv.scrub_ingested` supersedes the items and clears every copy of their content, the original (`source`, down to its kind: an email's body, a text's characters, a file's id), the `title` (a file's name, an email's subject), the extracted `text`, the chunks and their search documents (kernel migration `0038_ingestion_scrub`). It runs, in the transaction that causes it, when:
|
|
17
|
+
|
|
18
|
+
- **the record is deleted** (`eloxiv.forget_record`, from the tracking trigger): all of its items;
|
|
19
|
+
- **the record's personal data changes**: an update to any column its `dataSubjects` declaration names, or that an anonymising erasure sets (`record_source.personal_columns`, compared by the tracking trigger), scrubs all of its items, since what was ingested may hold the old values. An anonymising erasure is such an update, and so is a module clearing the data itself;
|
|
20
|
+
- **what an item was derived from changes**: before it prepares content, a module takes a basis with `ctx.ingestion.basis(record, ["subject", "snippet"])`, under the record's lock (held to the end of the call, so the values and the generation describe one version of the record; take it after writing the record, never before): the record's generation (moved by every write to the record and every scrub of it; [Search](search.md#derived-copies-and-how-each-goes)) and the fields the content comes from, with their values and hash (no fields for content from elsewhere, a file say). It builds the content from those values and submits it with that basis, which `submit` requires: under the record's lock the kernel refuses the submission (`InvalidInput`, "changed since") if the generation moved, whatever fields the basis named, so content prepared before any change (an edit, an anonymisation, a deletion) never lands after it. The item keeps the fields' columns and hash (`eloxiv.derived_hash`, kernel migration `0039_derived_ingestion`), and any write to the record that changes them (a sync applying a redaction, an edit, an anonymisation) supersedes and scrubs the item in that write's transaction. There is no gap between a submission and a write: the tracking trigger takes the record's lock on every update before it looks at the record's items, and a submission holds that lock from reading the record's fields to storing its item (checking at the insert that the fields still hash the same), so a write either finishes before the submission reads or finds and scrubs its item once it is stored (kernel migration `0040_derived_invalidation`). An item with no hash (stored before items recorded what they were derived from) counts as derived from the record and is scrubbed by its next change, to be submitted again; an item ingested from a file comes from the file, not the record's fields (the hash of no fields), and so does any item submitted without `derivedFrom`. Content the module does not keep (a message body) is derived from a field that changes with it: mail stores the provider's version of the message (MailProvider `version`) and derives the body from it, so a body-only change re-indexes it. The module submits it again from the new values: `ctx.ingestion.current(record)` lists the record's current items, so a source with no current item (never submitted, failed, or superseded by a change) is the one to submit. Mail does this for every message body (derived from the subject, sender and preview). Other changes (a read flag, a folder) leave ingested content alone;
|
|
21
|
+
- **a file is deleted** ([Files](files.md)): the items ingested from it;
|
|
22
|
+
- **a newer version of a source item is indexed**: the older versions (see the pipeline).
|
|
23
|
+
|
|
24
|
+
Submitting a superseded version again gives its content again (from the source the submission names).
|
|
25
|
+
|
|
26
|
+
- **Files**: an entity declaring `files: { ingest: true }` has every file attached to its records ingested once it is available ([Files](files.md)).
|
|
27
|
+
- **In a handler** (`submit`): `ctx.ingestion.submit({ record: { entity, id }, source })` for a record of the module's own entities (by Cedar type or entity name) that exists in the organisation the call acts in, in the handler's transaction. The record's lock is taken first (the search lock shared, then the record's; see [Search](search.md#the-index)), and only then is the record looked for and the source described (a file attached to it and available, a Connection of the caller's): a deletion under way finishes first, and the submission then finds the record gone (`Forbidden`), so nothing is ingested into a record that no longer exists:
|
|
28
|
+
|
|
29
|
+
```ts
|
|
30
|
+
ctx.ingestion.submit({
|
|
31
|
+
record: { entity: "doc", id: input.docId },
|
|
32
|
+
source: { kind: "email", key: message.id, subject: message.subject, html: message.html },
|
|
33
|
+
})
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
| Source | Identity (`sourceKey`) | Version |
|
|
37
|
+
| --- | --- | --- |
|
|
38
|
+
| `{ kind: "file", fileId }` (attached to the record, available) | `file:<id>` | its SHA-256 |
|
|
39
|
+
| `{ kind: "text", key, title?, mediaType?, text }` | `text:<key>` | a hash of the text |
|
|
40
|
+
| `{ kind: "email", key, subject, from?, text?, html? }` | `email:<key>` | a hash of the message |
|
|
41
|
+
| `{ kind: "document", connectionId, itemId, version, name? }` | `document:<connection>:<item>` | as given (the item's `modifiedAt`) |
|
|
42
|
+
|
|
43
|
+
## Operations
|
|
44
|
+
|
|
45
|
+
| Operation | What it does |
|
|
46
|
+
| --- | --- |
|
|
47
|
+
| `submit` (in process) | Queue a source item: stored with an `ingestion.submitted` event in the same transaction, so it is never lost. Idempotent per (record, source key, version): the same version again changes nothing (`created: false`); a failed or superseded one submitted again runs again (its next attempt). `basis` (required) is what the content was built from: refused if the record's generation moved since it was taken (see "Every copy goes") |
|
|
48
|
+
| `current` (in process) | The record's current items (not superseded), with their source key and state: what is indexed, or on its way, from the record as it is now |
|
|
49
|
+
| `basis` (in process) | Taken before content is prepared: the record's generation (which `submit` checks), and the fields the content will be built from, with their values (to build it from) and hash (kept on the item, so a change to other fields leaves it alone) |
|
|
50
|
+
| `status` (action `ingestion.status`) | The items of a record the caller may read: source, version, title, type, state, progress (0 to 1), chunks, characters, whether the text was truncated, the error |
|
|
51
|
+
| `datasets` (in process) | The calling module's staged datasets in the acting organisation (see "Staged datasets") |
|
|
52
|
+
| `collect`, `collection` (in process) | A corpus collection into one of the module's datasets, and how it stands (see "Corpus collections") |
|
|
53
|
+
| `extract` (in process) | The extractor hook: `KernelOptions.extractors` add media types (OCR, RTF, a Tika server), asked before the kernel's own |
|
|
54
|
+
|
|
55
|
+
A handler's `ctx.ingestion` (`submit`, `current`, `basis`, `runs`, `datasets`, `collect`, `collection`) acts on its caller's behalf, so each requires the call's assertion ([Invocation, "Authority"](invocation.md#authority)): it refuses once the capability is no longer bound to the call's transaction and person. Its locks follow the one lock order: the call's authority links (asserted when the call began), then the search lock and the record's own lock, then the record's rows ([Search](search.md)).
|
|
56
|
+
|
|
57
|
+
## The pipeline
|
|
58
|
+
|
|
59
|
+
A kernel reaction starts the durable workflow `eloxiv.ingest`, keyed by the item and attempt, run as the organisation's system identity:
|
|
60
|
+
|
|
61
|
+
1. **extract** (`fetching` → `extracting`): the file's bytes from the StorageBackend, the document's content over its Connection (`getContent`, as the Connection's owner, which must be in the item's organisation), or the inline text; then the text: plain text, Markdown, CSV, TSV, JSON, calendar and vCard as they are; HTML and XHTML reduced to their text (scripts, styles and comments dropped, blocks on their own lines; the title kept); XML; PDF (the strings of its text operators, compressed or not); DOCX, XLSX and PPTX (their XML parts, with the document title). Compressed content is inflated within a hard limit, so a compression bomb fails instead of filling memory. Every scan of markup and PDF content is linear (it moves forward with `indexOf` and stops at an unclosed construct; no backtracking pattern runs over a document). Every extractor writes into a text budget of `files.maxExtractedChars` (2,000,000) and stops when it is full (`truncated`), so a file whose text amplifies (a spreadsheet repeating one large shared string in every cell, say) costs what its first 2,000,000 characters cost, never its expanded size. The kernel's extractors run **in child processes** of the kernel's own runtime (Bun or Node), never in the kernel's process: a pool of `files.extractConcurrency` (2) processes, which is also the most extractions that run at once across every item. Each job has a wall-clock limit (`files.extractTimeoutMs`, 60 s) and a memory limit the operating system measures (`files.extractMemoryMb`, 512 MiB of resident memory, read every 50 ms, and on Linux its high-water mark checked before a job's answer is accepted, so a peak between two readings is not missed; on Node the child's heap is capped as well): past either, the process is killed (`SIGKILL`, so it stops using CPU and memory at once), the item fails with the reason, and a fresh process takes its place. A process that crashes takes only itself down. The deployment's own extractors (`KernelOptions.extractors`) are its trusted code and run in process, their output held to the same budget. The text is kept on the item.
|
|
62
|
+
2. **index** (`indexing` → `done`), in one transaction: the text cut into chunks of at most `files.chunkChars` (1,500) characters ending at a paragraph, sentence or word boundary, overlapping by `files.chunkOverlapChars` (200); each chunk's range recorded and indexed for Search under the record (in the record's search language, or `simple`), replacing the item's earlier chunks; older versions of the same source item superseded and their chunks removed. Versions are ordered by submission (a resubmission counts as the latest): an item never supersedes one submitted after it; it is superseded instead when that one is already indexed, and otherwise indexed meanwhile, so an older version stays searchable until a newer one is indexed (a newer one that fails leaves it in place). The step takes its locks in the order every index writer does (the search lock shared, the record's lock, then every version of the source item in id order; see [Search](search.md#the-index)), so concurrent index steps, and a record deleted meanwhile, queue instead of deadlocking. `ingestion.completed` is published.
|
|
63
|
+
|
|
64
|
+
A step that crashes runs again from its start; both are idempotent (the index step replaces the item's chunks), so a restart never indexes anything twice. A failure marks the item `failed` with its error and publishes `ingestion.failed`. Deleting the record (or changing its personal data) supersedes its items and clears every copy of their content, in that transaction ("Every copy goes"); an extract step still running then writes nothing to them (its write skips superseded items).
|
|
65
|
+
|
|
66
|
+
## Bulk runs
|
|
67
|
+
|
|
68
|
+
A module processing a provider's items in bulk (a mailbox backfill, a drive's listing, a corpus) uses `ctx.ingestion.runs` ([`Runs.ts`](../../packages/kernel/src/ingestion/Runs.ts), tables `eloxiv.ingestion_run` and `eloxiv.ingestion_run_item`, migration `0145_ingestion_runs`); the kernel's code uses `Ingestion.runs({ orgId, module })`, each operation in a transaction of its own.
|
|
69
|
+
|
|
70
|
+
| Operation | What it does |
|
|
71
|
+
| --- | --- |
|
|
72
|
+
| `openRun`: `open({ source, items, budget? })` | A run of the calling module in the acting organisation over the inventory of item keys the provider listed (at most 100,000, duplicates once), with an optional budget of cost units; its `runId` |
|
|
73
|
+
| `claim({ runId, worker, max, leaseMs })` | Lease up to `max` items (at most 1,000) to `worker` for `leaseMs`: pending items, and items whose lease ran out (a crashed or hung worker's), each with its attempt number. Two workers never hold one item (`FOR UPDATE SKIP LOCKED`). Nothing once the run is stopped or completed |
|
|
74
|
+
| `completeItem`: `complete({ runId, worker, key, attempt, cost? })` | The item, done, with its cost (default 1), **only for the attempt `claim` leased it under, while that lease holds**: a worker whose lease ran out is refused (`InvalidInput`), and so is a late answer from an earlier attempt after the item was leased again, by another worker or the same one, so an item is counted once. Spending the budget stops the run (`stopped`, `budget`) in the same statement |
|
|
75
|
+
| `reportItem`: `report({ runId, worker, key, attempt, reason })` | The item, not processed, with the reason (gone at the provider, refused): it counts towards completeness |
|
|
76
|
+
| `inventory(runId)` | Every item's state (`pending`, `leased`, `done`, `reported`), attempts and reason; the counts, the budget and what was spent; `complete` when every item is done or reported |
|
|
77
|
+
| `finishRun`: `finish(runId)` | Complete the run; refused (naming the items) while any is neither done nor reported. A stopped run stays stopped, its unprocessed items listed |
|
|
78
|
+
|
|
79
|
+
A run is its module's and organisation's alone: every statement is scoped to both. A finished run's bookkeeping is deleted 30 days after it finished.
|
|
80
|
+
|
|
81
|
+
## Staged datasets
|
|
82
|
+
|
|
83
|
+
Bounded tables of rows staged from what providers answered, to query again with SQL instead of asking the provider again ([`data/Datasets.ts`](../../packages/kernel/src/data/Datasets.ts), tables `eloxiv.staged_dataset` and `eloxiv.staged_row`, migration `0160_sandbox_data`). A dataset belongs to its organisation and one owner: a person (the kernel's `data` module, and read programs, [Sandbox](sandbox.md#read-programs-the-kernels-data-module)) or a module (`ctx.ingestion.datasets`). Every statement names both.
|
|
84
|
+
|
|
85
|
+
| Operation | What it does |
|
|
86
|
+
| --- | --- |
|
|
87
|
+
| `stageDataset`: `data.stage({ name, rows, expiresInS? })`, `ctx.ingestion.datasets.stage(name, rows, { expiresInS?, page? })` | Stage rows (JSON objects) as the dataset `name`, replacing it, or with `page`, replacing only that page of it; its columns are inferred from the values (number, boolean, text, JSON; keys that are not plain names stay in the rows, outside the relation) |
|
|
88
|
+
| `queryDataset`: `data.query({ name, sql, limit? })`, `ctx.ingestion.datasets.query(name, sql, limit?)` | One read-only `SELECT` over the relation `dataset` (at most 1,000 rows, `truncated` beyond) |
|
|
89
|
+
| `rows` (in process), `eloxiv.staged(name)` | The dataset's rows, in order |
|
|
90
|
+
| `listDatasets`: `data.datasets`, `ctx.ingestion.datasets.list()` | The owner's datasets that have not expired: rows, bytes, columns, expiry |
|
|
91
|
+
| `dropDataset`: `data.drop({ name })`, `ctx.ingestion.datasets.drop(name)` | Delete one |
|
|
92
|
+
|
|
93
|
+
- **Bounded**: at most `DATASET_MAX_ROWS` (20,000) rows, 8 MiB of JSON and 100 columns a dataset; a person holds at most 50 datasets and 32 MiB (`PERSON_QUOTA`), a module 500 and 256 MiB in each organisation (`MODULE_QUOTA`), counted under the owner's lock over datasets that have not expired. Past any bound the stage is refused and nothing is written.
|
|
94
|
+
- **Expiring**: a person's dataset expires after a day by default (at most a week), a module's after a week (at most 30 days); an expired dataset is never read again and is deleted, a hundred at a time, whenever one is staged.
|
|
95
|
+
- **Read-only SQL**: the query is checked as the query surface checks queries (Postgres's grammar; `SELECT` only; allowlisted functions and types; unqualified names), then runs on a connection of its own in a transaction that always rolls back: the rows go into a temporary table created as the read role `eloxiv_query`, which can read nothing of the database's, and the query becomes a temporary view over it, checked by what Postgres resolved it to: no relation but the temporary `dataset` (by OID, whatever its names, CTEs or scopes say), and the query surface's functions, operators and types only. It runs read-only with a 2 s statement timeout, its rows encoded and measured in Postgres as they stream: past 256 KiB for a value (`QUERY_MAX_VALUE_BYTES`) or 1 MiB for the result (`QUERY_MAX_BYTES`), it stops and is refused, so the kernel never holds more; one row past the call's limit is read only to say there is more (`truncated`), carrying no values and counting towards no limit. The read runs in a temporary function that answers any error with its SQLSTATE and the first 200 characters of its message, cut in Postgres, so an error never carries the query's values to the kernel. A dataset's rows read back (`rows`, `eloxiv.staged`) are measured in Postgres the same way.
|
|
96
|
+
|
|
97
|
+
## Corpus collections
|
|
98
|
+
|
|
99
|
+
A durable, checkpointed collection of a provider's paginated listing over a Connection into a staged dataset ([`data/Corpus.ts`](../../packages/kernel/src/data/Corpus.ts), table `eloxiv.corpus_collection`).
|
|
100
|
+
|
|
101
|
+
| Operation | What it does |
|
|
102
|
+
| --- | --- |
|
|
103
|
+
| `collect`: `ctx.ingestion.collect(spec)` (into a dataset of the module's), `data.collect(spec)` (into one of the person's) | `CollectSpec`: the Connection, `path` and `query`, `items` (a dotted path to each answer's items; empty: the body), `cursor` (`{ param, from }`: the next page's query parameter from a dotted path of the answer; or `{ param, page }`: a page number from `page`), `dataset`, `maxPages` (at most 500). Recorded with an `ingestion.collect` event in the caller's transaction, under the call's authority (bound with `bindDeferred`); its `collectionId` |
|
|
104
|
+
| `collection`: `ctx.ingestion.collection(id)`, `data.collection({ collectionId })` | Its status (`running`, `completed`, `stopped`, `failed`), pages, items, dataset and error, for its owner only |
|
|
105
|
+
|
|
106
|
+
A kernel reaction starts the workflow `eloxiv.corpus-collect`, keyed by the collection. A person's page is read through the invocation path (`connections.apiRead`, one page, a journalled step) as the person under the recorded authority or, when their agent asked, as the agent (through its agent session, so the app's agent tool groups and consent apply); a module's page is read as the module's (`Connections.capability` with the module, as its handlers' `ctx.connections` reads are), so a shared Connection must be granted to the module as well as to the person, checked at every page. Each module page's read is audited as `connections.apiRead` (surface `workflow`, as the person, with the collection, the module and the page in its detail): its success in the transaction that stages it, a failure or refusal after. Each page is staged as that page of the dataset with the collection's progress in one transaction, under the recorded authority asserted in it and confirmed at its commit (`Authority.within`): once a link no longer holds (a revoked token or agent session, a member removed), nothing more is staged, even a page already read, and the collection fails. A page already recorded is not staged again, and a restart resumes at the first step not journalled, so no page recorded is read again (only a read cut off before it was recorded runs again). It completes on a page with no items or no next cursor, stops at `maxPages` (`stopped`, error `maxPages`), and fails (`failed`, with why) on a refused read or a page past the dataset's or owner's bounds. An owner runs at most `COLLECTIONS_AT_ONCE` (3) collections at once.
|
|
107
|
+
|
|
108
|
+
## Guarantees
|
|
109
|
+
|
|
110
|
+
1. Chunks are found exactly by those who may read the record they belong to (Search's guarantee 1).
|
|
111
|
+
2. One run per source item and version; a newer submission supersedes an older one's chunks once it is indexed, never the other way round, and until then the older stays indexed.
|
|
112
|
+
3. Every item's state and progress are reported, failures with their reason.
|
|
113
|
+
4. Extraction is bounded: linear scans, inflated bytes, extracted characters (every extractor stops at the budget), chunk sizes, how many run at once, and each job's time and memory, in a child process that a hostile file can exhaust or crash without touching the kernel's process.
|
|
114
|
+
5. A module ingests content of its own records only, and a Connection's documents only for the Connection's owner (they are read as the owner, then found by whoever may read the record).
|
|
115
|
+
6. Nothing ingested outlives its record, its file, or the personal data it was ingested under: one scrub, in the transaction that removes them; and nothing is ingested into a record being deleted.
|
|
116
|
+
7. **Bulk runs**: a crashed worker's items are released when its lease runs out and resumed, and each item is counted once; a spent budget stops the run with nothing more leased and what is left listed; a run is complete only when every listed item is done or reported; no other module or organisation sees or settles a run. ([`ingestion-runs.test.ts`](../../packages/testing/test/ingestion-runs.test.ts))
|
|
117
|
+
8. **Staged datasets**: a dataset is queried again with SQL, repeatedly, and read by no other person, module or organisation; a query reads only the dataset (whatever its names say) and writes nothing; a result too large is refused in Postgres before the kernel holds it; datasets are bounded per person and per module, kept apart, and expire. ([`data-programs.test.ts`](../../registry/test/data-programs.test.ts))
|
|
118
|
+
9. **Corpus collections**: every page lands in the dataset once; a collection survives the kernel stopping mid-collection without reading a recorded page again; it stops at its page limit; an owner runs at most three at once; a collection and its dataset are read by no other person, module or organisation, and no one collects over another's Connection; nothing more is staged once its authority no longer holds; a module's collection needs the shared Connection granted to the module; an agent's collection reads as the agent. ([`corpus-collection.test.ts`](../../registry/test/corpus-collection.test.ts))
|
|
119
|
+
|
|
120
|
+
## How an implementation is checked
|
|
121
|
+
|
|
122
|
+
`ingestionConformance(start)` takes a `FilesSubject` (see [Files](files.md)): an attached file found by its chunks with their ranges and read by pages (`files.readText`); HTML email, DOCX, XLSX, PPTX and PDF extracted (an email's script never indexed); idempotence and supersession; a failed item and its retry; an image that cannot be extracted failing visibly; deletion removing chunks; status only for readers. The registry's [`effects.test.ts`](../../registry/test/effects.test.ts) checks that a change to a record's personal data (an anonymisation) scrubs its items, and that other changes do not. The kernel's runner is [`ingestion.test.ts`](../../packages/testing/test/ingestion.test.ts). The kernel's own tests add the child-process pool ([`extract-isolated.test.ts`](../../packages/kernel/test/extract-isolated.test.ts): time and memory limits kill the process, a crash is contained, the pool bounds concurrency), the text budget of every extractor ([`extract-bounds.test.ts`](../../packages/kernel/test/extract-bounds.test.ts)), hostile files over HTTP on both runtimes ([`ingestion-isolation.test.ts`](../../packages/testing/test/ingestion-isolation.test.ts)), and interleavings forced with database gates ([`ingestion-races.test.ts`](../../packages/testing/test/ingestion-races.test.ts): a submission waiting on a deletion under way finds the record gone; a deleted file leaves nothing of its items).
|
|
123
|
+
|
|
124
|
+
## Not yet guaranteed
|
|
125
|
+
|
|
126
|
+
- PDF text in fonts with their own encodings (CID fonts, most non-Latin text) is not decoded; plug in an `Extractor` for `application/pdf` where it matters. No OCR.
|
|
127
|
+
- Documents are ingested when a module submits them (for example from a Connection sync's pages); the kernel does not watch a drive by itself, and a bulk run is driven by the module's own workers (a workflow, a scheduled job): the kernel keeps its leases, budget and inventory.
|
|
128
|
+
- A budget stops new leases; items already leased when it is spent may still be completed (and counted), so spending can pass the budget by what was in flight.
|
|
129
|
+
- Embeddings are not part of this contract. Staged datasets are the seam a datasets product would build on; that product (its screens, sharing and dashboards) is deferred (decision 12).
|
|
130
|
+
- A collection reads one cursor or page-number listing; providers that page by `Link` headers are read with `connections.apiRead`'s own `maxPages` (a read program), not by a collection.
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
# Ingress
|
|
2
|
+
|
|
3
|
+
Inbound webhooks: signature verification, replay protection, durable acceptance and linked platform identities. A delivery acts as a person (through the platform identity they linked) or as a declared service principal, through the one invocation path with surface `ingress`. Unlinked senders cannot act as anyone.
|
|
4
|
+
|
|
5
|
+
- Kind: kernel service. Version 1.1.0 (1.0.0 had no handshake answers and no `receivedBy`).
|
|
6
|
+
- Schema: [`packages/contracts/schema/contracts/Ingress.json`](../../packages/contracts/schema/contracts/Ingress.json) (source [`Ingress.ts`](../../packages/contracts/src/contracts/Ingress.ts)).
|
|
7
|
+
- Implementation: [`packages/kernel/src/ingress/`](../../packages/kernel/src/ingress): `Definition.ts` (declaring sources), `Verifiers.ts` (built-in verifiers), `Ingress.ts` (the pipeline, the `eloxiv.ingress` workflow, link management). Tables: `eloxiv.ingress_delivery`, `eloxiv.linked_identity`, `eloxiv.link_code` (kernel migrations `0015_ingress`, `0019_ingress_signed_hash`).
|
|
8
|
+
- Kit: `@eloxiv/testing/conformance/Ingress` ([source](../../packages/testing/src/conformance/Ingress.ts)), against the desk fixture ([`conformance/desk/server.ts`](../../packages/testing/src/conformance/desk/server.ts)).
|
|
9
|
+
|
|
10
|
+
## Declaring a source
|
|
11
|
+
|
|
12
|
+
A module declares sources in `defineModule({ ingress })` (served as `<module>.<name>`), a connector likewise, and an app in `KernelApp.ingress` (served as named). Names are lower case letters, digits, `.`, `_` and `-`, unique across the app; the kernel refuses to start with a duplicate name or a handler naming an unknown action or workflow.
|
|
13
|
+
|
|
14
|
+
```ts
|
|
15
|
+
import { defineIngressSource, Verifiers } from "@eloxiv/kernel"
|
|
16
|
+
|
|
17
|
+
export const slackEvents = defineIngressSource({
|
|
18
|
+
name: "events", // POST /ingress/messaging.events in module `messaging`
|
|
19
|
+
verifier: Verifiers.slack(),
|
|
20
|
+
identity: {
|
|
21
|
+
kind: "linked",
|
|
22
|
+
platform: "slack",
|
|
23
|
+
// Who sent it, from the verified body; a `linkCode` completes a link instead of acting.
|
|
24
|
+
sender: (delivery) => {
|
|
25
|
+
const event = JSON.parse(delivery.body).event
|
|
26
|
+
const link = /^link (\S+)$/u.exec(event?.text ?? "")
|
|
27
|
+
return event?.user === undefined ? undefined : { externalId: `${event.team}:${event.user}`, linkCode: link?.[1] }
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
handler: { kind: "action", action: "messaging.receive", input: (delivery) => ({ raw: delivery.body }) },
|
|
31
|
+
keepHeaders: ["x-slack-retry-num"],
|
|
32
|
+
})
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
| Field | Meaning |
|
|
36
|
+
| --- | --- |
|
|
37
|
+
| `verifier` | A `Verifier`: `verify({ headers, body, secrets })` returns the delivery id, the signed timestamp and `signedHash` (the SHA-256 of exactly what the signature covers), or a refusal. `signsTimestamp` says whether a timestamp is required |
|
|
38
|
+
| `identity` | `{ kind: "linked", platform, sender, receivedBy? }`: the sender's platform identity (a user, a workspace, or both in one id), read from the verified delivery. `receivedBy` names the provider account that received it (`{ provider, accountId }`, Slack's receiving workspace): the delivery then acts only in an organisation with an active Connection to that account, so a link in any other organisation is not used (`unlinked`) and a link code from any other organisation is refused (`link-refused`, the code left unused); a delivery naming no account acts nowhere; or `{ kind: "principal", org, principal }`: a service principal of that organisation, by name, created by its admins (see [MachineIdentity](machine-identity.md)) |
|
|
39
|
+
| `handler` | `{ kind: "action", action, input }`: the action invoked as the actor; or `{ kind: "workflow", workflow, input }`: a workflow the app defines, run inside the delivery's own execution (its steps are named `handler/<step>` and act as the actor with surface `ingress`) |
|
|
40
|
+
| `keepHeaders` | Headers stored with the delivery for the handler (with `content-type`). Signature headers are never stored. No built-in scheme signs a header beyond its own timestamp and delivery id, so a kept header (GitHub's `x-github-event`, Slack's `x-slack-retry-num`) is the sender's claim: never authorise anything on it |
|
|
41
|
+
| `toleranceS`, `maxBodyBytes` | Overrides of the kernel's settings for this source |
|
|
42
|
+
| `answer` | A handshake the sender expects answered in the response itself (Slack's `url_verification`, whose `challenge` must come back): from the verified body, the `{ body, contentType }` to answer with, or undefined. See "Handshakes" below |
|
|
43
|
+
|
|
44
|
+
`input` and `sender` get an `IngressDelivery`: `source`, `deliveryId`, `body` (the verified raw body as UTF-8), `headers` (the kept ones), `signedAt`, `receivedAt`. They may run again after a restart, so they must be deterministic.
|
|
45
|
+
|
|
46
|
+
### Verifiers
|
|
47
|
+
|
|
48
|
+
`Verifiers.hmacSha256(options)` is HMAC-SHA256 with a shared secret over a signed payload built from the raw body (and the timestamp, where the scheme signs one), compared with `timingSafeEqual` against every presented signature and every secret without stopping early. Presets:
|
|
49
|
+
|
|
50
|
+
| Preset | Signature | Signed payload | Delivery id | Signed? |
|
|
51
|
+
| --- | --- | --- | --- | --- |
|
|
52
|
+
| `slack()` | `x-slack-signature: v0=<hex>`, `x-slack-request-timestamp` | `v0:<ts>:<body>` | the Events API `event_id` (the same on Slack's retries), else the payload's hash | timestamp and id (in the body) |
|
|
53
|
+
| `stripe()` | `stripe-signature: t=<ts>,v1=<hex>[,v1=…]` | `<ts>.<body>` | the event's `id` | timestamp and id (in the body) |
|
|
54
|
+
| `github()` | `x-hub-signature-256: sha256=<hex>` | the body | `x-github-delivery` | neither: GitHub signs no timestamp, and its delivery id and event header are unsigned |
|
|
55
|
+
| `eloxiv()` | `x-eloxiv-signature: v1=<hex>[,v1=…]`, `x-eloxiv-timestamp`, `x-eloxiv-delivery` | `<ts>.<delivery id>.<body>` | `x-eloxiv-delivery` | timestamp and id |
|
|
56
|
+
|
|
57
|
+
Any other scheme is a `Verifier` of the source's own; it must report `signedHash` over exactly what it verified.
|
|
58
|
+
|
|
59
|
+
### Secrets
|
|
60
|
+
|
|
61
|
+
Verifier secrets come from configuration for now, behind the `IngressSecrets` service (`secretsFor(source)`), which the Secrets contract will replace: `ELOXIV_INGRESS_SECRET_<SOURCE>` (the name upper-cased, other characters as `_`; for example `ELOXIV_INGRESS_SECRET_MESSAGING_EVENTS`), comma-separated so a secret can be rotated (any of them verifies), or `KernelConfig.ingress.secrets` keyed by source name. A source without a secret refuses everything and logs an error.
|
|
62
|
+
|
|
63
|
+
## The pipeline
|
|
64
|
+
|
|
65
|
+
### `deliver`: `POST /ingress/<source>`
|
|
66
|
+
|
|
67
|
+
1. **Verify.** Unknown source: `404 UnknownSource` (its body is not read). A body over the limit (default 1 MiB): `413 PayloadTooLarge`. The body is counted as it arrives: a declared `Content-Length` over the limit is refused before anything is read, and a body without one (chunked) at the first byte past it, before the sender finishes, so nothing past the limit is buffered. A body that does not arrive within `http.bodyTimeoutMs` (default 30 s): `408 RequestTimeout`. These are logged, not audited, since there is no whole body to hash, and the connection is closed. A missing or wrong signature, or a missing signed timestamp: `401 InvalidSignature`.
|
|
68
|
+
2. **Replay protection rests on what is signed.** A signed timestamp further than the tolerance (default 300 s) from now, either way: `401 StaleDelivery`. Each accepted delivery is stored for the retention period (default 7 days, never shorter than the tolerance) under its delivery id and under the hash of its signed payload, each unique per source:
|
|
69
|
+
- the same id with the **same body** is a redelivery (a sender's retry) and joins the existing execution (`200`, `duplicate: true`);
|
|
70
|
+
- the same id with **another body** is `409 ReplayedDelivery`;
|
|
71
|
+
- the **same signed payload under another delivery id** is the delivery already accepted, since the id is not necessarily signed (GitHub's is not): it joins that delivery (`200`, `duplicate: true`, the original `deliveryId`) and never acts a second time. A changed unsigned header (`x-github-event`) does not make it new either.
|
|
72
|
+
|
|
73
|
+
Deliveries accepted before the signed hash existed (migration `0019_ingress_signed_hash`) have none; a kernel starting fills it in for sources on GitHub's scheme, whose signed payload is the body (so the hash is the body's; one row per body), so their replays join them too. Other schemes sign their delivery id, which refuses such replays already.
|
|
74
|
+
|
|
75
|
+
The trade-off, for schemes that sign neither a timestamp nor an id (GitHub): two genuinely different events with byte-identical bodies would be taken for one (GitHub's payloads differ in practice), and a replay after the retention period is accepted again, since nothing signed dates it. Schemes that sign a timestamp (Slack, Stripe, Eloxiv) refuse old replays by the tolerance window, and their signed payload includes the timestamp, so identical bodies sent at different times stay distinct.
|
|
76
|
+
**Handshakes.** A source with `answer` is asked about a delivery only once its signature verified and its signed timestamp is inside the window. If it answers, that answer is the response (`200`, its body and content type) and the delivery is neither stored nor processed, so it never acts as anyone. A forged or stale handshake is refused like any other delivery (`401`, audited). A throwing `answer` counts as no answer. The Slack connector's `slackEvents` source answers `url_verification` with its challenge as plain text ([docs/connectors/slack.md](../connectors/slack.md); proven in [`registry/test/connector-slack.test.ts`](../../registry/test/connector-slack.test.ts), "answers a signed url_verification with its challenge, ...").
|
|
77
|
+
3. **Accept durably.** The raw delivery (body, hash, kept headers, signed time) is committed before the answer, so `200 { accepted: true, deliveryId, duplicate }` means it will be processed even if the kernel dies the next moment. Then the durable execution `eloxiv.ingress` keyed `<source>:<delivery id>` is started or joined ([Workflow](workflow.md)). A runner's sweep (every `sweepMs`, default 2 s) starts executions for accepted deliveries a crash left without one.
|
|
78
|
+
4. **Act.** In the execution, a journalled step resolves who the delivery acts as:
|
|
79
|
+
- a **link code** in a linked source's delivery completes the link: the code (created by a signed-in member, below) proves the Eloxiv side, the verified delivery proves the platform side. Outcome `linked`, or `link-refused` for an unknown, used or expired code;
|
|
80
|
+
- a **linked** sender acts as the linked actor in the linked organisation; a sender with no link (or none the mapping can name), or, for a source with `receivedBy`, a link in an organisation the receiving account has no active Connection in, is refused: outcome `unlinked`;
|
|
81
|
+
- a **principal** source acts as the named service principal of its organisation; outcome `no-principal` if it does not exist.
|
|
82
|
+
|
|
83
|
+
Then the handler runs through the invocation path as that actor, with surface `ingress` and the idempotency key `<execution id>:handle`: identity is re-checked (a member who left is `Forbidden`), the actor's policy applies, and the call is audited like any other. A linked sender's handler acts through the link: it is a link of the call's chain ([Invocation](invocation.md#authority)), asserted inside each call, so an unlink (or the link moved to someone else) that commits before the call refuses it, and one made while the call holds the link waits for it. The identity step journals what the delivery acts under (the link, or nothing revocable for a declared principal); one journalled before links were, resumed later, is refused. The delivery is settled once, in one transaction guarded by its state: `processed` (`handled`, `linked`), `refused` (`unlinked`, `link-refused`, `no-principal`) or `failed` (the handler's error tag, for example `Forbidden`).
|
|
84
|
+
|
|
85
|
+
### Refusals are audited without the payload
|
|
86
|
+
|
|
87
|
+
Every refusal writes one audit record: action `eloxiv.ingress.<source>`, surface `ingress`, outcome `denied`, the refusal's tag as `errorTag`, the SHA-256 of the body as `inputHash`, the delivery id (when known) as `idempotencyKey`, no actor. A refused request's body and signature are not stored anywhere, and the warning logged carries only the source, the reason and the body's hash. Deliveries refused while processing (`unlinked`, `link-refused`, `no-principal`) are audited the same way once.
|
|
88
|
+
|
|
89
|
+
### `status`
|
|
90
|
+
|
|
91
|
+
`Ingress.status(source, deliveryId)` (in process): the delivery's `state`, `outcome`, `executionId` and `receivedAt`, or nothing if it was never accepted.
|
|
92
|
+
|
|
93
|
+
## Linked identities
|
|
94
|
+
|
|
95
|
+
A table maps (platform, external id) to an actor in an organisation. Links are created only through an authorised flow:
|
|
96
|
+
|
|
97
|
+
1. a signed-in member calls **`createLinkCode`** (`POST /kernel/ingress/createLinkCode`, `{ platform }`): a one-time code (`elxl_…`, stored hashed) for themselves in the organisation they act in, valid 10 minutes, for a platform some source declares;
|
|
98
|
+
2. they send it from the platform (for example `link <code>` to the app's bot), and the verified delivery carrying it links its sender. A code works once: another platform user presenting it later is refused.
|
|
99
|
+
|
|
100
|
+
**`listLinks`** returns the caller's links in the organisation; **`unlink`** removes one of theirs (or anyone's with `eloxiv.machine.manage`). Both operations, like `createLinkCode`, need a signed-in session and are audited as `eloxiv.ingress.<operation>` (see [MachineIdentity](machine-identity.md) for how management operations work). Deleting a service principal deletes its links.
|
|
101
|
+
|
|
102
|
+
## Replying in the delivery's conversation
|
|
103
|
+
|
|
104
|
+
A source that declares `reply: { conversation }` (it must link identities with `receivedBy`) lets its workflow handler answer where the delivery came from. The handler's context then has `ctx.ingress` (no other workflow's does):
|
|
105
|
+
|
|
106
|
+
- `ctx.ingress.reply(step, { text })` posts the text in the delivery's own conversation: the channel and thread `conversation` reads from the verified delivery. It posts through the Connection that received the delivery: the first active Connection in the sender's organisation to the account `receivedBy` names, posted as that Connection's owner (in Slack, the workspace's installer) on Messaging's `sendMessage`. The handler gives only the text. An object with any other key is refused, so a handler cannot name another channel, another thread, another operation or another Connection, and the grant reaches nothing else of the Connection: the sender still cannot use it directly (`Connections.capability` refuses anyone but its owner).
|
|
107
|
+
- **At most once per step, a few per delivery.** The reply is a journalled step. Its claim (`eloxiv.ingress_reply`, kernel migration `0115_ingress_reply`) commits before the platform is asked. A step found claimed already (the process died mid-call) is `unknown` and is never posted again. A delivery is answered at most `MAX_INGRESS_REPLIES` (5) times; a further reply answers `failed`.
|
|
108
|
+
- **Only while both ends hold.** A step claimed already is settled from its own record first (`unknown` with its audit record when it was interrupted), before anything is asserted: recording what happened needs no authority to post again. A new claim asserts the sender's chain (their linked identity, their membership) and the receiving Connection for its owner (still theirs, still active, the owner still a member). Both are confirmed at the claim's commit (`Authority.confirm`): a link or Connection that lapses while the claim runs commits no claim, and nothing is posted. As with an external effect's claim, it is the claim that is checked: a revocation waits for the claim's locks, and one that comes after the claim commits meets the post already under way (one platform call). If either has gone, the reply answers `failed` and nothing is posted. A refusal by the platform is `failed`; a 5xx or a lost answer is `unknown`.
|
|
109
|
+
- **Audited as the Connection acting for the delivery.** Each posted (or failed) reply has an audit record `eloxiv.ingress.reply`. It is written in the same transaction as the reply's outcome; a claim found interrupted is recorded `unknown` with its own audit record (`errorTag: "Interrupted"`). Its actor is the Connection's owner; its `detail` names the Connection, the source, the delivery, the sender and the conversation; its input hash is the text's. `eloxiv.ingress_reply` keeps no text and is deleted with its delivery when the retention ends.
|
|
110
|
+
- `ctx.ingress.sendToAgent(step, { text })` sends the message to the sender's agent (`agent.send`, as the sender) under the channel's settings ([Connections, "Channels"](connections.md#channels)): refused (`{ kind: "refused", reason: "disabled" | "budget" }`) when the agent is not enabled there or the channel's daily budget is used up; in plan mode when the channel's scope is `plan`; in the conversation the thread continues for this person. Its steps are journalled; a send replayed after a crash (its receipt carries no output) finds its run again from the message it created. A kept conversation is replaced by a new one only when `agent.send` refuses it as gone or still busy; a send that may have committed (`ActionFailed` with `effect: "unknown"`, its answer lost) is retried once under its own idempotency key (a kernel workflow's `keyOf`), so a committed one answers its receipt and never starts a second run.
|
|
111
|
+
- `ctx.ingress.agentAnswer(step, { runId | sent, timeoutMs })` waits for one of the sender's agent runs to end. It is durable: journalled looks at the run, read under the sender's chain (`AgentRuntime.status` with the asserted capability), with durable sleeps between them (0.5 s doubling to 15 s), so it survives a restart. It is bounded by `timeoutMs` (default five minutes, at most an hour, judged on the journalled times): a run still going then is cancelled (`agent.cancel`, as the sender) and the wait answers `timedOut`. A run cancelled meanwhile answers `cancelled`; a finished one answers its final text.
|
|
112
|
+
|
|
113
|
+
The slack connector packages it as `slackAgent()` ([docs/connectors/slack.md](../connectors/slack.md#the-agent-in-slack)). Proven against the Slack protocol fake in [`registry/test/slack-agent.test.ts`](../../registry/test/slack-agent.test.ts): an answer in the thread, audited as the installer's Connection; a reply naming another channel refused, the sixth reply refused, a source without `reply` unable to post, the Connection refused to the sender; nothing posted once the sender's link is gone; a run past its deadline cancelled with the person told; an answer posted once after the kernel restarted mid-wait.
|
|
114
|
+
|
|
115
|
+
## Settings
|
|
116
|
+
|
|
117
|
+
`KernelConfig.ingress` (`IngressConfig`): `secrets`, `toleranceS`, `retentionS`, `maxBodyBytes`, `sweepMs`. Environment: `ELOXIV_INGRESS_SECRET_<SOURCE>`, `ELOXIV_INGRESS_TOLERANCE_S`, `ELOXIV_INGRESS_SWEEP_MS`. The body deadline is the kernel's `http.bodyTimeoutMs` (see [MachineIdentity](machine-identity.md#settings)).
|
|
118
|
+
|
|
119
|
+
## Guarantees
|
|
120
|
+
|
|
121
|
+
1. A delivery acts only after its signature verified with one of the source's secrets, in constant time.
|
|
122
|
+
2. A delivery outside the tolerance window, or reusing an accepted id with another body, is refused; an accepted signed payload never acts again within the retention period, whatever delivery id it is presented with.
|
|
123
|
+
3. `2xx` is answered only after the delivery is committed; every accepted delivery is processed, exactly once, in one execution keyed by its id, also across redeliveries and a SIGKILL at any point after acceptance.
|
|
124
|
+
4. A delivery acts as its linked actor or declared principal, through the invocation path with surface `ingress`, under that actor's policy; an unlinked sender never acts. With `receivedBy`, it acts and links only in an organisation connected to the account that received it.
|
|
125
|
+
5. Links are created only by a signed-in member's one-time code arriving in a verified delivery.
|
|
126
|
+
6. Refusals are audited by hash; refused payloads and signatures are never stored.
|
|
127
|
+
7. A source's handshake answer is sent only for a delivery whose signature and signed timestamp hold, and a handshake is never stored or processed.
|
|
128
|
+
|
|
129
|
+
## How an implementation is checked
|
|
130
|
+
|
|
131
|
+
`ingressConformance(harness)` registers, over HTTP against the desk fixture's four sources: a well-signed delivery processed exactly once while delivered three times; secret rotation; bad signatures (wrong secret, tampered body, an unsigned delivery id, none, a GitHub-style source) refused, audited and not stored; stale and future timestamps (Eloxiv and Slack schemes) and replayed ids (with and without a signed timestamp) refused and audited; the same GitHub-signed body under another delivery id (and another event header) joined to the first delivery, acting once; an unlinked sender accepted, then refused and audited, writing nothing; linking only through a one-time code (a guessed code and a reused one refused, unlinking stops it); a linked sender acting under their own policy (refused without the permission, allowed with it); a declared service principal (refused before it exists, acting as it after, keeping only declared headers); a workflow handler inside the delivery's execution as the linked actor with surface `ingress`, joined by Slack's retry; 404, and 413 for a declared length and for a chunked body refused before it ends.
|
|
132
|
+
|
|
133
|
+
The Eloxiv kernel runs it in [`packages/testing/test/ingress.test.ts`](../../packages/testing/test/ingress.test.ts), which also checks that a refused payload and signature appear in no table, that the sweep starts an accepted delivery that has no execution, and that a sender that stops part-way through its body is answered 408 at the deadline. [`packages/testing/test/ingress-restart.test.ts`](../../packages/testing/test/ingress-restart.test.ts) runs the kernel as a child process on the selected runtime and SIGKILLs it after acceptance: once after the handler's action committed but before its step was journalled (the step runs again and gets the replay receipt; a redelivery during the restart joins), and once before any processing.
|
|
134
|
+
|
|
135
|
+
## Not yet guaranteed
|
|
136
|
+
|
|
137
|
+
- **Retention for sources without a signed timestamp** (GitHub): replay protection rests on the stored signed body, so a replay after the retention period (7 days by default) would be accepted again. Raise `retentionS` for such sources if that matters more than storage.
|
|
138
|
+
- **A handler that keeps failing** settles the delivery as `failed` with the error tag; there is no automatic retry of a failed handler or dead-letter view beyond the delivery's state.
|
|
139
|
+
- **Linking UI**: the flow is two kernel operations and a verified delivery; the screens and the bot's reply are a connector's or the app's.
|
|
140
|
+
- **Secrets** come from configuration until the Secrets contract exists.
|
|
141
|
+
- **Per-source rate limits** and backpressure belong to Metering, not yet built.
|