@mrciphersmith/roomyx 0.6.2 → 0.7.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.
@@ -0,0 +1,154 @@
1
+ import { appendFileSync, existsSync, mkdirSync, readFileSync } from "node:fs";
2
+ import { dirname, join } from "node:path";
3
+ import { z } from "zod";
4
+ import { loadRoomLog } from "../log/store";
5
+
6
+ /**
7
+ * The record of rooms that have closed.
8
+ *
9
+ * **It is an index, not an archive of copies.** The obvious shape for "save
10
+ * closed rooms" is a folder under `.roomyx/` that the log gets copied into when
11
+ * the room ends. That is the wrong shape here for one specific reason: the room
12
+ * log is append-only and is the single source of truth for what was said
13
+ * (D-01a). Copying it makes a second one. The moment a copy exists, an append
14
+ * to the original — which `roomyx room append --force` still permits, and which
15
+ * a dispatcher does routinely if the room is reopened — leaves two files that
16
+ * disagree, with nothing recording which is current. A reader would have no way
17
+ * to tell, and the wrong answer is silent.
18
+ *
19
+ * So what gets written here is *what the room was*: its id, where its log lives,
20
+ * its goal, how many people and messages it had, when it started and closed.
21
+ * The transcript itself stays exactly where the operator put it, still the only
22
+ * copy. If they move or delete it, the entry says so rather than quietly
23
+ * serving stale text from a shadow copy.
24
+ *
25
+ * Append-only JSONL, like the room log and for the same reason: a closing room
26
+ * appends one line under no lock, and a concurrent reader sees whole lines.
27
+ */
28
+
29
+ const historyEntrySchema = z.object({
30
+ type: z.literal("room"),
31
+ id: z.string().min(1),
32
+ logPath: z.string().min(1),
33
+ goal: z.string(),
34
+ participants: z.number().int().min(0),
35
+ messages: z.number().int().min(0),
36
+ startedAt: z.string().min(1),
37
+ closedAt: z.string().min(1),
38
+ });
39
+
40
+ export type RoomHistoryEntry = z.infer<typeof historyEntrySchema>;
41
+
42
+ /** A history entry plus whether the transcript it points at is still there. */
43
+ export interface RoomHistoryRow extends RoomHistoryEntry {
44
+ logExists: boolean;
45
+ }
46
+
47
+ /** Sits next to the registry, because the two describe the same rooms at different times. */
48
+ export function defaultHistoryPath(registryPath: string): string {
49
+ return join(dirname(registryPath), "history.jsonl");
50
+ }
51
+
52
+ /**
53
+ * What a closed room's log says about itself. Never throws: this runs inside a
54
+ * shutdown handler, and a room that cannot be summarised is still a room worth
55
+ * recording. A log that has been deleted, or that has a malformed line, yields
56
+ * an entry with an empty goal and zero counts rather than an exception that
57
+ * takes the deregistration with it.
58
+ */
59
+ function summarize(logPath: string): { goal: string; participants: number; messages: number } {
60
+ try {
61
+ const { state, messages } = loadRoomLog(logPath);
62
+ return {
63
+ goal: state.goal_contract.goal_statement,
64
+ participants: state.roster.length,
65
+ messages: messages.length,
66
+ };
67
+ } catch {
68
+ return { goal: "", participants: 0, messages: 0 };
69
+ }
70
+ }
71
+
72
+ /**
73
+ * Records that a room has ended. Called from the shutdown path and from the
74
+ * registry's prune, so a room that crashed without deregistering is still
75
+ * remembered — the prune is the only moment anything notices it is gone.
76
+ *
77
+ * Both paths can fire for the same id (a slow shutdown pruned by a concurrent
78
+ * `rooms list`), so `readHistory` deduplicates rather than this refusing to
79
+ * append. Appending twice is cheap; taking a lock on a shutdown path to prevent
80
+ * it is not.
81
+ *
82
+ * Swallows its own errors for the same reason `summarize` does. Failing to
83
+ * write a convenience index must not be able to abort a shutdown that still has
84
+ * a port to release and a registry entry to remove.
85
+ */
86
+ export function archiveRoom(
87
+ historyPath: string,
88
+ room: { id: string; logPath: string; startedAt: string },
89
+ closedAt: string = new Date().toISOString(),
90
+ ): void {
91
+ try {
92
+ mkdirSync(dirname(historyPath), { recursive: true });
93
+ const entry: RoomHistoryEntry = {
94
+ type: "room",
95
+ id: room.id,
96
+ logPath: room.logPath,
97
+ startedAt: room.startedAt,
98
+ closedAt,
99
+ ...summarize(room.logPath),
100
+ };
101
+ appendFileSync(historyPath, `${JSON.stringify(entry)}\n`, "utf8");
102
+ } catch {
103
+ // Deliberately silent. See above.
104
+ }
105
+ }
106
+
107
+ export interface History {
108
+ rooms: RoomHistoryRow[];
109
+ /** Lines that did not parse. Reported rather than thrown — see below. */
110
+ unreadable: number;
111
+ }
112
+
113
+ /**
114
+ * Every closed room, newest first, with duplicates collapsed.
115
+ *
116
+ * **A malformed line is skipped, not raised.** This is the opposite of what
117
+ * `loadRoomLog` does with the room log, and the difference is deliberate: the
118
+ * room log is the transcript, where a line that will not parse means the record
119
+ * is damaged and reading past it would silently drop something someone said.
120
+ * This file is an index that can be rebuilt from nothing, and one bad line here
121
+ * must not be able to hide fifty good rooms. The count is returned so the
122
+ * surfaces can say the file has damage rather than pretending it is clean.
123
+ */
124
+ export function readHistory(historyPath: string, exists: (path: string) => boolean = existsSync): History {
125
+ if (!existsSync(historyPath)) return { rooms: [], unreadable: 0 };
126
+
127
+ const byId = new Map<string, RoomHistoryEntry>();
128
+ let unreadable = 0;
129
+
130
+ for (const line of readFileSync(historyPath, "utf8").replace(/^/, "").split("\n")) {
131
+ if (line.trim() === "") continue;
132
+ let parsed: unknown;
133
+ try {
134
+ parsed = JSON.parse(line);
135
+ } catch {
136
+ unreadable += 1;
137
+ continue;
138
+ }
139
+ const entry = historyEntrySchema.safeParse(parsed);
140
+ if (!entry.success) {
141
+ unreadable += 1;
142
+ continue;
143
+ }
144
+ // Last write wins: the prune path and the shutdown path can both record the
145
+ // same room, and the later one saw more of it.
146
+ byId.set(entry.data.id, entry.data);
147
+ }
148
+
149
+ const rooms = [...byId.values()]
150
+ .sort((a, b) => b.closedAt.localeCompare(a.closedAt))
151
+ .map((room) => ({ ...room, logExists: exists(room.logPath) }));
152
+
153
+ return { rooms, unreadable };
154
+ }
@@ -0,0 +1,142 @@
1
+ import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
2
+ import { dirname } from "node:path";
3
+ import { join } from "node:path";
4
+ import { syncSkill } from "./skill-sync";
5
+ import type { PlanItem } from "./init-plan";
6
+
7
+ /**
8
+ * Performs a plan the operator has ticked. One result line per item, whether it
9
+ * worked or not — a run that half-succeeded must say which half.
10
+ *
11
+ * Every write here is additive or backed up. Nothing this function does removes
12
+ * an existing line, key or file.
13
+ */
14
+
15
+ export interface ApplyResult {
16
+ readonly id: string;
17
+ readonly label: string;
18
+ readonly path: string;
19
+ readonly ok: boolean;
20
+ /** What happened, in one line, for the summary the CLI prints. */
21
+ readonly message: string;
22
+ }
23
+
24
+ export interface ApplyContext {
25
+ cwd: string;
26
+ bundledSkillPath: string;
27
+ configPath: string;
28
+ }
29
+
30
+ export function applyPlan(items: readonly PlanItem[], context: ApplyContext): ApplyResult[] {
31
+ return items.map((item) => {
32
+ try {
33
+ return { id: item.id, label: item.label, path: item.path, ok: true, message: applyOne(item, context) };
34
+ } catch (error) {
35
+ // One failing item must not abort the rest: a `~/.cursor` that is not
36
+ // writable should not cost the operator the Claude install they also
37
+ // asked for in the same submit.
38
+ return {
39
+ id: item.id,
40
+ label: item.label,
41
+ path: item.path,
42
+ ok: false,
43
+ message: error instanceof Error ? error.message : String(error),
44
+ };
45
+ }
46
+ });
47
+ }
48
+
49
+ function applyOne(item: PlanItem, context: ApplyContext): string {
50
+ switch (item.kind) {
51
+ case "skill": {
52
+ const result = syncSkill({
53
+ bundledSkillPath: context.bundledSkillPath,
54
+ targetPath: item.path,
55
+ configPath: context.configPath,
56
+ dryRun: false,
57
+ // The operator ticked this box and pressed Enter. That is what `--yes`
58
+ // means on the command line, and it is a stronger signal than a flag:
59
+ // they saw the exact path before agreeing to it.
60
+ yes: true,
61
+ });
62
+ if (!result.written) return result.warnings[0] ?? "not written";
63
+ return result.backedUpTo ? `written (backup: ${result.backedUpTo})` : "written";
64
+ }
65
+
66
+ case "logs":
67
+ mkdirSync(item.path, { recursive: true });
68
+ return "created";
69
+
70
+ case "gitignore":
71
+ return ensureGitignore(context.cwd);
72
+
73
+ case "mcp":
74
+ return ensureMcpServer(item.path, item.id === "mcp:cursor");
75
+ }
76
+ }
77
+
78
+ const IGNORE_LINES = [".roomyx/rooms/registry.json", ".roomyx/rooms/*.lock"];
79
+
80
+ /**
81
+ * Appends the two machine-local paths to `.gitignore` if they are not already
82
+ * covered, and leaves everything else in the file alone.
83
+ *
84
+ * Room logs are deliberately not ignored. The transcript is the artefact worth
85
+ * keeping; what is machine-local is the registry (pids and ports of processes
86
+ * on this host) and the transient lockfiles.
87
+ */
88
+ function ensureGitignore(cwd: string): string {
89
+ const path = join(cwd, ".gitignore");
90
+ const existing = existsSync(path) ? readFileSync(path, "utf8") : "";
91
+ const present = new Set(existing.split("\n").map((line) => line.trim()));
92
+ const missing = IGNORE_LINES.filter((line) => !present.has(line));
93
+ if (missing.length === 0) return "already covered";
94
+
95
+ const block = `${existing.length > 0 && !existing.endsWith("\n") ? "\n" : ""}\n# roomyx — machine-local state (room logs are NOT ignored)\n${missing.join("\n")}\n`;
96
+ writeFileSync(path, existing + block, "utf8");
97
+ return `added ${missing.length} line(s)`;
98
+ }
99
+
100
+ interface McpConfig {
101
+ mcpServers?: Record<string, unknown>;
102
+ }
103
+
104
+ /**
105
+ * Adds a `roomyx` entry to an MCP config, merging rather than replacing.
106
+ *
107
+ * The entry spawns `roomyx mcp --stdio`, not an HTTP URL. A URL would have to
108
+ * name a port that something is already listening on, so a registration written
109
+ * at `init` would point at nothing until the operator remembered to start a
110
+ * server — a config entry that is broken by default. Over stdio the client
111
+ * starts it when it needs it and there is no port at all.
112
+ *
113
+ * An existing `roomyx` key is left untouched: the operator may have pointed it
114
+ * somewhere deliberately, and silently rewriting someone's MCP config is the
115
+ * same class of theft D-02 exists to prevent.
116
+ */
117
+ function ensureMcpServer(path: string, createDir: boolean): string {
118
+ if (createDir) mkdirSync(dirname(path), { recursive: true });
119
+
120
+ let config: McpConfig = {};
121
+ if (existsSync(path)) {
122
+ const text = readFileSync(path, "utf8").trim();
123
+ if (text !== "") {
124
+ try {
125
+ config = JSON.parse(text) as McpConfig;
126
+ } catch (error) {
127
+ // Refused rather than overwritten. A file we cannot parse may still be
128
+ // a file someone is relying on.
129
+ throw new Error(
130
+ `${path} is not valid JSON — ${error instanceof Error ? error.message : String(error)}. Left untouched.`,
131
+ );
132
+ }
133
+ }
134
+ }
135
+
136
+ const servers = config.mcpServers ?? {};
137
+ if (servers.roomyx !== undefined) return "already registered — left as it is";
138
+
139
+ config.mcpServers = { ...servers, roomyx: { command: "roomyx", args: ["mcp", "--stdio"] } };
140
+ writeFileSync(path, `${JSON.stringify(config, null, 2)}\n`, "utf8");
141
+ return "registered";
142
+ }
@@ -0,0 +1,148 @@
1
+ import { existsSync } from "node:fs";
2
+ import { join } from "node:path";
3
+ import { SKILL_RUNTIMES } from "./skill-targets";
4
+ import type { SkillRuntime } from "./skill-targets";
5
+
6
+ /**
7
+ * What `roomyx init` offers to do, as data.
8
+ *
9
+ * Split from the screen that draws it and from the code that performs it,
10
+ * because the interesting decisions are here — which boxes start ticked, what
11
+ * is already done, what cannot be done and why — and none of them should need a
12
+ * renderer to test. The picker draws this list; `init-apply` executes it.
13
+ *
14
+ * **Nothing here writes.** A plan is built, shown, edited by the operator, and
15
+ * only then applied. That is what makes the interactive path satisfy D-02 more
16
+ * honestly than a flag did: landing a real skill file is a person ticking a box
17
+ * and pressing Enter, not a side effect of the mechanism existing.
18
+ */
19
+
20
+ export type PlanItemKind = "skill" | "logs" | "gitignore" | "mcp";
21
+
22
+ export interface PlanItem {
23
+ readonly id: string;
24
+ readonly kind: PlanItemKind;
25
+ /** Heading this item is listed under. */
26
+ readonly group: string;
27
+ readonly label: string;
28
+ /** Where it actually lands on disk. What `init-apply` acts on. */
29
+ readonly path: string;
30
+ /** How the path is shown, which may carry a short note the path itself must not. */
31
+ readonly detail: string;
32
+ /** Ticked when the picker opens. */
33
+ selected: boolean;
34
+ /** Set when the item is already satisfied — still listed, so the list is a complete picture. */
35
+ readonly done?: string;
36
+ /** For a skill item: which runtime, so `init-apply` does not have to parse the id. */
37
+ readonly runtime?: SkillRuntime;
38
+ }
39
+
40
+ export const GROUP_USER = "Skill — every project on this machine";
41
+ export const GROUP_PROJECT = "Skill — this project only (travels with the repo)";
42
+ export const GROUP_EXTRAS = "Also";
43
+
44
+ export interface PlanContext {
45
+ cwd: string;
46
+ /** Injectable so the tests never look at the operator's real home directory. */
47
+ exists?: (path: string) => boolean;
48
+ /** Injectable for the same reason. */
49
+ home?: string;
50
+ }
51
+
52
+ /**
53
+ * The offer, in the order it is shown.
54
+ *
55
+ * Boxes start ticked where the answer is not really in doubt: a runtime that is
56
+ * installed on this machine, a project that already has that runtime's
57
+ * directory, a logs directory the config already points at. Everything else
58
+ * starts unticked. The rule is that a default tick must never write somewhere
59
+ * the operator would be surprised to find a file — being surprised by a file in
60
+ * `~/.cursor` when Cursor is not installed is exactly that.
61
+ */
62
+ export function buildPlan(context: PlanContext): PlanItem[] {
63
+ const { cwd } = context;
64
+ const exists = context.exists ?? existsSync;
65
+ const items: PlanItem[] = [];
66
+
67
+ for (const runtime of SKILL_RUNTIMES) {
68
+ const path = runtime.path(cwd);
69
+ // Presence of the runtime's own directory, not of our skill: this decides
70
+ // whether to *offer it ticked*, never whether to offer it at all. A runtime
71
+ // installed after roomyx would otherwise be unreachable.
72
+ const present = exists(runtime.marker(cwd));
73
+ items.push({
74
+ id: `skill:${runtime.name}`,
75
+ kind: "skill",
76
+ group: runtime.scope === "user" ? GROUP_USER : GROUP_PROJECT,
77
+ label: runtime.label,
78
+ path,
79
+ detail: path,
80
+ selected: present,
81
+ done: exists(path) ? "replaces" : undefined,
82
+ runtime,
83
+ });
84
+ }
85
+
86
+ const logsDir = join(cwd, ".roomyx", "rooms", "logs");
87
+ items.push({
88
+ id: "logs",
89
+ kind: "logs",
90
+ group: GROUP_EXTRAS,
91
+ label: "Room-log directory",
92
+ path: logsDir,
93
+ detail: logsDir,
94
+ // `config.json` has named this directory since the first release and
95
+ // nothing ever created it, so `roomyx room new .roomyx/rooms/logs/x.jsonl`
96
+ // — the path the config itself points at — failed on a fresh project.
97
+ selected: true,
98
+ done: exists(logsDir) ? "already there" : undefined,
99
+ });
100
+
101
+ const isRepo = exists(join(cwd, ".git"));
102
+ items.push({
103
+ id: "gitignore",
104
+ kind: "gitignore",
105
+ group: GROUP_EXTRAS,
106
+ label: "Ignore registry, lockfiles",
107
+ path: join(cwd, ".gitignore"),
108
+ // The registry holds pids and ports of processes on *this* machine, and the
109
+ // lockfiles are transient. Room logs are deliberately not ignored: the
110
+ // transcript is the point.
111
+ // The path alone. The label already names exactly what gets ignored, which
112
+ // is also how it says what does not: the room logs.
113
+ detail: join(cwd, ".gitignore"),
114
+ selected: isRepo,
115
+ done: isRepo ? undefined : "not a git repository",
116
+ });
117
+
118
+ for (const [id, label, path] of mcpTargets(cwd)) {
119
+ const runtimeDir = id === "mcp:claude" ? join(cwd, ".claude") : join(cwd, ".cursor");
120
+ items.push({
121
+ id,
122
+ kind: "mcp",
123
+ group: GROUP_EXTRAS,
124
+ label,
125
+ path,
126
+ detail: path,
127
+ // Only pre-ticked when that runtime is already used in this project.
128
+ // Registering a server for an agent nobody here runs is clutter.
129
+ selected: exists(runtimeDir) || exists(path),
130
+ done: undefined,
131
+ });
132
+ }
133
+
134
+ return items;
135
+ }
136
+
137
+ /** Project-scoped MCP config files, by runtime. */
138
+ function mcpTargets(cwd: string): [string, string, string][] {
139
+ return [
140
+ ["mcp:claude", "MCP server for Claude Code", join(cwd, ".mcp.json")],
141
+ ["mcp:cursor", "MCP server for Cursor", join(cwd, ".cursor", "mcp.json")],
142
+ ];
143
+ }
144
+
145
+ /** The items a plan would actually act on. */
146
+ export function selectedItems(items: readonly PlanItem[]): PlanItem[] {
147
+ return items.filter((item) => item.selected);
148
+ }
@@ -4,6 +4,7 @@ import { z } from "zod";
4
4
  import { Client } from "@modelcontextprotocol/sdk/client/index.js";
5
5
  import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
6
6
  import { withLock } from "../lockfile";
7
+ import { archiveRoom, defaultHistoryPath } from "./history";
7
8
 
8
9
  /** Re-exported: the registry's own tests reach for it, and it lives in ../lockfile now. */
9
10
  export { releaseLockIfOwned } from "../lockfile";
@@ -115,9 +116,10 @@ export function listRooms(registryPath: string): RoomRegistryEntry[] {
115
116
  */
116
117
  export async function listLiveRooms(
117
118
  registryPath: string,
118
- options: { prune?: boolean } = {},
119
+ options: { prune?: boolean; historyPath?: string } = {},
119
120
  ): Promise<RoomRegistryEntry[]> {
120
121
  const prune = options.prune ?? true;
122
+ const historyPath = options.historyPath ?? defaultHistoryPath(registryPath);
121
123
  if (hasNoRegistry(registryPath)) return [];
122
124
  const rooms = withLock(registryPath, () => readRegistryUnlocked(registryPath).rooms);
123
125
  const checks = await Promise.all(
@@ -138,14 +140,24 @@ export async function listLiveRooms(
138
140
  // flight. Re-read under the lock and only remove entries this pass
139
141
  // actually confirmed dead, instead of blindly overwriting with the
140
142
  // stale `live` list computed before the re-read.
143
+ const dead = checks.filter((c) => !c.alive).map((c) => c.room);
141
144
  withLock(registryPath, () => {
142
145
  const current = readRegistryUnlocked(registryPath).rooms;
143
- const deadIds = new Set(checks.filter((c) => !c.alive).map((c) => c.room.id));
146
+ const deadIds = new Set(dead.map((r) => r.id));
144
147
  writeRegistryUnlocked(
145
148
  registryPath,
146
149
  current.filter((r) => !deadIds.has(r.id)),
147
150
  );
148
151
  });
152
+ // A room pruned here died without deregistering — crashed, or was killed
153
+ // with a signal no handler runs for. This is the only moment anything
154
+ // observes that it ended, so it is the only place its history entry can be
155
+ // written. Without it the rooms that are most worth being able to reread
156
+ // are exactly the ones that leave no trace.
157
+ //
158
+ // `closedAt` is now, not the moment it actually died, which is unknowable
159
+ // — the entry records when it was found gone.
160
+ for (const room of dead) archiveRoom(historyPath, room);
149
161
  }
150
162
  return live;
151
163
  }
@@ -1,53 +1,123 @@
1
+ import { existsSync } from "node:fs";
1
2
  import { homedir } from "node:os";
2
3
  import { join } from "node:path";
3
4
 
4
5
  /**
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.
6
+ * Where each agent runtime looks for skills, as a table rather than a switch.
7
+ *
8
+ * Adding a runtime is one row. It used to be a `case` in one function plus a
9
+ * literal in a union plus a line of prose, and the three had already drifted —
10
+ * `grok` was missing entirely even though it reads `~/.claude/skills` and has
11
+ * its own `~/.grok/skills`, so the only way to install for it was to type a
12
+ * full path by hand.
13
+ *
14
+ * **Two scopes, deliberately both offered.** A user-scoped skill is available in
15
+ * every project on the machine; a project-scoped one lives in the repository and
16
+ * travels with it, which is what a team wants and what every one of these
17
+ * runtimes ranks *higher* than the user-scoped copy. Neither is the right
18
+ * default for everyone, so `roomyx init` asks instead of choosing.
9
19
  */
10
- export const NAMED_TARGETS = ["claude", "codex", "keryx"] as const;
11
20
 
12
- export type NamedSkillTarget = (typeof NAMED_TARGETS)[number];
21
+ export interface SkillRuntime {
22
+ /** The `--target` name. */
23
+ readonly name: string;
24
+ /** How to say it to a person. */
25
+ readonly label: string;
26
+ readonly scope: "user" | "project";
27
+ /** Where the SKILL.md goes. */
28
+ readonly path: (cwd: string) => string;
29
+ /**
30
+ * The directory whose existence means this runtime is in use here. Used only
31
+ * to pre-tick sensible boxes in `roomyx init` — never to refuse a target,
32
+ * because a runtime installed after roomyx would then be unreachable.
33
+ */
34
+ readonly marker: (cwd: string) => string;
35
+ }
36
+
37
+ const SKILL_FILE = ["skills", "startup-room", "SKILL.md"] as const;
13
38
 
14
- export function isNamedTarget(value: string): value is NamedSkillTarget {
15
- return (NAMED_TARGETS as readonly string[]).includes(value);
39
+ function userRuntime(name: string, label: string, dir: string): SkillRuntime {
40
+ return {
41
+ name,
42
+ label,
43
+ scope: "user",
44
+ path: () => join(homedir(), dir, ...SKILL_FILE),
45
+ marker: () => join(homedir(), dir),
46
+ };
16
47
  }
17
48
 
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
- }
49
+ function projectRuntime(name: string, label: string, dir: string): SkillRuntime {
50
+ return {
51
+ name,
52
+ label,
53
+ scope: "project",
54
+ path: (cwd) => join(cwd, dir, ...SKILL_FILE),
55
+ marker: (cwd) => join(cwd, dir),
56
+ };
57
+ }
58
+
59
+ export const SKILL_RUNTIMES: readonly SkillRuntime[] = [
60
+ userRuntime("claude", "Claude Code", ".claude"),
61
+ userRuntime("codex", "Codex", ".codex"),
62
+ userRuntime("cursor", "Cursor", ".cursor"),
63
+ userRuntime("grok", "Grok", ".grok"),
64
+ projectRuntime("claude-project", "Claude Code", ".claude"),
65
+ projectRuntime("codex-project", "Codex", ".codex"),
66
+ projectRuntime("cursor-project", "Cursor", ".cursor"),
67
+ projectRuntime("grok-project", "Grok", ".grok"),
68
+ {
69
+ // keryx keeps a project's own skills in `.metaproject/project-skills/`, as
70
+ // distinct from `.metaproject/skills/`, which is keryx's own bundled set and
71
+ // not ours to write into. It has no user-scoped location, so there is one
72
+ // row rather than two, and the name has no `-project` suffix because there
73
+ // is nothing to distinguish it from.
74
+ name: "keryx",
75
+ label: "keryx",
76
+ scope: "project",
77
+ path: (cwd) => join(cwd, ".metaproject", "project-skills", "startup-room", "SKILL.md"),
78
+ marker: (cwd) => join(cwd, ".metaproject"),
79
+ },
80
+ ];
81
+
82
+ export const NAMED_TARGETS = SKILL_RUNTIMES.map((runtime) => runtime.name) as readonly string[];
83
+
84
+ export type NamedSkillTarget = string;
85
+
86
+ export function isNamedTarget(value: string): boolean {
87
+ return NAMED_TARGETS.includes(value);
88
+ }
89
+
90
+ export function runtimeByName(name: string): SkillRuntime | undefined {
91
+ return SKILL_RUNTIMES.find((runtime) => runtime.name === name);
92
+ }
93
+
94
+ /** True when this runtime looks like it is actually in use here. */
95
+ export function isRuntimePresent(runtime: SkillRuntime, cwd: string = process.cwd()): boolean {
96
+ return existsSync(runtime.marker(cwd));
97
+ }
98
+
99
+ export function pathForNamedTarget(target: string, cwd: string = process.cwd()): string {
100
+ const runtime = runtimeByName(target);
101
+ if (runtime === undefined) throw new Error(`Unknown skill target "${target}".`);
102
+ return runtime.path(cwd);
35
103
  }
36
104
 
37
105
  /**
38
106
  * 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.
107
+ * every runtime in the table; a name resolves to that runtime's path; anything
108
+ * else is passed through as a literal path.
109
+ *
110
+ * `all` genuinely means all, and that widened when the table grew from three
111
+ * rows to nine — a caller who typed `all` before now reaches Cursor, Grok and
112
+ * the project-scoped locations too. That is a change to what an existing flag
113
+ * does without the caller asking, so it ships in the minor position (D-13),
114
+ * not quietly in a patch.
41
115
  */
42
- export function resolveTargets(
43
- target: string,
44
- cwd: string = process.cwd(),
45
- ): { name: string; path: string }[] {
116
+ export function resolveTargets(target: string, cwd: string = process.cwd()): { name: string; path: string }[] {
46
117
  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) }];
118
+ return SKILL_RUNTIMES.map((runtime) => ({ name: runtime.name, path: runtime.path(cwd) }));
51
119
  }
120
+ const runtime = runtimeByName(target);
121
+ if (runtime) return [{ name: runtime.name, path: runtime.path(cwd) }];
52
122
  return [{ name: target, path: target }];
53
123
  }
@@ -62,7 +62,9 @@ export function createManagementMcpServer(options: ManagementOptions): McpServer
62
62
  // visits could drive it cross-origin. The CLI keeps the literal-path
63
63
  // escape hatch, because that is the operator on their own machine;
64
64
  // the network surface does not get one.
65
- target: z.enum([...NAMED_TARGETS, "all"]).describe("A runtime by name, or `all`."),
65
+ // `"all"` leads so the tuple has a known element at position 0 —
66
+ // NAMED_TARGETS is built from the runtime table and is a plain array.
67
+ target: z.enum(["all", ...NAMED_TARGETS] as [string, ...string[]]).describe("A runtime by name, or `all`."),
66
68
  },
67
69
  },
68
70
  // No `yes`, and no `dryRun`. `yes` is what D-02's overwrite guard turns