@collectui/cli 0.2.21 → 0.2.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -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
- - 始终写 **`collectui-dash`** MCP(Bearer PAT),Agent 可直接调用 Dash 工具
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` 给 shadcn 加 `--overwrite`。
117
+ `--scope @uiarc-pro` 可强制 scope;`--force` 或无头模式会给 shadcn 加 `--overwrite`,可能覆盖已有组件文件。
118
118
 
119
- ## MCP 与 Dash 结合
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
- Dash MCP 端点:`https://dash.collectui.pro/api/mcp`,Bearer PAT。工具:
133
- `me`、`list_repos`、`download_repo`、`submit_feedback`。
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
 
@@ -199,7 +196,7 @@ collectui update --check # 只查不装
199
196
  > 目录只收 **shadcn registry 体系**的三方库(能在 `components.json` 里注册、
200
197
  > 用 `shadcn add` 安装);ThreeUI / Aura / HeroUI 等自带独立安装器、不兼容
201
198
  > shadcn registry 的产品不在本 CLI 范围内。目录是内置快照,与 Dash 站点卡的
202
- > AI Tools 数据同源;实际能不能装以你账户的 `/api/me` 授权与绑定 key 为准。
199
+ > AI Tools 数据同源;实际能不能装以你账户的 `/api/account` 授权与绑定 key 为准。
203
200
  > Dash 新增 shadcn 库时同步本仓库 `src/catalog.mjs`。
204
201
 
205
202
  ## 安全
@@ -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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@collectui/cli",
3
- "version": "0.2.21",
3
+ "version": "0.2.23",
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
@@ -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,19 @@ export class ChangeSet {
27
28
  this.gitRepos = new Set();
28
29
  }
29
30
 
31
+ /** 人类显示路径:cwd 内相对化;cwd 外把 OS tmp / 家目录前缀缩写——init 默认
32
+ * 落 os.tmpdir()(macOS 是 /var/folders/_g/…/T 这种 per-user 长路径),原样
33
+ * 打印能把 Plan 面板撑到爆宽,窄终端直接折行错位。 */
30
34
  rel(path) {
31
35
  const r = relative(process.cwd(), path);
32
- return r && !r.startsWith("..") ? r : path;
36
+ if (r && !r.startsWith("..")) return r;
37
+ return shortenOutside(path);
38
+ }
39
+
40
+ /** 进 reporter 事件(action/preview)的路径:JSON 模式必须给真实绝对路径
41
+ * (Agent 拿去定位文件),只有人类显示走 rel() 缩写。 */
42
+ show(path) {
43
+ return this.reporter.json ? path : this.rel(path);
33
44
  }
34
45
 
35
46
  read(path) {
@@ -162,7 +173,7 @@ export class ChangeSet {
162
173
  const plans = await this.plan();
163
174
  if (plans.length === 0) {
164
175
  this.reporter.info("No changes — everything is already configured.");
165
- return { files: [], runs: [], skipped: true };
176
+ return { files: [], runs: [], skipped: true, dryRun: this.dryRun };
166
177
  }
167
178
 
168
179
  if (this.dryRun) {
@@ -266,6 +277,19 @@ export class ChangeSet {
266
277
  }
267
278
  }
268
279
 
280
+ /** cwd 之外路径的显示缩写:$TMPDIR / ~(仅人类显示;JSON 事件永远真实路径)。 */
281
+ function shortenOutside(path) {
282
+ const tmp = tmpdir();
283
+ if (tmp && tmp !== "/" && (path === tmp || path.startsWith(`${tmp}/`))) {
284
+ return path === tmp ? "$TMPDIR" : `$TMPDIR/${path.slice(tmp.length + 1)}`;
285
+ }
286
+ const home = process.env.HOME;
287
+ if (home && home !== "/" && (path === home || path.startsWith(`${home}/`))) {
288
+ return path === home ? "~" : `~/${path.slice(home.length + 1)}`;
289
+ }
290
+ return path;
291
+ }
292
+
269
293
  function exec(command, args, { cwd, env, quiet = false }) {
270
294
  return new Promise((resolve, reject) => {
271
295
  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> Show/init MCP config; call Dash MCP tools
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 collectui-dash MCP server
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", "dash", "skill"]);
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/help 已在前面分流)
180
+ showBanner(reporter); // 开机画面:任何子命令(headless/--version 已在前面分流;help 走 printHelp 自带同款)
174
181
  // 更新检查最先出发:与目录/账号请求并行,命令收尾时多半已查完(少等收尾那 1 秒)。
175
182
  // TTY 才查,有新版打一行提醒;手动 update 命令自身不触发(避免与前台安装并发写全局目录)
176
183
  const updateNotice =
@@ -23,7 +23,7 @@ export function requireToken(flags, reporter) {
23
23
  }
24
24
 
25
25
  /**
26
- * 账号数据 { account, sites, keys }——走 CLI 专用端点(不触发 /api/me 的全量聚合)。
26
+ * 账号数据 { account, sites, keys }——走 CLI 专用端点(不碰 Dash MCP me 工具那条全量聚合)。
27
27
  * required=false:未登录回 null(调用方降级);默认未登录直接报错退出 3。
28
28
  */
29
29
  export async function loadMe(flags, reporter, { required = true } = {}) {
@@ -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
- add("dash-mcp", "ok", `${tools.length} tools: ${tools.map((t) => t.name).join(", ")}`);
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("dash-mcp", status, error.message);
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}`);
@@ -2,15 +2,7 @@ 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 {
6
- addMeSecrets,
7
- dashMcpTool,
8
- dashMcpTools,
9
- dashMe,
10
- fetchAccount,
11
- formatMeHuman,
12
- formatTools,
13
- } from "../dash.mjs";
5
+ import { fetchAccount } from "../dash.mjs";
14
6
  import { buildMcpEntries, describeEntries, planMcpConfig, renderEntry } from "../mcp.mjs";
15
7
  import { requireToken, selectLibs } from "./common.mjs";
16
8
  import { resolveClients } from "./setup.mjs";
@@ -22,10 +14,6 @@ export async function mcpCmd(flags, rest, reporter) {
22
14
  return;
23
15
  }
24
16
 
25
- if (["tools", "call", "me", "repos", "download", "feedback"].includes(sub)) {
26
- return dashMcpCommand(sub, flags, rest.slice(1), reporter);
27
- }
28
-
29
17
  if (sub === "show" || sub === "init" || sub === "configure") {
30
18
  return mcpConfigCommand(sub, flags, rest.slice(1), reporter);
31
19
  }
@@ -99,100 +87,14 @@ async function mcpConfigCommand(sub, flags, rest, reporter) {
99
87
  reporter.outro(flags["dry-run"] ? "Dry run complete." : "MCP configuration updated.");
100
88
  }
101
89
 
102
- async function dashMcpCommand(sub, flags, rest, reporter) {
103
- const token = requireToken(flags, reporter);
104
-
105
- if (sub === "tools") {
106
- const tools = await dashMcpTools(token, { reporter });
107
- if (reporter.json) reporter.result({ tools });
108
- else reporter.note("Dash MCP tools", formatTools(tools));
109
- return;
110
- }
111
-
112
- if (sub === "call") {
113
- const name = rest[0];
114
- if (!name) throw usageError("Usage: cui mcp call <tool> [--args '<json>']");
115
- let args = {};
116
- if (flags.args) {
117
- try {
118
- args = JSON.parse(String(flags.args));
119
- } catch (error) {
120
- throw usageError(`--args is not valid JSON: ${error.message}`);
121
- }
122
- }
123
- const result = await dashMcpTool(token, name, args, { reporter });
124
- if (result?.keys) addMeSecrets(reporter, result);
125
- if (reporter.json) reporter.result({ tool: name, result });
126
- else reporter.note(`mcp:${name}`, typeof result === "string" ? result : JSON.stringify(result, null, 2));
127
- return;
128
- }
129
-
130
- if (sub === "me") {
131
- const me = await dashMe(token, { reporter });
132
- addMeSecrets(reporter, me);
133
- if (reporter.json) reporter.result(me);
134
- else reporter.note("Dash account", formatMeHuman(me));
135
- return;
136
- }
137
-
138
- if (sub === "repos") {
139
- const result = await dashMcpTool(token, "list_repos", {}, { reporter });
140
- if (reporter.json) reporter.result(result);
141
- else {
142
- const lines = (result?.releases ?? []).map(
143
- (r) => `- ${r.repo} v${r.version} ${r.size ?? "?"} bytes ${r.releasedAt}${r.brief ? `\n ${r.brief}` : ""}`
144
- );
145
- reporter.note("Downloadable repos", lines.join("\n") || "(none)");
146
- }
147
- return;
148
- }
149
-
150
- if (sub === "download") {
151
- const repo = rest[0];
152
- if (!repo) throw usageError("Usage: cui mcp download <owner/repo>");
153
- const result = await dashMcpTool(token, "download_repo", { repo }, { reporter });
154
- if (reporter.json) reporter.result(result);
155
- else {
156
- reporter.note(
157
- "Download",
158
- [
159
- `- repo: ${result?.repo ?? repo}`,
160
- `- version: ${result?.version ?? "?"}`,
161
- `- url: ${result?.url ?? "(no url)"}`,
162
- result?.gitUrl ? `- git: ${result.gitUrl}` : null,
163
- result?.expiresAt ? `- expires: ${result.expiresAt}` : null,
164
- ]
165
- .filter(Boolean)
166
- .join("\n")
167
- );
168
- }
169
- return;
170
- }
90
+ const MCP_HELP = `Usage: cui mcp <show|init|configure>
171
91
 
172
- if (sub === "feedback") {
173
- const message = rest.join(" ").trim();
174
- if (!message) throw usageError("Usage: cui mcp feedback <message> [--site reui,arc]");
175
- const result = await dashMcpTool(
176
- token,
177
- "submit_feedback",
178
- { message, ...(flags.site ? { site: String(flags.site) } : {}) },
179
- { reporter }
180
- );
181
- if (reporter.json) reporter.result(result);
182
- else reporter.note("Feedback", JSON.stringify(result, null, 2));
183
- return;
184
- }
185
-
186
- throw usageError(`Unknown mcp subcommand "${sub}".`, { hint: MCP_HELP });
187
- }
92
+ MCP servers are the agent's entry point; this command manages them for you:
188
93
 
189
- const MCP_HELP = `Usage: cui mcp <show|init|tools|call|me|repos|download|feedback>
94
+ show Print MCP server config (collectui + library servers) for each client
95
+ init Write/merge MCP configs into .mcp.json / .cursor / .vscode / codex
96
+ configure Same as init
190
97
 
191
- show Print MCP server config for the selected libraries and clients
192
- init Write/merge MCP configs (same as configure's MCP step)
193
- tools List tools on the CollectUI Dash MCP
194
- call <tool> Call a Dash MCP tool (--args '<json>')
195
- me Account aggregation via Dash MCP (falls back to REST)
196
- repos Downloadable snapshot repos via Dash MCP
197
- download <repo> Fresh download URL for a repo
198
- feedback <message> Submit feedback through Dash MCP (--site reui,arc)`;
98
+ The CollectUI MCP server itself is agent-only — call it from your MCP client
99
+ (it is already in .mcp.json), not through this CLI. People inspect their
100
+ account with \`cui whoami\`; the Dash site shows repos, feedback and orders.`;
@@ -1,3 +1,4 @@
1
+ import { protectGit } from "../git-privacy.mjs";
1
2
  import { existsSync, readdirSync, statSync } from "node:fs";
2
3
  import { tmpdir } from "node:os";
3
4
  import { basename, join, resolve } from "node:path";
@@ -5,7 +6,7 @@ import { ChangeSet } from "../changes.mjs";
5
6
  import { CLI_VERSION } from "../version.mjs";
6
7
  import { dashUrl, registryUrl, resolveToken } from "../config.mjs";
7
8
  import { CliError } from "../errors.mjs";
8
- import { login } from "../login.mjs";
9
+ import { login, saveSession } from "../login.mjs";
9
10
  import { fetchAccount } from "../dash.mjs";
10
11
  import { planMcpConfig, describeEntries } from "../mcp.mjs";
11
12
  import { detectPackageManager, planProjectConfig } from "../project.mjs";
@@ -61,30 +62,31 @@ function isNonEmptyDir(dir) {
61
62
  export async function runSetup({ flags, rest = [], reporter, mode }) {
62
63
  reporter.intro(`CollectUI CLI · ${mode}`);
63
64
 
65
+ let pendingSession;
64
66
  let token = resolveToken(flags);
65
67
  if (!token) {
66
- if (reporter.headless) {
67
- throw new CliError("Not logged in (headless).", {
68
+ if (reporter.headless || flags["dry-run"]) {
69
+ throw new CliError("Not logged in.", {
68
70
  code: 3,
69
71
  hint: "Pass --token dpat_... or set COLLECTUI_TOKEN. `cui login` opens Dash for you in a terminal.",
70
72
  });
71
73
  }
72
74
  reporter.info("No saved session — starting login first.");
73
- const session = await login({ reporter });
74
- token = session.token;
75
+ pendingSession = await login({ reporter, persist: false });
76
+ token = pendingSession.token;
75
77
  }
76
78
  reporter.addSecrets([token]);
77
79
 
78
80
  let me;
79
81
  try {
80
- me = await fetchAccount(token, { reporter });
82
+ me = pendingSession?.me ?? (await fetchAccount(token, { reporter }));
81
83
  } catch (error) {
82
- if (error?.exitCode === 3 && !reporter.headless) {
84
+ if (error?.exitCode === 3 && !reporter.headless && !flags["dry-run"]) {
83
85
  reporter.warn("Saved PAT was rejected — starting login again.");
84
- const session = await login({ reporter });
85
- token = session.token;
86
+ pendingSession = await login({ reporter, persist: false });
87
+ token = pendingSession.token;
86
88
  reporter.addSecrets([token]);
87
- me = session.me ?? (await fetchAccount(token, { reporter }));
89
+ me = pendingSession.me ?? (await fetchAccount(token, { reporter }));
88
90
  } else {
89
91
  throw error;
90
92
  }
@@ -157,7 +159,7 @@ export async function runSetup({ flags, rest = [], reporter, mode }) {
157
159
 
158
160
  let mcpEntries = [];
159
161
  if (!flags["no-mcp"]) {
160
- reporter.step(3, 5, "Configure MCP servers (library + CollectUI Dash)");
162
+ reporter.step(3, 5, "Configure MCP servers (library + CollectUI MCP)");
161
163
  const mcp = planMcpConfig(cs, {
162
164
  projectDir: target,
163
165
  units,
@@ -194,6 +196,33 @@ export async function runSetup({ flags, rest = [], reporter, mode }) {
194
196
  reporter.step(5, 5, "Apply changes");
195
197
  const applied = await cs.apply();
196
198
 
199
+ // 确认框选了 No:一行都没写。不装「已配置」、不给下一步指引(cd 过去什么都没有)
200
+ if (applied.aborted) {
201
+ reporter.outro("Aborted — nothing was written. Re-run when you are ready.");
202
+ return { target, mode, libraries: libs.map((lib) => lib.site), aborted: true };
203
+ }
204
+
205
+ // dry-run 同理只看过了:指引就是「去掉 --dry-run 再跑」,cd/install/add 全不成立
206
+ if (applied.dryRun) {
207
+ if (reporter.headless) {
208
+ reporter.result({
209
+ target,
210
+ mode,
211
+ libraries: libs.map((lib) => lib.site),
212
+ units: units.map((u) => u.site),
213
+ files: applied.files?.length ?? 0,
214
+ mcpClients: clients,
215
+ mcpServers: mcpEntries.map((e) => e.serverName),
216
+ dryRun: true,
217
+ });
218
+ }
219
+ reporter.outro("Dry run complete. Re-run without --dry-run to apply.");
220
+ return { target, mode, libraries: libs.map((lib) => lib.site), dryRun: true };
221
+ }
222
+
223
+ await protectGit(target, reporter, flags);
224
+ if (pendingSession) saveSession(token, me, { reporter });
225
+
197
226
  const summary = {
198
227
  target,
199
228
  mode,
@@ -202,9 +231,8 @@ export async function runSetup({ flags, rest = [], reporter, mode }) {
202
231
  files: applied.files?.length ?? 0,
203
232
  mcpClients: clients,
204
233
  mcpServers: mcpEntries.map((e) => e.serverName),
205
- dryRun: Boolean(flags["dry-run"]),
206
234
  next: [
207
- mode === "init" && !hasComponents ? `cd ${target}` : null,
235
+ mode === "init" && !hasComponents ? `cd ${cs.show(target)}` : null,
208
236
  install ? `dependencies installing via ${pm}` : "npm install (if dependencies are missing)",
209
237
  `cui add ${units[0]?.site ?? "<site>"} <component>`,
210
238
  "cui doctor",
@@ -217,9 +245,7 @@ export async function runSetup({ flags, rest = [], reporter, mode }) {
217
245
  reporter.note("Next steps", summary.next.join("\n"));
218
246
  }
219
247
  reporter.outro(
220
- flags["dry-run"]
221
- ? "Dry run complete. Re-run without --dry-run to apply."
222
- : `Done — ${libs.length} librar${libs.length === 1 ? "y" : "ies"} configured in ${target}.`
248
+ `Done — ${libs.length} librar${libs.length === 1 ? "y" : "ies"} configured in ${cs.show(target)}.`
223
249
  );
224
250
  return summary;
225
251
  }
@@ -5,7 +5,7 @@ import {
5
5
  resolveLibKeys,
6
6
  retiredSlugs,
7
7
  } from "../catalog.mjs";
8
- import { formatAccountHuman, maskKey } from "../dash.mjs";
8
+ import { accountBadge, formatAccountHuman, maskKey } from "../dash.mjs";
9
9
  import { resolveToken } from "../config.mjs";
10
10
  import { formatTable } from "../report.mjs";
11
11
  import { loadMe, requireToken } from "./common.mjs";
@@ -73,11 +73,28 @@ export async function whoamiCmd(flags, rest, reporter, { invokedAs } = {}) {
73
73
  rows.push({
74
74
  site: lib.site,
75
75
  cli: isOwned === false ? "-" : keys.cli ? "bound" : "-",
76
- mcp: isOwned === false ? "-" : keys.mcp ? "bound" : lib.mcp ? "-" : "generic",
76
+ // 未绑专属 MCP key:有 shadcn 通用 MCP 备选(boardui / reactbits 这类
77
+ // 「专属 + 备选」双通道库)照样可用 → generic;纯专属库无备选才落 "-"
78
+ mcp:
79
+ isOwned === false
80
+ ? "-"
81
+ : keys.mcp
82
+ ? "bound"
83
+ : lib.mcp
84
+ ? lib.shadcnUiMcp
85
+ ? "generic"
86
+ : "-"
87
+ : "generic",
77
88
  name: lib.siteName,
78
89
  owned: isOwned === null ? "?" : isOwned ? "yes" : "no",
79
90
  registries: (lib.registries ?? []).map((r) => r.scope).join(", ") || "-",
80
- mcpServer: lib.mcp ?? (lib.shadcnUiMcp ? "shadcn (generic)" : "-"),
91
+ mcpServer: lib.mcp
92
+ ? lib.shadcnUiMcp
93
+ ? `${lib.mcp} / shadcn (generic)`
94
+ : lib.mcp
95
+ : lib.shadcnUiMcp
96
+ ? "shadcn (generic)"
97
+ : "-",
81
98
  });
82
99
  }
83
100
 
@@ -112,7 +129,8 @@ export async function whoamiCmd(flags, rest, reporter, { invokedAs } = {}) {
112
129
  );
113
130
  reporter.note(
114
131
  me ? "Account" : "Catalog (not logged in)",
115
- [me ? formatAccountHuman(me.account) : null, table].filter(Boolean).join("\n\n")
132
+ [me ? formatAccountHuman(me.account) : null, table].filter(Boolean).join("\n\n"),
133
+ me ? { badge: accountBadge(me.account) } : undefined
116
134
  );
117
135
  if (extraOwned.length) {
118
136
  reporter.info(
package/src/dash.mjs CHANGED
@@ -1,57 +1,37 @@
1
+ import { CliError } from "./errors.mjs";
1
2
  import { dashUrl } from "./config.mjs";
2
- import { jsonRequest, mcpCall, toolResult } from "./http.mjs";
3
-
4
- /**
5
- * Dash 全量聚合(/api/me:站点、key、可下仓库、HP 凭据、订单)。
6
- * CLI 里只有 `cui dash me` 在 Dash MCP 不可用时拿它兜底——其余命令一律走下面的
7
- * fetchAccount(专用端点),全量聚合里 CLI 用不到的部分服务端就不去查。
8
- */
9
- export async function fetchMe(token, { reporter } = {}) {
10
- return jsonRequest(`${dashUrl()}/api/me`, {
11
- token,
12
- reporter,
13
- label: "dash /api/me",
14
- spinner: "Loading your account from Dash…",
15
- });
16
- }
3
+ import { jsonRequest, mcpCall } from "./http.mjs";
17
4
 
18
5
  /**
19
6
  * CLI 专用数据面 GET /api/account(2026-12-01):{ account, sites, keys }——账户本体 +
20
7
  * 按站授权 + 绑定 key。CLI 全部命令(whoami / init / configure / add / mcp / doctor /
21
8
  * login)要的只有这些;可下仓库、订单、HP 凭据一个都用不到。
22
- * 兼容旧 Dash:没有该路由(404),或只有首版形状(仅 account)→ 退回 /api/me 取同名切片。
23
9
  */
24
10
  export async function fetchAccount(token, { reporter } = {}) {
25
- const request = (path) =>
26
- jsonRequest(`${dashUrl()}${path}`, {
27
- token,
28
- reporter,
29
- label: `dash ${path}`,
30
- spinner: "Loading your account from Dash…",
31
- });
32
- let data = null;
33
- try {
34
- const light = await request("/api/account");
35
- if (Array.isArray(light?.sites) && Array.isArray(light?.keys)) data = light;
36
- } catch (error) {
37
- if (error?.status !== 404) throw error;
38
- }
39
- if (!data) {
40
- const me = await request("/api/me");
41
- data = { account: me?.account ?? null, sites: me?.sites ?? [], keys: me?.keys ?? [] };
11
+ const data = await jsonRequest(`${dashUrl()}/api/account`, {
12
+ token, reporter, label: "dash /api/account", spinner: "Loading your account from Dash…",
13
+ });
14
+ if (!data?.account || !Array.isArray(data.sites) || !Array.isArray(data.keys)) {
15
+ throw new CliError("Invalid /api/account response: expected account, sites and keys.");
42
16
  }
43
17
  return data;
44
18
  }
45
19
 
46
- /** `cui whoami` 的账户段:账户名 + uid、注册时间、徽章——最基本的账户信息,到此为止。 */
20
+ /** `cui whoami` 的账户段:uid、注册时间、徽章——最基本的账户信息,到此为止。
21
+ * 账户名不进正文(上移到面板标题栏右侧徽标,见 reporter.note 的 badge)。 */
47
22
  export function formatAccountHuman(account) {
48
23
  if (!account) return "No account data.";
49
- const lines = [`Account: ${account.username ?? "(unknown)"} uid=${account.uid ?? "?"}`];
24
+ const lines = [`Uid: ${account.uid ?? "?"}`];
50
25
  if (account.createdAt) lines.push(`Created: ${account.createdAt}`);
51
26
  if (account.badges?.length) lines.push(`Badges: ${account.badges.join(", ")}`);
52
27
  return lines.join("\n");
53
28
  }
54
29
 
30
+ /** 面板标题栏徽标:账户名(正文第一行让位给 Uid)。 */
31
+ export function accountBadge(account) {
32
+ return account?.username ?? "(unknown)";
33
+ }
34
+
55
35
  /** Dash MCP:stateless JSON-RPC,直接 tools/list 或 tools/call。 */
56
36
  export async function dashMcpTools(token, { reporter } = {}) {
57
37
  const result = await mcpCall({
@@ -63,41 +43,6 @@ export async function dashMcpTools(token, { reporter } = {}) {
63
43
  return result?.tools ?? [];
64
44
  }
65
45
 
66
- export async function dashMcpTool(token, name, args = {}, { reporter } = {}) {
67
- const result = await mcpCall({
68
- base: dashUrl(),
69
- token,
70
- method: "tools/call",
71
- params: { name, arguments: args },
72
- reporter,
73
- });
74
- if (result?.isError) {
75
- const text = (result.content ?? []).map((c) => c.text).filter(Boolean).join("\n");
76
- throw new Error(text || `Dash MCP tool ${name} failed`);
77
- }
78
- return toolResult(result);
79
- }
80
-
81
- export async function dashMe(token, { reporter } = {}) {
82
- try {
83
- return await dashMcpTool(token, "me", {}, { reporter });
84
- } catch (error) {
85
- if (/404|not enabled/i.test(error.message)) {
86
- reporter?.warn("Dash MCP is not enabled; falling back to GET /api/me.");
87
- return fetchMe(token, { reporter });
88
- }
89
- throw error;
90
- }
91
- }
92
-
93
- /** 把 account aggregation 里的明文 key 登记给 reporter,确保输出脱敏。 */
94
- export function addMeSecrets(reporter, me) {
95
- reporter?.addSecrets?.((me?.keys ?? []).map((k) => k.key).filter(Boolean));
96
- const hp = me?.herouiHp;
97
- if (hp && typeof hp === "object") {
98
- reporter?.addSecrets?.(Object.values(hp).filter((v) => typeof v === "string"));
99
- }
100
- }
101
46
 
102
47
  export function maskKey(value) {
103
48
  if (!value || typeof value !== "string") return "—";
@@ -105,49 +50,3 @@ export function maskKey(value) {
105
50
  return `${value.slice(0, 6)}…${value.slice(-4)}`;
106
51
  }
107
52
 
108
- export function formatMeHuman(me) {
109
- if (!me) return "No account data.";
110
- const lines = [];
111
- const account = me.account ?? {};
112
- lines.push(`Account: ${account.username ?? "(unknown)"} uid=${account.uid ?? "?"}`);
113
- if (account.createdAt) lines.push(`Created: ${account.createdAt}`);
114
- if (account.badges?.length) lines.push(`Badges: ${account.badges.join(", ")}`);
115
-
116
- const sites = me.sites ?? [];
117
- lines.push("");
118
- lines.push(`Libraries with access (${sites.length}):`);
119
- if (sites.length === 0) lines.push(" (none)");
120
- for (const site of sites) {
121
- const scopes = Array.isArray(site.scopes) && site.scopes.length ? site.scopes.join(", ") : "all";
122
- lines.push(` - ${site.slug} (${site.name}) — ${scopes}${site.expiresAt ? ` · until ${site.expiresAt}` : ""}`);
123
- }
124
-
125
- const keys = me.keys ?? [];
126
- lines.push("");
127
- lines.push(`Bound keys (${keys.length}):`);
128
- if (keys.length === 0) lines.push(" (none)");
129
- for (const key of keys) {
130
- lines.push(` - ${key.source} [${key.kind}] site=${key.site ?? "?"} ${maskKey(key.key)}`);
131
- }
132
-
133
- const repos = me.repos ?? [];
134
- lines.push("");
135
- lines.push(`Downloadable repos (${repos.length}):`);
136
- if (repos.length === 0) lines.push(" (none)");
137
- for (const repo of repos) lines.push(` - ${repo}`);
138
-
139
- const orders = me.orders ?? {};
140
- lines.push("");
141
- lines.push(`Orders: ${orders.paidCount ?? 0} paid, ${orders.pendingCount ?? 0} pending`);
142
- return lines.join("\n");
143
- }
144
-
145
- export function formatTools(tools) {
146
- return tools
147
- .map((tool) => {
148
- const required = tool.inputSchema?.required ?? [];
149
- const props = Object.keys(tool.inputSchema?.properties ?? {});
150
- return `- ${tool.name}${required.length ? ` (required: ${required.join(", ")})` : ""}\n ${tool.description ?? ""}\n args: ${props.join(", ") || "none"}`;
151
- })
152
- .join("\n");
153
- }
@@ -0,0 +1,72 @@
1
+ import { spawnSync } from 'node:child_process';
2
+ import { existsSync, lstatSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
3
+ import { dirname, join } from 'node:path';
4
+
5
+ const local = ['.env.local', '.mcp.json', '.cursor/mcp.json', '.vscode/mcp.json', '.collectui'];
6
+ const component = 'components.json';
7
+ function git(cwd, ...args) {
8
+ return spawnSync('git', ['--literal-pathspecs', '-C', cwd, ...args], {encoding:'utf8', timeout:5000, env:{...process.env,GIT_OPTIONAL_LOCKS:'0',GIT_NO_LAZY_FETCH:'1',GIT_TERMINAL_PROMPT:'0'}});
9
+ }
10
+ const entries = s => s.split('\0').filter(Boolean);
11
+ export function auditGit(cwd) {
12
+ const result = {messages:[], tracked:[], uncertain:false};
13
+ const root = git(cwd, 'rev-parse','--show-toplevel');
14
+ if (root.status !== 0) return result;
15
+ const read = (...args) => {
16
+ const r = git(cwd,...args);
17
+ if (r.status !== 0) { result.uncertain = true; return ''; }
18
+ return r.stdout;
19
+ };
20
+ const prefix = read('rev-parse','--show-prefix').trimEnd();
21
+ result.exclude = read('rev-parse','--path-format=absolute','--git-path','info/exclude').trimEnd();
22
+ result.prefix = prefix;
23
+ result.tracked = entries(read('ls-files','-z','--',...local));
24
+ if (result.tracked.length) result.messages.push(`索引中有本地专用配置(可能含凭据):${result.tracked.map(p=>JSON.stringify(p)).join('、')}。忽略规则不能取消跟踪。`);
25
+ if (entries(read('ls-files','-z','--',component)).length) {
26
+ const attr = entries(read('check-attr','-z','filter','--',component))[2];
27
+ if (attr !== 'collectui') result.messages.push('components.json:此路径未匹配 CollectUI Git filter;忽略规则不保护它,请核对索引并按需设置 Guard。');
28
+ try {
29
+ const data = JSON.parse(read('show',`:${prefix}${component}`));
30
+ if (Object.values(data.registries ?? {}).some(e => /registry\.collectui\.pro/i.test(typeof e==='string'?e:e?.url) || (e && typeof e==='object' && (Object.keys(e.headers??{}).length || Object.keys(e.params??{}).length)))) result.messages.push('components.json:索引版含镜像或鉴权配置。请配置 Guard,重新暂存并复核;不要取消跟踪此文件。');
31
+ } catch { result.uncertain=true; }
32
+ }
33
+ const hasHead = git(cwd,'rev-parse','--verify','HEAD').status===0;
34
+ if (hasHead) {
35
+ const files=entries(read('ls-tree','-r','-z','--name-only','HEAD','--',...local));
36
+ if(files.length) result.messages.push(`当前提交包含本地专用配置:${files.map(p=>JSON.stringify(p)).join('、')}。`);
37
+ }
38
+ for (const remote of [false,true]) {
39
+ const refs=remote?['--remotes']:['--branches','--tags',...(hasHead?['HEAD']:[])];
40
+ const files=entries(read('log',...refs,'--format=','--name-only','-z','--no-renames','--',...local));
41
+ const marker=read('log',...refs,'-1','--format=%h','--no-ext-diff','--no-textconv','-G','registry[.]collectui[.]pro|"(headers|params)"','--',component).trim();
42
+ if (remote && (files.length || marker)) result.remoteHit = true;
43
+ if(files.length || marker) result.messages.push(`${remote?'本机远端跟踪引用的历史':'本地提交历史'}中发现潜在敏感配置:${[...new Set([...files,...(marker?[prefix+component]:[])])].map(p=>JSON.stringify(p)).join('、')}。${remote?'按已外发处理:先撤销或轮换相关凭据,核查访问记录;停止跟踪不会清除旧提交。':'取消跟踪不影响旧提交。'}`);
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('历史或索引检查不完整(可能没有远端跟踪引用或是浅克隆),不能据此排除曾经推送。');
47
+ return result;
48
+ }
49
+
50
+ export async function protectGit(cwd, reporter, flags) {
51
+ const audit=auditGit(cwd);
52
+ if (flags["dry-run"] || !audit.exclude) return;
53
+ for(const message of audit.messages) reporter.warn?.(message);
54
+ // 将规则锚定在实际项目目录,兼容 monorepo 与 linked worktree。
55
+ const escape = s => s.replace(/[\\*?\[\] ]/g,'\\$&');
56
+ const rules=local.filter(p=>existsSync(join(cwd,p))).map(p=>'/'+escape(audit.prefix+p)+(p==='.collectui'?'/':''));
57
+ let text='';
58
+ try {text=readFileSync(audit.exclude,'utf8');} catch(e){if(e.code!=='ENOENT') throw e;}
59
+ const missing=rules.filter(p=>!text.split(/\r?\n/).includes(p));
60
+ if(missing.length){ mkdirSync(dirname(audit.exclude),{recursive:true}); writeFileSync(audit.exclude,text+(text&&!text.endsWith('\n')?'\n':'')+missing.join('\n')+'\n'); }
61
+ if (flags.yes || reporter.headless || !reporter.confirmCleanup) return;
62
+ if (audit.remoteHit && await reporter.confirmCleanup('是否查看已推送历史的清理步骤?不会修改仓库或远端。')) {
63
+ reporter.info('先轮换凭据,保存安全备份;与协作者确认受影响分支、标签及重写窗口。在隔离副本清理并复核所有引用,再由管理员单独批准更新远端。通知成员重新克隆,联系托管方处理 PR 引用和缓存,fork 和已下载副本无法保证收回。');
64
+ }
65
+ if (!audit.tracked.length) return;
66
+ if (!await reporter.confirmCleanup('是否仅从 Git 索引移除上述本地专用配置?保留磁盘文件,不清理历史,也不推送。')) return;
67
+ if(audit.tracked.some(p=>!lstatSync(join(cwd,p),{throwIfNoEntry:false})?.isFile()) || git(cwd,'diff','--quiet','--',...audit.tracked).status!==0 || git(cwd,'ls-files','--unmerged','--',...audit.tracked).stdout?.length) {
68
+ reporter.warn('文件缺失、有冲突或索引与工作区不同,未取消跟踪。请先人工核对。'); return;
69
+ }
70
+ const removed=git(cwd,'rm','--cached','--',...audit.tracked);
71
+ reporter[removed.status===0?'info':'warn'](removed.status===0?'已停止跟踪,文件仍在磁盘。请检查暂存差异后自行提交。':'Git 未能安全取消跟踪,请人工核对。');
72
+ }
package/src/http.mjs CHANGED
@@ -118,7 +118,7 @@ export async function jsonRequest(url, options = {}) {
118
118
  `HTTP ${out.res.status}`;
119
119
  throw new CliError(`${options.label ?? url} failed: ${message}`, {
120
120
  code: out.res.status === 401 || out.res.status === 403 ? 3 : 1,
121
- status: out.res.status, // 调用方按 HTTP 状态分支用(如新端点 404 → 退回旧端点)
121
+ status: out.res.status,
122
122
  hint:
123
123
  out.res.status === 401
124
124
  ? "Run `cui login` again (or pass --token) — your PAT may be missing, revoked or expired."
@@ -196,19 +196,3 @@ export async function mcpCall({ base, token, method, params, reporter, id = 1 })
196
196
  }
197
197
  return parsed.result;
198
198
  }
199
-
200
- /** MCP tools/call 的文本结果 → 尽量解析成结构化数据。 */
201
- export function toolResult(result) {
202
- if (!result) return null;
203
- if (result.structuredContent !== undefined) return result.structuredContent;
204
- const text = (result.content ?? [])
205
- .filter((c) => c?.type === "text" && typeof c.text === "string")
206
- .map((c) => c.text)
207
- .join("\n");
208
- if (!text) return null;
209
- try {
210
- return JSON.parse(text);
211
- } catch {
212
- return text;
213
- }
214
- }
package/src/login.mjs CHANGED
@@ -42,6 +42,7 @@ export async function login({
42
42
  noOpen = false,
43
43
  timeout = 180_000,
44
44
  reporter,
45
+ persist = true,
45
46
  skipVerify = false,
46
47
  pat = false,
47
48
  }) {
@@ -112,7 +113,7 @@ export async function login({
112
113
  } else {
113
114
  reporter.warn("--no-verify: token saved without checking it. Run `cui whoami` to verify.");
114
115
  }
115
- saveSession(token, me, { reporter });
116
+ if (persist) saveSession(token, me, { reporter });
116
117
  reporter.outro("Login complete. Try `cui whoami`.");
117
118
  return { token, me };
118
119
  }
package/src/mcp.mjs CHANGED
@@ -113,7 +113,8 @@ export function buildMcpEntries({ units, me, dashToken, registryBase, dashBase,
113
113
  if (dashToken) {
114
114
  entries.push({
115
115
  kind: "http",
116
- serverName: "collectui-dash",
116
+ // Agent 面前的名字就叫品牌名 collectui(旧名 collectui-dash 从未发布过,无兼容负担)
117
+ serverName: "collectui",
117
118
  url: `${dashBase.replace(/\/+$/, "")}/api/mcp`,
118
119
  headers: { Authorization: `Bearer ${dashToken}` },
119
120
  site: null,
@@ -121,7 +122,7 @@ export function buildMcpEntries({ units, me, dashToken, registryBase, dashBase,
121
122
  key: dashToken,
122
123
  });
123
124
  } else {
124
- reporter?.warn("No Dash PAT; collectui-dash MCP was skipped. Run `cui login` to add it.");
125
+ reporter?.warn("No Dash PAT; the CollectUI MCP (collectui) server was skipped. Run `cui login` to add it.");
125
126
  }
126
127
  }
127
128
 
package/src/report.mjs CHANGED
@@ -110,9 +110,12 @@ export function createReporter({
110
110
  else say(() => p.log.info(redact(`[${index}/${total}] ${title}`)));
111
111
  },
112
112
 
113
- note(title, body) {
114
- if (json) emit({ event: "note", title: redact(title), body: redact(body) });
115
- else say(() => p.note(redact(body), redact(title)));
113
+ note(title, body, { badge } = {}) {
114
+ if (json) {
115
+ emit({ event: "note", title: redact(title), body: redact(body), ...(badge ? { badge: redact(badge) } : {}) });
116
+ } else {
117
+ say(() => noteWithBadge(redact(body), redact(title), badge ? redact(badge) : null));
118
+ }
116
119
  },
117
120
 
118
121
  http(payload) {
@@ -167,6 +170,13 @@ export function createReporter({
167
170
  }
168
171
  },
169
172
 
173
+ async confirmCleanup(message) {
174
+ if (yes || headless || !process.stdin.isTTY || !process.stdout.isTTY) return false;
175
+ activity.pause();
176
+ const answer = await p.confirm({ message: redact(message), initialValue: false });
177
+ return !p.isCancel(answer) && answer === true;
178
+ },
179
+
170
180
  async confirm(message, { defaultValue = true } = {}) {
171
181
  if (yes || headless) return true;
172
182
  activity.pause(); // clack 提示框接管终端期间,屏幕上不能有 spinner 行
@@ -195,6 +205,49 @@ export function createReporter({
195
205
  return reporter;
196
206
  }
197
207
 
208
+ /**
209
+ * p.note 的标题栏徽标版:账户名这类「标题右侧的短元数据」不再挤进正文首行。
210
+ * 先让 clack 原样渲染整个面板(几何/颜色/缩进逐字节原生,不自己复刻),捕获
211
+ * 输出后只动标题行一刀:在尾部 ─ 段开个口,嵌入右对齐的 badge(badge 两侧
212
+ * 各留至少一个 ─,与左侧 `标题 ─` 对称)。面板宽度容不下时原样输出,退化回
213
+ * 普通面板。
214
+ */
215
+ function noteWithBadge(body, title, badge) {
216
+ if (!badge) return p.note(body, title);
217
+ const orig = process.stdout.write.bind(process.stdout);
218
+ let buf = "";
219
+ process.stdout.write = (chunk) => {
220
+ buf += chunk;
221
+ };
222
+ try {
223
+ p.note(body, title);
224
+ } finally {
225
+ process.stdout.write = orig;
226
+ }
227
+ orig(injectTitleBadge(buf, badge));
228
+ }
229
+
230
+ /** 单改标题行:◇ Account ────╮ → ◇ Account ── super-admin ─╮(总宽不变)。 */
231
+ function injectTitleBadge(buf, badge) {
232
+ const lines = buf.split("\n");
233
+ const at = lines.findIndex((line) => line.includes("◇"));
234
+ if (at === -1) return buf;
235
+ const line = lines[at];
236
+ const first = line.indexOf("─");
237
+ const last = line.lastIndexOf("─");
238
+ if (first === -1) return buf;
239
+ const label = ` ${badge} `;
240
+ const dashes = last - first + 1;
241
+ if (dashes < label.length + 2) return buf; // 放不下(badge 后还要留一个 ─)
242
+ const keep = dashes - label.length - 1; // badge 左侧保留的 ─ 数
243
+ // badge 与标题同色(clack 标题文本是默认前景);嵌入点在 gray ─ 段中间,
244
+ // 有色模式下要先把 gray 关掉、badge 后再重开,无色模式(非 TTY)纯文本
245
+ const colored = buf.includes("\x1b[");
246
+ const wrapped = colored ? `\x1b[39m${label}\x1b[90m` : label;
247
+ lines[at] = line.slice(0, first + keep) + wrapped + "─" + line.slice(last + 1);
248
+ return lines.join("\n");
249
+ }
250
+
198
251
  function sanitize(value, redact) {
199
252
  if (typeof value === "string") return redact(value);
200
253
  if (Array.isArray(value)) return value.map((v) => sanitize(v, redact));
@@ -48,7 +48,7 @@ This writes/merges:
48
48
  `https://registry.collectui.pro/api/r/<source>/...` with `${ENV}` headers.
49
49
  - `.env.local` → the license-key variables (mode 0600).
50
50
  - MCP configs (`.mcp.json`, `.cursor/mcp.json`, `.vscode/mcp.json`; Codex with
51
- `--clients codex`) → library MCP servers + `collectui-dash`.
51
+ `--clients codex`) → library MCP servers + `collectui`.
52
52
  - `.collectui/project.json` + `.collectui/environment.md` → machine-readable
53
53
  setup record.
54
54
 
@@ -75,21 +75,26 @@ collectui add 21st shugar/button-1
75
75
  Every library installs through `npx shadcn@latest add @scope/<component>
76
76
  --yes`. Use `--print` to only print the command.
77
77
 
78
- ### Dash MCP
78
+ ### CollectUI MCP (call it directly — do not shell out to the CLI for this)
79
+
80
+ The `collectui` MCP server is already written into this project's MCP config
81
+ (`.mcp.json` / `.cursor/mcp.json` / `.vscode/mcp.json`). Use your own MCP
82
+ client to call its tools: `me` (full account aggregation), `list_repos` /
83
+ `download_repo` (snapshot source downloads), `get_site` / `get_site_docs` /
84
+ `get_changelog`, `service_status`, `submit_feedback`, purchase-request tools.
85
+
86
+ Feedback submissions, purchase requests and votes change Dash data as the PAT owner. Headless `cui add` can overwrite existing component files.
87
+
88
+ Division of labor: **MCP answers "what"** (data, entitlements, docs);
89
+ **the CLI does "how"** (configure, install, write files). Never fetch MCP
90
+ data through the CLI — it has no such commands.
91
+
92
+ To inspect or re-write the MCP config itself:
79
93
 
80
94
  ```bash
81
95
  collectui mcp show --json
82
- collectui mcp tools --json
83
- collectui mcp call me --json
84
- collectui mcp repos --json
85
- collectui mcp download owner/repo --json
86
- collectui mcp feedback "..." --site reui --json
87
96
  ```
88
97
 
89
- Dash MCP endpoint: `https://dash.collectui.pro/api/mcp` (Bearer PAT). Tools:
90
- `me`, `list_repos`, `download_repo`, `submit_feedback`. The CLI also writes
91
- this server into the project's MCP config so agents can call it directly.
92
-
93
98
  ### Verify
94
99
 
95
100
  ```bash
@@ -1,92 +0,0 @@
1
- import { addMeSecrets, dashMcpTool, dashMcpTools, dashMe, formatMeHuman, formatTools } from "../dash.mjs";
2
- import { usageError } from "../errors.mjs";
3
- import { requireToken } from "./common.mjs";
4
-
5
- const ALLOWED = new Set(["me", "repos", "download", "feedback", "tools", "call"]);
6
-
7
- export async function dashCmd(flags, rest, reporter) {
8
- const sub = rest[0] ?? "me";
9
- if (!ALLOWED.has(sub)) {
10
- throw usageError(`Unknown dash subcommand "${sub}".`, {
11
- hint: "Usage: cui dash <me|repos|download|feedback|tools|call>",
12
- });
13
- }
14
- const token = requireToken(flags, reporter);
15
-
16
- if (sub === "me") {
17
- const me = await dashMe(token, { reporter });
18
- addMeSecrets(reporter, me);
19
- if (reporter.json) reporter.result(me);
20
- else reporter.note("Dash account", formatMeHuman(me));
21
- return;
22
- }
23
-
24
- if (sub === "tools") {
25
- const tools = await dashMcpTools(token, { reporter });
26
- if (reporter.json) reporter.result({ tools });
27
- else reporter.note("Dash MCP tools", formatTools(tools));
28
- return;
29
- }
30
-
31
- if (sub === "repos") {
32
- const result = await dashMcpTool(token, "list_repos", {}, { reporter });
33
- if (reporter.json) reporter.result(result);
34
- else {
35
- const lines = (result?.releases ?? []).map(
36
- (r) => `- ${r.repo} v${r.version} ${r.size ?? "?"} bytes ${r.releasedAt}`
37
- );
38
- reporter.note("Downloadable repos", lines.join("\n") || "(none)");
39
- }
40
- return;
41
- }
42
-
43
- if (sub === "download") {
44
- const repo = rest[1];
45
- if (!repo) throw usageError("Usage: cui dash download <owner/repo>");
46
- const result = await dashMcpTool(token, "download_repo", { repo }, { reporter });
47
- if (reporter.json) reporter.result(result);
48
- else {
49
- reporter.note(
50
- "Download",
51
- [
52
- `- repo: ${result?.repo ?? repo}`,
53
- `- version: ${result?.version ?? "?"}`,
54
- `- url: ${result?.url ?? "(no url)"}`,
55
- result?.expiresAt ? `- expires: ${result.expiresAt}` : null,
56
- ].filter(Boolean).join("\n")
57
- );
58
- }
59
- return;
60
- }
61
-
62
- if (sub === "feedback") {
63
- const message = rest.slice(1).join(" ").trim();
64
- if (!message) throw usageError("Usage: cui dash feedback <message> [--site reui]");
65
- const result = await dashMcpTool(
66
- token,
67
- "submit_feedback",
68
- { message, ...(flags.site ? { site: String(flags.site) } : {}) },
69
- { reporter }
70
- );
71
- if (reporter.json) reporter.result(result);
72
- else reporter.note("Feedback", JSON.stringify(result, null, 2));
73
- return;
74
- }
75
-
76
- if (sub === "call") {
77
- const name = rest[1];
78
- if (!name) throw usageError("Usage: cui dash call <tool> [--args '<json>']");
79
- let args = {};
80
- if (flags.args) {
81
- try {
82
- args = JSON.parse(String(flags.args));
83
- } catch (error) {
84
- throw usageError(`--args is not valid JSON: ${error.message}`);
85
- }
86
- }
87
- const result = await dashMcpTool(token, name, args, { reporter });
88
- if (result?.keys) addMeSecrets(reporter, result);
89
- if (reporter.json) reporter.result({ tool: name, result });
90
- else reporter.note(`mcp:${name}`, typeof result === "string" ? result : JSON.stringify(result, null, 2));
91
- }
92
- }