personal-bot 0.3.5 → 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 (45) 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/docs/README.md +1 -1
  6. package/docs/architecture/design.md +3 -4
  7. package/docs/hosts/antigravity.md +4 -2
  8. package/docs/hosts/pi.md +4 -15
  9. package/docs/maintainers/release.md +2 -2
  10. package/lib/antigravity-plugin/lib/extension/cli.js +1392 -1493
  11. package/lib/antigravity-plugin/package.json +1 -1
  12. package/lib/antigravity-plugin/plugin.json +1 -1
  13. package/lib/codex-marketplace/plugins/personal-bot/.codex-plugin/plugin.json +1 -1
  14. package/lib/codex-marketplace/plugins/personal-bot/.mcp.json +2 -2
  15. package/lib/codex-marketplace/plugins/personal-bot/hooks/hooks.json +3 -3
  16. package/lib/codex-marketplace/plugins/personal-bot/skills/pbot/SKILL.md +1 -1
  17. package/lib/extension/cli.js +1392 -1493
  18. package/lib/qoder-plugin/.mcp.json +2 -2
  19. package/lib/qoder-plugin/.qoder-plugin/plugin.json +1 -1
  20. package/lib/qoder-plugin/hooks/hooks.json +3 -3
  21. package/lib/qoder-plugin/skills/pbot/SKILL.md +1 -1
  22. package/package.json +1 -1
  23. package/src/extension/cli/commands/install.ts +77 -0
  24. package/src/extension/cli/index.ts +3 -4
  25. package/src/integrations/installation/installers/antigravity.ts +49 -0
  26. package/src/integrations/installation/installers/claude.ts +30 -0
  27. package/src/integrations/installation/installers/codex.ts +56 -0
  28. package/src/integrations/installation/installers/dsh.ts +25 -0
  29. package/src/integrations/installation/installers/pi.ts +26 -0
  30. package/src/integrations/installation/installers/qoder.ts +49 -0
  31. package/src/integrations/installation/installers/registry.ts +48 -0
  32. package/src/integrations/installation/processes.ts +2 -41
  33. package/src/model/installation.ts +28 -36
  34. package/src/services/installation/install-service.ts +107 -0
  35. package/lib/common/package-source.js +0 -16
  36. package/lib/extension/setup/guard.js +0 -11
  37. package/lib/integrations/installation/pi-bridge.js +0 -131
  38. package/lib/model/installation.js +0 -1
  39. package/resources/installer/plugins.json +0 -16
  40. package/src/extension/cli/commands/setup.ts +0 -159
  41. package/src/extension/setup/guard.ts +0 -12
  42. package/src/integrations/installation/pi-bridge.ts +0 -109
  43. package/src/integrations/installation/pi-setup.ts +0 -165
  44. package/src/services/installation/setup-service.ts +0 -91
  45. package/src/ui/setup.ts +0 -40
@@ -4,13 +4,13 @@
4
4
  "command": "sh",
5
5
  "args": [
6
6
  "-c",
7
- "if pbot --at-least 0.3.3 </dev/null >/dev/null 2>&1; then exec pbot \"$@\"; fi\nexec npx --yes --ignore-scripts --prefer-offline personal-bot@0.3.5 \"$@\"",
7
+ "if pbot --at-least 0.3.3 </dev/null >/dev/null 2>&1; then exec pbot \"$@\"; fi\nexec npx --yes --ignore-scripts --prefer-offline personal-bot@0.3.6 \"$@\"",
8
8
  "pbot",
9
9
  "mcp"
10
10
  ],
11
11
  "env": {
12
12
  "PBOT_HOST": "qoder",
13
- "PBOT_PLUGIN_VERSION": "0.3.5"
13
+ "PBOT_PLUGIN_VERSION": "0.3.6"
14
14
  }
15
15
  }
16
16
  }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "personal-bot",
3
- "version": "0.3.5",
3
+ "version": "0.3.6",
4
4
  "description": "Personal Bot workspace context and cross-harness workers.",
5
5
  "skills": "./skills/",
6
6
  "mcpServers": "./.mcp.json"
@@ -5,7 +5,7 @@
5
5
  "hooks": [
6
6
  {
7
7
  "type": "command",
8
- "command": "PBOT_PLUGIN_VERSION=0.3.5 PBOT_PLUGIN_MANIFEST=\"${QODER_PLUGIN_ROOT:+$QODER_PLUGIN_ROOT/.qoder-plugin/plugin.json}\" sh -c 'if pbot --at-least 0.3.3 </dev/null >/dev/null 2>&1; then exec pbot \"$@\"; fi\nexec npx --yes --ignore-scripts --prefer-offline personal-bot@0.3.5 \"$@\"' pbot plugin qoder hook",
8
+ "command": "PBOT_PLUGIN_VERSION=0.3.6 PBOT_PLUGIN_MANIFEST=\"${QODER_PLUGIN_ROOT:+$QODER_PLUGIN_ROOT/.qoder-plugin/plugin.json}\" sh -c 'if pbot --at-least 0.3.3 </dev/null >/dev/null 2>&1; then exec pbot \"$@\"; fi\nexec npx --yes --ignore-scripts --prefer-offline personal-bot@0.3.6 \"$@\"' pbot plugin qoder hook",
9
9
  "timeout": 120
10
10
  }
11
11
  ]
@@ -16,7 +16,7 @@
16
16
  "hooks": [
17
17
  {
18
18
  "type": "command",
19
- "command": "PBOT_PLUGIN_VERSION=0.3.5 PBOT_PLUGIN_MANIFEST=\"${QODER_PLUGIN_ROOT:+$QODER_PLUGIN_ROOT/.qoder-plugin/plugin.json}\" sh -c 'if pbot --at-least 0.3.3 </dev/null >/dev/null 2>&1; then exec pbot \"$@\"; fi\nexec npx --yes --ignore-scripts --prefer-offline personal-bot@0.3.5 \"$@\"' pbot plugin qoder hook",
19
+ "command": "PBOT_PLUGIN_VERSION=0.3.6 PBOT_PLUGIN_MANIFEST=\"${QODER_PLUGIN_ROOT:+$QODER_PLUGIN_ROOT/.qoder-plugin/plugin.json}\" sh -c 'if pbot --at-least 0.3.3 </dev/null >/dev/null 2>&1; then exec pbot \"$@\"; fi\nexec npx --yes --ignore-scripts --prefer-offline personal-bot@0.3.6 \"$@\"' pbot plugin qoder hook",
20
20
  "timeout": 120
21
21
  }
22
22
  ]
@@ -27,7 +27,7 @@
27
27
  "hooks": [
28
28
  {
29
29
  "type": "command",
30
- "command": "PBOT_PLUGIN_VERSION=0.3.5 PBOT_PLUGIN_MANIFEST=\"${QODER_PLUGIN_ROOT:+$QODER_PLUGIN_ROOT/.qoder-plugin/plugin.json}\" sh -c 'if pbot --at-least 0.3.3 </dev/null >/dev/null 2>&1; then exec pbot \"$@\"; fi\nexec npx --yes --ignore-scripts --prefer-offline personal-bot@0.3.5 \"$@\"' pbot plugin qoder hook",
30
+ "command": "PBOT_PLUGIN_VERSION=0.3.6 PBOT_PLUGIN_MANIFEST=\"${QODER_PLUGIN_ROOT:+$QODER_PLUGIN_ROOT/.qoder-plugin/plugin.json}\" sh -c 'if pbot --at-least 0.3.3 </dev/null >/dev/null 2>&1; then exec pbot \"$@\"; fi\nexec npx --yes --ignore-scripts --prefer-offline personal-bot@0.3.6 \"$@\"' pbot plugin qoder hook",
31
31
  "timeout": 120
32
32
  }
33
33
  ]
@@ -6,4 +6,4 @@ disable-model-invocation: true
6
6
 
7
7
  使用当前会话的 `workspaceRoot` 作为 `--workspace`。省略子命令时使用 `status`。可执行 `init`、`status`、`history status|list|summary|migrate|search|read`。保留用户指定的维度、模型和筛选参数。
8
8
 
9
- 运行 `npx --yes personal-bot@0.3.5 <子命令> --workspace "<workspaceRoot>"`。如果 `pbot --at-least 0.3.5` 返回 0,也可以用 `pbot` 执行同一条命令。返回实际结果。
9
+ 运行 `npx --yes personal-bot@0.3.6 <子命令> --workspace "<workspaceRoot>"`。如果 `pbot --at-least 0.3.6` 返回 0,也可以用 `pbot` 执行同一条命令。返回实际结果。
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "personal-bot",
3
- "version": "0.3.5",
3
+ "version": "0.3.6",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -0,0 +1,77 @@
1
+ import { packageRoot } from "../../../common/paths.js";
2
+ import { getHostInstaller, listHostInstallers } from "../../../integrations/installation/installers/registry.js";
3
+ import { findExecutable, SetupProcesses } from "../../../integrations/installation/processes.js";
4
+ import type { HostInstallResult, WorkspaceInstallSummary } from "../../../model/installation.js";
5
+ import {
6
+ executeHostInstall,
7
+ formatInstallUsage,
8
+ parseInstallArgs,
9
+ } from "../../../services/installation/install-service.js";
10
+ import { CliError, resolveCliWorkspace, withSignals } from "../args.js";
11
+ import type { CliCommand } from "../types.js";
12
+
13
+ function formatLine(result: HostInstallResult): string {
14
+ const scope = result.scope ? ` (${result.scope})` : "";
15
+ const version = result.version ? ` ${result.version}` : "";
16
+ const head = `[${result.state}] ${result.host}${scope}${version}: ${result.detail}`;
17
+ return result.nextStep ? `${head}\n 下一步:${result.nextStep}` : head;
18
+ }
19
+
20
+ function printHumanSummary(summary: WorkspaceInstallSummary): void {
21
+ console.log(`工作区:${summary.workspaceRoot}`);
22
+ for (const result of summary.results) console.log(formatLine(result));
23
+ }
24
+
25
+ export const installCommand: CliCommand = {
26
+ name: "install",
27
+ summary: "为指定宿主或本机全部已安装宿主安装插件(pbot install <host|all>)",
28
+ get usage() {
29
+ return formatInstallUsage(listHostInstallers());
30
+ },
31
+ updatePolicy: "none",
32
+ supportsWorkspaceFlag: true,
33
+ supportsJsonFlag: true,
34
+ async run(ctx) {
35
+ const hosts = listHostInstallers();
36
+ let parsed: ReturnType<typeof parseInstallArgs>;
37
+ try {
38
+ parsed = parseInstallArgs(ctx.args, hosts);
39
+ } catch (error) {
40
+ throw new CliError(error instanceof Error ? error.message : String(error), 2);
41
+ }
42
+ if (parsed.help) {
43
+ console.log(formatInstallUsage(hosts));
44
+ return 0;
45
+ }
46
+ const workspaceArg = ctx.workspace ?? parsed.workspace;
47
+ const json = ctx.json || parsed.json;
48
+ const outcome = await withSignals(
49
+ async controller => {
50
+ const workspace = await resolveCliWorkspace(workspaceArg, ctx.cwd);
51
+ const processes = new SetupProcesses(controller.signal, process.env);
52
+ const summary = await executeHostInstall({
53
+ workspaceRoot: workspace,
54
+ target: parsed.target!,
55
+ hosts,
56
+ resolveInstaller: getHostInstaller,
57
+ createContext: (_host, explicit) => ({
58
+ workspace,
59
+ packageRoot,
60
+ explicit,
61
+ env: process.env,
62
+ signal: controller.signal,
63
+ options: { dshProfile: parsed.dshProfile },
64
+ run: (command, args, runCwd, runOptions) => processes.run(command, args, runCwd, runOptions),
65
+ findExecutable: name => findExecutable(name, process.env),
66
+ }),
67
+ signal: controller.signal,
68
+ });
69
+ if (json) console.log(JSON.stringify(summary, null, 2));
70
+ else printHumanSummary(summary);
71
+ return summary.ok ? 0 : 1;
72
+ },
73
+ () => console.error("安装已取消。"),
74
+ );
75
+ return outcome.ok ? outcome.value : outcome.exitCode;
76
+ },
77
+ };
@@ -7,9 +7,9 @@ import { workspacePluginReleases } from "../../services/workspace/plugin-release
7
7
  import { readWorkspaceConfig } from "../../services/workspace/workspace-config.js";
8
8
  import { CliError, extractCommonFlags, resolveCliWorkspace } from "./args.js";
9
9
  import { historyCommand } from "./commands/history.js";
10
+ import { installCommand } from "./commands/install.js";
10
11
  import { mcpCommand } from "./commands/mcp.js";
11
12
  import { pluginCommand } from "./commands/plugin.js";
12
- import { installAntigravityCommand, setupCommand } from "./commands/setup.js";
13
13
  import { upgradeCommand } from "./commands/upgrade.js";
14
14
  import { initCommand, statusCommand } from "./commands/workspace.js";
15
15
  import type { CliCommand, CliContext } from "./types.js";
@@ -17,12 +17,11 @@ import type { CliCommand, CliContext } from "./types.js";
17
17
  const commands: readonly CliCommand[] = [
18
18
  initCommand,
19
19
  statusCommand,
20
- historyCommand,
20
+ installCommand,
21
21
  upgradeCommand,
22
+ historyCommand,
22
23
  mcpCommand,
23
24
  pluginCommand,
24
- setupCommand,
25
- installAntigravityCommand,
26
25
  ];
27
26
 
28
27
  const commandIndex = new Map<string, CliCommand>();
@@ -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
+ };
@@ -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";