@collectui/cli 0.0.0-stage → 0.2.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 CollectUI
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,205 @@
1
- # Temporary Holding Version
1
+ # @collectui/cli
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ CollectUI Dash 的 shadcn 三方库统一 CLI。一个命令完成:
4
+
5
+ **登录 Dash → 看清你拥有哪些库 → 一键把 registry / license key / MCP 配进项目 → 装组件 → 体检**。
6
+
7
+ - 身份绑定你本人的 Dash PAT(`dpat_...`),不碰任何上游账号
8
+ - 交互用 [`@clack/prompts`](https://github.com/bombshell-dev/clack)(与 `p` CLI 同款)
9
+ - `--json` / 非 TTY 自动进无头模式,Agent 可直接驱动
10
+ - 每一步都有计划与结果输出,`--dry-run` 只看不写
11
+ - PAT、CLI key、MCP key 全程脱敏,不会出现在日志里
12
+
13
+ ---
14
+
15
+ ## 安装
16
+
17
+ ```bash
18
+ npx @collectui/cli --help
19
+ # 或全局
20
+ npm i -g @collectui/cli
21
+ collectui --version
22
+ ```
23
+
24
+ 要求 Node ≥ 18.17。
25
+
26
+ ## 登录
27
+
28
+ ```bash
29
+ collectui login
30
+ ```
31
+
32
+ 会自动打开 `https://dash.collectui.pro/login`,登录后在右上角「API 密钥」创建一条 PAT(label 可填 `collectui-cli`),粘贴回终端即可。PAT 保存到 `~/.collectui/config.json`(`chmod 600`)。
33
+
34
+ 无头 / Agent:
35
+
36
+ ```bash
37
+ COLLECTUI_TOKEN=dpat_... collectui whoami --json
38
+ # 或
39
+ collectui login --token dpat_... --json
40
+ ```
41
+
42
+ > 登录页与 PAT 创建都在浏览器完成(Dash 的安全设计);CLI 同时开了
43
+ > `127.0.0.1` 回调监听,Dash 后续支持 CLI 配对时可直接回传 token,无需粘贴。
44
+
45
+ ## 看账户与库
46
+
47
+ ```bash
48
+ collectui whoami # 账户、按站权限、绑定 key、可下仓库、订单
49
+ collectui libs # 全库目录 + 你是否拥有 + CLI/MCP key 状态
50
+ collectui libs --json # Agent 用
51
+ ```
52
+
53
+ ## 一键配置到项目
54
+
55
+ 在已有 shadcn 项目里:
56
+
57
+ ```bash
58
+ collectui configure . --libs all
59
+ # 指定库
60
+ collectui configure . --libs reui,arc,bits
61
+ # 先看计划
62
+ collectui configure . --libs all --dry-run
63
+ ```
64
+
65
+ 会做这些事(每步都会打印):
66
+
67
+ 1. **`components.json`**:合并 `registries` 条目,URL 指向
68
+ `https://registry.collectui.pro/api/r/<source>/...`,认证头保留 `${ENV}` 模板
69
+ 2. **`.env.local`**:写入该库的 license key 变量(`chmod 600`)
70
+ 3. **MCP**:
71
+ - 库有专属 MCP → 写入 `<site>` server(HTTP 端点 / stdio 包)
72
+ - 库没有专属 MCP → 写官方 shadcn 通用 MCP(读 `components.json` 里所有 registry)
73
+ - 始终写 **`collectui-dash`** MCP(Bearer PAT),Agent 可直接调用 Dash 工具
74
+ - 默认写 `claude`(`.mcp.json`)、`cursor`(`.cursor/mcp.json`)、`vscode`(`.vscode/mcp.json`);`--clients codex` 写 `~/.codex/config.toml`
75
+ 4. **`.collectui/project.json` + `.collectui/environment.md`**:机器可读的配置记录(不含密钥)
76
+
77
+ ### 合并规则(不覆盖你的自定义配置)
78
+
79
+ | 情况 | 行为 |
80
+ | --- | --- |
81
+ | 没配置 | 添加 |
82
+ | 配置相同 | 跳过 |
83
+ | 同 URL、token 不同 | 更新 token(视为 CLI 自己写的条目) |
84
+ | 官方 shadcn 占位(`ui.shadcn.com` / `npx shadcn mcp`) | 替换为该库的专属 MCP |
85
+ | 自定义 URL/命令 | **保留**,并明确报告;只有 `--force` 才替换 |
86
+
87
+ ## 在 /tmp 初始化新项目
88
+
89
+ ```bash
90
+ collectui init /tmp/my-app --libs all
91
+ # 或让 CLI 选临时目录
92
+ collectui init --tmp --name my-app --libs reui,arc
93
+ ```
94
+
95
+ 默认模板:Vite + React + TypeScript + Tailwind v4 + shadcn 兼容
96
+ `components.json`,并执行 `git init`。`--no-install` 跳过依赖安装;
97
+ `--template none` 只配置、不搭脚手架。
98
+
99
+ ## 装组件
100
+
101
+ ```bash
102
+ collectui add reui data-grid
103
+ collectui add reui data-grid kanban
104
+ collectui add arc pro/dock # 自动选 @uiarc-pro
105
+ collectui add studio blocks/hero-01 # 自动选 @ss-blocks
106
+ collectui add 21st shugar/button-1
107
+ collectui add reui data-grid --print # 只打印命令
108
+ ```
109
+
110
+ - 所有库统一走 shadcn registry → `npx shadcn@latest add @scope/<component> --yes`
111
+
112
+ `--scope @uiarc-pro` 可强制 scope;`--force` 给 shadcn 加 `--overwrite`。
113
+
114
+ ## MCP 与 Dash 结合
115
+
116
+ ```bash
117
+ collectui mcp show # 打印按 client 分组的 MCP 配置
118
+ collectui mcp init # 只写/合并 MCP 配置
119
+ collectui mcp tools # Dash MCP 工具列表
120
+ collectui mcp call me # 调 Dash MCP 工具
121
+ collectui dash me # 账户聚合(MCP,404 回退 REST)
122
+ collectui dash repos # 可下快照仓
123
+ collectui dash download owner/repo # 取新的下载链接
124
+ collectui dash feedback "..." --site reui
125
+ ```
126
+
127
+ Dash MCP 端点:`https://dash.collectui.pro/api/mcp`,Bearer PAT。工具:
128
+ `me`、`list_repos`、`download_repo`、`submit_feedback`。
129
+
130
+ ## 无头 / Agent 驱动
131
+
132
+ ```bash
133
+ # 所有命令都支持 --json:stdout 逐行 JSON event,最后一条是 result
134
+ collectui libs --json
135
+ collectui init /tmp/app --libs all --yes --no-install --json
136
+ collectui configure . --libs all --yes --json
137
+ collectui doctor --json
138
+ ```
139
+
140
+ 约定:
141
+
142
+ - `--json` / 非 TTY 不弹任何交互
143
+ - Token 来源:`--token` > `COLLECTUI_TOKEN` > `DASH_PAT` > 本地配置
144
+ - 退出码:`0` 成功;`1` 一般错误;`2` 用法错误;`3` 认证错误
145
+ - 错误事件:`{"event":"error","message":...,"hint":...,"exitCode":...}`
146
+ - HTTP 请求也以 `{"event":"http",...}` 输出(token 已脱敏)
147
+ - 文件动作:`{"event":"action","kind":"write","path":...,"status":"created|updated",...}`
148
+
149
+ 装 Agent skill:
150
+
151
+ ```bash
152
+ collectui skill # .claude/skills/collectui/SKILL.md
153
+ collectui skill --global # ~/.claude/skills/collectui/SKILL.md
154
+ ```
155
+
156
+ ## 体检
157
+
158
+ ```bash
159
+ collectui doctor # 登录、account、Dash MCP、项目 registries/env/MCP
160
+ collectui doctor --deep # 再对每个已拥有库做一次 registry 探测(会消耗额度,慎用)
161
+ ```
162
+
163
+ ## 支持的库
164
+
165
+ | 站点 slug | 库 | registry scope | MCP |
166
+ | --- | --- | --- | --- |
167
+ | `affectui` | affectUI | `@affectui` | `affectui` |
168
+ | `arc` | Arc | `@uiarc`, `@uiarc-pro` | `arc` |
169
+ | `beui` | BeUI | `@beui`, `@beui-pro` | `beui` |
170
+ | `efferd` | Efferd | `@efferd` | shadcn 通用 |
171
+ | `magic` | MagicUI | `@magicui-pro` | shadcn 通用 |
172
+ | `bits` | React Bits | `@reactbits-starter`, `@reactbits-pro` | `reactbits` + shadcn |
173
+ | `reui` | ReUI | `@reui` | `reui` |
174
+ | `blocks` | Shadcnblocks | `@shadcnblocks` | shadcn 通用 |
175
+ | `space` | ShadcnSpace | `@shadcn-space` | `shadcnspace` |
176
+ | `studio` | Shadcnstudio | `@shadcn-studio`, `@ss-components`, `@ss-blocks`, `@ss-themes` | `shadcn-studio-mcp` (stdio) |
177
+ | `uikit` | Shadcn UI Kit | `@shadcnuikit` | `shadcnuikit` |
178
+ | `motion` | Motion | `@motion` | `motion-plus` |
179
+ | `21st` | 21st | `@21st` | `21st` |
180
+
181
+ > 目录只收 **shadcn registry 体系**的三方库(能在 `components.json` 里注册、
182
+ > 用 `shadcn add` 安装);ThreeUI / Aura / HeroUI 等自带独立安装器、不兼容
183
+ > shadcn registry 的产品不在本 CLI 范围内。目录是内置快照,与 Dash 站点卡的
184
+ > AI Tools 数据同源;实际能不能装以你账户的 `/api/me` 授权与绑定 key 为准。
185
+ > Dash 新增 shadcn 库时同步本仓库 `src/catalog.mjs`。
186
+
187
+ ## 安全
188
+
189
+ - PAT 只在 `~/.collectui/config.json`(0600)和你自己的项目文件里
190
+ - `.env.local`、`.mcp.json`、`.cursor/mcp.json`、`.vscode/mcp.json` 含凭据,
191
+ 脚手架默认把它们写进 `.gitignore`
192
+ - 日志脱敏:已知 key / PAT、`Bearer ...`、`dpat_...` 一律替换为 `[redacted]`
193
+ - 除 `registry.collectui.pro` / `dash.collectui.pro` 外,不向任何第三方发送密钥
194
+
195
+ ## 开发
196
+
197
+ ```bash
198
+ npm install
199
+ npm test # node:test(17 项:合并规则 + 端到端 init/configure/add/doctor)
200
+ node src/cli.mjs --help
201
+ ```
202
+
203
+ ## License
204
+
205
+ MIT
package/package.json CHANGED
@@ -1,6 +1,39 @@
1
1
  {
2
2
  "name": "@collectui/cli",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.2.0",
4
+ "description": "One CLI for every shadcn library on CollectUI Dash — login once, configure registries & MCP, scaffold agent-ready projects.",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "bin": {
8
+ "collectui": "src/cli.mjs",
9
+ "cui": "src/cli.mjs"
10
+ },
11
+ "files": [
12
+ "src",
13
+ "README.md",
14
+ "LICENSE"
15
+ ],
16
+ "engines": {
17
+ "node": ">=18.17"
18
+ },
19
+ "scripts": {
20
+ "test": "node --test test/*.test.mjs",
21
+ "check": "node --check src/cli.mjs && node --check src/catalog.mjs && node --check src/project.mjs && node --check src/mcp.mjs"
22
+ },
23
+ "dependencies": {
24
+ "@clack/prompts": "^0.11.0"
25
+ },
26
+ "keywords": [
27
+ "collectui",
28
+ "shadcn",
29
+ "registry",
30
+ "mcp",
31
+ "cli",
32
+ "components"
33
+ ],
34
+ "publishConfig": {
35
+ "access": "public"
36
+ },
37
+ "homepage": "https://dash.collectui.pro",
38
+ "repository": false
39
+ }
package/src/args.mjs ADDED
@@ -0,0 +1,90 @@
1
+ const BOOLEAN_FLAGS = new Set([
2
+ "json",
3
+ "yes",
4
+ "y",
5
+ "dry-run",
6
+ "no-open",
7
+ "no-install",
8
+ "install",
9
+ "no-mcp",
10
+ "no-dash-mcp",
11
+ "no-verify",
12
+ "force",
13
+ "verbose",
14
+ "help",
15
+ "version",
16
+ "headless",
17
+ "print",
18
+ "tmp",
19
+ "new",
20
+ "include-unowned",
21
+ "no-auto-configure",
22
+ "deep",
23
+ "quiet",
24
+ ]);
25
+
26
+ const SHORT = {
27
+ y: "yes",
28
+ h: "help",
29
+ v: "verbose",
30
+ V: "version",
31
+ };
32
+
33
+ /**
34
+ * 轻量参数解析:--key value / --key=value / --flag / -y。
35
+ * 未知长参数默认按「需要值」处理(后一个不是 flag 就吃掉),避免 agent 传参时静默丢值。
36
+ */
37
+ export function parseArgv(argv) {
38
+ const flags = {};
39
+ const positionals = [];
40
+ for (let i = 0; i < argv.length; i += 1) {
41
+ const arg = argv[i];
42
+ if (arg === "--") {
43
+ positionals.push(...argv.slice(i + 1));
44
+ break;
45
+ }
46
+ if (arg.startsWith("--")) {
47
+ const raw = arg.slice(2);
48
+ const eq = raw.indexOf("=");
49
+ if (eq !== -1) {
50
+ flags[raw.slice(0, eq)] = raw.slice(eq + 1);
51
+ continue;
52
+ }
53
+ const key = raw;
54
+ if (BOOLEAN_FLAGS.has(key)) {
55
+ flags[key] = true;
56
+ continue;
57
+ }
58
+ const next = argv[i + 1];
59
+ if (next !== undefined && !next.startsWith("-")) {
60
+ flags[key] = next;
61
+ i += 1;
62
+ } else {
63
+ flags[key] = true;
64
+ }
65
+ continue;
66
+ }
67
+ if (arg.startsWith("-") && arg.length > 1) {
68
+ const key = SHORT[arg.slice(1)] ?? arg.slice(1);
69
+ if (BOOLEAN_FLAGS.has(key)) flags[key] = true;
70
+ else {
71
+ const next = argv[i + 1];
72
+ if (next !== undefined && !next.startsWith("-")) {
73
+ flags[key] = next;
74
+ i += 1;
75
+ } else flags[key] = true;
76
+ }
77
+ continue;
78
+ }
79
+ positionals.push(arg);
80
+ }
81
+ return { flags, positionals };
82
+ }
83
+
84
+ export function listFlag(value) {
85
+ if (value === undefined || value === true || value === false || value === null) return [];
86
+ return String(value)
87
+ .split(/[,\s]+/)
88
+ .map((s) => s.trim())
89
+ .filter(Boolean);
90
+ }