@mrciphersmith/roomyx 0.9.0 → 0.10.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/CHANGELOG.md CHANGED
@@ -13,6 +13,56 @@ patch and never a minor. The rule, the reason, and an audit of the four of seven
13
13
  releases that followed it are in
14
14
  [`docs/roomyx/versioning.md`](docs/roomyx/versioning.md) and decision D-13.
15
15
 
16
+ ## [0.10.0] — 2026-09-10
17
+
18
+ A minor, because it is breaking: `room.post_owner_command` answers with a status
19
+ instead of a boolean, and `onOwnerCommand` returns one. In `0.x` the minor
20
+ position is the breaking position (D-13).
21
+
22
+ ### Fixed
23
+
24
+ - **An owner command actually reaches the room.** It used to be handed to
25
+ `onOwnerCommand` — a JS function supplied by whoever embeds the server — and
26
+ discarded when there was none. A model-driven orchestrator spawns
27
+ `roomyx serve` as a child process and cannot inject a function into it, so for
28
+ the consumer this feature exists for, the answer was always "no dispatcher is
29
+ attached" and the veto went nowhere. `prd.md` R5's criterion had no measurable
30
+ form because nothing was ever held anywhere.
31
+
32
+ ### Added
33
+
34
+ - **A per-room owner-command queue**, created by `serve()` and shared by every
35
+ session. It is created there and not inside the server factory because that
36
+ factory runs **once per MCP session**: state built inside it belongs to one
37
+ client, so a command posted by the TUI would be invisible to the session that
38
+ has to act on it.
39
+ - **`room.get_pending_owner_commands`** — what nobody has acknowledged, oldest
40
+ first. The dispatcher reads it on its next turn and writes the log line itself:
41
+ the server holds a queue, not a pen (D-01).
42
+ - **`room://owner-queue`** — the same set as a resource, which is the shape a
43
+ host can subscribe to later.
44
+ - **`room.ack_owner_command`** — settles one command, so "pending" keeps meaning
45
+ something. An unknown or already-acknowledged id is **refused**, because a
46
+ dispatcher told "acknowledged" about a command it never held stops looking.
47
+
48
+ ### Changed
49
+
50
+ - **The post response is `{ id, status, reason? }`, with `status` one of
51
+ `queued` | `accepted` | `refused`.** `accepted: boolean` could not express the
52
+ distinction that matters: a command held for a dispatcher that has not read it
53
+ yet is not the same as a command nothing will ever act on, and `false` meant
54
+ both. `queued` is the normal answer for a bare `serve`.
55
+ - **A handler that answers settles the command** rather than leaving it queued.
56
+ Two deliveries of one veto — once to the handler, once to whoever reads the
57
+ queue — is worse than one delivery to a stub the embedder wrote itself.
58
+ - **The queue is bounded (32 unacknowledged).** The server lives as long as the
59
+ room and a room runs for hours, so a queue nothing drains grows for as long as
60
+ somebody keeps posting. A full queue refuses the next post and says how many
61
+ are waiting; a refusal an operator can read beats a leak nobody measures.
62
+ - **The TUI shows three sentences, not two.** `queued` reads as a state, not as
63
+ a failure — showing the feature working as the feature failing is the mistake
64
+ this wording exists to avoid.
65
+
16
66
  ## [0.9.0] — 2026-09-10
17
67
 
18
68
  A minor, because it is breaking: `room.get_transcript` returns an object where it
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mrciphersmith/roomyx",
3
- "version": "0.9.0",
3
+ "version": "0.10.0",
4
4
  "description": "MCP server + terminal UI for startup-room: live room status, chat, per-agent modal, an installable room registry, and skill-sync.",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -101,11 +101,16 @@ async function runLive(url: string): Promise<void> {
101
101
  void roomClient
102
102
  .postOwnerCommand(kind, body)
103
103
  .then((result) => {
104
- viewer.chatView.statusBar.setNotice(
105
- result.accepted
106
- ? `${kind} accepted${result.reason ? ` — ${result.reason}` : ""}`
107
- : `${kind} not accepted — ${result.reason ?? "no reason given"}`,
108
- );
104
+ // Three answers, three sentences. `queued` is not a refusal: the
105
+ // command is held for a dispatcher that has not read it yet, and
106
+ // showing that as "not accepted" would report the feature working as
107
+ // the feature failing.
108
+ const sentence = {
109
+ queued: `${kind} queued — a dispatcher reads it with room.get_pending_owner_commands`,
110
+ accepted: `${kind} accepted${result.reason ? ` — ${result.reason}` : ""}`,
111
+ refused: `${kind} refused — ${result.reason ?? "no reason given"}`,
112
+ }[result.status];
113
+ viewer.chatView.statusBar.setNotice(sentence);
109
114
  })
110
115
  .catch((error: unknown) => {
111
116
  viewer.chatView.statusBar.setNotice(
@@ -2,6 +2,7 @@ import { Client } from "@modelcontextprotocol/sdk/client/index.js";
2
2
  import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
3
3
  import type { MessageEnvelope, RoomState } from "../log/types";
4
4
  import type { TranscriptPage } from "../server/tools/get-transcript";
5
+ import type { OwnerCommandResult } from "../server/index";
5
6
 
6
7
  export type ConnectionStatus = "connecting" | "connected" | "disconnected";
7
8
 
@@ -171,12 +172,16 @@ export class RoomClient {
171
172
  }
172
173
 
173
174
  /**
174
- * Sends an owner command to the room's dispatcher. Not a write to the log —
175
- * the server forwards it and answers with whatever the dispatcher said,
176
- * including `accepted: false` when no dispatcher is attached at all.
175
+ * Sends an owner command to the room. Not a write to the log — the server holds
176
+ * it in the room's queue, or hands it to an embedded dispatcher and reports
177
+ * that verdict.
178
+ *
179
+ * `queued` is a state, not a failure: it means the command is held and nobody
180
+ * has read it yet, which is the normal answer for a room whose dispatcher is
181
+ * an agent that will read the queue on its next turn.
177
182
  */
178
- async postOwnerCommand(kind: string, body: string): Promise<{ accepted: boolean; reason?: string }> {
179
- return this.callTool<{ accepted: boolean; reason?: string }>("room.post_owner_command", { kind, body });
183
+ async postOwnerCommand(kind: string, body: string): Promise<OwnerCommandResult> {
184
+ return this.callTool<OwnerCommandResult>("room.post_owner_command", { kind, body });
180
185
  }
181
186
 
182
187
  private async callTool<T>(name: string, args: Record<string, unknown>): Promise<T> {
@@ -1,25 +1,48 @@
1
1
  import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
2
2
  import { z } from "zod";
3
3
  import { getStateTool } from "./tools/get-state";
4
+ import { OWNER_COMMAND_KINDS, OwnerCommandQueue } from "./owner-queue";
5
+ import type { OwnerCommand, OwnerCommandEnvelope, OwnerCommandKind } from "./owner-queue";
4
6
  import { getTranscriptTool } from "./tools/get-transcript";
5
7
  import { getAgentDetailTool } from "./tools/get-agent-detail";
6
8
 
7
- export const OWNER_COMMAND_KINDS = ["veto", "constraint", "add_participant", "goal_edit"] as const;
8
-
9
- export type OwnerCommandKind = (typeof OWNER_COMMAND_KINDS)[number];
9
+ /**
10
+ * Re-exported so the vocabulary has one home — `owner-queue.ts`, where a command
11
+ * first exists — while everything that already reads it from the server's own
12
+ * surface keeps working.
13
+ */
14
+ export { OWNER_COMMAND_KINDS };
15
+ export type { OwnerCommand, OwnerCommandEnvelope, OwnerCommandKind };
10
16
 
11
- export interface OwnerCommand {
12
- kind: OwnerCommandKind;
13
- body: string;
14
- }
17
+ /**
18
+ * What became of a posted command.
19
+ *
20
+ * `queued` is the third answer and the reason this is not a boolean: a command
21
+ * held for a dispatcher that has not read it yet is **not** the same as a command
22
+ * nothing will ever act on, and `accepted: false` used to mean both. It is also
23
+ * the normal answer for a bare `roomyx serve`.
24
+ */
25
+ export type OwnerCommandStatus = "queued" | "accepted" | "refused";
15
26
 
16
27
  export interface OwnerCommandResult {
17
- accepted: boolean;
18
- /** Why it was not accepted, or how the dispatcher took it. */
28
+ /** The queue entry this command is, so a dispatcher can acknowledge exactly it. */
29
+ id: string;
30
+ status: OwnerCommandStatus;
31
+ /** The dispatcher's own words, when one handled it. */
19
32
  reason?: string;
20
33
  }
21
34
 
22
35
  export interface RoomMcpServerOptions {
36
+ /**
37
+ * The room's owner-command queue, shared by every session.
38
+ *
39
+ * Optional so a unit test or an embedder can build a server on its own — but
40
+ * a caller that wants a command posted in one session to be readable in
41
+ * another MUST pass the same queue to both, which is what `serve()` does.
42
+ * Omitting it gives this server a private queue, and a private queue is
43
+ * invisible to every other client.
44
+ */
45
+ ownerQueue?: OwnerCommandQueue;
23
46
  /**
24
47
  * Supplied by the dispatcher that embeds this server. `room.post_owner_command`
25
48
  * hands the command to it and returns whatever it says.
@@ -31,7 +54,17 @@ export interface RoomMcpServerOptions {
31
54
  * the honest answer for a bare `roomyx serve`: nothing is dispatching, and
32
55
  * pretending a command was accepted would be worse than saying so.
33
56
  */
34
- onOwnerCommand?: (command: OwnerCommand) => OwnerCommandResult | Promise<OwnerCommandResult>;
57
+ /**
58
+ * Supplied by a dispatcher that embeds this server. It is a **second road**
59
+ * into the same queue, not a parallel one: the command is held either way, and
60
+ * a handler that answers settles the entry so that whoever reads the queue
61
+ * does not act on it twice.
62
+ */
63
+ onOwnerCommand?: (
64
+ command: OwnerCommandEnvelope,
65
+ ) =>
66
+ | { status: Exclude<OwnerCommandStatus, "queued">; reason?: string }
67
+ | Promise<{ status: Exclude<OwnerCommandStatus, "queued">; reason?: string }>;
35
68
  }
36
69
 
37
70
  /**
@@ -41,6 +74,9 @@ export interface RoomMcpServerOptions {
41
74
  */
42
75
  export function createRoomMcpServer(logPath: string, options: RoomMcpServerOptions = {}): McpServer {
43
76
  const server = new McpServer({ name: "roomyx", version: "0.1.0" });
77
+ // A private queue when nobody injected one. Correct for a unit test, wrong for
78
+ // a room with more than one client — see the option's own comment.
79
+ const queue = options.ownerQueue ?? new OwnerCommandQueue();
44
80
 
45
81
  server.registerTool(
46
82
  "room.get_state",
@@ -107,23 +143,81 @@ export function createRoomMcpServer(logPath: string, options: RoomMcpServerOptio
107
143
  {
108
144
  title: "Post an owner command",
109
145
  description:
110
- "Hands a veto / constraint / add_participant / goal_edit to the dispatcher. Never writes to the room log itself.",
146
+ "Hands a veto / constraint / add_participant / goal_edit to the room: it is held in the room's queue " +
147
+ "for a dispatcher to read, and settlement is reported as `queued`, `accepted` or `refused`. " +
148
+ "Never writes to the room log itself.",
111
149
  inputSchema: {
112
150
  kind: z.enum(OWNER_COMMAND_KINDS),
113
151
  body: z.string().min(1),
114
152
  },
115
153
  },
116
154
  async ({ kind, body }) => {
117
- const result: OwnerCommandResult = options.onOwnerCommand
118
- ? await options.onOwnerCommand({ kind, body })
119
- : {
120
- accepted: false,
121
- reason:
122
- "No dispatcher is attached to this server, so there is nothing to act on the command. A room served by `roomyx serve` alone is read-only; owner commands need the orchestrator that runs the room to embed this server and handle them.",
123
- };
155
+ // `OwnerQueueFullError` is thrown and the SDK turns it into an error
156
+ // result: a full queue is a refusal with a diagnosis, not a success with a
157
+ // caveat. `accepted: true` for a command that was dropped is the shape
158
+ // this whole item exists to remove.
159
+ const queued = queue.post(kind, body);
160
+
161
+ if (options.onOwnerCommand) {
162
+ // The handler is a dispatcher that embedded this server, so its verdict
163
+ // is the answer — and it SETTLES the entry, because delivering the same
164
+ // veto twice (once to the handler, once to whoever reads the queue) is
165
+ // worse than one delivery to a stub the embedder wrote itself.
166
+ const verdict = await options.onOwnerCommand({ kind, body, id: queued.id });
167
+ queue.ack(queued.id);
168
+ const settled: OwnerCommandResult = { id: queued.id, status: verdict.status };
169
+ if (verdict.reason !== undefined) settled.reason = verdict.reason;
170
+ return { content: [{ type: "text", text: JSON.stringify(settled) }] };
171
+ }
172
+
173
+ const result: OwnerCommandResult = { id: queued.id, status: "queued" };
124
174
  return { content: [{ type: "text", text: JSON.stringify(result) }] };
125
175
  },
126
176
  );
127
177
 
178
+ server.registerTool(
179
+ "room.get_pending_owner_commands",
180
+ {
181
+ title: "Owner commands nobody has acted on",
182
+ description:
183
+ "Commands posted by the owner that have not been acknowledged yet, oldest first. " +
184
+ "Read-only: the room log is still written only by the dispatcher.",
185
+ },
186
+ async () => ({ content: [{ type: "text", text: JSON.stringify(queue.list()) }] }),
187
+ );
188
+
189
+ server.registerTool(
190
+ "room.ack_owner_command",
191
+ {
192
+ title: "Acknowledge an owner command",
193
+ description:
194
+ "Says that a command has been dealt with, so `pending` keeps meaning something. " +
195
+ "An unknown or already-acknowledged id is refused rather than reported as success.",
196
+ inputSchema: { id: z.string().min(1) },
197
+ },
198
+ async ({ id }) => {
199
+ if (!queue.ack(id)) {
200
+ // Thrown, not returned: the SDK turns this into an error result, and a
201
+ // dispatcher told "acknowledged" about a command it never held would
202
+ // stop looking for it.
203
+ throw new Error(`No pending owner command with id "${id}".`);
204
+ }
205
+ return { content: [{ type: "text", text: JSON.stringify({ acked: true, id }) }] };
206
+ },
207
+ );
208
+
209
+ server.registerResource(
210
+ "owner-queue",
211
+ "room://owner-queue",
212
+ {
213
+ title: "Owner command queue",
214
+ description: "The same pending commands as room.get_pending_owner_commands, as a resource.",
215
+ mimeType: "application/json",
216
+ },
217
+ async (uri) => ({
218
+ contents: [{ uri: uri.href, text: JSON.stringify(queue.list()) }],
219
+ }),
220
+ );
221
+
128
222
  return server;
129
223
  }
@@ -0,0 +1,127 @@
1
+ import { randomUUID } from "node:crypto";
2
+
3
+ /**
4
+ * The owner-command vocabulary, which lives here rather than in `index.ts`
5
+ * because this is where a command first exists.
6
+ *
7
+ * It is here for a structural reason, not a tidy one: `index.ts` imports the
8
+ * queue, so a queue that imported the vocabulary back from `index.ts` made the
9
+ * two modules cyclic. The cycle happened to work under this loader — the
10
+ * bindings are only read inside functions — but "happens to work" is the kind of
11
+ * thing that stops being true when a bundler or a load order changes, and the
12
+ * fix costs nothing: one direction of dependency instead of two.
13
+ */
14
+ export const OWNER_COMMAND_KINDS = ["veto", "constraint", "add_participant", "goal_edit"] as const;
15
+
16
+ export type OwnerCommandKind = (typeof OWNER_COMMAND_KINDS)[number];
17
+
18
+ export interface OwnerCommand {
19
+ kind: OwnerCommandKind;
20
+ body: string;
21
+ }
22
+
23
+ /**
24
+ * A command as it reaches a dispatcher: the same two fields, plus the queue
25
+ * entry's id.
26
+ *
27
+ * The id is what lets an embedded handler and a queue reader talk about the same
28
+ * command — the handler can settle it, or name it in the log line it writes, and
29
+ * the two roads meet at one identity instead of at a coincidence of body text.
30
+ */
31
+ export interface OwnerCommandEnvelope extends OwnerCommand {
32
+ id: string;
33
+ }
34
+
35
+ /**
36
+ * The owner-command queue, and the reason it is a separate object.
37
+ *
38
+ * `room.post_owner_command` used to hand the command straight to
39
+ * `onOwnerCommand` — a JS function supplied by whoever embeds the server. A
40
+ * model-driven orchestrator spawns `roomyx serve` as a child process and cannot
41
+ * inject a function into it, so for the consumer this feature exists for, the
42
+ * tool answered "no dispatcher is attached" and the command was **discarded**.
43
+ * `prd.md` R5's criterion ("at least one interactive command really reaches the
44
+ * room") had no measurable form because nothing was ever held anywhere.
45
+ *
46
+ * The queue is why it lives here and not inside `createRoomMcpServer`:
47
+ * `serveMcpOverHttp` calls that factory **once per session**, so state created
48
+ * inside it belongs to one client. A queue built there would accept the TUI's
49
+ * veto into a structure the dispatcher's own session cannot read — a feature
50
+ * that passes every single-client test and does nothing in the shape it exists
51
+ * for. `serve()` creates the queue and injects it into every session instead.
52
+ *
53
+ * **The server still does not write the room log** (D-01). This is a queue, not
54
+ * a pen: the dispatcher reads it and writes what it decides.
55
+ */
56
+
57
+ /**
58
+ * How many unacknowledged commands are held before posting is refused.
59
+ *
60
+ * A bound rather than unbounded, because the server lives exactly as long as the
61
+ * room and a room runs for hours: with nothing draining it, the queue grows for
62
+ * as long as somebody keeps posting. This project has already shipped one
63
+ * unbounded-retention defect — every MCP session retained for the life of the
64
+ * process — and the fix was a stated ceiling rather than hope. A refusal an
65
+ * operator can read beats a leak nobody measures.
66
+ *
67
+ * 32 is far more than a room needs (an owner sends a veto, not a stream) and
68
+ * small enough that a full queue means something is genuinely wrong.
69
+ */
70
+ export const OWNER_QUEUE_LIMIT = 32;
71
+
72
+ export interface QueuedOwnerCommand {
73
+ id: string;
74
+ kind: OwnerCommandKind;
75
+ body: string;
76
+ /** ISO timestamp, so a dispatcher can tell a fresh veto from a stale one. */
77
+ postedAt: string;
78
+ }
79
+
80
+ /** Thrown when the queue is full. Carries the count, because the number is the diagnosis. */
81
+ export class OwnerQueueFullError extends Error {
82
+ constructor(readonly waiting: number) {
83
+ super(
84
+ `The owner-command queue is full: ${waiting} command(s) have been posted and none has been acknowledged. ` +
85
+ `Nothing is reading the queue — a dispatcher reads it with \`room.get_pending_owner_commands\` and settles each one with \`room.ack_owner_command\`.`,
86
+ );
87
+ }
88
+ }
89
+
90
+ export class OwnerCommandQueue {
91
+ private readonly pending = new Map<string, QueuedOwnerCommand>();
92
+
93
+ /**
94
+ * Holds a command, or refuses when nothing has drained the queue.
95
+ *
96
+ * The refusal is the honest failure: silently dropping the oldest would lose
97
+ * a veto, and silently growing would leak. Refusing says which of the two
98
+ * problems the operator actually has.
99
+ */
100
+ post(kind: OwnerCommandKind, body: string): QueuedOwnerCommand {
101
+ if (this.pending.size >= OWNER_QUEUE_LIMIT) throw new OwnerQueueFullError(this.pending.size);
102
+ const command: QueuedOwnerCommand = {
103
+ id: `cmd-${randomUUID().slice(0, 8)}`,
104
+ kind,
105
+ body,
106
+ postedAt: new Date().toISOString(),
107
+ };
108
+ this.pending.set(command.id, command);
109
+ return command;
110
+ }
111
+
112
+ /** Oldest first: an owner command is a queue, not a set. */
113
+ list(): QueuedOwnerCommand[] {
114
+ return [...this.pending.values()];
115
+ }
116
+
117
+ /**
118
+ * Settles one command. False when the id is not held.
119
+ *
120
+ * Returning false rather than throwing, because the caller decides how loud it
121
+ * should be: the tool turns it into an error, while the handler path calls it
122
+ * right after posting a command it knows is there.
123
+ */
124
+ ack(id: string): boolean {
125
+ return this.pending.delete(id);
126
+ }
127
+ }
@@ -1,4 +1,5 @@
1
1
  import { createRoomMcpServer } from "./index";
2
+ import { OwnerCommandQueue } from "./owner-queue";
2
3
  import type { RoomMcpServerOptions } from "./index";
3
4
  import { serveMcpOverHttp } from "./http-transport";
4
5
  import type { McpHttpTransportHandle } from "./http-transport";
@@ -45,8 +46,15 @@ export async function serve(logPath: string, options: ServeOptions): Promise<Ser
45
46
  // that names the file and the line.
46
47
  loadRoomLog(logPath);
47
48
 
49
+ // ONE queue for the room, created here because this factory runs once per
50
+ // SESSION: state built inside it would belong to a single client, so a command
51
+ // posted by the TUI would be invisible to the dispatcher's own session. This is
52
+ // the difference between a feature and a feature that passes its tests.
53
+ const ownerQueue = new OwnerCommandQueue();
54
+
48
55
  const handle = await serveMcpOverHttp({
49
- createMcpServer: () => createRoomMcpServer(logPath, { onOwnerCommand: options.onOwnerCommand }),
56
+ createMcpServer: () =>
57
+ createRoomMcpServer(logPath, { onOwnerCommand: options.onOwnerCommand, ownerQueue }),
50
58
  commandLabel: "roomyx serve",
51
59
  defaultPort: 4319,
52
60
  port: options.port,