@collectui/cli 0.2.22 → 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 +16 -11
- package/package.json +1 -1
- package/src/changes.mjs +26 -2
- package/src/cli.mjs +19 -12
- package/src/commands/doctor.mjs +9 -2
- package/src/commands/mcp.mjs +9 -107
- package/src/commands/setup.mjs +42 -16
- package/src/commands/whoami.mjs +22 -4
- package/src/dash.mjs +15 -96
- package/src/git-privacy.mjs +72 -0
- package/src/http.mjs +1 -17
- package/src/login.mjs +2 -1
- package/src/mcp.mjs +3 -2
- package/src/report.mjs +56 -3
- package/src/skill/SKILL.md +16 -11
- package/src/commands/dash.mjs +0 -92
package/README.md
CHANGED
|
@@ -71,7 +71,7 @@ collectui configure . --libs all --dry-run
|
|
|
71
71
|
3. **MCP**:
|
|
72
72
|
- 库有专属 MCP → 写入 `<site>` server(HTTP 端点 / stdio 包)
|
|
73
73
|
- 库没有专属 MCP → 写官方 shadcn 通用 MCP(读 `components.json` 里所有 registry)
|
|
74
|
-
-
|
|
74
|
+
- 默认写 **`collectui`** MCP(Bearer PAT),Agent 可直接调用 Dash 工具
|
|
75
75
|
- 默认写 `claude`(`.mcp.json`)、`cursor`(`.cursor/mcp.json`)、`vscode`(`.vscode/mcp.json`);`--clients codex` 写 `~/.codex/config.toml`
|
|
76
76
|
4. **`.collectui/project.json` + `.collectui/environment.md`**:机器可读的配置记录(不含密钥)
|
|
77
77
|
|
|
@@ -114,23 +114,20 @@ collectui add reui data-grid --print # 只打印命令
|
|
|
114
114
|
|
|
115
115
|
- 所有库统一走 shadcn registry → `npx shadcn@latest add @scope/<component> --yes`
|
|
116
116
|
|
|
117
|
-
`--scope @uiarc-pro` 可强制 scope;`--force`
|
|
117
|
+
`--scope @uiarc-pro` 可强制 scope;`--force` 或无头模式会给 shadcn 加 `--overwrite`,可能覆盖已有组件文件。
|
|
118
118
|
|
|
119
|
-
## MCP
|
|
119
|
+
## MCP 配置
|
|
120
120
|
|
|
121
121
|
```bash
|
|
122
122
|
collectui mcp show # 打印按 client 分组的 MCP 配置
|
|
123
123
|
collectui mcp init # 只写/合并 MCP 配置
|
|
124
|
-
collectui mcp tools # Dash MCP 工具列表
|
|
125
|
-
collectui mcp call me # 调 Dash MCP 工具
|
|
126
|
-
collectui dash me # 账户聚合(MCP,404 回退 REST)
|
|
127
|
-
collectui dash repos # 可下快照仓
|
|
128
|
-
collectui dash download owner/repo # 取新的下载链接
|
|
129
|
-
collectui dash feedback "..." --site reui
|
|
130
124
|
```
|
|
131
125
|
|
|
132
|
-
|
|
133
|
-
`me
|
|
126
|
+
CollectUI MCP(server 名 `collectui`)是 **Agent 专用**通道:端点
|
|
127
|
+
`https://dash.collectui.pro/api/mcp`(Bearer PAT),工具 `me`、
|
|
128
|
+
`list_repos`、`download_repo`、`get_site_docs` 等——Agent 用自己的
|
|
129
|
+
MCP client 直接调,CLI 不提供转发。人查账户用 `collectui whoami`,
|
|
130
|
+
可下仓库/反馈/订单在 Dash 站点看。
|
|
134
131
|
|
|
135
132
|
## 无头 / Agent 驱动
|
|
136
133
|
|
|
@@ -221,3 +218,11 @@ node src/cli.mjs --help
|
|
|
221
218
|
## License
|
|
222
219
|
|
|
223
220
|
MIT
|
|
221
|
+
|
|
222
|
+
## 已有项目:配置是否进过 Git?
|
|
223
|
+
|
|
224
|
+
- **仅在暂存区**:用 `cui doctor` 检查索引。对于 `.env.local` 等本地文件,交互式 `configure` 可单独确认停止跟踪,保留磁盘文件;`components.json` 应保留,配置 Guard 后重新暂存,用 `collectui-guard status` 复核索引。不要贴出原始 diff 或凭据。
|
|
225
|
+
- **已在本地提交**:取消跟踪只影响下一次提交。先备份,推送之前复核并清理含敏感内容的本地历史。
|
|
226
|
+
- **已推送或分享**:立即撤销或轮换相关凭据,审查访问记录,再协调历史清理。列出受影响分支和标签,在独立副本备份、清理和复核;更新远端须另行确认,通知协作者重新克隆,必要时联系托管方处理 PR 引用及缓存。fork、旧克隆和已下载的副本无法保证删除。
|
|
227
|
+
|
|
228
|
+
检查使用本机已有的 Git 引用,不会联网核实、重写历史或强推。未命中不能证明从未外发;仅命中配置路径也不能证明其中有有效密钥。无头运行不会代替用户确认清理。
|
package/package.json
CHANGED
package/src/changes.mjs
CHANGED
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
statSync,
|
|
8
8
|
writeFileSync,
|
|
9
9
|
} from "node:fs";
|
|
10
|
+
import { tmpdir } from "node:os";
|
|
10
11
|
import { dirname, relative } from "node:path";
|
|
11
12
|
import { CliError } from "./errors.mjs";
|
|
12
13
|
|
|
@@ -27,9 +28,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
|
-
|
|
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>
|
|
44
|
-
dash <sub> Dash MCP: me, repos, download, feedback, tools, call
|
|
42
|
+
mcp <sub> Manage MCP servers for your agents: show / init config
|
|
45
43
|
skill [dir] Install the agent skill (.claude/skills/collectui)
|
|
46
44
|
doctor Verify login, registries, env and MCP config
|
|
47
45
|
update Update the CLI now (--check only checks)
|
|
@@ -57,7 +55,7 @@ Global options:
|
|
|
57
55
|
--pat login: paste a PAT instead of browser authorization (no-browser hosts)
|
|
58
56
|
--no-install init: skip dependency installation
|
|
59
57
|
--no-mcp init/configure: skip MCP configuration
|
|
60
|
-
--no-dash-mcp Do not add the
|
|
58
|
+
--no-dash-mcp Do not add the CollectUI MCP (collectui) server
|
|
61
59
|
--force Replace custom registry/MCP entries (deliberate)
|
|
62
60
|
--libs <list> Comma list or "all" (default: all owned)
|
|
63
61
|
--clients <list> claude,cursor,vscode,codex or all (default: claude,cursor,vscode)
|
|
@@ -82,7 +80,6 @@ Examples:
|
|
|
82
80
|
cui configure . --libs all --dry-run
|
|
83
81
|
cui add reui data-grid
|
|
84
82
|
cui mcp show --json
|
|
85
|
-
cui dash repos --json
|
|
86
83
|
COLLECTUI_TOKEN=dpat_... cui whoami --json
|
|
87
84
|
|
|
88
85
|
Environment:
|
|
@@ -102,7 +99,6 @@ const COMMANDS = {
|
|
|
102
99
|
configure: { run: configureCmd, aliases: ["config", "setup"] },
|
|
103
100
|
add: { run: addCmd, aliases: ["install"] },
|
|
104
101
|
mcp: { run: mcpCmd, aliases: [] },
|
|
105
|
-
dash: { run: dashCmd, aliases: [] },
|
|
106
102
|
skill: { run: skillCmd, aliases: ["install-skill"] },
|
|
107
103
|
doctor: { run: doctorCmd, aliases: ["check"] },
|
|
108
104
|
update: { run: updateCmd, aliases: ["upgrade"] },
|
|
@@ -121,9 +117,10 @@ function findCommand(name) {
|
|
|
121
117
|
* skill 只落一个文件,都读不到目录。whoami 标了 parallel——入口不等目录,命令里把
|
|
122
118
|
* 目录与账号两请求同 tick 并行发出(谁慢等谁,省掉串行那一趟)。
|
|
123
119
|
*/
|
|
124
|
-
const CATALOG_SKIP = new Set(["login", "logout", "update", "
|
|
120
|
+
const CATALOG_SKIP = new Set(["login", "logout", "update", "skill"]);
|
|
125
121
|
|
|
126
|
-
function printHelp() {
|
|
122
|
+
function printHelp(headless = false) {
|
|
123
|
+
showBanner({ headless }); // help 也是人肉场景:开机画面与其他子命令同款(headless/--json/非 TTY 降级为纯 HELP)
|
|
127
124
|
process.stdout.write(HELP);
|
|
128
125
|
}
|
|
129
126
|
|
|
@@ -131,6 +128,16 @@ function printVersion() {
|
|
|
131
128
|
process.stdout.write(`${CLI_NAME} ${CLI_VERSION}\n`);
|
|
132
129
|
}
|
|
133
130
|
|
|
131
|
+
/** help 分流发生在 makeReporter 之前:headless 判定照抄 createReporter 的公式。 */
|
|
132
|
+
function isHeadless(flags) {
|
|
133
|
+
return Boolean(
|
|
134
|
+
flags.json ||
|
|
135
|
+
process.env.COLLECTUI_JSON === "1" ||
|
|
136
|
+
flags.headless ||
|
|
137
|
+
!process.stdout.isTTY
|
|
138
|
+
);
|
|
139
|
+
}
|
|
140
|
+
|
|
134
141
|
function makeReporter(flags, token) {
|
|
135
142
|
const json = Boolean(flags.json) || process.env.COLLECTUI_JSON === "1";
|
|
136
143
|
const config = readConfig();
|
|
@@ -150,15 +157,15 @@ async function main() {
|
|
|
150
157
|
if (flags.json) process.env.COLLECTUI_JSON = "1";
|
|
151
158
|
|
|
152
159
|
if (flags.version || flags.V) return printVersion();
|
|
153
|
-
if (flags.help) return printHelp();
|
|
160
|
+
if (flags.help) return printHelp(isHeadless(flags));
|
|
154
161
|
|
|
155
162
|
const name = positionals[0];
|
|
156
163
|
if (!name) {
|
|
157
|
-
printHelp();
|
|
164
|
+
printHelp(isHeadless(flags));
|
|
158
165
|
return;
|
|
159
166
|
}
|
|
160
167
|
if (name === "help" || name === "--help" || name === "-h" || name === "?") {
|
|
161
|
-
printHelp();
|
|
168
|
+
printHelp(isHeadless(flags));
|
|
162
169
|
return;
|
|
163
170
|
}
|
|
164
171
|
const command = findCommand(name);
|
|
@@ -170,7 +177,7 @@ async function main() {
|
|
|
170
177
|
const reporter = makeReporter(flags, token);
|
|
171
178
|
if (token) reporter.addSecrets([token]);
|
|
172
179
|
|
|
173
|
-
showBanner(reporter); // 开机画面:任何子命令(headless/--version
|
|
180
|
+
showBanner(reporter); // 开机画面:任何子命令(headless/--version 已在前面分流;help 走 printHelp 自带同款)
|
|
174
181
|
// 更新检查最先出发:与目录/账号请求并行,命令收尾时多半已查完(少等收尾那 1 秒)。
|
|
175
182
|
// TTY 才查,有新版打一行提醒;手动 update 命令自身不触发(避免与前台安装并发写全局目录)
|
|
176
183
|
const updateNotice =
|
package/src/commands/doctor.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { auditGit } from "../git-privacy.mjs";
|
|
1
2
|
import { existsSync, readFileSync } from "node:fs";
|
|
2
3
|
import { join, resolve } from "node:path";
|
|
3
4
|
import { activeCatalog, ownedLibs, registryUrl, resolveLibKeys } from "../catalog.mjs";
|
|
@@ -36,16 +37,22 @@ export async function doctorCmd(flags, rest, reporter) {
|
|
|
36
37
|
if (token) {
|
|
37
38
|
try {
|
|
38
39
|
const tools = await dashMcpTools(token, { reporter });
|
|
39
|
-
|
|
40
|
+
// 工具名全列表一行几百字符会撑爆面板——只报数量 + 前几个,Agent 侧全量在 MCP client 里看
|
|
41
|
+
add(
|
|
42
|
+
"collectui mcp",
|
|
43
|
+
"ok",
|
|
44
|
+
`${tools.length} tools (${tools.slice(0, 3).map((t) => t.name).join(", ")}…)`
|
|
45
|
+
);
|
|
40
46
|
} catch (error) {
|
|
41
47
|
const status = /404|not enabled/i.test(error.message) ? "warn" : "fail";
|
|
42
|
-
add("
|
|
48
|
+
add("collectui mcp", status, error.message);
|
|
43
49
|
}
|
|
44
50
|
}
|
|
45
51
|
|
|
46
52
|
// 项目检查
|
|
47
53
|
const detected = detectProjectRoot(flags.cwd ? resolve(String(flags.cwd)) : process.cwd());
|
|
48
54
|
const root = detected.root;
|
|
55
|
+
for (const message of auditGit(root).messages) add("git privacy", "warn", message);
|
|
49
56
|
const componentsPath = join(root, "components.json");
|
|
50
57
|
if (!existsSync(componentsPath)) {
|
|
51
58
|
add("project", "warn", `no components.json under ${root}`);
|
package/src/commands/mcp.mjs
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
call <tool> Call a Dash MCP tool (--args '<json>')
|
|
195
|
-
me Account aggregation via Dash MCP
|
|
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.`;
|
package/src/commands/setup.mjs
CHANGED
|
@@ -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
|
|
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
|
-
|
|
74
|
-
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
|
-
|
|
85
|
-
token =
|
|
86
|
+
pendingSession = await login({ reporter, persist: false });
|
|
87
|
+
token = pendingSession.token;
|
|
86
88
|
reporter.addSecrets([token]);
|
|
87
|
-
me =
|
|
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
|
|
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
|
-
|
|
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
|
}
|
package/src/commands/whoami.mjs
CHANGED
|
@@ -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
|
-
|
|
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
|
|
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,44 +1,37 @@
|
|
|
1
|
+
import { CliError } from "./errors.mjs";
|
|
1
2
|
import { dashUrl } from "./config.mjs";
|
|
2
|
-
import { jsonRequest, mcpCall
|
|
3
|
+
import { jsonRequest, mcpCall } from "./http.mjs";
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* CLI 专用数据面 GET /api/account(2026-12-01):{ account, sites, keys }——账户本体 +
|
|
6
7
|
* 按站授权 + 绑定 key。CLI 全部命令(whoami / init / configure / add / mcp / doctor /
|
|
7
8
|
* login)要的只有这些;可下仓库、订单、HP 凭据一个都用不到。
|
|
8
|
-
* 兼容旧版 Dash:没有该路由(404),或只有首版形状(仅 account)→ 退回 /api/me 取同名切片。
|
|
9
|
-
* (/api/me 这个 HTTP 端点 2026-12-02 已从 Dash 移除,回退只对回滚到更早版本时有意义。)
|
|
10
9
|
*/
|
|
11
10
|
export async function fetchAccount(token, { reporter } = {}) {
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
spinner: "Loading your account from Dash…",
|
|
18
|
-
});
|
|
19
|
-
let data = null;
|
|
20
|
-
try {
|
|
21
|
-
const light = await request("/api/account");
|
|
22
|
-
if (Array.isArray(light?.sites) && Array.isArray(light?.keys)) data = light;
|
|
23
|
-
} catch (error) {
|
|
24
|
-
if (error?.status !== 404) throw error;
|
|
25
|
-
}
|
|
26
|
-
if (!data) {
|
|
27
|
-
const me = await request("/api/me");
|
|
28
|
-
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.");
|
|
29
16
|
}
|
|
30
17
|
return data;
|
|
31
18
|
}
|
|
32
19
|
|
|
33
|
-
/** `cui whoami`
|
|
20
|
+
/** `cui whoami` 的账户段:uid、注册时间、徽章——最基本的账户信息,到此为止。
|
|
21
|
+
* 账户名不进正文(上移到面板标题栏右侧徽标,见 reporter.note 的 badge)。 */
|
|
34
22
|
export function formatAccountHuman(account) {
|
|
35
23
|
if (!account) return "No account data.";
|
|
36
|
-
const lines = [`
|
|
24
|
+
const lines = [`Uid: ${account.uid ?? "?"}`];
|
|
37
25
|
if (account.createdAt) lines.push(`Created: ${account.createdAt}`);
|
|
38
26
|
if (account.badges?.length) lines.push(`Badges: ${account.badges.join(", ")}`);
|
|
39
27
|
return lines.join("\n");
|
|
40
28
|
}
|
|
41
29
|
|
|
30
|
+
/** 面板标题栏徽标:账户名(正文第一行让位给 Uid)。 */
|
|
31
|
+
export function accountBadge(account) {
|
|
32
|
+
return account?.username ?? "(unknown)";
|
|
33
|
+
}
|
|
34
|
+
|
|
42
35
|
/** Dash MCP:stateless JSON-RPC,直接 tools/list 或 tools/call。 */
|
|
43
36
|
export async function dashMcpTools(token, { reporter } = {}) {
|
|
44
37
|
const result = await mcpCall({
|
|
@@ -50,34 +43,6 @@ export async function dashMcpTools(token, { reporter } = {}) {
|
|
|
50
43
|
return result?.tools ?? [];
|
|
51
44
|
}
|
|
52
45
|
|
|
53
|
-
export async function dashMcpTool(token, name, args = {}, { reporter } = {}) {
|
|
54
|
-
const result = await mcpCall({
|
|
55
|
-
base: dashUrl(),
|
|
56
|
-
token,
|
|
57
|
-
method: "tools/call",
|
|
58
|
-
params: { name, arguments: args },
|
|
59
|
-
reporter,
|
|
60
|
-
});
|
|
61
|
-
if (result?.isError) {
|
|
62
|
-
const text = (result.content ?? []).map((c) => c.text).filter(Boolean).join("\n");
|
|
63
|
-
throw new Error(text || `Dash MCP tool ${name} failed`);
|
|
64
|
-
}
|
|
65
|
-
return toolResult(result);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/** 账户全量聚合(可下仓库、HP 凭据、订单)只有 Dash MCP 的 me 工具给——REST 端点 /api/me 已于 2026-12-02 移除。 */
|
|
69
|
-
export async function dashMe(token, { reporter } = {}) {
|
|
70
|
-
return dashMcpTool(token, "me", {}, { reporter });
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
/** 把 account aggregation 里的明文 key 登记给 reporter,确保输出脱敏。 */
|
|
74
|
-
export function addMeSecrets(reporter, me) {
|
|
75
|
-
reporter?.addSecrets?.((me?.keys ?? []).map((k) => k.key).filter(Boolean));
|
|
76
|
-
const hp = me?.herouiHp;
|
|
77
|
-
if (hp && typeof hp === "object") {
|
|
78
|
-
reporter?.addSecrets?.(Object.values(hp).filter((v) => typeof v === "string"));
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
46
|
|
|
82
47
|
export function maskKey(value) {
|
|
83
48
|
if (!value || typeof value !== "string") return "—";
|
|
@@ -85,49 +50,3 @@ export function maskKey(value) {
|
|
|
85
50
|
return `${value.slice(0, 6)}…${value.slice(-4)}`;
|
|
86
51
|
}
|
|
87
52
|
|
|
88
|
-
export function formatMeHuman(me) {
|
|
89
|
-
if (!me) return "No account data.";
|
|
90
|
-
const lines = [];
|
|
91
|
-
const account = me.account ?? {};
|
|
92
|
-
lines.push(`Account: ${account.username ?? "(unknown)"} uid=${account.uid ?? "?"}`);
|
|
93
|
-
if (account.createdAt) lines.push(`Created: ${account.createdAt}`);
|
|
94
|
-
if (account.badges?.length) lines.push(`Badges: ${account.badges.join(", ")}`);
|
|
95
|
-
|
|
96
|
-
const sites = me.sites ?? [];
|
|
97
|
-
lines.push("");
|
|
98
|
-
lines.push(`Libraries with access (${sites.length}):`);
|
|
99
|
-
if (sites.length === 0) lines.push(" (none)");
|
|
100
|
-
for (const site of sites) {
|
|
101
|
-
const scopes = Array.isArray(site.scopes) && site.scopes.length ? site.scopes.join(", ") : "all";
|
|
102
|
-
lines.push(` - ${site.slug} (${site.name}) — ${scopes}${site.expiresAt ? ` · until ${site.expiresAt}` : ""}`);
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
const keys = me.keys ?? [];
|
|
106
|
-
lines.push("");
|
|
107
|
-
lines.push(`Bound keys (${keys.length}):`);
|
|
108
|
-
if (keys.length === 0) lines.push(" (none)");
|
|
109
|
-
for (const key of keys) {
|
|
110
|
-
lines.push(` - ${key.source} [${key.kind}] site=${key.site ?? "?"} ${maskKey(key.key)}`);
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
const repos = me.repos ?? [];
|
|
114
|
-
lines.push("");
|
|
115
|
-
lines.push(`Downloadable repos (${repos.length}):`);
|
|
116
|
-
if (repos.length === 0) lines.push(" (none)");
|
|
117
|
-
for (const repo of repos) lines.push(` - ${repo}`);
|
|
118
|
-
|
|
119
|
-
const orders = me.orders ?? {};
|
|
120
|
-
lines.push("");
|
|
121
|
-
lines.push(`Orders: ${orders.paidCount ?? 0} paid, ${orders.pendingCount ?? 0} pending`);
|
|
122
|
-
return lines.join("\n");
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
export function formatTools(tools) {
|
|
126
|
-
return tools
|
|
127
|
-
.map((tool) => {
|
|
128
|
-
const required = tool.inputSchema?.required ?? [];
|
|
129
|
-
const props = Object.keys(tool.inputSchema?.properties ?? {});
|
|
130
|
-
return `- ${tool.name}${required.length ? ` (required: ${required.join(", ")})` : ""}\n ${tool.description ?? ""}\n args: ${props.join(", ") || "none"}`;
|
|
131
|
-
})
|
|
132
|
-
.join("\n");
|
|
133
|
-
}
|
|
@@ -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,
|
|
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
|
-
|
|
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;
|
|
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)
|
|
115
|
-
|
|
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));
|
package/src/skill/SKILL.md
CHANGED
|
@@ -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
|
|
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
|
-
###
|
|
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
|
package/src/commands/dash.mjs
DELETED
|
@@ -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
|
-
}
|