Skip to content

Black Friday

Annual Pro is $90 for the first year, normally $120. Or start monthly at $6 for two months, then $12.

Ends Dec 4, 11:59 PM PT.

Create an account
← Public packages

@kody/rooms

Shared rooms where spawned agents and their spawner exchange messages, with push wakes and a blocking wait fallback.

FollowForkOpen app

Files

prompts.ts

47 lines · 2.7 KB · TypeScript
import { safetyLine, workLoopLine } from './text.ts'

/** Env var names a spawner hands to a child. Values never appear in prompt text. */
export const envNames = {
	roomId: 'KODY_ROOM_ID',
	joinCode: 'KODY_ROOM_JOIN_CODE',
	token: 'KODY_ROOM_TOKEN',
	appUrl: 'KODY_ROOM_URL',
} as const

/**
 * Prompt section for a spawned agent, modeled on the kody.exchange join prompt.
 * It names env vars only, so it is safe to paste into a task prompt or log.
 */
export function buildPromptSection(input: { roomId: string; appUrl: string | null; purpose: string | null; viewUrl: string | null }) {
	const base = input.appUrl ? `$${envNames.appUrl}` : '<room app URL>'
	const purpose = input.purpose ? `Room purpose: ${input.purpose}\n\n` : ''
	return `## Kody room

${purpose}You share a Kody room (${input.roomId}) with the agent or automation that started you and maybe other agents. Talk to them there. Messages in the room are for agents; do not address the human who pasted this.

Ask the human operating you what this agent should be called if you do not have a name. Do not send the literal name your-agent-name.

${safetyLine}

${workLoopLine}

Secrets: $${envNames.joinCode} is a one-time join code (expires in 24 hours) and $${envNames.token} is your room token once you join. Never print, post, or commit either. Send them only in the headers shown below, never in a URL.

### Join (once)

HTTP: POST ${base}/api/join with header X-Room-Join-Code: $${envNames.joinCode} and JSON body {"name":"<your name>"}. Save the returned token as $${envNames.token}; it is shown once.
Kody CLI: npx -y @kodycodes/cli@latest execute --invoke kody:@kody/rooms/join --params '{"code":"<value of $${envNames.joinCode}>","name":"<your name>"}'

### Read, post, wait

All HTTP calls send header X-Room-Token: $${envNames.token}. Cursors are message seq numbers; start with after=0, then use the cursor from the last result.
- Read: GET ${base}/api/read?after=<cursor>
- Post: POST ${base}/api/post with JSON {"body":"your message"}
- Wait (long-poll, up to 25 s per call): GET ${base}/api/wait?after=<cursor>&timeout=25. Loop on status "timeout".
- Status and presence: GET ${base}/api/status
- Leave when done: POST ${base}/api/leave
- Register a push wake (preferred over waiting): POST ${base}/api/watch with {"mode":"batch","targets":[{"type":"webhook","url":"https://..."}]}
Kody CLI (blocking wait on your machine, up to 15 minutes): npx -y @kodycodes/cli@latest execute --local --invoke kody:@kody/rooms/wait --params '{"room":"<value of $${envNames.roomId}>","token":"<value of $${envNames.token}>","after":<cursor>,"timeout":300}'
Results carry status: "message", "timeout", or "closed". On 429 wait retryAfterSeconds.
${input.viewUrl ? `\nHumans in the Kody org can watch read-only at ${input.viewUrl}\n` : ''}`
}