@collectui/cli 0.2.22 → 0.2.26
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 +16 -11
- package/package.json +1 -1
- package/src/changes.mjs +232 -36
- package/src/cli.mjs +19 -12
- package/src/commands/common.mjs +103 -2
- package/src/commands/doctor.mjs +9 -2
- package/src/commands/mcp.mjs +19 -109
- package/src/commands/setup.mjs +67 -48
- package/src/commands/whoami.mjs +22 -4
- package/src/dash.mjs +15 -96
- package/src/git-privacy.mjs +77 -0
- package/src/http.mjs +1 -17
- package/src/login.mjs +2 -1
- package/src/mcp.mjs +3 -2
- package/src/report.mjs +73 -3
- package/src/skill/SKILL.md +19 -12
- package/src/commands/dash.mjs +0 -92
package/README.md
CHANGED
|
@@ -71,7 +71,7 @@ collectui configure . --libs all --dry-run
|
|
|
71
71
|
3. **MCP**:
|
|
72
72
|
- 库有专属 MCP → 写入 `<site>` server(HTTP 端点 / stdio 包)
|
|
73
73
|
- 库没有专属 MCP → 写官方 shadcn 通用 MCP(读 `components.json` 里所有 registry)
|
|
74
|
-
-
|
|
74
|
+
- 默认写 **`collectui`** MCP(Bearer PAT),Agent 可直接调用 Dash 工具
|
|
75
75
|
- 默认写 `claude`(`.mcp.json`)、`cursor`(`.cursor/mcp.json`)、`vscode`(`.vscode/mcp.json`);`--clients codex` 写 `~/.codex/config.toml`
|
|
76
76
|
4. **`.collectui/project.json` + `.collectui/environment.md`**:机器可读的配置记录(不含密钥)
|
|
77
77
|
|
|
@@ -114,23 +114,20 @@ collectui add reui data-grid --print # 只打印命令
|
|
|
114
114
|
|
|
115
115
|
- 所有库统一走 shadcn registry → `npx shadcn@latest add @scope/<component> --yes`
|
|
116
116
|
|
|
117
|
-
`--scope @uiarc-pro` 可强制 scope;`--force`
|
|
117
|
+
`--scope @uiarc-pro` 可强制 scope;`--force` 或无头模式会给 shadcn 加 `--overwrite`,可能覆盖已有组件文件。
|
|
118
118
|
|
|
119
|
-
## MCP
|
|
119
|
+
## MCP 配置
|
|
120
120
|
|
|
121
121
|
```bash
|
|
122
122
|
collectui mcp show # 打印按 client 分组的 MCP 配置
|
|
123
123
|
collectui mcp init # 只写/合并 MCP 配置
|
|
124
|
-
collectui mcp tools # Dash MCP 工具列表
|
|
125
|
-
collectui mcp call me # 调 Dash MCP 工具
|
|
126
|
-
collectui dash me # 账户聚合(MCP,404 回退 REST)
|
|
127
|
-
collectui dash repos # 可下快照仓
|
|
128
|
-
collectui dash download owner/repo # 取新的下载链接
|
|
129
|
-
collectui dash feedback "..." --site reui
|
|
130
124
|
```
|
|
131
125
|
|
|
132
|
-
|
|
133
|
-
`me
|
|
126
|
+
CollectUI MCP(server 名 `collectui`)是 **Agent 专用**通道:端点
|
|
127
|
+
`https://dash.collectui.pro/api/mcp`(Bearer PAT),工具 `me`、
|
|
128
|
+
`list_repos`、`download_repo`、`get_site_docs` 等——Agent 用自己的
|
|
129
|
+
MCP client 直接调,CLI 不提供转发。人查账户用 `collectui whoami`,
|
|
130
|
+
可下仓库/反馈/订单在 Dash 站点看。
|
|
134
131
|
|
|
135
132
|
## 无头 / Agent 驱动
|
|
136
133
|
|
|
@@ -221,3 +218,11 @@ node src/cli.mjs --help
|
|
|
221
218
|
## License
|
|
222
219
|
|
|
223
220
|
MIT
|
|
221
|
+
|
|
222
|
+
## 已有项目:配置是否进过 Git?
|
|
223
|
+
|
|
224
|
+
- **仅在暂存区**:用 `cui doctor` 检查索引。对于 `.env.local` 等本地文件,交互式 `configure` 可单独确认停止跟踪,保留磁盘文件;`components.json` 应保留,配置 Guard 后重新暂存,用 `collectui-guard status` 复核索引。不要贴出原始 diff 或凭据。
|
|
225
|
+
- **已在本地提交**:取消跟踪只影响下一次提交。先备份,推送之前复核并清理含敏感内容的本地历史。
|
|
226
|
+
- **已推送或分享**:立即撤销或轮换相关凭据,审查访问记录,再协调历史清理。列出受影响分支和标签,在独立副本备份、清理和复核;更新远端须另行确认,通知协作者重新克隆,必要时联系托管方处理 PR 引用及缓存。fork、旧克隆和已下载的副本无法保证删除。
|
|
227
|
+
|
|
228
|
+
检查使用本机已有的 Git 引用,不会联网核实、重写历史或强推。未命中不能证明从未外发;仅命中配置路径也不能证明其中有有效密钥。无头运行不会代替用户确认清理。
|
package/package.json
CHANGED
package/src/changes.mjs
CHANGED
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
statSync,
|
|
8
8
|
writeFileSync,
|
|
9
9
|
} from "node:fs";
|
|
10
|
+
import { tmpdir } from "node:os";
|
|
10
11
|
import { dirname, relative } from "node:path";
|
|
11
12
|
import { CliError } from "./errors.mjs";
|
|
12
13
|
|
|
@@ -27,9 +28,15 @@ export class ChangeSet {
|
|
|
27
28
|
this.gitRepos = new Set();
|
|
28
29
|
}
|
|
29
30
|
|
|
31
|
+
/** 人类显示路径:displayPath 的同语义包装(JSON 侧永远走真实路径,见 show())。 */
|
|
30
32
|
rel(path) {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
+
return displayPath(path);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** 进 reporter 事件(action/preview)的路径:JSON 模式必须给真实绝对路径
|
|
37
|
+
* (Agent 拿去定位文件),只有人类显示走 rel() 缩写。 */
|
|
38
|
+
show(path) {
|
|
39
|
+
return this.reporter.json ? path : this.rel(path);
|
|
33
40
|
}
|
|
34
41
|
|
|
35
42
|
read(path) {
|
|
@@ -162,11 +169,15 @@ export class ChangeSet {
|
|
|
162
169
|
const plans = await this.plan();
|
|
163
170
|
if (plans.length === 0) {
|
|
164
171
|
this.reporter.info("No changes — everything is already configured.");
|
|
165
|
-
return { files: [], runs: [], skipped: true };
|
|
172
|
+
return { files: [], runs: [], skipped: true, dryRun: this.dryRun };
|
|
166
173
|
}
|
|
167
174
|
|
|
168
175
|
if (this.dryRun) {
|
|
169
|
-
|
|
176
|
+
if (this.reporter.json) {
|
|
177
|
+
for (const item of plans) this.reporter.action({ ...item, status: "planned" });
|
|
178
|
+
} else {
|
|
179
|
+
this.reporter.note("Plan", renderPlanTree(plans, this));
|
|
180
|
+
}
|
|
170
181
|
for (const file of this.pendingFiles()) {
|
|
171
182
|
if (this.reporter.verbose || this.dryRun) {
|
|
172
183
|
this.reporter.preview(
|
|
@@ -179,17 +190,14 @@ export class ChangeSet {
|
|
|
179
190
|
return { files: this.pendingFiles(), runs: [], dryRun: true };
|
|
180
191
|
}
|
|
181
192
|
|
|
182
|
-
if (
|
|
183
|
-
this.reporter.
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
.map((p) => `- ${p.kind}${p.path ? ` ${this.rel(p.path)}` : ""}${p.summary ? ` — ${p.summary}` : ""}`)
|
|
187
|
-
.join("\n")
|
|
188
|
-
);
|
|
193
|
+
if (this.reporter.json) {
|
|
194
|
+
for (const item of plans) this.reporter.action({ ...item, status: "planned" });
|
|
195
|
+
} else {
|
|
196
|
+
this.reporter.note("Plan", renderPlanTree(plans, this));
|
|
189
197
|
}
|
|
190
198
|
|
|
191
199
|
const ok = await this.reporter.confirm(
|
|
192
|
-
`Apply ${plans.length} action(s) to ${this.root}?`,
|
|
200
|
+
`Apply ${plans.length} action(s) to ${this.rel(this.root)}?`,
|
|
193
201
|
{ defaultValue: true }
|
|
194
202
|
);
|
|
195
203
|
if (!ok) {
|
|
@@ -197,10 +205,20 @@ export class ChangeSet {
|
|
|
197
205
|
return { files: [], runs: [], aborted: true };
|
|
198
206
|
}
|
|
199
207
|
|
|
208
|
+
// 执行段输出(2026-12-06 用户定案「选择 Yes 后精简」):人类非 verbose 模式
|
|
209
|
+
// 不再逐条重播计划(Plan 树已完整展示),收敛为 run 逐条提示 + 一行统计;
|
|
210
|
+
// JSON 事件流与 verbose 逐条不变(Agent 契约 / 调试口径不受影响)。
|
|
211
|
+
const chatty = this.reporter.json || this.reporter.verbose;
|
|
212
|
+
const nDirs = { created: 0 };
|
|
213
|
+
const nFiles = { created: 0, updated: 0 };
|
|
214
|
+
let gitInit = "none";
|
|
215
|
+
|
|
200
216
|
for (const dir of [...this.dirs]) {
|
|
201
217
|
if (!existsSync(dir)) {
|
|
202
218
|
mkdirSync(dir, { recursive: true, mode: 0o755 });
|
|
203
|
-
|
|
219
|
+
nDirs.created++;
|
|
220
|
+
if (chatty)
|
|
221
|
+
this.reporter.action({ kind: "mkdir", path: this.rel(dir), summary: "create directory", status: "created" });
|
|
204
222
|
}
|
|
205
223
|
}
|
|
206
224
|
|
|
@@ -216,56 +234,234 @@ export class ChangeSet {
|
|
|
216
234
|
}
|
|
217
235
|
}
|
|
218
236
|
written.push(file);
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
237
|
+
nFiles[file.status === "updated" ? "updated" : "created"]++;
|
|
238
|
+
if (chatty)
|
|
239
|
+
this.reporter.action({
|
|
240
|
+
kind: "write",
|
|
241
|
+
path: this.rel(file.path),
|
|
242
|
+
summary: file.summary,
|
|
243
|
+
status: file.status,
|
|
244
|
+
changes: file.changes,
|
|
245
|
+
});
|
|
226
246
|
}
|
|
227
247
|
|
|
228
248
|
for (const repo of this.gitRepos) {
|
|
229
249
|
if (isGitRepo(repo)) {
|
|
230
|
-
|
|
250
|
+
gitInit = "existing";
|
|
251
|
+
if (chatty)
|
|
252
|
+
this.reporter.action({ kind: "git-init", path: this.rel(repo), summary: "already a git repo (skipped)", status: "unchanged" });
|
|
231
253
|
continue;
|
|
232
254
|
}
|
|
233
255
|
await exec("git", ["init", "-q"], { cwd: repo });
|
|
234
|
-
|
|
256
|
+
gitInit = "initialized";
|
|
257
|
+
if (chatty)
|
|
258
|
+
this.reporter.action({ kind: "git-init", path: this.rel(repo), summary: "git initialized", status: "created" });
|
|
235
259
|
}
|
|
236
260
|
|
|
237
261
|
for (const run of this.runs) {
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
262
|
+
if (chatty)
|
|
263
|
+
this.reporter.action({
|
|
264
|
+
kind: "run",
|
|
265
|
+
command: [run.command, ...run.args].join(" "),
|
|
266
|
+
path: this.rel(run.cwd),
|
|
267
|
+
summary: run.summary,
|
|
268
|
+
status: "running",
|
|
269
|
+
});
|
|
270
|
+
const release = this.reporter.activity(`${run.summary ?? "running"} (${[run.command, ...run.args].join(" ")})`);
|
|
245
271
|
const code = await exec(run.command, run.args, {
|
|
246
272
|
cwd: run.cwd,
|
|
247
273
|
env: { ...process.env, ...run.env },
|
|
248
274
|
quiet: run.quiet,
|
|
249
275
|
});
|
|
276
|
+
release();
|
|
250
277
|
if (code !== 0) {
|
|
251
278
|
throw new CliError(
|
|
252
279
|
`Command failed (exit ${code}): ${[run.command, ...run.args].join(" ")}`,
|
|
253
280
|
{ hint: "The files already written stay in place; fix the issue and re-run the same command (idempotent)." }
|
|
254
281
|
);
|
|
255
282
|
}
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
283
|
+
if (chatty)
|
|
284
|
+
this.reporter.action({
|
|
285
|
+
kind: "run",
|
|
286
|
+
command: [run.command, ...run.args].join(" "),
|
|
287
|
+
path: this.rel(run.cwd),
|
|
288
|
+
summary: "command completed",
|
|
289
|
+
status: "created",
|
|
290
|
+
});
|
|
291
|
+
else this.reporter.success(run.summary ?? [run.command, ...run.args].join(" "));
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
if (!chatty) {
|
|
295
|
+
const parts = [];
|
|
296
|
+
if (nFiles.created) parts.push(`${nFiles.created} created`);
|
|
297
|
+
if (nFiles.updated) parts.push(`${nFiles.updated} updated`);
|
|
298
|
+
if (nDirs.created) parts.push(`${nDirs.created} dir${nDirs.created > 1 ? "s" : ""}`);
|
|
299
|
+
if (gitInit === "initialized") parts.push("git initialized");
|
|
300
|
+
this.reporter.success(parts.length ? `Applied: ${parts.join(" · ")}` : "Applied (no changes)");
|
|
263
301
|
}
|
|
264
302
|
|
|
265
303
|
return { files: written, runs: this.runs, dryRun: false };
|
|
266
304
|
}
|
|
267
305
|
}
|
|
268
306
|
|
|
307
|
+
/** 人类显示路径(Changeset 外也可用):cwd 内相对化;cwd 外把 OS tmp / 家目录
|
|
308
|
+
* 前缀缩写(init 默认落 os.tmpdir(),macOS 是 /var/folders/…/T 这种 per-user
|
|
309
|
+
* 长路径,原样打印能把输出撑到爆宽,窄终端直接折行错位)。
|
|
310
|
+
* 仅限人类显示——JSON 事件永远给真实绝对路径(Agent 拿去定位文件)。 */
|
|
311
|
+
export function displayPath(path) {
|
|
312
|
+
const r = relative(process.cwd(), path);
|
|
313
|
+
if (r && !r.startsWith("..")) return r;
|
|
314
|
+
return shortenOutside(path);
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
/** cwd 之外路径的显示缩写:$TMPDIR / ~。 */
|
|
318
|
+
function shortenOutside(path) {
|
|
319
|
+
const tmp = tmpdir();
|
|
320
|
+
if (tmp && tmp !== "/" && (path === tmp || path.startsWith(`${tmp}/`))) {
|
|
321
|
+
return path === tmp ? "$TMPDIR" : `$TMPDIR/${path.slice(tmp.length + 1)}`;
|
|
322
|
+
}
|
|
323
|
+
const home = process.env.HOME;
|
|
324
|
+
if (home && home !== "/" && (path === home || path.startsWith(`${home}/`))) {
|
|
325
|
+
return path === home ? "~" : `~/${path.slice(home.length + 1)}`;
|
|
326
|
+
}
|
|
327
|
+
return path;
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
/** 树形 Plan 渲染(仅人类 TTY;JSON 事件不受影响)。
|
|
331
|
+
* - 根目录一行(rel 缩写),文件按目录层级展开;mkdir 条目被结构吸收
|
|
332
|
+
* (目录行尾 + 表示将创建),不再逐条平铺
|
|
333
|
+
* - 单子目录链合并压层级(src/components/ui 合成一个节点)
|
|
334
|
+
* - 精简配色:根目录加粗、目录 cyan、+ 绿 / ~ 黄、说明 dim;
|
|
335
|
+
* 非 TTY / NO_COLOR 退化为纯文本
|
|
336
|
+
* - git-init / run / 根外路径(如 codex 的 ~/.codex/config.toml)
|
|
337
|
+
* 不进树,收尾单列 */
|
|
338
|
+
export function renderPlanTree(plans, changeset) {
|
|
339
|
+
const root = changeset.root;
|
|
340
|
+
const inRoot = (p) => {
|
|
341
|
+
const r = relative(root, p);
|
|
342
|
+
return r && !r.startsWith("..") ? r : null;
|
|
343
|
+
};
|
|
344
|
+
const mkdirs = new Set(
|
|
345
|
+
plans.filter((x) => x.kind === "mkdir").map((x) => x.path)
|
|
346
|
+
);
|
|
347
|
+
const writes = [];
|
|
348
|
+
const tail = [];
|
|
349
|
+
for (const item of plans) {
|
|
350
|
+
if (item.kind === "mkdir") continue;
|
|
351
|
+
if (item.kind === "write") {
|
|
352
|
+
const r = inRoot(item.path);
|
|
353
|
+
if (r !== null) {
|
|
354
|
+
writes.push({
|
|
355
|
+
segs: r.split("/"),
|
|
356
|
+
icon: item.status === "updated" ? "~" : "+",
|
|
357
|
+
summary: item.summary,
|
|
358
|
+
});
|
|
359
|
+
continue;
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
tail.push(item);
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
// 构树:目录节点 {dirs: Map, file?, created?}
|
|
366
|
+
const tree = { dirs: new Map() };
|
|
367
|
+
for (const dir of mkdirs) {
|
|
368
|
+
const r = inRoot(dir);
|
|
369
|
+
if (r === null) continue;
|
|
370
|
+
let node = tree;
|
|
371
|
+
for (const seg of r.split("/")) {
|
|
372
|
+
if (!node.dirs.has(seg)) node.dirs.set(seg, { dirs: new Map() });
|
|
373
|
+
node = node.dirs.get(seg);
|
|
374
|
+
}
|
|
375
|
+
node.created = true;
|
|
376
|
+
}
|
|
377
|
+
for (const w of writes) {
|
|
378
|
+
let node = tree;
|
|
379
|
+
for (let i = 0; i < w.segs.length - 1; i++) {
|
|
380
|
+
const seg = w.segs[i];
|
|
381
|
+
if (!node.dirs.has(seg)) node.dirs.set(seg, { dirs: new Map() });
|
|
382
|
+
node = node.dirs.get(seg);
|
|
383
|
+
}
|
|
384
|
+
node.dirs.set(w.segs[w.segs.length - 1], {
|
|
385
|
+
dirs: new Map(),
|
|
386
|
+
file: { icon: w.icon, summary: w.summary },
|
|
387
|
+
});
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
const c = colorizer();
|
|
391
|
+
const lines = [];
|
|
392
|
+
const rootLabel = changeset.rel(root).replace(/\/+$/, "");
|
|
393
|
+
lines.push(c.bold(`${rootLabel}/`));
|
|
394
|
+
|
|
395
|
+
const walk = (node, prefix) => {
|
|
396
|
+
const kids = [...node.dirs.entries()];
|
|
397
|
+
kids.forEach(([name, kid], i) => {
|
|
398
|
+
const last = i === kids.length - 1;
|
|
399
|
+
const branch = last ? "└─ " : "├─ ";
|
|
400
|
+
// 单子目录链合并:中间目录(无文件、仅一个子目录)折叠进一个节点
|
|
401
|
+
let label = name;
|
|
402
|
+
let leaf = kid;
|
|
403
|
+
while (!leaf.file && leaf.dirs.size === 1) {
|
|
404
|
+
const [only] = [...leaf.dirs.entries()];
|
|
405
|
+
if (only[1].file) break;
|
|
406
|
+
label += `/${only[0]}`;
|
|
407
|
+
leaf = only[1];
|
|
408
|
+
}
|
|
409
|
+
if (leaf.file) {
|
|
410
|
+
const f = leaf.file;
|
|
411
|
+
let note = f.summary ? stripName(f.summary, label).trim() : "";
|
|
412
|
+
if (note) lines.push(`${prefix}${branch}${label}${f.icon === "+" ? ` ${c.green("+")}` : ` ${c.yellow("~")}`} ${c.dim(truncateLabel(note))}`);
|
|
413
|
+
else lines.push(`${prefix}${branch}${label}${f.icon === "+" ? ` ${c.green("+")}` : ` ${c.yellow("~")}`}`);
|
|
414
|
+
} else {
|
|
415
|
+
const mark = leaf.created ? ` ${c.green("+")}` : "";
|
|
416
|
+
lines.push(`${prefix}${branch}${c.cyan(`${label}/`)}${mark}`);
|
|
417
|
+
walk(leaf, `${prefix}${last ? " " : "│ "}`);
|
|
418
|
+
}
|
|
419
|
+
});
|
|
420
|
+
};
|
|
421
|
+
walk(tree, "");
|
|
422
|
+
|
|
423
|
+
if (tail.length) {
|
|
424
|
+
lines.push("");
|
|
425
|
+
for (const item of tail) {
|
|
426
|
+
const icon = item.kind === "run" ? "·" : "+";
|
|
427
|
+
const where = item.path && item.path !== root ? ` ${c.dim(changeset.rel(item.path))}` : "";
|
|
428
|
+
const cmd = item.command ? ` ${c.cyan(item.command)}` : "";
|
|
429
|
+
const note = item.summary ? ` — ${c.dim(truncateLabel(item.summary))}` : "";
|
|
430
|
+
lines.push(`${icon}${cmd}${where}${note}`);
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
return lines.join("\n");
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
/** 说明文案截断:树形行宽可控(小屏终端放得下)。 */
|
|
437
|
+
function truncateLabel(text, max = 56) {
|
|
438
|
+
const t = String(text);
|
|
439
|
+
return t.length > max ? `${t.slice(0, max - 1)}…` : t;
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
/** 说明里的重复路径剥除:scaffold 的 summary 是「create button.tsx (…)」形态,
|
|
443
|
+
* 树形行已展示文件名,前缀路径段剥掉只留括注。 */
|
|
444
|
+
function stripName(summary, label) {
|
|
445
|
+
const base = label.split("/").pop();
|
|
446
|
+
return String(summary).replace(
|
|
447
|
+
new RegExp(`^(?:create|write|update)\\s+(?:\\S*[/\\\\])?${base.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}\\s*`, "i"),
|
|
448
|
+
""
|
|
449
|
+
);
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
/** 精简配色器:TTY 且未设 NO_COLOR 才上色;红绿黄青 + 加粗 + 暗淡各一处。 */
|
|
453
|
+
function colorizer() {
|
|
454
|
+
const on = process.stdout.isTTY && !process.env.NO_COLOR;
|
|
455
|
+
const wrap = (code) => (s) => (on ? `\x1b[${code}m${s}\x1b[0m` : s);
|
|
456
|
+
return {
|
|
457
|
+
bold: wrap("1"),
|
|
458
|
+
dim: wrap("2"),
|
|
459
|
+
green: wrap("32"),
|
|
460
|
+
yellow: wrap("33"),
|
|
461
|
+
cyan: wrap("36"),
|
|
462
|
+
};
|
|
463
|
+
}
|
|
464
|
+
|
|
269
465
|
function exec(command, args, { cwd, env, quiet = false }) {
|
|
270
466
|
return new Promise((resolve, reject) => {
|
|
271
467
|
const isJson = process.env.COLLECTUI_JSON === "1";
|
package/src/cli.mjs
CHANGED
|
@@ -24,7 +24,6 @@ import { configureCmd } from "./commands/configure.mjs";
|
|
|
24
24
|
import { addCmd } from "./commands/add.mjs";
|
|
25
25
|
import { doctorCmd } from "./commands/doctor.mjs";
|
|
26
26
|
import { mcpCmd } from "./commands/mcp.mjs";
|
|
27
|
-
import { dashCmd } from "./commands/dash.mjs";
|
|
28
27
|
import { skillCmd } from "./commands/skill.mjs";
|
|
29
28
|
import { updateCmd } from "./commands/update.mjs";
|
|
30
29
|
|
|
@@ -40,8 +39,7 @@ Commands:
|
|
|
40
39
|
init [dir] Scaffold a fresh shadcn project and configure libraries (no dir: OS temp dir)
|
|
41
40
|
configure [dir] Configure an existing shadcn project
|
|
42
41
|
add <lib> <comp...> Install components with the library's channel
|
|
43
|
-
mcp <sub>
|
|
44
|
-
dash <sub> Dash MCP: me, repos, download, feedback, tools, call
|
|
42
|
+
mcp <sub> Manage MCP servers for your agents: show / init config
|
|
45
43
|
skill [dir] Install the agent skill (.claude/skills/collectui)
|
|
46
44
|
doctor Verify login, registries, env and MCP config
|
|
47
45
|
update Update the CLI now (--check only checks)
|
|
@@ -57,7 +55,7 @@ Global options:
|
|
|
57
55
|
--pat login: paste a PAT instead of browser authorization (no-browser hosts)
|
|
58
56
|
--no-install init: skip dependency installation
|
|
59
57
|
--no-mcp init/configure: skip MCP configuration
|
|
60
|
-
--no-dash-mcp Do not add the
|
|
58
|
+
--no-dash-mcp Do not add the CollectUI MCP (collectui) server
|
|
61
59
|
--force Replace custom registry/MCP entries (deliberate)
|
|
62
60
|
--libs <list> Comma list or "all" (default: all owned)
|
|
63
61
|
--clients <list> claude,cursor,vscode,codex or all (default: claude,cursor,vscode)
|
|
@@ -82,7 +80,6 @@ Examples:
|
|
|
82
80
|
cui configure . --libs all --dry-run
|
|
83
81
|
cui add reui data-grid
|
|
84
82
|
cui mcp show --json
|
|
85
|
-
cui dash repos --json
|
|
86
83
|
COLLECTUI_TOKEN=dpat_... cui whoami --json
|
|
87
84
|
|
|
88
85
|
Environment:
|
|
@@ -102,7 +99,6 @@ const COMMANDS = {
|
|
|
102
99
|
configure: { run: configureCmd, aliases: ["config", "setup"] },
|
|
103
100
|
add: { run: addCmd, aliases: ["install"] },
|
|
104
101
|
mcp: { run: mcpCmd, aliases: [] },
|
|
105
|
-
dash: { run: dashCmd, aliases: [] },
|
|
106
102
|
skill: { run: skillCmd, aliases: ["install-skill"] },
|
|
107
103
|
doctor: { run: doctorCmd, aliases: ["check"] },
|
|
108
104
|
update: { run: updateCmd, aliases: ["upgrade"] },
|
|
@@ -121,9 +117,10 @@ function findCommand(name) {
|
|
|
121
117
|
* skill 只落一个文件,都读不到目录。whoami 标了 parallel——入口不等目录,命令里把
|
|
122
118
|
* 目录与账号两请求同 tick 并行发出(谁慢等谁,省掉串行那一趟)。
|
|
123
119
|
*/
|
|
124
|
-
const CATALOG_SKIP = new Set(["login", "logout", "update", "
|
|
120
|
+
const CATALOG_SKIP = new Set(["login", "logout", "update", "skill"]);
|
|
125
121
|
|
|
126
|
-
function printHelp() {
|
|
122
|
+
function printHelp(headless = false) {
|
|
123
|
+
showBanner({ headless }); // help 也是人肉场景:开机画面与其他子命令同款(headless/--json/非 TTY 降级为纯 HELP)
|
|
127
124
|
process.stdout.write(HELP);
|
|
128
125
|
}
|
|
129
126
|
|
|
@@ -131,6 +128,16 @@ function printVersion() {
|
|
|
131
128
|
process.stdout.write(`${CLI_NAME} ${CLI_VERSION}\n`);
|
|
132
129
|
}
|
|
133
130
|
|
|
131
|
+
/** help 分流发生在 makeReporter 之前:headless 判定照抄 createReporter 的公式。 */
|
|
132
|
+
function isHeadless(flags) {
|
|
133
|
+
return Boolean(
|
|
134
|
+
flags.json ||
|
|
135
|
+
process.env.COLLECTUI_JSON === "1" ||
|
|
136
|
+
flags.headless ||
|
|
137
|
+
!process.stdout.isTTY
|
|
138
|
+
);
|
|
139
|
+
}
|
|
140
|
+
|
|
134
141
|
function makeReporter(flags, token) {
|
|
135
142
|
const json = Boolean(flags.json) || process.env.COLLECTUI_JSON === "1";
|
|
136
143
|
const config = readConfig();
|
|
@@ -150,15 +157,15 @@ async function main() {
|
|
|
150
157
|
if (flags.json) process.env.COLLECTUI_JSON = "1";
|
|
151
158
|
|
|
152
159
|
if (flags.version || flags.V) return printVersion();
|
|
153
|
-
if (flags.help) return printHelp();
|
|
160
|
+
if (flags.help) return printHelp(isHeadless(flags));
|
|
154
161
|
|
|
155
162
|
const name = positionals[0];
|
|
156
163
|
if (!name) {
|
|
157
|
-
printHelp();
|
|
164
|
+
printHelp(isHeadless(flags));
|
|
158
165
|
return;
|
|
159
166
|
}
|
|
160
167
|
if (name === "help" || name === "--help" || name === "-h" || name === "?") {
|
|
161
|
-
printHelp();
|
|
168
|
+
printHelp(isHeadless(flags));
|
|
162
169
|
return;
|
|
163
170
|
}
|
|
164
171
|
const command = findCommand(name);
|
|
@@ -170,7 +177,7 @@ async function main() {
|
|
|
170
177
|
const reporter = makeReporter(flags, token);
|
|
171
178
|
if (token) reporter.addSecrets([token]);
|
|
172
179
|
|
|
173
|
-
showBanner(reporter); // 开机画面:任何子命令(headless/--version
|
|
180
|
+
showBanner(reporter); // 开机画面:任何子命令(headless/--version 已在前面分流;help 走 printHelp 自带同款)
|
|
174
181
|
// 更新检查最先出发:与目录/账号请求并行,命令收尾时多半已查完(少等收尾那 1 秒)。
|
|
175
182
|
// TTY 才查,有新版打一行提醒;手动 update 命令自身不触发(避免与前台安装并发写全局目录)
|
|
176
183
|
const updateNotice =
|
package/src/commands/common.mjs
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import * as p from "@clack/prompts";
|
|
2
|
+
import { spawnSync } from "node:child_process";
|
|
3
|
+
import { existsSync } from "node:fs";
|
|
2
4
|
import { listFlag } from "../args.mjs";
|
|
3
5
|
import {
|
|
4
6
|
activeCatalog,
|
|
@@ -8,7 +10,7 @@ import {
|
|
|
8
10
|
ownedLibs,
|
|
9
11
|
} from "../catalog.mjs";
|
|
10
12
|
import { resolveToken } from "../config.mjs";
|
|
11
|
-
import { authError, usageError } from "../errors.mjs";
|
|
13
|
+
import { authError, CliError, usageError } from "../errors.mjs";
|
|
12
14
|
import { fetchAccount } from "../dash.mjs";
|
|
13
15
|
|
|
14
16
|
export function requireToken(flags, reporter) {
|
|
@@ -121,9 +123,108 @@ export function catalogSummary() {
|
|
|
121
123
|
return activeCatalog().libs.map((lib) => ({
|
|
122
124
|
site: lib.site,
|
|
123
125
|
name: lib.siteName,
|
|
124
|
-
source
|
|
126
|
+
// source = registry 源名(bits→reactbits / space→shadcn-space 这类真实不同才输出;
|
|
127
|
+
// 与 site 同值时省略——消费侧回退 `source ?? site`(2026-12-06 用户反馈去重复)
|
|
128
|
+
...(lib.source !== lib.site ? { source: lib.source } : {}),
|
|
125
129
|
registries: (lib.registries ?? []).map((r) => r.scope),
|
|
126
130
|
mcp: lib.mcp ?? null,
|
|
127
131
|
shadcnUiMcp: Boolean(lib.shadcnUiMcp),
|
|
128
132
|
}));
|
|
129
133
|
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* MCP client 的本机安装探测(2026-12-06「dash 固定了 Agent 但本机还没装」):
|
|
137
|
+
* 只做轻量本机检查(which / 常见目录),探测不到 ≠ 没装(PATH 不全的 GUI 环境
|
|
138
|
+
* 会漏报)——用途仅是给一句「装好后配置自动生效」的提示,绝不阻塞写入。
|
|
139
|
+
*/
|
|
140
|
+
export function detectClientApp(client) {
|
|
141
|
+
try {
|
|
142
|
+
const finder = process.platform === "win32" ? "where" : "which";
|
|
143
|
+
const hit = spawnSync(finder, [client === "vscode" ? "code" : client], {
|
|
144
|
+
encoding: "utf8",
|
|
145
|
+
timeout: 3000,
|
|
146
|
+
});
|
|
147
|
+
if (hit.status === 0) return true;
|
|
148
|
+
} catch {
|
|
149
|
+
// which 不可用(极端 Windows 等)——落到目录探测
|
|
150
|
+
}
|
|
151
|
+
const home = process.env.HOME ?? "";
|
|
152
|
+
const marks = {
|
|
153
|
+
claude: [home ? `${home}/.claude` : null],
|
|
154
|
+
codex: [home ? `${home}/.codex` : null],
|
|
155
|
+
cursor: [
|
|
156
|
+
process.platform === "darwin" ? "/Applications/Cursor.app" : null,
|
|
157
|
+
home ? `${home}/.cursor` : null,
|
|
158
|
+
],
|
|
159
|
+
vscode: [
|
|
160
|
+
process.platform === "darwin" ? "/Applications/Visual Studio Code.app" : null,
|
|
161
|
+
],
|
|
162
|
+
};
|
|
163
|
+
return (marks[client] ?? []).some((m) => !!m && existsSync(m));
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
const DEFAULT_CLIENTS = ["claude", "cursor", "vscode"];
|
|
167
|
+
export const ALL_CLIENTS = ["claude", "cursor", "codex", "vscode"];
|
|
168
|
+
|
|
169
|
+
/** 多选 UI 的选项面(显示顺序与 ALL_CLIENTS 一致,label 带写入目标一目了然) */
|
|
170
|
+
export const CLIENT_OPTIONS = [
|
|
171
|
+
{ value: "claude", label: "Claude Code — .mcp.json" },
|
|
172
|
+
{ value: "codex", label: "Codex — ~/.codex/config.toml" },
|
|
173
|
+
{ value: "cursor", label: "Cursor — .cursor/mcp.json" },
|
|
174
|
+
{ value: "vscode", label: "VS Code — .vscode/mcp.json" },
|
|
175
|
+
];
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* MCP client 集决策(2026-12-06 用户定案「用 dash 上选择的 Agent」):
|
|
179
|
+
* 1. --clients 显式给 → 按它(all = 全部四家)
|
|
180
|
+
* 2. 否则取 dash 账户 pin 的 Agent(copy-agent-pinned)∩ CLI 支持四家
|
|
181
|
+
* 3. 都没有 → 默认三件套(claude/cursor/vscode,codex 按需)
|
|
182
|
+
* pinnedAgents 里 CLI 写不了的 Agent(deepseek/trae 等)不在此处理——
|
|
183
|
+
* 调用方负责提示去 dash 站点卡的 AI Tools 弹窗复制配置块。
|
|
184
|
+
*/
|
|
185
|
+
export function resolveClients(flags, pinnedAgents = []) {
|
|
186
|
+
const raw = flags.clients;
|
|
187
|
+
if (!raw) {
|
|
188
|
+
const pinned = [...new Set(pinnedAgents)].filter((a) =>
|
|
189
|
+
ALL_CLIENTS.includes(a)
|
|
190
|
+
);
|
|
191
|
+
return pinned.length ? pinned : DEFAULT_CLIENTS;
|
|
192
|
+
}
|
|
193
|
+
const list = String(raw)
|
|
194
|
+
.split(/[,\s]+/)
|
|
195
|
+
.map((s) => s.trim().toLowerCase())
|
|
196
|
+
.filter(Boolean);
|
|
197
|
+
if (list.includes("all")) return ALL_CLIENTS;
|
|
198
|
+
const unknown = list.filter((c) => !ALL_CLIENTS.includes(c));
|
|
199
|
+
if (unknown.length) {
|
|
200
|
+
throw new CliError(`Unknown MCP client(s): ${unknown.join(", ")}`, {
|
|
201
|
+
code: 2,
|
|
202
|
+
hint: `Supported: ${ALL_CLIENTS.join(", ")}, all`,
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
return [...new Set(list)];
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/** client 决策全链(setup 与 mcp 命令共用):--clients > dash pin 集 > 默认三件套;
|
|
209
|
+
* 交互模式下多选让用户挑(预选默认集,空选确认 = 全部);dash 固定了 CLI
|
|
210
|
+
* 写不了的 Agent(deepseek/trae 等)提示去站点卡 AI Tools 弹窗复制。 */
|
|
211
|
+
export async function chooseClients(flags, me, reporter, { interactive = true } = {}) {
|
|
212
|
+
let clients = resolveClients(flags, me?.pinnedAgents ?? []);
|
|
213
|
+
const unsupportedPins = [...new Set(me?.pinnedAgents ?? [])].filter(
|
|
214
|
+
(a) => !ALL_CLIENTS.includes(a)
|
|
215
|
+
);
|
|
216
|
+
if (unsupportedPins.length && !reporter.json) {
|
|
217
|
+
reporter.info(
|
|
218
|
+
`Also pinned on dash: ${unsupportedPins.join(", ")} — no CLI writer yet; copy their config from the site card's AI Tools dialog.`
|
|
219
|
+
);
|
|
220
|
+
}
|
|
221
|
+
if (interactive && !flags.clients && !reporter.headless && !reporter.yes) {
|
|
222
|
+
const chosen = await reporter.multiSelect(
|
|
223
|
+
"Configure MCP for which agents? (confirm with none = all)",
|
|
224
|
+
CLIENT_OPTIONS,
|
|
225
|
+
{ selected: clients }
|
|
226
|
+
);
|
|
227
|
+
if (chosen) clients = chosen.length ? chosen : ALL_CLIENTS;
|
|
228
|
+
}
|
|
229
|
+
return clients;
|
|
230
|
+
}
|
package/src/commands/doctor.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { auditGit } from "../git-privacy.mjs";
|
|
1
2
|
import { existsSync, readFileSync } from "node:fs";
|
|
2
3
|
import { join, resolve } from "node:path";
|
|
3
4
|
import { activeCatalog, ownedLibs, registryUrl, resolveLibKeys } from "../catalog.mjs";
|
|
@@ -36,16 +37,22 @@ export async function doctorCmd(flags, rest, reporter) {
|
|
|
36
37
|
if (token) {
|
|
37
38
|
try {
|
|
38
39
|
const tools = await dashMcpTools(token, { reporter });
|
|
39
|
-
|
|
40
|
+
// 工具名全列表一行几百字符会撑爆面板——只报数量 + 前几个,Agent 侧全量在 MCP client 里看
|
|
41
|
+
add(
|
|
42
|
+
"collectui mcp",
|
|
43
|
+
"ok",
|
|
44
|
+
`${tools.length} tools (${tools.slice(0, 3).map((t) => t.name).join(", ")}…)`
|
|
45
|
+
);
|
|
40
46
|
} catch (error) {
|
|
41
47
|
const status = /404|not enabled/i.test(error.message) ? "warn" : "fail";
|
|
42
|
-
add("
|
|
48
|
+
add("collectui mcp", status, error.message);
|
|
43
49
|
}
|
|
44
50
|
}
|
|
45
51
|
|
|
46
52
|
// 项目检查
|
|
47
53
|
const detected = detectProjectRoot(flags.cwd ? resolve(String(flags.cwd)) : process.cwd());
|
|
48
54
|
const root = detected.root;
|
|
55
|
+
for (const message of auditGit(root).messages) add("git privacy", "warn", message);
|
|
49
56
|
const componentsPath = join(root, "components.json");
|
|
50
57
|
if (!existsSync(componentsPath)) {
|
|
51
58
|
add("project", "warn", `no components.json under ${root}`);
|