@collectui/cli 0.2.7 → 0.2.9

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 CHANGED
@@ -166,16 +166,18 @@ collectui doctor # 登录、account、Dash MCP、项目 registries/en
166
166
  collectui doctor --deep # 再对每个已拥有库做一次 registry 探测(会消耗额度,慎用)
167
167
  ```
168
168
 
169
- ## 自动更新
169
+ ## 更新检查
170
170
 
171
171
  CLI 每 12 小时后台查一次 npm(本地缓存 `~/.collectui/update-check.json`,绝不阻塞命令)。
172
- 交互终端下**默认自动更新**:发现新版即后台 `npm i -g @collectui/cli@latest`,
173
- 下次运行生效,当前命令不受影响。
172
+ 发现新版会在启动时**打一行提醒**,装不装由你决定:
174
173
 
175
- - 关掉:`collectui update --off`(仍会提示新版,只是不自动动手);
176
- 或环境变量 `COLLECTUI_NO_AUTO_UPDATE=1`(CI / Agent 全静默)
177
- - 手动:`collectui update`(前台看着装);`collectui update --check`(只查不装)
178
- - `--json` / 非 TTY / `npx` 临时跑:完全不碰更新逻辑
174
+ ```bash
175
+ collectui update # 手动更新(前台看着装)
176
+ collectui update --check # 只查不装
177
+ ```
178
+
179
+ - `COLLECTUI_NO_AUTO_UPDATE=1`:连检查带提醒全静默(CI / Agent 用)
180
+ - `--json` / 非 TTY / `npx` 临时跑:完全不碰更新逻辑;CLI **从不自动安装**任何东西
179
181
 
180
182
  ## 支持的库
181
183
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@collectui/cli",
3
- "version": "0.2.7",
3
+ "version": "0.2.9",
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",
package/src/args.mjs CHANGED
@@ -22,8 +22,6 @@ const BOOLEAN_FLAGS = new Set([
22
22
  "no-auto-configure",
23
23
  "deep",
24
24
  "quiet",
25
- "off",
26
- "on",
27
25
  "check",
28
26
  ]);
29
27
 
package/src/cli.mjs CHANGED
@@ -45,7 +45,7 @@ Commands:
45
45
  dash <sub> Dash MCP: me, repos, download, feedback, tools, call
46
46
  skill [dir] Install the agent skill (.claude/skills/collectui)
47
47
  doctor Verify login, registries, env and MCP config
48
- update Update the CLI now (--check only / --off/--on toggles auto-update)
48
+ update Update the CLI now (--check only checks)
49
49
 
50
50
  Global options:
51
51
  --token <PAT> Dash PAT (dpat_...); overrides saved login
@@ -91,7 +91,7 @@ Environment:
91
91
  COLLECTUI_DASH_URL default https://dash.collectui.pro
92
92
  COLLECTUI_REGISTRY_URL default https://registry.collectui.pro
93
93
  COLLECTUI_HOME config directory override
94
- COLLECTUI_NO_AUTO_UPDATE=1 disable background update check (CI/Agent silent)
94
+ COLLECTUI_NO_AUTO_UPDATE=1 disable update checks and notices entirely (CI/Agent silent)
95
95
  `;
96
96
 
97
97
  const COMMANDS = {
@@ -165,25 +165,37 @@ async function main() {
165
165
  if (token) reporter.addSecrets([token]);
166
166
 
167
167
  showBanner(reporter); // 开机画面:任何子命令(headless/--version/help 已在前面分流)
168
- // 自更新:交互 TTY 下后台检查/自动更(headless/CI 由门控静默跳过);
169
- // 手动 update 命令自身不触发(避免与前台安装并发写全局目录)
168
+ // 更新检查:交互 TTY 下后台查 npm、有新版打一行提醒(绝不自动装,headless 静默)
170
169
  if (name !== "update" && name !== "upgrade") {
171
- startBackgroundUpdate(reporter, { config: readConfig() });
170
+ startBackgroundUpdate(reporter);
172
171
  }
173
172
 
174
173
  await command.run(flags, rest, reporter);
175
174
  }
176
175
 
177
- main().catch((error) => {
178
- const exitCode = error instanceof CliError ? error.exitCode : 1;
179
- const message = error instanceof CliError ? error.message : error?.stack || String(error);
180
- const hint = error instanceof CliError ? error.hint : undefined;
181
- const json = process.env.COLLECTUI_JSON === "1" || process.argv.includes("--json");
182
- if (json) {
183
- process.stdout.write(`${JSON.stringify({ event: "error", message, hint: hint ?? null, exitCode })}\n`);
184
- } else {
185
- process.stderr.write(`✖ ${message}\n`);
186
- if (hint) process.stderr.write(` hint: ${hint}\n`);
187
- }
188
- process.exit(exitCode);
189
- });
176
+ /** 命令完成后 flush stdout 并退出:一次性进程不留后台尾巴(callback server 的
177
+ * keep-alive socket、undici 连接池等挂住 event loop 时进程会悬死不退)。 */
178
+ function flushAndExit(code = 0) {
179
+ process.stdout.write("", () => process.exit(code));
180
+ }
181
+
182
+ main()
183
+ .then(() => {
184
+ flushAndExit(process.exitCode ?? 0);
185
+ })
186
+ .catch((error) => {
187
+ const exitCode = error instanceof CliError ? error.exitCode : 1;
188
+ const message = error instanceof CliError ? error.message : error?.stack || String(error);
189
+ const hint = error instanceof CliError ? error.hint : undefined;
190
+ const json = process.env.COLLECTUI_JSON === "1" || process.argv.includes("--json");
191
+ if (json) {
192
+ process.stdout.write(`${JSON.stringify({ event: "error", message, hint: hint ?? null, exitCode })}\n`, () =>
193
+ process.exit(exitCode)
194
+ );
195
+ } else {
196
+ process.stderr.write(`✖ ${message}\n`, () => {
197
+ if (hint) process.stderr.write(` hint: ${hint}\n`, () => process.exit(exitCode));
198
+ else process.exit(exitCode);
199
+ });
200
+ }
201
+ });
@@ -1,24 +1,12 @@
1
1
  import { CLI_VERSION } from "../version.mjs";
2
2
  import { compareVersions, fetchLatestVersion, runManualUpdate } from "../update.mjs";
3
- import { writeConfig } from "../config.mjs";
4
3
  import { CliError } from "../errors.mjs";
5
4
 
6
5
  /**
7
6
  * collectui update 手动立即更新(前台,看着跑)
8
7
  * collectui update --check 只查不更(打 registry,不走缓存)
9
- * collectui update --off/--on 关/开自动更新(写 config.autoUpdate)
10
8
  */
11
9
  export async function updateCmd(flags, _rest, reporter) {
12
- if (flags.off || flags.on) {
13
- if (flags.off && flags.on) {
14
- throw new CliError("--off and --on are mutually exclusive.", { code: 2 });
15
- }
16
- const next = writeConfig({ autoUpdate: !flags.off });
17
- if (reporter.headless) reporter.result({ autoUpdate: next.autoUpdate !== false });
18
- reporter.outro(next.autoUpdate !== false ? "Auto-update enabled." : "Auto-update disabled (still notifies on new versions).");
19
- return;
20
- }
21
-
22
10
  reporter.step(1, 2, "Checking npm for the latest @collectui/cli");
23
11
  const latest = await fetchLatestVersion();
24
12
  const cmp = compareVersions(latest, CLI_VERSION);
package/src/login.mjs CHANGED
@@ -189,6 +189,13 @@ export function startCallbackServer({ state } = {}) {
189
189
  return listening;
190
190
  },
191
191
  close() {
192
+ // 浏览器对回调的 keep-alive 连接会挂住 event loop(server.close() 只停
193
+ // 接新连接、不断旧连接)——登录完成瞬间强断,否则进程悬死不退
194
+ try {
195
+ server.closeAllConnections?.();
196
+ } catch {
197
+ // Node <18.2 无此方法
198
+ }
192
199
  try {
193
200
  server.close();
194
201
  } catch {
package/src/update.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { spawn, spawnSync } from "node:child_process";
1
+ import { spawnSync } from "node:child_process";
2
2
  import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
3
3
  import { join } from "node:path";
4
4
  import { configDir } from "./config.mjs";
@@ -6,18 +6,16 @@ import { httpRequest } from "./http.mjs";
6
6
  import { CLI_VERSION } from "./version.mjs";
7
7
 
8
8
  /**
9
- * 自更新(2026-11-30):
10
- * - 启动时后台异步检查(12h 间隔 + ~/.collectui/update-check.json 缓存),绝不阻塞命令
11
- * - TTY 交互下默认自动后台更新(spawn npm i -g,当前进程不受影响);headless/--json
12
- * 完全不碰(Agent/CI 输出契约不可被自更新搅动)
13
- * - 开关:COLLECTUI_NO_AUTO_UPDATE=1(CI 显式意图 → 全静默)或 config.autoUpdate=false
14
- * (`collectui update --off` → 仍提示新版,但不自动动手);npx 临时跑不自动更
9
+ * 更新检查(2026-12-01 起只提醒不自动装):
10
+ * - 启动时后台异步查 npm latest(12h 间隔 + ~/.collectui/update-check.json 缓存),绝不阻塞命令
11
+ * - TTY 下发现新版 → 打一行显式提醒,装不装由用户跑 `collectui update` 决定
12
+ * - headless/--json 完全不碰(Agent/CI 输出契约不被搅动);npx 临时跑不需要
13
+ * - COLLECTUI_NO_AUTO_UPDATE=1:连检查带提示全静默(CI 显式意图)
15
14
  */
16
15
 
17
16
  export const NPM_PACKAGE = "@collectui/cli";
18
17
  const REGISTRY_LATEST = "https://registry.npmjs.org/@collectui/cli/latest";
19
18
  const CHECK_INTERVAL_MS = 12 * 60 * 60 * 1000;
20
- const SPAWN_BACKOFF_MS = 24 * 60 * 60 * 1000;
21
19
 
22
20
  function cacheFile() {
23
21
  return join(configDir(), "update-check.json");
@@ -60,18 +58,15 @@ export function compareVersions(a, b) {
60
58
 
61
59
  /**
62
60
  * 纯决策函数(单测覆盖):本次启动对更新做点什么。
63
- * 返回 { mode, latest?, reason },mode ∈
64
- * off-silent(env 显式禁 → 全静默)| none | notify(只提示)| notify-spawn(提示+后台更)| check(到点检查)
61
+ * mode ∈ off-silent(env 显式禁 → 全静默)| none | notify(有缓存新版 → 提醒)| check(到点检查)
65
62
  */
66
63
  export function decideUpdate({
67
64
  env = process.env,
68
- config = {},
69
65
  cache = {},
70
66
  now = Date.now(),
71
67
  isTTY = process.stdout.isTTY,
72
68
  version = CLI_VERSION,
73
69
  intervalMs = CHECK_INTERVAL_MS,
74
- spawnBackoffMs = SPAWN_BACKOFF_MS,
75
70
  } = {}) {
76
71
  const noAuto = env.COLLECTUI_NO_AUTO_UPDATE;
77
72
  if (noAuto === "1" || noAuto === "true" || noAuto === "yes") {
@@ -83,14 +78,9 @@ export function decideUpdate({
83
78
  if (!isTTY) {
84
79
  return { mode: "none", reason: "non-tty" };
85
80
  }
86
- const autoOn = config.autoUpdate !== false;
87
81
  const outdated = cache.latest ? compareVersions(cache.latest, version) > 0 : false;
88
82
  if (outdated) {
89
- if (!autoOn) return { mode: "notify", latest: cache.latest, reason: "manual-mode" };
90
- const spawnedRecently = cache.spawnedAt && now - cache.spawnedAt < spawnBackoffMs;
91
- return spawnedRecently
92
- ? { mode: "notify", latest: cache.latest, reason: "spawn-pending" }
93
- : { mode: "notify-spawn", latest: cache.latest, reason: "cached-outdated" };
83
+ return { mode: "notify", latest: cache.latest, reason: "cached-outdated" };
94
84
  }
95
85
  if (now - (cache.lastCheck ?? 0) >= intervalMs) {
96
86
  return { mode: "check", reason: "due" };
@@ -108,61 +98,32 @@ export async function fetchLatestVersion({ timeout = 8_000 } = {}) {
108
98
  return v;
109
99
  }
110
100
 
111
- /** 后台静默 spawn npm i -g;npm 不存在返回 false。 */
112
- export function spawnGlobalInstall() {
113
- const probe = spawnSync("npm", ["--version"], { timeout: 10_000, encoding: "utf8" });
114
- if (probe.status !== 0 || probe.error) return false;
115
- const child = spawn("npm", ["install", "-g", `${NPM_PACKAGE}@latest`], {
116
- detached: true,
117
- stdio: "ignore",
118
- shell: process.platform === "win32",
119
- });
120
- child.unref();
121
- return true;
122
- }
123
-
124
- /** 后台异步检查 + 视开关自动更;fire-and-forget,绝不抛。 */
125
- export function backgroundCheck({ autoOn = true, reporter } = {}) {
101
+ /** 后台异步检查:只写缓存,不装任何东西。fire-and-forget,绝不抛。 */
102
+ export function backgroundCheck() {
126
103
  const started = Date.now();
127
104
  return fetchLatestVersion()
128
105
  .then((latest) => {
129
106
  writeUpdateCache({ lastCheck: started, latest });
130
- if (autoOn && compareVersions(latest, CLI_VERSION) > 0) {
131
- const ok = spawnGlobalInstall();
132
- writeUpdateCache({ spawnedAt: Date.now(), spawnTo: ok ? latest : null });
133
- if (!ok && reporter) reporter.warn(`Auto-update failed (npm not found). Run \`npm i -g ${NPM_PACKAGE}\` manually.`);
134
- }
135
107
  return latest;
136
108
  })
137
109
  .catch(() => undefined);
138
110
  }
139
111
 
140
112
  /**
141
- * 启动钩子(cli.main 里 fire-and-forget 调):按 decideUpdate 执行提示/检查/自动更。
142
- * 提示走 reporter(TTY 人类输出);headless 由 decideUpdate 的 isTTY 门挡掉。
113
+ * 启动钩子(cli.main 里 fire-and-forget 调):按 decideUpdate 提醒/检查。
114
+ * 提醒走 reporter(TTY 人类输出);headless 由 decideUpdate 的 isTTY 门挡掉。
143
115
  */
144
116
  export function startBackgroundUpdate(reporter, deps = {}) {
145
117
  const decision = decideUpdate(deps);
146
118
  if (decision.mode === "off-silent" || decision.mode === "none") return;
147
- if (decision.mode === "notify" || decision.mode === "notify-spawn") {
148
- const to = decision.latest;
149
- if (decision.mode === "notify-spawn") {
150
- const ok = spawnGlobalInstall();
151
- writeUpdateCache({ spawnedAt: Date.now(), spawnTo: ok ? to : null });
152
- reporter.info(
153
- ok
154
- ? `⬆ ${NPM_PACKAGE} ${CLI_VERSION} → ${to}: updating in background — takes effect on next run (the binary blinks out for a few seconds while npm installs).`
155
- : `⬆ ${NPM_PACKAGE} ${to} available (auto-update failed; run \`npm i -g ${NPM_PACKAGE}\`).`
156
- );
157
- } else {
158
- reporter.info(
159
- `⬆ ${NPM_PACKAGE} ${CLI_VERSION} → ${to} available. Background update was already attempted — if your version didn't change, run \`collectui update\`.`
160
- );
161
- }
119
+ if (decision.mode === "notify") {
120
+ reporter.info(
121
+ `⬆ ${NPM_PACKAGE} ${CLI_VERSION} → ${decision.latest} available — run \`collectui update\` to upgrade.`
122
+ );
162
123
  return;
163
124
  }
164
125
  // mode === "check"
165
- backgroundCheck({ autoOn: deps.config?.autoUpdate !== false, reporter });
126
+ backgroundCheck();
166
127
  }
167
128
 
168
129
  /** 手动更新(`collectui update`):前台跑,人看着进度。runner 可注入(测试)。 */