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.
Files changed (86) hide show
  1. package/.claude-plugin/marketplace.json +2 -2
  2. package/.claude-plugin/plugin.json +1 -1
  3. package/README.md +191 -65
  4. package/README.zh-CN.md +189 -63
  5. package/bin/pbot.mjs +3 -17
  6. package/docs/README.md +1 -1
  7. package/docs/architecture/design.md +10 -9
  8. package/docs/architecture/extensibility.md +1 -1
  9. package/docs/architecture/principles.md +1 -1
  10. package/docs/hosts/antigravity.md +4 -2
  11. package/docs/hosts/pi.md +4 -15
  12. package/docs/maintainers/release.md +2 -2
  13. package/lib/antigravity-plugin/lib/common/paths.d.ts +1 -0
  14. package/lib/antigravity-plugin/lib/common/paths.js +2 -0
  15. package/lib/antigravity-plugin/lib/extension/acp-worker.js +26 -24
  16. package/lib/antigravity-plugin/lib/extension/cli.js +22495 -0
  17. package/lib/antigravity-plugin/lib/extension/mcp.js +22 -20
  18. package/lib/antigravity-plugin/lib/extension/workspace-cli.js +5 -20165
  19. package/lib/antigravity-plugin/package.json +1 -1
  20. package/lib/antigravity-plugin/plugin.json +1 -1
  21. package/lib/codex-marketplace/plugins/personal-bot/.codex-plugin/plugin.json +1 -1
  22. package/lib/codex-marketplace/plugins/personal-bot/.mcp.json +2 -2
  23. package/lib/codex-marketplace/plugins/personal-bot/hooks/hooks.json +3 -3
  24. package/lib/codex-marketplace/plugins/personal-bot/skills/pbot/SKILL.md +1 -1
  25. package/lib/common/paths.d.ts +1 -0
  26. package/lib/common/paths.js +2 -0
  27. package/lib/extension/acp-worker.js +26 -24
  28. package/lib/extension/cli.js +22495 -0
  29. package/lib/extension/mcp.js +22 -20
  30. package/lib/extension/workspace-cli.js +5 -20165
  31. package/lib/qoder-plugin/.mcp.json +2 -2
  32. package/lib/qoder-plugin/.qoder-plugin/plugin.json +1 -1
  33. package/lib/qoder-plugin/hooks/hooks.json +3 -3
  34. package/lib/qoder-plugin/skills/pbot/SKILL.md +1 -1
  35. package/package.json +1 -1
  36. package/scripts/README.md +1 -1
  37. package/src/common/paths.ts +2 -0
  38. package/src/extension/cli/args.ts +104 -0
  39. package/src/extension/cli/commands/history.ts +81 -0
  40. package/src/extension/cli/commands/install.ts +77 -0
  41. package/src/extension/cli/commands/mcp.ts +165 -0
  42. package/src/extension/cli/commands/plugin.ts +33 -0
  43. package/src/extension/cli/commands/upgrade.ts +158 -0
  44. package/src/extension/cli/commands/workspace.ts +71 -0
  45. package/src/extension/cli/index.ts +192 -0
  46. package/src/extension/cli/types.ts +30 -0
  47. package/src/integrations/installation/cli-update.ts +3 -3
  48. package/src/integrations/installation/installers/antigravity.ts +49 -0
  49. package/src/integrations/installation/installers/claude.ts +30 -0
  50. package/src/integrations/installation/installers/codex.ts +56 -0
  51. package/src/integrations/installation/installers/dsh.ts +25 -0
  52. package/src/integrations/installation/installers/pi.ts +26 -0
  53. package/src/integrations/installation/installers/qoder.ts +49 -0
  54. package/src/integrations/installation/installers/registry.ts +48 -0
  55. package/src/integrations/installation/processes.ts +2 -41
  56. package/src/model/installation.ts +28 -36
  57. package/src/services/installation/install-service.ts +107 -0
  58. package/lib/common/package-source.js +0 -16
  59. package/lib/extension/setup/cli.js +0 -364
  60. package/lib/extension/setup/guard.js +0 -11
  61. package/lib/extension/setup/upgrade.js +0 -153
  62. package/lib/integrations/installation/cli-update.js +0 -146
  63. package/lib/integrations/installation/pi-bridge.js +0 -131
  64. package/lib/integrations/installation/pi-setup.js +0 -193
  65. package/lib/integrations/installation/processes.js +0 -140
  66. package/lib/integrations/installation/upgraders/antigravity.js +0 -67
  67. package/lib/integrations/installation/upgraders/claude.js +0 -123
  68. package/lib/integrations/installation/upgraders/codex.js +0 -73
  69. package/lib/integrations/installation/upgraders/dsh.js +0 -62
  70. package/lib/integrations/installation/upgraders/pi.js +0 -90
  71. package/lib/integrations/installation/upgraders/qoder.js +0 -67
  72. package/lib/integrations/installation/upgraders/registry.js +0 -40
  73. package/lib/integrations/installation/workspace.js +0 -21
  74. package/lib/model/installation.js +0 -1
  75. package/lib/services/installation/setup-service.js +0 -140
  76. package/lib/services/installation/upgrade-service.js +0 -95
  77. package/lib/ui/setup.js +0 -52
  78. package/resources/installer/plugins.json +0 -16
  79. package/src/extension/setup/cli.ts +0 -303
  80. package/src/extension/setup/guard.ts +0 -12
  81. package/src/extension/setup/upgrade.ts +0 -158
  82. package/src/extension/setup/workspace-cli.ts +0 -167
  83. package/src/integrations/installation/pi-bridge.ts +0 -109
  84. package/src/integrations/installation/pi-setup.ts +0 -162
  85. package/src/services/installation/setup-service.ts +0 -126
  86. package/src/ui/setup.ts +0 -40
@@ -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 qoderInstaller: HostInstaller = {
18
+ host: "qoder",
19
+ async install(context: HostInstallContext): Promise<HostInstallResult> {
20
+ const qodercli = context.env.PBOT_QODER_COMMAND || await context.findExecutable("qodercli");
21
+ if (!qodercli) {
22
+ return {
23
+ host: this.host,
24
+ state: context.explicit ? "failed" : "skipped",
25
+ scope: "user",
26
+ detail: "未找到 Qoder CLI(qodercli)。请先安装 Qoder CLI 后重试。",
27
+ };
28
+ }
29
+ const pluginDir = join(context.packageRoot, "lib", "qoder-plugin");
30
+ const bundledVersion = await readManifestVersion(join(pluginDir, ".qoder-plugin", "plugin.json"));
31
+ if (!bundledVersion) {
32
+ return {
33
+ host: this.host,
34
+ state: "failed",
35
+ scope: "user",
36
+ detail: `缺少 Qoder CLI 插件构建产物:${pluginDir}。请先运行 npm run build。`,
37
+ };
38
+ }
39
+ await context.run(qodercli, ["plugin", "install", pluginDir], context.workspace);
40
+ return {
41
+ host: this.host,
42
+ state: "installed",
43
+ version: bundledVersion,
44
+ scope: "user",
45
+ detail: `已通过 qodercli plugin install 安装 Qoder CLI 插件(${bundledVersion})。`,
46
+ nextStep: "在目标工作区执行 pbot plugin qoder init 启用 Personal Bot。",
47
+ };
48
+ },
49
+ };
@@ -0,0 +1,48 @@
1
+ import { requireThat } from "../../../common/validation.js";
2
+ import type { HostInstaller } from "../../../model/installation.js";
3
+ import { antigravityInstaller } from "./antigravity.js";
4
+ import { claudeInstaller } from "./claude.js";
5
+ import { codexInstaller } from "./codex.js";
6
+ import { dshInstaller } from "./dsh.js";
7
+ import { piInstaller } from "./pi.js";
8
+ import { qoderInstaller } from "./qoder.js";
9
+
10
+ /** Extensible registry of per-host plugin installers; core install orchestration never branches on host IDs. */
11
+ export class HostInstallerRegistry {
12
+ readonly #installers = new Map<string, HostInstaller>();
13
+
14
+ constructor(initial: readonly HostInstaller[] = []) {
15
+ for (const installer of initial) this.register(installer);
16
+ }
17
+
18
+ register(installer: HostInstaller): this {
19
+ requireThat(typeof installer.host === "string" && installer.host.length > 0, "宿主安装适配器标识无效。");
20
+ this.#installers.set(installer.host, installer);
21
+ return this;
22
+ }
23
+
24
+ unregister(host: string): boolean {
25
+ return this.#installers.delete(host);
26
+ }
27
+
28
+ get(host: string): HostInstaller | undefined {
29
+ return this.#installers.get(host);
30
+ }
31
+
32
+ list(): string[] {
33
+ return [...this.#installers.keys()];
34
+ }
35
+ }
36
+
37
+ export const hostInstallers = new HostInstallerRegistry([
38
+ piInstaller,
39
+ dshInstaller,
40
+ claudeInstaller,
41
+ antigravityInstaller,
42
+ codexInstaller,
43
+ qoderInstaller,
44
+ ]);
45
+
46
+ export const registerHostInstaller = (installer: HostInstaller) => hostInstallers.register(installer);
47
+ export const getHostInstaller = (host: string) => hostInstallers.get(host);
48
+ export const listHostInstallers = () => hostInstallers.list();
@@ -1,8 +1,7 @@
1
1
  import { spawn } from "node:child_process";
2
2
  import { access, realpath, stat } from "node:fs/promises";
3
3
  import { constants } from "node:fs";
4
- import { delimiter, isAbsolute, join, resolve } from "node:path";
5
- import type { SystemCommand } from "../../model/installation.js";
4
+ import { delimiter, isAbsolute, resolve } from "node:path";
6
5
 
7
6
  export async function findExecutable(name: string, env: NodeJS.ProcessEnv = process.env): Promise<string | undefined> {
8
7
  const directories = (env.PATH ?? "").split(delimiter).filter(Boolean);
@@ -47,7 +46,7 @@ export class SetupProcesses {
47
46
  kill("SIGTERM");
48
47
  escalation = setTimeout(() => kill("SIGKILL"), 2000);
49
48
  };
50
- const cancel = () => stop(new Error("安装已取消。"));
49
+ const cancel = () => stop(new Error("操作已取消。"));
51
50
  const timer = timeoutMs > 0 ? setTimeout(() => stop(new Error(`命令超时:${command}`)), timeoutMs) : undefined;
52
51
  this.signal.addEventListener("abort", cancel, { once: true });
53
52
  const collect = (chunks: Buffer[]) => (chunk: Buffer) => {
@@ -71,41 +70,3 @@ export class SetupProcesses {
71
70
  });
72
71
  }
73
72
  }
74
-
75
- export function tmuxInstallCommand(platform: string, commands: ReadonlyMap<string, string>, root: boolean): SystemCommand {
76
- let command: string | undefined, args: string[];
77
- if (platform === "darwin") {
78
- command = commands.get("brew"); args = ["install", "tmux"];
79
- } else {
80
- const manager = ["apt-get", "dnf", "pacman", "zypper", "apk"].find(name => commands.has(name));
81
- command = manager ? commands.get(manager) : undefined;
82
- args = manager === "apt-get" ? ["install", "-y", "tmux"] : manager === "dnf" ? ["install", "-y", "tmux"]
83
- : manager === "pacman" ? ["-S", "--needed", "--noconfirm", "tmux"]
84
- : manager === "zypper" ? ["--non-interactive", "install", "tmux"] : ["add", "tmux"];
85
- if (command && !root) {
86
- const sudo = commands.get("sudo");
87
- if (!sudo) throw new Error("安装 tmux 需要管理员权限;请手动安装 tmux 后重新运行 setup。");
88
- return { command: sudo, args: [command, ...args] };
89
- }
90
- }
91
- if (!command) throw new Error(platform === "darwin"
92
- ? "未找到 Homebrew。请先通过现有环境安装 tmux,再运行 setup。"
93
- : "未找到支持的系统包管理器。请手动安装 tmux,再运行 setup。");
94
- return { command, args };
95
- }
96
-
97
- export async function inspectSystem(processes: SetupProcesses, cwd: string): Promise<{ npm: string; tmux?: SystemCommand }> {
98
- if (!["linux", "darwin"].includes(process.platform)) throw new Error("setup 支持 Linux 和 macOS;Windows 请使用 WSL。");
99
- const [major = 0, minor = 0] = process.versions.node.split(".").map(Number);
100
- if (major < 22 || major === 22 && minor < 19) throw new Error("需要 Node.js 22.19 或更高版本。");
101
- const npm = await findExecutable("npm", processes.env);
102
- if (!npm) throw new Error("未找到 npm。请先安装 Node.js/npm。");
103
- const tmux = await findExecutable("tmux", processes.env);
104
- if (tmux) { await processes.run(tmux, ["-V"], cwd); return { npm }; }
105
- const names = process.platform === "darwin" ? ["brew"] : ["apt-get", "dnf", "pacman", "zypper", "apk", "sudo"];
106
- const entries = await Promise.all(names.map(async name => [name, await findExecutable(name, processes.env)] as const));
107
- const commands = new Map(entries.filter((entry): entry is readonly [string, string] => entry[1] !== undefined));
108
- return { npm, tmux: tmuxInstallCommand(process.platform, commands, process.getuid?.() === 0) };
109
- }
110
-
111
- export function npmGlobalBinary(prefix: string): string { return join(prefix, "bin", "pi"); }
@@ -1,43 +1,35 @@
1
- export interface PluginSpec {
2
- id: string;
3
- label: string;
4
- description: string;
5
- source: string;
6
- defaultSelected: boolean;
1
+ export type HostInstallState = "installed" | "skipped" | "failed";
2
+
3
+ export interface HostInstallContext {
4
+ workspace: string;
5
+ packageRoot: string;
6
+ explicit: boolean;
7
+ env: NodeJS.ProcessEnv;
8
+ signal: AbortSignal;
9
+ options: Readonly<Record<string, string | undefined>>;
10
+ run(command: string, args: string[], cwd: string, options?: { interactive?: boolean; timeoutMs?: number }): Promise<string>;
11
+ findExecutable(name: string): Promise<string | undefined>;
7
12
  }
8
- export interface InstalledPackage {
9
- source: string;
10
- scope: "user" | "project";
11
- name?: string;
13
+
14
+ export interface HostInstallResult {
15
+ host: string;
16
+ state: HostInstallState;
12
17
  version?: string;
13
- installedPath?: string;
14
- filtered: boolean;
15
- entry: unknown;
16
- }
17
- export interface PackageChoice {
18
- plugin: PluginSpec;
19
- required: boolean;
20
- existing: InstalledPackage[];
21
- selected: boolean;
22
- keep: boolean;
23
- target?: string;
24
- error?: string;
18
+ scope?: string;
19
+ detail: string;
20
+ nextStep?: string;
25
21
  }
26
- export interface PiInstallation { command: string; root: string; version: string }
27
- export interface SystemCommand { command: string; args: string[] }
28
- export interface SetupPlan {
29
- workspace: string;
30
- pi?: PiInstallation;
31
- piVersion: string;
32
- tmux?: SystemCommand;
33
- packages: PackageChoice[];
22
+
23
+ export interface HostInstaller {
24
+ readonly host: string;
25
+ install(context: HostInstallContext): Promise<HostInstallResult>;
34
26
  }
35
- export interface SetupResult { name: string; state: "done" | "kept" | "skipped" | "failed"; detail: string }
36
- export interface SetupOperations {
37
- installTmux(command: SystemCommand): Promise<void>;
38
- ensurePi(existing: PiInstallation | undefined, version: string): Promise<PiInstallation>;
39
- installPackage(pi: PiInstallation, workspace: string, choice: PackageChoice): Promise<string>;
40
- verifyKeptPackage(pi: PiInstallation, workspace: string, choice: PackageChoice): Promise<string>;
27
+
28
+ export interface WorkspaceInstallSummary {
29
+ workspaceRoot: string;
30
+ target: string;
31
+ results: HostInstallResult[];
32
+ ok: boolean;
41
33
  }
42
34
 
43
35
  export type HostUpgradeState = "updated" | "up-to-date" | "skipped" | "failed";
@@ -0,0 +1,107 @@
1
+ import { requireThat } from "../../common/validation.js";
2
+ import type {
3
+ HostInstallContext,
4
+ HostInstaller,
5
+ HostInstallResult,
6
+ WorkspaceInstallSummary,
7
+ } from "../../model/installation.js";
8
+
9
+ export interface InstallArgs {
10
+ help: boolean;
11
+ target?: string;
12
+ workspace?: string;
13
+ dshProfile?: string;
14
+ json: boolean;
15
+ }
16
+
17
+ export function formatInstallUsage(hosts: readonly string[]): string {
18
+ return (
19
+ `用法:pbot install <${hosts.join("|")}|all> [--workspace <目录>] [--dsh-profile <名称>] [--json]\n` +
20
+ "为指定宿主安装 Personal Bot 插件;传入 all 时为本机已安装的各宿主统一安装。"
21
+ );
22
+ }
23
+
24
+ export function parseInstallArgs(args: readonly string[], hosts: readonly string[]): InstallArgs {
25
+ const usage = formatInstallUsage(hosts);
26
+ let target: string | undefined;
27
+ let workspace: string | undefined;
28
+ let dshProfile: string | undefined;
29
+ let json = false;
30
+ for (let index = 0; index < args.length; index++) {
31
+ const token = args[index]!;
32
+ if (token === "--help" || token === "-h") return { help: true, json: false };
33
+ if (token === "--json") { json = true; continue; }
34
+ if (token === "--workspace" || token.startsWith("--workspace=")) {
35
+ requireThat(workspace === undefined, "--workspace 只能指定一次。");
36
+ workspace = token === "--workspace" ? args[++index] : token.slice("--workspace=".length);
37
+ requireThat(workspace && !workspace.startsWith("-"), "--workspace 需要目录。");
38
+ continue;
39
+ }
40
+ if (token === "--dsh-profile" || token.startsWith("--dsh-profile=")) {
41
+ requireThat(dshProfile === undefined, "--dsh-profile 只能指定一次。");
42
+ dshProfile = token === "--dsh-profile" ? args[++index] : token.slice("--dsh-profile=".length);
43
+ requireThat(dshProfile && !dshProfile.startsWith("-"), "--dsh-profile 需要 profile 名称。");
44
+ continue;
45
+ }
46
+ if (token.startsWith("-")) {
47
+ throw new Error(`不支持的参数:${token}\n${usage}`);
48
+ }
49
+ requireThat(target === undefined, `只能指定一个安装目标,收到多余参数:${token}\n${usage}`);
50
+ target = token.trim().toLowerCase();
51
+ }
52
+ requireThat(target && target.length > 0, `缺少安装目标。\n${usage}`);
53
+ requireThat(target === "all" || hosts.includes(target), `未知宿主:${target}。\n${usage}`);
54
+ return {
55
+ help: false,
56
+ target,
57
+ ...(workspace !== undefined ? { workspace } : {}),
58
+ ...(dshProfile !== undefined ? { dshProfile } : {}),
59
+ json,
60
+ };
61
+ }
62
+
63
+ export async function executeHostInstall(input: {
64
+ workspaceRoot: string;
65
+ target: string;
66
+ hosts: readonly string[];
67
+ resolveInstaller: (host: string) => HostInstaller | undefined;
68
+ createContext: (host: string, explicit: boolean) => HostInstallContext;
69
+ onResult?: (result: HostInstallResult) => void;
70
+ signal: AbortSignal;
71
+ }): Promise<WorkspaceInstallSummary> {
72
+ const explicit = input.target !== "all";
73
+ const targets = explicit ? [input.target] : [...input.hosts];
74
+ const results: HostInstallResult[] = [];
75
+ for (const host of targets) {
76
+ input.signal.throwIfAborted();
77
+ const installer = input.resolveInstaller(host);
78
+ let result: HostInstallResult;
79
+ if (!installer) {
80
+ result = {
81
+ host,
82
+ state: explicit ? "failed" : "skipped",
83
+ detail: "未注册该宿主的安装适配器。",
84
+ };
85
+ } else {
86
+ try {
87
+ result = await installer.install(input.createContext(host, explicit));
88
+ } catch (error) {
89
+ input.signal.throwIfAborted();
90
+ result = {
91
+ host,
92
+ state: "failed",
93
+ detail: error instanceof Error ? error.message : String(error),
94
+ };
95
+ }
96
+ }
97
+ results.push(result);
98
+ input.onResult?.(result);
99
+ }
100
+ const ok = !results.some(item => item.state === "failed");
101
+ return {
102
+ workspaceRoot: input.workspaceRoot,
103
+ target: input.target,
104
+ results,
105
+ ok,
106
+ };
107
+ }
@@ -1,16 +0,0 @@
1
- import { prerelease, satisfies, valid } from "semver";
2
- export function npmName(source) {
3
- return /^npm:((?:@[a-z0-9._-]+\/)?[a-z0-9._-]+)(?:@[^\s]+)?$/.exec(source)?.[1];
4
- }
5
- export function ordinaryNpm(source) {
6
- const name = npmName(source);
7
- return name !== undefined && (source === `npm:${name}` || source === `npm:${name}@latest`);
8
- }
9
- export function checkStableVersion(version, nodeRange) {
10
- if (!valid(version) || prerelease(version))
11
- throw new Error(`latest 不是稳定版本:${version}`);
12
- if (nodeRange && !satisfies(process.versions.node, nodeRange)) {
13
- throw new Error(`目标版本要求 Node.js ${nodeRange},当前为 ${process.versions.node}。请先升级 Node.js。`);
14
- }
15
- return version;
16
- }