boardui 0.5.0 → 0.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.js +187 -42
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -86,6 +86,10 @@ function readProject(cwd) {
86
86
  );
87
87
  }
88
88
  const pkg = JSON.parse(readFileSync(pkgPath, "utf8"));
89
+ const dependencyVersions = {
90
+ ...pkg.devDependencies ?? {},
91
+ ...pkg.dependencies ?? {}
92
+ };
89
93
  const installedDependencies = /* @__PURE__ */ new Set([
90
94
  ...Object.keys(pkg.dependencies ?? {}),
91
95
  ...Object.keys(pkg.devDependencies ?? {})
@@ -113,7 +117,8 @@ function readProject(cwd) {
113
117
  isNextJs: installedDependencies.has("next"),
114
118
  hasAtAlias,
115
119
  usesSrcDir,
116
- installedDependencies
120
+ installedDependencies,
121
+ dependencyVersions
117
122
  };
118
123
  }
119
124
  function sourceRoot(project) {
@@ -273,11 +278,16 @@ async function fetchJson(url) {
273
278
  let response;
274
279
  try {
275
280
  response = await fetch(url);
276
- } catch (error) {
277
- throw new Error(
278
- `Could not reach the BoardUI registry at ${url}. Check your network connection.`,
279
- { cause: error }
280
- );
281
+ } catch {
282
+ await new Promise((resolve) => setTimeout(resolve, 500));
283
+ try {
284
+ response = await fetch(url);
285
+ } catch (error) {
286
+ throw new Error(
287
+ `Could not reach the BoardUI registry at ${url}. Check your network connection.`,
288
+ { cause: error }
289
+ );
290
+ }
281
291
  }
282
292
  if (!response.ok) {
283
293
  if (response.status === 404) {
@@ -294,7 +304,7 @@ async function fetchProRegistryItem(name) {
294
304
  const license = getLicense();
295
305
  if (!license) {
296
306
  throw new Error(
297
- `"${name}" is not in the public registry. If it's a BoardUI Pro component, run \`boardui login <license-key>\` first (the key is in your Lemon Squeezy receipt).`
307
+ `"${name}" is a BoardUI Pro component. Run \`boardui login <license-key>\` first (the key is in your Lemon Squeezy receipt).`
298
308
  );
299
309
  }
300
310
  let response;
@@ -325,10 +335,18 @@ async function fetchRegistryItem(name) {
325
335
  try {
326
336
  return await fetchJson(`${registryBaseUrl()}/${name}.json`);
327
337
  } catch (error) {
328
- if (error instanceof Error && error.message.startsWith("Not found in the registry")) {
329
- return fetchProRegistryItem(name);
338
+ if (!(error instanceof Error && error.message.startsWith("Not found in the registry"))) {
339
+ throw error;
330
340
  }
331
- throw error;
341
+ let listedAsPro = true;
342
+ try {
343
+ listedAsPro = (await fetchProIndex()).items.some((item) => item.name === name);
344
+ } catch {
345
+ }
346
+ if (!listedAsPro) {
347
+ throw new Error(`"${name}" is not in the BoardUI registry. Check the name with \`boardui list\`.`);
348
+ }
349
+ return fetchProRegistryItem(name);
332
350
  }
333
351
  }
334
352
  async function resolveItems(names) {
@@ -402,12 +420,15 @@ ${block}
402
420
  `);
403
421
  return "appended";
404
422
  }
423
+ function isRootAnchored(relPath) {
424
+ return relPath.startsWith(".") || relPath.startsWith("public/");
425
+ }
405
426
  function collectWrites(items, targetRoot, rootAnchor = targetRoot) {
406
427
  const writesByPath = /* @__PURE__ */ new Map();
407
428
  for (const item of items) {
408
429
  for (const file of item.files) {
409
430
  const relPath = file.target ?? file.path;
410
- const absPath = path3.join(relPath.startsWith(".") ? rootAnchor : targetRoot, relPath);
431
+ const absPath = path3.join(isRootAnchored(relPath) ? rootAnchor : targetRoot, relPath);
411
432
  const pending = writesByPath.get(absPath);
412
433
  if (pending) {
413
434
  if (pending.content !== file.content) {
@@ -438,10 +459,10 @@ function writeFiles(writes, overwrite) {
438
459
  }
439
460
  return report;
440
461
  }
441
- async function downloadAssets(items, targetRoot, overwrite) {
462
+ async function downloadAssets(items, targetRoot, overwrite, rootAnchor = targetRoot) {
442
463
  const report = { fetched: [], skipped: [], failed: [] };
443
464
  for (const asset of items.flatMap((item) => item.assets ?? [])) {
444
- const absPath = path3.join(targetRoot, asset.target);
465
+ const absPath = path3.join(isRootAnchored(asset.target) ? rootAnchor : targetRoot, asset.target);
445
466
  if (existsSync3(absPath) && !overwrite) {
446
467
  report.skipped.push(asset.target);
447
468
  continue;
@@ -464,11 +485,23 @@ function missingDependencies(items, project) {
464
485
  for (const spec of item.dependencies ?? []) {
465
486
  const at = spec.lastIndexOf("@");
466
487
  const pkg = at > 0 ? spec.slice(0, at) : spec;
467
- if (!project.installedDependencies.has(pkg)) wanted.set(pkg, spec);
488
+ const range = at > 0 ? spec.slice(at + 1) : "";
489
+ if (!project.installedDependencies.has(pkg)) {
490
+ wanted.set(pkg, spec);
491
+ continue;
492
+ }
493
+ const have = majorOf(project.dependencyVersions?.[pkg]);
494
+ const need = majorOf(range);
495
+ if (have !== void 0 && need !== void 0 && have !== need) wanted.set(pkg, spec);
468
496
  }
469
497
  }
470
498
  return wanted;
471
499
  }
500
+ function majorOf(range) {
501
+ if (!range) return void 0;
502
+ const match = /^[\^~>=v\s]*(\d+)/.exec(range.trim());
503
+ return match ? Number(match[1]) : void 0;
504
+ }
472
505
  async function installMissingDependencies(project, wanted) {
473
506
  const packages = [...wanted.values()];
474
507
  if (packages.length === 0) return { installed: [] };
@@ -681,7 +714,7 @@ The following files already exist:`));
681
714
  const assetSpinner = ora(
682
715
  `Downloading ${assetCount} template asset${assetCount === 1 ? "" : "s"}...`
683
716
  ).start();
684
- const assets = await downloadAssets(items, targetRoot, Boolean(options.overwrite));
717
+ const assets = await downloadAssets(items, targetRoot, Boolean(options.overwrite), project.cwd);
685
718
  if (assets.failed.length > 0) {
686
719
  assetSpinner.warn(
687
720
  `Downloaded ${assets.fetched.length} asset${assets.fetched.length === 1 ? "" : "s"}; failed: ${assets.failed.join(", ")} \u2014 re-run with --overwrite to retry.`
@@ -693,6 +726,8 @@ The following files already exist:`));
693
726
  }
694
727
  }
695
728
  const wanted = missingDependencies(items, project);
729
+ const missingDev = DEV_DEPS.filter((pkg) => !project.installedDependencies.has(pkg));
730
+ for (const pkg of missingDev) wanted.set(pkg, pkg);
696
731
  if (wanted.size > 0) {
697
732
  const packages = [...wanted.values()];
698
733
  let install = true;
@@ -718,6 +753,22 @@ The following files already exist:`));
718
753
  console.log(pc.dim(`Skipped. Install manually: ${project.packageManager} add ${packages.join(" ")}`));
719
754
  }
720
755
  }
756
+ const shipsAppRoute = items.some(
757
+ (item) => item.files.some((file) => (file.target ?? file.path).startsWith("app/"))
758
+ );
759
+ if (shipsAppRoute && !project.isNextJs) {
760
+ console.log(
761
+ pc.yellow(
762
+ "\nWarning: this component ships an app/ route handler, which only runs in Next.js. It was written, but this project does not depend on next."
763
+ )
764
+ );
765
+ }
766
+ if (missingDev.length > 0) {
767
+ console.log(
768
+ `
769
+ ${pc.bold("Note:")} Tailwind was installed. Make sure a ${pc.cyan("postcss.config.mjs")} loads ${pc.cyan("@tailwindcss/postcss")}, or run ${pc.cyan("npx boardui init")} to set the project up.`
770
+ );
771
+ }
721
772
  const installedGlobals = items.some((item) => item.name === "globals");
722
773
  if (installedGlobals) {
723
774
  console.log(
@@ -805,7 +856,7 @@ async function init(options) {
805
856
  for (const item of items) {
806
857
  for (const file of item.files) {
807
858
  const relPath = file.target ?? file.path;
808
- const absPath = path6.join(relPath.startsWith(".") ? project.cwd : targetRoot, relPath);
859
+ const absPath = path6.join(isRootAnchored(relPath) ? project.cwd : targetRoot, relPath);
809
860
  if (existsSync5(absPath) && !options.overwrite) {
810
861
  console.log(` ${pc2.dim("skipped (exists)")} ${relPath}`);
811
862
  continue;
@@ -933,7 +984,9 @@ Typical flow:
933
984
 
934
985
  Component names are exact \u2014 when unsure, call list_components instead of guessing.
935
986
 
936
- Design rules (always apply when writing UI in a BoardUI project): style with BoardUI's semantic Tailwind tokens, never raw palette classes or hex \u2014 text via text-text-primary/-secondary/-tertiary, surfaces via bg-background-*-default/-hover, borders via border-border-* and border-separator-border, icons via text-foreground-icon-*. Type uses composite utilities (text-title-2-medium, text-headline-medium, text-body-medium, ...) that set size/weight/line-height together \u2014 never rebuild them from text-sm font-medium. Dark mode flips tokens automatically via the .dark class; never hardcode dark: colors. Merge classes with cx() from @/utils/cx; icons from @remixicon/react as component references. init_boardui installs these rules as always-on files (AGENTS.md + .cursor/rules/boardui.mdc) so they survive beyond this session; install_rules adds them to an already initialized project. For deeper always-loaded knowledge (full catalog, theming, page patterns), install_skill writes the BoardUI agent skill into .claude/skills/boardui.
987
+ Design rules (always apply when writing UI in a BoardUI project): style with BoardUI's semantic Tailwind tokens, never raw palette classes or hex \u2014 text via text-text-primary/-secondary/-tertiary, surfaces via bg-background-*-default/-hover, borders via border-border-* and border-separator-border, icons via text-foreground-icon-*. Type uses composite utilities (text-title-2-medium, text-headline-medium, text-body-medium, ...) that set size/weight/line-height together \u2014 never rebuild them from text-sm font-medium. Dark mode flips tokens automatically via the .dark class; never hardcode dark: colors. Merge classes with cx() from @/utils/cx; icons from @remixicon/react as component references. init_boardui installs these rules as always-on files (AGENTS.md + .cursor/rules/boardui.mdc) so they survive beyond this session; install_rules adds them to an already initialized project.
988
+
989
+ Agent skill: BoardUI also ships an agent skill (SKILL.md open standard) carrying deeper always-loaded knowledge \u2014 the full component catalog, theming, page patterns, and the motion language. get_skill answers questions about it (returns SKILL.md and the file list); install_skill writes it into the project's .claude/skills/boardui. For other destinations, relay the CLI: npx boardui@latest skill (project), --global (~/.claude/skills), --client codex (~/.agents/skills, read by Codex and Gemini), --path <dir> (anywhere), --force (update). Docs: https://www.boardui.com/skill
937
990
 
938
991
  Pro: items marked PRO require a one-time BoardUI Pro license (${PRICING_URL}, lifetime updates). If the user wants a pro item and no license is active, relay the pricing link \u2014 and if they already purchased, ask them for the license key from their Lemon Squeezy receipt, then call activate_license with it. After that, pro installs work like free ones.`;
939
992
  var posthog = new PostHog("phc_Cp49ooHFujriAf92MgJgj2spJZ2kyBrJC2uUN8wDRqSV", {
@@ -955,6 +1008,73 @@ function proIndex() {
955
1008
  });
956
1009
  return proIndexPromise;
957
1010
  }
1011
+ function normalizeName(raw) {
1012
+ return raw.trim().toLowerCase().replace(/\.tsx?$/, "").replace(/[\s_]+/g, "-").replace(/^@?boardui\//, "");
1013
+ }
1014
+ function editDistance(a, b) {
1015
+ const rows = a.length + 1;
1016
+ const cols = b.length + 1;
1017
+ const d = Array.from({ length: rows }, (_, i) => {
1018
+ const row = new Array(cols).fill(0);
1019
+ row[0] = i;
1020
+ return row;
1021
+ });
1022
+ for (let j = 0; j < cols; j++) d[0][j] = j;
1023
+ for (let i = 1; i < rows; i++) {
1024
+ for (let j = 1; j < cols; j++) {
1025
+ d[i][j] = Math.min(
1026
+ d[i - 1][j] + 1,
1027
+ d[i][j - 1] + 1,
1028
+ d[i - 1][j - 1] + (a[i - 1] === b[j - 1] ? 0 : 1)
1029
+ );
1030
+ }
1031
+ }
1032
+ return d[rows - 1][cols - 1];
1033
+ }
1034
+ var CURATED_SUGGESTIONS = {
1035
+ textarea: ["input"],
1036
+ "text-area": ["input"],
1037
+ form: ["input", "select", "checkbox"],
1038
+ modal: ["settings-modal", "auth-card"],
1039
+ dialog: ["settings-modal"],
1040
+ card: ["stat-cards", "area-chart-card", "auth-card"],
1041
+ toast: ["notification"],
1042
+ chart: ["area-chart-card", "line-chart-card", "bar-list-card"]
1043
+ };
1044
+ async function nameUniverse() {
1045
+ const [free, pro] = await Promise.all([freeIndex(), proIndex()]);
1046
+ const all = /* @__PURE__ */ new Set([
1047
+ ...free.items.map((item) => item.name),
1048
+ ...pro.items.map((item) => item.name)
1049
+ ]);
1050
+ const aliases = /* @__PURE__ */ new Map();
1051
+ for (const item of pro.items) {
1052
+ const slug = item.docsUrl?.split("/").pop();
1053
+ if (slug && slug !== item.name && !all.has(slug)) aliases.set(slug, item.name);
1054
+ }
1055
+ return { all, aliases };
1056
+ }
1057
+ function resolveName(raw, universe) {
1058
+ const n = normalizeName(raw);
1059
+ if (universe.all.has(n)) return { name: n };
1060
+ const alias = universe.aliases.get(n);
1061
+ if (alias) return { name: alias };
1062
+ const suggestions = new Set(CURATED_SUGGESTIONS[n] ?? []);
1063
+ const scored = [];
1064
+ for (const name of universe.all) {
1065
+ if (name.includes(n) || n.includes(name)) scored.push({ name, score: 0 });
1066
+ else {
1067
+ const dist = editDistance(n, name);
1068
+ if (dist <= 2) scored.push({ name, score: dist });
1069
+ }
1070
+ }
1071
+ scored.sort((a, b) => a.score - b.score || a.name.localeCompare(b.name));
1072
+ for (const entry of scored) suggestions.add(entry.name);
1073
+ const hint = suggestions.size ? ` Closest matches: ${[...suggestions].slice(0, 4).join(", ")}.` : "";
1074
+ return {
1075
+ error: `Unknown component "${raw}".${hint} Call list_components for the exact names.`
1076
+ };
1077
+ }
958
1078
  function text(value) {
959
1079
  return { content: [{ type: "text", text: value }] };
960
1080
  }
@@ -979,7 +1099,7 @@ function loadProject(projectDir) {
979
1099
  return readProject(cwd);
980
1100
  } catch {
981
1101
  throw new Error(
982
- `No package.json found in ${cwd}. Pass projectDir with the absolute path of the user's project root (the directory containing package.json).`
1102
+ `No package.json found in ${cwd}. Pass projectDir with the absolute path of the user's project root (the directory containing package.json). If the directory is a fresh or empty one, scaffold an app there first (e.g. \`npx create-next-app@latest .\`), then call init_boardui again.`
983
1103
  );
984
1104
  }
985
1105
  }
@@ -1081,7 +1201,7 @@ ${INSTRUCTIONS}
1081
1201
 
1082
1202
  Pro license on this machine: ${licensed ? "ACTIVE (pro installs unlocked)" : `none yet \u2014 pro items show a purchase link (${PRICING_URL})`}.
1083
1203
 
1084
- Tools: list_components, get_component, get_usage_examples, install_components, init_boardui, install_rules, install_skill, get_theme, activate_license, license_status, deactivate_license.`
1204
+ Tools: list_components, get_component, get_usage_examples, install_components, init_boardui, install_rules, get_skill, install_skill, get_theme, activate_license, license_status, deactivate_license.`
1085
1205
  );
1086
1206
  })
1087
1207
  );
@@ -1146,8 +1266,11 @@ ${templates.map((item) => `- ${item.name}: ${item.description}`).join("\n")}`
1146
1266
  },
1147
1267
  annotations: { readOnlyHint: true }
1148
1268
  },
1149
- safe(async ({ name }) => {
1150
- const [free, pro] = await Promise.all([freeIndex(), proIndex()]);
1269
+ safe(async ({ name: rawName }) => {
1270
+ const resolved = resolveName(rawName, await nameUniverse());
1271
+ if (resolved.error !== void 0) return errorText(resolved.error);
1272
+ const name = resolved.name;
1273
+ const pro = await proIndex();
1151
1274
  const proItem = pro.items.find((item2) => item2.name === name);
1152
1275
  if (proItem && !getLicense()) {
1153
1276
  const example = proItem.example ? `
@@ -1158,11 +1281,6 @@ ${proItem.example}
1158
1281
  \`\`\`` : "";
1159
1282
  return text(proPitch([proItem]) + example);
1160
1283
  }
1161
- if (!proItem && !free.items.some((item2) => item2.name === name)) {
1162
- return errorText(
1163
- `Unknown component "${name}". Call list_components for the exact names.`
1164
- );
1165
- }
1166
1284
  const item = await fetchRegistryItem(name);
1167
1285
  return text(formatItemDetail(item, proItem ? "pro" : "free"));
1168
1286
  })
@@ -1177,8 +1295,11 @@ ${proItem.example}
1177
1295
  },
1178
1296
  annotations: { readOnlyHint: true }
1179
1297
  },
1180
- safe(async ({ name }) => {
1181
- const [free, pro] = await Promise.all([freeIndex(), proIndex()]);
1298
+ safe(async ({ name: rawName }) => {
1299
+ const resolved = resolveName(rawName, await nameUniverse());
1300
+ if (resolved.error !== void 0) return errorText(resolved.error);
1301
+ const name = resolved.name;
1302
+ const pro = await proIndex();
1182
1303
  const proItem = pro.items.find((item2) => item2.name === name);
1183
1304
  if (proItem) {
1184
1305
  const lines2 = [
@@ -1194,11 +1315,6 @@ ${proItem.example}
1194
1315
  }
1195
1316
  return text(lines2.join("\n"));
1196
1317
  }
1197
- if (!free.items.some((item2) => item2.name === name)) {
1198
- return errorText(
1199
- `Unknown component "${name}". Call list_components for the exact names.`
1200
- );
1201
- }
1202
1318
  const item = await fetchRegistryItem(name);
1203
1319
  const lines = [
1204
1320
  `# ${item.title} (${item.name})`,
@@ -1239,16 +1355,14 @@ ${proItem.example}
1239
1355
  projectDir
1240
1356
  }) => {
1241
1357
  const project = loadProject(projectDir);
1242
- const [free, pro] = await Promise.all([freeIndex(), proIndex()]);
1243
- const requested = [...new Set(names)];
1244
- const unknown = requested.filter(
1245
- (name) => !free.items.some((item) => item.name === name) && !pro.items.some((item) => item.name === name)
1246
- );
1358
+ const universe = await nameUniverse();
1359
+ const pro = await proIndex();
1360
+ const resolutions = [...new Set(names)].map((raw) => resolveName(raw, universe));
1361
+ const unknown = resolutions.flatMap((r) => r.error ? [r.error] : []);
1247
1362
  if (unknown.length > 0) {
1248
- return errorText(
1249
- `Unknown component${unknown.length === 1 ? "" : "s"}: ${unknown.join(", ")}. Call list_components for the exact names.`
1250
- );
1363
+ return errorText(unknown.join("\n"));
1251
1364
  }
1365
+ const requested = [...new Set(resolutions.flatMap((r) => r.name ? [r.name] : []))];
1252
1366
  const licensed = getLicense() !== null;
1253
1367
  const lockedPro = licensed ? [] : pro.items.filter((item) => requested.includes(item.name));
1254
1368
  const lockedNames = new Set(lockedPro.map((item) => item.name));
@@ -1275,7 +1389,7 @@ ${proItem.example}
1275
1389
  }
1276
1390
  const targetRoot = sourceRoot(project);
1277
1391
  const report = writeFiles(collectWrites(items, targetRoot, project.cwd), overwrite);
1278
- const assets = await downloadAssets(items, targetRoot, overwrite);
1392
+ const assets = await downloadAssets(items, targetRoot, overwrite, project.cwd);
1279
1393
  const wanted = missingDependencies(items, project);
1280
1394
  const deps = installDependencies ? await installMissingDependencies(project, wanted) : null;
1281
1395
  const written = report.created.length + report.overwritten.length;
@@ -1423,6 +1537,37 @@ NOT installed \u2014 pro fetch failed for ${proFailure.names.join(", ")}: ${proF
1423
1537
  }
1424
1538
  )
1425
1539
  );
1540
+ server.registerTool(
1541
+ "get_skill",
1542
+ {
1543
+ title: "About the BoardUI agent skill",
1544
+ description: "What the BoardUI agent skill is and what it contains: returns the live SKILL.md (workflow, design rules digest, component selection, gotchas, Pro licensing) plus the bundled reference files with their sizes, the install options for every client, and how updating works. Call this when the user asks about BoardUI skills or wants to read the skill before installing.",
1545
+ annotations: { readOnlyHint: true }
1546
+ },
1547
+ safe(async () => {
1548
+ const items = await resolveItems([SKILL_ITEM_NAME]);
1549
+ const files = items.flatMap((item) => item.files);
1550
+ const skillMd = files.find((file) => file.target === "SKILL.md")?.content ?? "";
1551
+ const listing = files.map((file) => `- ${file.target} (${Math.round(file.content.length / 1024)} KB)`).join("\n");
1552
+ return text(
1553
+ `The BoardUI agent skill (SKILL.md open standard) gives skill-capable agents always-loaded BoardUI knowledge; the MCP server stays the on-demand companion for live source and installs.
1554
+
1555
+ Files in the skill:
1556
+ ${listing}
1557
+
1558
+ Install options:
1559
+ - This project via MCP: call install_skill (writes .claude/skills/boardui; overwrite updates).
1560
+ - CLI: npx boardui@latest skill \u2014 flags: --global (~/.claude/skills), --client codex (~/.agents/skills, read by Codex and Gemini), --path <dir> (any client), --force (update in place).
1561
+ - Skills load when a session starts, so restart the agent or open a fresh chat after installing.
1562
+
1563
+ Docs: https://www.boardui.com/skill
1564
+
1565
+ --- SKILL.md (live) ---
1566
+
1567
+ ${skillMd}`
1568
+ );
1569
+ })
1570
+ );
1426
1571
  server.registerTool(
1427
1572
  "install_skill",
1428
1573
  {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "boardui",
3
- "version": "0.5.0",
3
+ "version": "0.5.2",
4
4
  "description": "Add BoardUI components to your project.",
5
5
  "license": "MIT",
6
6
  "type": "module",