@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/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 行
@@ -190,11 +200,71 @@ export function createReporter({
190
200
  }
191
201
  return answer;
192
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
+ },
193
220
  };
194
221
 
195
222
  return reporter;
196
223
  }
197
224
 
225
+ /**
226
+ * p.note 的标题栏徽标版:账户名这类「标题右侧的短元数据」不再挤进正文首行。
227
+ * 先让 clack 原样渲染整个面板(几何/颜色/缩进逐字节原生,不自己复刻),捕获
228
+ * 输出后只动标题行一刀:在尾部 ─ 段开个口,嵌入右对齐的 badge(badge 两侧
229
+ * 各留至少一个 ─,与左侧 `标题 ─` 对称)。面板宽度容不下时原样输出,退化回
230
+ * 普通面板。
231
+ */
232
+ function noteWithBadge(body, title, badge) {
233
+ if (!badge) return p.note(body, title);
234
+ const orig = process.stdout.write.bind(process.stdout);
235
+ let buf = "";
236
+ process.stdout.write = (chunk) => {
237
+ buf += chunk;
238
+ };
239
+ try {
240
+ p.note(body, title);
241
+ } finally {
242
+ process.stdout.write = orig;
243
+ }
244
+ orig(injectTitleBadge(buf, badge));
245
+ }
246
+
247
+ /** 单改标题行:◇ Account ────╮ → ◇ Account ── super-admin ─╮(总宽不变)。 */
248
+ function injectTitleBadge(buf, badge) {
249
+ const lines = buf.split("\n");
250
+ const at = lines.findIndex((line) => line.includes("◇"));
251
+ if (at === -1) return buf;
252
+ const line = lines[at];
253
+ const first = line.indexOf("─");
254
+ const last = line.lastIndexOf("─");
255
+ if (first === -1) return buf;
256
+ const label = ` ${badge} `;
257
+ const dashes = last - first + 1;
258
+ if (dashes < label.length + 2) return buf; // 放不下(badge 后还要留一个 ─)
259
+ const keep = dashes - label.length - 1; // badge 左侧保留的 ─ 数
260
+ // badge 与标题同色(clack 标题文本是默认前景);嵌入点在 gray ─ 段中间,
261
+ // 有色模式下要先把 gray 关掉、badge 后再重开,无色模式(非 TTY)纯文本
262
+ const colored = buf.includes("\x1b[");
263
+ const wrapped = colored ? `\x1b[39m${label}\x1b[90m` : label;
264
+ lines[at] = line.slice(0, first + keep) + wrapped + "─" + line.slice(last + 1);
265
+ return lines.join("\n");
266
+ }
267
+
198
268
  function sanitize(value, redact) {
199
269
  if (typeof value === "string") return redact(value);
200
270
  if (Array.isArray(value)) return value.map((v) => sanitize(v, redact));
@@ -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-dash`.
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
 
@@ -75,21 +77,26 @@ collectui add 21st shugar/button-1
75
77
  Every library installs through `npx shadcn@latest add @scope/<component>
76
78
  --yes`. Use `--print` to only print the command.
77
79
 
78
- ### Dash MCP
80
+ ### CollectUI MCP (call it directly — do not shell out to the CLI for this)
81
+
82
+ The `collectui` MCP server is already written into this project's MCP config
83
+ (`.mcp.json` / `.cursor/mcp.json` / `.vscode/mcp.json`). Use your own MCP
84
+ client to call its tools: `me` (full account aggregation), `list_repos` /
85
+ `download_repo` (snapshot source downloads), `get_site` / `get_site_docs` /
86
+ `get_changelog`, `service_status`, `submit_feedback`, purchase-request tools.
87
+
88
+ Feedback submissions, purchase requests and votes change Dash data as the PAT owner. Headless `cui add` can overwrite existing component files.
89
+
90
+ Division of labor: **MCP answers "what"** (data, entitlements, docs);
91
+ **the CLI does "how"** (configure, install, write files). Never fetch MCP
92
+ data through the CLI — it has no such commands.
93
+
94
+ To inspect or re-write the MCP config itself:
79
95
 
80
96
  ```bash
81
97
  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
98
  ```
88
99
 
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
100
  ### Verify
94
101
 
95
102
  ```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
- }