@mrciphersmith/roomyx 0.4.0 → 0.5.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 +173 -0
- package/README.md +45 -12
- package/package.json +5 -4
- package/src/bin/launch.mjs +68 -0
- package/src/bin/roomyx-client.mjs +8 -0
- package/src/bin/roomyx.mjs +4 -0
- package/src/cli/args.ts +155 -0
- package/src/cli/specs.ts +16 -0
- package/src/cli.ts +304 -151
- package/src/client/index.ts +40 -25
- package/src/log/write.ts +80 -0
- package/src/mcp-management/server.ts +38 -97
- package/src/server/http-transport.ts +149 -0
- package/src/server/serve.ts +13 -86
- package/src/cli/seed.ts +0 -73
package/src/cli.ts
CHANGED
|
@@ -5,36 +5,24 @@ import { serve } from "./server/serve";
|
|
|
5
5
|
import { init } from "./installer/init";
|
|
6
6
|
import { registerRoom, deregisterRoom, listLiveRooms } from "./installer/registry";
|
|
7
7
|
import { syncSkill } from "./installer/skill-sync";
|
|
8
|
+
import { appendMessage, createRoomLog, parseRoster } from "./log/write";
|
|
8
9
|
import { NAMED_TARGETS, resolveTargets } from "./installer/skill-targets";
|
|
9
10
|
import { serveManagement } from "./mcp-management/server";
|
|
11
|
+
import { ArgError, parseArgs, renderFlags } from "./cli/args";
|
|
12
|
+
import type { FlagSpecs, ParsedArgs } from "./cli/args";
|
|
13
|
+
import { CLIENT_FLAGS } from "./cli/specs";
|
|
10
14
|
|
|
11
15
|
/**
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
16
|
+
* The TUI is primarily `roomyx-client` (its own binary over
|
|
17
|
+
* src/client/index.ts) so the orchestrator and the TUI stay independent
|
|
18
|
+
* processes (decisions.md D-06). `roomyx client` is a thin alias that starts
|
|
19
|
+
* that same TUI in this process — a separate invocation from `serve`/`mcp`,
|
|
20
|
+
* not a shared lifetime.
|
|
21
|
+
*
|
|
22
|
+
* Every command declares its flags rather than scanning argv by hand. See
|
|
23
|
+
* `./cli/args` for what that fixes and why it was one defect rather than six.
|
|
18
24
|
*/
|
|
19
25
|
|
|
20
|
-
function parseFlags(args: string[]): Record<string, string | boolean> {
|
|
21
|
-
const flags: Record<string, string | boolean> = {};
|
|
22
|
-
for (let i = 0; i < args.length; i++) {
|
|
23
|
-
const arg = args[i];
|
|
24
|
-
if (arg?.startsWith("--")) {
|
|
25
|
-
const key = arg.slice(2);
|
|
26
|
-
const next = args[i + 1];
|
|
27
|
-
if (next !== undefined && !next.startsWith("--")) {
|
|
28
|
-
flags[key] = next;
|
|
29
|
-
i++;
|
|
30
|
-
} else {
|
|
31
|
-
flags[key] = true;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
return flags;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
26
|
function defaultRegistryPath(): string {
|
|
39
27
|
return join(process.cwd(), ".roomyx", "rooms", "registry.json");
|
|
40
28
|
}
|
|
@@ -47,127 +35,250 @@ function bundledSkillPath(): string {
|
|
|
47
35
|
return join(import.meta.dir, "bundled-skills", "startup-room", "SKILL.md");
|
|
48
36
|
}
|
|
49
37
|
|
|
50
|
-
const
|
|
51
|
-
"Usage: roomyx <init|serve <logPath>|client|mcp|rooms list|skills sync --target <claude|codex|keryx|all|path>>";
|
|
38
|
+
const REGISTRY_FLAG = { type: "string", describe: "Registry file (default .roomyx/rooms/registry.json)" } as const;
|
|
52
39
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
40
|
+
interface Command {
|
|
41
|
+
usage: string;
|
|
42
|
+
summary: string;
|
|
43
|
+
/** Extra lines under the flag table. */
|
|
44
|
+
notes?: string;
|
|
45
|
+
flags: FlagSpecs;
|
|
46
|
+
run: (args: ParsedArgs) => Promise<void>;
|
|
56
47
|
}
|
|
57
48
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
const absoluteLogPath = resolve(logPath);
|
|
69
|
-
const handle = await serve(absoluteLogPath, {
|
|
70
|
-
port: flags.port !== undefined ? Number(flags.port) : undefined,
|
|
71
|
-
host: typeof flags.host === "string" ? flags.host : undefined,
|
|
72
|
-
acknowledgeNonLoopback: flags["acknowledge-non-loopback"] === true,
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
const registryPath = typeof flags.registry === "string" ? flags.registry : defaultRegistryPath();
|
|
76
|
-
const entry = registerRoom(registryPath, {
|
|
77
|
-
port: handle.port,
|
|
78
|
-
logPath: absoluteLogPath,
|
|
79
|
-
pid: process.pid,
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
console.log(`roomyx serving ${absoluteLogPath} at ${handle.url}`);
|
|
83
|
-
console.log(`room ID: ${entry.id} — attach with \`roomyx-client --room ${entry.id}\``);
|
|
84
|
-
|
|
85
|
-
const shutdown = () => {
|
|
86
|
-
deregisterRoom(registryPath, entry.id);
|
|
87
|
-
void handle.close().then(() => process.exit(0));
|
|
88
|
-
};
|
|
89
|
-
process.on("SIGINT", shutdown);
|
|
90
|
-
process.on("SIGTERM", shutdown);
|
|
91
|
-
}
|
|
49
|
+
const COMMANDS: Record<string, Command> = {
|
|
50
|
+
init: {
|
|
51
|
+
usage: "roomyx init",
|
|
52
|
+
summary: "scaffold .roomyx/ in this project",
|
|
53
|
+
flags: {},
|
|
54
|
+
run: async () => {
|
|
55
|
+
const result = init({ cwd: process.cwd(), bundledSkillPath: bundledSkillPath() });
|
|
56
|
+
console.log(result.created ? `Created ${result.roomyxDir}` : `${result.roomyxDir} already initialized`);
|
|
57
|
+
},
|
|
58
|
+
},
|
|
92
59
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
}
|
|
60
|
+
"room new": {
|
|
61
|
+
usage: "roomyx room new <path> --goal <statement> [flags]",
|
|
62
|
+
summary: "create a room log",
|
|
63
|
+
notes: "Refuses to overwrite an existing log — a room log is append-only.",
|
|
64
|
+
flags: {
|
|
65
|
+
goal: { type: "string", describe: "Required. What the room is for, in one sentence" },
|
|
66
|
+
criteria: { type: "string", describe: "Success criteria, stored in the goal contract" },
|
|
67
|
+
roster: { type: "string", describe: "Participants, as id:Name,id2:Name2" },
|
|
68
|
+
},
|
|
69
|
+
run: async ({ positionals, flags }) => {
|
|
70
|
+
const path = positionals[0];
|
|
71
|
+
if (!path) throw new ArgError("Missing <path>.");
|
|
72
|
+
const goalStatement = flags.goal;
|
|
73
|
+
if (typeof goalStatement !== "string") {
|
|
74
|
+
throw new ArgError("Missing --goal. A room without a stated goal has nothing to converge on.");
|
|
75
|
+
}
|
|
76
|
+
const absolute = resolve(path);
|
|
77
|
+
createRoomLog(absolute, {
|
|
78
|
+
goalStatement,
|
|
79
|
+
criteria: typeof flags.criteria === "string" ? flags.criteria : undefined,
|
|
80
|
+
roster: typeof flags.roster === "string" ? parseRoster(flags.roster) : [],
|
|
81
|
+
});
|
|
82
|
+
console.log(`Created ${absolute}`);
|
|
83
|
+
console.log(`serve it with \`roomyx serve ${path}\``);
|
|
84
|
+
},
|
|
85
|
+
},
|
|
103
86
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
87
|
+
"room append": {
|
|
88
|
+
usage: "roomyx room append <path> --from <id> --body <text> [flags]",
|
|
89
|
+
summary: "append a message to a room log",
|
|
90
|
+
notes:
|
|
91
|
+
"Refuses when a live room is serving that log: its dispatcher is the\n single writer (D-01a). --force overrides if you know the room is gone.",
|
|
92
|
+
flags: {
|
|
93
|
+
from: { type: "string", describe: "Required. Participant id" },
|
|
94
|
+
body: { type: "string", describe: "Required. The message" },
|
|
95
|
+
kind: { type: "string", describe: "Message kind, e.g. challenge" },
|
|
96
|
+
"in-reply-to": { type: "number", describe: "seq of the message replied to" },
|
|
97
|
+
force: { type: "boolean", describe: "Append even if a live room serves this log" },
|
|
98
|
+
registry: REGISTRY_FLAG,
|
|
99
|
+
},
|
|
100
|
+
run: async ({ positionals, flags }) => {
|
|
101
|
+
const path = positionals[0];
|
|
102
|
+
if (!path) throw new ArgError("Missing <path>.");
|
|
103
|
+
const from = flags.from;
|
|
104
|
+
const body = flags.body;
|
|
105
|
+
if (typeof from !== "string" || typeof body !== "string") {
|
|
106
|
+
throw new ArgError("Both --from and --body are required.");
|
|
107
|
+
}
|
|
119
108
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
109
|
+
const absolute = resolve(path);
|
|
110
|
+
if (flags.force !== true) {
|
|
111
|
+
const registryPath = typeof flags.registry === "string" ? flags.registry : defaultRegistryPath();
|
|
112
|
+
const serving = (await listLiveRooms(registryPath)).find((room) => room.logPath === absolute);
|
|
113
|
+
if (serving) {
|
|
114
|
+
throw new ArgError(
|
|
115
|
+
`A live room (${serving.id}) is serving this log; its dispatcher is the single writer (D-01). Pass --force if you know it isn't.`,
|
|
116
|
+
);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
123
119
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
120
|
+
const message = appendMessage(absolute, {
|
|
121
|
+
from,
|
|
122
|
+
body,
|
|
123
|
+
kind: typeof flags.kind === "string" ? (flags.kind as never) : undefined,
|
|
124
|
+
inReplyTo: typeof flags["in-reply-to"] === "number" ? flags["in-reply-to"] : undefined,
|
|
125
|
+
});
|
|
126
|
+
console.log(`Appended seq ${message.seq} from ${message.from}.`);
|
|
127
|
+
},
|
|
128
|
+
},
|
|
128
129
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
130
|
+
serve: {
|
|
131
|
+
usage: "roomyx serve <logPath> [flags]",
|
|
132
|
+
summary: "serve a room log over MCP",
|
|
133
|
+
flags: {
|
|
134
|
+
port: { type: "number", describe: "Listen port (default 4319; 0 picks an ephemeral one)" },
|
|
135
|
+
host: { type: "string", describe: "Bind address (default 127.0.0.1)" },
|
|
136
|
+
"acknowledge-non-loopback": { type: "boolean", describe: "Required to bind a non-loopback host" },
|
|
137
|
+
registry: REGISTRY_FLAG,
|
|
138
|
+
},
|
|
139
|
+
run: async ({ positionals, flags }) => {
|
|
140
|
+
const logPath = positionals[0];
|
|
141
|
+
if (!logPath) throw new ArgError("Missing <logPath>.");
|
|
142
|
+
|
|
143
|
+
// Absolute, because the registry outlives this process's working
|
|
144
|
+
// directory: `roomyx-client` resolves rooms from wherever the person
|
|
145
|
+
// happened to run it, and a relative logPath means nothing there.
|
|
146
|
+
const absoluteLogPath = resolve(logPath);
|
|
147
|
+
const handle = await serve(absoluteLogPath, {
|
|
148
|
+
port: typeof flags.port === "number" ? flags.port : undefined,
|
|
149
|
+
host: typeof flags.host === "string" ? flags.host : undefined,
|
|
150
|
+
acknowledgeNonLoopback: flags["acknowledge-non-loopback"] === true,
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
const registryPath = typeof flags.registry === "string" ? flags.registry : defaultRegistryPath();
|
|
154
|
+
const entry = registerRoom(registryPath, {
|
|
155
|
+
port: handle.port,
|
|
156
|
+
logPath: absoluteLogPath,
|
|
157
|
+
pid: process.pid,
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
console.log(`roomyx serving ${absoluteLogPath} at ${handle.url}`);
|
|
161
|
+
console.log(`room ID: ${entry.id} — attach with \`roomyx-client --room ${entry.id}\``);
|
|
146
162
|
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
configPath: typeof flags.config === "string" ? flags.config : defaultConfigPath(),
|
|
163
|
+
const shutdown = () => {
|
|
164
|
+
deregisterRoom(registryPath, entry.id);
|
|
165
|
+
void handle.close().then(() => process.exit(0));
|
|
166
|
+
};
|
|
167
|
+
process.on("SIGINT", shutdown);
|
|
168
|
+
process.on("SIGTERM", shutdown);
|
|
154
169
|
},
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
170
|
+
},
|
|
171
|
+
|
|
172
|
+
"rooms list": {
|
|
173
|
+
usage: "roomyx rooms list [flags]",
|
|
174
|
+
summary: "live rooms, confirmed by a real call rather than by the file",
|
|
175
|
+
flags: { registry: REGISTRY_FLAG },
|
|
176
|
+
run: async ({ flags }) => {
|
|
177
|
+
// `--registry` used to be accepted here and silently ignored: this
|
|
178
|
+
// command took no arguments at all and read the default path, so
|
|
179
|
+
// `rooms list --registry /nonexistent.json` printed "No live rooms"
|
|
180
|
+
// about a different file.
|
|
181
|
+
const registryPath = typeof flags.registry === "string" ? flags.registry : defaultRegistryPath();
|
|
182
|
+
const rooms = await listLiveRooms(registryPath);
|
|
183
|
+
if (rooms.length === 0) {
|
|
184
|
+
console.log("No live rooms.");
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
for (const room of rooms) {
|
|
188
|
+
console.log(`${room.id} port=${room.port} log=${room.logPath} started=${room.startedAt}`);
|
|
189
|
+
}
|
|
159
190
|
},
|
|
160
|
-
|
|
191
|
+
},
|
|
161
192
|
|
|
162
|
-
|
|
163
|
-
|
|
193
|
+
client: {
|
|
194
|
+
usage: "roomyx client [flags]",
|
|
195
|
+
summary: "attach the terminal UI (same as the roomyx-client binary)",
|
|
196
|
+
flags: CLIENT_FLAGS,
|
|
197
|
+
run: async ({ flags }) => {
|
|
198
|
+
const { runClient } = await import("./client/index");
|
|
199
|
+
await runClient(flags);
|
|
200
|
+
},
|
|
201
|
+
},
|
|
164
202
|
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
}
|
|
203
|
+
mcp: {
|
|
204
|
+
usage: "roomyx mcp [flags]",
|
|
205
|
+
summary: "start the management MCP server",
|
|
206
|
+
notes: "Default port 4320, so it does not collide with `roomyx serve`.",
|
|
207
|
+
flags: {
|
|
208
|
+
port: { type: "number", describe: "Listen port (default 4320; 0 picks an ephemeral one)" },
|
|
209
|
+
host: { type: "string", describe: "Bind address (default 127.0.0.1)" },
|
|
210
|
+
"acknowledge-non-loopback": { type: "boolean", describe: "Required to bind a non-loopback host" },
|
|
211
|
+
registry: REGISTRY_FLAG,
|
|
212
|
+
config: { type: "string", describe: "Config file (default .roomyx/config.json)" },
|
|
213
|
+
},
|
|
214
|
+
run: async ({ flags }) => {
|
|
215
|
+
const handle = await serveManagement(
|
|
216
|
+
{
|
|
217
|
+
registryPath: typeof flags.registry === "string" ? flags.registry : defaultRegistryPath(),
|
|
218
|
+
bundledSkillPath: bundledSkillPath(),
|
|
219
|
+
configPath: typeof flags.config === "string" ? flags.config : defaultConfigPath(),
|
|
220
|
+
},
|
|
221
|
+
{
|
|
222
|
+
port: typeof flags.port === "number" ? flags.port : undefined,
|
|
223
|
+
host: typeof flags.host === "string" ? flags.host : undefined,
|
|
224
|
+
acknowledgeNonLoopback: flags["acknowledge-non-loopback"] === true,
|
|
225
|
+
},
|
|
226
|
+
);
|
|
227
|
+
|
|
228
|
+
console.log(`roomyx mcp listening at ${handle.url}`);
|
|
229
|
+
console.log("tools: roomyx.rooms.list, roomyx.skills.sync");
|
|
230
|
+
|
|
231
|
+
const shutdown = () => {
|
|
232
|
+
void handle.close().then(() => process.exit(0));
|
|
233
|
+
};
|
|
234
|
+
process.on("SIGINT", shutdown);
|
|
235
|
+
process.on("SIGTERM", shutdown);
|
|
236
|
+
},
|
|
237
|
+
},
|
|
238
|
+
|
|
239
|
+
"skills sync": {
|
|
240
|
+
usage: "roomyx skills sync --target <claude|codex|keryx|all|path> [flags]",
|
|
241
|
+
summary: "install the bundled startup-room skill",
|
|
242
|
+
notes:
|
|
243
|
+
"Without --yes nothing is written: the run reports what it would do and\n stops. D-02 — landing on a real skill file is a deliberate act, not a\n side effect of the mechanism existing.",
|
|
244
|
+
flags: {
|
|
245
|
+
target: { type: "string", describe: `Required. ${NAMED_TARGETS.join(", ")}, all, or a literal path` },
|
|
246
|
+
yes: { type: "boolean", describe: "Actually write" },
|
|
247
|
+
"dry-run": { type: "boolean", describe: "Report only (the default)" },
|
|
248
|
+
config: { type: "string", describe: "Config file the sync records hashes in" },
|
|
249
|
+
},
|
|
250
|
+
run: async ({ flags }) => {
|
|
251
|
+
const target = flags.target;
|
|
252
|
+
if (typeof target !== "string") {
|
|
253
|
+
throw new ArgError(`Missing --target. Expected one of ${NAMED_TARGETS.join(", ")}, all, or a path.`);
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
const yes = flags.yes === true;
|
|
257
|
+
const dryRun = flags["dry-run"] === true || !yes;
|
|
258
|
+
const configPath = typeof flags.config === "string" ? flags.config : defaultConfigPath();
|
|
259
|
+
if (!existsSync(configPath)) {
|
|
260
|
+
throw new ArgError(`No ${configPath}. Run \`roomyx init\` first.`);
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
for (const { name, path } of resolveTargets(target)) {
|
|
264
|
+
const result = syncSkill({
|
|
265
|
+
bundledSkillPath: bundledSkillPath(),
|
|
266
|
+
targetPath: path,
|
|
267
|
+
configPath,
|
|
268
|
+
dryRun,
|
|
269
|
+
yes,
|
|
270
|
+
});
|
|
271
|
+
console.log(name === path ? path : `${name}: ${path}`);
|
|
272
|
+
for (const warning of result.warnings) console.log(` warning: ${warning}`);
|
|
273
|
+
if (result.written) {
|
|
274
|
+
console.log(result.backedUpTo ? ` written (backup: ${result.backedUpTo})` : " written");
|
|
275
|
+
} else {
|
|
276
|
+
console.log(dryRun ? " would write (pass --yes to apply)" : " not written");
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
},
|
|
280
|
+
},
|
|
281
|
+
};
|
|
171
282
|
|
|
172
283
|
/** package.json ships in the tarball (see `files`), so this resolves for an installed copy too. */
|
|
173
284
|
function version(): string {
|
|
@@ -177,32 +288,74 @@ function version(): string {
|
|
|
177
288
|
return manifest.version;
|
|
178
289
|
}
|
|
179
290
|
|
|
291
|
+
function topLevelHelp(): string {
|
|
292
|
+
const names = Object.keys(COMMANDS);
|
|
293
|
+
const width = Math.max(...names.map((n) => n.length));
|
|
294
|
+
return [
|
|
295
|
+
"Usage: roomyx <command> [flags]",
|
|
296
|
+
"",
|
|
297
|
+
...names.map((n) => ` ${n.padEnd(width)} ${COMMANDS[n]!.summary}`),
|
|
298
|
+
"",
|
|
299
|
+
" --version",
|
|
300
|
+
"",
|
|
301
|
+
"`roomyx <command> --help` describes one command.",
|
|
302
|
+
"The terminal UI is also a separate binary: roomyx-client [--room <id>]",
|
|
303
|
+
].join("\n");
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
function commandHelp(name: string, command: Command): string {
|
|
307
|
+
const table = renderFlags(command.flags);
|
|
308
|
+
return [
|
|
309
|
+
command.usage,
|
|
310
|
+
"",
|
|
311
|
+
` ${command.summary}`,
|
|
312
|
+
...(command.notes ? ["", ` ${command.notes}`] : []),
|
|
313
|
+
...(table ? ["", table] : []),
|
|
314
|
+
].join("\n");
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
/** Longest command name first, so "room new" wins over a hypothetical "room". */
|
|
318
|
+
function matchCommand(argv: string[]): { name: string; command: Command; rest: string[] } | undefined {
|
|
319
|
+
for (const name of Object.keys(COMMANDS).sort((a, b) => b.split(" ").length - a.split(" ").length)) {
|
|
320
|
+
const words = name.split(" ");
|
|
321
|
+
if (words.every((word, i) => argv[i] === word)) {
|
|
322
|
+
return { name, command: COMMANDS[name]!, rest: argv.slice(words.length) };
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
return undefined;
|
|
326
|
+
}
|
|
327
|
+
|
|
180
328
|
async function main(): Promise<void> {
|
|
181
|
-
const
|
|
329
|
+
const argv = process.argv.slice(2);
|
|
182
330
|
|
|
183
|
-
if (
|
|
331
|
+
if (argv[0] === "--version" || argv[0] === "-v") {
|
|
184
332
|
console.log(version());
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
console.
|
|
201
|
-
|
|
333
|
+
return;
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
const matched = matchCommand(argv);
|
|
337
|
+
if (!matched) {
|
|
338
|
+
// `--help` is a request and exits 0. A bare `roomyx`, or a command that
|
|
339
|
+
// isn't one, is a usage error and exits 1 — the convention git follows,
|
|
340
|
+
// and the distinction a shell script or an agent actually reads.
|
|
341
|
+
const askedForHelp = argv[0] === "--help" || argv[0] === "-h";
|
|
342
|
+
console[askedForHelp ? "log" : "error"](topLevelHelp());
|
|
343
|
+
process.exit(askedForHelp ? 0 : 1);
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
const parsed = parseArgs(matched.rest, matched.command.flags);
|
|
347
|
+
if (parsed.help) {
|
|
348
|
+
console.log(commandHelp(matched.name, matched.command));
|
|
349
|
+
return;
|
|
202
350
|
}
|
|
351
|
+
await matched.command.run(parsed);
|
|
203
352
|
}
|
|
204
353
|
|
|
205
354
|
main().catch((error) => {
|
|
355
|
+
if (error instanceof ArgError) {
|
|
356
|
+
console.error(error.message);
|
|
357
|
+
process.exit(1);
|
|
358
|
+
}
|
|
206
359
|
console.error(error instanceof Error ? error.message : String(error));
|
|
207
360
|
process.exit(1);
|
|
208
361
|
});
|
package/src/client/index.ts
CHANGED
|
@@ -8,26 +8,24 @@ import type { RosterEntry } from "../log/types";
|
|
|
8
8
|
import { resolveConnectionUrl } from "../installer/resolve-connection";
|
|
9
9
|
import { IDLE, ownerPromptLine, stepOwnerPrompt } from "./owner-prompt";
|
|
10
10
|
import type { OwnerPromptState } from "./owner-prompt";
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
const flags = parseFlags(argv);
|
|
26
|
-
const registryPath = flags["registry"] ?? join(process.cwd(), ".roomyx", "rooms", "registry.json");
|
|
11
|
+
import { ArgError, parseArgs, renderFlags } from "../cli/args";
|
|
12
|
+
import type { FlagValues } from "../cli/args";
|
|
13
|
+
import { CLIENT_FLAGS } from "../cli/specs";
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Takes already-parsed flags rather than argv, so the two entry points — this
|
|
17
|
+
* file as a binary, and `roomyx client` — cannot disagree about what a flag
|
|
18
|
+
* means. They previously had one scanner each, which is how a bare
|
|
19
|
+
* `--registry` became `""` here (and `""` is not nullish, so it beat the
|
|
20
|
+
* default) while becoming `true` in the other.
|
|
21
|
+
*/
|
|
22
|
+
export async function runClient(flags: FlagValues): Promise<void> {
|
|
23
|
+
const registryPath =
|
|
24
|
+
typeof flags.registry === "string" ? flags.registry : join(process.cwd(), ".roomyx", "rooms", "registry.json");
|
|
27
25
|
|
|
28
26
|
const resolved = await resolveConnectionUrl({
|
|
29
|
-
connect: flags.connect,
|
|
30
|
-
room: flags.room,
|
|
27
|
+
connect: typeof flags.connect === "string" ? flags.connect : undefined,
|
|
28
|
+
room: typeof flags.room === "string" ? flags.room : undefined,
|
|
31
29
|
registryPath,
|
|
32
30
|
});
|
|
33
31
|
|
|
@@ -129,12 +127,29 @@ export async function runClient(argv: string[] = process.argv.slice(2)): Promise
|
|
|
129
127
|
});
|
|
130
128
|
}
|
|
131
129
|
|
|
130
|
+
const CLIENT_USAGE = ["roomyx-client [flags]", "", " attach the terminal UI to a live room", "", renderFlags(CLIENT_FLAGS)].join(
|
|
131
|
+
"\n",
|
|
132
|
+
);
|
|
133
|
+
|
|
132
134
|
if (import.meta.main) {
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
135
|
+
void (async () => {
|
|
136
|
+
try {
|
|
137
|
+
const parsed = parseArgs(process.argv.slice(2), CLIENT_FLAGS);
|
|
138
|
+
if (parsed.help) {
|
|
139
|
+
console.log(CLIENT_USAGE);
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
await runClient(parsed.flags);
|
|
143
|
+
} catch (error) {
|
|
144
|
+
// The message, not the object: a stack trace dumped at someone who
|
|
145
|
+
// simply hasn't started a room yet reads as a crash, and matches how
|
|
146
|
+
// cli.ts reports its own failures.
|
|
147
|
+
if (error instanceof ArgError) {
|
|
148
|
+
console.error(error.message);
|
|
149
|
+
} else {
|
|
150
|
+
console.error(error instanceof Error ? error.message : String(error));
|
|
151
|
+
}
|
|
152
|
+
process.exit(1);
|
|
153
|
+
}
|
|
154
|
+
})();
|
|
140
155
|
}
|