Matrix & identities
Matrix is the second channel, proving the channel trait; identities are the single gate every channel checks.
Identities and users (ADR-0004)
Section titled “Identities and users (ADR-0004)”One daemon; one organization. A channel identity resolves to a user (a person), and the user’s role bounds what they may do: admin is the operator (terminal, web panel, CLI), other users get their own session, memory, workspace, toolset and budget (see roles and users). The identities table links channel identities to their user:
ka-agent user invite --role member # the account, if newka-agent identity link telegram 12345 --role member # default: adminka-agent identity link matrix @javier:example.orgka-agent identity role telegram 12345 ops # reassign (audited)ka-agent identity list # shows user + role columnska-agent identity unlink matrix @javier:example.org- Pairing is a one-time code:
ka-agent pair matrixprints one to send to the bot (--role <r>binds the role at pairing time). Unknown senders stay silent and show inka-agent identity pending; a disabled account stays silent too (its identity exists, the account is just off), with one audit row. Linking is CLI-only (ka-agent identity link matrix @you:example.org) and audited (identity.link,identity.unlink,identity.role). An identity whose role was removed from the config fails closed (read-only, engine-muted). - Every channel gates inbound traffic on this table:
telegram:<uid>,matrix:<user_id>, each resolving to a user and their role. Anything else is audited and never answered. - The legacy
[telegram] allow_user_idsis a deprecated migration source: the daemon links each entry at startup (idempotent) and tells you to remove the key. - Unlinking is immediate policy; the channel stops answering that identity on the next message.
The channel trait
Section titled “The channel trait”Channel is name() plus run(shutdown). Telegram and Matrix implement it; the daemon spawns one task per enabled channel over the same runtime and store. Outbound runtime traffic (notes, answers, approval cards, errors) fans out through MultiSurface to every enabled channel, so you see it wherever you are.
Command semantics are shared: every channel parses the same /commands, including /y / /n text approvals, and returns the same replies. Only the transport differs.
Matrix (CS API v3 subset)
Section titled “Matrix (CS API v3 subset)”[matrix]enabled = truehomeserver = "http://127.0.0.1:8008" # local homeserver or TLS-terminating proxyuser_id = "@ka-agent:example.org" # the bot account; own events skippedtoken_secret = "matrix.access_token" # KA_AGENT_SECRET_MATRIX_ACCESS_TOKEN or a 0600 file- Inbound:
/_matrix/client/v3/synclong poll (25s);m.room.messagefrom joined rooms. Thenext_batchcursor persists after dispatch, mirroring the Telegram offset: at-least-once with dedupe; a crash between the two replays the event. - Streaming. An operator turn’s reply streams as one message edited in place: the first draft once 80 bytes have accumulated or 2s passed, then an
m.replaceedit every 2s with at least 80 new bytes (all thresholds count bytes, not characters). The final edit carries the shared renderer’sformatted_body(HTML). Scheduled turns (cron, briefing) are not streamed: their text arrives once, at the end. A failed draft send backs off one interval instead of retrying in a tight loop, and if the homeserver refuses the final edit the full text is posted as its own message so the answer is never truncated. - Room pinning and typing. The first send pins the turn to one room: its edits, final edit and typing stay there even if you write from another linked room meanwhile. Typing starts with the turn and is cleared when it finishes.
- Reminders arrive as their own message,
⏰ <text>, the same prefix the console and terminal use. - Errors: engine errors render as the plain form of the shared error card (
emoji title, one explanation line, one remedy hint, and the first 300 characters of the raw message); a retryable error appends/retry re-sends it(Matrix has no callback buttons, so the text command is the retry affordance). - Attachments in:
m.image/m.file/m.videodownload into<workspace>/attachments/and the room gets the@attachments/<file>reference to paste back. Filenames are sanitized ([A-Za-z0-9._-], no leading dot, at most 64 bytes) so an mxc id tail cannot steer the write; collisions get a-Nsuffix and are created exclusively, never overwritten. In a private conversation (/new private, same as every surface) media lands underattachments/.private-<short-id>/instead, destroyed when the conversation ends; see sessions. - Attachments out:
AgentEvent::Fileuploads and postsm.image/m.filewith the caption as the body. The 50 MB limit is checked from the file’s metadata before it is read, and the caption is capped to one message body (3500 bytes: media bodies cannot split like a reply). - Outbound text goes to the room the sender last wrote from (one room per linked identity); escalations (admin approval cards, memory proposals) go to the admin’s room, self-scope approval cards to the asking user’s own room. Bodies over 3500 bytes split on newline boundaries. Matrix shows formatted text: the same rendered Markdown subset as every other surface.
- Plain HTTP/1.1: point
homeserverat a local homeserver or your TLS-terminating reverse proxy; the client does not do TLS itself. - Approvals: text commands (
/y,/n) and a ✅/❌m.annotationreaction on the card message; both decide through the same runtime call.
Isolation
Section titled “Isolation”One profile per operator remains the OS boundary; two hostile principals run two instances (separate data roots see no episode, grant, identity or memory row of each other, proven by isolation_e2e.rs). Within one profile, users partition each other (ADR-0004): disjoint session, memory, notes, workspace and grant roots per user, enforced in-process (see roles); every user runs as the same UID, so RBAC bounds subjects of the assistant, not hostile tenants.