@collectui/cli 0.2.8 → 0.2.10

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
- CLI 每 12 小时后台查一次 npm(本地缓存 `~/.collectui/update-check.json`,绝不阻塞命令)。
172
- 交互终端下**默认自动更新**:发现新版即后台 `npm i -g @collectui/cli@latest`,
173
- 下次运行生效,当前命令不受影响。
171
+ **每次运行命令时即时异步查一次 npm**(与命令并行,不阻塞;结束时最多等 1 秒收结果)。
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.8",
3
+ "version": "0.2.10",
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,13 +165,17 @@ async function main() {
165
165
  if (token) reporter.addSecrets([token]);
166
166
 
167
167
  showBanner(reporter); // 开机画面:任何子命令(headless/--version/help 已在前面分流)
168
- // 自更新:交互 TTY 下后台检查/自动更(headless/CI 由门控静默跳过);
168
+ // 更新检查:与命令并行即时异步查一次 npm(TTY 才查),有新版打一行提醒;
169
169
  // 手动 update 命令自身不触发(避免与前台安装并发写全局目录)
170
- if (name !== "update" && name !== "upgrade") {
171
- startBackgroundUpdate(reporter, { config: readConfig() });
172
- }
170
+ const updateNotice =
171
+ name !== "update" && name !== "upgrade" ? startBackgroundUpdate(reporter) : null;
172
+ const race = (p, ms) => Promise.race([p, new Promise((r) => setTimeout(r, ms))]);
173
+ const settleUpdate = updateNotice
174
+ ? () => race(updateNotice.done, 1_000).catch(() => {})
175
+ : () => Promise.resolve();
173
176
 
174
177
  await command.run(flags, rest, reporter);
178
+ await settleUpdate();
175
179
  }
176
180
 
177
181
  /** 命令完成后 flush stdout 并退出:一次性进程不留后台尾巴(callback server 的
@@ -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/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
+ * - CLI 是一次性进程,没有「后台周期任务」——每次运行命令时即时异步查一次 npm
11
+ * (与命令并行,命令结束时最多再等 1 秒收结果)
12
+ * - 发现新版 → 打一行显式提醒,装不装由用户跑 `collectui update` 决定
13
+ * - headless/--json 完全不碰(Agent/CI 输出契约不被搅动);npx 临时跑不需要
14
+ * - COLLECTUI_NO_AUTO_UPDATE=1:连检查带提示全静默(CI 显式意图)
15
15
  */
16
16
 
17
17
  export const NPM_PACKAGE = "@collectui/cli";
18
18
  const REGISTRY_LATEST = "https://registry.npmjs.org/@collectui/cli/latest";
19
- 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");
@@ -59,19 +57,12 @@ export function compareVersions(a, b) {
59
57
  }
60
58
 
61
59
  /**
62
- * 纯决策函数(单测覆盖):本次启动对更新做点什么。
63
- * 返回 { mode, latest?, reason },mode ∈
64
- * off-silent(env 显式禁 → 全静默)| none | notify(只提示)| notify-spawn(提示+后台更)| check(到点检查)
60
+ * 纯决策函数(单测覆盖):本次启动是否检查更新。
61
+ * mode ∈ off-silent(env 显式禁 → 全静默)| none(npx / 非 TTY)| run(即时异步查)
65
62
  */
66
63
  export function decideUpdate({
67
64
  env = process.env,
68
- config = {},
69
- cache = {},
70
- now = Date.now(),
71
65
  isTTY = process.stdout.isTTY,
72
- version = CLI_VERSION,
73
- intervalMs = CHECK_INTERVAL_MS,
74
- spawnBackoffMs = SPAWN_BACKOFF_MS,
75
66
  } = {}) {
76
67
  const noAuto = env.COLLECTUI_NO_AUTO_UPDATE;
77
68
  if (noAuto === "1" || noAuto === "true" || noAuto === "yes") {
@@ -83,19 +74,7 @@ export function decideUpdate({
83
74
  if (!isTTY) {
84
75
  return { mode: "none", reason: "non-tty" };
85
76
  }
86
- const autoOn = config.autoUpdate !== false;
87
- const outdated = cache.latest ? compareVersions(cache.latest, version) > 0 : false;
88
- 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" };
94
- }
95
- if (now - (cache.lastCheck ?? 0) >= intervalMs) {
96
- return { mode: "check", reason: "due" };
97
- }
98
- return { mode: "none", reason: "recent" };
77
+ return { mode: "run", reason: "interactive" };
99
78
  }
100
79
 
101
80
  /** registry latest → 版本号;失败抛错(调用方决定吞还是报)。 */
@@ -108,61 +87,35 @@ export async function fetchLatestVersion({ timeout = 8_000 } = {}) {
108
87
  return v;
109
88
  }
110
89
 
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 } = {}) {
126
- const started = Date.now();
127
- return fetchLatestVersion()
128
- .then((latest) => {
129
- 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
- return latest;
136
- })
137
- .catch(() => undefined);
138
- }
139
-
140
90
  /**
141
- * 启动钩子(cli.main 里 fire-and-forget 调):按 decideUpdate 执行提示/检查/自动更。
142
- * 提示走 reporter(TTY 人类输出);headless 由 decideUpdate 的 isTTY 门挡掉。
91
+ * 启动钩子(cli.main 里调):与命令并行即时查一次 npm。
92
+ * - 缓存里已有新版 → 立即提醒(不用等本次查询)
93
+ * - 查询完成 → 写缓存;若发现有新版且还没提醒过,补一行提醒
94
+ * 返回 { done }:cli.main 在命令结束后最多等它 1 秒,没查完就放弃退出(绝不挂尾)。
143
95
  */
144
96
  export function startBackgroundUpdate(reporter, deps = {}) {
145
97
  const decision = decideUpdate(deps);
146
- 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
- }
162
- return;
98
+ if (decision.mode !== "run") return null;
99
+ let notified = false;
100
+ const cache = readUpdateCache();
101
+ if (cache.latest && compareVersions(cache.latest, CLI_VERSION) > 0) {
102
+ reporter.info(
103
+ `⬆ ${NPM_PACKAGE} ${CLI_VERSION} → ${cache.latest} available — run \`collectui update\` to upgrade.`
104
+ );
105
+ notified = true;
163
106
  }
164
- // mode === "check"
165
- backgroundCheck({ autoOn: deps.config?.autoUpdate !== false, reporter });
107
+ const done = fetchLatestVersion()
108
+ .then((latest) => {
109
+ writeUpdateCache({ lastCheck: Date.now(), latest });
110
+ if (!notified && compareVersions(latest, CLI_VERSION) > 0) {
111
+ reporter.info(
112
+ `⬆ ${NPM_PACKAGE} ${CLI_VERSION} → ${latest} available — run \`collectui update\` to upgrade.`
113
+ );
114
+ notified = true;
115
+ }
116
+ })
117
+ .catch(() => undefined);
118
+ return { done };
166
119
  }
167
120
 
168
121
  /** 手动更新(`collectui update`):前台跑,人看着进度。runner 可注入(测试)。 */