@collectui/cli 0.2.45 → 0.2.46

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.45",
3
+ "version": "0.2.46",
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/cli.mjs CHANGED
@@ -32,6 +32,7 @@ import { skillCmd } from "./commands/skill.mjs";
32
32
  import { updateCmd } from "./commands/update.mjs";
33
33
  import { applyCmd } from "./commands/apply.mjs";
34
34
  import { prefsCmd } from "./commands/prefs.mjs";
35
+ import { shellSetupCmd, writeCdRescue } from "./commands/shell.mjs";
35
36
  import { cleanCmd, migrateCmd } from "./commands/migrate.mjs";
36
37
 
37
38
  const HELP = `collectui ${CLI_VERSION} — one CLI for every shadcn library on CollectUI Dash
@@ -52,6 +53,7 @@ Commands:
52
53
  prefs <sub> Account preferences: ls / get / set (pm, pinned-agents)
53
54
  migrate <dest> Move a temp project to a permanent location (configs follow)
54
55
  clean Delete cui projects under the OS temp directory
56
+ shell-setup Install the shell wrapper once — your shell auto-cd's when the CLI rescues itself
55
57
  skill [dir] Install the agent skill (.claude/skills/collectui)
56
58
  doctor Verify login, registries, env and MCP config
57
59
  update Update the CLI now (--check only checks)
@@ -126,6 +128,7 @@ const COMMANDS = {
126
128
  apply: { run: applyCmd, aliases: ["preset"] },
127
129
  prefs: { run: prefsCmd, aliases: ["pref"] },
128
130
  migrate: { run: migrateCmd, aliases: ["keep", "move"] },
131
+ "shell-setup": { run: shellSetupCmd, aliases: ["shell"] },
129
132
  clean: { run: cleanCmd, aliases: ["cleanup"] },
130
133
  mcp: { run: mcpCmd, aliases: [] },
131
134
  skill: { run: skillCmd, aliases: ["install-skill"] },
@@ -216,8 +219,11 @@ async function main() {
216
219
  const safeDir = join(configDir());
217
220
  mkdirSync(safeDir, { recursive: true });
218
221
  process.chdir(safeDir);
222
+ // cd 信号:shell 集成(cui shell-setup 装的包装函数)会在命令结束后
223
+ // 替用户 shell 执行 cd——子进程改不了父 shell,但包装函数可以
224
+ writeCdRescue(safeDir);
219
225
  reporter.warn(
220
- `Your terminal's directory no longer exists — the CLI moved itself to ~/.collectui. Run \`cd ~\` in your shell when convenient.`
226
+ `Your terminal's directory no longer exists — the CLI moved itself to ~/.collectui${". Your shell will follow automatically (shell integration); otherwise run `cui shell-setup` once to enable that."}`
221
227
  );
222
228
  } catch {
223
229
  // 兜底 home;再失败极罕见,继续
@@ -0,0 +1,76 @@
1
+ import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
2
+ import { homedir } from "node:os";
3
+ import { join } from "node:path";
4
+ import { configDir } from "../config.mjs";
5
+
6
+ /**
7
+ * cui shell-setup —— 一次性安装 shell 集成(cd 自救包装函数,2026-12-07)。
8
+ *
9
+ * 背景:CLI 是子进程,改不了用户 shell 的 cwd;shell 卡在已删目录时,CLI
10
+ * 只能自保(自愈 chdir 到 ~/.collectui)。本命令往 ~/.zshrc(或 ~/.bashrc)
11
+ * 注入一个 cui 包装函数:命令结束后检查 CLI 写下的 .cd-rescue 信号,
12
+ * 存在则替 shell 执行 cd——「不要我手动 cd」的完整闭环。
13
+ *
14
+ * 注入块带 >>> / <<< 标记,幂等(已存在跳过);rc 未料到的 shell 报错退出。
15
+ */
16
+
17
+ const MARK_BEGIN = "# >>> collectui cli (cd rescue) >>>";
18
+ const MARK_END = "# <<< collectui cli (cd rescue) <<<";
19
+
20
+ const SNIPPET = `${MARK_BEGIN}
21
+ cui() {
22
+ command cui "$@"
23
+ local __cui_r="$HOME/.collectui/.cd-rescue"
24
+ if [ -f "$__cui_r" ]; then
25
+ local __cui_d
26
+ __cui_d=$(cat "$__cui_r" 2>/dev/null)
27
+ rm -f "$__cui_r"
28
+ if [ -n "$__cui_d" ] && [ -d "$__cui_d" ]; then
29
+ cd "$__cui_d" 2>/dev/null
30
+ fi
31
+ fi
32
+ }
33
+ ${MARK_END}`;
34
+
35
+ export async function shellSetupCmd(flags, _rest, reporter) {
36
+ const shell = String(flags.shell ?? "").toLowerCase() ||
37
+ (process.env.SHELL ?? "").toLowerCase() ||
38
+ "zsh";
39
+ const isBash = shell.includes("bash");
40
+ const isZsh = shell.includes("zsh");
41
+ if (!isBash && !isZsh) {
42
+ reporter.warn(
43
+ `Unrecognized shell "${shell}" — snippet is zsh/bash compatible; pass --shell zsh or --shell bash to force.`
44
+ );
45
+ }
46
+ const rcPath = join(
47
+ homedir(),
48
+ isBash ? ".bashrc" : ".zshrc"
49
+ );
50
+
51
+ const existing = existsSync(rcPath) ? readFileSync(rcPath, "utf8") : "";
52
+ if (existing.includes(MARK_BEGIN)) {
53
+ reporter.info(`Shell integration already present in ~/${isBash ? ".bashrc" : ".zshrc"} — nothing to do.`);
54
+ reporter.outro("Restart your terminal (or re-source the rc) if the wrapper is not active yet.");
55
+ return;
56
+ }
57
+ writeFileSync(
58
+ rcPath,
59
+ existing + (existing && !existing.endsWith("\n") ? "\n" : "") + `\n${SNIPPET}\n`,
60
+ { mode: 0o644 }
61
+ );
62
+ reporter.result({ rc: rcPath });
63
+ reporter.outro(
64
+ `Installed the cui wrapper to ~/${isBash ? ".bashrc" : ".zshrc"} — restart your terminal (or run \`source ~/${isBash ? ".bashrc" : ".zshrc"}\`) once. After that, when the CLI rescues itself from a dead directory, your shell follows automatically.`
65
+ );
66
+ }
67
+
68
+ /** CLI 侧信号文件读取/清理辅助(自愈路径写,包装函数消费删) */
69
+ export function writeCdRescue(dir) {
70
+ try {
71
+ mkdirSync(configDir(), { recursive: true });
72
+ writeFileSync(join(configDir(), ".cd-rescue"), dir, { mode: 0o600 });
73
+ } catch {
74
+ // 信号写失败只是退化回手动 cd,不影响主流程
75
+ }
76
+ }