@mrciphersmith/roomyx 0.2.0 → 0.3.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/README.md CHANGED
@@ -7,9 +7,11 @@ run at once and be found by id, and a skill-sync path that installs the bundled
7
7
  `startup-room` skill into a project without ever silently overwriting local
8
8
  edits.
9
9
 
10
- roomyx is **read-only** with respect to a room log. Nothing here writes messages
11
- into a room; the write path (`room.post_owner_command`) lives in the
12
- `startup-room` framework, not in this package.
10
+ roomyx never writes to a room log. Owner commands do exist —
11
+ `room.post_owner_command` takes a veto, constraint, added participant or goal
12
+ edit — but the tool only forwards them to the dispatcher that runs the room.
13
+ The log keeps exactly one writer, which is what the room's consistency rests
14
+ on.
13
15
 
14
16
  ## Requirements
15
17
 
@@ -53,10 +55,11 @@ modal, `Esc` closes it, `q` or `Ctrl-C` quits.
53
55
 
54
56
  ## Commands
55
57
 
56
- The orchestrator and the TUI are **separate binaries on purpose** — they are
57
- independent processes, and making the TUI a subcommand of `roomyx` would tie
58
- their lifetimes together. That is why it is `roomyx-client`, with a hyphen, and
59
- not `roomyx client`.
58
+ The TUI ships as its own binary, `roomyx-client`, because it is a separate
59
+ process with a lifetime independent of `serve` and `mcp` — closing it does
60
+ nothing to the room. `roomyx client`, with a space, starts that same TUI from
61
+ the single `roomyx` binary; it is an alias for convenience, not a second
62
+ implementation, and it does not tie the TUI's lifetime to anything.
60
63
 
61
64
  ### `roomyx init`
62
65
 
@@ -88,9 +91,43 @@ Lists rooms that are **confirmed live**, not merely present in the registry —
88
91
  each entry is verified with a real MCP round-trip, and entries that don't answer
89
92
  are pruned from the registry file as a side effect.
90
93
 
94
+ ### `roomyx mcp [flags]`
95
+
96
+ Starts the management MCP server (room listing + skill-sync). Default port
97
+ `4320`. See **Management server** below for tools and flags.
98
+
99
+ ### `roomyx skills sync --target <claude|codex|keryx|all|path> [flags]`
100
+
101
+ Installs the bundled `startup-room` skill into a runtime's skill location.
102
+
103
+ | Target | Path |
104
+ | --- | --- |
105
+ | `claude` | `~/.claude/skills/startup-room/SKILL.md` |
106
+ | `codex` | `~/.codex/skills/startup-room/SKILL.md` |
107
+ | `keryx` | `<cwd>/.metaproject/project-skills/startup-room/SKILL.md` |
108
+ | `all` | all three of the above |
109
+ | anything else | taken as a literal path |
110
+
111
+ | Flag | Default | Meaning |
112
+ | --- | --- | --- |
113
+ | `--yes` | off | Actually write. **Without it nothing is written** — the run reports what it would do and stops. |
114
+ | `--dry-run` | — | Says the same thing explicitly. Redundant unless paired with `--yes`, which it overrides. |
115
+ | `--config <path>` | `.roomyx/config.json` | Where the last-synced hashes are recorded. |
116
+
117
+ Requires `roomyx init` to have run, since that is what creates the config the
118
+ sync records into.
119
+
120
+ **This copies over the target; it does not merge into it.** If you already
121
+ maintain a fuller `startup-room` skill, fold the bundled text into it by hand
122
+ rather than pointing `--yes` at it. See **Skill sync safety** below for what
123
+ roomyx refuses outright.
124
+
91
125
  ### `roomyx-client [flags]`
92
126
 
93
- The terminal UI.
127
+ The terminal UI. `roomyx client` (space, not hyphen) is the same entry — an
128
+ alias so a single `roomyx` binary can attach without a second command on PATH.
129
+ `roomyx-client` remains the dedicated binary: a separate process, independent
130
+ lifetime from `serve`/`mcp`.
94
131
 
95
132
  | Flag | Meaning |
96
133
  | --- | --- |
@@ -110,6 +147,12 @@ list of candidate ids when more than one is.
110
147
  | `room.get_state` | — | Roster and current goal contract. |
111
148
  | `room.get_transcript` | `since_seq: number` | Messages with `seq` greater than `since_seq`, in order. |
112
149
  | `room.get_agent_detail` | `agent_id: string` | One participant's own messages and last-seen status. |
150
+ | `room.post_owner_command` | `kind: veto \| constraint \| add_participant \| goal_edit`, `body: string` | `{ accepted, reason? }` from the dispatcher. |
151
+
152
+ `room.post_owner_command` forwards; it never writes. A dispatcher supplies a
153
+ handler when it embeds the server (`onOwnerCommand` in `serve()`). A room served
154
+ by bare `roomyx serve` has no dispatcher, so the tool answers `accepted: false`
155
+ and says so — better than accepting a command nothing will act on.
113
156
 
114
157
  ### Management server
115
158
 
@@ -119,16 +162,26 @@ and skill-sync — to any MCP client.
119
162
  | Tool | Input | Returns |
120
163
  | --- | --- | --- |
121
164
  | `roomyx.rooms.list` | — | Live, liveness-checked rooms. |
122
- | `roomyx.skills.sync` | `targetPath: string`, `dryRun?: boolean`, `yes?: boolean` | Sync outcome: whether it would write, whether it did, and where the backup went. |
165
+ | `roomyx.skills.sync` | `target?: claude \| codex \| keryx \| all` or `targetPath?: string`, `dryRun?: boolean`, `yes?: boolean` | One result per target: whether it would write, whether it did, and where the backup went. |
123
166
 
124
- This server currently has **no CLI command** — it is exposed as a library entry
125
- point (`serveManagement` in `src/mcp-management/server.ts`) for embedding hosts
126
- to bind.
167
+ Start it with `roomyx mcp` (default port `4320`, so it does not collide with
168
+ `roomyx serve`'s `4319`). Same loopback / `--acknowledge-non-loopback` rules as
169
+ `serve`. It is also a library entry point (`serveManagement` in
170
+ `src/mcp-management/server.ts`) for embedding hosts to bind.
171
+
172
+ | Flag | Default | Meaning |
173
+ | --- | --- | --- |
174
+ | `--port <n>` | `4320` | Listen port. `0` picks an ephemeral one. |
175
+ | `--host <addr>` | `127.0.0.1` | Bind address. |
176
+ | `--acknowledge-non-loopback` | off | Required to bind anything other than loopback. |
177
+ | `--registry <path>` | `.roomyx/rooms/registry.json` | Registry file to list rooms from. |
178
+ | `--config <path>` | `.roomyx/config.json` | Config file skill-sync records hashes in. |
127
179
 
128
180
  ## Skill sync safety
129
181
 
130
- `roomyx.skills.sync` will not silently discard local work. It refuses to write,
131
- and returns a warning instead, in two cases — unless `yes: true` is passed:
182
+ Neither `roomyx skills sync` nor `roomyx.skills.sync` will silently discard
183
+ local work. Both refuse to write, and report a warning instead, in two cases —
184
+ unless `--yes` / `yes: true` is passed:
132
185
 
133
186
  - the target has changed since roomyx last synced it (hand-edited), or
134
187
  - the target already exists but roomyx has **no record of ever having written
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mrciphersmith/roomyx",
3
- "version": "0.2.0",
3
+ "version": "0.3.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,12 +1,66 @@
1
- # startup-room (roomyx-bundled placeholder)
1
+ ---
2
+ name: startup-room
3
+ description: Run a startup-room session with a live, attachable roomyx view. Use when starting, resuming, or observing a multi-persona room and you want the owner to be able to watch it in a terminal UI rather than only through the transcript.
4
+ ---
2
5
 
3
- **This is a placeholder, not the real, live `startup-room` skill content.**
6
+ # startup-room — roomyx integration
4
7
 
5
- Authoring the actual auto-launch-enabled skill text — the version that will
6
- eventually replace `~/.claude/skills/startup-room/SKILL.md` — is explicitly
7
- out of scope for `roomyx-installer` flow 003 (see
8
- `docs/requirements/roomyx-installer/description.md` and `decisions.md` D-02).
9
- This file exists only so `roomyx init` and `roomyx skills sync` have a real
10
- file to stage/copy/diff while the mechanism itself is built and tested.
8
+ **Scope.** This is roomyx's own contribution to the `startup-room` skill: the
9
+ steps that make a room observable while it runs. It is not the startup-room
10
+ methodology itself — persona design, the goal contract, scoring, convergence
11
+ and the rest live in the skill this text is meant to join.
11
12
 
12
- Do not sync this placeholder over a real skill file.
13
+ **How it lands matters.** `roomyx skills sync` copies this file over the
14
+ target; it does not merge into it. If you already maintain a fuller
15
+ `startup-room` skill, treat this as text to fold into your Setup/Kickoff
16
+ section by hand, not as a file to overwrite it with. roomyx backs up whatever
17
+ it replaces to `<target>.bak-<timestamp>` and refuses to write at all without
18
+ `--yes`, but a backup is a way to recover from the wrong move, not a reason to
19
+ make it.
20
+
21
+ ## At kickoff: start a room server
22
+
23
+ If roomyx is available for this project — a `.roomyx/` directory exists, or the
24
+ `roomyx` command resolves on `PATH` — start a server for the room's log as part
25
+ of kickoff:
26
+
27
+ ```bash
28
+ roomyx serve <logPath> --port 0
29
+ ```
30
+
31
+ `--port 0` takes an ephemeral port, so several rooms can run at once without
32
+ colliding. The command prints the bound URL and a short room ID:
33
+
34
+ ```
35
+ roomyx serving /abs/path/room.jsonl at http://127.0.0.1:41235/mcp
36
+ room ID: r-a1b2c3 — attach with `roomyx-client --room r-a1b2c3`
37
+ ```
38
+
39
+ Relay that room ID to the owner in the kickoff confirmation, together with the
40
+ attach command. That is the whole point of starting the server: the owner can
41
+ open the room in a terminal and watch it live instead of waiting for a summary.
42
+
43
+ If roomyx is not available, proceed exactly as you would otherwise. This step
44
+ is additive — a startup-room session has never required roomyx and still
45
+ doesn't.
46
+
47
+ ## While the room runs
48
+
49
+ - The server is **read-only**. It never writes to the room log; the dispatcher
50
+ remains the log's single writer. Attaching, detaching, or closing the TUI has
51
+ no effect on the room.
52
+ - The owner attaches with `roomyx-client --room <id>`, or with a bare
53
+ `roomyx-client` when only one room is live. `roomyx rooms list` shows what is
54
+ actually running — each entry is confirmed with a real call, not just read
55
+ out of the registry file.
56
+ - Owner commands (veto, constraint, add participant, edit goal) reach the
57
+ dispatcher through `room.post_owner_command`. A server started by bare
58
+ `roomyx serve` has no dispatcher attached and will say so rather than
59
+ silently swallow a command; an orchestrator that embeds the server handles
60
+ them itself.
61
+
62
+ ## At shutdown
63
+
64
+ Stop the server with `SIGINT`/`SIGTERM` — it removes its own registry entry on
65
+ the way out. A server killed outright leaves a stale entry behind, which is
66
+ harmless: the next `rooms list` or attach checks liveness and prunes it.
package/src/cli.ts CHANGED
@@ -1,17 +1,20 @@
1
1
  #!/usr/bin/env bun
2
- import { join } from "node:path";
2
+ import { existsSync } from "node:fs";
3
+ import { join, resolve } from "node:path";
3
4
  import { serve } from "./server/serve";
4
5
  import { init } from "./installer/init";
5
6
  import { registerRoom, deregisterRoom, listLiveRooms } from "./installer/registry";
7
+ import { syncSkill } from "./installer/skill-sync";
8
+ import { NAMED_TARGETS, resolveTargets } from "./installer/skill-targets";
9
+ import { serveManagement } from "./mcp-management/server";
6
10
 
7
11
  /**
8
- * `roomyx init` / `roomyx serve <logPath> [...]` / `roomyx rooms list`.
9
- * The TUI is `roomyx-client`, its own binary over src/client/index.ts — the
10
- * orchestrator and the TUI are independent processes by design (decisions.md
11
- * D-06), so they are separate binaries, not subcommands of one process that
12
- * would tie their lifetimes together. Hence the hyphen: `roomyx client`
13
- * would have to be dispatched from here, which is exactly the coupling D-06
14
- * rules out.
12
+ * `roomyx init` / `roomyx serve` / `roomyx rooms list` / `roomyx mcp` /
13
+ * `roomyx skills sync`.
14
+ * The TUI is primarily `roomyx-client` (its own binary over src/client/index.ts)
15
+ * so the orchestrator and the TUI stay independent processes (decisions.md
16
+ * D-06). `roomyx client` is a thin alias that starts that same TUI in this
17
+ * process — a separate invocation from `serve`/`mcp`, not a shared lifetime.
15
18
  */
16
19
 
17
20
  function parseFlags(args: string[]): Record<string, string | boolean> {
@@ -36,9 +39,19 @@ function defaultRegistryPath(): string {
36
39
  return join(process.cwd(), ".roomyx", "rooms", "registry.json");
37
40
  }
38
41
 
42
+ function defaultConfigPath(): string {
43
+ return join(process.cwd(), ".roomyx", "config.json");
44
+ }
45
+
46
+ function bundledSkillPath(): string {
47
+ return join(import.meta.dir, "bundled-skills", "startup-room", "SKILL.md");
48
+ }
49
+
50
+ const USAGE =
51
+ "Usage: roomyx <init|serve <logPath>|client|mcp|rooms list|skills sync --target <claude|codex|keryx|all|path>>";
52
+
39
53
  async function runInit(): Promise<void> {
40
- const bundledSkillPath = join(import.meta.dir, "bundled-skills", "startup-room", "SKILL.md");
41
- const result = init({ cwd: process.cwd(), bundledSkillPath });
54
+ const result = init({ cwd: process.cwd(), bundledSkillPath: bundledSkillPath() });
42
55
  console.log(result.created ? `Created ${result.roomyxDir}` : `${result.roomyxDir} already initialized`);
43
56
  }
44
57
 
@@ -48,16 +61,25 @@ async function runServe(logPath: string | undefined, rest: string[]): Promise<vo
48
61
  process.exit(1);
49
62
  }
50
63
  const flags = parseFlags(rest);
51
- const handle = await serve(logPath, {
64
+ // Absolute, because the registry outlives this process's working directory:
65
+ // `roomyx-client` resolves rooms from wherever the person happened to run it,
66
+ // and a relative logPath means nothing there. The specification's registry
67
+ // example has always shown an absolute path; only the code disagreed.
68
+ const absoluteLogPath = resolve(logPath);
69
+ const handle = await serve(absoluteLogPath, {
52
70
  port: flags.port !== undefined ? Number(flags.port) : undefined,
53
71
  host: typeof flags.host === "string" ? flags.host : undefined,
54
72
  acknowledgeNonLoopback: flags["acknowledge-non-loopback"] === true,
55
73
  });
56
74
 
57
75
  const registryPath = typeof flags.registry === "string" ? flags.registry : defaultRegistryPath();
58
- const entry = registerRoom(registryPath, { port: handle.port, logPath, pid: process.pid });
76
+ const entry = registerRoom(registryPath, {
77
+ port: handle.port,
78
+ logPath: absoluteLogPath,
79
+ pid: process.pid,
80
+ });
59
81
 
60
- console.log(`roomyx serving ${logPath} at ${handle.url}`);
82
+ console.log(`roomyx serving ${absoluteLogPath} at ${handle.url}`);
61
83
  console.log(`room ID: ${entry.id} — attach with \`roomyx-client --room ${entry.id}\``);
62
84
 
63
85
  const shutdown = () => {
@@ -79,6 +101,74 @@ async function runRoomsList(): Promise<void> {
79
101
  }
80
102
  }
81
103
 
104
+ /**
105
+ * `roomyx skills sync --target <claude|codex|keryx|all|path> [--dry-run] [--yes]`.
106
+ *
107
+ * Without `--yes` this reports what it would do and writes nothing — the
108
+ * specification's wording, and D-02's requirement that landing on a real skill
109
+ * file be a separate, deliberate act rather than a side effect of the
110
+ * mechanism existing. `--dry-run` is then the same thing said explicitly.
111
+ */
112
+ async function runSkillsSync(rest: string[]): Promise<void> {
113
+ const flags = parseFlags(rest);
114
+ const target = typeof flags.target === "string" ? flags.target : undefined;
115
+ if (!target) {
116
+ console.error(`Missing --target. Expected one of ${NAMED_TARGETS.join(", ")}, all, or a path.`);
117
+ process.exit(1);
118
+ }
119
+
120
+ const yes = flags.yes === true;
121
+ const dryRun = flags["dry-run"] === true || !yes;
122
+ const configPath = typeof flags.config === "string" ? flags.config : defaultConfigPath();
123
+
124
+ if (!existsSync(configPath)) {
125
+ console.error(`No ${configPath}. Run \`roomyx init\` first.`);
126
+ process.exit(1);
127
+ }
128
+
129
+ for (const { name, path } of resolveTargets(target)) {
130
+ const result = syncSkill({
131
+ bundledSkillPath: bundledSkillPath(),
132
+ targetPath: path,
133
+ configPath,
134
+ dryRun,
135
+ yes,
136
+ });
137
+ console.log(name === path ? path : `${name}: ${path}`);
138
+ for (const warning of result.warnings) console.log(` warning: ${warning}`);
139
+ if (result.written) {
140
+ console.log(result.backedUpTo ? ` written (backup: ${result.backedUpTo})` : " written");
141
+ } else {
142
+ console.log(dryRun ? " would write (pass --yes to apply)" : " not written");
143
+ }
144
+ }
145
+ }
146
+
147
+ async function runMcp(rest: string[]): Promise<void> {
148
+ const flags = parseFlags(rest);
149
+ const handle = await serveManagement(
150
+ {
151
+ registryPath: typeof flags.registry === "string" ? flags.registry : defaultRegistryPath(),
152
+ bundledSkillPath: bundledSkillPath(),
153
+ configPath: typeof flags.config === "string" ? flags.config : defaultConfigPath(),
154
+ },
155
+ {
156
+ port: flags.port !== undefined ? Number(flags.port) : undefined,
157
+ host: typeof flags.host === "string" ? flags.host : undefined,
158
+ acknowledgeNonLoopback: flags["acknowledge-non-loopback"] === true,
159
+ },
160
+ );
161
+
162
+ console.log(`roomyx mcp listening at ${handle.url}`);
163
+ console.log("tools: roomyx.rooms.list, roomyx.skills.sync");
164
+
165
+ const shutdown = () => {
166
+ void handle.close().then(() => process.exit(0));
167
+ };
168
+ process.on("SIGINT", shutdown);
169
+ process.on("SIGTERM", shutdown);
170
+ }
171
+
82
172
  async function main(): Promise<void> {
83
173
  const [command, ...rest] = process.argv.slice(2);
84
174
 
@@ -86,11 +176,18 @@ async function main(): Promise<void> {
86
176
  await runInit();
87
177
  } else if (command === "serve") {
88
178
  await runServe(rest[0], rest.slice(1));
179
+ } else if (command === "client") {
180
+ const { runClient } = await import("./client/index");
181
+ await runClient(rest);
182
+ } else if (command === "mcp") {
183
+ await runMcp(rest);
89
184
  } else if (command === "rooms" && rest[0] === "list") {
90
185
  await runRoomsList();
186
+ } else if (command === "skills" && rest[0] === "sync") {
187
+ await runSkillsSync(rest.slice(1));
91
188
  } else {
92
- console.error("Usage: roomyx <init|serve <logPath>|rooms list>");
93
- console.error("The terminal UI is a separate binary: roomyx-client [--room <id>]");
189
+ console.error(USAGE);
190
+ console.error("The terminal UI is also a separate binary: roomyx-client [--room <id>]");
94
191
  process.exit(1);
95
192
  }
96
193
  }
@@ -19,8 +19,8 @@ function parseFlags(args: string[]): Record<string, string> {
19
19
  return flags;
20
20
  }
21
21
 
22
- async function main(): Promise<void> {
23
- const flags = parseFlags(process.argv.slice(2));
22
+ export async function runClient(argv: string[] = process.argv.slice(2)): Promise<void> {
23
+ const flags = parseFlags(argv);
24
24
  const registryPath = flags["registry"] ?? join(process.cwd(), ".roomyx", "rooms", "registry.json");
25
25
 
26
26
  const resolved = await resolveConnectionUrl({
@@ -90,7 +90,12 @@ async function main(): Promise<void> {
90
90
  });
91
91
  }
92
92
 
93
- main().catch((error) => {
94
- console.error(error);
95
- process.exit(1);
96
- });
93
+ if (import.meta.main) {
94
+ runClient().catch((error) => {
95
+ // The message, not the object: a stack trace dumped at someone who simply
96
+ // hasn't started a room yet reads as a crash, and matches how cli.ts already
97
+ // reports its own failures.
98
+ console.error(error instanceof Error ? error.message : String(error));
99
+ process.exit(1);
100
+ });
101
+ }
@@ -1,4 +1,5 @@
1
- import { existsSync, readFileSync, renameSync, statSync, unlinkSync, writeFileSync } from "node:fs";
1
+ import { existsSync, mkdirSync, readFileSync, renameSync, statSync, unlinkSync, writeFileSync } from "node:fs";
2
+ import { dirname } from "node:path";
2
3
  import { z } from "zod";
3
4
  import { Client } from "@modelcontextprotocol/sdk/client/index.js";
4
5
  import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
@@ -93,6 +94,23 @@ function withLock<T>(registryPath: string, fn: () => T): T {
93
94
  }
94
95
  }
95
96
 
97
+ /**
98
+ * True when there is provably nothing to read: no registry file. Callers that
99
+ * only read use this to skip the lock entirely, because taking the lock means
100
+ * writing a lockfile NEXT TO the registry — which fails with ENOENT when the
101
+ * directory itself doesn't exist yet. That is the shape of the bug this
102
+ * guards: `readRegistryUnlocked` has always tolerated a missing registry, but
103
+ * in an un-`init`ed project no caller ever reached it, because withLock threw
104
+ * first. `roomyx rooms list` printed a bare ENOENT and `roomyx-client` printed
105
+ * a stack trace, both for the ordinary case of "you haven't started a room".
106
+ *
107
+ * Racing a registerRoom that lands right after the check is harmless: the
108
+ * reader returns the empty snapshot it would have returned a moment earlier.
109
+ */
110
+ function hasNoRegistry(path: string): boolean {
111
+ return !existsSync(path);
112
+ }
113
+
96
114
  function readRegistryUnlocked(path: string): { schemaVersion: 1; rooms: RoomRegistryEntry[] } {
97
115
  if (!existsSync(path)) {
98
116
  return { schemaVersion: 1, rooms: [] };
@@ -115,11 +133,19 @@ function generateRoomId(): string {
115
133
  return `r-${Math.random().toString(36).slice(2, 8)}`;
116
134
  }
117
135
 
118
- /** Adds a new room to the registry, generating its id. */
136
+ /**
137
+ * Adds a new room to the registry, generating its id. Creates the registry's
138
+ * directory if it isn't there: a write path has to be able to create its own
139
+ * storage, or `roomyx serve` in an un-`init`ed project binds its port and only
140
+ * then dies registering itself. This is not a back door around D-01's
141
+ * explicit, never-clobbering `init` — it creates one empty directory, not the
142
+ * config and staged skill that `init` scaffolds, and it clobbers nothing.
143
+ */
119
144
  export function registerRoom(
120
145
  registryPath: string,
121
146
  info: { port: number; logPath: string; pid: number },
122
147
  ): RoomRegistryEntry {
148
+ mkdirSync(dirname(registryPath), { recursive: true });
123
149
  return withLock(registryPath, () => {
124
150
  const registry = readRegistryUnlocked(registryPath);
125
151
  const entry: RoomRegistryEntry = {
@@ -134,8 +160,9 @@ export function registerRoom(
134
160
  });
135
161
  }
136
162
 
137
- /** Removes one room by id. No-op if the id isn't present. */
163
+ /** Removes one room by id. No-op if the id — or the whole registry — isn't there. */
138
164
  export function deregisterRoom(registryPath: string, id: string): void {
165
+ if (hasNoRegistry(registryPath)) return;
139
166
  withLock(registryPath, () => {
140
167
  const registry = readRegistryUnlocked(registryPath);
141
168
  writeRegistryUnlocked(
@@ -145,8 +172,9 @@ export function deregisterRoom(registryPath: string, id: string): void {
145
172
  });
146
173
  }
147
174
 
148
- /** All registered rooms, live or not. Empty array if the file doesn't exist. */
175
+ /** All registered rooms, live or not. Empty array if there is no registry yet. */
149
176
  export function listRooms(registryPath: string): RoomRegistryEntry[] {
177
+ if (hasNoRegistry(registryPath)) return [];
150
178
  return withLock(registryPath, () => readRegistryUnlocked(registryPath).rooms);
151
179
  }
152
180
 
@@ -157,6 +185,7 @@ export function listRooms(registryPath: string): RoomRegistryEntry[] {
157
185
  * omitted from the returned list.
158
186
  */
159
187
  export async function listLiveRooms(registryPath: string): Promise<RoomRegistryEntry[]> {
188
+ if (hasNoRegistry(registryPath)) return [];
160
189
  const rooms = withLock(registryPath, () => readRegistryUnlocked(registryPath).rooms);
161
190
  const checks = await Promise.all(
162
191
  rooms.map(async (room) => {
@@ -1,5 +1,6 @@
1
1
  import { createHash } from "node:crypto";
2
- import { copyFileSync, existsSync, readFileSync, writeFileSync } from "node:fs";
2
+ import { copyFileSync, existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
3
+ import { dirname } from "node:path";
3
4
 
4
5
  export interface SyncOptions {
5
6
  bundledSkillPath: string;
@@ -84,6 +85,11 @@ export function syncSkill(options: SyncOptions): SyncResult {
84
85
  copyFileSync(options.targetPath, backedUpTo);
85
86
  }
86
87
 
88
+ // A named target's runtime may be installed without ever having had a
89
+ // startup-room skill, so its directory need not exist. Same failure mode the
90
+ // registry had: the write is ready for a missing file but not a missing
91
+ // directory.
92
+ mkdirSync(dirname(options.targetPath), { recursive: true });
87
93
  writeFileSync(options.targetPath, bundledContent);
88
94
  writeConfig(options.configPath, {
89
95
  ...config,
@@ -0,0 +1,53 @@
1
+ import { homedir } from "node:os";
2
+ import { join } from "node:path";
3
+
4
+ /**
5
+ * The runtimes `roomyx skills sync --target` knows by name. Anything else the
6
+ * flag is given is treated as a literal path, which is what the tests use —
7
+ * D-02 requires the mechanism to be exercised against fixtures, never against
8
+ * a real `~/.claude/skills/...` file.
9
+ */
10
+ export const NAMED_TARGETS = ["claude", "codex", "keryx"] as const;
11
+
12
+ export type NamedSkillTarget = (typeof NAMED_TARGETS)[number];
13
+
14
+ export function isNamedTarget(value: string): value is NamedSkillTarget {
15
+ return (NAMED_TARGETS as readonly string[]).includes(value);
16
+ }
17
+
18
+ /**
19
+ * Where each runtime keeps the `startup-room` skill.
20
+ *
21
+ * Claude and Codex both scope skills to the user, under a home directory.
22
+ * keryx scopes them to the project instead: `.metaproject/project-skills/` is
23
+ * where a project's own skills live, as distinct from `.metaproject/skills/`,
24
+ * which is keryx's own bundled set and not ours to write into.
25
+ */
26
+ export function pathForNamedTarget(target: NamedSkillTarget, cwd: string = process.cwd()): string {
27
+ switch (target) {
28
+ case "claude":
29
+ return join(homedir(), ".claude", "skills", "startup-room", "SKILL.md");
30
+ case "codex":
31
+ return join(homedir(), ".codex", "skills", "startup-room", "SKILL.md");
32
+ case "keryx":
33
+ return join(cwd, ".metaproject", "project-skills", "startup-room", "SKILL.md");
34
+ }
35
+ }
36
+
37
+ /**
38
+ * Turns whatever `--target` was given into concrete paths. `all` fans out to
39
+ * every named runtime; a name resolves to that runtime's path; anything else
40
+ * is passed through as a literal path.
41
+ */
42
+ export function resolveTargets(
43
+ target: string,
44
+ cwd: string = process.cwd(),
45
+ ): { name: string; path: string }[] {
46
+ if (target === "all") {
47
+ return NAMED_TARGETS.map((name) => ({ name, path: pathForNamedTarget(name, cwd) }));
48
+ }
49
+ if (isNamedTarget(target)) {
50
+ return [{ name: target, path: pathForNamedTarget(target, cwd) }];
51
+ }
52
+ return [{ name: target, path: target }];
53
+ }
@@ -4,6 +4,7 @@ import { StreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/
4
4
  import { z } from "zod";
5
5
  import { listLiveRooms } from "../installer/registry";
6
6
  import { syncSkill } from "../installer/skill-sync";
7
+ import { NAMED_TARGETS, resolveTargets } from "../installer/skill-targets";
7
8
 
8
9
  export interface ManagementOptions {
9
10
  registryPath: string;
@@ -12,8 +13,10 @@ export interface ManagementOptions {
12
13
  }
13
14
 
14
15
  export interface ManagementServeOptions {
15
- port: number;
16
+ /** Defaults to 4320 so it does not collide with `roomyx serve` (4319). 0 selects an ephemeral port. */
17
+ port?: number;
16
18
  host?: string;
19
+ acknowledgeNonLoopback?: boolean;
17
20
  }
18
21
 
19
22
  /**
@@ -41,29 +44,47 @@ export function createManagementMcpServer(options: ManagementOptions): McpServer
41
44
  "roomyx.skills.sync",
42
45
  {
43
46
  title: "Sync the bundled startup-room skill",
44
- description: "Diffs/backs-up/writes the bundled skill into a target path (see decisions.md D-02 for safety rules).",
47
+ description:
48
+ "Diffs/backs-up/writes the bundled skill into a target (see decisions.md D-02 for safety rules).",
45
49
  inputSchema: {
46
- targetPath: z.string().min(1),
50
+ target: z
51
+ .enum([...NAMED_TARGETS, "all"])
52
+ .optional()
53
+ .describe("A runtime by name, or `all`. Use targetPath instead for a literal path."),
54
+ targetPath: z.string().min(1).optional().describe("A literal path. Takes precedence over target."),
47
55
  dryRun: z.boolean().optional(),
48
56
  yes: z.boolean().optional(),
49
57
  },
50
58
  },
51
- async ({ targetPath, dryRun, yes }) => ({
52
- content: [
53
- {
54
- type: "text",
55
- text: JSON.stringify(
56
- syncSkill({
57
- bundledSkillPath: options.bundledSkillPath,
58
- targetPath,
59
- configPath: options.configPath,
60
- dryRun,
61
- yes,
62
- }),
63
- ),
64
- },
65
- ],
66
- }),
59
+ async ({ target, targetPath, dryRun, yes }) => {
60
+ // One of the two is required, and neither can be marked required in the
61
+ // schema without excluding the other.
62
+ if (!target && !targetPath) {
63
+ return {
64
+ content: [
65
+ {
66
+ type: "text",
67
+ text: JSON.stringify({
68
+ error: `Pass either target (${[...NAMED_TARGETS, "all"].join(", ")}) or targetPath.`,
69
+ }),
70
+ },
71
+ ],
72
+ };
73
+ }
74
+ const targets = targetPath ? [{ name: targetPath, path: targetPath }] : resolveTargets(target as string);
75
+ const results = targets.map(({ name, path }) => ({
76
+ target: name,
77
+ path,
78
+ ...syncSkill({
79
+ bundledSkillPath: options.bundledSkillPath,
80
+ targetPath: path,
81
+ configPath: options.configPath,
82
+ dryRun,
83
+ yes,
84
+ }),
85
+ }));
86
+ return { content: [{ type: "text", text: JSON.stringify(results) }] };
87
+ },
67
88
  );
68
89
 
69
90
  return server;
@@ -75,39 +96,80 @@ export interface ManagementHandle {
75
96
  close(): Promise<void>;
76
97
  }
77
98
 
78
- /** Binds createManagementMcpServer() to a loopback HTTP transport, same pattern as ../server/serve.ts. */
99
+ const LOOPBACK_HOSTS = new Set(["127.0.0.1", "localhost", "::1"]);
100
+
101
+ /**
102
+ * Binds createManagementMcpServer() to a loopback HTTP transport, same
103
+ * multi-session pattern as ../server/serve.ts: one StreamableHTTP transport
104
+ * only ever completes a single initialize handshake, so each new session
105
+ * gets its own transport + McpServer pair.
106
+ */
79
107
  export async function serveManagement(
80
108
  options: ManagementOptions,
81
109
  serveOptions: ManagementServeOptions,
82
110
  ): Promise<ManagementHandle> {
83
111
  const host = serveOptions.host ?? "127.0.0.1";
84
- const mcpServer = createManagementMcpServer(options);
85
- const transport = new StreamableHTTPServerTransport({ sessionIdGenerator: () => crypto.randomUUID() });
86
- await mcpServer.connect(transport);
112
+ if (!LOOPBACK_HOSTS.has(host) && !serveOptions.acknowledgeNonLoopback) {
113
+ throw new Error(
114
+ `Refusing to bind roomyx mcp to non-loopback host "${host}" without --acknowledge-non-loopback.`,
115
+ );
116
+ }
87
117
 
88
- const httpServer = createServer((req, res) => {
89
- transport.handleRequest(req, res).catch((error) => {
90
- if (!res.headersSent) res.writeHead(500, { "content-type": "application/json" });
91
- res.end(JSON.stringify({ error: error instanceof Error ? error.message : String(error) }));
118
+ const sessions = new Map<string, StreamableHTTPServerTransport>();
119
+
120
+ async function createSession(): Promise<StreamableHTTPServerTransport> {
121
+ const transport = new StreamableHTTPServerTransport({
122
+ sessionIdGenerator: () => crypto.randomUUID(),
123
+ onsessioninitialized: (sessionId) => {
124
+ sessions.set(sessionId, transport);
125
+ },
126
+ onsessionclosed: (sessionId) => {
127
+ sessions.delete(sessionId);
128
+ },
92
129
  });
130
+ const mcpServer = createManagementMcpServer(options);
131
+ await mcpServer.connect(transport);
132
+ return transport;
133
+ }
134
+
135
+ const httpServer = createServer((req, res) => {
136
+ const sessionIdHeader = req.headers["mcp-session-id"];
137
+ const sessionId = typeof sessionIdHeader === "string" ? sessionIdHeader : undefined;
138
+ const existing = sessionId ? sessions.get(sessionId) : undefined;
139
+
140
+ const transportPromise = existing ? Promise.resolve(existing) : createSession();
141
+ transportPromise
142
+ .then((transport) => transport.handleRequest(req, res))
143
+ .catch((error) => {
144
+ if (!res.headersSent) res.writeHead(500, { "content-type": "application/json" });
145
+ res.end(JSON.stringify({ error: error instanceof Error ? error.message : String(error) }));
146
+ });
93
147
  });
94
148
 
149
+ const port = serveOptions.port ?? 4320;
95
150
  try {
96
151
  await new Promise<void>((resolve, reject) => {
97
152
  httpServer.once("error", reject);
98
- httpServer.listen(serveOptions.port, host, () => resolve());
153
+ httpServer.listen(port, host, () => resolve());
99
154
  });
100
155
  } catch (error) {
101
- await mcpServer.close().catch(() => undefined);
156
+ await Promise.all([...sessions.values()].map((t) => t.close().catch(() => undefined)));
102
157
  throw error;
103
158
  }
104
159
 
105
160
  const address = httpServer.address();
106
- const actualPort = typeof address === "object" && address !== null ? address.port : serveOptions.port;
161
+ const actualPort = typeof address === "object" && address !== null ? address.port : port;
107
162
 
108
163
  return {
109
164
  url: `http://${host}:${actualPort}/mcp`,
110
165
  port: actualPort,
111
- close: () => new Promise<void>((resolve, reject) => httpServer.close((err) => (err ? reject(err) : resolve()))),
166
+ close: () =>
167
+ new Promise<void>((resolve, reject) => {
168
+ httpServer.close(async (error) => {
169
+ await Promise.all([...sessions.values()].map((t) => t.close().catch(() => undefined)));
170
+ if (error) reject(error);
171
+ else resolve();
172
+ });
173
+ }),
112
174
  };
113
175
  }
@@ -4,13 +4,42 @@ import { getStateTool } from "./tools/get-state";
4
4
  import { getTranscriptTool } from "./tools/get-transcript";
5
5
  import { getAgentDetailTool } from "./tools/get-agent-detail";
6
6
 
7
+ export const OWNER_COMMAND_KINDS = ["veto", "constraint", "add_participant", "goal_edit"] as const;
8
+
9
+ export type OwnerCommandKind = (typeof OWNER_COMMAND_KINDS)[number];
10
+
11
+ export interface OwnerCommand {
12
+ kind: OwnerCommandKind;
13
+ body: string;
14
+ }
15
+
16
+ export interface OwnerCommandResult {
17
+ accepted: boolean;
18
+ /** Why it was not accepted, or how the dispatcher took it. */
19
+ reason?: string;
20
+ }
21
+
22
+ export interface RoomMcpServerOptions {
23
+ /**
24
+ * Supplied by the dispatcher that embeds this server. `room.post_owner_command`
25
+ * hands the command to it and returns whatever it says.
26
+ *
27
+ * There is deliberately no default that writes anywhere. D-01 makes the
28
+ * dispatcher the log's single writer, and D-02 explicitly rejected the
29
+ * obvious shortcut — a second, home-grown command file for the dispatcher to
30
+ * poll. So with no handler attached the tool exists and refuses, which is
31
+ * the honest answer for a bare `roomyx serve`: nothing is dispatching, and
32
+ * pretending a command was accepted would be worse than saying so.
33
+ */
34
+ onOwnerCommand?: (command: OwnerCommand) => OwnerCommandResult | Promise<OwnerCommandResult>;
35
+ }
36
+
7
37
  /**
8
- * Builds the roomyx MCP server for a given room log file. Read-only: none
9
- * of the three registered tools ever writes to `logPath` (R2-R4, AC4 —
10
- * `room.post_owner_command`, the write path, is out of scope for this
11
- * package; see docs/requirements/roomyx/).
38
+ * Builds the roomyx MCP server for a given room log file. Nothing here writes
39
+ * to `logPath` — not the three read tools (R2-R4, AC4), and not
40
+ * `room.post_owner_command`, which only forwards to the dispatcher (R5, D-01).
12
41
  */
13
- export function createRoomMcpServer(logPath: string): McpServer {
42
+ export function createRoomMcpServer(logPath: string, options: RoomMcpServerOptions = {}): McpServer {
14
43
  const server = new McpServer({ name: "roomyx", version: "0.1.0" });
15
44
 
16
45
  server.registerTool(
@@ -48,5 +77,28 @@ export function createRoomMcpServer(logPath: string): McpServer {
48
77
  }),
49
78
  );
50
79
 
80
+ server.registerTool(
81
+ "room.post_owner_command",
82
+ {
83
+ title: "Post an owner command",
84
+ description:
85
+ "Hands a veto / constraint / add_participant / goal_edit to the dispatcher. Never writes to the room log itself.",
86
+ inputSchema: {
87
+ kind: z.enum(OWNER_COMMAND_KINDS),
88
+ body: z.string().min(1),
89
+ },
90
+ },
91
+ async ({ kind, body }) => {
92
+ const result: OwnerCommandResult = options.onOwnerCommand
93
+ ? await options.onOwnerCommand({ kind, body })
94
+ : {
95
+ accepted: false,
96
+ reason:
97
+ "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.",
98
+ };
99
+ return { content: [{ type: "text", text: JSON.stringify(result) }] };
100
+ },
101
+ );
102
+
51
103
  return server;
52
104
  }
@@ -1,10 +1,11 @@
1
1
  import { createServer } from "node:http";
2
2
  import { StreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/streamableHttp.js";
3
3
  import { createRoomMcpServer } from "./index";
4
+ import type { RoomMcpServerOptions } from "./index";
4
5
 
5
6
  const LOOPBACK_HOSTS = new Set(["127.0.0.1", "localhost", "::1"]);
6
7
 
7
- export interface ServeOptions {
8
+ export interface ServeOptions extends RoomMcpServerOptions {
8
9
  /** Defaults to 4319 (specification.md's default). 0 selects an ephemeral port. */
9
10
  port?: number;
10
11
  host?: string;
@@ -51,7 +52,7 @@ export async function serve(logPath: string, options: ServeOptions): Promise<Ser
51
52
  sessions.delete(sessionId);
52
53
  },
53
54
  });
54
- const mcpServer = createRoomMcpServer(logPath);
55
+ const mcpServer = createRoomMcpServer(logPath, { onOwnerCommand: options.onOwnerCommand });
55
56
  await mcpServer.connect(transport);
56
57
  return transport;
57
58
  }