@mrciphersmith/roomyx 0.2.0 → 0.2.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mrciphersmith/roomyx",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
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"
@@ -91,6 +91,9 @@ async function main(): Promise<void> {
91
91
  }
92
92
 
93
93
  main().catch((error) => {
94
- console.error(error);
94
+ // The message, not the object: a stack trace dumped at someone who simply
95
+ // hasn't started a room yet reads as a crash, and matches how cli.ts already
96
+ // reports its own failures.
97
+ console.error(error instanceof Error ? error.message : String(error));
95
98
  process.exit(1);
96
99
  });
@@ -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) => {