personal-bot 0.3.3 → 0.3.4
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/README.md +2 -2
- package/README.zh-CN.md +2 -2
- package/bin/pbot.mjs +1 -1
- package/docs/architecture/extensibility.md +21 -0
- package/docs/guides/workspace-configuration.md +13 -0
- package/lib/antigravity-plugin/lib/extension/hosts/plugin-runtime.js +9 -2
- package/lib/antigravity-plugin/lib/extension/workspace-cli.js +49 -5
- package/lib/antigravity-plugin/lib/services/workspace/plugin-releases.d.ts +12 -0
- package/lib/antigravity-plugin/lib/services/workspace/plugin-releases.js +52 -4
- 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/extension/hosts/plugin-runtime.js +9 -2
- package/lib/extension/setup/cli.js +12 -0
- package/lib/extension/setup/upgrade.js +153 -0
- package/lib/extension/workspace-cli.js +49 -5
- package/lib/integrations/installation/cli-update.js +146 -0
- package/lib/integrations/installation/upgraders/antigravity.js +67 -0
- package/lib/integrations/installation/upgraders/claude.js +123 -0
- package/lib/integrations/installation/upgraders/codex.js +73 -0
- package/lib/integrations/installation/upgraders/dsh.js +62 -0
- package/lib/integrations/installation/upgraders/pi.js +90 -0
- package/lib/integrations/installation/upgraders/qoder.js +67 -0
- package/lib/integrations/installation/upgraders/registry.js +40 -0
- 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/lib/services/installation/setup-service.js +4 -1
- package/lib/services/installation/upgrade-service.js +95 -0
- package/lib/services/workspace/plugin-releases.d.ts +12 -0
- package/lib/services/workspace/plugin-releases.js +52 -4
- package/package.json +1 -1
- package/src/extension/hosts/plugin-runtime.ts +9 -2
- package/src/extension/setup/cli.ts +7 -0
- package/src/extension/setup/upgrade.ts +158 -0
- package/src/extension/setup/workspace-cli.ts +10 -2
- package/src/integrations/installation/cli-update.ts +28 -0
- package/src/integrations/installation/upgraders/antigravity.ts +68 -0
- package/src/integrations/installation/upgraders/claude.ts +123 -0
- package/src/integrations/installation/upgraders/codex.ts +73 -0
- package/src/integrations/installation/upgraders/dsh.ts +63 -0
- package/src/integrations/installation/upgraders/pi.ts +87 -0
- package/src/integrations/installation/upgraders/qoder.ts +68 -0
- package/src/integrations/installation/upgraders/registry.ts +48 -0
- package/src/model/installation.ts +45 -0
- package/src/services/installation/setup-service.ts +7 -2
- package/src/services/installation/upgrade-service.ts +127 -0
- package/src/services/workspace/plugin-releases.ts +57 -4
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { gte, valid } from "semver";
|
|
2
|
+
export function inferDshProfile(bindingPath) {
|
|
3
|
+
if (!bindingPath)
|
|
4
|
+
return undefined;
|
|
5
|
+
const normalized = bindingPath.replaceAll("\\", "/");
|
|
6
|
+
const match = /\/profiles\/([^/]+)\/node_modules\/personal-bot\/package\.json$/.exec(normalized);
|
|
7
|
+
return match?.[1];
|
|
8
|
+
}
|
|
9
|
+
export const dshUpgrader = {
|
|
10
|
+
host: "dsh",
|
|
11
|
+
async upgrade(context) {
|
|
12
|
+
if (context.currentVersion && valid(context.currentVersion) && gte(context.currentVersion, context.targetVersion)) {
|
|
13
|
+
return {
|
|
14
|
+
host: this.host,
|
|
15
|
+
state: "up-to-date",
|
|
16
|
+
previousVersion: context.currentVersion,
|
|
17
|
+
version: context.currentVersion,
|
|
18
|
+
detail: "已是最新版本。",
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
const profile = context.options.dshProfile || inferDshProfile(context.bindingPath);
|
|
22
|
+
if (!profile) {
|
|
23
|
+
return {
|
|
24
|
+
host: this.host,
|
|
25
|
+
state: "skipped",
|
|
26
|
+
...(context.currentVersion ? { previousVersion: context.currentVersion } : {}),
|
|
27
|
+
detail: "无法自动识别 dsh profile;请传入 --dsh-profile <名称> 或手动执行:dsh plugin --profile <名称> update personal-bot --latest",
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
const dsh = context.env.PBOT_DSH_COMMAND || await context.findExecutable("dsh");
|
|
31
|
+
if (!dsh) {
|
|
32
|
+
return {
|
|
33
|
+
host: this.host,
|
|
34
|
+
state: "skipped",
|
|
35
|
+
...(context.currentVersion ? { previousVersion: context.currentVersion } : {}),
|
|
36
|
+
scope: `profile:${profile}`,
|
|
37
|
+
detail: "未找到 dsh CLI(dsh),已跳过。",
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
try {
|
|
41
|
+
await context.run(dsh, ["plugin", "--profile", profile, "update", "personal-bot", "--latest"], context.workspace);
|
|
42
|
+
}
|
|
43
|
+
catch (error) {
|
|
44
|
+
return {
|
|
45
|
+
host: this.host,
|
|
46
|
+
state: "failed",
|
|
47
|
+
...(context.currentVersion ? { previousVersion: context.currentVersion } : {}),
|
|
48
|
+
scope: `profile:${profile}`,
|
|
49
|
+
detail: `${error instanceof Error ? error.message : String(error)}(提示:更新 dsh 插件前需先停止对应 profile 的 dsh 服务)`,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
return {
|
|
53
|
+
host: this.host,
|
|
54
|
+
state: "updated",
|
|
55
|
+
...(context.currentVersion ? { previousVersion: context.currentVersion } : {}),
|
|
56
|
+
version: context.targetVersion,
|
|
57
|
+
scope: `profile:${profile}`,
|
|
58
|
+
detail: `已更新 dsh profile "${profile}" 中的 personal-bot。`,
|
|
59
|
+
nextStep: `重新启动 dsh --profile ${profile} 使新版本生效。`,
|
|
60
|
+
};
|
|
61
|
+
},
|
|
62
|
+
};
|
|
@@ -0,0 +1,90 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,67 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,40 @@
|
|
|
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();
|
|
@@ -4,13 +4,13 @@
|
|
|
4
4
|
"command": "sh",
|
|
5
5
|
"args": [
|
|
6
6
|
"-c",
|
|
7
|
-
"if pbot --at-least 0.3.3 </dev/null >/dev/null 2>&1; then exec pbot \"$@\"; fi\nexec npx --yes --ignore-scripts --prefer-offline personal-bot@0.3.
|
|
7
|
+
"if pbot --at-least 0.3.3 </dev/null >/dev/null 2>&1; then exec pbot \"$@\"; fi\nexec npx --yes --ignore-scripts --prefer-offline personal-bot@0.3.4 \"$@\"",
|
|
8
8
|
"pbot",
|
|
9
9
|
"mcp"
|
|
10
10
|
],
|
|
11
11
|
"env": {
|
|
12
12
|
"PBOT_HOST": "qoder",
|
|
13
|
-
"PBOT_PLUGIN_VERSION": "0.3.
|
|
13
|
+
"PBOT_PLUGIN_VERSION": "0.3.4"
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
16
|
}
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
"hooks": [
|
|
6
6
|
{
|
|
7
7
|
"type": "command",
|
|
8
|
-
"command": "PBOT_PLUGIN_VERSION=0.3.
|
|
8
|
+
"command": "PBOT_PLUGIN_VERSION=0.3.4 PBOT_PLUGIN_MANIFEST=\"${QODER_PLUGIN_ROOT:+$QODER_PLUGIN_ROOT/.qoder-plugin/plugin.json}\" sh -c 'if pbot --at-least 0.3.3 </dev/null >/dev/null 2>&1; then exec pbot \"$@\"; fi\nexec npx --yes --ignore-scripts --prefer-offline personal-bot@0.3.4 \"$@\"' pbot plugin qoder hook",
|
|
9
9
|
"timeout": 120
|
|
10
10
|
}
|
|
11
11
|
]
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"hooks": [
|
|
17
17
|
{
|
|
18
18
|
"type": "command",
|
|
19
|
-
"command": "PBOT_PLUGIN_VERSION=0.3.
|
|
19
|
+
"command": "PBOT_PLUGIN_VERSION=0.3.4 PBOT_PLUGIN_MANIFEST=\"${QODER_PLUGIN_ROOT:+$QODER_PLUGIN_ROOT/.qoder-plugin/plugin.json}\" sh -c 'if pbot --at-least 0.3.3 </dev/null >/dev/null 2>&1; then exec pbot \"$@\"; fi\nexec npx --yes --ignore-scripts --prefer-offline personal-bot@0.3.4 \"$@\"' pbot plugin qoder hook",
|
|
20
20
|
"timeout": 120
|
|
21
21
|
}
|
|
22
22
|
]
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"hooks": [
|
|
28
28
|
{
|
|
29
29
|
"type": "command",
|
|
30
|
-
"command": "PBOT_PLUGIN_VERSION=0.3.
|
|
30
|
+
"command": "PBOT_PLUGIN_VERSION=0.3.4 PBOT_PLUGIN_MANIFEST=\"${QODER_PLUGIN_ROOT:+$QODER_PLUGIN_ROOT/.qoder-plugin/plugin.json}\" sh -c 'if pbot --at-least 0.3.3 </dev/null >/dev/null 2>&1; then exec pbot \"$@\"; fi\nexec npx --yes --ignore-scripts --prefer-offline personal-bot@0.3.4 \"$@\"' pbot plugin qoder hook",
|
|
31
31
|
"timeout": 120
|
|
32
32
|
}
|
|
33
33
|
]
|
|
@@ -6,4 +6,4 @@ disable-model-invocation: true
|
|
|
6
6
|
|
|
7
7
|
使用当前会话的 `workspaceRoot` 作为 `--workspace`。省略子命令时使用 `status`。可执行 `init`、`status`、`history status|list|summary|migrate|search|read`。保留用户指定的维度、模型和筛选参数。
|
|
8
8
|
|
|
9
|
-
运行 `npx --yes personal-bot@0.3.
|
|
9
|
+
运行 `npx --yes personal-bot@0.3.4 <子命令> --workspace "<workspaceRoot>"`。如果 `pbot --at-least 0.3.4` 返回 0,也可以用 `pbot` 执行同一条命令。返回实际结果。
|
|
@@ -45,6 +45,9 @@ export function parseSetupArgs(args) {
|
|
|
45
45
|
return { action: "help" };
|
|
46
46
|
if (args.length === 1 && ["--version", "-v"].includes(args[0]))
|
|
47
47
|
return { action: "version" };
|
|
48
|
+
if (args[0] === "upgrade" || args[0] === "update") {
|
|
49
|
+
return { action: "upgrade", upgradeArgs: args.slice(1), upgradeVerb: args[0] };
|
|
50
|
+
}
|
|
48
51
|
if (args[0] === "install-antigravity") {
|
|
49
52
|
if (args.length === 1)
|
|
50
53
|
return { action: "install-antigravity" };
|
|
@@ -62,7 +65,7 @@ export function parseSetupArgs(args) {
|
|
|
62
65
|
throw new Error("用法:pbot mcp [list|add|remove ...]");
|
|
63
66
|
}
|
|
64
67
|
if (args[0] !== "setup")
|
|
65
|
-
throw new Error("用法:pbot setup [--workspace <目录>] | pbot install-antigravity | pbot mcp [list|add|remove ...]");
|
|
68
|
+
throw new Error("用法:pbot setup [--workspace <目录>] | pbot upgrade|update [--workspace <目录>] | pbot install-antigravity | pbot mcp [list|add|remove ...]");
|
|
66
69
|
let workspace;
|
|
67
70
|
for (let index = 1; index < args.length; index++) {
|
|
68
71
|
const arg = args[index];
|
|
@@ -0,0 +1,95 @@
|
|
|
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
|
+
}
|
|
@@ -1,3 +1,15 @@
|
|
|
1
1
|
/** Each host owns its file, including when two hosts activate the same canonical workspace concurrently. */
|
|
2
2
|
export declare function bindWorkspacePlugin(root: string, host: string, binding?: string): void;
|
|
3
|
+
export interface WorkspacePluginBinding {
|
|
4
|
+
version: string;
|
|
5
|
+
bindingPath?: string;
|
|
6
|
+
}
|
|
7
|
+
export interface WorkspacePluginDrift {
|
|
8
|
+
outOfSync: boolean;
|
|
9
|
+
highest?: string;
|
|
10
|
+
lowest?: string;
|
|
11
|
+
versions: Record<string, string>;
|
|
12
|
+
}
|
|
13
|
+
export declare function workspacePluginBindings(root: string): Record<string, WorkspacePluginBinding>;
|
|
3
14
|
export declare function workspacePluginReleases(root: string): Record<string, string>;
|
|
15
|
+
export declare function workspacePluginDrift(releases: Record<string, string>): WorkspacePluginDrift;
|
|
@@ -7,6 +7,31 @@ import { resourceRoot } from "../../common/paths.js";
|
|
|
7
7
|
import { requireThat } from "../../common/validation.js";
|
|
8
8
|
import { releaseLine } from "../../common/version.js";
|
|
9
9
|
import { readJsonFile, writeJsonFile } from "../../storage/atomic-json.js";
|
|
10
|
+
function compareSemver(a, b) {
|
|
11
|
+
const parse = (value) => {
|
|
12
|
+
const match = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-([0-9A-Za-z.-]+))?/.exec(value);
|
|
13
|
+
return match
|
|
14
|
+
? { major: Number(match[1]), minor: Number(match[2]), patch: Number(match[3]), pre: match[4] ?? "" }
|
|
15
|
+
: undefined;
|
|
16
|
+
};
|
|
17
|
+
const left = parse(a);
|
|
18
|
+
const right = parse(b);
|
|
19
|
+
if (!left || !right)
|
|
20
|
+
return a.localeCompare(b);
|
|
21
|
+
if (left.major !== right.major)
|
|
22
|
+
return left.major - right.major;
|
|
23
|
+
if (left.minor !== right.minor)
|
|
24
|
+
return left.minor - right.minor;
|
|
25
|
+
if (left.patch !== right.patch)
|
|
26
|
+
return left.patch - right.patch;
|
|
27
|
+
if (left.pre === right.pre)
|
|
28
|
+
return 0;
|
|
29
|
+
if (!left.pre)
|
|
30
|
+
return 1;
|
|
31
|
+
if (!right.pre)
|
|
32
|
+
return -1;
|
|
33
|
+
return left.pre.localeCompare(right.pre);
|
|
34
|
+
}
|
|
10
35
|
function bindingDirectory(root) {
|
|
11
36
|
const key = createHash("sha256").update(root).digest("hex");
|
|
12
37
|
return join(homedir(), ".pbot", "workspaces", key);
|
|
@@ -44,7 +69,7 @@ export function bindWorkspacePlugin(root, host, binding = resolve(resourceRoot,
|
|
|
44
69
|
throw error;
|
|
45
70
|
}
|
|
46
71
|
}
|
|
47
|
-
export function
|
|
72
|
+
export function workspacePluginBindings(root) {
|
|
48
73
|
const directory = bindingDirectory(root);
|
|
49
74
|
let files;
|
|
50
75
|
try {
|
|
@@ -55,24 +80,47 @@ export function workspacePluginReleases(root) {
|
|
|
55
80
|
return {};
|
|
56
81
|
throw error;
|
|
57
82
|
}
|
|
58
|
-
const
|
|
83
|
+
const bindings = Object.create(null);
|
|
59
84
|
for (const file of files.filter(name => name.endsWith(".json"))) {
|
|
60
85
|
const host = decodeURIComponent(file.slice(0, -5));
|
|
61
86
|
try {
|
|
62
87
|
const binding = readJsonFile(directory, file, pluginBinding);
|
|
63
88
|
if (!isAbsolute(binding)) {
|
|
64
|
-
|
|
89
|
+
bindings[host] = { version: binding };
|
|
65
90
|
continue;
|
|
66
91
|
}
|
|
67
92
|
const manifest = JSON.parse(readFileSync(binding, "utf8"));
|
|
68
93
|
requireThat(object(manifest) && typeof manifest.version === "string", "无效的插件安装清单:" + binding);
|
|
69
94
|
releaseLine(manifest.version);
|
|
70
|
-
|
|
95
|
+
bindings[host] = { version: manifest.version, bindingPath: binding };
|
|
71
96
|
}
|
|
72
97
|
catch (error) {
|
|
73
98
|
if (error.code !== "ENOENT" && !permissionDenied(error))
|
|
74
99
|
throw error;
|
|
75
100
|
}
|
|
76
101
|
}
|
|
102
|
+
return bindings;
|
|
103
|
+
}
|
|
104
|
+
export function workspacePluginReleases(root) {
|
|
105
|
+
const bindings = workspacePluginBindings(root);
|
|
106
|
+
const releases = Object.create(null);
|
|
107
|
+
for (const [host, entry] of Object.entries(bindings))
|
|
108
|
+
releases[host] = entry.version;
|
|
77
109
|
return releases;
|
|
78
110
|
}
|
|
111
|
+
export function workspacePluginDrift(releases) {
|
|
112
|
+
let highest;
|
|
113
|
+
let lowest;
|
|
114
|
+
for (const version of Object.values(releases)) {
|
|
115
|
+
if (!highest || compareSemver(version, highest) > 0)
|
|
116
|
+
highest = version;
|
|
117
|
+
if (!lowest || compareSemver(version, lowest) < 0)
|
|
118
|
+
lowest = version;
|
|
119
|
+
}
|
|
120
|
+
return {
|
|
121
|
+
outOfSync: Boolean(highest && lowest && highest !== lowest),
|
|
122
|
+
...(highest ? { highest } : {}),
|
|
123
|
+
...(lowest ? { lowest } : {}),
|
|
124
|
+
versions: releases,
|
|
125
|
+
};
|
|
126
|
+
}
|
package/package.json
CHANGED
|
@@ -6,7 +6,7 @@ import { loadWorkspaceContext } from "../../integrations/agent-resources.js";
|
|
|
6
6
|
import type { PluginHostAdapter } from "../../model/plugin-host.js";
|
|
7
7
|
import { recordHistoryCapture } from "../../services/history/history-capture.js";
|
|
8
8
|
import { historyStartupNotices } from "../../services/history/summary-runner.js";
|
|
9
|
-
import { bindWorkspacePlugin } from "../../services/workspace/plugin-releases.js";
|
|
9
|
+
import { bindWorkspacePlugin, workspacePluginDrift, workspacePluginReleases } from "../../services/workspace/plugin-releases.js";
|
|
10
10
|
import { readWorkspaceConfig, workspaceFeatures } from "../../services/workspace/workspace-config.js";
|
|
11
11
|
import { initializeWorkspace } from "../../services/workspace/workspace-preparation.js";
|
|
12
12
|
import { discoverSkills, discoverWorkspaceSkills } from "../../services/workspace/workspace-skills.js";
|
|
@@ -79,7 +79,14 @@ export async function pluginHook(adapter: PluginHostAdapter, payload: unknown, r
|
|
|
79
79
|
const directory = join(resourceRoot, "skills");
|
|
80
80
|
workspaceSkills.push(...await discoverSkills(directory, directory));
|
|
81
81
|
}
|
|
82
|
-
const notices = event.isSessionStart && features.history ? historyStartupNotices(root) : [];
|
|
82
|
+
const notices = event.isSessionStart && features.history ? [...historyStartupNotices(root)] : [];
|
|
83
|
+
if (event.isSessionStart) {
|
|
84
|
+
const drift = workspacePluginDrift(workspacePluginReleases(root));
|
|
85
|
+
if (drift.outOfSync) {
|
|
86
|
+
const summary = Object.entries(drift.versions).map(([host, version]) => `${host}=${version}`).join(", ");
|
|
87
|
+
notices.push(`检测到当前工作区各宿主 Personal Bot 插件版本不一致(${summary}),可在终端运行 pbot upgrade 统一升级。`);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
83
90
|
if (!includePrompts && !workspaceSkills.length && !notices.length) return adapter.formatPass(payload);
|
|
84
91
|
const context = await loadWorkspaceContext({
|
|
85
92
|
host: adapter.host,
|
|
@@ -17,6 +17,7 @@ import {
|
|
|
17
17
|
upsertWorkspaceMcpServer,
|
|
18
18
|
} from "../../services/workspace/workspace-mcp.js";
|
|
19
19
|
import { SetupUI } from "../../ui/setup.js";
|
|
20
|
+
import { runUpgradeCommand } from "./upgrade.js";
|
|
20
21
|
|
|
21
22
|
const root = new URL("../../../", import.meta.url);
|
|
22
23
|
const quote = (value: string) => "'" + value.replaceAll("'", "'\\''") + "'";
|
|
@@ -168,6 +169,7 @@ export async function main(args: string[]): Promise<number> {
|
|
|
168
169
|
if (options.action === "help") {
|
|
169
170
|
console.log("Personal Bot " + manifest.version + "\n\n用法:pbot setup [--workspace <目录>]\n" +
|
|
170
171
|
" npx personal-bot@latest setup\n" +
|
|
172
|
+
" pbot upgrade|update [--workspace <目录>] [--version <版本>] [--hosts <列表>] [--dsh-profile <名称>] [--json]\n" +
|
|
171
173
|
" pbot init | status [--workspace <目录>] [--json]\n" +
|
|
172
174
|
" pbot history status|list|summary|migrate|search|read [参数] [--workspace <目录>] [--json]\n" +
|
|
173
175
|
" pbot install-antigravity\n" +
|
|
@@ -175,11 +177,16 @@ export async function main(args: string[]): Promise<number> {
|
|
|
175
177
|
" pbot mcp\n" +
|
|
176
178
|
" pbot mcp list|add|remove ...\n\n" +
|
|
177
179
|
"setup 安装或升级 Pi、pbot 和选中的插件,然后启动 Pi 执行 /pbot init。\n" +
|
|
180
|
+
"upgrade|update 将全局 CLI 与当前工作区已绑定的各宿主插件统一升级到 npm 最新稳定版。\n" +
|
|
178
181
|
"install-antigravity 通过原生 agy plugin install 安装或更新 Antigravity 插件。\n" +
|
|
179
182
|
"mcp 无参数时启动统一 stdio MCP 服务(暴露 worker_* 与 workspace_mcp_*);带 list/add/remove 时管理工作区 .pbot/mcp.json。\n" +
|
|
180
183
|
"支持 Linux/macOS,需要 Node.js 22.19+ 和 npm。\n--help 显示帮助;--version 显示安装器版本。");
|
|
181
184
|
return 0;
|
|
182
185
|
}
|
|
186
|
+
if (options.action === "upgrade") {
|
|
187
|
+
try { return await runUpgradeCommand(options.upgradeArgs ?? [], options.upgradeVerb ?? "upgrade"); }
|
|
188
|
+
catch (error) { console.error(error instanceof Error ? error.message : String(error)); return 2; }
|
|
189
|
+
}
|
|
183
190
|
if (options.action === "mcp-manage") {
|
|
184
191
|
try { return await runMcpManage(options.mcpArgs ?? []); }
|
|
185
192
|
catch (error) { console.error(error instanceof Error ? error.message : String(error)); return 2; }
|