@keystoneui/mcp 0.2.0-beta.1 → 0.2.0-beta.10

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/dist/index.js CHANGED
@@ -1,28 +1,37 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  auditChecklistTool,
4
+ detectProjectContext,
5
+ displayUrl,
6
+ escapedError,
4
7
  getExamplesTool,
8
+ isCommandSafe,
5
9
  listComponentsTool,
6
10
  loadProjectConfig,
11
+ lookupManifest,
12
+ nameRefusal,
13
+ parseThemeCode,
14
+ parseThemeParts,
15
+ readPackageVersion,
16
+ redactUrlInError,
17
+ registryCatalogueUrl,
18
+ resolveDocs,
7
19
  searchComponentsTool,
20
+ shown,
21
+ themeBuilderUrl,
22
+ themeInstallCommand,
23
+ themeInstallUrl,
8
24
  viewComponentTool
9
- } from "./chunk-DZNQW5EA.js";
25
+ } from "./chunk-5RKRKR2Z.js";
26
+
27
+ // src/cli.ts
28
+ import { existsSync as existsSync3, readFileSync as readFileSync3 } from "fs";
10
29
 
11
30
  // src/info.ts
12
31
  import { existsSync, readFileSync } from "fs";
13
32
  import { homedir } from "os";
14
33
  import { resolve } from "path";
15
- import { fileURLToPath } from "url";
16
34
  var DEFAULT_DOCS_URL = "https://keystoneui.io";
17
- function readPackageVersion() {
18
- try {
19
- const pkgPath = fileURLToPath(new URL("../package.json", import.meta.url));
20
- const pkg = JSON.parse(readFileSync(pkgPath, "utf-8"));
21
- return pkg.version ?? "unknown";
22
- } catch {
23
- return "unknown";
24
- }
25
- }
26
35
  function detectMcpClients(cwd) {
27
36
  const candidates = [
28
37
  { name: "claude", path: resolve(cwd, ".mcp.json") },
@@ -82,21 +91,22 @@ function collect() {
82
91
  const docsUrl = process.env.KEYSTONEUI_URL ?? DEFAULT_DOCS_URL;
83
92
  const version = readPackageVersion();
84
93
  return {
85
- schema: 1,
94
+ schema: 2,
86
95
  package: { name: "@keystoneui/mcp", version },
96
+ project: detectProjectContext(cwd),
87
97
  environment: {
88
98
  node: process.version,
89
99
  platform: process.platform,
90
100
  cwd,
91
- registryUrl: config.registry.url,
92
- docsUrl
101
+ registryUrl: displayUrl(config.registry.url),
102
+ docsUrl: displayUrl(docsUrl)
93
103
  },
94
104
  mcpClients: detectMcpClients(cwd),
95
105
  installedPackages: detectInstalledPackages(cwd),
96
106
  links: {
97
- docs: docsUrl,
98
- registry: `${config.registry.url}/registry.json`,
99
- llms: `${docsUrl}/llms.txt`
107
+ docs: displayUrl(docsUrl),
108
+ registry: displayUrl(registryCatalogueUrl(config.registry)),
109
+ llms: displayUrl(`${docsUrl}/llms.txt`)
100
110
  }
101
111
  };
102
112
  }
@@ -106,16 +116,30 @@ function pad(label, width = 18) {
106
116
  }
107
117
  return label.padEnd(width, " ");
108
118
  }
119
+ function shownOr(value) {
120
+ return value === null || value === void 0 ? "(unknown)" : shown(value);
121
+ }
109
122
  function printText(data) {
110
123
  const lines = [];
111
124
  lines.push(`${data.package.name} v${data.package.version}`);
112
125
  lines.push("");
126
+ const p = data.project;
127
+ lines.push("Project");
128
+ lines.push(` ${pad("Install mode")}${p.installMode}`);
129
+ lines.push(` ${pad("UI alias")}${shownOr(p.aliases?.ui)}`);
130
+ lines.push(` ${pad("Theme CSS")}${shownOr(p.tailwindCssFile)}`);
131
+ lines.push(` ${pad("Icon library")}${shownOr(p.iconLibrary)}`);
132
+ lines.push(
133
+ ` ${pad("RSC")}${p.isRSC === null ? "(unknown)" : String(p.isRSC)}`
134
+ );
135
+ lines.push(` ${pad("Package manager")}${shownOr(p.packageManager)}`);
136
+ lines.push("");
113
137
  lines.push("Environment");
114
- lines.push(` ${pad("Node")}${data.environment.node}`);
115
- lines.push(` ${pad("Platform")}${data.environment.platform}`);
116
- lines.push(` ${pad("Project root")}${data.environment.cwd}`);
117
- lines.push(` ${pad("Registry URL")}${data.environment.registryUrl}`);
118
- lines.push(` ${pad("Docs URL")}${data.environment.docsUrl}`);
138
+ lines.push(` ${pad("Node")}${shown(data.environment.node)}`);
139
+ lines.push(` ${pad("Platform")}${shown(data.environment.platform)}`);
140
+ lines.push(` ${pad("Project root")}${shown(data.environment.cwd)}`);
141
+ lines.push(` ${pad("Registry URL")}${shown(data.environment.registryUrl)}`);
142
+ lines.push(` ${pad("Docs URL")}${shown(data.environment.docsUrl)}`);
119
143
  lines.push("");
120
144
  lines.push("MCP clients");
121
145
  const configured = data.mcpClients.filter((c) => c.configured);
@@ -123,7 +147,7 @@ function printText(data) {
123
147
  lines.push(" (none configured for keystoneui)");
124
148
  } else {
125
149
  for (const client of configured) {
126
- lines.push(` ${pad(client.name)}${client.configPath}`);
150
+ lines.push(` ${pad(client.name)}${shown(client.configPath)}`);
127
151
  }
128
152
  }
129
153
  lines.push("");
@@ -132,14 +156,14 @@ function printText(data) {
132
156
  lines.push(" (none detected in this project)");
133
157
  } else {
134
158
  for (const pkg of data.installedPackages) {
135
- lines.push(` ${pad(pkg.name, 28)}v${pkg.version}`);
159
+ lines.push(` ${pad(shown(pkg.name), 28)}v${shown(pkg.version)}`);
136
160
  }
137
161
  }
138
162
  lines.push("");
139
163
  lines.push("Links");
140
- lines.push(` ${pad("Docs")}${data.links.docs}`);
141
- lines.push(` ${pad("Registry")}${data.links.registry}`);
142
- lines.push(` ${pad("llms.txt")}${data.links.llms}`);
164
+ lines.push(` ${pad("Docs")}${shown(data.links.docs)}`);
165
+ lines.push(` ${pad("Registry")}${shown(data.links.registry)}`);
166
+ lines.push(` ${pad("llms.txt")}${shown(data.links.llms)}`);
143
167
  console.log(lines.join("\n"));
144
168
  }
145
169
  function runInfo(args) {
@@ -155,6 +179,7 @@ function runInfo(args) {
155
179
  // src/init.ts
156
180
  import { existsSync as existsSync2, mkdirSync, readFileSync as readFileSync2, writeFileSync } from "fs";
157
181
  import { dirname, resolve as resolve2 } from "path";
182
+ var TRUST_POINTER = "The server runs with this project's settings. Before using it in a project you have not reviewed, read https://keystoneui.io/docs/agents/mcp-server#projects-you-do-not-trust";
158
183
  var SERVER_ENTRY = {
159
184
  command: "npx",
160
185
  args: ["@keystoneui/mcp@latest"]
@@ -223,7 +248,11 @@ function mergeJsonConfig(existing, client) {
223
248
  function writeJsonClient(client) {
224
249
  const targetPath = resolve2(process.cwd(), client.configPath);
225
250
  const dir = dirname(targetPath);
226
- mkdirSync(dir, { recursive: true });
251
+ try {
252
+ mkdirSync(dir, { recursive: true });
253
+ } catch (error) {
254
+ throw escapedError(error);
255
+ }
227
256
  let existing = {};
228
257
  if (existsSync2(targetPath)) {
229
258
  try {
@@ -232,10 +261,15 @@ function writeJsonClient(client) {
232
261
  }
233
262
  }
234
263
  const merged = mergeJsonConfig(existing, client);
235
- writeFileSync(targetPath, `${JSON.stringify(merged, null, 2)}
264
+ try {
265
+ writeFileSync(targetPath, `${JSON.stringify(merged, null, 2)}
236
266
  `);
267
+ } catch (error) {
268
+ throw escapedError(error);
269
+ }
237
270
  console.log(`Created ${client.configPath}`);
238
271
  console.log(`Keystone UI MCP server configured for ${client.name}.`);
272
+ console.log(TRUST_POINTER);
239
273
  }
240
274
  function printCodexInstructions() {
241
275
  console.log("Codex uses a global TOML config that cannot be auto-written.");
@@ -247,17 +281,18 @@ function printCodexInstructions() {
247
281
  console.log(' args = ["@keystoneui/mcp@latest"]');
248
282
  console.log("");
249
283
  console.log("Then restart Codex.");
284
+ console.log(TRUST_POINTER);
250
285
  }
251
286
  function printUsage() {
252
287
  const names = CLIENTS.map((c) => c.name).join(", ");
253
- console.log("Usage: npx @keystoneui/mcp init --client <name>");
288
+ console.log("Usage: npx @keystoneui/mcp@latest init --client <name>");
254
289
  console.log("");
255
290
  console.log(`Supported clients: ${names}`);
256
291
  console.log("");
257
292
  console.log("Examples:");
258
- console.log(" npx @keystoneui/mcp init --client cursor");
259
- console.log(" npx @keystoneui/mcp init --client claude");
260
- console.log(" npx @keystoneui/mcp init --client vscode");
293
+ console.log(" npx @keystoneui/mcp@latest init --client cursor");
294
+ console.log(" npx @keystoneui/mcp@latest init --client claude");
295
+ console.log(" npx @keystoneui/mcp@latest init --client vscode");
261
296
  }
262
297
  function init() {
263
298
  const clientName = parseArgs();
@@ -268,7 +303,7 @@ function init() {
268
303
  }
269
304
  const client = CLIENTS.find((c) => c.name === clientName);
270
305
  if (!client) {
271
- console.error(`Unknown client: "${clientName}"`);
306
+ console.error(`Unknown client: "${shown(clientName)}"`);
272
307
  console.error("");
273
308
  printUsage();
274
309
  process.exitCode = 1;
@@ -281,6 +316,177 @@ function init() {
281
316
  writeJsonClient(client);
282
317
  }
283
318
 
319
+ // src/theme-audit.ts
320
+ var TEXT_PAIRS = [
321
+ ["foreground", "background"],
322
+ ["card-foreground", "card"],
323
+ ["popover-foreground", "popover"],
324
+ ["primary-foreground", "primary"],
325
+ ["secondary-foreground", "secondary"],
326
+ ["muted-foreground", "background"],
327
+ ["accent-foreground", "accent"],
328
+ ["destructive-foreground", "destructive"],
329
+ ["success-foreground", "success"],
330
+ ["warning-foreground", "warning"],
331
+ ["info-foreground", "info"],
332
+ ["success-text", "background"],
333
+ ["warning-text", "background"]
334
+ ];
335
+ var TEXT_FALLBACKS = {
336
+ "success-text": "success",
337
+ "warning-text": "warning"
338
+ };
339
+ var AA_TEXT = 4.5;
340
+ var DECLARATION_RE = /--([\w-]+)\s*:\s*([^;]+);/g;
341
+ var OKLCH_RE = /^oklch\(\s*([\d.]+)(%?)\s+([\d.]+)\s+([\d.]+)(?:deg)?\s*\)$/i;
342
+ var HEX_RE = /^#([0-9a-f]{3}|[0-9a-f]{6})$/i;
343
+ var COMMENT_RE = /\/\*[\s\S]*?\*\//g;
344
+ function declarations(block) {
345
+ const out = {};
346
+ for (const [, name, value] of block.matchAll(DECLARATION_RE)) {
347
+ out[name] = value.trim();
348
+ }
349
+ return out;
350
+ }
351
+ function closingBrace(css, open) {
352
+ let depth = 0;
353
+ for (let i = open; i < css.length; i++) {
354
+ if (css[i] === "{") {
355
+ depth++;
356
+ } else if (css[i] === "}") {
357
+ depth--;
358
+ if (depth === 0) {
359
+ return i;
360
+ }
361
+ }
362
+ }
363
+ return css.length;
364
+ }
365
+ function themeBlocks(css) {
366
+ const blocks = [];
367
+ const preludes = [];
368
+ let start = 0;
369
+ for (let i = 0; i < css.length; i++) {
370
+ const ch = css[i];
371
+ if (ch === "{") {
372
+ const prelude = css.slice(start, i).trim();
373
+ const ancestorsOk = preludes.every((p) => p.startsWith("@layer"));
374
+ if (ancestorsOk && (prelude === ":root" || prelude === ".dark")) {
375
+ const j = closingBrace(css, i);
376
+ blocks.push({ body: css.slice(i + 1, j), selector: prelude });
377
+ i = j;
378
+ start = j + 1;
379
+ continue;
380
+ }
381
+ preludes.push(prelude);
382
+ start = i + 1;
383
+ } else if (ch === "}") {
384
+ preludes.pop();
385
+ start = i + 1;
386
+ } else if (ch === ";") {
387
+ start = i + 1;
388
+ }
389
+ }
390
+ return blocks;
391
+ }
392
+ function readThemeTokens(css) {
393
+ const stripped = css.replace(COMMENT_RE, "");
394
+ const light = {};
395
+ const dark = {};
396
+ for (const { body, selector } of themeBlocks(stripped)) {
397
+ Object.assign(selector === ":root" ? light : dark, declarations(body));
398
+ }
399
+ return { dark: { ...light, ...dark }, light };
400
+ }
401
+ function linearRgb(value) {
402
+ const oklch = OKLCH_RE.exec(value.trim());
403
+ if (oklch) {
404
+ const l = Number(oklch[1]) / (oklch[2] === "%" ? 100 : 1);
405
+ const c = Number(oklch[3]);
406
+ const h = Number(oklch[4]) * Math.PI / 180;
407
+ const a = c * Math.cos(h);
408
+ const b = c * Math.sin(h);
409
+ const l3 = (l + 0.3963377774 * a + 0.2158037573 * b) ** 3;
410
+ const m3 = (l - 0.1055613458 * a - 0.0638541728 * b) ** 3;
411
+ const s3 = (l - 0.0894841775 * a - 1.291485548 * b) ** 3;
412
+ const clamp = (x) => Math.min(Math.max(x, 0), 1);
413
+ return [
414
+ clamp(4.0767416621 * l3 - 3.3077115913 * m3 + 0.2309699292 * s3),
415
+ clamp(
416
+ -1.2684380046 * l3 + 2.6097574011 * m3 - 0.3413193965 * s3
417
+ ),
418
+ clamp(-0.0041960863 * l3 - 0.7034186147 * m3 + 1.707614701 * s3)
419
+ ];
420
+ }
421
+ const hex = HEX_RE.exec(value.trim());
422
+ if (hex) {
423
+ const digits = hex[1].length === 3 ? [...hex[1]].map((d) => d + d).join("") : hex[1];
424
+ const channel = (i) => {
425
+ const v = Number.parseInt(digits.slice(i, i + 2), 16) / 255;
426
+ return v <= 0.04045 ? v / 12.92 : ((v + 0.055) / 1.055) ** 2.4;
427
+ };
428
+ return [channel(0), channel(2), channel(4)];
429
+ }
430
+ return null;
431
+ }
432
+ function contrastRatio(fg, bg) {
433
+ const a = linearRgb(fg);
434
+ const b = linearRgb(bg);
435
+ if (!(a && b)) {
436
+ return null;
437
+ }
438
+ const y = ([r, g, bl]) => 0.2126 * r + 0.7152 * g + 0.0722 * bl;
439
+ const [hi, lo] = [y(a), y(b)].sort((p, q) => q - p);
440
+ return (hi + 0.05) / (lo + 0.05);
441
+ }
442
+ function statusOf(ratio) {
443
+ if (ratio === null) {
444
+ return "skip";
445
+ }
446
+ return ratio >= AA_TEXT ? "pass" : "fail";
447
+ }
448
+ function auditTheme(tokens) {
449
+ const results = [];
450
+ for (const mode of ["light", "dark"]) {
451
+ for (const [fg, bg] of TEXT_PAIRS) {
452
+ const fallback = tokens[mode][fg] === void 0 ? TEXT_FALLBACKS[fg] : void 0;
453
+ const fgValue = tokens[mode][fallback ?? fg];
454
+ const bgValue = tokens[mode][bg];
455
+ if (!(fgValue && bgValue)) {
456
+ continue;
457
+ }
458
+ const ratio = contrastRatio(fgValue, bgValue);
459
+ results.push({
460
+ ...fallback && { fallback },
461
+ mode,
462
+ pair: `${fg} on ${bg}`,
463
+ ratio,
464
+ status: statusOf(ratio)
465
+ });
466
+ }
467
+ }
468
+ return results;
469
+ }
470
+ function formatAudit(file, results) {
471
+ if (results.length === 0) {
472
+ return `No keystone token pairs found in ${shown(file)}. Pass the CSS file that holds :root and .dark.`;
473
+ }
474
+ const lines = results.map((r) => {
475
+ const mark = { fail: "\u2716", pass: "\u2714", skip: "\u2013" }[r.status];
476
+ const ratio = r.ratio === null ? "needs a browser" : `${r.ratio.toFixed(2)}:1`;
477
+ const note = r.fallback ? ` (not declared; measured --${r.fallback}, which paints instead)` : "";
478
+ return `${mark} ${r.mode.padEnd(5)} ${r.pair.padEnd(42)} ${ratio}${note}`;
479
+ });
480
+ const failed = results.filter((r) => r.status === "fail").length;
481
+ return [
482
+ `Theme contrast \u2014 ${shown(file)} (WCAG AA for text: ${AA_TEXT}:1)`,
483
+ "",
484
+ ...lines,
485
+ "",
486
+ failed === 0 ? "All measurable pairs pass." : `${failed} pair(s) under ${AA_TEXT}:1.`
487
+ ].join("\n");
488
+ }
489
+
284
490
  // src/cli.ts
285
491
  var VERBS = [
286
492
  "init",
@@ -291,7 +497,8 @@ var VERBS = [
291
497
  "examples",
292
498
  "docs",
293
499
  "audit",
294
- "blocks"
500
+ "blocks",
501
+ "theme"
295
502
  ];
296
503
  var BLOCK_NAME_PATTERN = /^[a-z0-9-]+$/;
297
504
  function isCliVerb(arg) {
@@ -317,24 +524,48 @@ function parseArgs2(args) {
317
524
  }
318
525
  return { flags, positional };
319
526
  }
527
+ var TYPES = [
528
+ "ui",
529
+ "block",
530
+ "example",
531
+ "kit",
532
+ "hook",
533
+ "style",
534
+ "theme",
535
+ "font",
536
+ "item"
537
+ ];
320
538
  function parseType(value) {
321
539
  if (value === void 0) {
322
540
  return;
323
541
  }
324
- if (value === "ui" || value === "block" || value === "example") {
542
+ if (TYPES.includes(value)) {
325
543
  return value;
326
544
  }
327
545
  throw new Error(
328
- `Invalid --type value "${value}". Expected one of: ui, block, example.`
546
+ `Invalid --type value "${shown(value)}". Expected one of: ${TYPES.join(", ")}.`
329
547
  );
330
548
  }
549
+ function refuseInvalid(names) {
550
+ const valid = [];
551
+ for (const name of names) {
552
+ const refusal = nameRefusal(name);
553
+ if (refusal) {
554
+ console.error(refusal);
555
+ process.exitCode = 1;
556
+ } else {
557
+ valid.push(name);
558
+ }
559
+ }
560
+ return valid;
561
+ }
331
562
  function parseInt10(value, fallback) {
332
563
  if (value === void 0) {
333
564
  return fallback;
334
565
  }
335
566
  const n = Number.parseInt(value, 10);
336
567
  if (Number.isNaN(n)) {
337
- throw new Error(`Expected an integer, got "${value}".`);
568
+ throw new Error(`Expected an integer, got "${shown(value)}".`);
338
569
  }
339
570
  return n;
340
571
  }
@@ -348,24 +579,30 @@ function printUsage2() {
348
579
  );
349
580
  console.log(" search <query> [--type T] [--category C] [--limit N]");
350
581
  console.log(
351
- " Fuzzy search components, blocks, examples"
582
+ " Fuzzy search components, blocks, kits, examples"
352
583
  );
353
584
  console.log(" list [--type T] [--category C] [--limit N] [--offset N]");
354
585
  console.log(
355
- " List items (T = ui|block|example)"
586
+ " List items (T = ui|block|example|kit|style|theme|item)"
587
+ );
588
+ console.log(
589
+ " view <name> [<name>...] Show source of components, blocks, kits"
356
590
  );
357
- console.log(" view <name> [<name>...] Show component source");
358
591
  console.log(
359
592
  " examples <name> Show all demos for a component/block"
360
593
  );
361
594
  console.log(
362
- " docs <name> Fetch /llms.mdx/docs/components/<name>"
595
+ " docs <name> [--type component|block] Fetch /llms.mdx/docs/{components|blocks}/<name>"
363
596
  );
364
597
  console.log(
365
- " audit Print post-install checklist"
598
+ " audit [--theme [css]] [--strict] Post-install checklist, or measure your theme's contrast"
366
599
  );
367
600
  console.log(
368
- " blocks [<filter>] [--category C] List or filter full-page blocks"
601
+ " blocks [<filter>] [--category C] List or filter full-page blocks; an exact block name views it (kits: list --type kit)"
602
+ );
603
+ console.log(" theme <code> [--only theme,font,density]");
604
+ console.log(
605
+ " Install a theme-builder code via shadcn"
369
606
  );
370
607
  console.log("");
371
608
  console.log("Without a verb, launches the MCP stdio server.");
@@ -374,7 +611,7 @@ async function runSearch(args) {
374
611
  const { flags, positional } = parseArgs2(args);
375
612
  if (positional.length === 0) {
376
613
  console.error(
377
- "Usage: keystoneui search <query> [--type ui|block|example] [--category C] [--limit N]"
614
+ "Usage: keystoneui search <query> [--type ui|block|example|kit|hook|style|theme|font|item] [--category C] [--limit N]"
378
615
  );
379
616
  process.exitCode = 1;
380
617
  return;
@@ -414,8 +651,12 @@ async function runView(args) {
414
651
  process.exitCode = 1;
415
652
  return;
416
653
  }
654
+ const names = refuseInvalid(positional);
655
+ if (names.length === 0) {
656
+ return;
657
+ }
417
658
  const config = loadProjectConfig();
418
- const text = await viewComponentTool(config, { names: positional });
659
+ const text = await viewComponentTool(config, { names });
419
660
  console.log(text);
420
661
  }
421
662
  async function runExamples(args) {
@@ -425,34 +666,65 @@ async function runExamples(args) {
425
666
  process.exitCode = 1;
426
667
  return;
427
668
  }
669
+ if (refuseInvalid([positional[0]]).length === 0) {
670
+ return;
671
+ }
428
672
  const config = loadProjectConfig();
429
673
  const text = await getExamplesTool(config, { name: positional[0] });
430
674
  console.log(text);
431
675
  }
432
676
  async function runDocs(args) {
433
- const { positional } = parseArgs2(args);
677
+ const { flags, positional } = parseArgs2(args);
434
678
  if (positional.length === 0) {
435
- console.error("Usage: keystoneui docs <name>");
679
+ console.error("Usage: keystoneui docs <name> [--type component|block]");
436
680
  process.exitCode = 1;
437
681
  return;
438
682
  }
439
683
  const name = positional[0];
440
- const siteUrl = process.env.KEYSTONEUI_URL ?? "https://keystoneui.io";
441
- const url = `${siteUrl}/llms.mdx/docs/components/${name}`;
442
- const response = await fetch(url, {
684
+ if (refuseInvalid([name]).length === 0) {
685
+ return;
686
+ }
687
+ const section = flags.type === "block" ? "blocks" : "components";
688
+ const result = await resolveDocs(loadProjectConfig(), name, section, () => ({
443
689
  headers: { "User-Agent": "keystoneui-cli/0.1" }
444
- });
445
- if (!response.ok) {
690
+ }));
691
+ if (result.kind === "unreachable") {
692
+ throw escapedError(redactUrlInError(result.error, result.url));
693
+ }
694
+ if (result.kind === "status") {
446
695
  console.error(
447
- `Failed to fetch ${url}: ${response.status} ${response.statusText}`
696
+ `Failed to fetch ${shown(displayUrl(result.url))}: ${result.status} ${shown(result.statusText)}`
448
697
  );
449
698
  process.exitCode = 1;
450
699
  return;
451
700
  }
452
- console.log(await response.text());
701
+ console.log(result.text);
453
702
  }
454
- function runAudit() {
455
- console.log(auditChecklistTool());
703
+ function runAudit(args) {
704
+ const { flags } = parseArgs2(args);
705
+ if (!("theme" in flags)) {
706
+ console.log(auditChecklistTool());
707
+ return;
708
+ }
709
+ const file = flags.theme === "true" ? detectProjectContext().tailwindCssFile : flags.theme;
710
+ if (!(file && existsSync3(file))) {
711
+ console.error(
712
+ "Usage: keystoneui audit --theme [path/to/globals.css] [--strict]\nNo CSS file found \u2014 pass the one that holds your :root and .dark tokens."
713
+ );
714
+ process.exitCode = 1;
715
+ return;
716
+ }
717
+ let css;
718
+ try {
719
+ css = readFileSync3(file, "utf-8");
720
+ } catch (error) {
721
+ throw escapedError(error);
722
+ }
723
+ const results = auditTheme(readThemeTokens(css));
724
+ console.log(formatAudit(file, results));
725
+ if (flags.strict === "true" && results.some((r) => r.status === "fail")) {
726
+ process.exitCode = 1;
727
+ }
456
728
  }
457
729
  async function runBlocks(args) {
458
730
  const { flags, positional } = parseArgs2(args);
@@ -474,6 +746,14 @@ async function runBlocks(args) {
474
746
  console.log(text2);
475
747
  return;
476
748
  }
749
+ if (positional.length === 1 && await isBlockName(config, filter)) {
750
+ if (refuseInvalid([filter]).length === 0) {
751
+ return;
752
+ }
753
+ const text2 = await viewComponentTool(config, { names: [filter] });
754
+ console.log(text2);
755
+ return;
756
+ }
477
757
  const text = await searchComponentsTool(config, {
478
758
  query: filter,
479
759
  limit: 20,
@@ -482,6 +762,43 @@ async function runBlocks(args) {
482
762
  });
483
763
  console.log(text);
484
764
  }
765
+ async function isBlockName(config, name) {
766
+ try {
767
+ const { items } = await lookupManifest(config.registry);
768
+ return items.some(
769
+ (item) => item.name === name && item.type === "registry:block"
770
+ );
771
+ } catch {
772
+ return false;
773
+ }
774
+ }
775
+ function runTheme(args) {
776
+ const { flags, positional } = parseArgs2(args);
777
+ const code = positional[0];
778
+ const fields = code ? parseThemeCode(code) : null;
779
+ if (!(code && fields)) {
780
+ console.error(
781
+ "Usage: keystoneui theme <code> [--only theme,font,density]\nCopy a code from https://keystoneui.io/theme-builder (Code panel)."
782
+ );
783
+ process.exitCode = 1;
784
+ return;
785
+ }
786
+ const siteUrl = process.env.KEYSTONEUI_URL ?? "https://keystoneui.io";
787
+ const only = parseThemeParts(flags.only);
788
+ const heading = fields.heading === fields.font ? "" : ` \xB7 heading ${fields.heading}`;
789
+ const density = fields.density === "default" ? "" : ` \xB7 density ${fields.density}`;
790
+ console.log(`Theme ${code}`);
791
+ console.log(
792
+ ` base ${fields.base} \xB7 primary ${fields.primary} \xB7 radius ${fields.radius} \xB7 font ${fields.font}${heading}${density}`
793
+ );
794
+ console.log("");
795
+ console.log("Install (writes the tokens into your global CSS):");
796
+ console.log(
797
+ isCommandSafe(themeInstallUrl(code, siteUrl, only)) ? ` ${themeInstallCommand(code, siteUrl, only)}` : ` (no command: ${shown(displayUrl(siteUrl))} holds a line break or control character)`
798
+ );
799
+ console.log("");
800
+ console.log(`Edit: ${shown(themeBuilderUrl(code, siteUrl))}`);
801
+ }
485
802
  async function runCli(args) {
486
803
  const verb = args[0];
487
804
  const rest = args.slice(1);
@@ -490,7 +807,7 @@ async function runCli(args) {
490
807
  return;
491
808
  }
492
809
  if (!isCliVerb(verb)) {
493
- console.error(`Unknown verb: "${verb}".`);
810
+ console.error(`Unknown verb: "${shown(verb)}".`);
494
811
  console.error("");
495
812
  printUsage2();
496
813
  process.exitCode = 1;
@@ -519,11 +836,14 @@ async function runCli(args) {
519
836
  await runDocs(rest);
520
837
  return;
521
838
  case "audit":
522
- runAudit();
839
+ runAudit(rest);
523
840
  return;
524
841
  case "blocks":
525
842
  await runBlocks(rest);
526
843
  return;
844
+ case "theme":
845
+ runTheme(rest);
846
+ return;
527
847
  default: {
528
848
  const exhaustive = verb;
529
849
  throw new Error(`Unhandled verb: ${exhaustive}`);
@@ -542,6 +862,6 @@ if (isCliVerb(verbCandidate)) {
542
862
  process.exit();
543
863
  }
544
864
  var { StdioServerTransport } = await import("@modelcontextprotocol/sdk/server/stdio.js");
545
- var { server } = await import("./server-5ZV7UIUD.js");
865
+ var { server } = await import("./server-WIAN72HA.js");
546
866
  var transport = new StdioServerTransport();
547
867
  await server.connect(transport);