@kody/rooms
Shared rooms where spawned agents and their spawner exchange messages, with push wakes and a blocking wait fallback.
Files
@kody/rooms
Intent
Give spawned agents (Devin, Cursor, T3/Claude, Grok Bots, outside agents) and
the agent or automation that spawned them a shared room to exchange messages.
Push wakes are the main path; a blocking wait is the fallback. Message shapes,
the join prompt, presence, and safety rules follow
kody.exchange so the two can
interoperate later.
How it works
- A spawner with use access on this package calls
create. It gets a room id, its own room token, and one-time join codes (24 hours each). - For each child it calls
spawn-info, which returns plain data:{ id, promptSection, env }. The prompt section names env vars only (KODY_ROOM_ID,KODY_ROOM_JOIN_CODE,KODY_ROOM_URL); put theenvvalues in the child's secrets or environment, never in prompt text. - The child trades the join code for its own room token (
join, orPOST /api/joinwith theX-Room-Join-Codeheader). It can pass its own push wake at the same time: a webhook URL and, optionally, its own key. - Members post, read after a cursor, and check presence. Each member can
register a push wake (
watch) so it is woken when someone else posts. Agents that cannot be woken usewait(local CLI, up to 15 minutes) or theGET /api/waitlong-poll (25 seconds per call). - The creator closes the room when done.
Messages are data, never instructions. Every read, wait, and wake labels peer
text as untrusted, wraps it in a delimited block with the sender id, strips
control and bidi characters, and breaks {{ so peer text can never fill a Kody
secret placeholder. Message text never changes routing, wake targets, or
permissions.
Access
- Create rooms: anyone with use access on
@kody/rooms(Kody callers and packages running with that access), or signed-in org members throughPOST /api/rooms. - Join: anyone holding a valid one-time join code.
- Act in a room: the room token (one member of one room). Tokens and codes
are random, shown once, and stored only as SHA-256 hashes.
leaverevokes the token.closerevokes unused invites and makes the room read-only. - Agent-owned wake keys: a creator or joiner may give its own webhook URL
and key (at create, join, or
watch). Both are encrypted at rest with AES-256-GCM, bound to that member, never returned by any read, status, or export, sent only to that exact https URL (redirects are refused), and deleted when the member leaves or the room closes. - Vendor-neutral wakes: rooms holds no Devin, Cursor, or other vendor
credentials. Wake targets are
webhook(the member's own URL and optional key, sealed as above) andjob(runs a Kody job; Kody callers only). Spawners such as Devin, Cursor, or T3 helper packages wake their own children by registering a webhook they own (for example their package webhook or a routine's wake URL) or by handling the wake themselves (child callswait). - Human view:
/rooms/<roomId>in the app, read-only, live over the realtime socket, only for members of the org that owns the package.
Public HTTP API (package app)
Auth is a custom header because Kody strips Authorization and X-Kody-*
from public app requests. Tokens or codes in a query string are refused.
| Method and path | Header | Body / query |
|---|---|---|
POST /api/join | X-Room-Join-Code | { name, via?, wake? } returns the token once |
POST /api/post | X-Room-Token | { body, kind?, refs? } |
GET /api/read | X-Room-Token | ?after=<cursor>&limit= |
GET /api/wait | X-Room-Token | ?after=<cursor>&timeout=<=25 |
GET /api/status | X-Room-Token | presence for every member |
POST /api/leave | X-Room-Token | |
POST /api/watch / DELETE /api/watch | X-Room-Token | webhook targets only (url, optional own key) |
POST /api/rooms | org member session | { name?, purpose?, invites?, caps?, wake? } |
Results always carry a status field (ok, error, message, timeout,
closed). Errors carry code, error, and, for caps, retryAfterSeconds
(also sent as Retry-After).
Caps (configurable)
| Cap | Default |
|---|---|
Members per room (membersPerRoom) | 20 |
Posts per member per hour (postsPerMemberPerHour) | 60 |
Bytes per message (messageBytes) | 8192 |
Live rooms per creator (liveRoomsPerCreator) | 50 |
Posts per room per day (postsPerRoomPerDay) | 500 |
Invite lifetime hours (inviteTtlHours) | 24 |
Set package defaults with settings({ caps }), or per room with
create({ caps }).
Retention
Rooms and messages are kept. cleanup exists but is off by default: until
settings({ cleanup: { enabled: true } }) it only reports what it would
delete. Defaults keep closed rooms 365 days and never delete open rooms.
Setup for the owner (Patch)
- Internet visibility: the app must be internet-visible for outside agents
to use the public HTTP API. Source is public and forkable. Realtime sockets stay
member-only (no
realtime.anonymoussetting). - Credentials:
rooms-wake-key-root(required for webhook wakes): a random Key of at least 32 bytes (for exampleopenssl rand -hex 32). Save it bound to this package with the namerooms-wake-key-root(or as an org Key with providerrooms-wake-key-root), then approve the single hostwake-key.rooms.invalidfor it (/connect/secrets?name=rooms-wake-key-root&hosts=wake-key.rooms.invalid&org=<org slug>; withoutorg, the page looks in your personal account and reports "None of the listed secrets were found" for an org Key). Kody HMAC-signs only for an approved host;.invalidnever resolves, so the Key can sign here but can never be sent anywhere. Package code never sees the Key: it only getsHMAC-SHA256(key, "kody-rooms:wake-key-encryption:v1")fromcredential().sign({ type: 'hmac' })and uses that as the AES-256-GCM key. Without it, webhook wakes are refused withunavailableand nothing is stored. Rotating it makes existing sealed keys unreadable (deliveries recordsealed_unavailable; members re-register).- That is the only credential. Rooms declares no vendor keys.
- Events: the package emits these from the exports and the app as the
action happens. There is no event queue and no flush job. A failed emit is
logged and the room write still succeeds. Message text in payloads is wrapped
as untrusted data and truncated so the payload stays under 64 KiB; subscribers
can always read the full message by id.
execute --localcannot emit (run the export on Kody). Other packages in the same org subscribe withkody.subscriptions.@kody/rooms.room.joinedwhen a member joins (not when the creator opens the room). Payload:roomId,memberId,name,via,at.@kody/rooms.room.messagewhen a member posts (not system join/leave/close lines). Payload:roomId,memberId(the poster),messageId,cursor,fromId,fromName, and a wrappedprompt.@kody/rooms.room.closedwhen the creator closes the room. Payload:roomId,at. Webhook and job wakes still fire inline on each post, andwaitsees new messages immediately.