astralis-cli 0.1.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 +12 -6
- package/package.json +2 -2
- package/src/commands/connect-mcp.mjs +146 -0
- package/src/commands/theme.mjs +116 -44
- package/src/index.mjs +16 -7
- package/src/lib/ui.mjs +46 -3
- package/src/commands/mcp.mjs +0 -71
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
|
|
51
|
-
docs server
|
|
52
|
-
|
|
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
|
|
56
|
-
npx astralis-cli mcp --
|
|
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.1
|
|
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",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"node": ">=18"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"astralis-ui": "^0.
|
|
39
|
+
"astralis-ui": "^0.2.0"
|
|
40
40
|
},
|
|
41
41
|
"scripts": {
|
|
42
42
|
"test": "node --test"
|
|
@@ -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/commands/theme.mjs
CHANGED
|
@@ -1,58 +1,130 @@
|
|
|
1
1
|
import { parseArgs } from "node:util";
|
|
2
2
|
import { existsSync, writeFileSync } from "node:fs";
|
|
3
|
-
import {
|
|
3
|
+
import { themeCss, validateSeed, isEmptySeed } from "astralis-ui/serialize";
|
|
4
4
|
import { ok, fail, cyan, dim } from "../lib/ui.mjs";
|
|
5
5
|
|
|
6
|
-
const HEX_PATTERN = /^#([0-9a-f]{3}|[0-9a-f]{6})$/i;
|
|
7
|
-
|
|
8
|
-
const serialize = (vars) =>
|
|
9
|
-
Object.entries(vars)
|
|
10
|
-
.map(([name, value]) => ` ${name}: ${value};`)
|
|
11
|
-
.join("\n");
|
|
12
|
-
|
|
13
6
|
/**
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
7
|
+
* Renders a theme seed as a stylesheet — the static equivalent of
|
|
8
|
+
* <AstralisProvider tokens={seed}>, for people who prefer build-time theming
|
|
9
|
+
* over the runtime provider.
|
|
10
|
+
*
|
|
11
|
+
* Both the colour maths and the serialization come from the library and are
|
|
12
|
+
* never duplicated here, so `astralis theme` and the provider cannot drift.
|
|
19
13
|
*/
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
14
|
+
|
|
15
|
+
/** Flag -> seed field. */
|
|
16
|
+
const STRING_FLAGS = {
|
|
17
|
+
brand: "brandColor",
|
|
18
|
+
gray: "grayColor",
|
|
19
|
+
error: "errorColor",
|
|
20
|
+
warning: "warningColor",
|
|
21
|
+
success: "successColor",
|
|
22
|
+
info: "infoColor",
|
|
23
|
+
"font-heading": "fontHeading",
|
|
24
|
+
"font-body": "fontBody",
|
|
25
|
+
"font-mono": "fontMono",
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const NUMBER_FLAGS = {
|
|
29
|
+
radius: "radiusScale",
|
|
30
|
+
spacing: "spacingScale",
|
|
31
|
+
"font-scale": "fontSizeScale",
|
|
32
|
+
motion: "motionScale",
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const USAGE = `Usage: astralis theme [options]
|
|
36
|
+
|
|
37
|
+
Colours
|
|
38
|
+
--brand <hex> brand hue, e.g. "#8b5cf6"
|
|
39
|
+
--gray <hex> neutral hue — drives every surface, label and border,
|
|
40
|
+
and tints white/black so the page follows the neutral
|
|
41
|
+
|
|
42
|
+
Status (each seeds its own palette; the red/orange/green/blue hues and
|
|
43
|
+
their colorScheme values are never altered)
|
|
44
|
+
--error <hex> defaults to red
|
|
45
|
+
--warning <hex> defaults to orange
|
|
46
|
+
--success <hex> defaults to green
|
|
47
|
+
--info <hex> defaults to blue
|
|
48
|
+
|
|
49
|
+
Typefaces
|
|
50
|
+
--font-heading <stack>
|
|
51
|
+
--font-body <stack>
|
|
52
|
+
--font-mono <stack>
|
|
53
|
+
|
|
54
|
+
Scales (1 = library default; 0 is allowed)
|
|
55
|
+
--radius <n> border-radius multiplier
|
|
56
|
+
--spacing <n> spacing multiplier — the density dial
|
|
57
|
+
--font-scale <n> font-size multiplier
|
|
58
|
+
--motion <n> duration multiplier (0 disables transitions)
|
|
59
|
+
|
|
60
|
+
Output
|
|
61
|
+
--out <file> default: astralis-theme.css
|
|
62
|
+
--force overwrite an existing file
|
|
63
|
+
|
|
64
|
+
A bare hex is shorthand for --brand: astralis theme "#8b5cf6"`;
|
|
37
65
|
|
|
38
66
|
export async function run(argv) {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
67
|
+
let parsed;
|
|
68
|
+
try {
|
|
69
|
+
parsed = parseArgs({
|
|
70
|
+
args: argv,
|
|
71
|
+
options: {
|
|
72
|
+
...Object.fromEntries(
|
|
73
|
+
[...Object.keys(STRING_FLAGS), ...Object.keys(NUMBER_FLAGS)].map((f) => [f, { type: "string" }]),
|
|
74
|
+
),
|
|
75
|
+
out: { type: "string", default: "astralis-theme.css" },
|
|
76
|
+
force: { type: "boolean", default: false },
|
|
77
|
+
help: { type: "boolean", default: false },
|
|
78
|
+
},
|
|
79
|
+
allowPositionals: true,
|
|
80
|
+
});
|
|
81
|
+
} catch (error) {
|
|
82
|
+
fail(`${error.message}\n\n${USAGE}`);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const { values, positionals } = parsed;
|
|
86
|
+
if (values.help) {
|
|
87
|
+
console.log(USAGE);
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const seed = {};
|
|
92
|
+
for (const [flag, field] of Object.entries(STRING_FLAGS)) {
|
|
93
|
+
if (values[flag] !== undefined) seed[field] = values[flag];
|
|
94
|
+
}
|
|
95
|
+
for (const [flag, field] of Object.entries(NUMBER_FLAGS)) {
|
|
96
|
+
if (values[flag] === undefined) continue;
|
|
97
|
+
const n = Number(values[flag]);
|
|
98
|
+
if (!Number.isFinite(n)) fail(`--${flag} expects a number, got "${values[flag]}".`);
|
|
99
|
+
seed[field] = n;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// Back-compat: `astralis theme "#8b5cf6"` still means --brand.
|
|
103
|
+
if (positionals[0]) {
|
|
104
|
+
if (seed.brandColor) fail("Pass the brand colour as a positional OR as --brand, not both.");
|
|
105
|
+
seed.brandColor = positionals[0].toLowerCase();
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
if (isEmptySeed(seed)) fail(`Nothing to generate — no theme options given.\n\n${USAGE}`);
|
|
109
|
+
|
|
110
|
+
const issues = validateSeed(seed);
|
|
111
|
+
if (issues.length) {
|
|
112
|
+
fail(`Invalid theme options:\n${issues.map((i) => ` ${i.field}: ${i.message}`).join("\n")}`);
|
|
113
|
+
}
|
|
114
|
+
|
|
51
115
|
if (existsSync(values.out) && !values.force) {
|
|
52
116
|
fail(`${values.out} already exists — pass --force to overwrite.`);
|
|
53
117
|
}
|
|
54
118
|
|
|
55
|
-
writeFileSync(values.out, themeCss(
|
|
119
|
+
writeFileSync(values.out, themeCss(seed));
|
|
56
120
|
ok(`wrote ${cyan(values.out)}`);
|
|
57
|
-
|
|
121
|
+
|
|
122
|
+
const usesFont = seed.fontHeading || seed.fontBody || seed.fontMono;
|
|
123
|
+
console.log(
|
|
124
|
+
`\nImport it after the library stylesheet:\n` +
|
|
125
|
+
` ${cyan('import "astralis-ui/styles.css";')}\n` +
|
|
126
|
+
` ${cyan(`import "./${values.out}";`)}\n` +
|
|
127
|
+
(usesFont ? `${dim("Custom fonts must be loaded by your app (next/font or a <link>).")}\n` : "") +
|
|
128
|
+
`${dim("Runtime alternative: <AstralisProvider tokens={…}> — same math.")}`,
|
|
129
|
+
);
|
|
58
130
|
}
|
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 = `
|
|
@@ -23,10 +23,15 @@ ${bold("Commands")}
|
|
|
23
23
|
${dim("--framework next|vite · extra args pass to the scaffolder")}
|
|
24
24
|
${cyan("init")} wire astralis-ui into this project (Next.js or Vite)
|
|
25
25
|
${dim("--dry-run show the changes without writing")}
|
|
26
|
-
${cyan("theme
|
|
27
|
-
${dim(
|
|
28
|
-
|
|
29
|
-
${dim("--
|
|
26
|
+
${cyan("theme")} generate a static theme stylesheet from a seed
|
|
27
|
+
${dim("--brand/--gray <hex> · --font-heading/-body/-mono <stack>")}
|
|
28
|
+
${dim("--radius/--spacing/--font-scale/--motion <n>")}
|
|
29
|
+
${dim("--out <file> (default astralis-theme.css) · --force")}
|
|
30
|
+
${dim("run `astralis theme --help` for the full list")}
|
|
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")}
|
|
30
35
|
|
|
31
36
|
${bold("Docs")} ${cyan("https://astralis-zeta.vercel.app/docs")}
|
|
32
37
|
`;
|
|
@@ -40,7 +45,11 @@ if (!command || command === "--help" || command === "-h" || command === "help")
|
|
|
40
45
|
console.log(pkg.version);
|
|
41
46
|
} else if (COMMANDS[command]) {
|
|
42
47
|
const { run } = await COMMANDS[command]();
|
|
43
|
-
|
|
48
|
+
try {
|
|
49
|
+
await run(rest);
|
|
50
|
+
} finally {
|
|
51
|
+
closePrompts();
|
|
52
|
+
}
|
|
44
53
|
} else {
|
|
45
54
|
fail(`Unknown command "${command}" — run ${cyan("astralis --help")}.`);
|
|
46
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
|
|
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
|
+
}
|
package/src/commands/mcp.mjs
DELETED
|
@@ -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
|
-
}
|