@mrciphersmith/roomyx 0.12.2 → 0.12.3

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.
Files changed (44) hide show
  1. package/CHANGELOG.md +91 -0
  2. package/README.md +84 -4
  3. package/package.json +11 -10
  4. package/src/bin/launch.mjs +1 -1
  5. package/src/bundled-personas/groups.md +3 -3
  6. package/src/bundled-skills/startup-room/reference/roomyx.md +5 -0
  7. package/src/cli/client.ts +12 -0
  8. package/src/cli/experiment.ts +67 -0
  9. package/src/cli/init.ts +149 -0
  10. package/src/cli/mcp.ts +54 -0
  11. package/src/cli/personas.ts +40 -0
  12. package/src/cli/room-append.ts +357 -0
  13. package/src/cli/room.ts +91 -0
  14. package/src/cli/rooms.ts +65 -0
  15. package/src/cli/serve.ts +84 -0
  16. package/src/cli/shared.ts +71 -0
  17. package/src/cli/skills.ts +58 -0
  18. package/src/cli/specs.ts +1 -0
  19. package/src/cli.ts +29 -884
  20. package/src/client/index.ts +16 -3
  21. package/src/client/mcp-client.ts +106 -7
  22. package/src/client/shutdown.ts +29 -6
  23. package/src/experiment/manifest.ts +151 -0
  24. package/src/installer/init-apply.ts +38 -7
  25. package/src/installer/init.ts +5 -2
  26. package/src/installer/registry.ts +38 -6
  27. package/src/installer/resolve-connection.ts +54 -8
  28. package/src/installer/room-tool.ts +6 -3
  29. package/src/installer/skill-sync.ts +86 -3
  30. package/src/installer/skill-targets.ts +7 -3
  31. package/src/lockfile.ts +13 -2
  32. package/src/log/schema.ts +108 -38
  33. package/src/log/store.ts +1 -0
  34. package/src/log/types.ts +8 -1
  35. package/src/log/write.ts +115 -6
  36. package/src/mcp-management/server.ts +30 -4
  37. package/src/room-token.ts +129 -0
  38. package/src/server/http-transport.ts +43 -0
  39. package/src/server/index.ts +76 -3
  40. package/src/server/log-watcher.ts +80 -0
  41. package/src/server/owner-queue.ts +7 -1
  42. package/src/server/serve.ts +112 -30
  43. package/src/server/shutdown.ts +33 -7
  44. package/src/writer-lease.ts +161 -14
@@ -0,0 +1,71 @@
1
+ import { join } from "node:path";
2
+ import { createServerShutdown } from "../server/shutdown";
3
+ import { findRoomServing, listRoomsWithLiveness } from "../installer/registry";
4
+ import { ArgError } from "./args";
5
+ import type { FlagSpecs, ParsedArgs } from "./args";
6
+
7
+ export function defaultRegistryPath(): string {
8
+ return join(process.cwd(), ".roomyx", "rooms", "registry.json");
9
+ }
10
+
11
+ export function defaultConfigPath(): string {
12
+ return join(process.cwd(), ".roomyx", "config.json");
13
+ }
14
+
15
+ export function bundledSkillPath(): string {
16
+ return join(import.meta.dir, "..", "bundled-skills", "startup-room", "SKILL.md");
17
+ }
18
+
19
+ export function bundledPersonasPath(): string {
20
+ return join(import.meta.dir, "..", "bundled-personas");
21
+ }
22
+
23
+ export const REGISTRY_FLAG = { type: "string", describe: "Registry file (default .roomyx/rooms/registry.json)" } as const;
24
+
25
+ /**
26
+ * Wires the signals. The shutdown itself lives in `../server/shutdown`, where a
27
+ * test can reach it — this module runs its entry point on import.
28
+ *
29
+ * Written once because there were three copies and they had drifted: the two
30
+ * here handled SIGINT and SIGTERM and guarded nothing, while the client handled
31
+ * SIGHUP as well and guarded re-entry. So closing a terminal (SIGHUP) killed
32
+ * `roomyx serve` outright, skipping deregistration and leaving a stale registry
33
+ * entry — which a recycled port then resurrects as a live room.
34
+ *
35
+ * `cleanup` runs *after* the close resolves, not before. Deregistering first
36
+ * meant a shutdown that hung — and it hung whenever a client was attached —
37
+ * removed the room from the registry while the process kept running and kept
38
+ * the port. The room became invisible while still being served.
39
+ */
40
+ export function runUntilSignal(close: () => Promise<void>, cleanup: () => void = () => undefined): void {
41
+ const shutdown = createServerShutdown(close, cleanup);
42
+ for (const signal of ["SIGINT", "SIGTERM", "SIGHUP"] as const) process.on(signal, shutdown);
43
+ }
44
+
45
+ export interface Command {
46
+ usage: string;
47
+ summary: string;
48
+ /** Extra lines under the flag table. */
49
+ notes?: string;
50
+ flags: FlagSpecs;
51
+ run: (args: ParsedArgs) => Promise<void>;
52
+ }
53
+
54
+ /**
55
+ * The live room serving this log, or a refusal that says what to do.
56
+ *
57
+ * Shared by the three commands that talk to a room's own MCP server. They need
58
+ * a port, and the registry is the only place a room's port is written down —
59
+ * which is exactly why these tools had no caller before: there is no way to
60
+ * reach a room without going through here first.
61
+ */
62
+ export async function servingRoomFor(absoluteLog: string, registryPath: string) {
63
+ const serving = findRoomServing(absoluteLog, await listRoomsWithLiveness(registryPath, { prune: false }));
64
+ if (serving === undefined) {
65
+ throw new ArgError(
66
+ `No live room is serving ${absoluteLog}. These commands read from the room's own server, ` +
67
+ `so the room has to be running: start it with \`roomyx serve ${absoluteLog} --port 0\`.`,
68
+ );
69
+ }
70
+ return serving;
71
+ }
@@ -0,0 +1,58 @@
1
+ import { existsSync } from "node:fs";
2
+ import { syncSkillBundle } from "../installer/skill-sync";
3
+ import { NAMED_TARGETS, resolveTargets } from "../installer/skill-targets";
4
+ import { ArgError } from "./args";
5
+ import { bundledSkillPath, defaultConfigPath } from "./shared";
6
+ import type { Command } from "./shared";
7
+
8
+ export const skillsSync: Command = {
9
+ usage: "roomyx skills sync --target <runtime|all|path> [flags]",
10
+ summary: "install the bundled startup-room skill",
11
+ notes:
12
+ "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.",
13
+ flags: {
14
+ target: { type: "string", describe: `Required. ${NAMED_TARGETS.join(", ")}, all, or a literal path` },
15
+ yes: { type: "boolean", describe: "Actually write" },
16
+ "dry-run": { type: "boolean", describe: "Report only (the default)" },
17
+ config: { type: "string", describe: "Config file the sync records hashes in" },
18
+ },
19
+ run: async ({ flags }) => {
20
+ const target = flags.target;
21
+ if (typeof target !== "string") {
22
+ throw new ArgError(`Missing --target. Expected one of ${NAMED_TARGETS.join(", ")}, all, or a path.`);
23
+ }
24
+
25
+ const yes = flags.yes === true;
26
+ // The gate itself lives in `syncSkill` now, computed once for every
27
+ // surface — this line only forwards what the operator typed.
28
+ const dryRun = flags["dry-run"] === true;
29
+ const configPath = typeof flags.config === "string" ? flags.config : defaultConfigPath();
30
+ if (!existsSync(configPath)) {
31
+ throw new ArgError(`No ${configPath}. Run \`roomyx init\` first.`);
32
+ }
33
+
34
+ for (const { name, path } of resolveTargets(target)) {
35
+ const result = syncSkillBundle({
36
+ bundledSkillPath: bundledSkillPath(),
37
+ targetPath: path,
38
+ configPath,
39
+ dryRun,
40
+ yes,
41
+ });
42
+ console.log(name === path ? path : `${name}: ${path}`);
43
+ for (const warning of result.warnings) console.log(` warning: ${warning}`);
44
+ if (result.upToDate) {
45
+ console.log(" already in sync — nothing written, no backup made");
46
+ } else if (result.written) {
47
+ console.log(result.backedUpTo ? ` written (backup: ${result.backedUpTo})` : " written");
48
+ } else {
49
+ // "not written" was the message whenever `dryRun` was false, which
50
+ // after the gate moved into syncSkill meant the ordinary
51
+ // no-flags run reported a bare refusal instead of the sentence that
52
+ // says how to proceed. Branch on why nothing was written, not on
53
+ // which flag was passed.
54
+ console.log(result.wouldWrite ? " would write (pass --yes to apply)" : " not written");
55
+ }
56
+ }
57
+ },
58
+ };
package/src/cli/specs.ts CHANGED
@@ -12,6 +12,7 @@ import type { FlagSpecs } from "./args";
12
12
  export const CLIENT_FLAGS: FlagSpecs = {
13
13
  room: { type: "string", describe: "Attach to a specific live room by id" },
14
14
  connect: { type: "string", describe: "Attach to an explicit MCP URL; the registry is not consulted" },
15
+ token: { type: "string", describe: "The room's token, when --connect names a room this registry does not know" },
15
16
  registry: { type: "string", describe: "Registry file (default .roomyx/rooms/registry.json)" },
16
17
  open: { type: "string", describe: "Reread a closed room from its log file, read-only" },
17
18
  archive: { type: "boolean", describe: "Pick a closed room from the history index" },