@collectui/cli 0.2.38 → 0.2.40
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/cli.mjs +2 -0
- package/src/commands/common.mjs +36 -2
- package/src/commands/mcp.mjs +15 -3
- package/src/commands/setup.mjs +15 -4
- package/src/mcp.mjs +22 -3
package/package.json
CHANGED
package/src/cli.mjs
CHANGED
|
@@ -64,6 +64,8 @@ Global options:
|
|
|
64
64
|
--no-install init: skip dependency installation
|
|
65
65
|
--no-mcp init/configure: skip MCP configuration
|
|
66
66
|
--no-dash-mcp Do not add the CollectUI MCP (collectui) server
|
|
67
|
+
--scope <s> global | project — where MCP configs are written
|
|
68
|
+
(interactive asks, default global; headless defaults to project)
|
|
67
69
|
--force Replace custom registry/MCP entries (deliberate)
|
|
68
70
|
--libs <list> Comma list or "all" (default: all owned)
|
|
69
71
|
--clients <list> claude,cursor,vscode,codex or all (default: your Dash-pinned agents, else claude,cursor,vscode)
|
package/src/commands/common.mjs
CHANGED
|
@@ -217,10 +217,32 @@ export function resolveClients(flags, pinnedAgents = []) {
|
|
|
217
217
|
return [...new Set(list)];
|
|
218
218
|
}
|
|
219
219
|
|
|
220
|
+
/** MCP 写入作用域(--scope > 交互选择,默认 global——2026-12-07 用户定案:
|
|
221
|
+
* claude=~/.claude.json / cursor=~/.cursor/mcp.json / vscode=User/mcp.json /
|
|
222
|
+
* codex 恒全局;project = 各自项目内文件)。返回 "global" | "project"。 */
|
|
223
|
+
export async function chooseScope(flags, reporter, { interactive = true } = {}) {
|
|
224
|
+
const raw = String(flags.scope ?? "").toLowerCase();
|
|
225
|
+
if (raw === "global" || raw === "project") return raw;
|
|
226
|
+
if (raw) {
|
|
227
|
+
throw usageError(`--scope must be global or project (got: ${flags.scope})`);
|
|
228
|
+
}
|
|
229
|
+
// 无头(headless/--yes)保守回 project:不碰用户 home(CI/测试/Agent 的
|
|
230
|
+
// 意外副作用);交互场景默认问、选中 global——2026-12-07 用户定案
|
|
231
|
+
if (!interactive || reporter.headless || reporter.yes) return "project";
|
|
232
|
+
const choice = await reporter.select(
|
|
233
|
+
"Write MCP config where? (global follows you across projects)",
|
|
234
|
+
[
|
|
235
|
+
{ value: "global", label: "Global — user-level config, all projects (default)" },
|
|
236
|
+
{ value: "project", label: "Project — config files inside this project only" },
|
|
237
|
+
]
|
|
238
|
+
);
|
|
239
|
+
return choice ?? "global";
|
|
240
|
+
}
|
|
241
|
+
|
|
220
242
|
/** client 决策全链(setup 与 mcp 命令共用):--clients > dash pin 集 > 默认三件套;
|
|
221
243
|
* 交互模式下多选让用户挑(预选默认集,空选确认 = 全部);dash 固定了 CLI
|
|
222
244
|
* 写不了的 Agent(deepseek/trae 等)提示去站点卡 AI Tools 弹窗复制。 */
|
|
223
|
-
export async function chooseClients(flags, me, reporter, { interactive = true } = {}) {
|
|
245
|
+
export async function chooseClients(flags, me, reporter, { interactive = true, scope = "project" } = {}) {
|
|
224
246
|
let clients = resolveClients(flags, me?.pinnedAgents ?? []);
|
|
225
247
|
const unsupportedPins = [...new Set(me?.pinnedAgents ?? [])].filter(
|
|
226
248
|
(a) => !ALL_CLIENTS.includes(a)
|
|
@@ -233,7 +255,7 @@ export async function chooseClients(flags, me, reporter, { interactive = true }
|
|
|
233
255
|
if (interactive && !flags.clients && !reporter.headless && !reporter.yes) {
|
|
234
256
|
const chosen = await reporter.multiSelect(
|
|
235
257
|
"Configure MCP for which agents? (space to select · enter to confirm · none = all)",
|
|
236
|
-
CLIENT_OPTIONS,
|
|
258
|
+
CLIENT_OPTIONS.map((o) => clientOptionFor(o, scope)),
|
|
237
259
|
{ selected: [] }
|
|
238
260
|
);
|
|
239
261
|
if (chosen) clients = chosen.length ? chosen : ALL_CLIENTS;
|
|
@@ -274,3 +296,15 @@ export function includeDashMcp(flags, me) {
|
|
|
274
296
|
if (flags?.["no-dash-mcp"]) return false;
|
|
275
297
|
return me?.cliDashMcp !== false;
|
|
276
298
|
}
|
|
299
|
+
|
|
300
|
+
/** Agent 多选 label 按作用域显示目标文件(global = user 级路径) */
|
|
301
|
+
function clientOptionFor(option, scope) {
|
|
302
|
+
if (scope !== "global") return option;
|
|
303
|
+
const where = {
|
|
304
|
+
claude: "~/.claude.json (user)",
|
|
305
|
+
codex: "~/.codex/config.toml",
|
|
306
|
+
cursor: "~/.cursor/mcp.json",
|
|
307
|
+
vscode: "VS Code User/mcp.json",
|
|
308
|
+
}[option.value];
|
|
309
|
+
return where ? { ...option, label: `${option.label.split(" — ")[0]} — ${where}` } : option;
|
|
310
|
+
}
|
package/src/commands/mcp.mjs
CHANGED
|
@@ -4,7 +4,14 @@ import { dashUrl, registryUrl } from "../config.mjs";
|
|
|
4
4
|
import { usageError } from "../errors.mjs";
|
|
5
5
|
import { fetchAccount } from "../dash.mjs";
|
|
6
6
|
import { buildMcpEntries, describeEntries, planMcpConfig, renderEntry } from "../mcp.mjs";
|
|
7
|
-
import {
|
|
7
|
+
import {
|
|
8
|
+
chooseClients,
|
|
9
|
+
chooseScope,
|
|
10
|
+
detectClientApp,
|
|
11
|
+
includeDashMcp,
|
|
12
|
+
requireToken,
|
|
13
|
+
selectLibs,
|
|
14
|
+
} from "./common.mjs";
|
|
8
15
|
|
|
9
16
|
export async function mcpCmd(flags, rest, reporter) {
|
|
10
17
|
const sub = rest[0] ?? "show";
|
|
@@ -26,7 +33,11 @@ async function mcpConfigCommand(sub, flags, rest, reporter) {
|
|
|
26
33
|
reporter.addSecrets((me.keys ?? []).map((k) => k.key).filter(Boolean));
|
|
27
34
|
const { units } = await selectLibs({ flags, me, reporter });
|
|
28
35
|
// show 是只读命令:不弹多选,按默认集打印(init/configure 才交互挑 Agent)
|
|
29
|
-
const
|
|
36
|
+
const scope = await chooseScope(flags, reporter, { interactive: sub !== "show" });
|
|
37
|
+
const clients = await chooseClients(flags, me, reporter, {
|
|
38
|
+
interactive: sub !== "show",
|
|
39
|
+
scope,
|
|
40
|
+
});
|
|
30
41
|
const target = resolve(flags.cwd || rest[0] || process.cwd());
|
|
31
42
|
|
|
32
43
|
const entries = buildMcpEntries({
|
|
@@ -52,7 +63,7 @@ async function mcpConfigCommand(sub, flags, rest, reporter) {
|
|
|
52
63
|
}
|
|
53
64
|
reporter.note("MCP servers", describeEntries(entries).join("\n") || "(none)");
|
|
54
65
|
for (const client of clients) {
|
|
55
|
-
reporter.preview(`${client}
|
|
66
|
+
reporter.preview(`${client} (${scope})`, JSON.stringify(configs[client], null, 2));
|
|
56
67
|
}
|
|
57
68
|
return;
|
|
58
69
|
}
|
|
@@ -65,6 +76,7 @@ async function mcpConfigCommand(sub, flags, rest, reporter) {
|
|
|
65
76
|
});
|
|
66
77
|
planMcpConfig(cs, {
|
|
67
78
|
projectDir: target,
|
|
79
|
+
scope,
|
|
68
80
|
units,
|
|
69
81
|
me,
|
|
70
82
|
dashToken: token,
|
package/src/commands/setup.mjs
CHANGED
|
@@ -16,7 +16,14 @@ import {
|
|
|
16
16
|
planScaffold,
|
|
17
17
|
runShadcnCommand,
|
|
18
18
|
} from "../scaffold.mjs";
|
|
19
|
-
import {
|
|
19
|
+
import {
|
|
20
|
+
chooseClients,
|
|
21
|
+
chooseScope,
|
|
22
|
+
collectShadcnFlags,
|
|
23
|
+
detectClientApp,
|
|
24
|
+
includeDashMcp,
|
|
25
|
+
selectLibs,
|
|
26
|
+
} from "./common.mjs";
|
|
20
27
|
|
|
21
28
|
// client 集/选项面已迁 common.mjs(mcp 命令与 setup 共用决策链);
|
|
22
29
|
// 此处 re-export 兼容既有 import
|
|
@@ -93,7 +100,9 @@ export async function runSetup({ flags, rest = [], reporter, mode }) {
|
|
|
93
100
|
const target = resolveTarget({ flags, rest, mode });
|
|
94
101
|
let hasComponents = existsSync(join(target, "components.json"));
|
|
95
102
|
const nonEmpty = isNonEmptyDir(target);
|
|
96
|
-
|
|
103
|
+
// 模板不给 = 走官方命令链(账户 cli-init-command > 内置默认)——旧默认 "vite"
|
|
104
|
+
// 会让 officialScaffold 恒假、命令链永不触发(2026-12-07 用户实锤)
|
|
105
|
+
const template = flags.template ? String(flags.template) : null;
|
|
97
106
|
|
|
98
107
|
if (mode === "configure" && !hasComponents) {
|
|
99
108
|
throw new CliError(`${displayPath(target)} has no components.json.`, {
|
|
@@ -173,7 +182,8 @@ export async function runSetup({ flags, rest = [], reporter, mode }) {
|
|
|
173
182
|
!officialScaffold && // 官方 init 自带依赖安装
|
|
174
183
|
flags.install !== false &&
|
|
175
184
|
!flags["no-install"];
|
|
176
|
-
const
|
|
185
|
+
const scope = await chooseScope(flags, reporter);
|
|
186
|
+
const clients = await chooseClients(flags, me, reporter, { scope });
|
|
177
187
|
const projectName = flags.name ? String(flags.name) : basename(target) || "collectui-app";
|
|
178
188
|
|
|
179
189
|
const cs = new ChangeSet({
|
|
@@ -196,7 +206,7 @@ export async function runSetup({ flags, rest = [], reporter, mode }) {
|
|
|
196
206
|
hasComponents = existsSync(join(target, "components.json"));
|
|
197
207
|
} else {
|
|
198
208
|
reporter.step(1, 5, `Scaffold ${template} project in ${displayPath(target)}`);
|
|
199
|
-
planScaffold(cs, { target, name: projectName, template, pm, install });
|
|
209
|
+
planScaffold(cs, { target, name: projectName, template: "vite", pm, install });
|
|
200
210
|
}
|
|
201
211
|
} else {
|
|
202
212
|
reporter.step(1, 5, `Use existing project ${displayPath(target)}`);
|
|
@@ -217,6 +227,7 @@ export async function runSetup({ flags, rest = [], reporter, mode }) {
|
|
|
217
227
|
reporter.step(3, 5, "Configure MCP servers (library + CollectUI MCP)");
|
|
218
228
|
const mcp = planMcpConfig(cs, {
|
|
219
229
|
projectDir: target,
|
|
230
|
+
scope,
|
|
220
231
|
units,
|
|
221
232
|
me,
|
|
222
233
|
dashToken: token,
|
package/src/mcp.mjs
CHANGED
|
@@ -23,7 +23,23 @@ export const CLIENT_FILES = {
|
|
|
23
23
|
codex: { root: null, file: null, type: false },
|
|
24
24
|
};
|
|
25
25
|
|
|
26
|
-
export function mcpConfigPath(client, { projectDir, codexHome } = {}) {
|
|
26
|
+
export function mcpConfigPath(client, { projectDir, codexHome, scope = "project" } = {}) {
|
|
27
|
+
// 全局作用域(2026-12-07 用户定案:默认问一次,scope 可选,默认 global):
|
|
28
|
+
// claude = ~/.claude.json(user scope,结构与 .mcp.json 同为 mcpServers);
|
|
29
|
+
// cursor = ~/.cursor/mcp.json;vscode = VS Code User/mcp.json(按平台);
|
|
30
|
+
// codex 本就只有全局(~/.codex/config.toml),不受 scope 影响
|
|
31
|
+
if (scope === "global" && client !== "codex") {
|
|
32
|
+
const home = homedir();
|
|
33
|
+
if (client === "claude") return join(home, ".claude.json");
|
|
34
|
+
if (client === "cursor") return join(home, ".cursor", "mcp.json");
|
|
35
|
+
if (client === "vscode") {
|
|
36
|
+
if (process.platform === "darwin")
|
|
37
|
+
return join(home, "Library/Application Support/Code/User/mcp.json");
|
|
38
|
+
if (process.platform === "win32")
|
|
39
|
+
return join(process.env.APPDATA ?? home, "Code", "User", "mcp.json");
|
|
40
|
+
return join(home, ".config/Code/User/mcp.json");
|
|
41
|
+
}
|
|
42
|
+
}
|
|
27
43
|
if (client === "codex") {
|
|
28
44
|
const home = codexHome || process.env.CODEX_HOME || join(homedir(), ".codex");
|
|
29
45
|
return join(home, "config.toml");
|
|
@@ -329,6 +345,7 @@ export function planMcpConfig(cs, {
|
|
|
329
345
|
force,
|
|
330
346
|
includeDash,
|
|
331
347
|
codexHome,
|
|
348
|
+
scope = "project",
|
|
332
349
|
reporter,
|
|
333
350
|
}) {
|
|
334
351
|
const entries = buildMcpEntries({
|
|
@@ -346,13 +363,15 @@ export function planMcpConfig(cs, {
|
|
|
346
363
|
}
|
|
347
364
|
if (entries.some((entry) => entry.key)) {
|
|
348
365
|
reporter?.warn(
|
|
349
|
-
|
|
366
|
+
scope === "global"
|
|
367
|
+
? "MCP configs contain access tokens — they are written user-level (outside any project, not in git)."
|
|
368
|
+
: "MCP configs contain access tokens — keep .mcp.json, .cursor/mcp.json and .vscode/mcp.json out of git."
|
|
350
369
|
);
|
|
351
370
|
}
|
|
352
371
|
|
|
353
372
|
const allDecisions = [];
|
|
354
373
|
for (const client of clients) {
|
|
355
|
-
const path = mcpConfigPath(client, { projectDir, codexHome });
|
|
374
|
+
const path = mcpConfigPath(client, { projectDir, codexHome, scope });
|
|
356
375
|
if (client === "codex") {
|
|
357
376
|
const before = cs.read(path) ?? "";
|
|
358
377
|
const { text, decisions } = mergeCodexToml(before, entries, { force });
|