personal-bot 0.3.3 → 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/README.md +2 -2
- package/README.zh-CN.md +2 -2
- package/bin/pbot.mjs +3 -17
- package/docs/architecture/design.md +8 -6
- package/docs/architecture/extensibility.md +21 -0
- package/docs/architecture/principles.md +1 -1
- package/docs/guides/workspace-configuration.md +13 -0
- 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/hosts/plugin-runtime.js +9 -2
- package/lib/antigravity-plugin/lib/extension/mcp.js +22 -20
- package/lib/antigravity-plugin/lib/extension/workspace-cli.js +5 -20121
- 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/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/hosts/plugin-runtime.js +9 -2
- package/lib/extension/mcp.js +22 -20
- package/lib/extension/workspace-cli.js +5 -20121
- 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/workspace/plugin-releases.d.ts +12 -0
- package/lib/services/workspace/plugin-releases.js +52 -4
- 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/extension/hosts/plugin-runtime.ts +9 -2
- package/src/integrations/installation/cli-update.ts +31 -3
- package/src/integrations/installation/pi-setup.ts +6 -3
- 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 +0 -30
- package/src/services/installation/upgrade-service.ts +127 -0
- package/src/services/workspace/plugin-releases.ts +57 -4
- package/lib/extension/setup/cli.js +0 -352
- package/lib/integrations/installation/pi-setup.js +0 -193
- package/lib/integrations/installation/processes.js +0 -140
- package/lib/integrations/installation/workspace.js +0 -21
- package/lib/services/installation/setup-service.js +0 -137
- package/lib/ui/setup.js +0 -52
- package/src/extension/setup/cli.ts +0 -296
- package/src/extension/setup/workspace-cli.ts +0 -159
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { execFile, spawn } from "node:child_process";
|
|
2
2
|
import { lstat, mkdir, readFile, realpath, rmdir } from "node:fs/promises";
|
|
3
3
|
import { homedir } from "node:os";
|
|
4
|
-
import { dirname, join
|
|
4
|
+
import { dirname, join } from "node:path";
|
|
5
5
|
import { promisify } from "node:util";
|
|
6
6
|
import { gt, lt, valid } from "semver";
|
|
7
7
|
import { object } from "../../common/json.js";
|
|
8
|
-
import {
|
|
8
|
+
import { packageRoot } from "../../common/paths.js";
|
|
9
9
|
import { requireThat } from "../../common/validation.js";
|
|
10
10
|
import { packageVersion } from "../../common/version.js";
|
|
11
11
|
|
|
@@ -60,7 +60,7 @@ async function globalPackage(): Promise<string | undefined> {
|
|
|
60
60
|
const directory = join(stdout.trim(), "personal-bot");
|
|
61
61
|
try {
|
|
62
62
|
// An npm link points at a development checkout; keep updates out of that checkout.
|
|
63
|
-
if ((await lstat(directory)).isDirectory() && await realpath(directory) === await realpath(
|
|
63
|
+
if ((await lstat(directory)).isDirectory() && await realpath(directory) === await realpath(packageRoot)) return directory;
|
|
64
64
|
} catch (error) {
|
|
65
65
|
if ((error as NodeJS.ErrnoException).code !== "ENOENT") throw error;
|
|
66
66
|
}
|
|
@@ -95,6 +95,34 @@ async function upgradeGlobal(directory: string, required: string, env: NodeJS.Pr
|
|
|
95
95
|
}
|
|
96
96
|
}
|
|
97
97
|
|
|
98
|
+
export async function upgradeManagedGlobalCli(required: string, env: NodeJS.ProcessEnv = process.env): Promise<{
|
|
99
|
+
state: "updated" | "up-to-date" | "skipped" | "failed";
|
|
100
|
+
globalDirectory?: string;
|
|
101
|
+
exitCode?: number;
|
|
102
|
+
detail: string;
|
|
103
|
+
}> {
|
|
104
|
+
requireThat(valid(required) && /^[0-9]/.test(required) && required === required.trim(), "无效的插件发布版本:" + required);
|
|
105
|
+
if (!lt(packageVersion, required)) {
|
|
106
|
+
return { state: "up-to-date", detail: `CLI 已是 ${packageVersion}。` };
|
|
107
|
+
}
|
|
108
|
+
const global = await globalPackage();
|
|
109
|
+
if (!global) {
|
|
110
|
+
return { state: "skipped", detail: `当前运行的是本地或非全局安装(${packageVersion}),跳过全局 CLI 覆盖。` };
|
|
111
|
+
}
|
|
112
|
+
const status = await upgradeGlobal(global, required, env);
|
|
113
|
+
if (status === undefined) {
|
|
114
|
+
return { state: "skipped", globalDirectory: global, detail: "全局 npm 目录不可写或正被其他进程更新,已跳过全局 CLI 覆盖。" };
|
|
115
|
+
}
|
|
116
|
+
if (status !== 0) {
|
|
117
|
+
return { state: "failed", globalDirectory: global, exitCode: status, detail: `npm 更新全局 personal-bot@${required} 失败(退出码 ${status})。` };
|
|
118
|
+
}
|
|
119
|
+
return { state: "updated", globalDirectory: global, detail: `已将全局 CLI 从 ${packageVersion} 更新到 ${required}。` };
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export function execCliEntry(entry: string, args: readonly string[], env: NodeJS.ProcessEnv = process.env): Promise<number> {
|
|
123
|
+
return runProgram(process.execPath, [entry, ...args], env, false);
|
|
124
|
+
}
|
|
125
|
+
|
|
98
126
|
/** Upgrade managed global installs in place. Project, npx and linked installs use npm's shared version cache. */
|
|
99
127
|
export async function runUpdatedCli(required: string | undefined, args: readonly string[], input?: string): Promise<number | undefined> {
|
|
100
128
|
if (!required) return undefined;
|
|
@@ -1,16 +1,19 @@
|
|
|
1
1
|
import { access, readFile, realpath } from "node:fs/promises";
|
|
2
|
-
import { constants } from "node:fs";
|
|
2
|
+
import { constants, existsSync } from "node:fs";
|
|
3
3
|
import { dirname, join, resolve } from "node:path";
|
|
4
4
|
import { homedir } from "node:os";
|
|
5
5
|
import { fileURLToPath } from "node:url";
|
|
6
6
|
import { checkStableVersion, npmName } from "../../common/package-source.js";
|
|
7
|
+
import { packageRoot as pbotPackageRoot } from "../../common/paths.js";
|
|
7
8
|
import type { InstalledPackage, PackageChoice, PiInstallation, SetupOperations, SystemCommand } from "../../model/installation.js";
|
|
8
9
|
import { findExecutable, npmGlobalBinary, SetupProcesses } from "./processes.js";
|
|
9
10
|
|
|
10
11
|
export const piPackageName = "@earendil-works/pi-coding-agent";
|
|
11
12
|
export class PiBootstrapRequired extends Error {}
|
|
12
|
-
const
|
|
13
|
-
const
|
|
13
|
+
const localBridge = fileURLToPath(new URL("./pi-bridge.js", import.meta.url));
|
|
14
|
+
const bridge = existsSync(localBridge) ? localBridge : join(pbotPackageRoot, "lib/integrations/installation/pi-bridge.js");
|
|
15
|
+
const localGuard = fileURLToPath(new URL("../../extension/setup/guard.js", import.meta.url));
|
|
16
|
+
const guard = existsSync(localGuard) ? localGuard : join(pbotPackageRoot, "lib/extension/setup/guard.js");
|
|
14
17
|
|
|
15
18
|
async function packageRoot(command: string, version: string, env: NodeJS.ProcessEnv): Promise<string> {
|
|
16
19
|
const resolved = await realpath(command);
|
|
@@ -0,0 +1,68 @@
|
|
|
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
|
+
import type { HostUpgradeContext, HostUpgradeResult, HostUpgrader } from "../../../model/installation.js";
|
|
6
|
+
|
|
7
|
+
async function readManifestVersion(path: string): Promise<string | undefined> {
|
|
8
|
+
try {
|
|
9
|
+
const data: unknown = JSON.parse(await readFile(path, "utf8"));
|
|
10
|
+
return object(data) && typeof data.version === "string" && valid(data.version) ? data.version : undefined;
|
|
11
|
+
} catch (error) {
|
|
12
|
+
if ((error as NodeJS.ErrnoException).code === "ENOENT") return undefined;
|
|
13
|
+
throw error;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export const antigravityUpgrader: HostUpgrader = {
|
|
18
|
+
host: "antigravity",
|
|
19
|
+
async upgrade(context: HostUpgradeContext): Promise<HostUpgradeResult> {
|
|
20
|
+
if (context.currentVersion && valid(context.currentVersion) && gte(context.currentVersion, context.targetVersion)) {
|
|
21
|
+
return {
|
|
22
|
+
host: this.host,
|
|
23
|
+
state: "up-to-date",
|
|
24
|
+
previousVersion: context.currentVersion,
|
|
25
|
+
version: context.currentVersion,
|
|
26
|
+
scope: "user",
|
|
27
|
+
detail: "已是最新版本。",
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
const pluginDir = join(context.packageRoot, "lib", "antigravity-plugin");
|
|
31
|
+
const bundledVersion = await readManifestVersion(join(pluginDir, "plugin.json"));
|
|
32
|
+
if (!bundledVersion) {
|
|
33
|
+
return {
|
|
34
|
+
host: this.host,
|
|
35
|
+
state: "skipped",
|
|
36
|
+
...(context.currentVersion ? { previousVersion: context.currentVersion } : {}),
|
|
37
|
+
detail: `缺少 Antigravity 插件构建产物:${pluginDir}`,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
if (lt(bundledVersion, context.targetVersion)) {
|
|
41
|
+
return {
|
|
42
|
+
host: this.host,
|
|
43
|
+
state: "skipped",
|
|
44
|
+
...(context.currentVersion ? { previousVersion: context.currentVersion } : {}),
|
|
45
|
+
detail: `当前本地包产物版本为 ${bundledVersion},低于目标版本 ${context.targetVersion};请先更新全局 personal-bot 包。`,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
const agy = context.env.PBOT_AGY_COMMAND || await context.findExecutable("agy");
|
|
49
|
+
if (!agy) {
|
|
50
|
+
return {
|
|
51
|
+
host: this.host,
|
|
52
|
+
state: "skipped",
|
|
53
|
+
...(context.currentVersion ? { previousVersion: context.currentVersion } : {}),
|
|
54
|
+
detail: "未找到 Antigravity CLI(agy),已跳过。",
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
await context.run(agy, ["plugin", "install", pluginDir], context.workspace);
|
|
58
|
+
return {
|
|
59
|
+
host: this.host,
|
|
60
|
+
state: "updated",
|
|
61
|
+
...(context.currentVersion ? { previousVersion: context.currentVersion } : {}),
|
|
62
|
+
version: bundledVersion,
|
|
63
|
+
scope: "user",
|
|
64
|
+
detail: `已通过 agy plugin install 更新到 ${bundledVersion}。`,
|
|
65
|
+
nextStep: "重启 Antigravity 会话使新版本生效。",
|
|
66
|
+
};
|
|
67
|
+
},
|
|
68
|
+
};
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { realpath } from "node:fs/promises";
|
|
2
|
+
import { gte, valid } from "semver";
|
|
3
|
+
import { object } from "../../../common/json.js";
|
|
4
|
+
import type { HostUpgradeContext, HostUpgradeResult, HostUpgrader } from "../../../model/installation.js";
|
|
5
|
+
|
|
6
|
+
interface ClaudePluginEntry {
|
|
7
|
+
id: string;
|
|
8
|
+
version?: string;
|
|
9
|
+
scope?: string;
|
|
10
|
+
projectPath?: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function parsePluginList(raw: string): ClaudePluginEntry[] {
|
|
14
|
+
const parsed: unknown = JSON.parse(raw);
|
|
15
|
+
const items = Array.isArray(parsed)
|
|
16
|
+
? parsed
|
|
17
|
+
: object(parsed) && Array.isArray(parsed.plugins)
|
|
18
|
+
? parsed.plugins
|
|
19
|
+
: [];
|
|
20
|
+
const entries: ClaudePluginEntry[] = [];
|
|
21
|
+
for (const item of items) {
|
|
22
|
+
if (!object(item)) continue;
|
|
23
|
+
const id = typeof item.id === "string" ? item.id : typeof item.name === "string" ? item.name : undefined;
|
|
24
|
+
if (!id) continue;
|
|
25
|
+
entries.push({
|
|
26
|
+
id,
|
|
27
|
+
...(typeof item.version === "string" ? { version: item.version } : {}),
|
|
28
|
+
...(typeof item.scope === "string" ? { scope: item.scope } : {}),
|
|
29
|
+
...(typeof item.projectPath === "string" ? { projectPath: item.projectPath } : {}),
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
return entries;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
async function resolvePathSafe(value: string): Promise<string> {
|
|
36
|
+
try { return await realpath(value); } catch { return value; }
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
async function selectMatchingEntry(entries: ClaudePluginEntry[], workspace: string): Promise<ClaudePluginEntry | undefined> {
|
|
40
|
+
const canonicalWorkspace = await resolvePathSafe(workspace);
|
|
41
|
+
const candidates = entries.filter(entry => entry.id === "personal-bot" || entry.id.startsWith("personal-bot@"));
|
|
42
|
+
if (!candidates.length) return undefined;
|
|
43
|
+
const scopedMatches: ClaudePluginEntry[] = [];
|
|
44
|
+
for (const entry of candidates) {
|
|
45
|
+
if (!entry.projectPath) {
|
|
46
|
+
scopedMatches.push(entry);
|
|
47
|
+
continue;
|
|
48
|
+
}
|
|
49
|
+
if (await resolvePathSafe(entry.projectPath) === canonicalWorkspace) scopedMatches.push(entry);
|
|
50
|
+
}
|
|
51
|
+
const priority = new Map<string, number>([["local", 0], ["project", 1], ["user", 2]]);
|
|
52
|
+
scopedMatches.sort((a, b) => (priority.get(a.scope ?? "") ?? 9) - (priority.get(b.scope ?? "") ?? 9));
|
|
53
|
+
return scopedMatches[0];
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export const claudeUpgrader: HostUpgrader = {
|
|
57
|
+
host: "claude",
|
|
58
|
+
async upgrade(context: HostUpgradeContext): Promise<HostUpgradeResult> {
|
|
59
|
+
const claude = context.env.PBOT_CLAUDE_COMMAND || await context.findExecutable("claude");
|
|
60
|
+
if (!claude) {
|
|
61
|
+
return {
|
|
62
|
+
host: this.host,
|
|
63
|
+
state: "skipped",
|
|
64
|
+
...(context.currentVersion ? { previousVersion: context.currentVersion } : {}),
|
|
65
|
+
detail: "未找到 Claude Code CLI(claude),已跳过。",
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
let entries: ClaudePluginEntry[];
|
|
69
|
+
try {
|
|
70
|
+
const raw = await context.run(claude, ["plugin", "list", "--json"], context.workspace);
|
|
71
|
+
entries = parsePluginList(raw);
|
|
72
|
+
} catch (error) {
|
|
73
|
+
return {
|
|
74
|
+
host: this.host,
|
|
75
|
+
state: "failed",
|
|
76
|
+
...(context.currentVersion ? { previousVersion: context.currentVersion } : {}),
|
|
77
|
+
detail: `查询 Claude 插件列表失败:${error instanceof Error ? error.message : String(error)}`,
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
const entry = await selectMatchingEntry(entries, context.workspace);
|
|
81
|
+
if (!entry) {
|
|
82
|
+
return {
|
|
83
|
+
host: this.host,
|
|
84
|
+
state: "skipped",
|
|
85
|
+
...(context.currentVersion ? { previousVersion: context.currentVersion } : {}),
|
|
86
|
+
detail: "未在 Claude 插件列表中找到 personal-bot(可能通过 --plugin-dir 本地加载),已跳过。",
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
const installedVersion = entry.version ?? context.currentVersion;
|
|
90
|
+
const scope = entry.scope ?? "user";
|
|
91
|
+
if (installedVersion && valid(installedVersion) && gte(installedVersion, context.targetVersion)) {
|
|
92
|
+
return {
|
|
93
|
+
host: this.host,
|
|
94
|
+
state: "up-to-date",
|
|
95
|
+
previousVersion: installedVersion,
|
|
96
|
+
version: installedVersion,
|
|
97
|
+
scope,
|
|
98
|
+
detail: "已是最新版本。",
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
const atIndex = entry.id.indexOf("@");
|
|
102
|
+
const marketplace = atIndex > 0 ? entry.id.slice(atIndex + 1) : undefined;
|
|
103
|
+
if (marketplace) {
|
|
104
|
+
try {
|
|
105
|
+
await context.run(claude, ["plugin", "marketplace", "update", marketplace], context.workspace);
|
|
106
|
+
} catch {
|
|
107
|
+
// Continue to plugin update even if marketplace refresh is unsupported or cached.
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
const updateArgs = ["plugin", "update", entry.id, "--yes"];
|
|
111
|
+
if (entry.scope) updateArgs.push("--scope", entry.scope);
|
|
112
|
+
await context.run(claude, updateArgs, context.workspace);
|
|
113
|
+
return {
|
|
114
|
+
host: this.host,
|
|
115
|
+
state: "updated",
|
|
116
|
+
...(installedVersion ? { previousVersion: installedVersion } : {}),
|
|
117
|
+
version: context.targetVersion,
|
|
118
|
+
scope,
|
|
119
|
+
detail: `已按原有作用域(${scope})更新 ${entry.id}。`,
|
|
120
|
+
nextStep: "重启 Claude Code 会话使新版本生效。",
|
|
121
|
+
};
|
|
122
|
+
},
|
|
123
|
+
};
|
|
@@ -0,0 +1,73 @@
|
|
|
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
|
+
import type { HostUpgradeContext, HostUpgradeResult, HostUpgrader } from "../../../model/installation.js";
|
|
6
|
+
|
|
7
|
+
async function readManifestVersion(path: string): Promise<string | undefined> {
|
|
8
|
+
try {
|
|
9
|
+
const data: unknown = JSON.parse(await readFile(path, "utf8"));
|
|
10
|
+
return object(data) && typeof data.version === "string" && valid(data.version) ? data.version : undefined;
|
|
11
|
+
} catch (error) {
|
|
12
|
+
if ((error as NodeJS.ErrnoException).code === "ENOENT") return undefined;
|
|
13
|
+
throw error;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export const codexUpgrader: HostUpgrader = {
|
|
18
|
+
host: "codex",
|
|
19
|
+
async upgrade(context: HostUpgradeContext): Promise<HostUpgradeResult> {
|
|
20
|
+
if (context.currentVersion && valid(context.currentVersion) && gte(context.currentVersion, context.targetVersion)) {
|
|
21
|
+
return {
|
|
22
|
+
host: this.host,
|
|
23
|
+
state: "up-to-date",
|
|
24
|
+
previousVersion: context.currentVersion,
|
|
25
|
+
version: context.currentVersion,
|
|
26
|
+
scope: "user",
|
|
27
|
+
detail: "已是最新版本。",
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
const marketplaceDir = join(context.packageRoot, "lib", "codex-marketplace");
|
|
31
|
+
const bundledVersion = await readManifestVersion(join(marketplaceDir, "plugins", "personal-bot", ".codex-plugin", "plugin.json"));
|
|
32
|
+
if (!bundledVersion) {
|
|
33
|
+
return {
|
|
34
|
+
host: this.host,
|
|
35
|
+
state: "skipped",
|
|
36
|
+
...(context.currentVersion ? { previousVersion: context.currentVersion } : {}),
|
|
37
|
+
detail: `缺少 Codex 插件构建产物:${marketplaceDir}`,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
if (lt(bundledVersion, context.targetVersion)) {
|
|
41
|
+
return {
|
|
42
|
+
host: this.host,
|
|
43
|
+
state: "skipped",
|
|
44
|
+
...(context.currentVersion ? { previousVersion: context.currentVersion } : {}),
|
|
45
|
+
detail: `当前本地包产物版本为 ${bundledVersion},低于目标版本 ${context.targetVersion};请先更新全局 personal-bot 包。`,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
const codex = context.env.PBOT_CODEX_COMMAND || await context.findExecutable("codex");
|
|
49
|
+
if (!codex) {
|
|
50
|
+
return {
|
|
51
|
+
host: this.host,
|
|
52
|
+
state: "skipped",
|
|
53
|
+
...(context.currentVersion ? { previousVersion: context.currentVersion } : {}),
|
|
54
|
+
detail: "未找到 Codex CLI(codex),已跳过。",
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
try {
|
|
58
|
+
await context.run(codex, ["plugin", "marketplace", "add", marketplaceDir], context.workspace);
|
|
59
|
+
} catch {
|
|
60
|
+
// Marketplace may already be registered; proceed to re-install the plugin from it.
|
|
61
|
+
}
|
|
62
|
+
await context.run(codex, ["plugin", "add", "personal-bot@pbot-local"], context.workspace);
|
|
63
|
+
return {
|
|
64
|
+
host: this.host,
|
|
65
|
+
state: "updated",
|
|
66
|
+
...(context.currentVersion ? { previousVersion: context.currentVersion } : {}),
|
|
67
|
+
version: bundledVersion,
|
|
68
|
+
scope: "user",
|
|
69
|
+
detail: `已通过 codex plugin add 更新到 ${bundledVersion}。`,
|
|
70
|
+
nextStep: "重启 Codex 会话;若 hooks 有变化,请在 Codex /hooks 中重新核对信任。",
|
|
71
|
+
};
|
|
72
|
+
},
|
|
73
|
+
};
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { gte, valid } from "semver";
|
|
2
|
+
import type { HostUpgradeContext, HostUpgradeResult, HostUpgrader } from "../../../model/installation.js";
|
|
3
|
+
|
|
4
|
+
export function inferDshProfile(bindingPath?: string): string | undefined {
|
|
5
|
+
if (!bindingPath) return undefined;
|
|
6
|
+
const normalized = bindingPath.replaceAll("\\", "/");
|
|
7
|
+
const match = /\/profiles\/([^/]+)\/node_modules\/personal-bot\/package\.json$/.exec(normalized);
|
|
8
|
+
return match?.[1];
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export const dshUpgrader: HostUpgrader = {
|
|
12
|
+
host: "dsh",
|
|
13
|
+
async upgrade(context: HostUpgradeContext): Promise<HostUpgradeResult> {
|
|
14
|
+
if (context.currentVersion && valid(context.currentVersion) && gte(context.currentVersion, context.targetVersion)) {
|
|
15
|
+
return {
|
|
16
|
+
host: this.host,
|
|
17
|
+
state: "up-to-date",
|
|
18
|
+
previousVersion: context.currentVersion,
|
|
19
|
+
version: context.currentVersion,
|
|
20
|
+
detail: "已是最新版本。",
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
const profile = context.options.dshProfile || inferDshProfile(context.bindingPath);
|
|
24
|
+
if (!profile) {
|
|
25
|
+
return {
|
|
26
|
+
host: this.host,
|
|
27
|
+
state: "skipped",
|
|
28
|
+
...(context.currentVersion ? { previousVersion: context.currentVersion } : {}),
|
|
29
|
+
detail: "无法自动识别 dsh profile;请传入 --dsh-profile <名称> 或手动执行:dsh plugin --profile <名称> update personal-bot --latest",
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
const dsh = context.env.PBOT_DSH_COMMAND || await context.findExecutable("dsh");
|
|
33
|
+
if (!dsh) {
|
|
34
|
+
return {
|
|
35
|
+
host: this.host,
|
|
36
|
+
state: "skipped",
|
|
37
|
+
...(context.currentVersion ? { previousVersion: context.currentVersion } : {}),
|
|
38
|
+
scope: `profile:${profile}`,
|
|
39
|
+
detail: "未找到 dsh CLI(dsh),已跳过。",
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
try {
|
|
43
|
+
await context.run(dsh, ["plugin", "--profile", profile, "update", "personal-bot", "--latest"], context.workspace);
|
|
44
|
+
} catch (error) {
|
|
45
|
+
return {
|
|
46
|
+
host: this.host,
|
|
47
|
+
state: "failed",
|
|
48
|
+
...(context.currentVersion ? { previousVersion: context.currentVersion } : {}),
|
|
49
|
+
scope: `profile:${profile}`,
|
|
50
|
+
detail: `${error instanceof Error ? error.message : String(error)}(提示:更新 dsh 插件前需先停止对应 profile 的 dsh 服务)`,
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
return {
|
|
54
|
+
host: this.host,
|
|
55
|
+
state: "updated",
|
|
56
|
+
...(context.currentVersion ? { previousVersion: context.currentVersion } : {}),
|
|
57
|
+
version: context.targetVersion,
|
|
58
|
+
scope: `profile:${profile}`,
|
|
59
|
+
detail: `已更新 dsh profile "${profile}" 中的 personal-bot。`,
|
|
60
|
+
nextStep: `重新启动 dsh --profile ${profile} 使新版本生效。`,
|
|
61
|
+
};
|
|
62
|
+
},
|
|
63
|
+
};
|
|
@@ -0,0 +1,87 @@
|
|
|
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
|
+
import type { HostUpgradeContext, HostUpgradeResult, HostUpgrader } from "../../../model/installation.js";
|
|
7
|
+
|
|
8
|
+
function packageSource(entry: unknown): string | undefined {
|
|
9
|
+
if (typeof entry === "string") return entry;
|
|
10
|
+
if (object(entry) && typeof entry.source === "string") return entry.source;
|
|
11
|
+
return undefined;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
async function hasCustomOnlySource(workspace: string): Promise<boolean> {
|
|
15
|
+
const settingsPath = join(workspace, ".pi", "settings.json");
|
|
16
|
+
try {
|
|
17
|
+
const data: unknown = JSON.parse(await readFile(settingsPath, "utf8"));
|
|
18
|
+
if (!object(data) || !Array.isArray(data.packages)) return false;
|
|
19
|
+
const sources = data.packages.map(packageSource).filter((value): value is string => value !== undefined);
|
|
20
|
+
const matches = sources.filter(source => source.includes("personal-bot"));
|
|
21
|
+
if (!matches.length) return false;
|
|
22
|
+
return matches.every(source => npmName(source) !== "personal-bot");
|
|
23
|
+
} catch (error) {
|
|
24
|
+
if ((error as NodeJS.ErrnoException).code === "ENOENT") return false;
|
|
25
|
+
throw error;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
async function readLocalPiVersion(workspace: string): Promise<string | undefined> {
|
|
30
|
+
const manifestPath = join(workspace, ".pi", "npm", "node_modules", "personal-bot", "package.json");
|
|
31
|
+
try {
|
|
32
|
+
const data: unknown = JSON.parse(await readFile(manifestPath, "utf8"));
|
|
33
|
+
return object(data) && data.name === "personal-bot" && typeof data.version === "string" && valid(data.version)
|
|
34
|
+
? data.version
|
|
35
|
+
: undefined;
|
|
36
|
+
} catch (error) {
|
|
37
|
+
if ((error as NodeJS.ErrnoException).code === "ENOENT") return undefined;
|
|
38
|
+
throw error;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export const piUpgrader: HostUpgrader = {
|
|
43
|
+
host: "pi",
|
|
44
|
+
async upgrade(context: HostUpgradeContext): Promise<HostUpgradeResult> {
|
|
45
|
+
const current = await readLocalPiVersion(context.workspace) ?? context.currentVersion;
|
|
46
|
+
if (current && valid(current) && gte(current, context.targetVersion)) {
|
|
47
|
+
return {
|
|
48
|
+
host: this.host,
|
|
49
|
+
state: "up-to-date",
|
|
50
|
+
previousVersion: current,
|
|
51
|
+
version: current,
|
|
52
|
+
scope: "local",
|
|
53
|
+
detail: "已是最新版本。",
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
if (await hasCustomOnlySource(context.workspace)) {
|
|
57
|
+
return {
|
|
58
|
+
host: this.host,
|
|
59
|
+
state: "skipped",
|
|
60
|
+
...(current ? { previousVersion: current } : {}),
|
|
61
|
+
scope: "local",
|
|
62
|
+
detail: "工作区 Pi 配置中的 personal-bot 使用非 npm 自定义来源,已保留当前配置。",
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
const pi = context.env.PBOT_PI_COMMAND || await context.findExecutable("pi");
|
|
66
|
+
if (!pi) {
|
|
67
|
+
return {
|
|
68
|
+
host: this.host,
|
|
69
|
+
state: "skipped",
|
|
70
|
+
...(current ? { previousVersion: current } : {}),
|
|
71
|
+
scope: "local",
|
|
72
|
+
detail: "未找到 Pi CLI(pi),已跳过。",
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
await context.run(pi, ["install", "--local", `npm:personal-bot@${context.targetVersion}`], context.workspace);
|
|
76
|
+
const installed = await readLocalPiVersion(context.workspace) ?? context.targetVersion;
|
|
77
|
+
return {
|
|
78
|
+
host: this.host,
|
|
79
|
+
state: "updated",
|
|
80
|
+
...(current ? { previousVersion: current } : {}),
|
|
81
|
+
version: installed,
|
|
82
|
+
scope: "local",
|
|
83
|
+
detail: `已通过 pi install --local 更新工作区 personal-bot 到 ${installed}。`,
|
|
84
|
+
nextStep: "在 Pi 中执行 /reload 或重启 Pi 使新版本生效。",
|
|
85
|
+
};
|
|
86
|
+
},
|
|
87
|
+
};
|
|
@@ -0,0 +1,68 @@
|
|
|
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
|
+
import type { HostUpgradeContext, HostUpgradeResult, HostUpgrader } from "../../../model/installation.js";
|
|
6
|
+
|
|
7
|
+
async function readManifestVersion(path: string): Promise<string | undefined> {
|
|
8
|
+
try {
|
|
9
|
+
const data: unknown = JSON.parse(await readFile(path, "utf8"));
|
|
10
|
+
return object(data) && typeof data.version === "string" && valid(data.version) ? data.version : undefined;
|
|
11
|
+
} catch (error) {
|
|
12
|
+
if ((error as NodeJS.ErrnoException).code === "ENOENT") return undefined;
|
|
13
|
+
throw error;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export const qoderUpgrader: HostUpgrader = {
|
|
18
|
+
host: "qoder",
|
|
19
|
+
async upgrade(context: HostUpgradeContext): Promise<HostUpgradeResult> {
|
|
20
|
+
if (context.currentVersion && valid(context.currentVersion) && gte(context.currentVersion, context.targetVersion)) {
|
|
21
|
+
return {
|
|
22
|
+
host: this.host,
|
|
23
|
+
state: "up-to-date",
|
|
24
|
+
previousVersion: context.currentVersion,
|
|
25
|
+
version: context.currentVersion,
|
|
26
|
+
scope: "user",
|
|
27
|
+
detail: "已是最新版本。",
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
const pluginDir = join(context.packageRoot, "lib", "qoder-plugin");
|
|
31
|
+
const bundledVersion = await readManifestVersion(join(pluginDir, ".qoder-plugin", "plugin.json"));
|
|
32
|
+
if (!bundledVersion) {
|
|
33
|
+
return {
|
|
34
|
+
host: this.host,
|
|
35
|
+
state: "skipped",
|
|
36
|
+
...(context.currentVersion ? { previousVersion: context.currentVersion } : {}),
|
|
37
|
+
detail: `缺少 Qoder CLI 插件构建产物:${pluginDir}`,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
if (lt(bundledVersion, context.targetVersion)) {
|
|
41
|
+
return {
|
|
42
|
+
host: this.host,
|
|
43
|
+
state: "skipped",
|
|
44
|
+
...(context.currentVersion ? { previousVersion: context.currentVersion } : {}),
|
|
45
|
+
detail: `当前本地包产物版本为 ${bundledVersion},低于目标版本 ${context.targetVersion};请先更新全局 personal-bot 包。`,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
const qodercli = context.env.PBOT_QODER_COMMAND || await context.findExecutable("qodercli");
|
|
49
|
+
if (!qodercli) {
|
|
50
|
+
return {
|
|
51
|
+
host: this.host,
|
|
52
|
+
state: "skipped",
|
|
53
|
+
...(context.currentVersion ? { previousVersion: context.currentVersion } : {}),
|
|
54
|
+
detail: "未找到 Qoder CLI(qodercli),已跳过。",
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
await context.run(qodercli, ["plugin", "install", pluginDir], context.workspace);
|
|
58
|
+
return {
|
|
59
|
+
host: this.host,
|
|
60
|
+
state: "updated",
|
|
61
|
+
...(context.currentVersion ? { previousVersion: context.currentVersion } : {}),
|
|
62
|
+
version: bundledVersion,
|
|
63
|
+
scope: "user",
|
|
64
|
+
detail: `已通过 qodercli plugin install 更新到 ${bundledVersion}。`,
|
|
65
|
+
nextStep: "重启 Qoder CLI 会话使新版本生效。",
|
|
66
|
+
};
|
|
67
|
+
},
|
|
68
|
+
};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { requireThat } from "../../../common/validation.js";
|
|
2
|
+
import type { HostUpgrader } from "../../../model/installation.js";
|
|
3
|
+
import { antigravityUpgrader } from "./antigravity.js";
|
|
4
|
+
import { claudeUpgrader } from "./claude.js";
|
|
5
|
+
import { codexUpgrader } from "./codex.js";
|
|
6
|
+
import { dshUpgrader } from "./dsh.js";
|
|
7
|
+
import { piUpgrader } from "./pi.js";
|
|
8
|
+
import { qoderUpgrader } from "./qoder.js";
|
|
9
|
+
|
|
10
|
+
/** Extensible registry of per-host plugin upgraders; core upgrade orchestration never branches on host IDs. */
|
|
11
|
+
export class HostUpgraderRegistry {
|
|
12
|
+
readonly #upgraders = new Map<string, HostUpgrader>();
|
|
13
|
+
|
|
14
|
+
constructor(initial: readonly HostUpgrader[] = []) {
|
|
15
|
+
for (const upgrader of initial) this.register(upgrader);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
register(upgrader: HostUpgrader): this {
|
|
19
|
+
requireThat(typeof upgrader.host === "string" && upgrader.host.length > 0, "宿主升级适配器标识无效。");
|
|
20
|
+
this.#upgraders.set(upgrader.host, upgrader);
|
|
21
|
+
return this;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
unregister(host: string): boolean {
|
|
25
|
+
return this.#upgraders.delete(host);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
get(host: string): HostUpgrader | undefined {
|
|
29
|
+
return this.#upgraders.get(host);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
list(): string[] {
|
|
33
|
+
return [...this.#upgraders.keys()];
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export const hostUpgraders = new HostUpgraderRegistry([
|
|
38
|
+
piUpgrader,
|
|
39
|
+
claudeUpgrader,
|
|
40
|
+
antigravityUpgrader,
|
|
41
|
+
codexUpgrader,
|
|
42
|
+
qoderUpgrader,
|
|
43
|
+
dshUpgrader,
|
|
44
|
+
]);
|
|
45
|
+
|
|
46
|
+
export const registerHostUpgrader = (upgrader: HostUpgrader) => hostUpgraders.register(upgrader);
|
|
47
|
+
export const getHostUpgrader = (host: string) => hostUpgraders.get(host);
|
|
48
|
+
export const listHostUpgraders = () => hostUpgraders.list();
|
|
@@ -39,3 +39,48 @@ export interface SetupOperations {
|
|
|
39
39
|
installPackage(pi: PiInstallation, workspace: string, choice: PackageChoice): Promise<string>;
|
|
40
40
|
verifyKeptPackage(pi: PiInstallation, workspace: string, choice: PackageChoice): Promise<string>;
|
|
41
41
|
}
|
|
42
|
+
|
|
43
|
+
export type HostUpgradeState = "updated" | "up-to-date" | "skipped" | "failed";
|
|
44
|
+
|
|
45
|
+
export interface HostUpgradeContext {
|
|
46
|
+
workspace: string;
|
|
47
|
+
targetVersion: string;
|
|
48
|
+
currentVersion?: string;
|
|
49
|
+
packageRoot: string;
|
|
50
|
+
bindingPath?: string;
|
|
51
|
+
env: NodeJS.ProcessEnv;
|
|
52
|
+
signal: AbortSignal;
|
|
53
|
+
options: Readonly<Record<string, string | undefined>>;
|
|
54
|
+
run(command: string, args: string[], cwd: string, options?: { interactive?: boolean; timeoutMs?: number }): Promise<string>;
|
|
55
|
+
findExecutable(name: string): Promise<string | undefined>;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export interface HostUpgradeResult {
|
|
59
|
+
host: string;
|
|
60
|
+
state: HostUpgradeState;
|
|
61
|
+
previousVersion?: string;
|
|
62
|
+
version?: string;
|
|
63
|
+
scope?: string;
|
|
64
|
+
detail: string;
|
|
65
|
+
nextStep?: string;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export interface HostUpgrader {
|
|
69
|
+
readonly host: string;
|
|
70
|
+
upgrade(context: HostUpgradeContext): Promise<HostUpgradeResult>;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export interface CliUpgradeSummary {
|
|
74
|
+
state: HostUpgradeState;
|
|
75
|
+
previousVersion: string;
|
|
76
|
+
version: string;
|
|
77
|
+
detail: string;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export interface WorkspaceUpgradeSummary {
|
|
81
|
+
workspaceRoot: string;
|
|
82
|
+
targetVersion: string;
|
|
83
|
+
cli: CliUpgradeSummary;
|
|
84
|
+
results: HostUpgradeResult[];
|
|
85
|
+
ok: boolean;
|
|
86
|
+
}
|