personal-bot 0.3.4 → 0.3.5
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/.claude-plugin/marketplace.json +2 -2
- package/.claude-plugin/plugin.json +1 -1
- package/bin/pbot.mjs +3 -17
- package/docs/architecture/design.md +8 -6
- package/docs/architecture/extensibility.md +1 -1
- package/docs/architecture/principles.md +1 -1
- package/lib/antigravity-plugin/lib/common/paths.d.ts +1 -0
- package/lib/antigravity-plugin/lib/common/paths.js +2 -0
- package/lib/antigravity-plugin/lib/extension/acp-worker.js +26 -24
- package/lib/antigravity-plugin/lib/extension/cli.js +22596 -0
- package/lib/antigravity-plugin/lib/extension/mcp.js +22 -20
- package/lib/antigravity-plugin/lib/extension/workspace-cli.js +5 -20165
- package/lib/antigravity-plugin/package.json +1 -1
- package/lib/antigravity-plugin/plugin.json +1 -1
- package/lib/codex-marketplace/plugins/personal-bot/.codex-plugin/plugin.json +1 -1
- package/lib/codex-marketplace/plugins/personal-bot/.mcp.json +2 -2
- package/lib/codex-marketplace/plugins/personal-bot/hooks/hooks.json +3 -3
- package/lib/codex-marketplace/plugins/personal-bot/skills/pbot/SKILL.md +1 -1
- package/lib/common/paths.d.ts +1 -0
- package/lib/common/paths.js +2 -0
- package/lib/extension/acp-worker.js +26 -24
- package/lib/extension/cli.js +22596 -0
- package/lib/extension/mcp.js +22 -20
- package/lib/extension/workspace-cli.js +5 -20165
- package/lib/qoder-plugin/.mcp.json +2 -2
- package/lib/qoder-plugin/.qoder-plugin/plugin.json +1 -1
- package/lib/qoder-plugin/hooks/hooks.json +3 -3
- package/lib/qoder-plugin/skills/pbot/SKILL.md +1 -1
- package/package.json +1 -1
- package/scripts/README.md +1 -1
- package/src/common/paths.ts +2 -0
- package/src/extension/cli/args.ts +104 -0
- package/src/extension/cli/commands/history.ts +81 -0
- package/src/extension/cli/commands/mcp.ts +165 -0
- package/src/extension/cli/commands/plugin.ts +33 -0
- package/src/extension/cli/commands/setup.ts +159 -0
- package/src/extension/cli/commands/upgrade.ts +158 -0
- package/src/extension/cli/commands/workspace.ts +71 -0
- package/src/extension/cli/index.ts +193 -0
- package/src/extension/cli/types.ts +30 -0
- package/src/integrations/installation/cli-update.ts +3 -3
- package/src/integrations/installation/pi-setup.ts +6 -3
- package/src/services/installation/setup-service.ts +0 -35
- package/lib/extension/setup/cli.js +0 -364
- package/lib/extension/setup/upgrade.js +0 -153
- package/lib/integrations/installation/cli-update.js +0 -146
- package/lib/integrations/installation/pi-setup.js +0 -193
- package/lib/integrations/installation/processes.js +0 -140
- package/lib/integrations/installation/upgraders/antigravity.js +0 -67
- package/lib/integrations/installation/upgraders/claude.js +0 -123
- package/lib/integrations/installation/upgraders/codex.js +0 -73
- package/lib/integrations/installation/upgraders/dsh.js +0 -62
- package/lib/integrations/installation/upgraders/pi.js +0 -90
- package/lib/integrations/installation/upgraders/qoder.js +0 -67
- package/lib/integrations/installation/upgraders/registry.js +0 -40
- package/lib/integrations/installation/workspace.js +0 -21
- package/lib/services/installation/setup-service.js +0 -140
- package/lib/services/installation/upgrade-service.js +0 -95
- package/lib/ui/setup.js +0 -52
- package/src/extension/setup/cli.ts +0 -303
- package/src/extension/setup/upgrade.ts +0 -158
- package/src/extension/setup/workspace-cli.ts +0 -167
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
import { readFile } from "node:fs/promises";
|
|
2
|
-
import { join } from "node:path";
|
|
3
|
-
import { gte, valid } from "semver";
|
|
4
|
-
import { object } from "../../../common/json.js";
|
|
5
|
-
import { npmName } from "../../../common/package-source.js";
|
|
6
|
-
function packageSource(entry) {
|
|
7
|
-
if (typeof entry === "string")
|
|
8
|
-
return entry;
|
|
9
|
-
if (object(entry) && typeof entry.source === "string")
|
|
10
|
-
return entry.source;
|
|
11
|
-
return undefined;
|
|
12
|
-
}
|
|
13
|
-
async function hasCustomOnlySource(workspace) {
|
|
14
|
-
const settingsPath = join(workspace, ".pi", "settings.json");
|
|
15
|
-
try {
|
|
16
|
-
const data = JSON.parse(await readFile(settingsPath, "utf8"));
|
|
17
|
-
if (!object(data) || !Array.isArray(data.packages))
|
|
18
|
-
return false;
|
|
19
|
-
const sources = data.packages.map(packageSource).filter((value) => value !== undefined);
|
|
20
|
-
const matches = sources.filter(source => source.includes("personal-bot"));
|
|
21
|
-
if (!matches.length)
|
|
22
|
-
return false;
|
|
23
|
-
return matches.every(source => npmName(source) !== "personal-bot");
|
|
24
|
-
}
|
|
25
|
-
catch (error) {
|
|
26
|
-
if (error.code === "ENOENT")
|
|
27
|
-
return false;
|
|
28
|
-
throw error;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
async function readLocalPiVersion(workspace) {
|
|
32
|
-
const manifestPath = join(workspace, ".pi", "npm", "node_modules", "personal-bot", "package.json");
|
|
33
|
-
try {
|
|
34
|
-
const data = JSON.parse(await readFile(manifestPath, "utf8"));
|
|
35
|
-
return object(data) && data.name === "personal-bot" && typeof data.version === "string" && valid(data.version)
|
|
36
|
-
? data.version
|
|
37
|
-
: undefined;
|
|
38
|
-
}
|
|
39
|
-
catch (error) {
|
|
40
|
-
if (error.code === "ENOENT")
|
|
41
|
-
return undefined;
|
|
42
|
-
throw error;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
export const piUpgrader = {
|
|
46
|
-
host: "pi",
|
|
47
|
-
async upgrade(context) {
|
|
48
|
-
const current = await readLocalPiVersion(context.workspace) ?? context.currentVersion;
|
|
49
|
-
if (current && valid(current) && gte(current, context.targetVersion)) {
|
|
50
|
-
return {
|
|
51
|
-
host: this.host,
|
|
52
|
-
state: "up-to-date",
|
|
53
|
-
previousVersion: current,
|
|
54
|
-
version: current,
|
|
55
|
-
scope: "local",
|
|
56
|
-
detail: "已是最新版本。",
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
if (await hasCustomOnlySource(context.workspace)) {
|
|
60
|
-
return {
|
|
61
|
-
host: this.host,
|
|
62
|
-
state: "skipped",
|
|
63
|
-
...(current ? { previousVersion: current } : {}),
|
|
64
|
-
scope: "local",
|
|
65
|
-
detail: "工作区 Pi 配置中的 personal-bot 使用非 npm 自定义来源,已保留当前配置。",
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
const pi = context.env.PBOT_PI_COMMAND || await context.findExecutable("pi");
|
|
69
|
-
if (!pi) {
|
|
70
|
-
return {
|
|
71
|
-
host: this.host,
|
|
72
|
-
state: "skipped",
|
|
73
|
-
...(current ? { previousVersion: current } : {}),
|
|
74
|
-
scope: "local",
|
|
75
|
-
detail: "未找到 Pi CLI(pi),已跳过。",
|
|
76
|
-
};
|
|
77
|
-
}
|
|
78
|
-
await context.run(pi, ["install", "--local", `npm:personal-bot@${context.targetVersion}`], context.workspace);
|
|
79
|
-
const installed = await readLocalPiVersion(context.workspace) ?? context.targetVersion;
|
|
80
|
-
return {
|
|
81
|
-
host: this.host,
|
|
82
|
-
state: "updated",
|
|
83
|
-
...(current ? { previousVersion: current } : {}),
|
|
84
|
-
version: installed,
|
|
85
|
-
scope: "local",
|
|
86
|
-
detail: `已通过 pi install --local 更新工作区 personal-bot 到 ${installed}。`,
|
|
87
|
-
nextStep: "在 Pi 中执行 /reload 或重启 Pi 使新版本生效。",
|
|
88
|
-
};
|
|
89
|
-
},
|
|
90
|
-
};
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import { readFile } from "node:fs/promises";
|
|
2
|
-
import { join } from "node:path";
|
|
3
|
-
import { gte, lt, valid } from "semver";
|
|
4
|
-
import { object } from "../../../common/json.js";
|
|
5
|
-
async function readManifestVersion(path) {
|
|
6
|
-
try {
|
|
7
|
-
const data = JSON.parse(await readFile(path, "utf8"));
|
|
8
|
-
return object(data) && typeof data.version === "string" && valid(data.version) ? data.version : undefined;
|
|
9
|
-
}
|
|
10
|
-
catch (error) {
|
|
11
|
-
if (error.code === "ENOENT")
|
|
12
|
-
return undefined;
|
|
13
|
-
throw error;
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
export const qoderUpgrader = {
|
|
17
|
-
host: "qoder",
|
|
18
|
-
async upgrade(context) {
|
|
19
|
-
if (context.currentVersion && valid(context.currentVersion) && gte(context.currentVersion, context.targetVersion)) {
|
|
20
|
-
return {
|
|
21
|
-
host: this.host,
|
|
22
|
-
state: "up-to-date",
|
|
23
|
-
previousVersion: context.currentVersion,
|
|
24
|
-
version: context.currentVersion,
|
|
25
|
-
scope: "user",
|
|
26
|
-
detail: "已是最新版本。",
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
const pluginDir = join(context.packageRoot, "lib", "qoder-plugin");
|
|
30
|
-
const bundledVersion = await readManifestVersion(join(pluginDir, ".qoder-plugin", "plugin.json"));
|
|
31
|
-
if (!bundledVersion) {
|
|
32
|
-
return {
|
|
33
|
-
host: this.host,
|
|
34
|
-
state: "skipped",
|
|
35
|
-
...(context.currentVersion ? { previousVersion: context.currentVersion } : {}),
|
|
36
|
-
detail: `缺少 Qoder CLI 插件构建产物:${pluginDir}`,
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
if (lt(bundledVersion, context.targetVersion)) {
|
|
40
|
-
return {
|
|
41
|
-
host: this.host,
|
|
42
|
-
state: "skipped",
|
|
43
|
-
...(context.currentVersion ? { previousVersion: context.currentVersion } : {}),
|
|
44
|
-
detail: `当前本地包产物版本为 ${bundledVersion},低于目标版本 ${context.targetVersion};请先更新全局 personal-bot 包。`,
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
const qodercli = context.env.PBOT_QODER_COMMAND || await context.findExecutable("qodercli");
|
|
48
|
-
if (!qodercli) {
|
|
49
|
-
return {
|
|
50
|
-
host: this.host,
|
|
51
|
-
state: "skipped",
|
|
52
|
-
...(context.currentVersion ? { previousVersion: context.currentVersion } : {}),
|
|
53
|
-
detail: "未找到 Qoder CLI(qodercli),已跳过。",
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
await context.run(qodercli, ["plugin", "install", pluginDir], context.workspace);
|
|
57
|
-
return {
|
|
58
|
-
host: this.host,
|
|
59
|
-
state: "updated",
|
|
60
|
-
...(context.currentVersion ? { previousVersion: context.currentVersion } : {}),
|
|
61
|
-
version: bundledVersion,
|
|
62
|
-
scope: "user",
|
|
63
|
-
detail: `已通过 qodercli plugin install 更新到 ${bundledVersion}。`,
|
|
64
|
-
nextStep: "重启 Qoder CLI 会话使新版本生效。",
|
|
65
|
-
};
|
|
66
|
-
},
|
|
67
|
-
};
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { requireThat } from "../../../common/validation.js";
|
|
2
|
-
import { antigravityUpgrader } from "./antigravity.js";
|
|
3
|
-
import { claudeUpgrader } from "./claude.js";
|
|
4
|
-
import { codexUpgrader } from "./codex.js";
|
|
5
|
-
import { dshUpgrader } from "./dsh.js";
|
|
6
|
-
import { piUpgrader } from "./pi.js";
|
|
7
|
-
import { qoderUpgrader } from "./qoder.js";
|
|
8
|
-
/** Extensible registry of per-host plugin upgraders; core upgrade orchestration never branches on host IDs. */
|
|
9
|
-
export class HostUpgraderRegistry {
|
|
10
|
-
#upgraders = new Map();
|
|
11
|
-
constructor(initial = []) {
|
|
12
|
-
for (const upgrader of initial)
|
|
13
|
-
this.register(upgrader);
|
|
14
|
-
}
|
|
15
|
-
register(upgrader) {
|
|
16
|
-
requireThat(typeof upgrader.host === "string" && upgrader.host.length > 0, "宿主升级适配器标识无效。");
|
|
17
|
-
this.#upgraders.set(upgrader.host, upgrader);
|
|
18
|
-
return this;
|
|
19
|
-
}
|
|
20
|
-
unregister(host) {
|
|
21
|
-
return this.#upgraders.delete(host);
|
|
22
|
-
}
|
|
23
|
-
get(host) {
|
|
24
|
-
return this.#upgraders.get(host);
|
|
25
|
-
}
|
|
26
|
-
list() {
|
|
27
|
-
return [...this.#upgraders.keys()];
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
export const hostUpgraders = new HostUpgraderRegistry([
|
|
31
|
-
piUpgrader,
|
|
32
|
-
claudeUpgrader,
|
|
33
|
-
antigravityUpgrader,
|
|
34
|
-
codexUpgrader,
|
|
35
|
-
qoderUpgrader,
|
|
36
|
-
dshUpgrader,
|
|
37
|
-
]);
|
|
38
|
-
export const registerHostUpgrader = (upgrader) => hostUpgraders.register(upgrader);
|
|
39
|
-
export const getHostUpgrader = (host) => hostUpgraders.get(host);
|
|
40
|
-
export const listHostUpgraders = () => hostUpgraders.list();
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { stat, realpath } from "node:fs/promises";
|
|
2
|
-
import { dirname, join, relative, resolve } from "node:path";
|
|
3
|
-
export async function resolveWorkspace(value, cwd, home) {
|
|
4
|
-
const path = resolve(cwd, value === "~" ? home : value.startsWith("~/") ? join(home, value.slice(2)) : value);
|
|
5
|
-
let existing = path;
|
|
6
|
-
while (true) {
|
|
7
|
-
try {
|
|
8
|
-
if (!(await stat(existing)).isDirectory())
|
|
9
|
-
throw new Error("工作区或其父路径不是目录:" + existing);
|
|
10
|
-
return resolve(await realpath(existing), relative(existing, path));
|
|
11
|
-
}
|
|
12
|
-
catch (error) {
|
|
13
|
-
if (error.code !== "ENOENT")
|
|
14
|
-
throw error;
|
|
15
|
-
const parent = dirname(existing);
|
|
16
|
-
if (parent === existing)
|
|
17
|
-
throw error;
|
|
18
|
-
existing = parent;
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
}
|
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
import { npmName, ordinaryNpm } from "../../common/package-source.js";
|
|
2
|
-
export const pbotPackage = {
|
|
3
|
-
id: "pbot", label: "Personal Bot", description: "工作区个人助手", source: "npm:personal-bot", defaultSelected: true,
|
|
4
|
-
};
|
|
5
|
-
export function parseCatalog(value) {
|
|
6
|
-
if (!Array.isArray(value))
|
|
7
|
-
throw new Error("插件清单必须是数组。");
|
|
8
|
-
const ids = new Set(["pbot"]), names = new Set(["personal-bot"]);
|
|
9
|
-
return value.map((item) => {
|
|
10
|
-
if (!item || typeof item !== "object")
|
|
11
|
-
throw new Error("无效插件清单项。");
|
|
12
|
-
const entry = item;
|
|
13
|
-
for (const field of ["id", "label", "description", "source"]) {
|
|
14
|
-
if (typeof entry[field] !== "string" || !entry[field].trim() || /[\x00-\x1f\x7f]/.test(entry[field])) {
|
|
15
|
-
throw new Error(`无效插件字段:${field}`);
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
const plugin = entry;
|
|
19
|
-
const name = npmName(plugin.source);
|
|
20
|
-
if (!/^[a-z0-9-]+$/.test(plugin.id) || !name || !ordinaryNpm(plugin.source) ||
|
|
21
|
-
typeof plugin.defaultSelected !== "boolean" || ids.has(plugin.id) || names.has(name)) {
|
|
22
|
-
throw new Error(`无效或重复的插件:${plugin.id}`);
|
|
23
|
-
}
|
|
24
|
-
ids.add(plugin.id);
|
|
25
|
-
names.add(name);
|
|
26
|
-
return { id: plugin.id, label: plugin.label, description: plugin.description,
|
|
27
|
-
source: `npm:${name}`, defaultSelected: plugin.defaultSelected };
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
export function packageChoices(catalog, installed) {
|
|
31
|
-
const first = !installed.some(pkg => pkg.name === "personal-bot");
|
|
32
|
-
return [pbotPackage, ...catalog].map(plugin => {
|
|
33
|
-
const matches = installed.filter(pkg => pkg.name === npmName(plugin.source));
|
|
34
|
-
// A project npm entry overrides the same npm identity in user settings. Different
|
|
35
|
-
// git/local identities still need an explicit decision before changing sources.
|
|
36
|
-
const localNpm = matches.some(pkg => pkg.scope === "project" && npmName(pkg.source));
|
|
37
|
-
const existing = matches.filter(pkg => !(localNpm && pkg.scope === "user" && npmName(pkg.source)));
|
|
38
|
-
const custom = existing.some(pkg => !ordinaryNpm(pkg.source));
|
|
39
|
-
return { plugin, required: plugin.id === "pbot", existing,
|
|
40
|
-
selected: plugin.id === "pbot" || (first ? plugin.defaultSelected : existing.length > 0), keep: custom };
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
export function parseSetupArgs(args) {
|
|
44
|
-
if (!args.length || args.length === 1 && ["--help", "-h"].includes(args[0]))
|
|
45
|
-
return { action: "help" };
|
|
46
|
-
if (args.length === 1 && ["--version", "-v"].includes(args[0]))
|
|
47
|
-
return { action: "version" };
|
|
48
|
-
if (args[0] === "upgrade" || args[0] === "update") {
|
|
49
|
-
return { action: "upgrade", upgradeArgs: args.slice(1), upgradeVerb: args[0] };
|
|
50
|
-
}
|
|
51
|
-
if (args[0] === "install-antigravity") {
|
|
52
|
-
if (args.length === 1)
|
|
53
|
-
return { action: "install-antigravity" };
|
|
54
|
-
if (args.length === 2 && ["--help", "-h"].includes(args[1]))
|
|
55
|
-
return { action: "help" };
|
|
56
|
-
throw new Error("用法:pbot install-antigravity");
|
|
57
|
-
}
|
|
58
|
-
if (args[0] === "mcp") {
|
|
59
|
-
if (args.length === 1)
|
|
60
|
-
return { action: "mcp" };
|
|
61
|
-
if (args.length === 2 && ["--help", "-h"].includes(args[1]))
|
|
62
|
-
return { action: "help" };
|
|
63
|
-
if (["list", "add", "remove"].includes(args[1]))
|
|
64
|
-
return { action: "mcp-manage", mcpArgs: args.slice(1) };
|
|
65
|
-
throw new Error("用法:pbot mcp [list|add|remove ...]");
|
|
66
|
-
}
|
|
67
|
-
if (args[0] !== "setup")
|
|
68
|
-
throw new Error("用法:pbot setup [--workspace <目录>] | pbot upgrade|update [--workspace <目录>] | pbot install-antigravity | pbot mcp [list|add|remove ...]");
|
|
69
|
-
let workspace;
|
|
70
|
-
for (let index = 1; index < args.length; index++) {
|
|
71
|
-
const arg = args[index];
|
|
72
|
-
if ((arg === "--help" || arg === "-h") && args.length === 2)
|
|
73
|
-
return { action: "help" };
|
|
74
|
-
if (arg !== "--workspace" || workspace !== undefined)
|
|
75
|
-
throw new Error(`不支持的参数:${arg}`);
|
|
76
|
-
const value = args[++index];
|
|
77
|
-
if (!value || value.startsWith("--") || /[\x00-\x1f\x7f]/.test(value))
|
|
78
|
-
throw new Error("--workspace 需要目录。");
|
|
79
|
-
workspace = value;
|
|
80
|
-
}
|
|
81
|
-
return workspace === undefined ? { action: "setup" } : { action: "setup", workspace };
|
|
82
|
-
}
|
|
83
|
-
export async function executeSetup(plan, operations, report, signal) {
|
|
84
|
-
const results = [];
|
|
85
|
-
const add = (result) => { results.push(result); report(result); };
|
|
86
|
-
let pi;
|
|
87
|
-
try {
|
|
88
|
-
signal.throwIfAborted();
|
|
89
|
-
if (plan.tmux) {
|
|
90
|
-
await operations.installTmux(plan.tmux);
|
|
91
|
-
add({ name: "tmux", state: "done", detail: "已安装" });
|
|
92
|
-
}
|
|
93
|
-
signal.throwIfAborted();
|
|
94
|
-
pi = await operations.ensurePi(plan.pi, plan.piVersion);
|
|
95
|
-
add({ name: "Pi", state: "done", detail: pi.version });
|
|
96
|
-
}
|
|
97
|
-
catch (error) {
|
|
98
|
-
signal.throwIfAborted();
|
|
99
|
-
add({ name: "运行环境", state: "failed", detail: String(error) });
|
|
100
|
-
return { results };
|
|
101
|
-
}
|
|
102
|
-
for (const choice of plan.packages) {
|
|
103
|
-
signal.throwIfAborted();
|
|
104
|
-
const name = choice.plugin.label;
|
|
105
|
-
if (!choice.selected) {
|
|
106
|
-
add({ name, state: "skipped", detail: "本次不处理" });
|
|
107
|
-
continue;
|
|
108
|
-
}
|
|
109
|
-
if (choice.error) {
|
|
110
|
-
add({ name, state: "failed", detail: choice.error });
|
|
111
|
-
if (choice.required)
|
|
112
|
-
return { results };
|
|
113
|
-
continue;
|
|
114
|
-
}
|
|
115
|
-
if (choice.keep) {
|
|
116
|
-
try {
|
|
117
|
-
const source = await operations.verifyKeptPackage(pi, plan.workspace, choice);
|
|
118
|
-
add({ name, state: "kept", detail: source });
|
|
119
|
-
}
|
|
120
|
-
catch (error) {
|
|
121
|
-
signal.throwIfAborted();
|
|
122
|
-
add({ name, state: "failed", detail: String(error) });
|
|
123
|
-
if (choice.required)
|
|
124
|
-
return { results };
|
|
125
|
-
}
|
|
126
|
-
continue;
|
|
127
|
-
}
|
|
128
|
-
try {
|
|
129
|
-
const version = await operations.installPackage(pi, plan.workspace, choice);
|
|
130
|
-
add({ name, state: "done", detail: version });
|
|
131
|
-
}
|
|
132
|
-
catch (error) {
|
|
133
|
-
signal.throwIfAborted();
|
|
134
|
-
add({ name, state: "failed", detail: String(error) });
|
|
135
|
-
if (choice.required)
|
|
136
|
-
return { results };
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
return { pi, results };
|
|
140
|
-
}
|
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
import { valid } from "semver";
|
|
2
|
-
import { requireThat } from "../../common/validation.js";
|
|
3
|
-
export const upgradeUsage = "用法:pbot upgrade|update [--workspace <目录>] [--version <MAJOR.MINOR.PATCH>] [--hosts <h1,h2>] [--dsh-profile <名称>] [--json]\n" +
|
|
4
|
-
"将全局 CLI 与当前工作区已绑定的各宿主插件统一升级到 npm 最新稳定版(或指定版本)。";
|
|
5
|
-
export function parseUpgradeArgs(args) {
|
|
6
|
-
let workspace;
|
|
7
|
-
let version;
|
|
8
|
-
let hosts;
|
|
9
|
-
let dshProfile;
|
|
10
|
-
let json = false;
|
|
11
|
-
for (let index = 0; index < args.length; index++) {
|
|
12
|
-
const token = args[index];
|
|
13
|
-
if (token === "--help" || token === "-h")
|
|
14
|
-
return { help: true, json: false };
|
|
15
|
-
if (token === "--json") {
|
|
16
|
-
json = true;
|
|
17
|
-
continue;
|
|
18
|
-
}
|
|
19
|
-
if (token === "--workspace" || token.startsWith("--workspace=")) {
|
|
20
|
-
requireThat(workspace === undefined, "--workspace 只能指定一次。");
|
|
21
|
-
workspace = token === "--workspace" ? args[++index] : token.slice("--workspace=".length);
|
|
22
|
-
requireThat(workspace && !workspace.startsWith("-"), "--workspace 需要目录。");
|
|
23
|
-
continue;
|
|
24
|
-
}
|
|
25
|
-
if (token === "--version" || token.startsWith("--version=")) {
|
|
26
|
-
requireThat(version === undefined, "--version 只能指定一次。");
|
|
27
|
-
version = token === "--version" ? args[++index] : token.slice("--version=".length);
|
|
28
|
-
requireThat(version && valid(version) && /^[0-9]/.test(version) && version === version.trim(), "--version 需要合法的 MAJOR.MINOR.PATCH 版本号。");
|
|
29
|
-
continue;
|
|
30
|
-
}
|
|
31
|
-
if (token === "--hosts" || token.startsWith("--hosts=")) {
|
|
32
|
-
requireThat(hosts === undefined, "--hosts 只能指定一次。");
|
|
33
|
-
const raw = token === "--hosts" ? args[++index] : token.slice("--hosts=".length);
|
|
34
|
-
requireThat(raw && !raw.startsWith("-"), "--hosts 需要逗号分隔的宿主名称。");
|
|
35
|
-
hosts = [...new Set(raw.split(",").map(item => item.trim()).filter(Boolean))];
|
|
36
|
-
requireThat(hosts.length > 0, "--hosts 不能为空。");
|
|
37
|
-
continue;
|
|
38
|
-
}
|
|
39
|
-
if (token === "--dsh-profile" || token.startsWith("--dsh-profile=")) {
|
|
40
|
-
requireThat(dshProfile === undefined, "--dsh-profile 只能指定一次。");
|
|
41
|
-
dshProfile = token === "--dsh-profile" ? args[++index] : token.slice("--dsh-profile=".length);
|
|
42
|
-
requireThat(dshProfile && !dshProfile.startsWith("-"), "--dsh-profile 需要 profile 名称。");
|
|
43
|
-
continue;
|
|
44
|
-
}
|
|
45
|
-
throw new Error(`不支持的参数:${token}\n${upgradeUsage}`);
|
|
46
|
-
}
|
|
47
|
-
return {
|
|
48
|
-
help: false,
|
|
49
|
-
...(workspace !== undefined ? { workspace } : {}),
|
|
50
|
-
...(version !== undefined ? { version } : {}),
|
|
51
|
-
...(hosts !== undefined ? { hosts } : {}),
|
|
52
|
-
...(dshProfile !== undefined ? { dshProfile } : {}),
|
|
53
|
-
json,
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
export async function executeWorkspaceUpgrade(input) {
|
|
57
|
-
const results = [];
|
|
58
|
-
for (const target of input.targets) {
|
|
59
|
-
input.signal.throwIfAborted();
|
|
60
|
-
const upgrader = input.resolveUpgrader(target.host);
|
|
61
|
-
let result;
|
|
62
|
-
if (!upgrader) {
|
|
63
|
-
result = {
|
|
64
|
-
host: target.host,
|
|
65
|
-
state: "skipped",
|
|
66
|
-
...(target.currentVersion ? { previousVersion: target.currentVersion } : {}),
|
|
67
|
-
detail: "未注册该宿主的自动升级适配器,已跳过。",
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
else {
|
|
71
|
-
try {
|
|
72
|
-
result = await upgrader.upgrade(input.createContext(target));
|
|
73
|
-
}
|
|
74
|
-
catch (error) {
|
|
75
|
-
input.signal.throwIfAborted();
|
|
76
|
-
result = {
|
|
77
|
-
host: target.host,
|
|
78
|
-
state: "failed",
|
|
79
|
-
...(target.currentVersion ? { previousVersion: target.currentVersion } : {}),
|
|
80
|
-
detail: error instanceof Error ? error.message : String(error),
|
|
81
|
-
};
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
results.push(result);
|
|
85
|
-
input.onResult?.(result);
|
|
86
|
-
}
|
|
87
|
-
const ok = input.cli.state !== "failed" && !results.some(item => item.state === "failed");
|
|
88
|
-
return {
|
|
89
|
-
workspaceRoot: input.workspaceRoot,
|
|
90
|
-
targetVersion: input.targetVersion,
|
|
91
|
-
cli: input.cli,
|
|
92
|
-
results,
|
|
93
|
-
ok,
|
|
94
|
-
};
|
|
95
|
-
}
|
package/lib/ui/setup.js
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { createInterface } from "node:readline/promises";
|
|
2
|
-
export class SetupUI {
|
|
3
|
-
controller;
|
|
4
|
-
constructor(controller) {
|
|
5
|
-
this.controller = controller;
|
|
6
|
-
}
|
|
7
|
-
text(value) { console.log(value); }
|
|
8
|
-
async ask(label, fallback = "") {
|
|
9
|
-
this.controller.signal.throwIfAborted();
|
|
10
|
-
const reader = createInterface({ input: process.stdin, output: process.stdout, terminal: true });
|
|
11
|
-
reader.on("SIGINT", () => this.controller.abort(new Error("安装已取消。")));
|
|
12
|
-
reader.on("close", () => { if (!answered)
|
|
13
|
-
this.controller.abort(new Error("输入已关闭。")); });
|
|
14
|
-
let answered = false;
|
|
15
|
-
try {
|
|
16
|
-
const value = await reader.question(label + (fallback ? " [" + fallback + "]" : "") + ": ", { signal: this.controller.signal });
|
|
17
|
-
answered = true;
|
|
18
|
-
return value.trim() || fallback;
|
|
19
|
-
}
|
|
20
|
-
finally {
|
|
21
|
-
answered = true;
|
|
22
|
-
reader.close();
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
async confirm(label, fallback = true) {
|
|
26
|
-
while (true) {
|
|
27
|
-
const answer = (await this.ask(label + (fallback ? " [Y/n]" : " [y/N]"))).toLowerCase();
|
|
28
|
-
if (!answer)
|
|
29
|
-
return fallback;
|
|
30
|
-
if (["y", "yes", "是"].includes(answer))
|
|
31
|
-
return true;
|
|
32
|
-
if (["n", "no", "否"].includes(answer))
|
|
33
|
-
return false;
|
|
34
|
-
this.text("请输入 y 或 n。");
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
async selectMany(labels, defaults) {
|
|
38
|
-
labels.forEach((label, index) => this.text(" " + (defaults.includes(index) ? "[x] " : "[ ] ") + (index + 1) + ". " + label));
|
|
39
|
-
while (true) {
|
|
40
|
-
const answer = await this.ask("选择插件编号(逗号分隔,回车保留默认,0 不选)");
|
|
41
|
-
if (!answer)
|
|
42
|
-
return defaults;
|
|
43
|
-
if (answer === "0")
|
|
44
|
-
return [];
|
|
45
|
-
const parts = answer.split(/[,,\s]+/);
|
|
46
|
-
if (parts.every(part => /^\d+$/.test(part) && Number(part) >= 1 && Number(part) <= labels.length)) {
|
|
47
|
-
return [...new Set(parts.map(part => Number(part) - 1))];
|
|
48
|
-
}
|
|
49
|
-
this.text("请输入列表中的编号。");
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
}
|