@collectui/cli 0.2.44 → 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 +1 -1
- package/src/cli.mjs +18 -3
- package/src/commands/shell.mjs +76 -0
package/package.json
CHANGED
package/src/cli.mjs
CHANGED
|
@@ -9,8 +9,11 @@
|
|
|
9
9
|
* (stdout 只出逐行 JSON event,Agent 直接消费)。所有动作经 ChangeSet:
|
|
10
10
|
* 先展示计划再落盘,`--dry-run` 只看不写,密钥全程脱敏。
|
|
11
11
|
*/
|
|
12
|
+
import { mkdirSync } from "node:fs";
|
|
12
13
|
import { homedir } from "node:os";
|
|
14
|
+
import { join } from "node:path";
|
|
13
15
|
import { parseArgv } from "./args.mjs";
|
|
16
|
+
import { configDir } from "./config.mjs";
|
|
14
17
|
import { CLI_NAME, CLI_VERSION } from "./version.mjs";
|
|
15
18
|
import { collectSecrets, readConfig, resolveToken } from "./config.mjs";
|
|
16
19
|
import { CliError, usageError } from "./errors.mjs";
|
|
@@ -29,6 +32,7 @@ import { skillCmd } from "./commands/skill.mjs";
|
|
|
29
32
|
import { updateCmd } from "./commands/update.mjs";
|
|
30
33
|
import { applyCmd } from "./commands/apply.mjs";
|
|
31
34
|
import { prefsCmd } from "./commands/prefs.mjs";
|
|
35
|
+
import { shellSetupCmd, writeCdRescue } from "./commands/shell.mjs";
|
|
32
36
|
import { cleanCmd, migrateCmd } from "./commands/migrate.mjs";
|
|
33
37
|
|
|
34
38
|
const HELP = `collectui ${CLI_VERSION} — one CLI for every shadcn library on CollectUI Dash
|
|
@@ -49,6 +53,7 @@ Commands:
|
|
|
49
53
|
prefs <sub> Account preferences: ls / get / set (pm, pinned-agents)
|
|
50
54
|
migrate <dest> Move a temp project to a permanent location (configs follow)
|
|
51
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
|
|
52
57
|
skill [dir] Install the agent skill (.claude/skills/collectui)
|
|
53
58
|
doctor Verify login, registries, env and MCP config
|
|
54
59
|
update Update the CLI now (--check only checks)
|
|
@@ -123,6 +128,7 @@ const COMMANDS = {
|
|
|
123
128
|
apply: { run: applyCmd, aliases: ["preset"] },
|
|
124
129
|
prefs: { run: prefsCmd, aliases: ["pref"] },
|
|
125
130
|
migrate: { run: migrateCmd, aliases: ["keep", "move"] },
|
|
131
|
+
"shell-setup": { run: shellSetupCmd, aliases: ["shell"] },
|
|
126
132
|
clean: { run: cleanCmd, aliases: ["cleanup"] },
|
|
127
133
|
mcp: { run: mcpCmd, aliases: [] },
|
|
128
134
|
skill: { run: skillCmd, aliases: ["install-skill"] },
|
|
@@ -209,12 +215,21 @@ async function main() {
|
|
|
209
215
|
process.cwd();
|
|
210
216
|
} catch {
|
|
211
217
|
try {
|
|
212
|
-
|
|
218
|
+
// 切到 CLI 自己的家目录(2026-12-07 用户定:不落 ~ 而落 ~/.collectui)
|
|
219
|
+
const safeDir = join(configDir());
|
|
220
|
+
mkdirSync(safeDir, { recursive: true });
|
|
221
|
+
process.chdir(safeDir);
|
|
222
|
+
// cd 信号:shell 集成(cui shell-setup 装的包装函数)会在命令结束后
|
|
223
|
+
// 替用户 shell 执行 cd——子进程改不了父 shell,但包装函数可以
|
|
224
|
+
writeCdRescue(safeDir);
|
|
213
225
|
reporter.warn(
|
|
214
|
-
`Your terminal's directory no longer exists — the CLI moved itself to
|
|
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."}`
|
|
215
227
|
);
|
|
216
228
|
} catch {
|
|
217
|
-
//
|
|
229
|
+
// 兜底 home;再失败极罕见,继续
|
|
230
|
+
try {
|
|
231
|
+
process.chdir(homedir());
|
|
232
|
+
} catch {}
|
|
218
233
|
}
|
|
219
234
|
}
|
|
220
235
|
if (token) reporter.addSecrets([token]);
|
|
@@ -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
|
+
}
|