personal-bot 0.3.4 → 0.3.6
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 +191 -65
- package/README.zh-CN.md +189 -63
- package/bin/pbot.mjs +3 -17
- package/docs/README.md +1 -1
- package/docs/architecture/design.md +10 -9
- package/docs/architecture/extensibility.md +1 -1
- package/docs/architecture/principles.md +1 -1
- package/docs/hosts/antigravity.md +4 -2
- package/docs/hosts/pi.md +4 -15
- package/docs/maintainers/release.md +2 -2
- 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 +22495 -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 +22495 -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/install.ts +77 -0
- package/src/extension/cli/commands/mcp.ts +165 -0
- package/src/extension/cli/commands/plugin.ts +33 -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 +192 -0
- package/src/extension/cli/types.ts +30 -0
- package/src/integrations/installation/cli-update.ts +3 -3
- package/src/integrations/installation/installers/antigravity.ts +49 -0
- package/src/integrations/installation/installers/claude.ts +30 -0
- package/src/integrations/installation/installers/codex.ts +56 -0
- package/src/integrations/installation/installers/dsh.ts +25 -0
- package/src/integrations/installation/installers/pi.ts +26 -0
- package/src/integrations/installation/installers/qoder.ts +49 -0
- package/src/integrations/installation/installers/registry.ts +48 -0
- package/src/integrations/installation/processes.ts +2 -41
- package/src/model/installation.ts +28 -36
- package/src/services/installation/install-service.ts +107 -0
- package/lib/common/package-source.js +0 -16
- package/lib/extension/setup/cli.js +0 -364
- package/lib/extension/setup/guard.js +0 -11
- package/lib/extension/setup/upgrade.js +0 -153
- package/lib/integrations/installation/cli-update.js +0 -146
- package/lib/integrations/installation/pi-bridge.js +0 -131
- 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/model/installation.js +0 -1
- 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/resources/installer/plugins.json +0 -16
- package/src/extension/setup/cli.ts +0 -303
- package/src/extension/setup/guard.ts +0 -12
- package/src/extension/setup/upgrade.ts +0 -158
- package/src/extension/setup/workspace-cli.ts +0 -167
- package/src/integrations/installation/pi-bridge.ts +0 -109
- package/src/integrations/installation/pi-setup.ts +0 -162
- package/src/services/installation/setup-service.ts +0 -126
- package/src/ui/setup.ts +0 -40
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import { readFile } from "node:fs/promises";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { valid } from "semver";
|
|
4
|
+
import { object } from "../../../common/json.js";
|
|
5
|
+
import { checkStableVersion } from "../../../common/package-source.js";
|
|
6
|
+
import { packageRoot } from "../../../common/paths.js";
|
|
7
|
+
import { packageVersion } from "../../../common/version.js";
|
|
8
|
+
import { execCliEntry, upgradeManagedGlobalCli } from "../../../integrations/installation/cli-update.js";
|
|
9
|
+
import { findExecutable, SetupProcesses } from "../../../integrations/installation/processes.js";
|
|
10
|
+
import { getHostUpgrader } from "../../../integrations/installation/upgraders/registry.js";
|
|
11
|
+
import type { CliUpgradeSummary, HostUpgradeResult, WorkspaceUpgradeSummary } from "../../../model/installation.js";
|
|
12
|
+
import {
|
|
13
|
+
executeWorkspaceUpgrade,
|
|
14
|
+
parseUpgradeArgs,
|
|
15
|
+
upgradeUsage,
|
|
16
|
+
type WorkspaceUpgradeTarget,
|
|
17
|
+
} from "../../../services/installation/upgrade-service.js";
|
|
18
|
+
import { workspacePluginBindings } from "../../../services/workspace/plugin-releases.js";
|
|
19
|
+
import { CliError, resolveCliWorkspace, withSignals } from "../args.js";
|
|
20
|
+
import type { CliCommand } from "../types.js";
|
|
21
|
+
|
|
22
|
+
async function latestStableVersion(processes: SetupProcesses, cwd: string): Promise<string> {
|
|
23
|
+
const npm = await findExecutable("npm", processes.env);
|
|
24
|
+
if (!npm) throw new Error("未找到 npm,无法查询 personal-bot 最新稳定版。");
|
|
25
|
+
const text = await processes.run(npm, ["view", "personal-bot@latest", "version", "engines", "--json",
|
|
26
|
+
"--fetch-retries=0", "--fetch-timeout=15000"], cwd);
|
|
27
|
+
const value = JSON.parse(text) as { version?: string; engines?: { node?: string } };
|
|
28
|
+
if (typeof value.version !== "string") throw new Error("无法取得 personal-bot 的最新版本。");
|
|
29
|
+
return checkStableVersion(value.version, value.engines?.node);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
async function discoverWorkspaceTargets(workspace: string, requestedHosts?: readonly string[]): Promise<WorkspaceUpgradeTarget[]> {
|
|
33
|
+
const bindings = workspacePluginBindings(workspace);
|
|
34
|
+
const byHost = new Map<string, WorkspaceUpgradeTarget>();
|
|
35
|
+
for (const [host, entry] of Object.entries(bindings)) {
|
|
36
|
+
byHost.set(host, {
|
|
37
|
+
host,
|
|
38
|
+
currentVersion: entry.version,
|
|
39
|
+
...(entry.bindingPath ? { bindingPath: entry.bindingPath } : {}),
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
if (!byHost.has("pi")) {
|
|
43
|
+
const localPiManifest = join(workspace, ".pi", "npm", "node_modules", "personal-bot", "package.json");
|
|
44
|
+
try {
|
|
45
|
+
const manifest: unknown = JSON.parse(await readFile(localPiManifest, "utf8"));
|
|
46
|
+
if (object(manifest) && manifest.name === "personal-bot" && typeof manifest.version === "string" && valid(manifest.version)) {
|
|
47
|
+
byHost.set("pi", { host: "pi", currentVersion: manifest.version, bindingPath: localPiManifest });
|
|
48
|
+
}
|
|
49
|
+
} catch (error) {
|
|
50
|
+
if ((error as NodeJS.ErrnoException).code !== "ENOENT") throw error;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
if (requestedHosts) {
|
|
54
|
+
return requestedHosts.map(host => byHost.get(host) ?? { host });
|
|
55
|
+
}
|
|
56
|
+
return [...byHost.values()].sort((a, b) => a.host.localeCompare(b.host));
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function formatLine(result: HostUpgradeResult): string {
|
|
60
|
+
const transition = result.previousVersion && result.version && result.previousVersion !== result.version
|
|
61
|
+
? `${result.previousVersion} → ${result.version}`
|
|
62
|
+
: result.version ?? result.previousVersion ?? "";
|
|
63
|
+
const scope = result.scope ? ` (${result.scope})` : "";
|
|
64
|
+
const head = `[${result.state}] ${result.host}${scope}${transition ? " " + transition : ""}: ${result.detail}`;
|
|
65
|
+
return result.nextStep ? `${head}\n 下一步:${result.nextStep}` : head;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function printHumanSummary(summary: WorkspaceUpgradeSummary): void {
|
|
69
|
+
console.log(`工作区:${summary.workspaceRoot}`);
|
|
70
|
+
console.log(`目标版本:${summary.targetVersion}`);
|
|
71
|
+
console.log(`[${summary.cli.state}] cli ${summary.cli.previousVersion} → ${summary.cli.version}: ${summary.cli.detail}`);
|
|
72
|
+
if (!summary.results.length) {
|
|
73
|
+
console.log("当前工作区尚未绑定任何宿主插件。如需指定宿主,可传入 --hosts <宿主列表>。");
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
for (const result of summary.results) console.log(formatLine(result));
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export const upgradeCommand: CliCommand = {
|
|
80
|
+
name: "upgrade",
|
|
81
|
+
aliases: ["update"],
|
|
82
|
+
summary: "统一升级全局 CLI 与当前工作区已绑定的各宿主插件",
|
|
83
|
+
usage: upgradeUsage,
|
|
84
|
+
updatePolicy: "none",
|
|
85
|
+
supportsWorkspaceFlag: true,
|
|
86
|
+
supportsJsonFlag: true,
|
|
87
|
+
async run(ctx) {
|
|
88
|
+
let parsed: ReturnType<typeof parseUpgradeArgs>;
|
|
89
|
+
try {
|
|
90
|
+
parsed = parseUpgradeArgs(ctx.args);
|
|
91
|
+
} catch (error) {
|
|
92
|
+
throw new CliError(error instanceof Error ? error.message : String(error), 2);
|
|
93
|
+
}
|
|
94
|
+
const workspaceArg = ctx.workspace ?? parsed.workspace;
|
|
95
|
+
const json = ctx.json || parsed.json;
|
|
96
|
+
const outcome = await withSignals(
|
|
97
|
+
async controller => {
|
|
98
|
+
const workspace = await resolveCliWorkspace(workspaceArg, ctx.cwd);
|
|
99
|
+
const processes = new SetupProcesses(controller.signal, process.env);
|
|
100
|
+
const targetVersion = parsed.version ?? await latestStableVersion(processes, ctx.cwd);
|
|
101
|
+
|
|
102
|
+
let cli: CliUpgradeSummary;
|
|
103
|
+
if (process.env.PBOT_UPGRADING_CLI === targetVersion) {
|
|
104
|
+
cli = {
|
|
105
|
+
state: "updated",
|
|
106
|
+
previousVersion: process.env.PBOT_UPGRADING_PREVIOUS_VERSION || packageVersion,
|
|
107
|
+
version: packageVersion,
|
|
108
|
+
detail: `已将全局 CLI 更新到 ${packageVersion}。`,
|
|
109
|
+
};
|
|
110
|
+
} else {
|
|
111
|
+
const cliResult = await upgradeManagedGlobalCli(targetVersion, process.env);
|
|
112
|
+
if (cliResult.state === "updated" && cliResult.globalDirectory) {
|
|
113
|
+
const nextEnv = {
|
|
114
|
+
...process.env,
|
|
115
|
+
PBOT_UPGRADING_CLI: targetVersion,
|
|
116
|
+
PBOT_UPGRADING_PREVIOUS_VERSION: packageVersion,
|
|
117
|
+
};
|
|
118
|
+
return execCliEntry(join(cliResult.globalDirectory, "bin", "pbot.mjs"), ctx.rawArgs, nextEnv);
|
|
119
|
+
}
|
|
120
|
+
cli = {
|
|
121
|
+
state: cliResult.state,
|
|
122
|
+
previousVersion: packageVersion,
|
|
123
|
+
version: packageVersion,
|
|
124
|
+
detail: cliResult.detail,
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
const targets = await discoverWorkspaceTargets(workspace, parsed.hosts);
|
|
129
|
+
const summary = await executeWorkspaceUpgrade({
|
|
130
|
+
workspaceRoot: workspace,
|
|
131
|
+
targetVersion,
|
|
132
|
+
cli,
|
|
133
|
+
targets,
|
|
134
|
+
resolveUpgrader: getHostUpgrader,
|
|
135
|
+
createContext: target => ({
|
|
136
|
+
workspace,
|
|
137
|
+
targetVersion,
|
|
138
|
+
...(target.currentVersion ? { currentVersion: target.currentVersion } : {}),
|
|
139
|
+
packageRoot,
|
|
140
|
+
...(target.bindingPath ? { bindingPath: target.bindingPath } : {}),
|
|
141
|
+
env: process.env,
|
|
142
|
+
signal: controller.signal,
|
|
143
|
+
options: { dshProfile: parsed.dshProfile },
|
|
144
|
+
run: (command, args, runCwd, runOptions) => processes.run(command, args, runCwd, runOptions),
|
|
145
|
+
findExecutable: name => findExecutable(name, process.env),
|
|
146
|
+
}),
|
|
147
|
+
signal: controller.signal,
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
if (json) console.log(JSON.stringify(summary, null, 2));
|
|
151
|
+
else printHumanSummary(summary);
|
|
152
|
+
return summary.ok ? 0 : 1;
|
|
153
|
+
},
|
|
154
|
+
() => console.error("升级已取消。"),
|
|
155
|
+
);
|
|
156
|
+
return outcome.ok ? outcome.value : outcome.exitCode;
|
|
157
|
+
},
|
|
158
|
+
};
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { mkdir, stat } from "node:fs/promises";
|
|
2
|
+
import { requireThat } from "../../../common/validation.js";
|
|
3
|
+
import { packageVersion } from "../../../common/version.js";
|
|
4
|
+
import { minimumCliRelease } from "../../../integrations/installation/cli-update.js";
|
|
5
|
+
import { workspacePluginDrift, workspacePluginReleases } from "../../../services/workspace/plugin-releases.js";
|
|
6
|
+
import { readWorkspaceConfig } from "../../../services/workspace/workspace-config.js";
|
|
7
|
+
import { initializeWorkspace } from "../../../services/workspace/workspace-preparation.js";
|
|
8
|
+
import { printJson, requireNoExtraArgs, resolveCliWorkspace } from "../args.js";
|
|
9
|
+
import type { CliCommand } from "../types.js";
|
|
10
|
+
|
|
11
|
+
const initUsage = "用法:pbot init [--workspace <目录>] [--json]\n初始化共享工作区资料并启用 Personal Bot。";
|
|
12
|
+
const statusUsage = "用法:pbot status [--workspace <目录>] [--json]\n查看工作区根目录、CLI 版本、各宿主插件版本、同步状态与配置。";
|
|
13
|
+
|
|
14
|
+
async function reportWorkspaceStatus(root: string, compact: boolean, checkRelease: boolean): Promise<number> {
|
|
15
|
+
const configuration = await readWorkspaceConfig(root);
|
|
16
|
+
const active = checkRelease || configuration.enabled;
|
|
17
|
+
const plugins = active ? workspacePluginReleases(root) : {};
|
|
18
|
+
const required = active ? await minimumCliRelease(root, plugins) : undefined;
|
|
19
|
+
const drift = workspacePluginDrift(plugins);
|
|
20
|
+
printJson({
|
|
21
|
+
workspaceRoot: root,
|
|
22
|
+
version: packageVersion,
|
|
23
|
+
plugins,
|
|
24
|
+
outOfSync: drift.outOfSync,
|
|
25
|
+
minimumCliVersion: required ?? null,
|
|
26
|
+
configuration,
|
|
27
|
+
}, compact);
|
|
28
|
+
return configuration.error ? 1 : 0;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export const initCommand: CliCommand = {
|
|
32
|
+
name: "init",
|
|
33
|
+
summary: "初始化共享资料并启用工作区",
|
|
34
|
+
usage: initUsage,
|
|
35
|
+
updatePolicy: "workspace",
|
|
36
|
+
supportsWorkspaceFlag: true,
|
|
37
|
+
supportsJsonFlag: true,
|
|
38
|
+
allowUninitializedUpdate: () => true,
|
|
39
|
+
beforeUpdate(ctx, _root, configuration) {
|
|
40
|
+
requireNoExtraArgs(ctx.args, initUsage);
|
|
41
|
+
if (configuration.error) throw new Error(configuration.error);
|
|
42
|
+
},
|
|
43
|
+
async run(ctx) {
|
|
44
|
+
requireNoExtraArgs(ctx.args, initUsage);
|
|
45
|
+
const root = await resolveCliWorkspace(ctx.workspace, ctx.cwd);
|
|
46
|
+
const existing = await readWorkspaceConfig(root);
|
|
47
|
+
if (existing.error) throw new Error(existing.error);
|
|
48
|
+
await mkdir(root, { recursive: true });
|
|
49
|
+
await initializeWorkspace(root);
|
|
50
|
+
requireThat((await stat(root)).isDirectory(), "工作区必须是目录。");
|
|
51
|
+
return reportWorkspaceStatus(root, ctx.json, true);
|
|
52
|
+
},
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
export const statusCommand: CliCommand = {
|
|
56
|
+
name: "status",
|
|
57
|
+
summary: "查看工作区状态、插件版本与配置",
|
|
58
|
+
usage: statusUsage,
|
|
59
|
+
updatePolicy: "workspace",
|
|
60
|
+
supportsWorkspaceFlag: true,
|
|
61
|
+
supportsJsonFlag: true,
|
|
62
|
+
beforeUpdate(ctx) {
|
|
63
|
+
requireNoExtraArgs(ctx.args, statusUsage);
|
|
64
|
+
},
|
|
65
|
+
async run(ctx) {
|
|
66
|
+
requireNoExtraArgs(ctx.args, statusUsage);
|
|
67
|
+
const root = await resolveCliWorkspace(ctx.workspace, ctx.cwd);
|
|
68
|
+
requireThat((await stat(root)).isDirectory(), "工作区必须是目录。");
|
|
69
|
+
return reportWorkspaceStatus(root, ctx.json, false);
|
|
70
|
+
},
|
|
71
|
+
};
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
import { realpathSync } from "node:fs";
|
|
2
|
+
import { pathToFileURL } from "node:url";
|
|
3
|
+
import { gte, valid } from "semver";
|
|
4
|
+
import { packageVersion } from "../../common/version.js";
|
|
5
|
+
import { minimumCliRelease, runUpdatedCli } from "../../integrations/installation/cli-update.js";
|
|
6
|
+
import { workspacePluginReleases } from "../../services/workspace/plugin-releases.js";
|
|
7
|
+
import { readWorkspaceConfig } from "../../services/workspace/workspace-config.js";
|
|
8
|
+
import { CliError, extractCommonFlags, resolveCliWorkspace } from "./args.js";
|
|
9
|
+
import { historyCommand } from "./commands/history.js";
|
|
10
|
+
import { installCommand } from "./commands/install.js";
|
|
11
|
+
import { mcpCommand } from "./commands/mcp.js";
|
|
12
|
+
import { pluginCommand } from "./commands/plugin.js";
|
|
13
|
+
import { upgradeCommand } from "./commands/upgrade.js";
|
|
14
|
+
import { initCommand, statusCommand } from "./commands/workspace.js";
|
|
15
|
+
import type { CliCommand, CliContext } from "./types.js";
|
|
16
|
+
|
|
17
|
+
const commands: readonly CliCommand[] = [
|
|
18
|
+
initCommand,
|
|
19
|
+
statusCommand,
|
|
20
|
+
installCommand,
|
|
21
|
+
upgradeCommand,
|
|
22
|
+
historyCommand,
|
|
23
|
+
mcpCommand,
|
|
24
|
+
pluginCommand,
|
|
25
|
+
];
|
|
26
|
+
|
|
27
|
+
const commandIndex = new Map<string, CliCommand>();
|
|
28
|
+
for (const command of commands) {
|
|
29
|
+
commandIndex.set(command.name, command);
|
|
30
|
+
for (const alias of command.aliases ?? []) commandIndex.set(alias, command);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function listCommands(): readonly CliCommand[] {
|
|
34
|
+
return commands;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function resolveCommand(name: string | undefined): CliCommand | undefined {
|
|
38
|
+
return name ? commandIndex.get(name) : undefined;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function formatRootHelp(): string {
|
|
42
|
+
const lines = [
|
|
43
|
+
`Personal Bot ${packageVersion}`,
|
|
44
|
+
"",
|
|
45
|
+
"用法:pbot <命令> [选项] [参数]",
|
|
46
|
+
"",
|
|
47
|
+
"命令:",
|
|
48
|
+
...commands.map(cmd => {
|
|
49
|
+
const label = cmd.aliases?.length ? `${cmd.name}|${cmd.aliases.join("|")}` : cmd.name;
|
|
50
|
+
return ` ${label.padEnd(22)} ${cmd.summary}`;
|
|
51
|
+
}),
|
|
52
|
+
"",
|
|
53
|
+
"通用选项:",
|
|
54
|
+
" --workspace <目录> 指定工作区根目录(默认当前目录,适用于工作区命令)",
|
|
55
|
+
" --json 输出 JSON(init/status/history/mcp 输出单行 JSON)",
|
|
56
|
+
" -h, --help 显示帮助(可配合具体命令使用:pbot <命令> --help)",
|
|
57
|
+
" -v, --version 显示当前 CLI 版本",
|
|
58
|
+
" --at-least <版本> 检查当前 CLI 是否满足最低版本要求",
|
|
59
|
+
"",
|
|
60
|
+
"支持 Linux/macOS,需要 Node.js 22.19+ 和 npm。",
|
|
61
|
+
];
|
|
62
|
+
return lines.join("\n");
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export async function updateForWorkspace(root: string, args: readonly string[], input?: string): Promise<number | undefined> {
|
|
66
|
+
return runUpdatedCli(await minimumCliRelease(root, workspacePluginReleases(root)), args, input);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export async function updateForCommand(args: readonly string[]): Promise<number | undefined> {
|
|
70
|
+
if (!args.length) return undefined;
|
|
71
|
+
if (["--version", "-v", "--at-least", "--help", "-h", "help"].includes(args[0]!)) return undefined;
|
|
72
|
+
const parsed = extractCommonFlags(args);
|
|
73
|
+
if (parsed.help || !parsed.rest.length) return undefined;
|
|
74
|
+
const [verb, ...rest] = parsed.rest;
|
|
75
|
+
const command = resolveCommand(verb);
|
|
76
|
+
if (!command) return undefined;
|
|
77
|
+
const ctx: CliContext = {
|
|
78
|
+
verb: verb!,
|
|
79
|
+
rawArgs: args,
|
|
80
|
+
args: rest,
|
|
81
|
+
...(parsed.workspace !== undefined ? { workspace: parsed.workspace } : {}),
|
|
82
|
+
json: parsed.json,
|
|
83
|
+
cwd: process.cwd(),
|
|
84
|
+
};
|
|
85
|
+
const policy = typeof command.updatePolicy === "function" ? command.updatePolicy(ctx) : command.updatePolicy;
|
|
86
|
+
if (policy !== "workspace") return undefined;
|
|
87
|
+
const root = command.resolveWorkspaceRoot
|
|
88
|
+
? await command.resolveWorkspaceRoot(ctx)
|
|
89
|
+
: await resolveCliWorkspace(ctx.workspace, ctx.cwd);
|
|
90
|
+
const configuration = await readWorkspaceConfig(root);
|
|
91
|
+
command.beforeUpdate?.(ctx, root, configuration);
|
|
92
|
+
const initializing = command.allowUninitializedUpdate?.(ctx) ?? false;
|
|
93
|
+
if (!configuration.enabled && !(initializing && !configuration.error)) return undefined;
|
|
94
|
+
return updateForWorkspace(root, args);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export async function main(args: readonly string[]): Promise<number> {
|
|
98
|
+
try {
|
|
99
|
+
// Fast local probes: never touch workspace config or npm.
|
|
100
|
+
if (args[0] === "--at-least") {
|
|
101
|
+
const version = args[1];
|
|
102
|
+
if (args.length !== 2 || !version || !valid(version)) {
|
|
103
|
+
throw new CliError("用法:pbot --at-least <MAJOR.MINOR.PATCH>", 1);
|
|
104
|
+
}
|
|
105
|
+
return gte(packageVersion, version) ? 0 : 1;
|
|
106
|
+
}
|
|
107
|
+
if (args.length === 1 && (args[0] === "--version" || args[0] === "-v")) {
|
|
108
|
+
console.log(packageVersion);
|
|
109
|
+
return 0;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const parsed = extractCommonFlags(args);
|
|
113
|
+
const [verb, ...rest] = parsed.rest;
|
|
114
|
+
|
|
115
|
+
// Top-level help or `pbot help [command]`
|
|
116
|
+
if (!verb) {
|
|
117
|
+
if (parsed.help || args.length === 0) {
|
|
118
|
+
console.log(formatRootHelp());
|
|
119
|
+
return 0;
|
|
120
|
+
}
|
|
121
|
+
throw new CliError(`缺少命令。\n\n${formatRootHelp()}`, 2);
|
|
122
|
+
}
|
|
123
|
+
if (verb === "help") {
|
|
124
|
+
const target = resolveCommand(rest[0]);
|
|
125
|
+
if (rest.length > 1 || (rest[0] && !target)) {
|
|
126
|
+
throw new CliError(`未知命令:${rest.join(" ")}\n\n${formatRootHelp()}`, 2);
|
|
127
|
+
}
|
|
128
|
+
console.log(target ? target.usage : formatRootHelp());
|
|
129
|
+
return 0;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
const command = resolveCommand(verb);
|
|
133
|
+
if (!command) {
|
|
134
|
+
if (parsed.help) {
|
|
135
|
+
console.log(formatRootHelp());
|
|
136
|
+
return 0;
|
|
137
|
+
}
|
|
138
|
+
throw new CliError(`未知命令:${verb}\n\n${formatRootHelp()}`, 2);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
if (parsed.help) {
|
|
142
|
+
console.log(command.usage);
|
|
143
|
+
return 0;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
if (parsed.workspace !== undefined && !command.supportsWorkspaceFlag) {
|
|
147
|
+
throw new CliError(`命令 ${command.name} 不支持 --workspace 参数。\n${command.usage}`, 2);
|
|
148
|
+
}
|
|
149
|
+
if (parsed.json && !command.supportsJsonFlag) {
|
|
150
|
+
throw new CliError(`命令 ${command.name} 不支持 --json 参数。\n${command.usage}`, 2);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
const ctx: CliContext = {
|
|
154
|
+
verb,
|
|
155
|
+
rawArgs: args,
|
|
156
|
+
args: rest,
|
|
157
|
+
...(parsed.workspace !== undefined ? { workspace: parsed.workspace } : {}),
|
|
158
|
+
json: parsed.json,
|
|
159
|
+
cwd: process.cwd(),
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
const policy = typeof command.updatePolicy === "function" ? command.updatePolicy(ctx) : command.updatePolicy;
|
|
163
|
+
if (policy === "workspace") {
|
|
164
|
+
const root = command.resolveWorkspaceRoot
|
|
165
|
+
? await command.resolveWorkspaceRoot(ctx)
|
|
166
|
+
: await resolveCliWorkspace(ctx.workspace, ctx.cwd);
|
|
167
|
+
const configuration = await readWorkspaceConfig(root);
|
|
168
|
+
command.beforeUpdate?.(ctx, root, configuration);
|
|
169
|
+
const initializing = command.allowUninitializedUpdate?.(ctx) ?? false;
|
|
170
|
+
if (configuration.enabled || (initializing && !configuration.error)) {
|
|
171
|
+
const updated = await updateForWorkspace(root, args);
|
|
172
|
+
if (updated !== undefined) return updated;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
return await command.run(ctx, { updateForWorkspace });
|
|
177
|
+
} catch (error) {
|
|
178
|
+
if (error instanceof CliError) {
|
|
179
|
+
console.error(error.message);
|
|
180
|
+
return error.exitCode;
|
|
181
|
+
}
|
|
182
|
+
console.error(error instanceof Error ? error.message : String(error));
|
|
183
|
+
return 1;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
if (process.argv[1] && import.meta.url === pathToFileURL(realpathSync(process.argv[1])).href) {
|
|
188
|
+
main(process.argv.slice(2)).then(code => { process.exitCode = code; }).catch(error => {
|
|
189
|
+
console.error(error instanceof Error ? error.message : String(error));
|
|
190
|
+
process.exitCode = 1;
|
|
191
|
+
});
|
|
192
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { WorkspaceConfiguration } from "../../model/workspace-config.js";
|
|
2
|
+
|
|
3
|
+
export type CliUpdatePolicy = "none" | "workspace" | "hook";
|
|
4
|
+
|
|
5
|
+
export interface CliContext {
|
|
6
|
+
readonly verb: string;
|
|
7
|
+
readonly rawArgs: readonly string[];
|
|
8
|
+
readonly args: string[];
|
|
9
|
+
readonly workspace?: string;
|
|
10
|
+
readonly json: boolean;
|
|
11
|
+
readonly cwd: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface CliCommand {
|
|
15
|
+
readonly name: string;
|
|
16
|
+
readonly aliases?: readonly string[];
|
|
17
|
+
readonly summary: string;
|
|
18
|
+
readonly usage: string;
|
|
19
|
+
readonly updatePolicy: CliUpdatePolicy | ((ctx: CliContext) => CliUpdatePolicy);
|
|
20
|
+
readonly supportsWorkspaceFlag?: boolean;
|
|
21
|
+
readonly supportsJsonFlag?: boolean;
|
|
22
|
+
readonly resolveWorkspaceRoot?: (ctx: CliContext) => Promise<string>;
|
|
23
|
+
readonly allowUninitializedUpdate?: (ctx: CliContext) => boolean;
|
|
24
|
+
readonly beforeUpdate?: (ctx: CliContext, root: string, configuration: WorkspaceConfiguration) => void;
|
|
25
|
+
readonly run: (ctx: CliContext, helpers: CliRuntimeHelpers) => Promise<number>;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface CliRuntimeHelpers {
|
|
29
|
+
readonly updateForWorkspace: (root: string, args: readonly string[], input?: string) => Promise<number | undefined>;
|
|
30
|
+
}
|
|
@@ -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
|
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { readFile } from "node:fs/promises";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { valid } from "semver";
|
|
4
|
+
import { object } from "../../../common/json.js";
|
|
5
|
+
import type { HostInstallContext, HostInstaller, HostInstallResult } 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 antigravityInstaller: HostInstaller = {
|
|
18
|
+
host: "antigravity",
|
|
19
|
+
async install(context: HostInstallContext): Promise<HostInstallResult> {
|
|
20
|
+
const agy = context.env.PBOT_AGY_COMMAND || await context.findExecutable("agy");
|
|
21
|
+
if (!agy) {
|
|
22
|
+
return {
|
|
23
|
+
host: this.host,
|
|
24
|
+
state: context.explicit ? "failed" : "skipped",
|
|
25
|
+
scope: "user",
|
|
26
|
+
detail: "未找到 Antigravity CLI(agy)。请先安装 agy 后重试。",
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
const pluginDir = join(context.packageRoot, "lib", "antigravity-plugin");
|
|
30
|
+
const bundledVersion = await readManifestVersion(join(pluginDir, "plugin.json"));
|
|
31
|
+
if (!bundledVersion) {
|
|
32
|
+
return {
|
|
33
|
+
host: this.host,
|
|
34
|
+
state: "failed",
|
|
35
|
+
scope: "user",
|
|
36
|
+
detail: `缺少 Antigravity 插件构建产物:${pluginDir}。请先运行 npm run build。`,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
await context.run(agy, ["plugin", "install", pluginDir], context.workspace);
|
|
40
|
+
return {
|
|
41
|
+
host: this.host,
|
|
42
|
+
state: "installed",
|
|
43
|
+
version: bundledVersion,
|
|
44
|
+
scope: "user",
|
|
45
|
+
detail: `已通过 agy plugin install 安装 Antigravity 插件(${bundledVersion})。`,
|
|
46
|
+
nextStep: "在 Antigravity 目标工作区执行 /pbot init 启用 Personal Bot。",
|
|
47
|
+
};
|
|
48
|
+
},
|
|
49
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { HostInstallContext, HostInstaller, HostInstallResult } from "../../../model/installation.js";
|
|
2
|
+
|
|
3
|
+
const claudeMarketplace = "realqiyan/personal-bot";
|
|
4
|
+
|
|
5
|
+
export const claudeInstaller: HostInstaller = {
|
|
6
|
+
host: "claude",
|
|
7
|
+
async install(context: HostInstallContext): Promise<HostInstallResult> {
|
|
8
|
+
const claude = context.env.PBOT_CLAUDE_COMMAND || await context.findExecutable("claude");
|
|
9
|
+
if (!claude) {
|
|
10
|
+
return {
|
|
11
|
+
host: this.host,
|
|
12
|
+
state: context.explicit ? "failed" : "skipped",
|
|
13
|
+
scope: "user",
|
|
14
|
+
detail: "未找到 Claude Code CLI(claude)。请先安装 Claude Code 后重试。",
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
await context.run(
|
|
18
|
+
claude,
|
|
19
|
+
["plugin", "install", "personal-bot", "--marketplace", claudeMarketplace, "--yes"],
|
|
20
|
+
context.workspace,
|
|
21
|
+
);
|
|
22
|
+
return {
|
|
23
|
+
host: this.host,
|
|
24
|
+
state: "installed",
|
|
25
|
+
scope: "user",
|
|
26
|
+
detail: `已通过 claude plugin install 从 ${claudeMarketplace} 安装 personal-bot。`,
|
|
27
|
+
nextStep: "在 Claude Code 目标工作区执行 /personal-bot:pbot init 启用 Personal Bot。",
|
|
28
|
+
};
|
|
29
|
+
},
|
|
30
|
+
};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { readFile } from "node:fs/promises";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { valid } from "semver";
|
|
4
|
+
import { object } from "../../../common/json.js";
|
|
5
|
+
import type { HostInstallContext, HostInstaller, HostInstallResult } 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 codexInstaller: HostInstaller = {
|
|
18
|
+
host: "codex",
|
|
19
|
+
async install(context: HostInstallContext): Promise<HostInstallResult> {
|
|
20
|
+
const codex = context.env.PBOT_CODEX_COMMAND || await context.findExecutable("codex");
|
|
21
|
+
if (!codex) {
|
|
22
|
+
return {
|
|
23
|
+
host: this.host,
|
|
24
|
+
state: context.explicit ? "failed" : "skipped",
|
|
25
|
+
scope: "user",
|
|
26
|
+
detail: "未找到 Codex CLI(codex)。请先安装 Codex CLI 后重试。",
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
const marketplaceDir = join(context.packageRoot, "lib", "codex-marketplace");
|
|
30
|
+
const bundledVersion = await readManifestVersion(
|
|
31
|
+
join(marketplaceDir, "plugins", "personal-bot", ".codex-plugin", "plugin.json"),
|
|
32
|
+
);
|
|
33
|
+
if (!bundledVersion) {
|
|
34
|
+
return {
|
|
35
|
+
host: this.host,
|
|
36
|
+
state: "failed",
|
|
37
|
+
scope: "user",
|
|
38
|
+
detail: `缺少 Codex 插件构建产物:${marketplaceDir}。请先运行 npm run build。`,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
try {
|
|
42
|
+
await context.run(codex, ["plugin", "marketplace", "add", marketplaceDir], context.workspace);
|
|
43
|
+
} catch {
|
|
44
|
+
// Marketplace may already be registered; proceed to install the plugin from it.
|
|
45
|
+
}
|
|
46
|
+
await context.run(codex, ["plugin", "add", "personal-bot@pbot-local"], context.workspace);
|
|
47
|
+
return {
|
|
48
|
+
host: this.host,
|
|
49
|
+
state: "installed",
|
|
50
|
+
version: bundledVersion,
|
|
51
|
+
scope: "user",
|
|
52
|
+
detail: `已通过 codex plugin add 安装 Codex 插件(${bundledVersion})。`,
|
|
53
|
+
nextStep: "在 Codex 的 /hooks 中核对并信任 Personal Bot hooks,然后执行 pbot plugin codex init 启用工作区。",
|
|
54
|
+
};
|
|
55
|
+
},
|
|
56
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { HostInstallContext, HostInstaller, HostInstallResult } from "../../../model/installation.js";
|
|
2
|
+
|
|
3
|
+
export const dshInstaller: HostInstaller = {
|
|
4
|
+
host: "dsh",
|
|
5
|
+
async install(context: HostInstallContext): Promise<HostInstallResult> {
|
|
6
|
+
const profile = context.options.dshProfile || "pbot";
|
|
7
|
+
const dsh = context.env.PBOT_DSH_COMMAND || await context.findExecutable("dsh");
|
|
8
|
+
if (!dsh) {
|
|
9
|
+
return {
|
|
10
|
+
host: this.host,
|
|
11
|
+
state: context.explicit ? "failed" : "skipped",
|
|
12
|
+
scope: `profile:${profile}`,
|
|
13
|
+
detail: "未找到 dsh CLI(dsh)。请先安装 @deepseek-ai/dsh 后重试。",
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
await context.run(dsh, ["plugin", "--profile", profile, "add", "personal-bot@latest"], context.workspace);
|
|
17
|
+
return {
|
|
18
|
+
host: this.host,
|
|
19
|
+
state: "installed",
|
|
20
|
+
scope: `profile:${profile}`,
|
|
21
|
+
detail: `已通过 dsh plugin --profile ${profile} add 安装 personal-bot。`,
|
|
22
|
+
nextStep: `启动 dsh --profile ${profile} 并在工作区执行 /pbot init 启用 Personal Bot。`,
|
|
23
|
+
};
|
|
24
|
+
},
|
|
25
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { packageVersion } from "../../../common/version.js";
|
|
2
|
+
import type { HostInstallContext, HostInstaller, HostInstallResult } from "../../../model/installation.js";
|
|
3
|
+
|
|
4
|
+
export const piInstaller: HostInstaller = {
|
|
5
|
+
host: "pi",
|
|
6
|
+
async install(context: HostInstallContext): Promise<HostInstallResult> {
|
|
7
|
+
const pi = context.env.PBOT_PI_COMMAND || await context.findExecutable("pi");
|
|
8
|
+
if (!pi) {
|
|
9
|
+
return {
|
|
10
|
+
host: this.host,
|
|
11
|
+
state: context.explicit ? "failed" : "skipped",
|
|
12
|
+
scope: "local",
|
|
13
|
+
detail: "未找到 Pi CLI(pi)。请先安装 Pi 后重试。",
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
await context.run(pi, ["install", "--local", "npm:personal-bot"], context.workspace);
|
|
17
|
+
return {
|
|
18
|
+
host: this.host,
|
|
19
|
+
state: "installed",
|
|
20
|
+
version: packageVersion,
|
|
21
|
+
scope: "local",
|
|
22
|
+
detail: "已通过 pi install --local 安装工作区 personal-bot。",
|
|
23
|
+
nextStep: "启动 Pi 并在工作区执行 /pbot init 启用 Personal Bot。",
|
|
24
|
+
};
|
|
25
|
+
},
|
|
26
|
+
};
|