@collectui/cli 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/cli.mjs ADDED
@@ -0,0 +1,174 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * collectui / cui —— CollectUI Dash 的 shadcn 三方库统一 CLI。
4
+ *
5
+ * 一个命令管所有库:登录 Dash(PAT)→ 看清拥有哪些库 → 一键把 registry、
6
+ * license env、MCP servers 配进任意项目 → add 装组件 → doctor 体检。
7
+ *
8
+ * 交互用 @clack/prompts(p CLI 同款);`--json` 或非 TTY 自动进无头模式
9
+ * (stdout 只出逐行 JSON event,Agent 直接消费)。所有动作经 ChangeSet:
10
+ * 先展示计划再落盘,`--dry-run` 只看不写,密钥全程脱敏。
11
+ */
12
+ import { parseArgv } from "./args.mjs";
13
+ import { CLI_NAME, CLI_VERSION } from "./version.mjs";
14
+ import { collectSecrets, readConfig, resolveToken } from "./config.mjs";
15
+ import { CliError, usageError } from "./errors.mjs";
16
+ import { createReporter } from "./report.mjs";
17
+ import { loginCmd, logoutCmd } from "./commands/login.mjs";
18
+ import { whoamiCmd } from "./commands/whoami.mjs";
19
+ import { libsCmd } from "./commands/libs.mjs";
20
+ import { initCmd } from "./commands/init.mjs";
21
+ import { configureCmd } from "./commands/configure.mjs";
22
+ import { addCmd } from "./commands/add.mjs";
23
+ import { doctorCmd } from "./commands/doctor.mjs";
24
+ import { mcpCmd } from "./commands/mcp.mjs";
25
+ import { dashCmd } from "./commands/dash.mjs";
26
+ import { skillCmd } from "./commands/skill.mjs";
27
+
28
+ const HELP = `collectui ${CLI_VERSION} — one CLI for every shadcn library on CollectUI Dash
29
+
30
+ Usage:
31
+ collectui <command> [args] [flags]
32
+
33
+ Commands:
34
+ login Open Dash in your browser and save a PAT
35
+ logout Remove the saved PAT
36
+ whoami, me Show account, libraries, bound keys and repos
37
+ libs List every library, ownership and key status
38
+ init [dir] Scaffold a project and configure selected libraries
39
+ configure [dir] Configure an existing shadcn project
40
+ add <lib> <comp...> Install components with the library's channel
41
+ mcp <sub> Show/init MCP config; call Dash MCP tools
42
+ dash <sub> Dash MCP: me, repos, download, feedback, tools, call
43
+ skill [dir] Install the agent skill (.claude/skills/collectui)
44
+ doctor Verify login, registries, env and MCP config
45
+
46
+ Global options:
47
+ --token <PAT> Dash PAT (dpat_...); overrides saved login
48
+ --json Headless: one JSON event per line, no prompts
49
+ --headless No prompts (human output); agents usually want --json
50
+ --yes, -y Skip confirmation prompts
51
+ --dry-run Print the full plan; write nothing
52
+ --verbose, -v Show HTTP requests, diffs and per-entry decisions
53
+ --no-open Do not open a browser during login
54
+ --no-install init: skip dependency installation
55
+ --no-mcp init/configure: skip MCP configuration
56
+ --no-dash-mcp Do not add the collectui-dash MCP server
57
+ --force Replace custom registry/MCP entries (deliberate)
58
+ --libs <list> Comma list or "all" (default: all owned)
59
+ --clients <list> claude,cursor,vscode,codex or all (default: claude,cursor,vscode)
60
+ --cwd <dir> Project directory (default: current directory)
61
+ --tmp init under the OS temp directory
62
+ --name <name> Project/package name
63
+ --template <t> vite (default) or none
64
+ --pm <pm> npm | pnpm | yarn | bun
65
+ --scope <@scope> add: force a registry scope
66
+ --no-auto-configure add: refuse to write missing registry scopes
67
+ --print add: print the command without running it
68
+ --deep doctor: probe every owned registry
69
+ --timeout <ms> login callback/paste timeout (default 180000)
70
+ --help, -h Show help
71
+ --version, -V Show version
72
+
73
+ Examples:
74
+ collectui login
75
+ collectui libs --json
76
+ collectui init /tmp/my-app --libs reui,arc --yes --no-install
77
+ collectui configure . --libs all --dry-run
78
+ collectui add reui data-grid
79
+ collectui mcp show --json
80
+ collectui dash repos --json
81
+ COLLECTUI_TOKEN=dpat_... collectui whoami --json
82
+
83
+ Environment:
84
+ COLLECTUI_TOKEN Dash PAT (headless/CI)
85
+ COLLECTUI_DASH_URL default https://dash.collectui.pro
86
+ COLLECTUI_REGISTRY_URL default https://registry.collectui.pro
87
+ COLLECTUI_HOME config directory override
88
+ `;
89
+
90
+ const COMMANDS = {
91
+ login: { run: loginCmd, aliases: [] },
92
+ logout: { run: logoutCmd, aliases: [] },
93
+ whoami: { run: whoamiCmd, aliases: ["me"] },
94
+ libs: { run: libsCmd, aliases: ["list"] },
95
+ init: { run: initCmd, aliases: ["new"] },
96
+ configure: { run: configureCmd, aliases: ["config", "setup"] },
97
+ add: { run: addCmd, aliases: ["install"] },
98
+ mcp: { run: mcpCmd, aliases: [] },
99
+ dash: { run: dashCmd, aliases: [] },
100
+ skill: { run: skillCmd, aliases: ["install-skill"] },
101
+ doctor: { run: doctorCmd, aliases: ["check"] },
102
+ };
103
+
104
+ function findCommand(name) {
105
+ if (COMMANDS[name]) return { name, ...COMMANDS[name] };
106
+ for (const [key, value] of Object.entries(COMMANDS)) {
107
+ if (value.aliases.includes(name)) return { name: key, ...value };
108
+ }
109
+ return null;
110
+ }
111
+
112
+ function printHelp() {
113
+ process.stdout.write(HELP);
114
+ }
115
+
116
+ function printVersion() {
117
+ process.stdout.write(`${CLI_NAME} ${CLI_VERSION}\n`);
118
+ }
119
+
120
+ function makeReporter(flags, token) {
121
+ const json = Boolean(flags.json) || process.env.COLLECTUI_JSON === "1";
122
+ const config = readConfig();
123
+ return createReporter({
124
+ json,
125
+ yes: Boolean(flags.yes || flags.y),
126
+ dryRun: Boolean(flags["dry-run"]),
127
+ secrets: collectSecrets(null, token || config.token),
128
+ verbose: Boolean(flags.verbose || flags.v),
129
+ forceHeadless: Boolean(flags.headless),
130
+ });
131
+ }
132
+
133
+ async function main() {
134
+ const argv = process.argv.slice(2);
135
+ const { flags, positionals } = parseArgv(argv);
136
+ if (flags.json) process.env.COLLECTUI_JSON = "1";
137
+
138
+ if (flags.version || flags.V) return printVersion();
139
+ if (flags.help) return printHelp();
140
+
141
+ const name = positionals[0];
142
+ if (!name) {
143
+ printHelp();
144
+ return;
145
+ }
146
+ if (name === "help" || name === "--help" || name === "-h" || name === "?") {
147
+ printHelp();
148
+ return;
149
+ }
150
+ const command = findCommand(name);
151
+ if (!command) {
152
+ throw usageError(`Unknown command "${name}".`, "Run `collectui help` to see the command list.");
153
+ }
154
+ const rest = positionals.slice(1);
155
+ const token = resolveToken(flags);
156
+ const reporter = makeReporter(flags, token);
157
+ if (token) reporter.addSecrets([token]);
158
+
159
+ await command.run(flags, rest, reporter);
160
+ }
161
+
162
+ main().catch((error) => {
163
+ const exitCode = error instanceof CliError ? error.exitCode : 1;
164
+ const message = error instanceof CliError ? error.message : error?.stack || String(error);
165
+ const hint = error instanceof CliError ? error.hint : undefined;
166
+ const json = process.env.COLLECTUI_JSON === "1" || process.argv.includes("--json");
167
+ if (json) {
168
+ process.stdout.write(`${JSON.stringify({ event: "error", message, hint: hint ?? null, exitCode })}\n`);
169
+ } else {
170
+ process.stderr.write(`✖ ${message}\n`);
171
+ if (hint) process.stderr.write(` hint: ${hint}\n`);
172
+ }
173
+ process.exit(exitCode);
174
+ });
@@ -0,0 +1,186 @@
1
+ import { existsSync, readFileSync } from "node:fs";
2
+ import { join, resolve } from "node:path";
3
+ import { ChangeSet } from "../changes.mjs";
4
+ import { libBySlug, resolveLibKeys } from "../catalog.mjs";
5
+ import { CliError, usageError } from "../errors.mjs";
6
+ import { registryUrl } from "../config.mjs";
7
+ import { detectProjectRoot, mergeRegistries, parseEnvText } from "../project.mjs";
8
+ import { loadMe } from "./common.mjs";
9
+
10
+ /**
11
+ * collectui add <lib> <component...>
12
+ * 全部库都走 shadcn registry 通道:npx shadcn@latest add @scope/<component> --yes
13
+ */
14
+ export async function addCmd(flags, rest, reporter) {
15
+ const libSlug = rest[0];
16
+ const rawComponents = rest.slice(1);
17
+ if (!libSlug || rawComponents.length === 0) {
18
+ throw usageError("Usage: collectui add <library> <component...>", {
19
+ hint: "Examples: collectui add reui data-grid · collectui add arc pro/dock · collectui add studio blocks/hero-01",
20
+ });
21
+ }
22
+
23
+ const lib = libBySlug(libSlug);
24
+ if (!lib) throw usageError(`Unknown library "${libSlug}".`, { hint: "Run `collectui libs`." });
25
+
26
+ const detected = detectProjectRoot(flags.cwd ? resolve(String(flags.cwd)) : process.cwd());
27
+ const root = detected.root;
28
+ if (!existsSync(join(root, "components.json"))) {
29
+ throw new CliError(`No components.json under ${root}.`, {
30
+ hint: "Run `collectui init` first, or --cwd into a shadcn project.",
31
+ });
32
+ }
33
+
34
+ const me = await loadMe(flags, reporter, { required: false });
35
+ if (me) reporter.addSecrets((me.keys ?? []).map((k) => k.key).filter(Boolean));
36
+
37
+ const envText = readText(join(root, ".env.local")) ?? "";
38
+ const fileEnv = parseEnvText(envText);
39
+ const meCliKey = me ? resolveLibKeys(lib, me).cli : null;
40
+ const envCliKey = pickEnvKey(lib, fileEnv);
41
+ const cliKey = meCliKey || envCliKey;
42
+ if (cliKey) reporter.addSecrets([cliKey]);
43
+
44
+ return addViaRegistry({ flags, reporter, lib, rawComponents, root, cliKey, fileEnv, me });
45
+ }
46
+
47
+ function addViaRegistry({ flags, reporter, lib, rawComponents, root, cliKey, fileEnv, me }) {
48
+ const picked = pickRegistries(lib, rawComponents, flags.scope);
49
+ const names = picked.map((item) => item.name);
50
+ const scopes = [...new Set(picked.map((item) => item.registry?.scope).filter(Boolean))];
51
+
52
+ const needsKey = picked.some(
53
+ (item) => item.registry && (item.registry.headers || item.registry.params)
54
+ );
55
+ if (needsKey && !cliKey) {
56
+ throw new CliError(`No CLI key for ${lib.siteName}.`, {
57
+ hint: `Bind a key on ${lib.siteName} in Dash, or write the matching variable into .env.local.`,
58
+ });
59
+ }
60
+
61
+ const componentsPath = join(root, "components.json");
62
+ let components;
63
+ try {
64
+ components = JSON.parse(readFileSync(componentsPath, "utf8"));
65
+ } catch (error) {
66
+ throw new CliError(`Cannot parse ${componentsPath}: ${error.message}`, {
67
+ hint: "Fix the JSON, then retry.",
68
+ });
69
+ }
70
+ const missing = scopes.filter((scope) => !(components.registries ?? {})[scope]);
71
+ if (missing.length > 0) {
72
+ if (flags["no-auto-configure"]) {
73
+ throw new CliError(
74
+ `${root} is missing registry scope(s): ${missing.join(", ")}.`,
75
+ { hint: `Run \`collectui configure ${root} --libs ${lib.site}\` first.` }
76
+ );
77
+ }
78
+ if (flags.print) {
79
+ reporter.warn(`Missing registry scope(s) ${missing.join(", ")} — a real run would auto-configure them.`);
80
+ } else if (!cliKey && needsKey) {
81
+ throw new CliError(`Cannot auto-configure ${lib.siteName}: no CLI key is bound.`, {
82
+ hint: "Run `collectui configure` after binding a key in Dash.",
83
+ });
84
+ }
85
+ }
86
+
87
+ const args = ["shadcn@latest", "add", ...names, "--yes"];
88
+ // --force 或无头模式加 --overwrite:shadcn 遇到同名文件会弹覆盖确认,
89
+ // 非 TTY 下默认拒绝并静默跳过剩余文件(starter button.tsx 实测踩坑);
90
+ // 无头场景重装是常态,覆盖同名 starter/依赖文件是预期行为。
91
+ if (flags.force || reporter.headless) args.push("--overwrite");
92
+ // 子进程 env:.env.local 现值打底,再补齐该库全部 env spec——
93
+ // cliKey 型用账户 key,固定值型(studio 的 EMAIL 等)也不能漏,shadcn CLI
94
+ // 要求 components.json 里引用的每个 ${VAR} 都有值。
95
+ const env = { ...fileEnv };
96
+ for (const spec of lib.env ?? []) {
97
+ if (env[spec.name]) continue;
98
+ if (spec.from === "cliKey") {
99
+ if (cliKey) env[spec.name] = cliKey;
100
+ } else if (spec.value !== undefined) {
101
+ env[spec.name] = spec.value;
102
+ }
103
+ }
104
+
105
+ const command = ["npx", ...args].join(" ");
106
+ if (flags.print) {
107
+ reporter.result({ command, components: names, scopes, env: Object.keys(env), missingScopes: missing });
108
+ return { command };
109
+ }
110
+
111
+ reporter.info(
112
+ `Registry: ${scopes.join(", ") || "(direct)"}${needsKey ? " (key attached via env)" : " (free)"}`
113
+ );
114
+ const cs = new ChangeSet({
115
+ reporter,
116
+ dryRun: Boolean(flags["dry-run"]),
117
+ yes: Boolean(flags.yes) || reporter.headless,
118
+ root,
119
+ });
120
+ if (missing.length > 0) {
121
+ const { components: next } = mergeRegistries(components, [lib], {
122
+ me,
123
+ registryBase: registryUrl(),
124
+ force: Boolean(flags.force),
125
+ });
126
+ cs.write(componentsPath, `${JSON.stringify(next, null, 2)}\n`, {
127
+ summary: `auto-configure ${lib.siteName} registry scope(s): ${missing.join(", ")}`,
128
+ });
129
+ }
130
+ cs.run("npx", args, { cwd: root, env, summary: `install ${names.join(", ")}` });
131
+ return cs.apply();
132
+ }
133
+
134
+ function pickRegistries(lib, components, scopeFlag) {
135
+ let forced = null;
136
+ if (scopeFlag) {
137
+ forced = String(scopeFlag).startsWith("@") ? String(scopeFlag) : `@${scopeFlag}`;
138
+ if (!lib.registries.some((r) => r.scope === forced)) {
139
+ throw usageError(`Unknown scope "${scopeFlag}" for ${lib.site}.`, {
140
+ hint: `Available: ${lib.registries.map((r) => r.scope).join(", ")}`,
141
+ });
142
+ }
143
+ }
144
+
145
+ return components.map((component) => {
146
+ if (component.startsWith("@")) {
147
+ const scope = component.split("/")[0];
148
+ return { name: component, registry: lib.registries.find((r) => r.scope === scope) ?? null };
149
+ }
150
+ if (forced) {
151
+ return { name: `${forced}/${component}`, registry: lib.registries.find((r) => r.scope === forced) };
152
+ }
153
+ // 组件带路径前缀(pro/、components/、blocks/、themes/、starter/)时自动选对应 scope。
154
+ // registry path 里的 style 段(studio 的 blocks/new-york-v4/…)允许用户省略:
155
+ // `blocks/hero-01` 与 `blocks/new-york-v4/hero-01` 都路由到 @ss-blocks。
156
+ for (const registry of lib.registries) {
157
+ const prefix = (registry.path ?? "").split("{")[0];
158
+ if (prefix && component.startsWith(prefix)) {
159
+ return { name: `${registry.scope}/${component.slice(prefix.length)}`, registry };
160
+ }
161
+ const dirPrefix = prefix.includes("/") ? `${prefix.split("/")[0]}/` : null;
162
+ if (dirPrefix && dirPrefix !== prefix && component.startsWith(dirPrefix)) {
163
+ const rest = component.slice(dirPrefix.length);
164
+ if (!rest.includes("/")) {
165
+ return { name: `${registry.scope}/${rest}`, registry };
166
+ }
167
+ }
168
+ }
169
+ return { name: `${lib.registries[0].scope}/${component}`, registry: lib.registries[0] };
170
+ });
171
+ }
172
+
173
+ function pickEnvKey(lib, env) {
174
+ for (const spec of lib.env ?? []) {
175
+ if (spec.from === "cliKey" && env[spec.name]) return env[spec.name];
176
+ }
177
+ return null;
178
+ }
179
+
180
+ function readText(path) {
181
+ try {
182
+ return readFileSync(path, "utf8");
183
+ } catch {
184
+ return null;
185
+ }
186
+ }
@@ -0,0 +1,125 @@
1
+ import * as p from "@clack/prompts";
2
+ import { listFlag } from "../args.mjs";
3
+ import {
4
+ LIBS,
5
+ allSlugs,
6
+ configUnits,
7
+ libBySlug,
8
+ ownedLibs,
9
+ } from "../catalog.mjs";
10
+ import { resolveToken } from "../config.mjs";
11
+ import { authError, usageError } from "../errors.mjs";
12
+ import { fetchMe } from "../dash.mjs";
13
+
14
+ export function requireToken(flags, reporter) {
15
+ const token = resolveToken(flags);
16
+ if (!token) {
17
+ throw authError("Not logged in.", {
18
+ hint: "Run `collectui login` (opens Dash in your browser), or pass --token / set COLLECTUI_TOKEN.",
19
+ });
20
+ }
21
+ reporter?.addSecrets([token]);
22
+ return token;
23
+ }
24
+
25
+ export async function loadMe(flags, reporter, { required = true } = {}) {
26
+ const token = resolveToken(flags);
27
+ if (!token) {
28
+ if (required) return requireToken(flags, reporter);
29
+ return null;
30
+ }
31
+ reporter?.addSecrets([token]);
32
+ const me = await fetchMe(token, { reporter });
33
+ reporter?.addSecrets(
34
+ (me.keys ?? []).map((k) => k.key).filter(Boolean)
35
+ );
36
+ return me;
37
+ }
38
+
39
+ export function ownedSlugs(me) {
40
+ return new Set(ownedLibs(me).map((lib) => lib.site));
41
+ }
42
+
43
+ /**
44
+ * 选中要配置的库:
45
+ * - --libs all / 逗号列表 / 单个
46
+ * - 未指定时:无头 = 全部已拥有;TTY = 多选(默认全选)
47
+ */
48
+ export async function selectLibs({ flags, me, reporter }) {
49
+ const owned = ownedLibs(me);
50
+ if (owned.length === 0) {
51
+ throw usageError("Your account has no libraries with shadcn registry/MCP access.", {
52
+ hint: "Buy or bind a library in Dash first: https://dash.collectui.pro",
53
+ });
54
+ }
55
+
56
+ const requested = listFlag(flags.libs);
57
+ let slugs;
58
+ if (requested.length === 0 || requested.includes("all")) {
59
+ if (reporter.headless || flags.yes) {
60
+ slugs = owned.map((lib) => lib.site);
61
+ } else {
62
+ const answer = await p.multiselect({
63
+ message: "Which libraries do you want to configure?",
64
+ options: owned.map((lib) => ({
65
+ value: lib.site,
66
+ label: `${lib.siteName} (${lib.site})`,
67
+ })),
68
+ initialValues: owned.map((lib) => lib.site),
69
+ required: true,
70
+ });
71
+ if (p.isCancel(answer)) {
72
+ p.cancel("Cancelled.");
73
+ process.exit(0);
74
+ }
75
+ slugs = answer;
76
+ }
77
+ } else {
78
+ slugs = requested;
79
+ }
80
+
81
+ const libs = [];
82
+ const seen = new Set();
83
+ const ownedSet = ownedSlugs(me);
84
+ const unowned = [];
85
+
86
+ for (const slug of slugs) {
87
+ const lib = libBySlug(slug);
88
+ if (!lib) {
89
+ throw usageError(`Unknown library "${slug}".`, {
90
+ hint: `Available: ${allSlugs().join(", ")}`,
91
+ });
92
+ }
93
+ if (!ownedSet.has(lib.site) && !flags["include-unowned"]) {
94
+ unowned.push(`${lib.siteName} (${lib.site})`);
95
+ continue;
96
+ }
97
+ if (!seen.has(lib.site)) {
98
+ seen.add(lib.site);
99
+ libs.push(lib);
100
+ }
101
+ }
102
+
103
+ if (unowned.length > 0) {
104
+ throw authError(`Not entitled to: ${unowned.join(", ")}.`, {
105
+ hint: "Buy/bind these libraries in Dash, or pass --include-unowned for free registry layers.",
106
+ });
107
+ }
108
+
109
+ return { libs, units: configUnits(libs) };
110
+ }
111
+
112
+ export function libLabel(lib) {
113
+ return `${lib.siteName} (${lib.site})`;
114
+ }
115
+
116
+ export function catalogSummary() {
117
+ return LIBS.map((lib) => ({
118
+ site: lib.site,
119
+ name: lib.siteName,
120
+ source: lib.source,
121
+ registries: (lib.registries ?? []).map((r) => r.scope),
122
+ mcp: lib.mcp ?? null,
123
+ shadcnUiMcp: Boolean(lib.shadcnUiMcp),
124
+ }));
125
+ }
@@ -0,0 +1,5 @@
1
+ import { runSetup } from "./setup.mjs";
2
+
3
+ export async function configureCmd(flags, rest, reporter) {
4
+ return runSetup({ flags, rest, reporter, mode: "configure" });
5
+ }
@@ -0,0 +1,92 @@
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: collectui 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: collectui 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: collectui 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: collectui 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
+ }