boardui 0.5.11 → 0.5.12

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 (3) hide show
  1. package/README.md +7 -1
  2. package/dist/index.js +145 -75
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -53,6 +53,10 @@ transitively (utils, icons, other components), writes the source files into
53
53
  your project, and installs any missing npm packages. Run without arguments for
54
54
  an interactive picker.
55
55
 
56
+ Names are forgiving: shadcn/ui's names resolve to the BoardUI item
57
+ (`boardui add dialog sheet` installs `modal` and `drawer`), as do plurals and
58
+ docs-page slugs. An unknown name fails with the closest real ones.
59
+
56
60
  | Option | Description |
57
61
  | --- | --- |
58
62
  | `-a, --all` | Add every component in the registry |
@@ -228,7 +232,9 @@ After a successful `boardui init`, the CLI sends one anonymous event containing
228
232
  the CLI version, detected package manager, and whether `--pro` was used. After a
229
233
  successful `boardui add`, it sends the CLI version, package manager, and the
230
234
  component names explicitly requested by the user. Automatically resolved
231
- dependencies are not included. A random installation ID is stored in the
235
+ dependencies are not included. Each event also says whether a person ran the
236
+ command (`source: "cli"`) or an agent ran it through `boardui mcp`
237
+ (`source: "mcp"`). A random installation ID is stored in the
232
238
  operating system's user config directory so repeat runs can be counted without
233
239
  collecting identity.
234
240
 
package/dist/index.js CHANGED
@@ -678,6 +678,103 @@ async function installMissingDependencies(project, wanted) {
678
678
  }
679
679
  }
680
680
 
681
+ // ../lib/agent/item-names.ts
682
+ function normalizeName(raw) {
683
+ return raw.trim().toLowerCase().replace(/\.tsx?$/, "").replace(/[\s_]+/g, "-").replace(/^@?boardui\//, "");
684
+ }
685
+ function editDistance(a, b) {
686
+ const rows = a.length + 1;
687
+ const cols = b.length + 1;
688
+ const d = Array.from({ length: rows }, (_, i) => {
689
+ const row = new Array(cols).fill(0);
690
+ row[0] = i;
691
+ return row;
692
+ });
693
+ for (let j = 0; j < cols; j++) d[0][j] = j;
694
+ for (let i = 1; i < rows; i++) {
695
+ for (let j = 1; j < cols; j++) {
696
+ d[i][j] = Math.min(
697
+ d[i - 1][j] + 1,
698
+ d[i][j - 1] + 1,
699
+ d[i - 1][j - 1] + (a[i - 1] === b[j - 1] ? 0 : 1)
700
+ );
701
+ }
702
+ }
703
+ return d[rows - 1][cols - 1];
704
+ }
705
+ var UNRELEASED = {
706
+ "agent-orb": '"agent-orb" is not available yet. It is still in progress and not open to public use.',
707
+ orb: "The BoardUI orb component is not available yet. It is still in progress and not open to public use."
708
+ };
709
+ var CURATED_SUGGESTIONS = {
710
+ form: ["input", "select", "checkbox"],
711
+ card: ["stat-cards", "checkbox-card", "auth-card"],
712
+ chart: ["area-chart-card", "line-chart-card", "bar-list-card"],
713
+ alert: ["notification", "toast", "announcement"]
714
+ };
715
+ function docsSlug(url) {
716
+ if (!url) return void 0;
717
+ try {
718
+ return new URL(url).pathname.split("/").filter(Boolean).pop();
719
+ } catch {
720
+ return void 0;
721
+ }
722
+ }
723
+ function buildNameUniverse(free, pro) {
724
+ const freeItems = free?.items ?? [];
725
+ const proItems = pro?.items ?? [];
726
+ const all = /* @__PURE__ */ new Set([...freeItems.map((item) => item.name), ...proItems.map((item) => item.name)]);
727
+ const aliases = /* @__PURE__ */ new Map();
728
+ const add2 = (alias, name) => {
729
+ if (alias && alias !== name && !all.has(alias) && !aliases.has(alias)) aliases.set(alias, name);
730
+ };
731
+ for (const item of freeItems) for (const alias of item.meta?.aliases ?? []) add2(alias, item.name);
732
+ for (const item of proItems) for (const alias of item.aliases ?? []) add2(alias, item.name);
733
+ for (const item of proItems.filter((i) => i.kind === "template")) add2(docsSlug(item.docsUrl), item.name);
734
+ for (const item of proItems) add2(docsSlug(item.docsUrl), item.name);
735
+ for (const item of freeItems) add2(docsSlug(item.meta?.docsUrl), item.name);
736
+ return { all, aliases };
737
+ }
738
+ function lookup(name, universe) {
739
+ return universe.all.has(name) ? name : universe.aliases.get(name);
740
+ }
741
+ function aliasNote(raw, name) {
742
+ return normalizeName(raw) === name ? "" : `"${raw}" is BoardUI's "${name}"; use that name from here on.`;
743
+ }
744
+ function resolveName(raw, universe, listHint = "Call list_components for the exact names.") {
745
+ const n = normalizeName(raw);
746
+ const direct = lookup(n, universe);
747
+ if (direct) return { name: direct };
748
+ const unreleased = UNRELEASED[n];
749
+ if (unreleased) return { error: unreleased };
750
+ const variants = [
751
+ `${n}s`,
752
+ ...n.endsWith("s") ? [n.slice(0, -1)] : [],
753
+ ...n.endsWith("-chart") ? [`${n}-card`] : []
754
+ ];
755
+ for (const variant of variants) {
756
+ const name = lookup(variant, universe);
757
+ if (name) return { name };
758
+ }
759
+ const suggestions = new Set(
760
+ (CURATED_SUGGESTIONS[n] ?? []).filter((name) => universe.all.has(name))
761
+ );
762
+ const scored = [];
763
+ for (const name of universe.all) {
764
+ if (name.includes(n) || n.includes(name)) scored.push({ name, score: 0 });
765
+ else {
766
+ const dist = editDistance(n, name);
767
+ if (dist <= 2) scored.push({ name, score: dist });
768
+ }
769
+ }
770
+ scored.sort((a, b) => a.score - b.score || a.name.localeCompare(b.name));
771
+ for (const entry of scored) suggestions.add(entry.name);
772
+ const hint = suggestions.size ? ` Closest matches: ${[...suggestions].slice(0, 4).join(", ")}.` : "";
773
+ return {
774
+ error: `Unknown component "${raw}".${hint} ${listHint}`
775
+ };
776
+ }
777
+
681
778
  // src/lib/telemetry.ts
682
779
  import { randomUUID } from "crypto";
683
780
  import { existsSync as existsSync5, mkdirSync as mkdirSync3, readFileSync as readFileSync6, writeFileSync as writeFileSync3 } from "fs";
@@ -819,6 +916,29 @@ async function pickComponents() {
819
916
  });
820
917
  return names ?? [];
821
918
  }
919
+ async function resolveRequestedNames(names) {
920
+ let universe;
921
+ try {
922
+ const [free, pro] = await Promise.all([fetchRegistryIndex(), fetchProIndex().catch(() => null)]);
923
+ universe = buildNameUniverse(free, pro);
924
+ } catch {
925
+ return { names, notes: [], errors: [] };
926
+ }
927
+ const resolved = [];
928
+ const notes = [];
929
+ const errors = [];
930
+ for (const raw of names) {
931
+ const result = resolveName(raw, universe, "Run `boardui list` for the exact names.");
932
+ if (result.error !== void 0) {
933
+ errors.push(result.error);
934
+ continue;
935
+ }
936
+ resolved.push(result.name);
937
+ const note = aliasNote(raw, result.name);
938
+ if (note) notes.push(note);
939
+ }
940
+ return { names: [...new Set(resolved)], notes, errors };
941
+ }
822
942
  async function add(components, options) {
823
943
  const project = readProject(process.cwd());
824
944
  checkDirectoryOverride(project.config, options.path ?? options.dir);
@@ -844,8 +964,18 @@ async function add(components, options) {
844
964
  console.log("Nothing to add.");
845
965
  return;
846
966
  }
847
- const requestedComponents = [...new Set(names)];
848
967
  const spinner = ora("Resolving components...").start();
968
+ if (!options.all) {
969
+ const requested = await resolveRequestedNames(names);
970
+ if (requested.errors.length > 0) {
971
+ spinner.fail(requested.errors.join("\n"));
972
+ process.exitCode = 1;
973
+ return;
974
+ }
975
+ for (const note of requested.notes) spinner.info(note).start("Resolving components...");
976
+ names = requested.names;
977
+ }
978
+ const requestedComponents = [...new Set(names)];
849
979
  let items;
850
980
  try {
851
981
  items = await resolveItems(names);
@@ -1249,77 +1379,15 @@ function proIndex() {
1249
1379
  });
1250
1380
  return proIndexPromise;
1251
1381
  }
1252
- function normalizeName(raw) {
1253
- return raw.trim().toLowerCase().replace(/\.tsx?$/, "").replace(/[\s_]+/g, "-").replace(/^@?boardui\//, "");
1254
- }
1255
- function editDistance(a, b) {
1256
- const rows = a.length + 1;
1257
- const cols = b.length + 1;
1258
- const d = Array.from({ length: rows }, (_, i) => {
1259
- const row = new Array(cols).fill(0);
1260
- row[0] = i;
1261
- return row;
1262
- });
1263
- for (let j = 0; j < cols; j++) d[0][j] = j;
1264
- for (let i = 1; i < rows; i++) {
1265
- for (let j = 1; j < cols; j++) {
1266
- d[i][j] = Math.min(
1267
- d[i - 1][j] + 1,
1268
- d[i][j - 1] + 1,
1269
- d[i - 1][j - 1] + (a[i - 1] === b[j - 1] ? 0 : 1)
1270
- );
1271
- }
1272
- }
1273
- return d[rows - 1][cols - 1];
1274
- }
1275
- var UNRELEASED = {
1276
- "agent-orb": '"agent-orb" is not available yet. It is still in progress and not open to public use.',
1277
- orb: "The BoardUI orb component is not available yet. It is still in progress and not open to public use."
1278
- };
1279
- var CURATED_SUGGESTIONS = {
1280
- "text-area": ["textarea"],
1281
- form: ["input", "select", "checkbox"],
1282
- modal: ["settings-modal", "auth-card"],
1283
- dialog: ["settings-modal"],
1284
- card: ["stat-cards", "area-chart-card", "auth-card"],
1285
- toast: ["notification"],
1286
- chart: ["area-chart-card", "line-chart-card", "bar-list-card"]
1287
- };
1288
1382
  async function nameUniverse() {
1289
1383
  const [free, pro] = await Promise.all([freeIndex(), proIndex()]);
1290
- const all = /* @__PURE__ */ new Set([
1291
- ...free.items.map((item) => item.name),
1292
- ...pro.items.map((item) => item.name)
1293
- ]);
1294
- const aliases = /* @__PURE__ */ new Map();
1295
- for (const item of pro.items) {
1296
- const slug = item.docsUrl?.split("/").pop();
1297
- if (slug && slug !== item.name && !all.has(slug)) aliases.set(slug, item.name);
1298
- }
1299
- return { all, aliases };
1384
+ return buildNameUniverse(free, pro);
1300
1385
  }
1301
- function resolveName(raw, universe) {
1302
- const n = normalizeName(raw);
1303
- if (universe.all.has(n)) return { name: n };
1304
- const alias = universe.aliases.get(n);
1305
- if (alias) return { name: alias };
1306
- const unreleased = UNRELEASED[n];
1307
- if (unreleased) return { error: unreleased };
1308
- const suggestions = new Set(CURATED_SUGGESTIONS[n] ?? []);
1309
- const scored = [];
1310
- for (const name of universe.all) {
1311
- if (name.includes(n) || n.includes(name)) scored.push({ name, score: 0 });
1312
- else {
1313
- const dist = editDistance(n, name);
1314
- if (dist <= 2) scored.push({ name, score: dist });
1315
- }
1316
- }
1317
- scored.sort((a, b) => a.score - b.score || a.name.localeCompare(b.name));
1318
- for (const entry of scored) suggestions.add(entry.name);
1319
- const hint = suggestions.size ? ` Closest matches: ${[...suggestions].slice(0, 4).join(", ")}.` : "";
1320
- return {
1321
- error: `Unknown component "${raw}".${hint} Call list_components for the exact names.`
1322
- };
1386
+ function withAliasNote(raw, name, body) {
1387
+ const note = aliasNote(raw, name);
1388
+ return note ? `${note}
1389
+
1390
+ ${body}` : body;
1323
1391
  }
1324
1392
  function text(value) {
1325
1393
  return { content: [{ type: "text", text: value }] };
@@ -1575,10 +1643,10 @@ Public usage example (source requires the license):
1575
1643
  \`\`\`tsx
1576
1644
  ${projectExample(proItem.example, project)}
1577
1645
  \`\`\`` : "";
1578
- return text(proPitch([proItem]) + example);
1646
+ return text(withAliasNote(rawName, name, proPitch([proItem]) + example));
1579
1647
  }
1580
1648
  const item = await fetchRegistryItem(name);
1581
- return text(formatItemDetail(projectItem(item, project), proItem ? "pro" : "free"));
1649
+ return text(withAliasNote(rawName, name, formatItemDetail(projectItem(item, project), proItem ? "pro" : "free")));
1582
1650
  })
1583
1651
  );
1584
1652
  server.registerTool(
@@ -1611,7 +1679,7 @@ ${projectExample(proItem.example, project)}
1611
1679
  } else {
1612
1680
  lines2.push("", "No public example \u2014 see the docs page for a live preview.");
1613
1681
  }
1614
- return text(lines2.join("\n"));
1682
+ return text(withAliasNote(rawName, name, lines2.join("\n")));
1615
1683
  }
1616
1684
  const item = projectItem(await fetchRegistryItem(name), project);
1617
1685
  const lines = [
@@ -1629,7 +1697,7 @@ ${projectExample(proItem.example, project)}
1629
1697
  if (!item.meta?.example && !item.meta?.snippets?.length) {
1630
1698
  lines.push("", "No docs examples for this item \u2014 call get_component for the source.");
1631
1699
  }
1632
- return text(lines.join("\n"));
1700
+ return text(withAliasNote(rawName, name, lines.join("\n")));
1633
1701
  })
1634
1702
  );
1635
1703
  server.registerTool(
@@ -1655,12 +1723,14 @@ ${projectExample(proItem.example, project)}
1655
1723
  const project = loadProject(projectDir);
1656
1724
  const universe = await nameUniverse();
1657
1725
  const pro = await proIndex();
1658
- const resolutions = [...new Set(names)].map((raw) => resolveName(raw, universe));
1726
+ const rawNames = [...new Set(names)];
1727
+ const resolutions = rawNames.map((raw) => resolveName(raw, universe));
1659
1728
  const unknown = resolutions.flatMap((r) => r.error ? [r.error] : []);
1660
1729
  if (unknown.length > 0) {
1661
1730
  return errorText(unknown.join("\n"));
1662
1731
  }
1663
1732
  const requested = [...new Set(resolutions.flatMap((r) => r.name ? [r.name] : []))];
1733
+ const aliasNotes = rawNames.map((raw, i) => aliasNote(raw, resolutions[i].name ?? raw)).filter(Boolean);
1664
1734
  const licensed = getLicense() !== null;
1665
1735
  const lockedPro = licensed ? [] : pro.items.filter((item) => requested.includes(item.name));
1666
1736
  const lockedNames = new Set(lockedPro.map((item) => item.name));
@@ -1720,7 +1790,7 @@ ${projectExample(proItem.example, project)}
1720
1790
  `The globals stylesheet was installed \u2014 make sure the root layout imports it: import "${mappedImport("@/styles/globals.css", project.config)}"; (replaces the default create-next-app globals.css import).`
1721
1791
  );
1722
1792
  }
1723
- let result = lines.join("\n") + aliasWarning(project);
1793
+ let result = [...aliasNotes, ...lines].join("\n") + aliasWarning(project);
1724
1794
  if (lockedPro.length > 0) {
1725
1795
  result += `
1726
1796
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "boardui",
3
- "version": "0.5.11",
3
+ "version": "0.5.12",
4
4
  "description": "Add BoardUI components to your project.",
5
5
  "license": "MIT",
6
6
  "type": "module",