astralis-cli 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/README.md CHANGED
@@ -45,17 +45,23 @@ npx astralis-cli theme "#8b5cf6" --out astralis-theme.css
45
45
 
46
46
  Import it **after** `astralis-ui/styles.css`.
47
47
 
48
- ### `astralis mcp`
48
+ ### `astralis connect-mcp`
49
49
 
50
- Connects AI coding agents to the [astralis-mcp](https://www.npmjs.com/package/astralis-mcp)
51
- docs server — prints ready-made configs for Claude Code, Cursor, and any MCP
52
- client; `--write` adds it to Claude Desktop's config for you (with a backup).
50
+ Connects a single client to the [astralis-mcp](https://www.npmjs.com/package/astralis-mcp)
51
+ docs server. It prompts for the client (Claude Code, Codex, Cursor, Claude
52
+ Desktop, or Antigravity), tells you exactly what it's about to do, asks you to
53
+ confirm, then does it — running the client's own `mcp add` command, or writing
54
+ its JSON config (with a backup). Pass `--client` to skip the prompt.
53
55
 
54
56
  ```bash
55
- npx astralis-cli mcp # print configs
56
- npx astralis-cli mcp --write # configure Claude Desktop
57
+ npx astralis-cli connect-mcp # prompt for a client, then configure it
58
+ npx astralis-cli connect-mcp --client antigravity # go straight to Antigravity
59
+ npx astralis-cli connect-mcp --client codex # go straight to Codex
57
60
  ```
58
61
 
62
+ Claude Code and Codex are configured by running their own `mcp add` command;
63
+ Cursor, Claude Desktop, and Antigravity by writing their config files.
64
+
59
65
  ## License
60
66
 
61
67
  MIT
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "astralis-cli",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "Setup and tooling CLI for Astralis UI — wire up a project, generate a static brand theme, connect the MCP server.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -0,0 +1,146 @@
1
+ import { parseArgs } from "node:util";
2
+ import { existsSync, readFileSync, writeFileSync, copyFileSync, mkdirSync } from "node:fs";
3
+ import { join, dirname } from "node:path";
4
+ import { homedir } from "node:os";
5
+ import { spawnSync } from "node:child_process";
6
+ import { ok, warn, info, fail, confirm, select, bold, cyan, dim } from "../lib/ui.mjs";
7
+
8
+ /**
9
+ * Connect one AI coding agent to the astralis-mcp docs server. Pick a client
10
+ * (prompted, or via --client); the CLI explains exactly what it will do for
11
+ * that client, confirms, then does it — running the client's own `mcp add`
12
+ * command, or writing its JSON config file (with a backup).
13
+ */
14
+
15
+ /** Windows can't spawn npx directly from a JSON command — it needs the cmd shim. */
16
+ export function mcpServerEntry(platform = process.platform) {
17
+ return platform === "win32"
18
+ ? { command: "cmd", args: ["/c", "npx", "-y", "astralis-mcp"] }
19
+ : { command: "npx", args: ["-y", "astralis-mcp"] };
20
+ }
21
+
22
+ export function claudeDesktopConfigPath(platform = process.platform, home = homedir()) {
23
+ if (platform === "win32") return join(process.env.APPDATA ?? join(home, "AppData", "Roaming"), "Claude", "claude_desktop_config.json");
24
+ if (platform === "darwin") return join(home, "Library", "Application Support", "Claude", "claude_desktop_config.json");
25
+ return join(home, ".config", "Claude", "claude_desktop_config.json");
26
+ }
27
+
28
+ export function cursorConfigPath(home = homedir()) {
29
+ return join(home, ".cursor", "mcp.json");
30
+ }
31
+
32
+ /** Antigravity shares one config across IDE and CLI — same path on every platform. */
33
+ export function antigravityConfigPath(home = homedir()) {
34
+ return join(home, ".gemini", "config", "mcp_config.json");
35
+ }
36
+
37
+ /**
38
+ * Every supported client, in menu order. Two kinds:
39
+ * "command" — the client owns its config; we run its `mcp add` for you.
40
+ * "file" — we write an `mcpServers` entry into its JSON config (with backup).
41
+ */
42
+ export const CLIENTS = {
43
+ "claude-code": { label: "Claude Code", kind: "command", bin: "claude" },
44
+ codex: { label: "Codex", kind: "command", bin: "codex" },
45
+ cursor: { label: "Cursor", kind: "file", path: cursorConfigPath, reload: "Reload Cursor to pick it up." },
46
+ "claude-desktop": { label: "Claude Desktop", kind: "file", path: claudeDesktopConfigPath, reload: "Restart Claude Desktop to pick it up." },
47
+ antigravity: { label: "Antigravity", kind: "file", path: antigravityConfigPath, reload: "Reload Antigravity to pick it up." },
48
+ };
49
+
50
+ /** The `mcp add` argv both command-based clients happen to share. */
51
+ const ADD_ARGS = ["mcp", "add", "astralis", "--", "npx", "-y", "astralis-mcp"];
52
+
53
+ /**
54
+ * Parse an existing config file's contents. An empty or whitespace-only file
55
+ * (something else touched it into existence) counts as a fresh config, not an
56
+ * error; genuinely malformed JSON throws for the caller to report.
57
+ */
58
+ export function parseConfigFile(raw) {
59
+ return raw.trim() === "" ? {} : JSON.parse(raw);
60
+ }
61
+
62
+ export async function run(argv) {
63
+ const { values } = parseArgs({ args: argv, options: { client: { type: "string" } } });
64
+
65
+ let key = values.client;
66
+ if (key === undefined) {
67
+ console.log(`${bold("Connect a client")} to the Astralis MCP docs server.\n`);
68
+ key = await select(
69
+ "Which client do you want to connect?",
70
+ Object.entries(CLIENTS).map(([value, { label }]) => ({ value, label })),
71
+ );
72
+ if (key === null) {
73
+ warn("No client selected — nothing to do.");
74
+ return;
75
+ }
76
+ }
77
+
78
+ const client = CLIENTS[key];
79
+ if (!client) {
80
+ fail(`Unknown --client "${key}" — expected one of: ${Object.keys(CLIENTS).join(", ")}.`);
81
+ }
82
+
83
+ console.log();
84
+ if (client.kind === "command") await connectViaCommand(client);
85
+ else await connectViaFile(client);
86
+ }
87
+
88
+ /** Run the client's own `mcp add` command, falling back to a copy-paste line. */
89
+ async function connectViaCommand(client) {
90
+ const cmdline = `${client.bin} ${ADD_ARGS.join(" ")}`;
91
+ info(`${bold(client.label)} manages MCP servers with its own CLI.`);
92
+ console.log(` I'll run: ${cyan(cmdline)}`);
93
+ console.log(dim(` Needs the ${client.bin} CLI on your PATH.`));
94
+
95
+ if (!(await confirm("Proceed?"))) {
96
+ warn("Cancelled.");
97
+ return;
98
+ }
99
+
100
+ const result = spawnSync(cmdline, { stdio: "inherit", shell: true });
101
+ if (result.status === 0) {
102
+ ok(`Connected ${client.label} to the Astralis docs server.`);
103
+ } else {
104
+ fail(`That didn't complete (is the ${cyan(client.bin)} CLI installed?). You can run it yourself:\n ${cyan(cmdline)}`);
105
+ }
106
+ }
107
+
108
+ /** Merge the astralis entry into the client's JSON config, backing up first. */
109
+ async function connectViaFile(client) {
110
+ const entry = mcpServerEntry();
111
+ const configPath = client.path();
112
+
113
+ // Read the existing config first — nothing to describe or back up if the
114
+ // server is already there.
115
+ let config = {};
116
+ if (existsSync(configPath)) {
117
+ try {
118
+ config = parseConfigFile(readFileSync(configPath, "utf8"));
119
+ } catch {
120
+ fail(`${configPath} exists but isn't valid JSON — fix or remove it first.`);
121
+ }
122
+ }
123
+
124
+ if (config.mcpServers?.astralis) {
125
+ ok(`${client.label} already has an "astralis" MCP server configured:`);
126
+ console.log(dim(JSON.stringify(config.mcpServers.astralis, null, 2)));
127
+ return;
128
+ }
129
+
130
+ info(`${bold(client.label)} reads MCP servers from a JSON config file.`);
131
+ console.log(` ${dim("file: ")} ${cyan(configPath)}`);
132
+ console.log(` ${dim("adds: ")} ${cyan(`"astralis": ${JSON.stringify(entry)}`)}`);
133
+ if (existsSync(configPath)) console.log(dim(" Your current config will be backed up for ease of revision."));
134
+
135
+ if (!(await confirm("Proceed?"))) {
136
+ warn("Cancelled.");
137
+ return;
138
+ }
139
+
140
+ if (existsSync(configPath)) copyFileSync(configPath, configPath + ".bak");
141
+ else mkdirSync(dirname(configPath), { recursive: true });
142
+ config.mcpServers = { ...config.mcpServers, astralis: entry };
143
+ writeFileSync(configPath, JSON.stringify(config, null, 2) + "\n");
144
+ ok(`written${existsSync(configPath + ".bak") ? dim(` (backup: ${configPath}.bak)`) : ""}`);
145
+ info(client.reload);
146
+ }
package/src/index.mjs CHANGED
@@ -2,13 +2,13 @@
2
2
  import { readFileSync } from "node:fs";
3
3
  import { fileURLToPath } from "node:url";
4
4
  import { join, dirname } from "node:path";
5
- import { bold, cyan, dim, fail } from "./lib/ui.mjs";
5
+ import { bold, cyan, dim, fail, closePrompts } from "./lib/ui.mjs";
6
6
 
7
7
  const COMMANDS = {
8
8
  create: () => import("./commands/create.mjs"),
9
9
  init: () => import("./commands/init.mjs"),
10
10
  theme: () => import("./commands/theme.mjs"),
11
- mcp: () => import("./commands/mcp.mjs"),
11
+ "connect-mcp": () => import("./commands/connect-mcp.mjs"),
12
12
  };
13
13
 
14
14
  const HELP = `
@@ -28,8 +28,10 @@ ${bold("Commands")}
28
28
  ${dim("--radius/--spacing/--font-scale/--motion <n>")}
29
29
  ${dim("--out <file> (default astralis-theme.css) · --force")}
30
30
  ${dim("run `astralis theme --help` for the full list")}
31
- ${cyan("mcp")} connect AI coding agents to the Astralis docs server
32
- ${dim("--write add it to Claude Desktop's config")}
31
+ ${cyan("connect-mcp")} connect a client to the Astralis docs server
32
+ ${dim("prompts for the client, then configures it for you")}
33
+ ${dim("--client claude-code|codex|cursor|claude-desktop|antigravity")}
34
+ ${dim(" skip the prompt and pick the client directly")}
33
35
 
34
36
  ${bold("Docs")} ${cyan("https://astralis-zeta.vercel.app/docs")}
35
37
  `;
@@ -43,7 +45,11 @@ if (!command || command === "--help" || command === "-h" || command === "help")
43
45
  console.log(pkg.version);
44
46
  } else if (COMMANDS[command]) {
45
47
  const { run } = await COMMANDS[command]();
46
- await run(rest);
48
+ try {
49
+ await run(rest);
50
+ } finally {
51
+ closePrompts();
52
+ }
47
53
  } else {
48
54
  fail(`Unknown command "${command}" — run ${cyan("astralis --help")}.`);
49
55
  }
package/src/lib/ui.mjs CHANGED
@@ -25,10 +25,53 @@ export function fail(message) {
25
25
  process.exit(1);
26
26
  }
27
27
 
28
+ /*
29
+ * One shared readline for the whole process, draining lines through a queue.
30
+ * readline reads ahead, so with piped input it emits the next line's `line`
31
+ * event in the gap between one prompt resolving and the next registering its
32
+ * listener (e.g. select → confirm) — a per-question `rl.question` loses it. A
33
+ * standing `line` listener queues those reads instead. Callers run
34
+ * closePrompts() when done so the open stream stops keeping the process alive.
35
+ */
36
+ let sharedRl = null;
37
+ let lineQueue = [];
38
+ let lineWaiter = null;
39
+
40
+ function ask(promptText) {
41
+ if (!sharedRl) {
42
+ sharedRl = readline.createInterface({ input: process.stdin, output: process.stdout });
43
+ sharedRl.on("line", (line) => {
44
+ if (lineWaiter) { const resolve = lineWaiter; lineWaiter = null; resolve(line); }
45
+ else lineQueue.push(line);
46
+ });
47
+ // EOF (piped input exhausted): unblock a pending prompt with an empty answer.
48
+ sharedRl.on("close", () => { if (lineWaiter) { const resolve = lineWaiter; lineWaiter = null; resolve(""); } });
49
+ }
50
+ process.stdout.write(promptText);
51
+ if (lineQueue.length) return Promise.resolve(lineQueue.shift());
52
+ return new Promise((resolve) => { lineWaiter = resolve; });
53
+ }
54
+
55
+ export function closePrompts() {
56
+ sharedRl?.close();
57
+ sharedRl = null;
58
+ lineQueue = [];
59
+ lineWaiter = null;
60
+ }
61
+
28
62
  /** y/N prompt; default no. */
29
63
  export async function confirm(question) {
30
- const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
31
- const answer = await rl.question(`${question} ${dim("(y/N)")} `);
32
- rl.close();
64
+ const answer = await ask(`${question} ${dim("(y/N)")} `);
33
65
  return /^y(es)?$/i.test(answer.trim());
34
66
  }
67
+
68
+ /**
69
+ * Numbered single-choice prompt. `options` is [{ value, label }].
70
+ * Returns the chosen value, or null if the answer isn't a listed number.
71
+ */
72
+ export async function select(question, options) {
73
+ console.log(question);
74
+ options.forEach((o, i) => console.log(` ${cyan(String(i + 1))} ${o.label}`));
75
+ const answer = await ask(`${dim("Enter a number:")} `);
76
+ return options[Number(answer.trim()) - 1]?.value ?? null;
77
+ }
@@ -1,71 +0,0 @@
1
- import { parseArgs } from "node:util";
2
- import { existsSync, readFileSync, writeFileSync, copyFileSync, mkdirSync } from "node:fs";
3
- import { join, dirname } from "node:path";
4
- import { homedir } from "node:os";
5
- import { ok, warn, info, fail, confirm, bold, cyan, dim } from "../lib/ui.mjs";
6
-
7
- /**
8
- * Connect AI coding agents to the astralis-mcp docs server. Prints the config
9
- * for every client; --write merges it into Claude Desktop's config file
10
- * (the only client without a CLI or UI for adding servers by hand).
11
- */
12
-
13
- /** Windows can't spawn npx directly from a JSON command — it needs the cmd shim. */
14
- export function mcpServerEntry(platform = process.platform) {
15
- return platform === "win32"
16
- ? { command: "cmd", args: ["/c", "npx", "-y", "astralis-mcp"] }
17
- : { command: "npx", args: ["-y", "astralis-mcp"] };
18
- }
19
-
20
- export function claudeDesktopConfigPath(platform = process.platform, home = homedir()) {
21
- if (platform === "win32") return join(process.env.APPDATA ?? join(home, "AppData", "Roaming"), "Claude", "claude_desktop_config.json");
22
- if (platform === "darwin") return join(home, "Library", "Application Support", "Claude", "claude_desktop_config.json");
23
- return join(home, ".config", "Claude", "claude_desktop_config.json");
24
- }
25
-
26
- export async function run(argv) {
27
- const { values } = parseArgs({
28
- args: argv,
29
- options: { write: { type: "boolean", default: false } },
30
- });
31
-
32
- const entry = mcpServerEntry();
33
- const snippet = JSON.stringify({ mcpServers: { astralis: entry } }, null, 2);
34
-
35
- if (!values.write) {
36
- console.log(`${bold("Astralis MCP server")} — live component docs for AI coding agents.\n`);
37
- console.log(`${bold("Claude Code")}\n ${cyan("claude mcp add astralis -- npx -y astralis-mcp")}\n`);
38
- console.log(`${bold("Cursor")} ${dim("(~/.cursor/mcp.json)")} ${bold("/ any MCP client")}\n${snippet.split("\n").map((l) => " " + l).join("\n")}\n`);
39
- console.log(`${bold("Claude Desktop")}\n ${cyan("astralis mcp --write")} ${dim(`(edits ${claudeDesktopConfigPath()})`)}`);
40
- return;
41
- }
42
-
43
- const configPath = claudeDesktopConfigPath();
44
- let config = {};
45
- if (existsSync(configPath)) {
46
- try {
47
- config = JSON.parse(readFileSync(configPath, "utf8"));
48
- } catch {
49
- fail(`${configPath} exists but isn't valid JSON — fix or remove it first.`);
50
- }
51
- }
52
-
53
- if (config.mcpServers?.astralis) {
54
- ok("Claude Desktop already has an \"astralis\" MCP server configured:");
55
- console.log(dim(JSON.stringify(config.mcpServers.astralis, null, 2)));
56
- return;
57
- }
58
-
59
- info(`This will add the "astralis" server to ${cyan(configPath)}`);
60
- if (!(await confirm("Write it?"))) {
61
- warn("Nothing written.");
62
- return;
63
- }
64
-
65
- if (existsSync(configPath)) copyFileSync(configPath, configPath + ".bak");
66
- else mkdirSync(dirname(configPath), { recursive: true });
67
- config.mcpServers = { ...config.mcpServers, astralis: entry };
68
- writeFileSync(configPath, JSON.stringify(config, null, 2) + "\n");
69
- ok(`written${existsSync(configPath + ".bak") ? dim(` (backup: ${configPath}.bak)`) : ""}`);
70
- info("Restart Claude Desktop to pick it up.");
71
- }