@collectui/cli 0.2.20 → 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 +3 -4
- package/package.json +1 -1
- package/src/cli.mjs +7 -9
- package/src/commands/add.mjs +1 -1
- package/src/commands/common.mjs +6 -10
- package/src/commands/doctor.mjs +2 -2
- package/src/commands/mcp.mjs +10 -2
- package/src/commands/setup.mjs +3 -3
- package/src/commands/whoami.mjs +116 -13
- package/src/dash.mjs +22 -10
- package/src/login.mjs +4 -10
- package/src/skill/SKILL.md +5 -4
- package/src/commands/libs.mjs +0 -95
package/README.md
CHANGED
|
@@ -47,9 +47,8 @@ collectui login --token dpat_... --json # 或显式传入
|
|
|
47
47
|
## 看账户与库
|
|
48
48
|
|
|
49
49
|
```bash
|
|
50
|
-
collectui whoami #
|
|
51
|
-
collectui
|
|
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
|
|
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
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
|
|
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
|
|
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
|
|
102
|
-
|
|
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"] },
|
|
@@ -120,10 +118,10 @@ function findCommand(name) {
|
|
|
120
118
|
|
|
121
119
|
/**
|
|
122
120
|
* 纯本地/纯账号命令不拉动态目录(省一次网络等待):dash 子命令全是 Dash MCP 调用、
|
|
123
|
-
* skill 只落一个文件,都读不到目录。
|
|
121
|
+
* skill 只落一个文件,都读不到目录。whoami 标了 parallel——入口不等目录,命令里把
|
|
124
122
|
* 目录与账号两请求同 tick 并行发出(谁慢等谁,省掉串行那一趟)。
|
|
125
123
|
*/
|
|
126
|
-
const CATALOG_SKIP = new Set(["login", "logout", "
|
|
124
|
+
const CATALOG_SKIP = new Set(["login", "logout", "update", "dash", "skill"]);
|
|
127
125
|
|
|
128
126
|
function printHelp() {
|
|
129
127
|
process.stdout.write(HELP);
|
|
@@ -186,7 +184,7 @@ async function main() {
|
|
|
186
184
|
: () => Promise.resolve();
|
|
187
185
|
|
|
188
186
|
try {
|
|
189
|
-
await command.run(flags, rest, reporter);
|
|
187
|
+
await command.run(flags, rest, reporter, { invokedAs: name });
|
|
190
188
|
await settleUpdate();
|
|
191
189
|
} finally {
|
|
192
190
|
reporter.settleLoading(); // 异常退出也不把 spinner 行 / 藏起的光标留在终端
|
package/src/commands/add.mjs
CHANGED
|
@@ -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
|
|
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;
|
package/src/commands/common.mjs
CHANGED
|
@@ -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 { fetchAccount
|
|
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,21 +33,13 @@ export async function loadMe(flags, reporter, { required = true } = {}) {
|
|
|
29
33
|
return null;
|
|
30
34
|
}
|
|
31
35
|
reporter?.addSecrets([token]);
|
|
32
|
-
const me = await
|
|
36
|
+
const me = await fetchAccount(token, { reporter });
|
|
33
37
|
reporter?.addSecrets(
|
|
34
38
|
(me.keys ?? []).map((k) => k.key).filter(Boolean)
|
|
35
39
|
);
|
|
36
40
|
return me;
|
|
37
41
|
}
|
|
38
42
|
|
|
39
|
-
/** whoami 用:只要账户本体(轻量端点,不触发 /api/me 的全量聚合)。 */
|
|
40
|
-
export async function loadAccount(flags, reporter) {
|
|
41
|
-
const token = resolveToken(flags);
|
|
42
|
-
if (!token) return requireToken(flags, reporter);
|
|
43
|
-
reporter?.addSecrets([token]);
|
|
44
|
-
return fetchAccount(token, { reporter });
|
|
45
|
-
}
|
|
46
|
-
|
|
47
43
|
export function ownedSlugs(me) {
|
|
48
44
|
return new Set(ownedLibs(me).map((lib) => lib.site));
|
|
49
45
|
}
|
package/src/commands/doctor.mjs
CHANGED
|
@@ -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,
|
|
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
|
|
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);
|
package/src/commands/mcp.mjs
CHANGED
|
@@ -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 {
|
|
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
|
|
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);
|
package/src/commands/setup.mjs
CHANGED
|
@@ -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 {
|
|
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
|
|
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
|
|
87
|
+
me = session.me ?? (await fetchAccount(token, { reporter }));
|
|
88
88
|
} else {
|
|
89
89
|
throw error;
|
|
90
90
|
}
|
package/src/commands/whoami.mjs
CHANGED
|
@@ -1,24 +1,127 @@
|
|
|
1
|
+
import {
|
|
2
|
+
activeCatalog,
|
|
3
|
+
ensureCatalog,
|
|
4
|
+
ownedLibs,
|
|
5
|
+
resolveLibKeys,
|
|
6
|
+
retiredSlugs,
|
|
7
|
+
} from "../catalog.mjs";
|
|
1
8
|
import { formatAccountHuman, maskKey } from "../dash.mjs";
|
|
2
|
-
import {
|
|
9
|
+
import { resolveToken } from "../config.mjs";
|
|
10
|
+
import { formatTable } from "../report.mjs";
|
|
11
|
+
import { loadMe, requireToken } from "./common.mjs";
|
|
3
12
|
|
|
4
13
|
/**
|
|
5
|
-
* cui whoami
|
|
14
|
+
* cui whoami 我是谁 + 我的库:账户段(账户名 / uid / 注册时间 / 徽章)+ 全库表
|
|
15
|
+
* SITE · CLI KEY · MCP KEY(MCP 值区分专属 bound / 通用 generic)
|
|
16
|
+
* cui whoami --verbose 宽表(OWNED / REGISTRIES / MCP SERVER 等内部细节)
|
|
17
|
+
* 未拥有的行两列均为 "-"。
|
|
6
18
|
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
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。
|
|
10
26
|
*/
|
|
11
|
-
|
|
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
|
+
}
|
|
83
|
+
|
|
12
84
|
if (reporter.json) {
|
|
13
|
-
const me = await loadMe(flags, reporter);
|
|
14
85
|
reporter.result({
|
|
15
|
-
account: me
|
|
16
|
-
sites: me
|
|
17
|
-
keys: (me
|
|
18
|
-
|
|
19
|
-
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,
|
|
20
90
|
});
|
|
21
91
|
return;
|
|
22
92
|
}
|
|
23
|
-
|
|
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
|
+
}
|
|
24
127
|
}
|
package/src/dash.mjs
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import { dashUrl } from "./config.mjs";
|
|
2
2
|
import { jsonRequest, mcpCall, toolResult } from "./http.mjs";
|
|
3
3
|
|
|
4
|
-
/**
|
|
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,
|
|
@@ -12,9 +16,10 @@ export async function fetchMe(token, { reporter } = {}) {
|
|
|
12
16
|
}
|
|
13
17
|
|
|
14
18
|
/**
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
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 取同名切片。
|
|
18
23
|
*/
|
|
19
24
|
export async function fetchAccount(token, { reporter } = {}) {
|
|
20
25
|
const request = (path) =>
|
|
@@ -24,20 +29,27 @@ export async function fetchAccount(token, { reporter } = {}) {
|
|
|
24
29
|
label: `dash ${path}`,
|
|
25
30
|
spinner: "Loading your account from Dash…",
|
|
26
31
|
});
|
|
27
|
-
let data;
|
|
32
|
+
let data = null;
|
|
28
33
|
try {
|
|
29
|
-
|
|
34
|
+
const light = await request("/api/account");
|
|
35
|
+
if (Array.isArray(light?.sites) && Array.isArray(light?.keys)) data = light;
|
|
30
36
|
} catch (error) {
|
|
31
37
|
if (error?.status !== 404) throw error;
|
|
32
|
-
data = await request("/api/me");
|
|
33
38
|
}
|
|
34
|
-
|
|
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;
|
|
35
44
|
}
|
|
36
45
|
|
|
37
|
-
/** `cui whoami`
|
|
46
|
+
/** `cui whoami` 的账户段:账户名 + uid、注册时间、徽章——最基本的账户信息,到此为止。 */
|
|
38
47
|
export function formatAccountHuman(account) {
|
|
39
48
|
if (!account) return "No account data.";
|
|
40
|
-
|
|
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");
|
|
41
53
|
}
|
|
42
54
|
|
|
43
55
|
/** Dash MCP:stateless JSON-RPC,直接 tools/list 或 tools/call。 */
|
package/src/login.mjs
CHANGED
|
@@ -3,18 +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
|
|
9
|
+
/** 校验 PAT 并取回账号数据(CLI 专用端点 GET /api/account:账户 + 按站授权 + 绑定 key)。 */
|
|
10
10
|
export async function verifyToken(token, { reporter } = {}) {
|
|
11
|
-
return
|
|
12
|
-
token,
|
|
13
|
-
reporter,
|
|
14
|
-
label: "dash /api/me",
|
|
15
|
-
spinner: "Verifying your PAT with Dash…",
|
|
16
|
-
headers: { Accept: "application/json" },
|
|
17
|
-
});
|
|
11
|
+
return fetchAccount(token, { reporter });
|
|
18
12
|
}
|
|
19
13
|
|
|
20
14
|
export function saveSession(token, me, { reporter } = {}) {
|
|
@@ -119,7 +113,7 @@ export async function login({
|
|
|
119
113
|
reporter.warn("--no-verify: token saved without checking it. Run `cui whoami` to verify.");
|
|
120
114
|
}
|
|
121
115
|
saveSession(token, me, { reporter });
|
|
122
|
-
reporter.outro("Login complete. Try `cui
|
|
116
|
+
reporter.outro("Login complete. Try `cui whoami`.");
|
|
123
117
|
return { token, me };
|
|
124
118
|
}
|
|
125
119
|
|
package/src/skill/SKILL.md
CHANGED
|
@@ -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
|
-
`
|
|
35
|
-
|
|
36
|
-
|
|
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/commands/libs.mjs
DELETED
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
import { activeCatalog, ownedLibs, resolveLibKeys, retiredSlugs } from "../catalog.mjs";
|
|
2
|
-
import { ensureCatalog } from "../catalog.mjs";
|
|
3
|
-
import { formatTable } from "../report.mjs";
|
|
4
|
-
import { loadMe } from "./common.mjs";
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* cui libs 精简三列:SITE + CLI KEY + MCP KEY(MCP 值区分专属 bound / 通用 generic)
|
|
8
|
-
* cui libs --verbose 完整表格(registries/MCP server 名等内部细节)
|
|
9
|
-
* 未拥有的行两列均为 "-";加载态为行内覆写 spinner(不闪),品牌一出就转。
|
|
10
|
-
*/
|
|
11
|
-
export async function libsCmd(flags, rest, reporter) {
|
|
12
|
-
// 入口没等目录(COMMANDS.libs.parallel):目录、账号两请求这里同 tick 并行发出,谁慢等谁。
|
|
13
|
-
// 命令自己的区间排最前 → 两个请求在途期间同一行转到底,结束原地落成结果行。
|
|
14
|
-
const land = reporter.activity("Loading your account from Dash…");
|
|
15
|
-
const [, outcome] = await Promise.all([
|
|
16
|
-
ensureCatalog({ reporter }),
|
|
17
|
-
loadMe(flags, reporter, { required: false }).then(
|
|
18
|
-
(me) => ({ me }),
|
|
19
|
-
(error) => ({ error })
|
|
20
|
-
),
|
|
21
|
-
]);
|
|
22
|
-
const me = outcome.me ?? null;
|
|
23
|
-
if (outcome.error) {
|
|
24
|
-
land();
|
|
25
|
-
reporter.warn(`Could not load account (${outcome.error.message}); showing catalog only.`);
|
|
26
|
-
} else {
|
|
27
|
-
land(me ? `Account ${me.account?.username ?? me.account?.uid}` : "Catalog (not logged in)");
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
const owned = me ? new Set(ownedLibs(me).map((lib) => lib.site)) : null;
|
|
31
|
-
// 账号里拥有但不属于 shadcn registry 体系的库(自带独立安装器,如 threeui/
|
|
32
|
-
// heroui v3/aura)——本 CLI 管不到,但必须点名说明,不然用户以为少了。
|
|
33
|
-
// 停用站(Dash sites 表 retired,如 hero v2 / io)不再点名。
|
|
34
|
-
const LIBS = activeCatalog().libs;
|
|
35
|
-
const knownSites = new Set(LIBS.map((lib) => lib.site));
|
|
36
|
-
const retired = retiredSlugs();
|
|
37
|
-
const extraOwned = me
|
|
38
|
-
? [
|
|
39
|
-
...new Set([
|
|
40
|
-
...(me.sites ?? []).map((s) => s.slug),
|
|
41
|
-
...(me.keys ?? []).map((k) => k.site).filter(Boolean),
|
|
42
|
-
]),
|
|
43
|
-
].filter((slug) => !knownSites.has(slug) && !retired.has(slug))
|
|
44
|
-
: [];
|
|
45
|
-
const rows = [];
|
|
46
|
-
|
|
47
|
-
for (const lib of LIBS) {
|
|
48
|
-
const keys = me ? resolveLibKeys(lib, me) : { cli: null, mcp: null };
|
|
49
|
-
const isOwned = owned ? owned.has(lib.site) : null;
|
|
50
|
-
rows.push({
|
|
51
|
-
site: lib.site,
|
|
52
|
-
cli: isOwned === false ? "-" : keys.cli ? "bound" : "-",
|
|
53
|
-
mcp: isOwned === false ? "-" : keys.mcp ? "bound" : lib.mcp ? "-" : "generic",
|
|
54
|
-
name: lib.siteName,
|
|
55
|
-
owned: isOwned === null ? "?" : isOwned ? "yes" : "no",
|
|
56
|
-
registries: (lib.registries ?? []).map((r) => r.scope).join(", ") || "-",
|
|
57
|
-
mcpServer: lib.mcp ?? (lib.shadcnUiMcp ? "shadcn (generic)" : "-"),
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
if (reporter.json) {
|
|
62
|
-
reporter.result({ account: me?.account ?? null, libraries: rows });
|
|
63
|
-
return;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
const verbose = Boolean(flags.verbose || flags.v);
|
|
67
|
-
reporter.note(
|
|
68
|
-
me ? `Account ${me.account?.username ?? me.account?.uid}` : "Catalog (not logged in)",
|
|
69
|
-
verbose
|
|
70
|
-
? formatTable(rows, [
|
|
71
|
-
{ key: "site", header: "SITE" },
|
|
72
|
-
{ key: "name", header: "LIBRARY" },
|
|
73
|
-
{ key: "owned", header: "OWNED" },
|
|
74
|
-
{ key: "cli", header: "CLI KEY" },
|
|
75
|
-
{ key: "mcp", header: "MCP KEY" },
|
|
76
|
-
{ key: "registries", header: "REGISTRIES" },
|
|
77
|
-
{ key: "mcpServer", header: "MCP SERVER" },
|
|
78
|
-
])
|
|
79
|
-
: formatTable(rows, [
|
|
80
|
-
{ key: "site", header: "SITE" },
|
|
81
|
-
{ key: "cli", header: "CLI KEY" },
|
|
82
|
-
{ key: "mcp", header: "MCP KEY" },
|
|
83
|
-
])
|
|
84
|
-
);
|
|
85
|
-
if (extraOwned.length) {
|
|
86
|
-
reporter.info(
|
|
87
|
-
`Your account also owns ${extraOwned.length} librar${extraOwned.length === 1 ? "y" : "ies"} ` +
|
|
88
|
-
`outside the shadcn registry system (${extraOwned.join(", ")}) — ` +
|
|
89
|
-
`they install via their own tooling and are not managed by this CLI.`
|
|
90
|
-
);
|
|
91
|
-
}
|
|
92
|
-
if (!me) {
|
|
93
|
-
reporter.info("Run `cui login` to see which libraries your account owns and to bind keys.");
|
|
94
|
-
}
|
|
95
|
-
}
|