@collectui/cli 0.2.23 → 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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@collectui/cli",
3
- "version": "0.2.23",
3
+ "version": "0.2.26",
4
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",
package/src/changes.mjs CHANGED
@@ -28,13 +28,9 @@ export class ChangeSet {
28
28
  this.gitRepos = new Set();
29
29
  }
30
30
 
31
- /** 人类显示路径:cwd 内相对化;cwd 外把 OS tmp / 家目录前缀缩写——init 默认
32
- * 落 os.tmpdir()(macOS 是 /var/folders/_g/…/T 这种 per-user 长路径),原样
33
- * 打印能把 Plan 面板撑到爆宽,窄终端直接折行错位。 */
31
+ /** 人类显示路径:displayPath 的同语义包装(JSON 侧永远走真实路径,见 show())。 */
34
32
  rel(path) {
35
- const r = relative(process.cwd(), path);
36
- if (r && !r.startsWith("..")) return r;
37
- return shortenOutside(path);
33
+ return displayPath(path);
38
34
  }
39
35
 
40
36
  /** 进 reporter 事件(action/preview)的路径:JSON 模式必须给真实绝对路径
@@ -177,7 +173,11 @@ export class ChangeSet {
177
173
  }
178
174
 
179
175
  if (this.dryRun) {
180
- for (const item of plans) this.reporter.action({ ...item, status: "planned" });
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
+ }
181
181
  for (const file of this.pendingFiles()) {
182
182
  if (this.reporter.verbose || this.dryRun) {
183
183
  this.reporter.preview(
@@ -190,17 +190,14 @@ export class ChangeSet {
190
190
  return { files: this.pendingFiles(), runs: [], dryRun: true };
191
191
  }
192
192
 
193
- if (!this.reporter.json) {
194
- this.reporter.note(
195
- "Plan",
196
- plans
197
- .map((p) => `- ${p.kind}${p.path ? ` ${this.rel(p.path)}` : ""}${p.summary ? ` — ${p.summary}` : ""}`)
198
- .join("\n")
199
- );
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));
200
197
  }
201
198
 
202
199
  const ok = await this.reporter.confirm(
203
- `Apply ${plans.length} action(s) to ${this.root}?`,
200
+ `Apply ${plans.length} action(s) to ${this.rel(this.root)}?`,
204
201
  { defaultValue: true }
205
202
  );
206
203
  if (!ok) {
@@ -208,10 +205,20 @@ export class ChangeSet {
208
205
  return { files: [], runs: [], aborted: true };
209
206
  }
210
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
+
211
216
  for (const dir of [...this.dirs]) {
212
217
  if (!existsSync(dir)) {
213
218
  mkdirSync(dir, { recursive: true, mode: 0o755 });
214
- this.reporter.action({ kind: "mkdir", path: this.rel(dir), summary: "create directory", status: "created" });
219
+ nDirs.created++;
220
+ if (chatty)
221
+ this.reporter.action({ kind: "mkdir", path: this.rel(dir), summary: "create directory", status: "created" });
215
222
  }
216
223
  }
217
224
 
@@ -227,57 +234,87 @@ export class ChangeSet {
227
234
  }
228
235
  }
229
236
  written.push(file);
230
- this.reporter.action({
231
- kind: "write",
232
- path: this.rel(file.path),
233
- summary: file.summary,
234
- status: file.status,
235
- changes: file.changes,
236
- });
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
+ });
237
246
  }
238
247
 
239
248
  for (const repo of this.gitRepos) {
240
249
  if (isGitRepo(repo)) {
241
- this.reporter.action({ kind: "git-init", path: this.rel(repo), summary: "already a git repo (skipped)", status: "unchanged" });
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" });
242
253
  continue;
243
254
  }
244
255
  await exec("git", ["init", "-q"], { cwd: repo });
245
- this.reporter.action({ kind: "git-init", path: this.rel(repo), summary: "git initialized", status: "created" });
256
+ gitInit = "initialized";
257
+ if (chatty)
258
+ this.reporter.action({ kind: "git-init", path: this.rel(repo), summary: "git initialized", status: "created" });
246
259
  }
247
260
 
248
261
  for (const run of this.runs) {
249
- this.reporter.action({
250
- kind: "run",
251
- command: [run.command, ...run.args].join(" "),
252
- path: this.rel(run.cwd),
253
- summary: run.summary,
254
- status: "running",
255
- });
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(" ")})`);
256
271
  const code = await exec(run.command, run.args, {
257
272
  cwd: run.cwd,
258
273
  env: { ...process.env, ...run.env },
259
274
  quiet: run.quiet,
260
275
  });
276
+ release();
261
277
  if (code !== 0) {
262
278
  throw new CliError(
263
279
  `Command failed (exit ${code}): ${[run.command, ...run.args].join(" ")}`,
264
280
  { hint: "The files already written stay in place; fix the issue and re-run the same command (idempotent)." }
265
281
  );
266
282
  }
267
- this.reporter.action({
268
- kind: "run",
269
- command: [run.command, ...run.args].join(" "),
270
- path: this.rel(run.cwd),
271
- summary: "command completed",
272
- status: "created",
273
- });
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)");
274
301
  }
275
302
 
276
303
  return { files: written, runs: this.runs, dryRun: false };
277
304
  }
278
305
  }
279
306
 
280
- /** cwd 之外路径的显示缩写:$TMPDIR / ~(仅人类显示;JSON 事件永远真实路径)。 */
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 / ~。 */
281
318
  function shortenOutside(path) {
282
319
  const tmp = tmpdir();
283
320
  if (tmp && tmp !== "/" && (path === tmp || path.startsWith(`${tmp}/`))) {
@@ -290,6 +327,141 @@ function shortenOutside(path) {
290
327
  return path;
291
328
  }
292
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
+
293
465
  function exec(command, args, { cwd, env, quiet = false }) {
294
466
  return new Promise((resolve, reject) => {
295
467
  const isJson = process.env.COLLECTUI_JSON === "1";
@@ -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: lib.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
+ }
@@ -4,8 +4,7 @@ import { dashUrl, registryUrl } from "../config.mjs";
4
4
  import { usageError } from "../errors.mjs";
5
5
  import { fetchAccount } from "../dash.mjs";
6
6
  import { buildMcpEntries, describeEntries, planMcpConfig, renderEntry } from "../mcp.mjs";
7
- import { requireToken, selectLibs } from "./common.mjs";
8
- import { resolveClients } from "./setup.mjs";
7
+ import { chooseClients, detectClientApp, requireToken, selectLibs } from "./common.mjs";
9
8
 
10
9
  export async function mcpCmd(flags, rest, reporter) {
11
10
  const sub = rest[0] ?? "show";
@@ -26,7 +25,8 @@ async function mcpConfigCommand(sub, flags, rest, reporter) {
26
25
  const me = await fetchAccount(token, { reporter });
27
26
  reporter.addSecrets((me.keys ?? []).map((k) => k.key).filter(Boolean));
28
27
  const { units } = await selectLibs({ flags, me, reporter });
29
- const clients = resolveClients(flags);
28
+ // show 是只读命令:不弹多选,按默认集打印(init/configure 才交互挑 Agent)
29
+ const clients = await chooseClients(flags, me, reporter, { interactive: sub !== "show" });
30
30
  const target = resolve(flags.cwd || rest[0] || process.cwd());
31
31
 
32
32
  const entries = buildMcpEntries({
@@ -84,6 +84,14 @@ async function mcpConfigCommand(sub, flags, rest, reporter) {
84
84
  files: applied.files?.length ?? 0,
85
85
  dryRun: Boolean(flags["dry-run"]),
86
86
  });
87
+ if (!reporter.headless) {
88
+ const undetected = clients.filter((c) => !detectClientApp(c));
89
+ if (undetected.length) {
90
+ reporter.info(
91
+ `MCP config written for ${undetected.join(", ")} — app not detected on this machine; it picks the config up once installed.`
92
+ );
93
+ }
94
+ }
87
95
  reporter.outro(flags["dry-run"] ? "Dry run complete." : "MCP configuration updated.");
88
96
  }
89
97
 
@@ -2,7 +2,7 @@ import { protectGit } from "../git-privacy.mjs";
2
2
  import { existsSync, readdirSync, statSync } from "node:fs";
3
3
  import { tmpdir } from "node:os";
4
4
  import { basename, join, resolve } from "node:path";
5
- import { ChangeSet } from "../changes.mjs";
5
+ import { ChangeSet, displayPath } from "../changes.mjs";
6
6
  import { CLI_VERSION } from "../version.mjs";
7
7
  import { dashUrl, registryUrl, resolveToken } from "../config.mjs";
8
8
  import { CliError } from "../errors.mjs";
@@ -11,28 +11,11 @@ import { fetchAccount } from "../dash.mjs";
11
11
  import { planMcpConfig, describeEntries } from "../mcp.mjs";
12
12
  import { detectPackageManager, planProjectConfig } from "../project.mjs";
13
13
  import { planManifest, planScaffold } from "../scaffold.mjs";
14
- import { selectLibs } from "./common.mjs";
15
-
16
- const DEFAULT_CLIENTS = ["claude", "cursor", "vscode"];
17
- const ALL_CLIENTS = ["claude", "cursor", "codex", "vscode"];
18
-
19
- export function resolveClients(flags) {
20
- const raw = flags.clients;
21
- if (!raw) return DEFAULT_CLIENTS;
22
- const list = String(raw)
23
- .split(/[,\s]+/)
24
- .map((s) => s.trim().toLowerCase())
25
- .filter(Boolean);
26
- if (list.includes("all")) return ALL_CLIENTS;
27
- const unknown = list.filter((c) => !ALL_CLIENTS.includes(c));
28
- if (unknown.length) {
29
- throw new CliError(`Unknown MCP client(s): ${unknown.join(", ")}`, {
30
- code: 2,
31
- hint: `Supported: ${ALL_CLIENTS.join(", ")}, all`,
32
- });
33
- }
34
- return [...new Set(list)];
35
- }
14
+ import { chooseClients, detectClientApp, selectLibs } from "./common.mjs";
15
+
16
+ // client 集/选项面已迁 common.mjs(mcp 命令与 setup 共用决策链);
17
+ // 此处 re-export 兼容既有 import
18
+ export { resolveClients, CLIENT_OPTIONS, ALL_CLIENTS } from "./common.mjs";
36
19
 
37
20
  export function resolveTarget({ flags, rest, mode }) {
38
21
  const explicit = flags.cwd || rest[0];
@@ -105,16 +88,16 @@ export async function runSetup({ flags, rest = [], reporter, mode }) {
105
88
  const template = flags.template ? String(flags.template) : "vite";
106
89
 
107
90
  if (mode === "configure" && !hasComponents) {
108
- throw new CliError(`${target} has no components.json.`, {
91
+ throw new CliError(`${displayPath(target)} has no components.json.`, {
109
92
  hint: "Point at a shadcn project, or run `cui init` to create one.",
110
93
  });
111
94
  }
112
95
  if (mode === "init" && hasComponents) {
113
- reporter.info(`${target} already has components.json — switching to configure mode (no scaffold).`);
96
+ reporter.info(`${displayPath(target)} already has components.json — switching to configure mode (no scaffold).`);
114
97
  mode = "configure";
115
98
  }
116
99
  if (mode === "init" && !hasComponents && nonEmpty && !flags.force) {
117
- throw new CliError(`Target directory is not empty: ${target}`, {
100
+ throw new CliError(`Target directory is not empty: ${displayPath(target)}`, {
118
101
  hint: "Pick an empty/new directory, or pass --force to add missing files without overwriting existing ones.",
119
102
  });
120
103
  }
@@ -130,7 +113,7 @@ export async function runSetup({ flags, rest = [], reporter, mode }) {
130
113
  !hasComponents &&
131
114
  flags.install !== false &&
132
115
  !flags["no-install"];
133
- const clients = resolveClients(flags);
116
+ const clients = await chooseClients(flags, me, reporter);
134
117
  const projectName = flags.name ? String(flags.name) : basename(target) || "collectui-app";
135
118
 
136
119
  const cs = new ChangeSet({
@@ -141,10 +124,10 @@ export async function runSetup({ flags, rest = [], reporter, mode }) {
141
124
  });
142
125
 
143
126
  if (mode === "init" && !hasComponents) {
144
- reporter.step(1, 5, `Scaffold ${template} project in ${target}`);
127
+ reporter.step(1, 5, `Scaffold ${template} project in ${displayPath(target)}`);
145
128
  planScaffold(cs, { target, name: projectName, template, pm, install });
146
129
  } else {
147
- reporter.step(1, 5, `Use existing project ${target}`);
130
+ reporter.step(1, 5, `Use existing project ${displayPath(target)}`);
148
131
  }
149
132
 
150
133
  reporter.step(2, 5, "Configure shadcn registries and license keys");
@@ -233,9 +216,11 @@ export async function runSetup({ flags, rest = [], reporter, mode }) {
233
216
  mcpServers: mcpEntries.map((e) => e.serverName),
234
217
  next: [
235
218
  mode === "init" && !hasComponents ? `cd ${cs.show(target)}` : null,
236
- install ? `dependencies installing via ${pm}` : "npm install (if dependencies are missing)",
237
- `cui add ${units[0]?.site ?? "<site>"} <component>`,
238
- "cui doctor",
219
+ // 只有 CLI 没自动装(--no-install / configure 模式)才提示安装;
220
+ // 自动装过的场景不再出现——装完了还叫人装是语义矛盾(2026-12-06 用户反馈)
221
+ install ? null : `${pm} install`,
222
+ // 按实际选的库逐个给 add 示例——用户配了几个库就列几行
223
+ ...units.slice(0, 3).map((u) => `cui add ${u.site} <component>`),
239
224
  ].filter(Boolean),
240
225
  };
241
226
  if (reporter.headless) {
@@ -243,6 +228,14 @@ export async function runSetup({ flags, rest = [], reporter, mode }) {
243
228
  } else {
244
229
  // TTY 下不画 Result 大框;下一步行动指引是 summary 里唯一对人有用的
245
230
  reporter.note("Next steps", summary.next.join("\n"));
231
+ // dash 固定了 / 用户选了某 Agent 但本机还没装:写入不依赖安装,提示一句
232
+ // 「装好后打开项目即生效」,消除「配了却好像没用上」的困惑
233
+ const undetected = clients.filter((c) => !detectClientApp(c));
234
+ if (undetected.length) {
235
+ reporter.info(
236
+ `MCP config written for ${undetected.join(", ")} — app not detected on this machine; it picks the config up once installed.`
237
+ );
238
+ }
246
239
  }
247
240
  reporter.outro(
248
241
  `Done — ${libs.length} librar${libs.length === 1 ? "y" : "ies"} configured in ${cs.show(target)}.`
@@ -42,8 +42,13 @@ export function auditGit(cwd) {
42
42
  if (remote && (files.length || marker)) result.remoteHit = true;
43
43
  if(files.length || marker) result.messages.push(`${remote?'本机远端跟踪引用的历史':'本地提交历史'}中发现潜在敏感配置:${[...new Set([...files,...(marker?[prefix+component]:[])])].map(p=>JSON.stringify(p)).join('、')}。${remote?'按已外发处理:先撤销或轮换相关凭据,核查访问记录;停止跟踪不会清除旧提交。':'取消跟踪不影响旧提交。'}`);
44
44
  }
45
- if (!read('for-each-ref','--count=1','--format=%(objectname)','refs/remotes').trim() || read('rev-parse','--is-shallow-repository').trim()==='true') result.uncertain=true;
46
- if(result.uncertain) result.messages.push('历史或索引检查不完整(可能没有远端跟踪引用或是浅克隆),不能据此排除曾经推送。');
45
+ // 不确定态只对「有历史可查却查不全」的仓库报:全新仓库(还没有任何提交)
46
+ // 没有历史可言,谈不上外发风险——cui init 刚 git init 完的场景不该弹这条。
47
+ // 文案保持通俗(2026-12-06 用户反馈:术语化的「远端跟踪引用/浅克隆」看不懂)。
48
+ const hasRemotes = read('for-each-ref','--count=1','--format=%(objectname)','refs/remotes').trim();
49
+ const shallow = read('rev-parse','--is-shallow-repository').trim()==='true';
50
+ if (hasHead && (!hasRemotes || shallow)) result.uncertain=true;
51
+ if(result.uncertain) result.messages.push('git 历史无法完整检查(仓库没有远端,或是浅克隆),不能确认这些文件从未推送出去过。');
47
52
  return result;
48
53
  }
49
54
 
package/src/report.mjs CHANGED
@@ -200,6 +200,23 @@ export function createReporter({
200
200
  }
201
201
  return answer;
202
202
  },
203
+
204
+ /** 多选(Agent 选择等)。headless/JSON 返回 null(调用方走默认集,不阻塞)。 */
205
+ async multiSelect(message, options, { selected = [] } = {}) {
206
+ if (headless) return null;
207
+ activity.pause();
208
+ const answer = await p.multiselect({
209
+ message: redact(message),
210
+ options,
211
+ initialValues: selected,
212
+ required: false,
213
+ });
214
+ if (p.isCancel(answer)) {
215
+ p.cancel("Cancelled.");
216
+ process.exit(0);
217
+ }
218
+ return answer;
219
+ },
203
220
  };
204
221
 
205
222
  return reporter;
@@ -47,8 +47,10 @@ This writes/merges:
47
47
  - `components.json` → `registries` entries pointing at
48
48
  `https://registry.collectui.pro/api/r/<source>/...` with `${ENV}` headers.
49
49
  - `.env.local` → the license-key variables (mode 0600).
50
- - MCP configs (`.mcp.json`, `.cursor/mcp.json`, `.vscode/mcp.json`; Codex with
51
- `--clients codex`) → library MCP servers + `collectui`.
50
+ - MCP configs (`.mcp.json`, `.cursor/mcp.json`, `.vscode/mcp.json`, Codex's
51
+ `~/.codex/config.toml`) → library MCP servers + `collectui`. Client set:
52
+ the user's Dash-pinned agents when available, else claude/cursor/vscode;
53
+ override with `--clients`.
52
54
  - `.collectui/project.json` + `.collectui/environment.md` → machine-readable
53
55
  setup record.
54
56