@collectui/cli 0.2.40 → 0.2.42

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@collectui/cli",
3
- "version": "0.2.40",
3
+ "version": "0.2.42",
4
4
  "description": "One CLI for every shadcn library on CollectUI Dash — login once, configure registries & MCP, scaffold agent-ready projects.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -220,12 +220,15 @@ export function resolveClients(flags, pinnedAgents = []) {
220
220
  /** MCP 写入作用域(--scope > 交互选择,默认 global——2026-12-07 用户定案:
221
221
  * claude=~/.claude.json / cursor=~/.cursor/mcp.json / vscode=User/mcp.json /
222
222
  * codex 恒全局;project = 各自项目内文件)。返回 "global" | "project"。 */
223
- export async function chooseScope(flags, reporter, { interactive = true } = {}) {
223
+ export async function chooseScope(flags, reporter, { interactive = true, me } = {}) {
224
224
  const raw = String(flags.scope ?? "").toLowerCase();
225
225
  if (raw === "global" || raw === "project") return raw;
226
226
  if (raw) {
227
227
  throw usageError(`--scope must be global or project (got: ${flags.scope})`);
228
228
  }
229
+ // 账户偏好 cli-scope(dash「CLI 偏好」/ cui prefs set scope):设置过
230
+ // 就直接用不再问(2026-12-07 用户定案:scope 也是偏好)
231
+ if (me?.cliScope === "global" || me?.cliScope === "project") return me.cliScope;
229
232
  // 无头(headless/--yes)保守回 project:不碰用户 home(CI/测试/Agent 的
230
233
  // 意外副作用);交互场景默认问、选中 global——2026-12-07 用户定案
231
234
  if (!interactive || reporter.headless || reporter.yes) return "project";
@@ -2,6 +2,7 @@ import { existsSync, rmSync, statSync } from "node:fs";
2
2
  import { tmpdir } from "node:os";
3
3
  import { join } from "node:path";
4
4
  import { displayPath } from "../changes.mjs";
5
+ import { shellInside } from "./migrate.mjs";
5
6
  import { runSetup } from "./setup.mjs";
6
7
 
7
8
  /**
@@ -21,6 +22,11 @@ export async function initCmd(flags, rest, reporter) {
21
22
  String(flags.name ?? "collectui-app").replace(/[\\/]+/g, "-")
22
23
  );
23
24
  if (existsSync(target) && statSync(target).isDirectory()) {
25
+ if (shellInside(target)) {
26
+ reporter.warn(
27
+ `Your terminal is inside ${displayPath(target)} — cd out (e.g. \`cd ~\`) right after this command, or the next command will crash with ENOENT.`
28
+ );
29
+ }
24
30
  rmSync(target, { recursive: true, force: true });
25
31
  reporter.info(`Removed previous project at ${displayPath(target)} — starting fresh.`);
26
32
  }
@@ -33,7 +33,7 @@ async function mcpConfigCommand(sub, flags, rest, reporter) {
33
33
  reporter.addSecrets((me.keys ?? []).map((k) => k.key).filter(Boolean));
34
34
  const { units } = await selectLibs({ flags, me, reporter });
35
35
  // show 是只读命令:不弹多选,按默认集打印(init/configure 才交互挑 Agent)
36
- const scope = await chooseScope(flags, reporter, { interactive: sub !== "show" });
36
+ const scope = await chooseScope(flags, reporter, { interactive: sub !== "show", me });
37
37
  const clients = await chooseClients(flags, me, reporter, {
38
38
  interactive: sub !== "show",
39
39
  scope,
@@ -56,6 +56,7 @@ export async function migrateCmd(flags, rest, reporter) {
56
56
  return;
57
57
  }
58
58
 
59
+ warnShellInside(source, reporter);
59
60
  mkdirSync(resolve(dest, ".."), { recursive: true });
60
61
  let moved;
61
62
  try {
@@ -111,12 +112,33 @@ export async function cleanCmd(flags, rest, reporter) {
111
112
  return;
112
113
  }
113
114
  for (const t of targets) {
115
+ warnShellInside(t, reporter);
114
116
  rmSync(t, { recursive: true, force: true });
115
117
  reporter.success(`Deleted ${displayPath(t)}`);
116
118
  }
117
119
  reporter.outro(`Cleaned ${targets.length} director${targets.length === 1 ? "y" : "ies"}.`);
118
120
  }
119
121
 
122
+
123
+ /** shell 的 cwd 是否在将被删除/移走的目录内(删除后下一条命令会 uv_cwd 崩,
124
+ * 2026-12-07 用户实锤:npx 直接 ENOENT)——删除前提示先 cd 出去 */
125
+ export function shellInside(path) {
126
+ try {
127
+ const cwd = process.cwd();
128
+ return cwd === path || cwd.startsWith(path + "/");
129
+ } catch {
130
+ return false;
131
+ }
132
+ }
133
+
134
+ function warnShellInside(path, reporter) {
135
+ if (shellInside(path)) {
136
+ reporter.warn(
137
+ `Your terminal is still inside ${displayPath(path)} — after it is removed, cd elsewhere (e.g. \`cd ~\`) before running any other command.`
138
+ );
139
+ }
140
+ }
141
+
120
142
  /** tmpdir 下带 .collectui/project.json 标志的目录清单(名字升序) */
121
143
  function cuiTmpProjects() {
122
144
  const out = [];
@@ -24,6 +24,7 @@ const KEY_MAP = {
24
24
  "pinned-agents": "copy-agent-pinned",
25
25
  libs: "cli-default-libs",
26
26
  "dash-mcp": "cli-dash-mcp",
27
+ scope: "cli-scope",
27
28
  };
28
29
 
29
30
  const PM_VALUES = [...VALID_PM];
@@ -46,6 +47,7 @@ export async function prefsCmd(flags, rest, reporter) {
46
47
  ? me.cliDefaultLibs.join(",")
47
48
  : "(unset — defaults to all owned)",
48
49
  "dash-mcp": me?.cliDashMcp === false ? "off" : "on (default)",
50
+ scope: me?.cliScope ?? "(unset — asks interactively, default global)",
49
51
  };
50
52
  if (sub === "get") {
51
53
  const key = rest[1];
@@ -89,6 +91,13 @@ export async function prefsCmd(flags, rest, reporter) {
89
91
  const v = String(value).toLowerCase();
90
92
  value = ["off", "0", "false", "no"].includes(v) ? "0" : "1";
91
93
  }
94
+ if (key === "scope") {
95
+ const v = String(value).toLowerCase();
96
+ if (v !== "global" && v !== "project") {
97
+ throw usageError(`scope must be global or project (got: ${value})`);
98
+ }
99
+ value = v;
100
+ }
92
101
  const token = requireToken(flags, reporter);
93
102
  await jsonRequest(`${dashUrl()}/api/account/prefs`, {
94
103
  method: "POST",
@@ -122,6 +131,7 @@ Account-wide preferences (stored in Dash, shared across machines):
122
131
  pinned-agents Default MCP agent set (empty = claude,cursor,vscode)
123
132
  libs Default library set (comma slugs; empty = all owned)
124
133
  dash-mcp Include the collectui MCP server: on | off (default on)
134
+ scope MCP config location: global | project (unset = ask, default global)
125
135
 
126
136
  Examples:
127
137
  cui prefs ls
@@ -182,7 +182,7 @@ export async function runSetup({ flags, rest = [], reporter, mode }) {
182
182
  !officialScaffold && // 官方 init 自带依赖安装
183
183
  flags.install !== false &&
184
184
  !flags["no-install"];
185
- const scope = await chooseScope(flags, reporter);
185
+ const scope = await chooseScope(flags, reporter, { me });
186
186
  const clients = await chooseClients(flags, me, reporter, { scope });
187
187
  const projectName = flags.name ? String(flags.name) : basename(target) || "collectui-app";
188
188