@collectui/cli 0.2.19 → 0.2.21

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
@@ -47,9 +47,8 @@ collectui login --token dpat_... --json # 或显式传入
47
47
  ## 看账户与库
48
48
 
49
49
  ```bash
50
- collectui whoami # 账户、按站权限、绑定 key、可下仓库、订单
51
- collectui libs # 全库目录 + 你是否拥有 + CLI/MCP key 状态
52
- collectui libs --json # Agent 用
50
+ collectui whoami # 我是谁 + 我的库:账户信息、每个库是否拥有、CLI/MCP key 状态
51
+ collectui whoami --json # Agent 用(account + sites + keys 脱敏 + libraries)
53
52
  ```
54
53
 
55
54
  ## 一键配置到项目
@@ -137,7 +136,7 @@ Dash MCP 端点:`https://dash.collectui.pro/api/mcp`,Bearer PAT。工具:
137
136
 
138
137
  ```bash
139
138
  # 所有命令都支持 --json:stdout 逐行 JSON event,最后一条是 result
140
- collectui libs --json
139
+ collectui whoami --json
141
140
  collectui init /tmp/app --libs all --yes --no-install --json
142
141
  collectui configure . --libs all --yes --json
143
142
  collectui doctor --json
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@collectui/cli",
3
- "version": "0.2.19",
4
- "description": "One CLI for every shadcn library on CollectUI Dash \u2014 login once, configure registries & MCP, scaffold agent-ready projects.",
3
+ "version": "0.2.21",
4
+ "description": "One CLI for every shadcn library on CollectUI Dash — login once, configure registries & MCP, scaffold agent-ready projects.",
5
5
  "license": "MIT",
6
6
  "type": "module",
7
7
  "bin": {
package/src/catalog.mjs CHANGED
@@ -421,6 +421,7 @@ export async function fetchCatalog({ reporter } = {}) {
421
421
  timeout: 8_000,
422
422
  retries: 1,
423
423
  reporter,
424
+ spinner: "Loading the library catalog from Dash…",
424
425
  }).catch((error) => {
425
426
  reporter?.info?.(`Catalog endpoint unavailable (${error.message}); using built-in snapshot.`);
426
427
  return null;
package/src/cli.mjs CHANGED
@@ -19,7 +19,6 @@ import { ensureCatalog } from "./catalog.mjs";
19
19
  import { showBanner } from "./banner.mjs";
20
20
  import { loginCmd, logoutCmd } from "./commands/login.mjs";
21
21
  import { whoamiCmd } from "./commands/whoami.mjs";
22
- import { libsCmd } from "./commands/libs.mjs";
23
22
  import { initCmd } from "./commands/init.mjs";
24
23
  import { configureCmd } from "./commands/configure.mjs";
25
24
  import { addCmd } from "./commands/add.mjs";
@@ -37,8 +36,7 @@ Usage:
37
36
  Commands:
38
37
  login Authorize CollectUI CLI in your browser (OAuth-style)
39
38
  logout Remove the saved PAT
40
- whoami, me Show account, libraries, bound keys and repos
41
- libs List every library, ownership and key status
39
+ whoami, me Who you are + your libraries (ownership, CLI/MCP key status)
42
40
  init [dir] Scaffold a fresh shadcn project and configure libraries (no dir: OS temp dir)
43
41
  configure [dir] Configure an existing shadcn project
44
42
  add <lib> <comp...> Install components with the library's channel
@@ -78,7 +76,7 @@ Global options:
78
76
 
79
77
  Examples:
80
78
  cui login
81
- cui libs --json
79
+ cui whoami --json
82
80
  cui init --libs reui,arc --yes --no-install # fresh verify project under the OS temp dir
83
81
  cui init /tmp/my-app --libs all --yes --no-install
84
82
  cui configure . --libs all --dry-run
@@ -98,8 +96,8 @@ Environment:
98
96
  const COMMANDS = {
99
97
  login: { run: loginCmd, aliases: [] },
100
98
  logout: { run: logoutCmd, aliases: [] },
101
- whoami: { run: whoamiCmd, aliases: ["me"] },
102
- libs: { run: libsCmd, aliases: ["list"] },
99
+ // libs / list:已并入 whoami 的旧命令名,保留为别名——老脚本、用户项目里已装的 skill 不至于 Unknown command
100
+ whoami: { run: whoamiCmd, aliases: ["me", "libs", "list"], parallel: true },
103
101
  init: { run: initCmd, aliases: ["new"] },
104
102
  configure: { run: configureCmd, aliases: ["config", "setup"] },
105
103
  add: { run: addCmd, aliases: ["install"] },
@@ -118,8 +116,12 @@ function findCommand(name) {
118
116
  return null;
119
117
  }
120
118
 
121
- /** 纯本地/纯账号命令不拉动态目录(省一次网络等待)。 */
122
- const CATALOG_SKIP = new Set(["login", "logout", "whoami", "update"]);
119
+ /**
120
+ * 纯本地/纯账号命令不拉动态目录(省一次网络等待):dash 子命令全是 Dash MCP 调用、
121
+ * skill 只落一个文件,都读不到目录。whoami 标了 parallel——入口不等目录,命令里把
122
+ * 目录与账号两请求同 tick 并行发出(谁慢等谁,省掉串行那一趟)。
123
+ */
124
+ const CATALOG_SKIP = new Set(["login", "logout", "update", "dash", "skill"]);
123
125
 
124
126
  function printHelp() {
125
127
  process.stdout.write(HELP);
@@ -169,20 +171,24 @@ async function main() {
169
171
  if (token) reporter.addSecrets([token]);
170
172
 
171
173
  showBanner(reporter); // 开机画面:任何子命令(headless/--version/help 已在前面分流)
172
- // 动态目录(Dash GET /api/libs):新上库自动包含、停用站自动剔除;失败降级
173
- // 内置快照(目录可用性优先)——与更新检查互不影响
174
- if (!CATALOG_SKIP.has(name)) await ensureCatalog({ reporter });
175
- // 更新检查:与命令并行即时异步查一次 npm(TTY 才查),有新版打一行提醒;
176
- // 手动 update 命令自身不触发(避免与前台安装并发写全局目录)
174
+ // 更新检查最先出发:与目录/账号请求并行,命令收尾时多半已查完(少等收尾那 1 秒)。
175
+ // TTY 才查,有新版打一行提醒;手动 update 命令自身不触发(避免与前台安装并发写全局目录)
177
176
  const updateNotice =
178
177
  name !== "update" && name !== "upgrade" ? startBackgroundUpdate(reporter) : null;
178
+ // 动态目录(Dash GET /api/libs):新上库自动包含、停用站自动剔除;失败降级
179
+ // 内置快照(目录可用性优先)——与更新检查互不影响
180
+ if (!CATALOG_SKIP.has(name) && !command.parallel) await ensureCatalog({ reporter });
179
181
  const race = (p, ms) => Promise.race([p, new Promise((r) => setTimeout(r, ms))]);
180
182
  const settleUpdate = updateNotice
181
183
  ? () => race(updateNotice.done, 1_000).catch(() => {})
182
184
  : () => Promise.resolve();
183
185
 
184
- await command.run(flags, rest, reporter);
185
- await settleUpdate();
186
+ try {
187
+ await command.run(flags, rest, reporter, { invokedAs: name });
188
+ await settleUpdate();
189
+ } finally {
190
+ reporter.settleLoading(); // 异常退出也不把 spinner 行 / 藏起的光标留在终端
191
+ }
186
192
  }
187
193
 
188
194
  /** 命令完成后 flush stdout 并退出:一次性进程不留后台尾巴(callback server 的
@@ -21,7 +21,7 @@ export async function addCmd(flags, rest, reporter) {
21
21
  }
22
22
 
23
23
  const lib = libBySlug(libSlug);
24
- if (!lib) throw usageError(`Unknown library "${libSlug}".`, { hint: "Run `cui libs`." });
24
+ if (!lib) throw usageError(`Unknown library "${libSlug}".`, { hint: "Run `cui whoami`." });
25
25
 
26
26
  const detected = detectProjectRoot(flags.cwd ? resolve(String(flags.cwd)) : process.cwd());
27
27
  const root = detected.root;
@@ -9,7 +9,7 @@ import {
9
9
  } from "../catalog.mjs";
10
10
  import { resolveToken } from "../config.mjs";
11
11
  import { authError, usageError } from "../errors.mjs";
12
- import { fetchMe } from "../dash.mjs";
12
+ import { fetchAccount } from "../dash.mjs";
13
13
 
14
14
  export function requireToken(flags, reporter) {
15
15
  const token = resolveToken(flags);
@@ -22,6 +22,10 @@ export function requireToken(flags, reporter) {
22
22
  return token;
23
23
  }
24
24
 
25
+ /**
26
+ * 账号数据 { account, sites, keys }——走 CLI 专用端点(不触发 /api/me 的全量聚合)。
27
+ * required=false:未登录回 null(调用方降级);默认未登录直接报错退出 3。
28
+ */
25
29
  export async function loadMe(flags, reporter, { required = true } = {}) {
26
30
  const token = resolveToken(flags);
27
31
  if (!token) {
@@ -29,7 +33,7 @@ export async function loadMe(flags, reporter, { required = true } = {}) {
29
33
  return null;
30
34
  }
31
35
  reporter?.addSecrets([token]);
32
- const me = await fetchMe(token, { reporter });
36
+ const me = await fetchAccount(token, { reporter });
33
37
  reporter?.addSecrets(
34
38
  (me.keys ?? []).map((k) => k.key).filter(Boolean)
35
39
  );
@@ -3,7 +3,7 @@ import { join, resolve } from "node:path";
3
3
  import { activeCatalog, ownedLibs, registryUrl, resolveLibKeys } from "../catalog.mjs";
4
4
  import { registryUrl as registryBase, resolveToken, tokenSource } from "../config.mjs";
5
5
  import { httpRequest } from "../http.mjs";
6
- import { dashMcpTools, fetchMe } from "../dash.mjs";
6
+ import { dashMcpTools, fetchAccount } from "../dash.mjs";
7
7
  import { detectProjectRoot, parseEnvText } from "../project.mjs";
8
8
  import { formatTable } from "../report.mjs";
9
9
 
@@ -26,7 +26,7 @@ export async function doctorCmd(flags, rest, reporter) {
26
26
  let me = null;
27
27
  if (token) {
28
28
  try {
29
- me = await fetchMe(token, { reporter });
29
+ me = await fetchAccount(token, { reporter });
30
30
  add("account", "ok", `${me.account?.username ?? me.account?.uid} · ${me.sites?.length ?? 0} libraries`);
31
31
  } catch (error) {
32
32
  add("account", "fail", error.message);
@@ -93,6 +93,7 @@ export async function doctorCmd(flags, rest, reporter) {
93
93
  headers: probe.headers,
94
94
  reporter,
95
95
  label: `registry probe ${lib.site}`,
96
+ spinner: `Probing the ${lib.site} registry…`,
96
97
  timeout: 20_000,
97
98
  retries: 1,
98
99
  });
@@ -2,7 +2,15 @@ import { resolve } from "node:path";
2
2
  import { ChangeSet } from "../changes.mjs";
3
3
  import { dashUrl, registryUrl } from "../config.mjs";
4
4
  import { usageError } from "../errors.mjs";
5
- import { addMeSecrets, dashMcpTool, dashMcpTools, dashMe, fetchMe, formatMeHuman, formatTools } from "../dash.mjs";
5
+ import {
6
+ addMeSecrets,
7
+ dashMcpTool,
8
+ dashMcpTools,
9
+ dashMe,
10
+ fetchAccount,
11
+ formatMeHuman,
12
+ formatTools,
13
+ } from "../dash.mjs";
6
14
  import { buildMcpEntries, describeEntries, planMcpConfig, renderEntry } from "../mcp.mjs";
7
15
  import { requireToken, selectLibs } from "./common.mjs";
8
16
  import { resolveClients } from "./setup.mjs";
@@ -27,7 +35,7 @@ export async function mcpCmd(flags, rest, reporter) {
27
35
 
28
36
  async function mcpConfigCommand(sub, flags, rest, reporter) {
29
37
  const token = requireToken(flags, reporter);
30
- const me = await fetchMe(token, { reporter });
38
+ const me = await fetchAccount(token, { reporter });
31
39
  reporter.addSecrets((me.keys ?? []).map((k) => k.key).filter(Boolean));
32
40
  const { units } = await selectLibs({ flags, me, reporter });
33
41
  const clients = resolveClients(flags);
@@ -6,7 +6,7 @@ import { CLI_VERSION } from "../version.mjs";
6
6
  import { dashUrl, registryUrl, resolveToken } from "../config.mjs";
7
7
  import { CliError } from "../errors.mjs";
8
8
  import { login } from "../login.mjs";
9
- import { fetchMe } from "../dash.mjs";
9
+ import { fetchAccount } from "../dash.mjs";
10
10
  import { planMcpConfig, describeEntries } from "../mcp.mjs";
11
11
  import { detectPackageManager, planProjectConfig } from "../project.mjs";
12
12
  import { planManifest, planScaffold } from "../scaffold.mjs";
@@ -77,14 +77,14 @@ export async function runSetup({ flags, rest = [], reporter, mode }) {
77
77
 
78
78
  let me;
79
79
  try {
80
- me = await fetchMe(token, { reporter });
80
+ me = await fetchAccount(token, { reporter });
81
81
  } catch (error) {
82
82
  if (error?.exitCode === 3 && !reporter.headless) {
83
83
  reporter.warn("Saved PAT was rejected — starting login again.");
84
84
  const session = await login({ reporter });
85
85
  token = session.token;
86
86
  reporter.addSecrets([token]);
87
- me = session.me ?? (await fetchMe(token, { reporter }));
87
+ me = session.me ?? (await fetchAccount(token, { reporter }));
88
88
  } else {
89
89
  throw error;
90
90
  }
@@ -9,7 +9,7 @@ import { startSpin } from "../report.mjs";
9
9
  */
10
10
  export async function updateCmd(flags, _rest, reporter) {
11
11
  reporter.step(1, 2, "Checking npm for the latest @collectui/cli");
12
- const latest = await fetchLatestVersion();
12
+ const latest = await fetchLatestVersion({ reporter });
13
13
  const cmp = compareVersions(latest, CLI_VERSION);
14
14
  const summary = { current: CLI_VERSION, latest, updateAvailable: cmp > 0 };
15
15
 
@@ -1,17 +1,127 @@
1
- import { formatMeHuman, maskKey } from "../dash.mjs";
2
- import { loadMe } from "./common.mjs";
1
+ import {
2
+ activeCatalog,
3
+ ensureCatalog,
4
+ ownedLibs,
5
+ resolveLibKeys,
6
+ retiredSlugs,
7
+ } from "../catalog.mjs";
8
+ import { formatAccountHuman, maskKey } from "../dash.mjs";
9
+ import { resolveToken } from "../config.mjs";
10
+ import { formatTable } from "../report.mjs";
11
+ import { loadMe, requireToken } from "./common.mjs";
12
+
13
+ /**
14
+ * cui whoami 我是谁 + 我的库:账户段(账户名 / uid / 注册时间 / 徽章)+ 全库表
15
+ * SITE · CLI KEY · MCP KEY(MCP 值区分专属 bound / 通用 generic)
16
+ * cui whoami --verbose 宽表(OWNED / REGISTRIES / MCP SERVER 等内部细节)
17
+ * 未拥有的行两列均为 "-"。
18
+ *
19
+ * 2026-12-01 起 `libs` 并入本命令(libs / list 保留为别名)。数据面是 CLI 专用端点
20
+ * GET /api/account(账户 + 按站授权 + 绑定 key)+ 动态目录 GET /api/libs,两者并行。
21
+ * 可下仓库 / 订单 / HP 凭据一律不展示(全量聚合看 `cui dash me`)。
22
+ *
23
+ * 别名之间只差一处(兼容两边的旧契约):以 whoami / me 调用且未登录 → 报错退出 3
24
+ * (whoami 的语义是校验登录态);以旧命令名 libs / list 调用且未登录 → 照旧给纯目录表
25
+ * + 登录提示,退出 0。
26
+ */
27
+ const CATALOG_ONLY_ALIASES = new Set(["libs", "list"]);
28
+
29
+ export async function whoamiCmd(flags, rest, reporter, { invokedAs } = {}) {
30
+ const strict = !CATALOG_ONLY_ALIASES.has(invokedAs);
31
+ if (strict && !resolveToken(flags)) requireToken(flags, reporter); // 未登录:不等目录,立刻报错
32
+
33
+ // 入口没等目录(COMMANDS.whoami.parallel):目录、账号两请求这里同 tick 并行发出,谁慢等谁。
34
+ // 命令自己的区间排最前 → 两个请求在途期间同一行转到底(未登录时只拉目录,文案如实)。
35
+ const loggedIn = Boolean(resolveToken(flags));
36
+ const done = reporter.activity(
37
+ loggedIn ? "Loading your account from Dash…" : "Loading the library catalog from Dash…"
38
+ );
39
+ const [, outcome] = await Promise.all([
40
+ ensureCatalog({ reporter }),
41
+ loadMe(flags, reporter, { required: false }).then(
42
+ (me) => ({ me }),
43
+ (error) => ({ error })
44
+ ),
45
+ ]);
46
+ const me = outcome.me ?? null;
47
+ done();
48
+ if (outcome.error) {
49
+ if (strict) throw outcome.error;
50
+ reporter.warn(`Could not load account (${outcome.error.message}); showing catalog only.`);
51
+ }
52
+
53
+ const owned = me ? new Set(ownedLibs(me).map((lib) => lib.site)) : null;
54
+ // 账号里拥有但不属于 shadcn registry 体系的库(自带独立安装器,如 threeui/
55
+ // heroui v3/aura)——本 CLI 管不到,但必须点名说明,不然用户以为少了。
56
+ // 停用站(Dash sites 表 retired,如 hero v2 / io)不再点名。
57
+ const LIBS = activeCatalog().libs;
58
+ const knownSites = new Set(LIBS.map((lib) => lib.site));
59
+ const retired = retiredSlugs();
60
+ const extraOwned = me
61
+ ? [
62
+ ...new Set([
63
+ ...(me.sites ?? []).map((s) => s.slug),
64
+ ...(me.keys ?? []).map((k) => k.site).filter(Boolean),
65
+ ]),
66
+ ].filter((slug) => !knownSites.has(slug) && !retired.has(slug))
67
+ : [];
68
+ const rows = [];
69
+
70
+ for (const lib of LIBS) {
71
+ const keys = me ? resolveLibKeys(lib, me) : { cli: null, mcp: null };
72
+ const isOwned = owned ? owned.has(lib.site) : null;
73
+ rows.push({
74
+ site: lib.site,
75
+ cli: isOwned === false ? "-" : keys.cli ? "bound" : "-",
76
+ mcp: isOwned === false ? "-" : keys.mcp ? "bound" : lib.mcp ? "-" : "generic",
77
+ name: lib.siteName,
78
+ owned: isOwned === null ? "?" : isOwned ? "yes" : "no",
79
+ registries: (lib.registries ?? []).map((r) => r.scope).join(", ") || "-",
80
+ mcpServer: lib.mcp ?? (lib.shadcnUiMcp ? "shadcn (generic)" : "-"),
81
+ });
82
+ }
3
83
 
4
- export async function whoamiCmd(flags, rest, reporter) {
5
- const me = await loadMe(flags, reporter);
6
84
  if (reporter.json) {
7
85
  reporter.result({
8
- account: me.account,
9
- sites: me.sites,
10
- keys: (me.keys ?? []).map((k) => ({ ...k, key: maskKey(k.key) })),
11
- repos: me.repos,
12
- orders: me.orders,
86
+ account: me?.account ?? null,
87
+ sites: me?.sites ?? [],
88
+ keys: (me?.keys ?? []).map((k) => ({ ...k, key: maskKey(k.key) })),
89
+ libraries: rows,
13
90
  });
14
91
  return;
15
92
  }
16
- reporter.note("Account", formatMeHuman(me));
93
+
94
+ const verbose = Boolean(flags.verbose || flags.v);
95
+ const table = formatTable(
96
+ rows,
97
+ verbose
98
+ ? [
99
+ { key: "site", header: "SITE" },
100
+ { key: "name", header: "LIBRARY" },
101
+ { key: "owned", header: "OWNED" },
102
+ { key: "cli", header: "CLI KEY" },
103
+ { key: "mcp", header: "MCP KEY" },
104
+ { key: "registries", header: "REGISTRIES" },
105
+ { key: "mcpServer", header: "MCP SERVER" },
106
+ ]
107
+ : [
108
+ { key: "site", header: "SITE" },
109
+ { key: "cli", header: "CLI KEY" },
110
+ { key: "mcp", header: "MCP KEY" },
111
+ ]
112
+ );
113
+ reporter.note(
114
+ me ? "Account" : "Catalog (not logged in)",
115
+ [me ? formatAccountHuman(me.account) : null, table].filter(Boolean).join("\n\n")
116
+ );
117
+ if (extraOwned.length) {
118
+ reporter.info(
119
+ `Your account also owns ${extraOwned.length} librar${extraOwned.length === 1 ? "y" : "ies"} ` +
120
+ `outside the shadcn registry system (${extraOwned.join(", ")}) — ` +
121
+ `they install via their own tooling and are not managed by this CLI.`
122
+ );
123
+ }
124
+ if (!me) {
125
+ reporter.info("Run `cui login` to see which libraries your account owns and to bind keys.");
126
+ }
17
127
  }
package/src/dash.mjs CHANGED
@@ -1,15 +1,57 @@
1
1
  import { dashUrl } from "./config.mjs";
2
2
  import { jsonRequest, mcpCall, toolResult } from "./http.mjs";
3
3
 
4
- /** Dash REST 聚合(与 dash MCP me 工具同源,见 apps/user-dashboard/lib/agent-api.ts)。 */
4
+ /**
5
+ * Dash 全量聚合(/api/me:站点、key、可下仓库、HP 凭据、订单)。
6
+ * CLI 里只有 `cui dash me` 在 Dash MCP 不可用时拿它兜底——其余命令一律走下面的
7
+ * fetchAccount(专用端点),全量聚合里 CLI 用不到的部分服务端就不去查。
8
+ */
5
9
  export async function fetchMe(token, { reporter } = {}) {
6
10
  return jsonRequest(`${dashUrl()}/api/me`, {
7
11
  token,
8
12
  reporter,
9
13
  label: "dash /api/me",
14
+ spinner: "Loading your account from Dash…",
10
15
  });
11
16
  }
12
17
 
18
+ /**
19
+ * CLI 专用数据面 GET /api/account(2026-12-01):{ account, sites, keys }——账户本体 +
20
+ * 按站授权 + 绑定 key。CLI 全部命令(whoami / init / configure / add / mcp / doctor /
21
+ * login)要的只有这些;可下仓库、订单、HP 凭据一个都用不到。
22
+ * 兼容旧 Dash:没有该路由(404),或只有首版形状(仅 account)→ 退回 /api/me 取同名切片。
23
+ */
24
+ export async function fetchAccount(token, { reporter } = {}) {
25
+ const request = (path) =>
26
+ jsonRequest(`${dashUrl()}${path}`, {
27
+ token,
28
+ reporter,
29
+ label: `dash ${path}`,
30
+ spinner: "Loading your account from Dash…",
31
+ });
32
+ let data = null;
33
+ try {
34
+ const light = await request("/api/account");
35
+ if (Array.isArray(light?.sites) && Array.isArray(light?.keys)) data = light;
36
+ } catch (error) {
37
+ if (error?.status !== 404) throw error;
38
+ }
39
+ if (!data) {
40
+ const me = await request("/api/me");
41
+ data = { account: me?.account ?? null, sites: me?.sites ?? [], keys: me?.keys ?? [] };
42
+ }
43
+ return data;
44
+ }
45
+
46
+ /** `cui whoami` 的账户段:账户名 + uid、注册时间、徽章——最基本的账户信息,到此为止。 */
47
+ export function formatAccountHuman(account) {
48
+ if (!account) return "No account data.";
49
+ const lines = [`Account: ${account.username ?? "(unknown)"} uid=${account.uid ?? "?"}`];
50
+ if (account.createdAt) lines.push(`Created: ${account.createdAt}`);
51
+ if (account.badges?.length) lines.push(`Badges: ${account.badges.join(", ")}`);
52
+ return lines.join("\n");
53
+ }
54
+
13
55
  /** Dash MCP:stateless JSON-RPC,直接 tools/list 或 tools/call。 */
14
56
  export async function dashMcpTools(token, { reporter } = {}) {
15
57
  const result = await mcpCall({
package/src/errors.mjs CHANGED
@@ -1,10 +1,12 @@
1
- /** CLI 统一错误:message 给用户看,code 决定退出码(1 通用 / 2 用法 / 3 认证)。 */
1
+ /** CLI 统一错误:message 给用户看,code 决定退出码(1 通用 / 2 用法 / 3 认证);
2
+ * status 是 HTTP 状态(网络请求失败时带,调用方按它分支)。 */
2
3
  export class CliError extends Error {
3
- constructor(message, { code = 1, hint } = {}) {
4
+ constructor(message, { code = 1, hint, status } = {}) {
4
5
  super(message);
5
6
  this.name = "CliError";
6
7
  this.exitCode = code;
7
8
  this.hint = hint;
9
+ this.status = status;
8
10
  }
9
11
  }
10
12
 
package/src/http.mjs CHANGED
@@ -10,8 +10,13 @@ function shouldRetry(status) {
10
10
  }
11
11
 
12
12
  /**
13
- * 统一 HTTP 入口:超时、退避重试、请求/响应日志(transparency)。
13
+ * 统一 HTTP 入口:超时、退避重试、请求/响应日志(transparency)、加载态。
14
14
  * 只对幂等方法(GET/HEAD)自动重试;POST 由调用方决定(MCP tools/call 重试可能重复提交)。
15
+ *
16
+ * 加载态:带 reporter 的请求在途即转 spinner(首帧与触发它的那行输出同 tick 落屏,
17
+ * 响应到了才清行,重试退避期间不断拍)——「等网络」永远有反馈,命令里不用各写各的。
18
+ * spinner 选项是在途文案(缺省 Loading…)。不传 reporter 的调用(后台更新检查)不转:
19
+ * 它与命令并行,会在 clack 提示框或输出中间乱入。
15
20
  */
16
21
  export async function httpRequest(url, options = {}) {
17
22
  const {
@@ -24,6 +29,7 @@ export async function httpRequest(url, options = {}) {
24
29
  retryUnsafe = false,
25
30
  reporter,
26
31
  label,
32
+ spinner,
27
33
  } = options;
28
34
 
29
35
  const finalHeaders = {
@@ -39,56 +45,61 @@ export async function httpRequest(url, options = {}) {
39
45
  const canRetry = retryUnsafe || method === "GET" || method === "HEAD";
40
46
  const attempts = canRetry ? retries + 1 : 1;
41
47
  let lastError;
48
+ const release = reporter?.activity?.(spinner ?? "Loading…") ?? (() => {});
42
49
 
43
- for (let attempt = 1; attempt <= attempts; attempt += 1) {
44
- const started = Date.now();
45
- reporter?.http?.({ phase: "request", method, url, label, attempt, max: attempts });
46
- let res;
47
- try {
48
- res = await fetch(url, {
50
+ try {
51
+ for (let attempt = 1; attempt <= attempts; attempt += 1) {
52
+ const started = Date.now();
53
+ reporter?.http?.({ phase: "request", method, url, label, attempt, max: attempts });
54
+ let res;
55
+ try {
56
+ res = await fetch(url, {
57
+ method,
58
+ headers: finalHeaders,
59
+ body,
60
+ signal: AbortSignal.timeout(timeout),
61
+ redirect: "follow",
62
+ });
63
+ } catch (error) {
64
+ const ms = Date.now() - started;
65
+ reporter?.http?.({ phase: "error", method, url, label, ms, error: error.message });
66
+ lastError = error;
67
+ if (attempt < attempts) {
68
+ await sleep(500 * attempt + Math.floor(Math.random() * 250));
69
+ continue;
70
+ }
71
+ throw new CliError(`Network request failed: ${method} ${url} — ${error.message}`, {
72
+ hint: "Check your network / proxy, then retry. Dash might be temporarily unreachable.",
73
+ });
74
+ }
75
+
76
+ const text = await res.text();
77
+ const ms = Date.now() - started;
78
+ reporter?.http?.({
79
+ phase: "response",
49
80
  method,
50
- headers: finalHeaders,
51
- body,
52
- signal: AbortSignal.timeout(timeout),
53
- redirect: "follow",
81
+ url,
82
+ label,
83
+ status: res.status,
84
+ ms,
85
+ bytes: text.length,
86
+ attempt,
54
87
  });
55
- } catch (error) {
56
- const ms = Date.now() - started;
57
- reporter?.http?.({ phase: "error", method, url, label, ms, error: error.message });
58
- lastError = error;
59
- if (attempt < attempts) {
88
+
89
+ if (res.ok) return { res, text };
90
+
91
+ if (attempt < attempts && shouldRetry(res.status)) {
60
92
  await sleep(500 * attempt + Math.floor(Math.random() * 250));
61
93
  continue;
62
94
  }
63
- throw new CliError(`Network request failed: ${method} ${url} — ${error.message}`, {
64
- hint: "Check your network / proxy, then retry. Dash might be temporarily unreachable.",
65
- });
66
- }
67
-
68
- const text = await res.text();
69
- const ms = Date.now() - started;
70
- reporter?.http?.({
71
- phase: "response",
72
- method,
73
- url,
74
- label,
75
- status: res.status,
76
- ms,
77
- bytes: text.length,
78
- attempt,
79
- });
80
-
81
- if (res.ok) return { res, text };
82
95
 
83
- if (attempt < attempts && shouldRetry(res.status)) {
84
- await sleep(500 * attempt + Math.floor(Math.random() * 250));
85
- continue;
96
+ return { res, text, error: true };
86
97
  }
87
98
 
88
- return { res, text, error: true };
99
+ throw new CliError(`Network request failed: ${method} ${url} — ${lastError?.message ?? "unknown error"}`);
100
+ } finally {
101
+ release();
89
102
  }
90
-
91
- throw new CliError(`Network request failed: ${method} ${url} — ${lastError?.message ?? "unknown error"}`);
92
103
  }
93
104
 
94
105
  export async function jsonRequest(url, options = {}) {
@@ -107,6 +118,7 @@ export async function jsonRequest(url, options = {}) {
107
118
  `HTTP ${out.res.status}`;
108
119
  throw new CliError(`${options.label ?? url} failed: ${message}`, {
109
120
  code: out.res.status === 401 || out.res.status === 403 ? 3 : 1,
121
+ status: out.res.status, // 调用方按 HTTP 状态分支用(如新端点 404 → 退回旧端点)
110
122
  hint:
111
123
  out.res.status === 401
112
124
  ? "Run `cui login` again (or pass --token) — your PAT may be missing, revoked or expired."
@@ -132,6 +144,7 @@ export async function mcpCall({ base, token, method, params, reporter, id = 1 })
132
144
  body,
133
145
  reporter,
134
146
  label: `mcp:${method}`,
147
+ spinner: "Calling Dash MCP…",
135
148
  headers: { "Content-Type": "application/json" },
136
149
  timeout: 30_000,
137
150
  retries: 0,
package/src/login.mjs CHANGED
@@ -3,17 +3,12 @@ import { randomBytes } from "node:crypto";
3
3
  import { createServer } from "node:http";
4
4
  import * as p from "@clack/prompts";
5
5
  import { clearConfig, configFile, dashUrl, writeConfig } from "./config.mjs";
6
+ import { fetchAccount } from "./dash.mjs";
6
7
  import { authError } from "./errors.mjs";
7
- import { jsonRequest } from "./http.mjs";
8
8
 
9
- /** 校验 PAT 并返回 /api/me 聚合。 */
9
+ /** 校验 PAT 并取回账号数据(CLI 专用端点 GET /api/account:账户 + 按站授权 + 绑定 key)。 */
10
10
  export async function verifyToken(token, { reporter } = {}) {
11
- return jsonRequest(`${dashUrl()}/api/me`, {
12
- token,
13
- reporter,
14
- label: "dash /api/me",
15
- headers: { Accept: "application/json" },
16
- });
11
+ return fetchAccount(token, { reporter });
17
12
  }
18
13
 
19
14
  export function saveSession(token, me, { reporter } = {}) {
@@ -118,7 +113,7 @@ export async function login({
118
113
  reporter.warn("--no-verify: token saved without checking it. Run `cui whoami` to verify.");
119
114
  }
120
115
  saveSession(token, me, { reporter });
121
- reporter.outro("Login complete. Try `cui libs`.");
116
+ reporter.outro("Login complete. Try `cui whoami`.");
122
117
  return { token, me };
123
118
  }
124
119
 
package/src/report.mjs CHANGED
@@ -4,6 +4,7 @@ import * as p from "@clack/prompts";
4
4
  * 透明输出层:
5
5
  * - TTY / 人类模式:@clack/prompts(p CLI 同款)的 intro/log/step/note/outro
6
6
  * - 无头 / Agent 模式(--json 或非 TTY):逐行 JSON event,stdout 只出机器可读内容
7
+ * - 加载态:网络请求在途即转 spinner(createActivity),人类可读输出落地前自动让路
7
8
  *
8
9
  * 所有输出都过 redact():PAT、CLI key、MCP key 永远不会出现在日志里。
9
10
  */
@@ -14,9 +15,18 @@ export function createReporter({
14
15
  secrets = [],
15
16
  verbose = false,
16
17
  forceHeadless = false,
18
+ stream = process.stdout,
17
19
  } = {}) {
18
20
  let secretList = [...secrets].filter((s) => typeof s === "string" && s.length >= 4);
19
21
  const headless = json || forceHeadless || !process.stdout.isTTY;
22
+ // --json:加载态整套不存在(零字节),机器可读契约不受搅动
23
+ const activity = json ? NO_ACTIVITY : createActivity({ stream });
24
+
25
+ /** 人类可读输出统一先给 spinner 让路(清行),再落字。 */
26
+ const say = (write) => {
27
+ activity.pause();
28
+ write();
29
+ };
20
30
 
21
31
  function redact(value) {
22
32
  let out = typeof value === "string" ? value : String(value ?? "");
@@ -43,6 +53,7 @@ export function createReporter({
43
53
  function raw(msg, level = "info") {
44
54
  if (json) return;
45
55
  const text = redact(msg);
56
+ activity.pause();
46
57
  if (level === "error") p.log.error(text);
47
58
  else if (level === "warn") p.log.warn(text);
48
59
  else if (level === "success") p.log.success(text);
@@ -58,15 +69,19 @@ export function createReporter({
58
69
  addSecrets,
59
70
  redact,
60
71
  headlessMode: headless,
72
+ /** 登记一段「在等」的区间(TTY 下即 spinner),返回 release(finalMessage?)。 */
73
+ activity: activity.acquire,
74
+ /** 进程收尾:清行、还光标,在途区间一并作废。 */
75
+ settleLoading: activity.drop,
61
76
 
62
77
  intro(title) {
63
78
  if (json) emit({ event: "intro", title: redact(title) });
64
- else p.intro(redact(title));
79
+ else say(() => p.intro(redact(title)));
65
80
  },
66
81
 
67
82
  outro(title) {
68
83
  if (json) emit({ event: "outro", title: redact(title) });
69
- else p.outro(redact(title));
84
+ else say(() => p.outro(redact(title)));
70
85
  },
71
86
 
72
87
  info(msg) {
@@ -91,21 +106,23 @@ export function createReporter({
91
106
 
92
107
  step(index, total, title) {
93
108
  if (json) emit({ event: "step", index, total, title: redact(title) });
94
- else if (typeof p.log.step === "function") p.log.step(redact(`[${index}/${total}] ${title}`));
95
- else p.log.info(redact(`[${index}/${total}] ${title}`));
109
+ else if (typeof p.log.step === "function") say(() => p.log.step(redact(`[${index}/${total}] ${title}`)));
110
+ else say(() => p.log.info(redact(`[${index}/${total}] ${title}`)));
96
111
  },
97
112
 
98
113
  note(title, body) {
99
114
  if (json) emit({ event: "note", title: redact(title), body: redact(body) });
100
- else p.note(redact(body), redact(title));
115
+ else say(() => p.note(redact(body), redact(title)));
101
116
  },
102
117
 
103
118
  http(payload) {
104
119
  if (json) emit({ event: "http", ...payload, url: redact(payload.url) });
105
120
  else if (verbose && payload.phase === "request") {
106
- p.log.info(redact(` → ${payload.method} ${payload.url}${payload.attempt > 1 ? ` (retry ${payload.attempt})` : ""}`));
121
+ say(() =>
122
+ p.log.info(redact(` → ${payload.method} ${payload.url}${payload.attempt > 1 ? ` (retry ${payload.attempt})` : ""}`))
123
+ );
107
124
  } else if (verbose && payload.phase === "response") {
108
- p.log.info(redact(` ← ${payload.status} ${payload.url} (${payload.ms}ms)`));
125
+ say(() => p.log.info(redact(` ← ${payload.status} ${payload.url} (${payload.ms}ms)`)));
109
126
  }
110
127
  },
111
128
 
@@ -127,29 +144,32 @@ export function createReporter({
127
144
  const icon =
128
145
  status === "created" ? "+" : status === "updated" ? "~" : status === "unchanged" ? "=" : "·";
129
146
  const line = `${icon} ${summary ?? kind}${path ? ` ${path}` : ""}`;
130
- if (dryRun || status === "planned") p.log.info(redact(line));
131
- else p.log.success(redact(line));
132
- if (!json && changes.length && verbose) {
133
- for (const c of changes) p.log.info(redact(` · ${c}`));
134
- }
147
+ say(() => {
148
+ if (dryRun || status === "planned") p.log.info(redact(line));
149
+ else p.log.success(redact(line));
150
+ if (!json && changes.length && verbose) {
151
+ for (const c of changes) p.log.info(redact(` · ${c}`));
152
+ }
153
+ });
135
154
  },
136
155
 
137
156
  preview(label, text) {
138
157
  const body = redact(text);
139
158
  if (json) emit({ event: "preview", label: redact(label), text: body });
140
- else if (verbose || dryRun) p.note(body, redact(label));
159
+ else if (verbose || dryRun) say(() => p.note(body, redact(label)));
141
160
  },
142
161
 
143
162
  result(data) {
144
163
  if (json) emit({ event: "result", ...sanitize(data, redact) });
145
164
  else {
146
165
  const lines = flattenResult(data).map(redact);
147
- if (lines.length) p.note(lines.join("\n"), "Result");
166
+ if (lines.length) say(() => p.note(lines.join("\n"), "Result"));
148
167
  }
149
168
  },
150
169
 
151
170
  async confirm(message, { defaultValue = true } = {}) {
152
171
  if (yes || headless) return true;
172
+ activity.pause(); // clack 提示框接管终端期间,屏幕上不能有 spinner 行
153
173
  const answer = await p.confirm({ message: redact(message), initialValue: defaultValue });
154
174
  if (p.isCancel(answer)) {
155
175
  p.cancel("Cancelled.");
@@ -162,6 +182,7 @@ export function createReporter({
162
182
  if (headless) {
163
183
  throw new Error(`Interactive selection required: ${message}. Pass flags instead.`);
164
184
  }
185
+ activity.pause();
165
186
  const answer = await p.select({ message: redact(message), options });
166
187
  if (p.isCancel(answer)) {
167
188
  p.cancel("Cancelled.");
@@ -226,25 +247,40 @@ export function formatTable(rows, columns) {
226
247
  * 1. 不擦行——`\x1b[K` 每帧先擦后写,擦除→空白的空窗在部分终端被渲染成
227
248
  * 一帧空行,这就是「整行在闪」。改为首帧铺满整行,后续帧 `\r` 回行首
228
249
  * 等长覆写(braille 帧全部单列等宽,每帧渲染串严格等长,必然盖满旧行)。
250
+ * set(message) 换文案同理:新文案更短就补空格到旧行长度,照样不擦行。
229
251
  * 2. 隐藏光标——不藏的话块状光标每帧在行首/行尾来回跳,观感同闪。
230
- * stop 恢复;进程意外退出由 exit 钩子兜底恢复,终端不会丢光标。
252
+ * stop 恢复;进程正常退出由 exit 钩子兜底(Ctrl+C 等信号不触发 exit 钩子,
253
+ * 由 createActivity 接管)。
231
254
  * 3. 单次 write 整串——不拆多次写,避免终端分批渲染出中间态。
232
255
  * 仅 TTY 用;stop(finalMessage) 清行后打印终态(省略则只清行),幂等。
233
256
  */
234
257
  export function startSpin(message, { stream = process.stdout, interval = 90 } = {}) {
235
- if (!stream.isTTY) return { stop: () => {} };
258
+ if (!stream.isTTY) return { stop: () => {}, set: () => {} };
236
259
  const frames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"];
237
- const render = (frame) => `${frame} ${message}`;
260
+ let current = message;
261
+ let shown = 0; // 行上已落屏的文案长度——下一帧覆写的基准
238
262
  let i = 0;
239
263
  let stopped = false;
240
264
  const restoreCursor = () => stream.write("\x1b[?25h");
241
265
  process.once("exit", restoreCursor);
242
- stream.write(`\x1b[?25l${render(frames[0])}`);
266
+ const draw = () => {
267
+ const pad = " ".repeat(Math.max(0, shown - current.length));
268
+ stream.write(`\r${frames[i]} ${current}${pad}`);
269
+ shown = current.length;
270
+ };
271
+ stream.write(`\x1b[?25l${frames[i]} ${current}`);
272
+ shown = current.length;
243
273
  const timer = setInterval(() => {
244
- i += 1;
245
- stream.write(`\r${render(frames[i % frames.length])}`);
274
+ i = (i + 1) % frames.length;
275
+ draw();
246
276
  }, interval);
247
277
  return {
278
+ /** 原地换文案(切换加载阶段):随下一帧一起换,不擦行、不断拍。 */
279
+ set(next) {
280
+ if (stopped || next === current) return;
281
+ current = next;
282
+ draw();
283
+ },
248
284
  stop(finalMessage) {
249
285
  if (stopped) return;
250
286
  stopped = true;
@@ -255,3 +291,98 @@ export function startSpin(message, { stream = process.stdout, interval = 90 } =
255
291
  },
256
292
  };
257
293
  }
294
+
295
+ const NO_ACTIVITY = {
296
+ acquire: () => () => {},
297
+ pause: () => {},
298
+ drop: () => {},
299
+ };
300
+
301
+ /**
302
+ * 加载态:把「在等」的区间画成一行 spinner。
303
+ * - acquire(message) 登记一段在途区间,返回 release()(幂等)。屏幕上没有 spinner 时
304
+ * 当拍就写首帧——与触发它的那行输出(品牌 / 上一条结果)同一个 tick 落屏,
305
+ * 不存在「出了品牌却没动静」的空窗。
306
+ * - 多段区间重叠只占一行:显示最先登记的文案,头部结束原地切下一条。
307
+ * - release(finalMessage):区间全部结束时 spinner 行还在屏上,就原地落成这一行
308
+ * (与旧 startSpin().stop(finalMessage) 同款落地,不清行再写)。
309
+ * - pause() 给人类可读输出让路(清行、还光标);输出落地后若还有区间在等,下一拍
310
+ * 在新行接着转。让路后同一 tick 内区间就结束的,一帧都不会多画。
311
+ * - Ctrl+C / SIGTERM:清行、还光标再退。默认信号处置不触发 exit 钩子——终端会
312
+ * 被留下一个藏死的光标 + 冻住的 spinner 行(PTY 实测)。
313
+ */
314
+ function createActivity({ stream, interval = 90 }) {
315
+ if (!stream.isTTY) return NO_ACTIVITY;
316
+ const queue = [];
317
+ let spin = null; // 屏幕上正在转的 spinner(null = 没有 spinner 行)
318
+ let resume = null; // 让路后等下一拍在新行接着转的定时器
319
+ let hooked = false;
320
+ const clearResume = () => {
321
+ if (resume) {
322
+ clearTimeout(resume);
323
+ resume = null;
324
+ }
325
+ };
326
+ const start = () => {
327
+ clearResume();
328
+ spin = startSpin(queue[0].message, { stream, interval });
329
+ };
330
+ const onSigint = () => {
331
+ spin?.stop();
332
+ process.exit(130);
333
+ };
334
+ const onSigterm = () => {
335
+ spin?.stop();
336
+ process.exit(143);
337
+ };
338
+ function hook(on) {
339
+ if (on === hooked) return;
340
+ hooked = on;
341
+ const op = on ? "once" : "removeListener";
342
+ process[op]("SIGINT", onSigint);
343
+ process[op]("SIGTERM", onSigterm);
344
+ }
345
+ return {
346
+ acquire(message) {
347
+ const entry = { message };
348
+ queue.push(entry);
349
+ hook(true);
350
+ if (!spin) start();
351
+ let released = false;
352
+ return (finalMessage) => {
353
+ if (released) return;
354
+ released = true;
355
+ const at = queue.indexOf(entry);
356
+ if (at !== -1) queue.splice(at, 1);
357
+ if (queue.length > 0) {
358
+ if (at === 0 && spin) spin.set(queue[0].message);
359
+ return;
360
+ }
361
+ clearResume();
362
+ hook(false);
363
+ if (spin) spin.stop(finalMessage);
364
+ else if (finalMessage != null) stream.write(`${finalMessage}\n`);
365
+ spin = null;
366
+ };
367
+ },
368
+ pause() {
369
+ if (spin) {
370
+ spin.stop();
371
+ spin = null;
372
+ }
373
+ if (!resume && queue.length > 0) {
374
+ resume = setTimeout(() => {
375
+ resume = null;
376
+ if (queue.length > 0 && !spin) start();
377
+ }, interval);
378
+ }
379
+ },
380
+ drop() {
381
+ queue.length = 0;
382
+ clearResume();
383
+ hook(false);
384
+ spin?.stop();
385
+ spin = null;
386
+ },
387
+ };
388
+ }
@@ -28,12 +28,13 @@ never stores upstream vendor accounts.
28
28
 
29
29
  ```bash
30
30
  collectui whoami --json
31
- collectui libs --json
32
31
  ```
33
32
 
34
- `libs` marks which libraries the account owns and whether CLI/MCP keys are
35
- bound. Catalog slugs: `affectui arc beui efferd magic bits reui blocks space
36
- studio uikit motion 21st`. Only shadcn-registry libraries are included;
33
+ The result has `account` and `libraries`: one row per library with `site`,
34
+ `owned` (`yes` / `no`), `cli` and `mcp` (`bound` / `-` / `generic` — whether
35
+ that library's CLI / MCP key is bound to the account). Use `libraries[].site`
36
+ as the catalog slugs for `--libs`; the catalog is dynamic, so new libraries
37
+ appear without a CLI release. Only shadcn-registry libraries are included;
37
38
  ThreeUI, Aura and HeroUI ship their own installers and are out of scope.
38
39
 
39
40
  ### Configure an existing project
package/src/update.mjs CHANGED
@@ -78,8 +78,14 @@ export function decideUpdate({
78
78
  }
79
79
 
80
80
  /** registry latest → 版本号;失败抛错(调用方决定吞还是报)。 */
81
- export async function fetchLatestVersion({ timeout = 8_000 } = {}) {
82
- const out = await httpRequest(REGISTRY_LATEST, { timeout, retries: 1 });
81
+ export async function fetchLatestVersion({ timeout = 8_000, reporter } = {}) {
82
+ // 带 reporter 才转 spinner:前台 `cui update` 传;后台检查不传(与命令并行,不能乱入)
83
+ const out = await httpRequest(REGISTRY_LATEST, {
84
+ timeout,
85
+ retries: 1,
86
+ reporter,
87
+ spinner: "Checking npm for updates…",
88
+ });
83
89
  if (!out.res.ok) throw new Error(`registry ${out.res.status}`);
84
90
  const parsed = JSON.parse(out.text);
85
91
  const v = parsed?.version;
@@ -1,88 +0,0 @@
1
- import { activeCatalog, ownedLibs, resolveLibKeys, retiredSlugs } from "../catalog.mjs";
2
- import { formatTable, startSpin } from "../report.mjs";
3
- import { loadMe } from "./common.mjs";
4
-
5
- /**
6
- * cui libs 精简三列:SITE + CLI KEY + MCP KEY(MCP 值区分专属 bound / 通用 generic)
7
- * cui libs --verbose 完整表格(registries/MCP server 名等内部细节)
8
- * 未拥有的行两列均为 "-";加载态为行内覆写 spinner(不闪)。
9
- */
10
- export async function libsCmd(flags, rest, reporter) {
11
- const interactive = !reporter.headless && !reporter.json;
12
- const spin = interactive ? startSpin("Loading your account from Dash…") : null;
13
- let me = null;
14
- try {
15
- me = await loadMe(flags, reporter, { required: false });
16
- } catch (error) {
17
- spin?.stop();
18
- reporter.warn(`Could not load account (${error.message}); showing catalog only.`);
19
- }
20
-
21
- const owned = me ? new Set(ownedLibs(me).map((lib) => lib.site)) : null;
22
- // 账号里拥有但不属于 shadcn registry 体系的库(自带独立安装器,如 threeui/
23
- // heroui v3/aura)——本 CLI 管不到,但必须点名说明,不然用户以为少了。
24
- // 停用站(Dash sites 表 retired,如 hero v2 / io)不再点名。
25
- const LIBS = activeCatalog().libs;
26
- const knownSites = new Set(LIBS.map((lib) => lib.site));
27
- const retired = retiredSlugs();
28
- const extraOwned = me
29
- ? [
30
- ...new Set([
31
- ...(me.sites ?? []).map((s) => s.slug),
32
- ...(me.keys ?? []).map((k) => k.site).filter(Boolean),
33
- ]),
34
- ].filter((slug) => !knownSites.has(slug) && !retired.has(slug))
35
- : [];
36
- const rows = [];
37
-
38
- for (const lib of LIBS) {
39
- const keys = me ? resolveLibKeys(lib, me) : { cli: null, mcp: null };
40
- const isOwned = owned ? owned.has(lib.site) : null;
41
- rows.push({
42
- site: lib.site,
43
- cli: isOwned === false ? "-" : keys.cli ? "bound" : "-",
44
- mcp: isOwned === false ? "-" : keys.mcp ? "bound" : lib.mcp ? "-" : "generic",
45
- name: lib.siteName,
46
- owned: isOwned === null ? "?" : isOwned ? "yes" : "no",
47
- registries: (lib.registries ?? []).map((r) => r.scope).join(", ") || "-",
48
- mcpServer: lib.mcp ?? (lib.shadcnUiMcp ? "shadcn (generic)" : "-"),
49
- });
50
- }
51
-
52
- spin?.stop(me ? `Account ${me.account?.username ?? me.account?.uid}` : "Catalog (not logged in)");
53
-
54
- if (reporter.json) {
55
- reporter.result({ account: me?.account ?? null, libraries: rows });
56
- return;
57
- }
58
-
59
- const verbose = Boolean(flags.verbose || flags.v);
60
- reporter.note(
61
- me ? `Account ${me.account?.username ?? me.account?.uid}` : "Catalog (not logged in)",
62
- verbose
63
- ? formatTable(rows, [
64
- { key: "site", header: "SITE" },
65
- { key: "name", header: "LIBRARY" },
66
- { key: "owned", header: "OWNED" },
67
- { key: "cli", header: "CLI KEY" },
68
- { key: "mcp", header: "MCP KEY" },
69
- { key: "registries", header: "REGISTRIES" },
70
- { key: "mcpServer", header: "MCP SERVER" },
71
- ])
72
- : formatTable(rows, [
73
- { key: "site", header: "SITE" },
74
- { key: "cli", header: "CLI KEY" },
75
- { key: "mcp", header: "MCP KEY" },
76
- ])
77
- );
78
- if (extraOwned.length) {
79
- reporter.info(
80
- `Your account also owns ${extraOwned.length} librar${extraOwned.length === 1 ? "y" : "ies"} ` +
81
- `outside the shadcn registry system (${extraOwned.join(", ")}) — ` +
82
- `they install via their own tooling and are not managed by this CLI.`
83
- );
84
- }
85
- if (!me) {
86
- reporter.info("Run `cui login` to see which libraries your account owns and to bind keys.");
87
- }
88
- }