readyroom 0.0.0 → 0.1.4
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/README.md +506 -1
- package/dist/server.mjs +21559 -0
- package/package.json +54 -11
package/README.md
CHANGED
|
@@ -1 +1,506 @@
|
|
|
1
|
-
|
|
1
|
+
<p align="center">
|
|
2
|
+
<a href="https://www.npmjs.com/package/readyroom"><img alt="npm" src="https://img.shields.io/npm/v/readyroom?color=0e646e&labelColor=0B2140"></a>
|
|
3
|
+
<img alt="node ≥ 22" src="https://img.shields.io/badge/node-%E2%89%A5%2022-0e646e?labelColor=0B2140">
|
|
4
|
+
<img alt="three ways to run it: npx, Docker, Cloudflare Worker" src="https://img.shields.io/badge/run-npx%20%7C%20docker%20%7C%20worker-0e646e?labelColor=0B2140">
|
|
5
|
+
<img alt="license: Unlicense" src="https://img.shields.io/badge/license-Unlicense-0e646e?labelColor=0B2140">
|
|
6
|
+
</p>
|
|
7
|
+
|
|
8
|
+
# readyroom
|
|
9
|
+
|
|
10
|
+
**The bridge runs the ship. The ready room decides.**
|
|
11
|
+
|
|
12
|
+
> [!WARNING]
|
|
13
|
+
> readyroom is under active development. Don't rely on it for anything that matters until v1.
|
|
14
|
+
|
|
15
|
+
## What is this?
|
|
16
|
+
|
|
17
|
+
An agent that reaches a decision it should not make alone has two bad options today. It can
|
|
18
|
+
guess, and the guess becomes fact downstream. Or it can stop and wait, which holds its session
|
|
19
|
+
open until a human notices, and usually surfaces as a modal that hijacks whatever you were
|
|
20
|
+
doing.
|
|
21
|
+
|
|
22
|
+
readyroom gives it a third. The agent writes a **ticket** — one question, optional choices,
|
|
23
|
+
minimal context — and goes back to work. You drain the tickets from one page when you get to
|
|
24
|
+
them. The page groups them under the agent that asked, so you always know who is waiting on
|
|
25
|
+
you, and the agent collects the answer the next time it asks.
|
|
26
|
+
|
|
27
|
+
The name is the design. On a ship, the bridge is where the work happens and the **ready room**
|
|
28
|
+
is where the captain steps away to decide something that should not be decided in the noise.
|
|
29
|
+
The whole invariant is **N agents, one interrupt channel**: however many agents you run, they
|
|
30
|
+
share one place to ask and one place for you to answer.
|
|
31
|
+
|
|
32
|
+
## Why readyroom
|
|
33
|
+
|
|
34
|
+
- **No agent ever blocks.** `ask_human` enqueues a ticket and returns in under 200 ms. A
|
|
35
|
+
blocking tool holds the MCP session open and wedges the client the moment you step away
|
|
36
|
+
from the keyboard for twenty minutes.
|
|
37
|
+
- **The queue survives a restart.** Tickets are written atomically to disk, or to a single
|
|
38
|
+
Durable Object on the Worker. A restart that forgot pending tickets would mean an agent
|
|
39
|
+
waiting forever on a question nobody can see any more.
|
|
40
|
+
- **You know which agent is asking.** Tickets are grouped by **stream** — the agent that
|
|
41
|
+
asked — with the newest stream first. A flat list of questions from four agents is not a
|
|
42
|
+
queue you can drain; it is a pile.
|
|
43
|
+
- **It never takes over your screen.** There is no modal and no focus stealing. The page is a
|
|
44
|
+
**status board, not a chat log**: it shows what is waiting and clears when you have answered.
|
|
45
|
+
- **Draining is keyboard-first.** `j`/`k` to move, `1`-`5` to pick an option, `Enter` to
|
|
46
|
+
submit, `u` to undo. A queue with only a mouse is the slow path, and the point of a queue is
|
|
47
|
+
that it drains quickly.
|
|
48
|
+
- **The log is append-only and never pruned.** An approval log is the only record that a human
|
|
49
|
+
authorised something, so it is kept in full. That is what a log is.
|
|
50
|
+
- **Three ways to run it, one program.** `npx` for one machine, Docker for an always-on box,
|
|
51
|
+
a Cloudflare Worker for when your agents cannot reach either.
|
|
52
|
+
|
|
53
|
+
## Vocabulary
|
|
54
|
+
|
|
55
|
+
These words are used exactly, in code, comments, tool descriptions, and docs. No synonyms.
|
|
56
|
+
|
|
57
|
+
- **ticket** — one pending request: `{ id, stream, question, options, context, urgency, status, created_at, expires_at }`.
|
|
58
|
+
- **stream** — which agent asked. Defaults to `$READYROOM_STREAM`, else `basename(cwd)`.
|
|
59
|
+
- **drain** — the human answering tickets from the page.
|
|
60
|
+
- **heads-up page** — the single HTML page served at `GET /`.
|
|
61
|
+
|
|
62
|
+
The tool names (`ask_human`, `wait_for_answer`, `list_pending`, `cancel_ticket`) are the
|
|
63
|
+
agent-facing contract and do not change with the product name. The product name is a separate
|
|
64
|
+
layer, the way `ripgrep` ships `rg`.
|
|
65
|
+
|
|
66
|
+
## The one rule that matters
|
|
67
|
+
|
|
68
|
+
**`ask_human` enqueues and returns. It never waits.**
|
|
69
|
+
|
|
70
|
+
A blocking tool holds the MCP session open and wedges the client when the human is heads-down
|
|
71
|
+
for twenty minutes. Enqueue-then-poll keeps the transport healthy. `ask_human` returns
|
|
72
|
+
`{ id, status: "pending" }` in under 200 ms.
|
|
73
|
+
|
|
74
|
+
This rule is also what makes the Worker target possible at all. A Workers invocation cannot
|
|
75
|
+
hold a session open for twenty minutes; a request that enqueues and returns is stateless enough
|
|
76
|
+
to run per-request on the edge. There is no blocking variant on any target.
|
|
77
|
+
|
|
78
|
+
The `ask_human` tool description is where the agent learns the protocol: *on `pending`,
|
|
79
|
+
continue with independent work and call `wait_for_answer` again later; do not poll in a tight
|
|
80
|
+
loop.*
|
|
81
|
+
|
|
82
|
+
## The four MCP tools
|
|
83
|
+
|
|
84
|
+
All four tools are identical across all three targets. Only the transport differs.
|
|
85
|
+
|
|
86
|
+
### `ask_human`
|
|
87
|
+
|
|
88
|
+
Enqueues a ticket and returns immediately.
|
|
89
|
+
|
|
90
|
+
```ts
|
|
91
|
+
ask_human({
|
|
92
|
+
question: string, // required. One sentence. What must be decided.
|
|
93
|
+
options?: string[], // optional. 2-5 mutually exclusive choices.
|
|
94
|
+
context?: string, // optional. Minimal text needed to decide. Plain text.
|
|
95
|
+
default_answer?: string, // optional. Used only if the ticket expires. Set it only
|
|
96
|
+
// when it is safe for the agent to proceed without a human.
|
|
97
|
+
timeout_seconds?: number, // optional. Default 1800. Max 86400.
|
|
98
|
+
urgency?: "low" | "normal" | "blocking", // optional. Default "normal".
|
|
99
|
+
stream?: string // optional. Overrides the env/basename default.
|
|
100
|
+
}) => { id: string, status: "pending", expires_at: string }
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### `wait_for_answer`
|
|
104
|
+
|
|
105
|
+
Waits for the human to answer, then returns the result. Returns immediately if the ticket is
|
|
106
|
+
already answered or expired.
|
|
107
|
+
|
|
108
|
+
```ts
|
|
109
|
+
wait_for_answer({
|
|
110
|
+
id: string,
|
|
111
|
+
timeout_seconds?: number // default 60, max 600
|
|
112
|
+
}) => {
|
|
113
|
+
id: string,
|
|
114
|
+
status: "pending" | "answered" | "expired",
|
|
115
|
+
answer?: string,
|
|
116
|
+
answered_by?: string, // "human" | "default"
|
|
117
|
+
answered_at?: string
|
|
118
|
+
}
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
### `list_pending`
|
|
122
|
+
|
|
123
|
+
Lists the tickets still pending across every agent stream. Takes no arguments.
|
|
124
|
+
|
|
125
|
+
```ts
|
|
126
|
+
list_pending({}) => { tickets: Ticket[] }
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
### `cancel_ticket`
|
|
130
|
+
|
|
131
|
+
Cancels a ticket the agent no longer needs answered.
|
|
132
|
+
|
|
133
|
+
```ts
|
|
134
|
+
cancel_ticket({ id: string }) => { id: string, status: "cancelled" }
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
### The `HUMAN ANSWER:` prefix
|
|
138
|
+
|
|
139
|
+
A delivered human answer is prefixed with `HUMAN ANSWER:` so a model can never confuse it with
|
|
140
|
+
its own earlier guess. An answer that came from `default_answer` gets a clearly different
|
|
141
|
+
prefix — `DEFAULT ANSWER (applied on expiry; no human responded):` — because labelling the
|
|
142
|
+
agent's own default as a human answer would be worse than no prefix at all.
|
|
143
|
+
|
|
144
|
+
## Three ways aboard
|
|
145
|
+
|
|
146
|
+
They run the same program. They differ in where it lives and who can reach it.
|
|
147
|
+
|
|
148
|
+
| | `npx` | Docker from GHCR | Cloudflare Worker |
|
|
149
|
+
|---|---|---|---|
|
|
150
|
+
| setup | `npx readyroom` | pull `ghcr.io/therebelrobot/readyroom` | `wrangler deploy` |
|
|
151
|
+
| runs | on the host, as you | in a container, as a non-root user | on the edge, with no box to patch |
|
|
152
|
+
| state | `./.state` on disk | a volume mount | one SQLite Durable Object |
|
|
153
|
+
| reachable from | loopback only, by default | loopback; your LAN through a reverse proxy | anywhere, behind Cloudflare Access |
|
|
154
|
+
| MCP transport | stdio + Streamable HTTP | stdio + Streamable HTTP | Streamable HTTP |
|
|
155
|
+
| live updates | SSE | SSE | polling; the page falls back on its own |
|
|
156
|
+
| best for | trying it in a minute | always-on, arm64, survives reboots | agents that cannot reach your house |
|
|
157
|
+
|
|
158
|
+
### npx — one developer, one machine, thirty seconds
|
|
159
|
+
|
|
160
|
+
```sh
|
|
161
|
+
npx readyroom
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
No config, no container, no account. The server speaks stdio MCP (wire it into your MCP client)
|
|
165
|
+
and also serves Streamable HTTP on the same process for clients that want it.
|
|
166
|
+
|
|
167
|
+
**The singleton.** Three MCP clients spawning `npx readyroom` would otherwise produce three
|
|
168
|
+
processes, three attempts to bind port 8971, and three writers to one `tickets.json` — which
|
|
169
|
+
breaks the single-writer invariant and can corrupt the queue. So:
|
|
170
|
+
|
|
171
|
+
- The **first** process to start becomes the **daemon**: it binds the port, owns the store, and
|
|
172
|
+
writes `${READYROOM_STATE_DIR}/daemon.json` containing `{ pid, port, started_at }`.
|
|
173
|
+
- Every **subsequent** process becomes a **client**: it reads `daemon.json`, confirms the pid is
|
|
174
|
+
alive and `/healthz` answers, then proxies its MCP tool calls to the daemon over
|
|
175
|
+
`http://127.0.0.1:<port>`. It serves stdio on its own file descriptors and nothing else. It
|
|
176
|
+
never writes `tickets.json`.
|
|
177
|
+
|
|
178
|
+
If `daemon.json` is stale (pid dead, or the port refuses), the starting process acquires the
|
|
179
|
+
daemon role itself and overwrites the file. If the daemon is unreachable but a foreign service
|
|
180
|
+
holds the port, the process **refuses to start** with a message naming the port — it never
|
|
181
|
+
silently falls back to a second writer.
|
|
182
|
+
|
|
183
|
+
### Self-hosted Docker on a Raspberry Pi
|
|
184
|
+
|
|
185
|
+
Always-on, arm64, LAN-reachable, survives reboots. The image is multi-arch
|
|
186
|
+
(`linux/amd64,linux/arm64`); arm64 is required because the deploy target is a Pi.
|
|
187
|
+
|
|
188
|
+
```sh
|
|
189
|
+
docker run --rm -d \
|
|
190
|
+
-p 127.0.0.1:8971:8971 \
|
|
191
|
+
-v "$(pwd)/.state:/app/.state" \
|
|
192
|
+
--env-file .env \
|
|
193
|
+
ghcr.io/therebelrobot/readyroom:latest
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
Or as a mergeable compose snippet. It binds to loopback; LAN exposure goes through the reverse
|
|
197
|
+
proxy.
|
|
198
|
+
|
|
199
|
+
```yaml
|
|
200
|
+
services:
|
|
201
|
+
readyroom:
|
|
202
|
+
image: ghcr.io/therebelrobot/readyroom:latest
|
|
203
|
+
container_name: readyroom
|
|
204
|
+
restart: unless-stopped
|
|
205
|
+
stdin_open: true
|
|
206
|
+
ports:
|
|
207
|
+
- "127.0.0.1:8971:8971"
|
|
208
|
+
environment:
|
|
209
|
+
READYROOM_TOKEN: ${READYROOM_TOKEN:?set READYROOM_TOKEN}
|
|
210
|
+
READYROOM_STATE_DIR: /app/.state
|
|
211
|
+
READYROOM_BIND: 0.0.0.0
|
|
212
|
+
volumes:
|
|
213
|
+
- ./readyroom-state:/app/.state
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
The container runs the same Node entry as npx, in stdio-plus-HTTP mode, as a non-root user, and
|
|
217
|
+
handles `SIGTERM`.
|
|
218
|
+
|
|
219
|
+
> [!NOTE]
|
|
220
|
+
> **GHCR packages start private.** After the first publish run, flip the package to public in
|
|
221
|
+
> the GitHub package settings, or `docker pull` will fail with an authentication error.
|
|
222
|
+
|
|
223
|
+
### Cloudflare Worker
|
|
224
|
+
|
|
225
|
+
Always-on, reachable from anywhere, no box to patch. The Worker serves the heads-up page and
|
|
226
|
+
the Streamable HTTP MCP endpoint from the same origin, backed by one SQLite Durable Object
|
|
227
|
+
instance.
|
|
228
|
+
|
|
229
|
+
```sh
|
|
230
|
+
# 1. Supply the token as a secret (never committed).
|
|
231
|
+
wrangler secret put READYROOM_TOKEN
|
|
232
|
+
|
|
233
|
+
# 2. Deploy.
|
|
234
|
+
npm run deploy:worker
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
The MCP endpoint is per-agent: **`POST /mcp/{stream}`**. Each agent gets its own URL, configured
|
|
238
|
+
once in the client. There is no `cwd` on Workers, so `basename(cwd)` cannot be the fallback —
|
|
239
|
+
the stream is required and comes from the path segment or an explicit `stream` tool argument.
|
|
240
|
+
If neither is present, the tool call fails with an error naming both ways to supply it. No
|
|
241
|
+
default is invented.
|
|
242
|
+
|
|
243
|
+
## Environment variables
|
|
244
|
+
|
|
245
|
+
Five variables, plus one optional extra.
|
|
246
|
+
|
|
247
|
+
| Variable | Default | Meaning |
|
|
248
|
+
|---|---|---|
|
|
249
|
+
| `READYROOM_STREAM` | `basename(cwd)` | Default stream for tickets. Overridable per call via the `stream` tool argument. |
|
|
250
|
+
| `READYROOM_TOKEN` | *(unset)* | Shared secret for `/api/*` and the MCP endpoint. Mandatory on Docker and Worker; optional on npx (loopback-only). |
|
|
251
|
+
| `READYROOM_BIND` | `127.0.0.1` | Bind address. A non-loopback value refuses to start unless `READYROOM_TOKEN` is set. |
|
|
252
|
+
| `READYROOM_STATE_DIR` | `./.state` | Directory holding `tickets.json`, `audit.jsonl`, and `daemon.json`. |
|
|
253
|
+
| `READYROOM_PORT` | `8971` | TCP port. Must not collide with 3000-3899, which a worktree helper allocates. |
|
|
254
|
+
| `READYROOM_ALLOWED_ORIGINS` | *(unset)* | Optional. Comma-separated extra origins allowed on the `/mcp` Origin guard, appended to the server's own origin. |
|
|
255
|
+
|
|
256
|
+
### Mapping to the Worker
|
|
257
|
+
|
|
258
|
+
On the Worker these are **`vars` and `secrets` in the Wrangler config, not process
|
|
259
|
+
environment**. The mapping is explicit:
|
|
260
|
+
|
|
261
|
+
| Node env var | Worker equivalent |
|
|
262
|
+
|---|---|
|
|
263
|
+
| `READYROOM_TOKEN` | **Secret.** `wrangler secret put READYROOM_TOKEN`. Never committed. |
|
|
264
|
+
| `READYROOM_ALLOWED_ORIGINS` | `[vars]` in `wrangler.toml` (optional). |
|
|
265
|
+
| `READYROOM_STREAM` | Not applicable — the stream comes from the `POST /mcp/{stream}` path. |
|
|
266
|
+
| `READYROOM_BIND` | Not applicable — there is no bind address on Workers. |
|
|
267
|
+
| `READYROOM_STATE_DIR` | Not applicable — there is no state dir; the Durable Object owns the state. |
|
|
268
|
+
| `READYROOM_PORT` | Not applicable — the Worker is addressed by URL. |
|
|
269
|
+
|
|
270
|
+
## The loopback bind rule, per target
|
|
271
|
+
|
|
272
|
+
An approval endpoint is a privilege-escalation surface — whoever can answer a ticket can grant
|
|
273
|
+
an agent permission to act. The bind rule exists for that reason.
|
|
274
|
+
|
|
275
|
+
- **npx** — binds `127.0.0.1` by default. `READYROOM_BIND` may override, but when it is
|
|
276
|
+
anything other than a loopback address the server **refuses to start** unless
|
|
277
|
+
`READYROOM_TOKEN` is set. With no token configured, `/api/*` is reachable only on loopback,
|
|
278
|
+
where the OS is the access control.
|
|
279
|
+
- **Docker** — the container binds `0.0.0.0` internally and the port is mapped to `127.0.0.1`
|
|
280
|
+
on the host. The process therefore *always* sees a non-loopback bind, so the token is
|
|
281
|
+
mandatory and the refusal rule always applies. **The loopback guarantee comes from the port
|
|
282
|
+
mapping, not from the process.**
|
|
283
|
+
- **Worker** — there is no loopback and no safe fallback configuration. The token is mandatory,
|
|
284
|
+
the refusal rule has no analogue, and the service is public by construction. This is not
|
|
285
|
+
pretended otherwise.
|
|
286
|
+
|
|
287
|
+
## Who has the conn
|
|
288
|
+
|
|
289
|
+
Whoever can answer a ticket can grant an agent permission to act. Three rules follow.
|
|
290
|
+
|
|
291
|
+
1. **Every `/api/*` route requires `Authorization: Bearer $READYROOM_TOKEN`,** compared in
|
|
292
|
+
constant time. The comparison is a shared `constantTimeEqual(a, b)` that compares digests
|
|
293
|
+
byte by byte with no early return — `node:crypto.timingSafeEqual` is a Node builtin and is
|
|
294
|
+
not reliably present on Workers, so one shared implementation is the only way all three
|
|
295
|
+
targets get the same guarantee.
|
|
296
|
+
2. **The page collects the token once and stores it in `localStorage`,** attaching it to every
|
|
297
|
+
request. A `401` drops the stored token and re-prompts.
|
|
298
|
+
3. **The Streamable HTTP MCP endpoint rejects a missing or mismatched `Origin` with `403`.**
|
|
299
|
+
The MCP specification requires this of HTTP transports, and it is the reason the SDK ships
|
|
300
|
+
host and origin validation guards. It is the browser-side guard against a malicious page in
|
|
301
|
+
the same browser POSTing to the local MCP endpoint (DNS rebinding / cross-origin).
|
|
302
|
+
|
|
303
|
+
The reason for all three: an approval endpoint is a privilege-escalation surface.
|
|
304
|
+
|
|
305
|
+
### Never expose this to a public network directly
|
|
306
|
+
|
|
307
|
+
- **LAN access goes through the existing reverse proxy with its own auth in front.** The
|
|
308
|
+
container (or npx process) binds loopback; the reverse proxy terminates TLS, enforces its own
|
|
309
|
+
authentication, and forwards to `127.0.0.1:8971`. The proxy is the only thing on the LAN that
|
|
310
|
+
can reach the port.
|
|
311
|
+
- **Worker deployments should sit behind Cloudflare Access.** The Worker is public by
|
|
312
|
+
construction; Cloudflare Access is the layer that keeps it from being reachable by anyone
|
|
313
|
+
with the URL.
|
|
314
|
+
|
|
315
|
+
Topology:
|
|
316
|
+
|
|
317
|
+
```
|
|
318
|
+
agent (MCP client) ──stdio──▶ readyroom (loopback :8971)
|
|
319
|
+
▲
|
|
320
|
+
human browser ──HTTPS──▶ reverse proxy (own auth) ──▶ 127.0.0.1:8971
|
|
321
|
+
```
|
|
322
|
+
|
|
323
|
+
## The queue and the log
|
|
324
|
+
|
|
325
|
+
One interface, two implementations. The ticket lifecycle — enqueue, expire, answer, undo — is
|
|
326
|
+
written once against the interface and does not branch on target.
|
|
327
|
+
|
|
328
|
+
```ts
|
|
329
|
+
interface TicketStore {
|
|
330
|
+
load(): Promise<void>;
|
|
331
|
+
list(filter: { status?: Status; since?: string }): Promise<Ticket[]>;
|
|
332
|
+
get(id: string): Promise<Ticket | undefined>;
|
|
333
|
+
put(ticket: Ticket): Promise<void>;
|
|
334
|
+
appendAudit(entry: AuditEntry): Promise<void>; // append-only, never updated
|
|
335
|
+
}
|
|
336
|
+
```
|
|
337
|
+
|
|
338
|
+
### `FileTicketStore` (npx / Docker)
|
|
339
|
+
|
|
340
|
+
`${READYROOM_STATE_DIR}/tickets.json`, default `./.state`. Writes are atomic: write
|
|
341
|
+
`tickets.json.tmp`, `fsync`, `rename`. Single process, single writer, loaded on boot. The queue
|
|
342
|
+
must survive a container restart — a restart that forgets pending tickets means an agent waits
|
|
343
|
+
forever.
|
|
344
|
+
|
|
345
|
+
Every state change is also appended to `${READYROOM_STATE_DIR}/audit.jsonl` — one JSON object
|
|
346
|
+
per line.
|
|
347
|
+
|
|
348
|
+
### `DurableObjectTicketStore` (Worker)
|
|
349
|
+
|
|
350
|
+
One Durable Object instance, SQLite-backed via `ctx.storage.sql`, tables `tickets` and `audit`.
|
|
351
|
+
A single DO instance is a single writer with a transaction boundary — exactly the
|
|
352
|
+
`FileTicketStore` invariant expressed on the edge. It is addressed deterministically with
|
|
353
|
+
`idFromName("queue")` so every request lands on the same instance. The migration uses
|
|
354
|
+
`new_sqlite_classes`; `new_classes` would leave the SQL API unavailable.
|
|
355
|
+
|
|
356
|
+
### Invariants that hold on both
|
|
357
|
+
|
|
358
|
+
- **The audit log is append-only and never pruned.** This is a **deliberate difference from a
|
|
359
|
+
retention policy** — an approval log is the only record that a human authorised something, so
|
|
360
|
+
it is kept in full. That is what a log is.
|
|
361
|
+
- **Expiry is evaluated lazily on read.** A ticket is expired if `expires_at` has passed and it
|
|
362
|
+
is still pending; the read path resolves it to `expired` and applies `default_answer` if one
|
|
363
|
+
was set. Workers have no long-lived process, so a timer-based expiry would silently not happen
|
|
364
|
+
there, and divergence between targets on when a ticket expires is worse than a few wasted
|
|
365
|
+
reads. A Cron Trigger on Workers is an optional optimization, never the contract.
|
|
366
|
+
- **The undo window is five minutes,** measured against the audit entry's timestamp.
|
|
367
|
+
|
|
368
|
+
## The Worker's three consequences
|
|
369
|
+
|
|
370
|
+
The Worker has no state dir, no bind address, and no daemon role. Three consequences follow:
|
|
371
|
+
|
|
372
|
+
1. **The token is mandatory.** There is no loopback and no safe fallback, so a token-less
|
|
373
|
+
request to any `/api/*` route is rejected. (On the Node target, a missing token is an allow —
|
|
374
|
+
the bind refusal rule guarantees a token-less server is only reachable on loopback.)
|
|
375
|
+
2. **`/api/events` returns `501`** with a short plain-text body. The heads-up page's polling
|
|
376
|
+
fallback carries the Worker target; no Durable-Object-held stream fleet is built for v1.
|
|
377
|
+
3. **`wait_for_answer` clamps its timeout** to a short window (5 seconds) and returns
|
|
378
|
+
`status: "pending"` promptly rather than erroring. This is the **one place the three targets
|
|
379
|
+
differ in observable behavior.** Returning `pending` promptly means the agent's documented
|
|
380
|
+
protocol — call again later — is already the correct handling, so no agent needs to know
|
|
381
|
+
which target it is talking to.
|
|
382
|
+
|
|
383
|
+
## The heads-up page
|
|
384
|
+
|
|
385
|
+
The page is a **status board**, not a chat log. It shows what is waiting and clears when you
|
|
386
|
+
have answered — which is why there is no markdown parser and no message history.
|
|
387
|
+
|
|
388
|
+
`public/index.html`. One file, shared by all three targets. All CSS and JS inline. No CDN, no
|
|
389
|
+
external origin, no build step. It renders correctly when opened from the server with the
|
|
390
|
+
network otherwise cut. It is inlined at build time into each target's bundle.
|
|
391
|
+
|
|
392
|
+
- **Live.** Subscribes to `/api/events`; if the connection fails, falls back to polling
|
|
393
|
+
`/api/tickets` every 5 s. This fallback is the Worker target's live-update path, so it is
|
|
394
|
+
load-bearing, not a nicety.
|
|
395
|
+
- **Grouped by stream.** Tickets grouped under a stream heading, newest stream first. You need
|
|
396
|
+
to know which agent is asking.
|
|
397
|
+
- **Card contents.** Stream name, ticket age (`4m`), urgency badge, the question, the context,
|
|
398
|
+
option buttons, a free-text field, and an Answer button.
|
|
399
|
+
- **Keyboard-first.** `j`/`k` move between tickets, `1`-`5` pick an option, `Enter` submits, `u`
|
|
400
|
+
undoes the last answer. Draining a queue with a mouse is the slow path.
|
|
401
|
+
- **Tab title carries the count.** `(3) heads-up`.
|
|
402
|
+
- **No colour-only signalling.** Urgency and status are carried by text and borders as well as
|
|
403
|
+
hue, so the page is legible on an e-ink display and in grayscale print.
|
|
404
|
+
- **No animation on the critical path.** Respects `prefers-reduced-motion`. No hover-only
|
|
405
|
+
affordances — every action is reachable by keyboard and by tap.
|
|
406
|
+
- **Undo.** Answered tickets stay in a "recent" section for 5 minutes with an Undo button that
|
|
407
|
+
calls `/api/undo`.
|
|
408
|
+
- **First paint is synchronous.** Rendered at the end of the script, not inside
|
|
409
|
+
`requestAnimationFrame`, and re-rendered on `window` `load` — the page may be embedded in a
|
|
410
|
+
hidden or zero-sized frame, where rAF never fires. The empty board reads "Nothing on the
|
|
411
|
+
board."
|
|
412
|
+
|
|
413
|
+
`context` is rendered as text with line breaks preserved. There is no markdown parser.
|
|
414
|
+
|
|
415
|
+
## HTTP route table
|
|
416
|
+
|
|
417
|
+
```
|
|
418
|
+
GET /healthz -> 200, body "ok"
|
|
419
|
+
GET / -> the heads-up page (index.html)
|
|
420
|
+
GET /api/tickets -> { tickets: Ticket[] } pending + last 5 min of answered
|
|
421
|
+
GET /api/events -> text/event-stream of ticket changes (501 on the Worker)
|
|
422
|
+
POST /api/answer -> { id, answer, answered_by? } -> 200 | 404 | 409 already answered
|
|
423
|
+
POST /api/undo -> { id } -> 200 | 409 outside the undo window
|
|
424
|
+
POST /mcp/{stream} -> the Streamable HTTP MCP endpoint (Origin-guarded)
|
|
425
|
+
```
|
|
426
|
+
|
|
427
|
+
Unknown route -> `404`. Known route, wrong method -> `405`. The Node target additionally serves
|
|
428
|
+
`POST /internal/tool-call`, the loopback proxy the client process uses.
|
|
429
|
+
|
|
430
|
+
## CI/CD
|
|
431
|
+
|
|
432
|
+
Four GitHub Actions workflows:
|
|
433
|
+
|
|
434
|
+
- **`.github/workflows/ci.yml`** — on push and PR: `npm ci`, typecheck, build,
|
|
435
|
+
`wrangler deploy --dry-run`, `docker build`.
|
|
436
|
+
- **`.github/workflows/publish.yml`** — on the default branch and `v*` tags: buildx for
|
|
437
|
+
`linux/amd64,linux/arm64` (arm64 is required; the deploy target is a Pi), push to GHCR, auth
|
|
438
|
+
via the built-in `GITHUB_TOKEN` with `packages: write` (no PAT, no repo secrets),
|
|
439
|
+
`docker/metadata-action` tags (`latest` on the default branch, semver on `v*`, `sha-<short>`),
|
|
440
|
+
GHA build cache scoped per image, one matrix entry per image. Supply chain:
|
|
441
|
+
`provenance: mode=max`, `sbom: true`, and `actions/attest-build-provenance` pushed to the
|
|
442
|
+
registry.
|
|
443
|
+
- **`.github/workflows/publish-npm.yml`** — on `v*` tags: `npm publish` with provenance, using
|
|
444
|
+
npm Trusted Publishing (OIDC) rather than a stored token. It needs `id-token: write` and the
|
|
445
|
+
trusted-publisher entry configured on the package.
|
|
446
|
+
- **`.github/workflows/deploy-worker.yml`** — on `v*` tags: `wrangler deploy` with
|
|
447
|
+
`CLOUDFLARE_API_TOKEN`. **Optional and off by default** — it only runs when the repository
|
|
448
|
+
variable `ENABLE_WORKER_DEPLOY` is `'true'`. A Worker deploy needs the operator's own
|
|
449
|
+
Cloudflare account, so it is a documented manual step (`npm run deploy:worker`) unless the
|
|
450
|
+
deploy token is supplied.
|
|
451
|
+
|
|
452
|
+
`.github/dependabot.yml` covers `github-actions`, `npm`, and `docker`.
|
|
453
|
+
|
|
454
|
+
### npm publishing
|
|
455
|
+
|
|
456
|
+
Trusted publishing (OIDC) is used, so no `NODE_AUTH_TOKEN` is stored. **The very first publish
|
|
457
|
+
must be interactive** (`npm login && npm publish`) because a trusted-publisher entry can only be
|
|
458
|
+
configured against a package that already exists on the registry. After that, the workflow
|
|
459
|
+
publishes via OIDC.
|
|
460
|
+
|
|
461
|
+
## Development
|
|
462
|
+
|
|
463
|
+
```sh
|
|
464
|
+
npm run dev # tsx watch, with the HTML loader registered
|
|
465
|
+
npm test # node --test over test/*.test.ts, test/core/*.test.ts, test/storage/*.test.ts
|
|
466
|
+
npm run typecheck # tsc --noEmit
|
|
467
|
+
npm run build # esbuild -> dist/server.mjs (single file, HTML inlined)
|
|
468
|
+
npm run build:worker # wrangler deploy --dry-run --outdir dist/worker
|
|
469
|
+
npm run dev:worker # wrangler dev
|
|
470
|
+
```
|
|
471
|
+
|
|
472
|
+
Repo conventions:
|
|
473
|
+
|
|
474
|
+
- TypeScript, Node >= 22. `module` and `moduleResolution` = `ESNext` / `bundler`.
|
|
475
|
+
- **Never** put `.js` extensions in import paths. Import `./queue`, not `./queue.js`.
|
|
476
|
+
- `tsx` for dev, `esbuild` for build. Bundle to a single file, so there is no runtime import
|
|
477
|
+
resolution.
|
|
478
|
+
- Zero runtime dependencies except `@modelcontextprotocol/sdk`. `wrangler` and
|
|
479
|
+
`@cloudflare/workers-types` are devDependencies; Durable Objects are a platform primitive and
|
|
480
|
+
need no package.
|
|
481
|
+
- **All logging goes to stderr.** Nothing may be written to stdout except the MCP protocol. A
|
|
482
|
+
stray `console.log` in a shared module breaks the npx target only — the hardest one to notice.
|
|
483
|
+
- Unlicense.
|
|
484
|
+
|
|
485
|
+
Three entry points, one shared core:
|
|
486
|
+
|
|
487
|
+
- `src/index.ts` — Node entry: daemon-or-client, stdio MCP, HTTP, `FileTicketStore`.
|
|
488
|
+
- `src/worker.ts` — Worker entry: `export default { fetch }`, the Durable Object class,
|
|
489
|
+
`DurableObjectTicketStore`.
|
|
490
|
+
- `src/core/*` — ticket lifecycle, validation, the four tool definitions, the page. No
|
|
491
|
+
target-specific imports anywhere under `src/core/`.
|
|
492
|
+
|
|
493
|
+
## Out of scope
|
|
494
|
+
|
|
495
|
+
No multi-user accounts, no roles, no permissions, no rich markdown rendering, no database, no
|
|
496
|
+
mobile app, no push notifications, no WebSockets, no cloud sync, no LLM in the decision path.
|
|
497
|
+
**The human decides.**
|
|
498
|
+
|
|
499
|
+
Also not in scope: any compliance posture. `readyroom` is a convenience gate, not an
|
|
500
|
+
authorization-of-record system for regulated data. It is not covered by a BAA on any target, its
|
|
501
|
+
audit log has no retention policy, and nothing in it should be treated as evidence a human
|
|
502
|
+
authorized a regulated action. Users who need that should look elsewhere.
|
|
503
|
+
|
|
504
|
+
## License
|
|
505
|
+
|
|
506
|
+
Public domain, under [The Unlicense](LICENSE).
|