personal-bot 0.3.5 → 0.3.7

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/docs/README.md +2 -2
  6. package/docs/architecture/design.md +3 -4
  7. package/docs/architecture/model-context.md +1 -2
  8. package/docs/guides/capabilities.md +4 -8
  9. package/docs/hosts/antigravity.md +4 -2
  10. package/docs/hosts/pi.md +4 -15
  11. package/docs/maintainers/release.md +2 -2
  12. package/lib/antigravity-plugin/lib/extension/acp-worker.js +2 -2
  13. package/lib/antigravity-plugin/lib/extension/cli.js +1403 -1504
  14. package/lib/antigravity-plugin/lib/extension/mcp.js +66 -49
  15. package/lib/antigravity-plugin/lib/integrations/agent-resources.js +2 -2
  16. package/lib/antigravity-plugin/package.json +1 -1
  17. package/lib/antigravity-plugin/plugin.json +1 -1
  18. package/lib/antigravity-plugin/resources/agents/coordinator.md +3 -7
  19. package/lib/antigravity-plugin/resources/agents/general-purpose.md +3 -3
  20. package/lib/antigravity-plugin/resources/prompts/plugin-coordinator.md +1 -2
  21. package/lib/antigravity-plugin/resources/prompts/workspace.md +12 -16
  22. package/lib/antigravity-plugin/resources/skills/provider-connections/SKILL.md +7 -6
  23. package/lib/antigravity-plugin/resources/templates/workspace-agents.md +0 -4
  24. package/lib/antigravity-plugin/skills/pbot/SKILL.md +14 -6
  25. package/lib/antigravity-plugin/skills/provider-connections/SKILL.md +7 -6
  26. package/lib/codex-marketplace/plugins/personal-bot/.codex-plugin/plugin.json +1 -1
  27. package/lib/codex-marketplace/plugins/personal-bot/.mcp.json +2 -2
  28. package/lib/codex-marketplace/plugins/personal-bot/hooks/hooks.json +3 -3
  29. package/lib/codex-marketplace/plugins/personal-bot/skills/pbot/SKILL.md +2 -2
  30. package/lib/extension/acp-worker.js +2 -2
  31. package/lib/extension/cli.js +1403 -1504
  32. package/lib/extension/mcp/tool-contract.js +49 -55
  33. package/lib/extension/mcp/workers.d.ts +6 -0
  34. package/lib/extension/mcp/workers.js +25 -8
  35. package/lib/extension/mcp.js +66 -49
  36. package/lib/integrations/agent-resources.js +2 -2
  37. package/lib/qoder-plugin/.mcp.json +2 -2
  38. package/lib/qoder-plugin/.qoder-plugin/plugin.json +1 -1
  39. package/lib/qoder-plugin/hooks/hooks.json +3 -3
  40. package/lib/qoder-plugin/skills/pbot/SKILL.md +2 -2
  41. package/lib/tools/history/contract.js +12 -12
  42. package/package.json +1 -1
  43. package/resources/agents/coordinator.md +3 -7
  44. package/resources/agents/general-purpose.md +3 -3
  45. package/resources/antigravity/skills/pbot/SKILL.md +14 -6
  46. package/resources/claude/skills/pbot/SKILL.md +14 -6
  47. package/resources/plugin/skills/pbot/SKILL.md +2 -2
  48. package/resources/prompts/history-coordinator.md +1 -2
  49. package/resources/prompts/plugin-coordinator.md +1 -2
  50. package/resources/prompts/workspace.md +12 -16
  51. package/resources/skills/provider-connections/SKILL.md +7 -6
  52. package/resources/templates/workspace-agents.md +0 -4
  53. package/src/extension/cli/commands/install.ts +77 -0
  54. package/src/extension/cli/index.ts +3 -4
  55. package/src/extension/mcp/tool-contract.ts +49 -55
  56. package/src/extension/mcp/workers.ts +32 -10
  57. package/src/integrations/agent-resources.ts +2 -2
  58. package/src/integrations/installation/installers/antigravity.ts +49 -0
  59. package/src/integrations/installation/installers/claude.ts +30 -0
  60. package/src/integrations/installation/installers/codex.ts +56 -0
  61. package/src/integrations/installation/installers/dsh.ts +25 -0
  62. package/src/integrations/installation/installers/pi.ts +26 -0
  63. package/src/integrations/installation/installers/qoder.ts +49 -0
  64. package/src/integrations/installation/installers/registry.ts +48 -0
  65. package/src/integrations/installation/processes.ts +2 -41
  66. package/src/model/installation.ts +28 -36
  67. package/src/pbot.ts +1 -1
  68. package/src/services/installation/install-service.ts +107 -0
  69. package/src/tools/history/contract.ts +12 -12
  70. package/lib/antigravity-plugin/resources/references/compute-finance.md +0 -22
  71. package/lib/antigravity-plugin/resources/references/compute.md +0 -16
  72. package/lib/antigravity-plugin/resources/references/task-conductor.md +0 -25
  73. package/lib/common/package-source.js +0 -16
  74. package/lib/extension/setup/guard.js +0 -11
  75. package/lib/integrations/installation/pi-bridge.js +0 -131
  76. package/lib/model/installation.js +0 -1
  77. package/resources/installer/plugins.json +0 -16
  78. package/resources/references/compute-finance.md +0 -22
  79. package/resources/references/compute.md +0 -16
  80. package/resources/references/task-conductor.md +0 -25
  81. package/src/extension/cli/commands/setup.ts +0 -159
  82. package/src/extension/setup/guard.ts +0 -12
  83. package/src/integrations/installation/pi-bridge.ts +0 -109
  84. package/src/integrations/installation/pi-setup.ts +0 -165
  85. package/src/services/installation/setup-service.ts +0 -91
  86. package/src/ui/setup.ts +0 -40
@@ -40,15 +40,27 @@ const progressIntervalMs = 5_000;
40
40
 
41
41
  export type ProgressReporter = (message: string) => void;
42
42
 
43
- export const mcpWorkerOnlyInstructions =
44
- "提供跨助手协作能力(worker_*):可启动并调度其他外部 AI 助手在当前工作区中独立执行任务,适用于用户指定其他助手、需要特定模型或思考深度、获取独立审查/第二意见,或并行处理子任务。不需要借助其他助手时,优先自行完成或使用当前内置子代理。\n" +
45
- "使用流程:用 worker_create 启动目标助手(或用 worker_discover 复用已有会话)→ 用 worker_request 派发任务或继续追问 → 任务完成后可用 worker_close 结束会话。后台等待、超时续等(timedOut)或长结果翻页(nextOffset)用 worker_output;助手请求授权或提问(needsResponse)时,先向用户确认,再用 worker_response 回复。";
43
+ const workerCapabilityInstruction =
44
+ "跨助手委派(worker_*):启动并调度其他外部助手在当前工作区独立执行任务;无需外部助手时优先自行完成或使用内置子代理。" +
45
+ "流程:worker_create 启动(或 worker_discover 复用)→ worker_request 派发/追问 → 完成后 worker_close;" +
46
+ "后台取结果、超时续等(timedOut)或翻页(nextOffset)用 worker_output;返回 needsResponse 时先向用户确认,再用 worker_response 回复。";
47
+
48
+ const workspaceMcpCapabilityInstruction =
49
+ "工作区共享 MCP(workspace_mcp_*):先用 workspace_mcp_discover 查 .pbot/mcp.json 中的服务与工具,再用 workspace_mcp_call 调用。";
50
+
51
+ const historyCapabilityInstruction =
52
+ "跨宿主历史(history_search / history_read):只读检索当前工作区跨宿主记录的历史问答与摘要归档。";
53
+
54
+ export function buildMcpInstructions(options: { workspaceMcp: boolean; history: boolean }): string {
55
+ const parts = [workerCapabilityInstruction];
56
+ if (options.workspaceMcp) parts.push(workspaceMcpCapabilityInstruction);
57
+ if (options.history) parts.push(historyCapabilityInstruction);
58
+ return parts.length === 1 ? parts[0]! : parts.map((text, index) => `${index + 1}. ${text}`).join("\n");
59
+ }
60
+
61
+ export const mcpWorkerOnlyInstructions = buildMcpInstructions({ workspaceMcp: false, history: false });
46
62
 
47
- export const mcpInstructions =
48
- "提供三类能力:\n" +
49
- "1. 跨助手协作(worker_*):启动并调度其他外部 AI 助手在当前工作区中独立执行任务,适用于用户指定其他助手、需要特定模型或思考深度、获取独立审查/第二意见,或并行处理子任务。不需要借助其他助手时,优先自行完成或使用当前内置子代理。使用流程:worker_create 启动助手(或 worker_discover 复用已有会话)→ worker_request 派发任务或追问 → 完成后 worker_close 结束;后台等待、超时续等(timedOut)或长结果翻页(nextOffset)用 worker_output;返回 needsResponse 时先向用户确认,再用 worker_response 回复。\n" +
50
- "2. 工作区共享外部工具(workspace_mcp_*):发现并调用当前工作区接入的外部工具服务与数据源(可与当前环境原生工具同时使用)。先用 workspace_mcp_discover 查看可用服务与工具说明,再用 workspace_mcp_call 调用。\n" +
51
- "3. 跨宿主历史查询(history_search / history_read):只读检索当前工作区在 Pi、dsh、Claude Code、Antigravity 等宿主中记录的历史问答与摘要归档。";
63
+ export const mcpInstructions = buildMcpInstructions({ workspaceMcp: true, history: true });
52
64
 
53
65
  export function defaultWorkerDirectory(): string {
54
66
  if (process.env.PBOT_MCP_AGENT_DIR) return process.env.PBOT_MCP_AGENT_DIR;
@@ -252,7 +264,7 @@ export class McpWorkerRuntime {
252
264
  return entry;
253
265
  }
254
266
 
255
- async toolDefinitions() {
267
+ private async resolveToolContext() {
256
268
  let commands: AcpCommands | undefined;
257
269
  let includeWorkspaceMcp = !this.#nativeWorkspaceMcp;
258
270
  let includeHistory = !this.#nativeHistory;
@@ -266,6 +278,16 @@ export class McpWorkerRuntime {
266
278
  includeHistory = !this.#nativeHistory && features.history;
267
279
  }
268
280
  } catch { /* Fall back to registered built-in harnesses when cwd is outside an enabled workspace. */ }
281
+ return { commands, includeWorkspaceMcp, includeHistory };
282
+ }
283
+
284
+ async serverInstructions(): Promise<string> {
285
+ const { includeWorkspaceMcp, includeHistory } = await this.resolveToolContext();
286
+ return buildMcpInstructions({ workspaceMcp: includeWorkspaceMcp, history: includeHistory });
287
+ }
288
+
289
+ async toolDefinitions() {
290
+ const { commands, includeWorkspaceMcp, includeHistory } = await this.resolveToolContext();
269
291
  const defaultBackend = this.#defaultBackend ? canonicalAcpBackend(this.#defaultBackend, commands) : undefined;
270
292
  const workspaceBound = Boolean(pluginMcpWorkspaceRoot());
271
293
  return [
@@ -556,7 +578,7 @@ export async function handleMcpRequest(
556
578
  protocolVersion: requested || protocolVersion,
557
579
  capabilities: { tools: {} },
558
580
  serverInfo: { name: "personal-bot", version: packageVersion },
559
- instructions: runtime.nativeWorkspaceMcp ? mcpWorkerOnlyInstructions : mcpInstructions,
581
+ instructions: await runtime.serverInstructions(),
560
582
  },
561
583
  };
562
584
  }
@@ -37,7 +37,7 @@ export async function agentText(
37
37
  export function formatWorkspaceSkills(skills: readonly WorkspaceSkillMeta[]): string {
38
38
  if (!skills.length) return "";
39
39
  const lines = skills.map(skill => `- **${skill.name}**(\`${skill.path}\`):${skill.description}`);
40
- return "## 工作区技能\n\n匹配任务时按需读取对应 `SKILL.md` 正文:\n" + lines.join("\n");
40
+ return "## 可用技能\n\n任务匹配时按需读取对应 `SKILL.md` 正文:\n" + lines.join("\n");
41
41
  }
42
42
 
43
43
  export async function loadWorkspaceContext(options: {
@@ -71,7 +71,7 @@ export async function loadWorkspaceContext(options: {
71
71
  : ["", "", ""];
72
72
  const skillsSection = formatWorkspaceSkills(workspaceSkills);
73
73
  const noticesSection = notices.length
74
- ? "## 启动提示\n\n" + notices.map(item => `- ${item}`).join("\n")
74
+ ? "## 启动提示\n\n以下为工作区维护提醒,适时顺带告知用户即可,勿未经用户要求自行执行:\n" + notices.map(item => `- ${item}`).join("\n")
75
75
  : "";
76
76
  const environment = { host, workspaceRoot: root, resourceRoot };
77
77
  const text = [
@@ -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";
package/src/pbot.ts CHANGED
@@ -34,7 +34,7 @@ export default function pbot(pi: ExtensionAPI) {
34
34
  ...server,
35
35
  exposure: "direct",
36
36
  timeout: 600,
37
- description: "跨代理程序委派(worker_*)",
37
+ description: "跨助手委派(worker_*)",
38
38
  });
39
39
  registeredMcpServers.push(mcpServerName);
40
40
  }
@@ -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
+ }