@mrciphersmith/roomyx 0.8.2 → 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 +86 -0
- package/package.json +1 -1
- package/src/client/components/status-bar.ts +19 -3
- package/src/client/index.ts +10 -5
- package/src/client/mcp-client.ts +23 -10
- package/src/client/screens/chat-view.ts +1 -1
- package/src/server/index.ts +131 -22
- package/src/server/owner-queue.ts +127 -0
- package/src/server/serve.ts +9 -1
- package/src/server/tools/get-transcript.ts +48 -3
package/CHANGELOG.md
CHANGED
|
@@ -13,6 +13,92 @@ 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
|
+
|
|
66
|
+
## [0.9.0] — 2026-09-10
|
|
67
|
+
|
|
68
|
+
A minor, because it is breaking: `room.get_transcript` returns an object where it
|
|
69
|
+
returned a bare array. In `0.x` the minor position is the breaking position
|
|
70
|
+
(D-13).
|
|
71
|
+
|
|
72
|
+
### Changed
|
|
73
|
+
|
|
74
|
+
- **`room.get_transcript` pages, and says whether it paged.** The response is now
|
|
75
|
+
`{ messages, has_more, next_seq }`. A cold attach at `since_seq: 0` used to ship
|
|
76
|
+
the entire transcript as one text block — 3.8 MB in the room the backlog
|
|
77
|
+
measured — and the consumer on the management path is a language model, so that
|
|
78
|
+
is not slow CPU, it is a context window. Pass `next_seq` back as `since_seq` to
|
|
79
|
+
continue.
|
|
80
|
+
- **The default is bounded (200).** An opt-in limit would have left every
|
|
81
|
+
existing caller shipping the whole room, which is the caller the problem was
|
|
82
|
+
measured on. A bare array could not express "there is more", and a truncated
|
|
83
|
+
list that looks complete is the defect this project keeps re-filing — hence the
|
|
84
|
+
object rather than a silent cap.
|
|
85
|
+
- **`roomyx-client` reads the page and its cursor.** The polling loop takes
|
|
86
|
+
`next_seq` from the response instead of computing `max` over what arrived: the
|
|
87
|
+
server knows which messages it actually sent, and a bounded page means "the
|
|
88
|
+
last seq I received" and "the cursor" are the same number only by luck.
|
|
89
|
+
|
|
90
|
+
### Fixed
|
|
91
|
+
|
|
92
|
+
- **The status bar shows the goal's threshold.** The room is goal-driven and its
|
|
93
|
+
goal is a number to cross; the line carried the goal statement and not the
|
|
94
|
+
number, so a reader could not tell how close the room was. A goal that states
|
|
95
|
+
no threshold gets no invented one.
|
|
96
|
+
- **Over-long status lines are clipped with a marker instead of cut by the pane
|
|
97
|
+
edge.** With `wrapMode: "none"` on a `height: 1` row, a truncated goal read as
|
|
98
|
+
a short goal — and an owner command's answer stopped mid-word: a real veto
|
|
99
|
+
against a dispatcher-less room ended at "…the command. A". Both the goal line
|
|
100
|
+
and a notice now end with the client's own `…` marker.
|
|
101
|
+
|
|
16
102
|
## [0.8.2] — 2026-09-10
|
|
17
103
|
|
|
18
104
|
A patch. Closes the backlog's S3 and corrects two documents that described a
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mrciphersmith/roomyx",
|
|
3
|
-
"version": "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"
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { TextRenderable } from "@opentui/core";
|
|
2
2
|
import type { RenderContext } from "@opentui/core";
|
|
3
|
+
import { clip } from "../clip";
|
|
3
4
|
import type { ConnectionStatus } from "../mcp-client";
|
|
4
5
|
import type { GoalContract } from "../../log/types";
|
|
5
6
|
|
|
@@ -15,11 +16,15 @@ export type DisplayStatus = ConnectionStatus | "closed";
|
|
|
15
16
|
export class StatusBar {
|
|
16
17
|
readonly node: TextRenderable;
|
|
17
18
|
private goalStatement = "";
|
|
19
|
+
/** The number the room exists to cross. Empty when the goal states none. */
|
|
20
|
+
private threshold = "";
|
|
18
21
|
private status: DisplayStatus = "connecting";
|
|
22
|
+
private readonly width: number;
|
|
19
23
|
/** Takes over the line while an owner command is being composed or answered. */
|
|
20
24
|
private notice: string | null = null;
|
|
21
25
|
|
|
22
|
-
constructor(ctx: RenderContext) {
|
|
26
|
+
constructor(ctx: RenderContext, options: { width: number }) {
|
|
27
|
+
this.width = options.width;
|
|
23
28
|
// Same reason as the roster rows: with the default word wrapping, an
|
|
24
29
|
// over-long line went to a second row that `height: 1` clipped, taking the
|
|
25
30
|
// whole trailing word with it. This line carries the goal statement and
|
|
@@ -30,6 +35,12 @@ export class StatusBar {
|
|
|
30
35
|
|
|
31
36
|
setGoalContract(goal: GoalContract): void {
|
|
32
37
|
this.goalStatement = goal.goal_statement;
|
|
38
|
+
// R12: the room is goal-driven, and the goal is a number to cross. Showing
|
|
39
|
+
// the statement without the number left the reader unable to tell how close
|
|
40
|
+
// the room was, in the one line that has room to say it. A goal that states
|
|
41
|
+
// no threshold gets no invented one.
|
|
42
|
+
this.threshold =
|
|
43
|
+
goal.threshold.pass_at_or_above > 0 ? ` · pass ≥${goal.threshold.pass_at_or_above}` : "";
|
|
33
44
|
this.render();
|
|
34
45
|
}
|
|
35
46
|
|
|
@@ -45,8 +56,13 @@ export class StatusBar {
|
|
|
45
56
|
}
|
|
46
57
|
|
|
47
58
|
private render(): void {
|
|
59
|
+
// Clipped rather than cut by the pane edge. `wrapMode: "none"` on a
|
|
60
|
+
// `height: 1` row means anything longer vanished mid-word with nothing to
|
|
61
|
+
// say it had been cut — a truncated goal read as a short goal, and a real
|
|
62
|
+
// vet o's refusal stopped at "…the command. A" (R12, widened 2026-09-09).
|
|
63
|
+
// The client's own cutter is used rather than a second one written here.
|
|
48
64
|
if (this.notice !== null) {
|
|
49
|
-
this.node.content = this.notice;
|
|
65
|
+
this.node.content = clip(this.notice, this.width);
|
|
50
66
|
return;
|
|
51
67
|
}
|
|
52
68
|
const statusLabel = {
|
|
@@ -55,6 +71,6 @@ export class StatusBar {
|
|
|
55
71
|
disconnected: "disconnected — retrying",
|
|
56
72
|
closed: "closed",
|
|
57
73
|
}[this.status];
|
|
58
|
-
this.node.content = `[${statusLabel}] ${this.goalStatement}
|
|
74
|
+
this.node.content = clip(`[${statusLabel}] ${this.goalStatement}${this.threshold}`, this.width);
|
|
59
75
|
}
|
|
60
76
|
}
|
package/src/client/index.ts
CHANGED
|
@@ -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
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
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(
|
package/src/client/mcp-client.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
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
|
+
import type { TranscriptPage } from "../server/tools/get-transcript";
|
|
5
|
+
import type { OwnerCommandResult } from "../server/index";
|
|
4
6
|
|
|
5
7
|
export type ConnectionStatus = "connecting" | "connected" | "disconnected";
|
|
6
8
|
|
|
@@ -170,12 +172,16 @@ export class RoomClient {
|
|
|
170
172
|
}
|
|
171
173
|
|
|
172
174
|
/**
|
|
173
|
-
* Sends an owner command to the room
|
|
174
|
-
* the
|
|
175
|
-
*
|
|
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.
|
|
176
182
|
*/
|
|
177
|
-
async postOwnerCommand(kind: string, body: string): Promise<
|
|
178
|
-
return this.callTool<
|
|
183
|
+
async postOwnerCommand(kind: string, body: string): Promise<OwnerCommandResult> {
|
|
184
|
+
return this.callTool<OwnerCommandResult>("room.post_owner_command", { kind, body });
|
|
179
185
|
}
|
|
180
186
|
|
|
181
187
|
private async callTool<T>(name: string, args: Record<string, unknown>): Promise<T> {
|
|
@@ -244,12 +250,19 @@ export class RoomClient {
|
|
|
244
250
|
const again = () => {
|
|
245
251
|
this.transcriptTimer = setTimeout(() => this.pollTranscript(generation), this.transcriptIntervalMs);
|
|
246
252
|
};
|
|
247
|
-
|
|
248
|
-
|
|
253
|
+
// No `limit`: the poll asks for what has arrived since the last one, which is
|
|
254
|
+
// normally nothing to a couple of messages. The server's default only
|
|
255
|
+
// matters to a caller doing a cold attach, and it pages there.
|
|
256
|
+
this.callTool<TranscriptPage>("room.get_transcript", { since_seq: this.sinceSeq })
|
|
257
|
+
.then((page) => {
|
|
249
258
|
if (this.isStale(generation)) return;
|
|
250
|
-
if (messages.length > 0) {
|
|
251
|
-
|
|
252
|
-
|
|
259
|
+
if (page.messages.length > 0) {
|
|
260
|
+
// The cursor comes from the page rather than from `max` of what arrived:
|
|
261
|
+
// the server knows which messages it actually sent, and a page is
|
|
262
|
+
// bounded, so "the last seq I received" and "the cursor" are the same
|
|
263
|
+
// number only by luck.
|
|
264
|
+
this.sinceSeq = Math.max(this.sinceSeq, page.next_seq);
|
|
265
|
+
this.events.onNewMessages?.(page.messages);
|
|
253
266
|
}
|
|
254
267
|
again();
|
|
255
268
|
})
|
|
@@ -58,7 +58,7 @@ export class ChatView {
|
|
|
58
58
|
) {
|
|
59
59
|
this.ctx = ctx;
|
|
60
60
|
this.node = new BoxRenderable(ctx, { width: options.width, height: options.height, flexDirection: "column" });
|
|
61
|
-
this.statusBar = new StatusBar(ctx);
|
|
61
|
+
this.statusBar = new StatusBar(ctx, { width: options.width });
|
|
62
62
|
this.node.add(this.statusBar.node);
|
|
63
63
|
|
|
64
64
|
const body = new BoxRenderable(ctx, { flexDirection: "row", flexGrow: 1 });
|
package/src/server/index.ts
CHANGED
|
@@ -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
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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
|
-
|
|
18
|
-
|
|
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
|
-
|
|
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",
|
|
@@ -67,11 +103,26 @@ export function createRoomMcpServer(logPath: string, options: RoomMcpServerOptio
|
|
|
67
103
|
"room.get_transcript",
|
|
68
104
|
{
|
|
69
105
|
title: "Room transcript delta",
|
|
70
|
-
description:
|
|
71
|
-
|
|
106
|
+
description:
|
|
107
|
+
"Messages with seq greater than since_seq, in order — at most `limit` of them. " +
|
|
108
|
+
"The result carries has_more and next_seq so a page can be told from a complete answer: " +
|
|
109
|
+
"pass next_seq back as since_seq to continue.",
|
|
110
|
+
inputSchema: {
|
|
111
|
+
since_seq: z.number().int().min(0),
|
|
112
|
+
limit: z.number().int().min(0).optional(),
|
|
113
|
+
},
|
|
72
114
|
},
|
|
73
|
-
async ({ since_seq }) => ({
|
|
74
|
-
content: [
|
|
115
|
+
async ({ since_seq, limit }) => ({
|
|
116
|
+
content: [
|
|
117
|
+
{
|
|
118
|
+
type: "text",
|
|
119
|
+
text: JSON.stringify(
|
|
120
|
+
limit === undefined
|
|
121
|
+
? getTranscriptTool(logPath, since_seq)
|
|
122
|
+
: getTranscriptTool(logPath, since_seq, limit),
|
|
123
|
+
),
|
|
124
|
+
},
|
|
125
|
+
],
|
|
75
126
|
}),
|
|
76
127
|
);
|
|
77
128
|
|
|
@@ -92,23 +143,81 @@ export function createRoomMcpServer(logPath: string, options: RoomMcpServerOptio
|
|
|
92
143
|
{
|
|
93
144
|
title: "Post an owner command",
|
|
94
145
|
description:
|
|
95
|
-
"Hands a veto / constraint / add_participant / goal_edit to the
|
|
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.",
|
|
96
149
|
inputSchema: {
|
|
97
150
|
kind: z.enum(OWNER_COMMAND_KINDS),
|
|
98
151
|
body: z.string().min(1),
|
|
99
152
|
},
|
|
100
153
|
},
|
|
101
154
|
async ({ kind, body }) => {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
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" };
|
|
109
174
|
return { content: [{ type: "text", text: JSON.stringify(result) }] };
|
|
110
175
|
},
|
|
111
176
|
);
|
|
112
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
|
+
|
|
113
222
|
return server;
|
|
114
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
|
+
}
|
package/src/server/serve.ts
CHANGED
|
@@ -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: () =>
|
|
56
|
+
createMcpServer: () =>
|
|
57
|
+
createRoomMcpServer(logPath, { onOwnerCommand: options.onOwnerCommand, ownerQueue }),
|
|
50
58
|
commandLabel: "roomyx serve",
|
|
51
59
|
defaultPort: 4319,
|
|
52
60
|
port: options.port,
|
|
@@ -1,8 +1,53 @@
|
|
|
1
1
|
import { getTranscript, loadRoomLog } from "../../log/store";
|
|
2
2
|
import type { MessageEnvelope } from "../../log/types";
|
|
3
3
|
|
|
4
|
-
/**
|
|
5
|
-
|
|
4
|
+
/**
|
|
5
|
+
* How many messages `room.get_transcript` returns when the caller does not say.
|
|
6
|
+
*
|
|
7
|
+
* There has to be a default, and this is the reason: the caller that existed
|
|
8
|
+
* before this parameter did was passing only `since_seq`, and a cold attach at
|
|
9
|
+
* `since_seq: 0` shipped the entire transcript as one text block — 3.8 MB in the
|
|
10
|
+
* room the backlog measured. The consumer on the management path is a language
|
|
11
|
+
* model, so that is not slow CPU, it is a context window. An opt-in limit would
|
|
12
|
+
* leave every existing caller shipping the whole room.
|
|
13
|
+
*
|
|
14
|
+
* 200 is a page a model can read in one go and a page the TUI never notices: it
|
|
15
|
+
* polls once a second with a cursor, so it is only ever asking for what has
|
|
16
|
+
* arrived since the last poll.
|
|
17
|
+
*/
|
|
18
|
+
export const DEFAULT_TRANSCRIPT_LIMIT = 200;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* A page of the transcript, with the two facts a caller needs to know whether
|
|
22
|
+
* it has the whole answer.
|
|
23
|
+
*
|
|
24
|
+
* It used to be a bare array, which cannot express "there is more" — and a
|
|
25
|
+
* truncated list that looks complete is exactly the defect this project keeps
|
|
26
|
+
* re-filing. `has_more` says whether another call will return anything, and
|
|
27
|
+
* `next_seq` is the cursor to pass as `since_seq` for it, so the caller does not
|
|
28
|
+
* re-derive the cursor from whichever message happened to arrive last.
|
|
29
|
+
*/
|
|
30
|
+
export interface TranscriptPage {
|
|
31
|
+
messages: MessageEnvelope[];
|
|
32
|
+
has_more: boolean;
|
|
33
|
+
next_seq: number;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** MCP tool `room.get_transcript`: messages with seq > sinceSeq, at most `limit`. Read-only. */
|
|
37
|
+
export function getTranscriptTool(
|
|
38
|
+
logPath: string,
|
|
39
|
+
sinceSeq: number,
|
|
40
|
+
limit: number = DEFAULT_TRANSCRIPT_LIMIT,
|
|
41
|
+
): TranscriptPage {
|
|
6
42
|
const { messages } = loadRoomLog(logPath);
|
|
7
|
-
|
|
43
|
+
const after = getTranscript(messages, sinceSeq);
|
|
44
|
+
const page = after.slice(0, Math.max(0, limit));
|
|
45
|
+
return {
|
|
46
|
+
messages: page,
|
|
47
|
+
has_more: after.length > page.length,
|
|
48
|
+
// The cursor advances only over messages actually returned. Advancing it to
|
|
49
|
+
// the last message in the *log* would skip everything the page did not
|
|
50
|
+
// carry, and the log is append-only: nothing would ever fetch it again.
|
|
51
|
+
next_seq: page.length > 0 ? (page[page.length - 1] as MessageEnvelope).seq : sinceSeq,
|
|
52
|
+
};
|
|
8
53
|
}
|