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,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
|
+
}
|
|
@@ -42,12 +42,17 @@ export function packageChoices(catalog: PluginSpec[], installed: InstalledPackag
|
|
|
42
42
|
});
|
|
43
43
|
}
|
|
44
44
|
export function parseSetupArgs(args: string[]): {
|
|
45
|
-
action: "help" | "version" | "setup" | "install-antigravity" | "mcp" | "mcp-manage";
|
|
45
|
+
action: "help" | "version" | "setup" | "upgrade" | "install-antigravity" | "mcp" | "mcp-manage";
|
|
46
46
|
workspace?: string;
|
|
47
47
|
mcpArgs?: string[];
|
|
48
|
+
upgradeArgs?: string[];
|
|
49
|
+
upgradeVerb?: "upgrade" | "update";
|
|
48
50
|
} {
|
|
49
51
|
if (!args.length || args.length === 1 && ["--help", "-h"].includes(args[0]!)) return { action: "help" };
|
|
50
52
|
if (args.length === 1 && ["--version", "-v"].includes(args[0]!)) return { action: "version" };
|
|
53
|
+
if (args[0] === "upgrade" || args[0] === "update") {
|
|
54
|
+
return { action: "upgrade", upgradeArgs: args.slice(1), upgradeVerb: args[0] };
|
|
55
|
+
}
|
|
51
56
|
if (args[0] === "install-antigravity") {
|
|
52
57
|
if (args.length === 1) return { action: "install-antigravity" };
|
|
53
58
|
if (args.length === 2 && ["--help", "-h"].includes(args[1]!)) return { action: "help" };
|
|
@@ -59,7 +64,7 @@ export function parseSetupArgs(args: string[]): {
|
|
|
59
64
|
if (["list", "add", "remove"].includes(args[1]!)) return { action: "mcp-manage", mcpArgs: args.slice(1) };
|
|
60
65
|
throw new Error("用法:pbot mcp [list|add|remove ...]");
|
|
61
66
|
}
|
|
62
|
-
if (args[0] !== "setup") throw new Error("用法:pbot setup [--workspace <目录>] | pbot install-antigravity | pbot mcp [list|add|remove ...]");
|
|
67
|
+
if (args[0] !== "setup") throw new Error("用法:pbot setup [--workspace <目录>] | pbot upgrade|update [--workspace <目录>] | pbot install-antigravity | pbot mcp [list|add|remove ...]");
|
|
63
68
|
let workspace: string | undefined;
|
|
64
69
|
for (let index = 1; index < args.length; index++) {
|
|
65
70
|
const arg = args[index]!;
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { valid } from "semver";
|
|
2
|
+
import { requireThat } from "../../common/validation.js";
|
|
3
|
+
import type {
|
|
4
|
+
CliUpgradeSummary,
|
|
5
|
+
HostUpgradeContext,
|
|
6
|
+
HostUpgradeResult,
|
|
7
|
+
HostUpgrader,
|
|
8
|
+
WorkspaceUpgradeSummary,
|
|
9
|
+
} from "../../model/installation.js";
|
|
10
|
+
|
|
11
|
+
export interface UpgradeArgs {
|
|
12
|
+
help: boolean;
|
|
13
|
+
workspace?: string;
|
|
14
|
+
version?: string;
|
|
15
|
+
hosts?: string[];
|
|
16
|
+
dshProfile?: string;
|
|
17
|
+
json: boolean;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface WorkspaceUpgradeTarget {
|
|
21
|
+
host: string;
|
|
22
|
+
currentVersion?: string;
|
|
23
|
+
bindingPath?: string;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export const upgradeUsage =
|
|
27
|
+
"用法:pbot upgrade|update [--workspace <目录>] [--version <MAJOR.MINOR.PATCH>] [--hosts <h1,h2>] [--dsh-profile <名称>] [--json]\n" +
|
|
28
|
+
"将全局 CLI 与当前工作区已绑定的各宿主插件统一升级到 npm 最新稳定版(或指定版本)。";
|
|
29
|
+
|
|
30
|
+
export function parseUpgradeArgs(args: readonly string[]): UpgradeArgs {
|
|
31
|
+
let workspace: string | undefined;
|
|
32
|
+
let version: string | undefined;
|
|
33
|
+
let hosts: string[] | undefined;
|
|
34
|
+
let dshProfile: string | undefined;
|
|
35
|
+
let json = false;
|
|
36
|
+
for (let index = 0; index < args.length; index++) {
|
|
37
|
+
const token = args[index]!;
|
|
38
|
+
if (token === "--help" || token === "-h") return { help: true, json: false };
|
|
39
|
+
if (token === "--json") { json = true; continue; }
|
|
40
|
+
if (token === "--workspace" || token.startsWith("--workspace=")) {
|
|
41
|
+
requireThat(workspace === undefined, "--workspace 只能指定一次。");
|
|
42
|
+
workspace = token === "--workspace" ? args[++index] : token.slice("--workspace=".length);
|
|
43
|
+
requireThat(workspace && !workspace.startsWith("-"), "--workspace 需要目录。");
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
if (token === "--version" || token.startsWith("--version=")) {
|
|
47
|
+
requireThat(version === undefined, "--version 只能指定一次。");
|
|
48
|
+
version = token === "--version" ? args[++index] : token.slice("--version=".length);
|
|
49
|
+
requireThat(version && valid(version) && /^[0-9]/.test(version) && version === version.trim(),
|
|
50
|
+
"--version 需要合法的 MAJOR.MINOR.PATCH 版本号。");
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
if (token === "--hosts" || token.startsWith("--hosts=")) {
|
|
54
|
+
requireThat(hosts === undefined, "--hosts 只能指定一次。");
|
|
55
|
+
const raw = token === "--hosts" ? args[++index] : token.slice("--hosts=".length);
|
|
56
|
+
requireThat(raw && !raw.startsWith("-"), "--hosts 需要逗号分隔的宿主名称。");
|
|
57
|
+
hosts = [...new Set(raw.split(",").map(item => item.trim()).filter(Boolean))];
|
|
58
|
+
requireThat(hosts.length > 0, "--hosts 不能为空。");
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
if (token === "--dsh-profile" || token.startsWith("--dsh-profile=")) {
|
|
62
|
+
requireThat(dshProfile === undefined, "--dsh-profile 只能指定一次。");
|
|
63
|
+
dshProfile = token === "--dsh-profile" ? args[++index] : token.slice("--dsh-profile=".length);
|
|
64
|
+
requireThat(dshProfile && !dshProfile.startsWith("-"), "--dsh-profile 需要 profile 名称。");
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
throw new Error(`不支持的参数:${token}\n${upgradeUsage}`);
|
|
68
|
+
}
|
|
69
|
+
return {
|
|
70
|
+
help: false,
|
|
71
|
+
...(workspace !== undefined ? { workspace } : {}),
|
|
72
|
+
...(version !== undefined ? { version } : {}),
|
|
73
|
+
...(hosts !== undefined ? { hosts } : {}),
|
|
74
|
+
...(dshProfile !== undefined ? { dshProfile } : {}),
|
|
75
|
+
json,
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export async function executeWorkspaceUpgrade(
|
|
80
|
+
input: {
|
|
81
|
+
workspaceRoot: string;
|
|
82
|
+
targetVersion: string;
|
|
83
|
+
cli: CliUpgradeSummary;
|
|
84
|
+
targets: readonly WorkspaceUpgradeTarget[];
|
|
85
|
+
resolveUpgrader: (host: string) => HostUpgrader | undefined;
|
|
86
|
+
createContext: (target: WorkspaceUpgradeTarget) => HostUpgradeContext;
|
|
87
|
+
onResult?: (result: HostUpgradeResult) => void;
|
|
88
|
+
signal: AbortSignal;
|
|
89
|
+
},
|
|
90
|
+
): Promise<WorkspaceUpgradeSummary> {
|
|
91
|
+
const results: HostUpgradeResult[] = [];
|
|
92
|
+
for (const target of input.targets) {
|
|
93
|
+
input.signal.throwIfAborted();
|
|
94
|
+
const upgrader = input.resolveUpgrader(target.host);
|
|
95
|
+
let result: HostUpgradeResult;
|
|
96
|
+
if (!upgrader) {
|
|
97
|
+
result = {
|
|
98
|
+
host: target.host,
|
|
99
|
+
state: "skipped",
|
|
100
|
+
...(target.currentVersion ? { previousVersion: target.currentVersion } : {}),
|
|
101
|
+
detail: "未注册该宿主的自动升级适配器,已跳过。",
|
|
102
|
+
};
|
|
103
|
+
} else {
|
|
104
|
+
try {
|
|
105
|
+
result = await upgrader.upgrade(input.createContext(target));
|
|
106
|
+
} catch (error) {
|
|
107
|
+
input.signal.throwIfAborted();
|
|
108
|
+
result = {
|
|
109
|
+
host: target.host,
|
|
110
|
+
state: "failed",
|
|
111
|
+
...(target.currentVersion ? { previousVersion: target.currentVersion } : {}),
|
|
112
|
+
detail: error instanceof Error ? error.message : String(error),
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
results.push(result);
|
|
117
|
+
input.onResult?.(result);
|
|
118
|
+
}
|
|
119
|
+
const ok = input.cli.state !== "failed" && !results.some(item => item.state === "failed");
|
|
120
|
+
return {
|
|
121
|
+
workspaceRoot: input.workspaceRoot,
|
|
122
|
+
targetVersion: input.targetVersion,
|
|
123
|
+
cli: input.cli,
|
|
124
|
+
results,
|
|
125
|
+
ok,
|
|
126
|
+
};
|
|
127
|
+
}
|
|
@@ -8,6 +8,25 @@ 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
10
|
|
|
11
|
+
function compareSemver(a: string, b: string): number {
|
|
12
|
+
const parse = (value: string) => {
|
|
13
|
+
const match = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-([0-9A-Za-z.-]+))?/.exec(value);
|
|
14
|
+
return match
|
|
15
|
+
? { major: Number(match[1]), minor: Number(match[2]), patch: Number(match[3]), pre: match[4] ?? "" }
|
|
16
|
+
: undefined;
|
|
17
|
+
};
|
|
18
|
+
const left = parse(a);
|
|
19
|
+
const right = parse(b);
|
|
20
|
+
if (!left || !right) return a.localeCompare(b);
|
|
21
|
+
if (left.major !== right.major) return left.major - right.major;
|
|
22
|
+
if (left.minor !== right.minor) return left.minor - right.minor;
|
|
23
|
+
if (left.patch !== right.patch) return left.patch - right.patch;
|
|
24
|
+
if (left.pre === right.pre) return 0;
|
|
25
|
+
if (!left.pre) return 1;
|
|
26
|
+
if (!right.pre) return -1;
|
|
27
|
+
return left.pre.localeCompare(right.pre);
|
|
28
|
+
}
|
|
29
|
+
|
|
11
30
|
function bindingDirectory(root: string) {
|
|
12
31
|
const key = createHash("sha256").update(root).digest("hex");
|
|
13
32
|
return join(homedir(), ".pbot", "workspaces", key);
|
|
@@ -42,7 +61,19 @@ export function bindWorkspacePlugin(root: string, host: string, binding = resolv
|
|
|
42
61
|
}
|
|
43
62
|
}
|
|
44
63
|
|
|
45
|
-
export
|
|
64
|
+
export interface WorkspacePluginBinding {
|
|
65
|
+
version: string;
|
|
66
|
+
bindingPath?: string;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export interface WorkspacePluginDrift {
|
|
70
|
+
outOfSync: boolean;
|
|
71
|
+
highest?: string;
|
|
72
|
+
lowest?: string;
|
|
73
|
+
versions: Record<string, string>;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export function workspacePluginBindings(root: string): Record<string, WorkspacePluginBinding> {
|
|
46
77
|
const directory = bindingDirectory(root);
|
|
47
78
|
let files: string[];
|
|
48
79
|
try { files = readdirSync(directory); }
|
|
@@ -50,19 +81,41 @@ export function workspacePluginReleases(root: string): Record<string, string> {
|
|
|
50
81
|
if ((error as NodeJS.ErrnoException).code === "ENOENT" || permissionDenied(error)) return {};
|
|
51
82
|
throw error;
|
|
52
83
|
}
|
|
53
|
-
const
|
|
84
|
+
const bindings: Record<string, WorkspacePluginBinding> = Object.create(null);
|
|
54
85
|
for (const file of files.filter(name => name.endsWith(".json"))) {
|
|
55
86
|
const host = decodeURIComponent(file.slice(0, -5));
|
|
56
87
|
try {
|
|
57
88
|
const binding = readJsonFile(directory, file, pluginBinding);
|
|
58
|
-
if (!isAbsolute(binding)) {
|
|
89
|
+
if (!isAbsolute(binding)) { bindings[host] = { version: binding }; continue; }
|
|
59
90
|
const manifest: unknown = JSON.parse(readFileSync(binding, "utf8"));
|
|
60
91
|
requireThat(object(manifest) && typeof manifest.version === "string", "无效的插件安装清单:" + binding);
|
|
61
92
|
releaseLine(manifest.version);
|
|
62
|
-
|
|
93
|
+
bindings[host] = { version: manifest.version, bindingPath: binding };
|
|
63
94
|
} catch (error) {
|
|
64
95
|
if ((error as NodeJS.ErrnoException).code !== "ENOENT" && !permissionDenied(error)) throw error;
|
|
65
96
|
}
|
|
66
97
|
}
|
|
98
|
+
return bindings;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export function workspacePluginReleases(root: string): Record<string, string> {
|
|
102
|
+
const bindings = workspacePluginBindings(root);
|
|
103
|
+
const releases: Record<string, string> = Object.create(null);
|
|
104
|
+
for (const [host, entry] of Object.entries(bindings)) releases[host] = entry.version;
|
|
67
105
|
return releases;
|
|
68
106
|
}
|
|
107
|
+
|
|
108
|
+
export function workspacePluginDrift(releases: Record<string, string>): WorkspacePluginDrift {
|
|
109
|
+
let highest: string | undefined;
|
|
110
|
+
let lowest: string | undefined;
|
|
111
|
+
for (const version of Object.values(releases)) {
|
|
112
|
+
if (!highest || compareSemver(version, highest) > 0) highest = version;
|
|
113
|
+
if (!lowest || compareSemver(version, lowest) < 0) lowest = version;
|
|
114
|
+
}
|
|
115
|
+
return {
|
|
116
|
+
outOfSync: Boolean(highest && lowest && highest !== lowest),
|
|
117
|
+
...(highest ? { highest } : {}),
|
|
118
|
+
...(lowest ? { lowest } : {}),
|
|
119
|
+
versions: releases,
|
|
120
|
+
};
|
|
121
|
+
}
|