personal-bot 0.3.6 → 0.4.0

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 (143) hide show
  1. package/.claude-plugin/marketplace.json +2 -2
  2. package/.claude-plugin/plugin.json +1 -1
  3. package/README.md +5 -8
  4. package/README.zh-CN.md +5 -8
  5. package/bin/pbot-pi-acp.mjs +1 -1
  6. package/docs/README.md +1 -1
  7. package/docs/architecture/design.md +2 -2
  8. package/docs/architecture/extensibility.md +1 -1
  9. package/docs/architecture/model-context.md +1 -2
  10. package/docs/guides/capabilities.md +4 -8
  11. package/docs/guides/cross-harness-workers.md +4 -4
  12. package/docs/guides/history.md +1 -3
  13. package/docs/guides/workspace-configuration.md +4 -4
  14. package/docs/hosts/claude-code.md +2 -2
  15. package/docs/hosts/codex-qoder.md +1 -1
  16. package/lib/antigravity-plugin/bin/pbot-pi-acp.mjs +1 -1
  17. package/lib/antigravity-plugin/lib/extension/acp/member.d.ts +1 -1
  18. package/lib/antigravity-plugin/lib/extension/acp/member.js +11 -10
  19. package/lib/antigravity-plugin/lib/extension/acp-worker.js +348 -203
  20. package/lib/antigravity-plugin/lib/extension/cli.js +574 -549
  21. package/lib/antigravity-plugin/lib/extension/hosts/dsh/acp-member.js +1 -1
  22. package/lib/antigravity-plugin/lib/extension/hosts/pi/acp-member.js +3 -4
  23. package/lib/antigravity-plugin/lib/extension/hosts/plugin-runtime.js +0 -11
  24. package/lib/antigravity-plugin/lib/extension/mcp.js +462 -326
  25. package/lib/antigravity-plugin/lib/integrations/agent-resources.js +2 -2
  26. package/lib/antigravity-plugin/lib/model/acp.d.ts +29 -35
  27. package/lib/antigravity-plugin/lib/model/agent.d.ts +33 -17
  28. package/lib/antigravity-plugin/lib/model/agent.js +0 -1
  29. package/lib/antigravity-plugin/lib/storage/acp-files.d.ts +5 -8
  30. package/lib/antigravity-plugin/lib/storage/acp-files.js +34 -40
  31. package/lib/antigravity-plugin/lib/storage/agent-files.d.ts +19 -10
  32. package/lib/antigravity-plugin/lib/storage/agent-files.js +147 -43
  33. package/lib/antigravity-plugin/package.json +1 -1
  34. package/lib/antigravity-plugin/plugin.json +1 -1
  35. package/lib/antigravity-plugin/resources/agents/coordinator.md +3 -7
  36. package/lib/antigravity-plugin/resources/agents/general-purpose.md +3 -3
  37. package/lib/antigravity-plugin/resources/prompts/plugin-coordinator.md +1 -2
  38. package/lib/antigravity-plugin/resources/prompts/workspace.md +12 -16
  39. package/lib/antigravity-plugin/resources/skills/provider-connections/SKILL.md +7 -6
  40. package/lib/antigravity-plugin/resources/templates/workspace-agents.md +0 -4
  41. package/lib/antigravity-plugin/skills/pbot/SKILL.md +14 -6
  42. package/lib/antigravity-plugin/skills/provider-connections/SKILL.md +7 -6
  43. package/lib/codex-marketplace/plugins/personal-bot/.codex-plugin/plugin.json +1 -1
  44. package/lib/codex-marketplace/plugins/personal-bot/.mcp.json +2 -2
  45. package/lib/codex-marketplace/plugins/personal-bot/hooks/hooks.json +3 -3
  46. package/lib/codex-marketplace/plugins/personal-bot/skills/pbot/SKILL.md +2 -2
  47. package/lib/extension/acp/member.d.ts +1 -1
  48. package/lib/extension/acp/member.js +11 -10
  49. package/lib/extension/acp/worker.js +34 -33
  50. package/lib/extension/acp-worker.js +348 -203
  51. package/lib/extension/cli.js +574 -549
  52. package/lib/extension/hosts/dsh/acp-member.js +1 -1
  53. package/lib/extension/hosts/dsh/command.js +1 -1
  54. package/lib/extension/hosts/dsh/workspace.js +1 -3
  55. package/lib/extension/hosts/pi/acp-member.js +3 -4
  56. package/lib/extension/hosts/plugin-runtime.js +0 -11
  57. package/lib/extension/mcp/tool-contract.d.ts +8 -50
  58. package/lib/extension/mcp/tool-contract.js +48 -62
  59. package/lib/extension/mcp/workers.d.ts +13 -27
  60. package/lib/extension/mcp/workers.js +60 -25
  61. package/lib/extension/mcp.js +462 -326
  62. package/lib/integrations/acp/agents.d.ts +2 -3
  63. package/lib/integrations/acp/agents.js +22 -22
  64. package/lib/integrations/acp/harnesses/claude.js +1 -1
  65. package/lib/integrations/agent-resources.js +2 -2
  66. package/lib/model/acp.d.ts +29 -35
  67. package/lib/model/agent.d.ts +33 -17
  68. package/lib/model/agent.js +0 -1
  69. package/lib/qoder-plugin/.mcp.json +2 -2
  70. package/lib/qoder-plugin/.qoder-plugin/plugin.json +1 -1
  71. package/lib/qoder-plugin/hooks/hooks.json +3 -3
  72. package/lib/qoder-plugin/skills/pbot/SKILL.md +2 -2
  73. package/lib/services/agents/acp-run.d.ts +6 -4
  74. package/lib/services/agents/acp-run.js +62 -43
  75. package/lib/services/agents/agent-run.d.ts +10 -6
  76. package/lib/services/agents/agent-run.js +142 -65
  77. package/lib/services/agents/agent-service.d.ts +3 -21
  78. package/lib/services/agents/agent-service.js +180 -126
  79. package/lib/storage/acp-files.d.ts +5 -8
  80. package/lib/storage/acp-files.js +34 -40
  81. package/lib/storage/agent-files.d.ts +19 -10
  82. package/lib/storage/agent-files.js +147 -43
  83. package/lib/tools/history/contract.js +12 -12
  84. package/package.json +1 -1
  85. package/resources/agents/coordinator.md +3 -7
  86. package/resources/agents/general-purpose.md +3 -3
  87. package/resources/antigravity/skills/pbot/SKILL.md +14 -6
  88. package/resources/claude/skills/pbot/SKILL.md +14 -6
  89. package/resources/plugin/skills/pbot/SKILL.md +2 -2
  90. package/resources/prompts/history-coordinator.md +1 -2
  91. package/resources/prompts/plugin-coordinator.md +1 -2
  92. package/resources/prompts/workspace.md +12 -16
  93. package/resources/skills/provider-connections/SKILL.md +7 -6
  94. package/resources/templates/workspace-agents.md +0 -4
  95. package/src/extension/acp/member.ts +14 -11
  96. package/src/extension/acp/worker.ts +31 -28
  97. package/src/extension/cli/commands/upgrade.ts +8 -36
  98. package/src/extension/cli/commands/workspace.ts +3 -8
  99. package/src/extension/cli/index.ts +1 -2
  100. package/src/extension/hosts/dsh/acp-member.ts +1 -1
  101. package/src/extension/hosts/dsh/command.ts +1 -1
  102. package/src/extension/hosts/dsh/workspace.ts +1 -3
  103. package/src/extension/hosts/pi/acp-member.ts +3 -4
  104. package/src/extension/hosts/pi/command.ts +1 -1
  105. package/src/extension/hosts/pi/lifecycle.ts +0 -2
  106. package/src/extension/hosts/plugin-runtime.ts +0 -10
  107. package/src/extension/mcp/tool-contract.ts +48 -62
  108. package/src/extension/mcp/workers.ts +66 -27
  109. package/src/integrations/acp/agents.ts +28 -27
  110. package/src/integrations/acp/harnesses/claude.ts +1 -1
  111. package/src/integrations/agent-resources.ts +2 -2
  112. package/src/integrations/hosts/dsh/session.ts +2 -2
  113. package/src/integrations/installation/cli-update.ts +2 -2
  114. package/src/integrations/installation/installers/claude.ts +4 -4
  115. package/src/integrations/installation/installers/qoder.ts +5 -5
  116. package/src/integrations/installation/upgraders/antigravity.ts +57 -15
  117. package/src/integrations/installation/upgraders/claude.ts +1 -4
  118. package/src/integrations/installation/upgraders/codex.ts +85 -15
  119. package/src/integrations/installation/upgraders/dsh.ts +46 -24
  120. package/src/integrations/installation/upgraders/pi.ts +18 -11
  121. package/src/integrations/installation/upgraders/qoder.ts +95 -20
  122. package/src/model/acp.ts +27 -29
  123. package/src/model/agent.ts +80 -16
  124. package/src/model/installation.ts +0 -2
  125. package/src/pbot.ts +2 -2
  126. package/src/services/agents/acp-run.ts +81 -49
  127. package/src/services/agents/agent-run.ts +154 -56
  128. package/src/services/agents/agent-service.ts +204 -133
  129. package/src/services/installation/upgrade-service.ts +1 -5
  130. package/src/storage/acp-files.ts +50 -45
  131. package/src/storage/agent-files.ts +159 -46
  132. package/src/tools/history/contract.ts +12 -12
  133. package/lib/antigravity-plugin/lib/services/workspace/plugin-releases.d.ts +0 -15
  134. package/lib/antigravity-plugin/lib/services/workspace/plugin-releases.js +0 -126
  135. package/lib/antigravity-plugin/resources/references/compute-finance.md +0 -22
  136. package/lib/antigravity-plugin/resources/references/compute.md +0 -16
  137. package/lib/antigravity-plugin/resources/references/task-conductor.md +0 -25
  138. package/lib/services/workspace/plugin-releases.d.ts +0 -15
  139. package/lib/services/workspace/plugin-releases.js +0 -126
  140. package/resources/references/compute-finance.md +0 -22
  141. package/resources/references/compute.md +0 -16
  142. package/resources/references/task-conductor.md +0 -25
  143. package/src/services/workspace/plugin-releases.ts +0 -121
@@ -1,12 +1,10 @@
1
1
  import { fork, spawnSync } from "node:child_process";
2
2
  import { existsSync } from "node:fs";
3
- import { join, resolve } from "node:path";
3
+ import { resolve } from "node:path";
4
4
  import { setTimeout as delay } from "node:timers/promises";
5
- import type { AgentHost, AgentDescriptor, AgentOptions, AgentSessionReference } from "../../model/agent.js";
5
+ import type { AgentDescriptor, AgentHost, AgentOptions, AgentSessionReference } from "../../model/agent.js";
6
6
  import type { AcpBackend, AcpCommands, AcpModelsResult } from "../../model/acp.js";
7
- import { AgentFiles, launch } from "../../storage/agent-files.js";
8
- import { acpInput, acpProcess, acpReport } from "../../storage/acp-files.js";
9
- import { fileId } from "../../storage/file-access.js";
7
+ import { AgentFiles, status, workerRecord } from "../../storage/agent-files.js";
10
8
  import { requireThat } from "../../common/validation.js";
11
9
  import { resourceRoot } from "../../common/paths.js";
12
10
  import { acpLaunch, filterAcpStartOptions } from "./launch.js";
@@ -35,13 +33,13 @@ export class AcpWorkerHost implements AgentHost {
35
33
  }
36
34
 
37
35
  /** Probe a backend's advertised model and thinking choices in an isolated ACP process without prompting. */
38
- async inspectModels(backend: AcpBackend, cwd: string, options: Pick<AgentOptions, "provider" | "model"> = {}): Promise<AcpModelsResult> {
36
+ async inspectModels(backend: AcpBackend, workspace: string, options: Pick<AgentOptions, "provider" | "model"> = {}): Promise<AcpModelsResult> {
39
37
  this.available(backend);
40
38
  const filtered = this.filterOptions(backend, options);
41
39
  const reference = this.prepare(backend, filtered);
42
40
  return await new Promise<AcpModelsResult>((resolveResult, reject) => {
43
41
  const child = fork(this.worker, ["--probe"], {
44
- cwd, env: { ...process.env }, detached: true, stdio: ["ignore", "ignore", "ignore", "ipc"], execArgv: [],
42
+ cwd: workspace, env: { ...process.env }, detached: true, stdio: ["ignore", "ignore", "ignore", "ipc"], execArgv: [],
45
43
  });
46
44
  let result: AcpModelsResult | undefined, failure: Error | undefined;
47
45
  const timer = setTimeout(() => {
@@ -59,7 +57,7 @@ export class AcpWorkerHost implements AgentHost {
59
57
  child.once("spawn", () => {
60
58
  child.send({
61
59
  reference,
62
- cwd,
60
+ cwd: workspace,
63
61
  ...(filtered.provider ? { provider: filtered.provider } : {}),
64
62
  ...(filtered.model ? { model: filtered.model } : {}),
65
63
  });
@@ -72,9 +70,9 @@ export class AcpWorkerHost implements AgentHost {
72
70
  });
73
71
  }
74
72
 
75
- private process(id: string) {
76
- const record = this.files.optional(id, "acp-process.json", acpProcess);
77
- if (!record || this.files.read(id, "launch.json", launch).generation !== record.generation) return;
73
+ private process(id: string): { generation: string; pid: number } | undefined {
74
+ const record = this.files.optional(id, "worker.json", workerRecord);
75
+ if (!record?.pid) return;
78
76
  let denied = false;
79
77
  try { process.kill(-record.pid, 0); }
80
78
  catch (error) {
@@ -86,7 +84,7 @@ export class AcpWorkerHost implements AgentHost {
86
84
  const leader = spawnSync("ps", ["-p", String(record.pid), "-o", "args="], { encoding: "utf8" });
87
85
  // A dead leader can leave its group alive. A reused leader must match our exact launch identity.
88
86
  if (leader.status === 0 && !leader.stdout.includes("--pbot-acp-agent " + id + " --generation " + record.generation) || denied && leader.status !== 0) return;
89
- return record;
87
+ return { generation: record.generation, pid: record.pid };
90
88
  }
91
89
 
92
90
  alive(id: string) {
@@ -96,10 +94,11 @@ export class AcpWorkerHost implements AgentHost {
96
94
  async validateSession(d: AgentDescriptor, reference: AgentSessionReference) {
97
95
  requireThat(!this.alive(d.agentId), "ACP 成员仍在运行,不能恢复。");
98
96
  if (reference.sessionId === null) {
99
- requireThat(!this.files.optional(d.agentId, "acp-input.json", acpInput), "ACP 输入交付状态不明;请核对原请求后新建成员。");
97
+ const saved = this.files.optional(d.agentId, "state.json", status);
98
+ requireThat(!saved?.activeRequestId, "ACP 输入交付状态不明;请核对原请求后新建成员。");
100
99
  return;
101
100
  }
102
- const generation = this.files.read(d.agentId, "launch.json", launch).generation;
101
+ const generation = this.files.worker(d.agentId).generation;
103
102
  await new Promise<void>((resolveResult, reject) => {
104
103
  const child = this.spawn(d, generation, true);
105
104
  let validated = false, failure: Error | undefined;
@@ -119,7 +118,7 @@ export class AcpWorkerHost implements AgentHost {
119
118
  private spawn(d: AgentDescriptor, generation: string, validate = false) {
120
119
  return fork(this.worker, ["--pbot-acp-agent", d.agentId, "--generation", generation, "--directory", this.files.directory(d.agentId),
121
120
  ...(validate ? ["--validate"] : [])], {
122
- cwd: d.cwd, env: { ...process.env }, detached: true, stdio: ["ignore", "ignore", "ignore", "ipc"], execArgv: [],
121
+ cwd: d.workspace, env: { ...process.env }, detached: true, stdio: ["ignore", "ignore", "ignore", "ipc"], execArgv: [],
123
122
  });
124
123
  }
125
124
 
@@ -127,13 +126,22 @@ export class AcpWorkerHost implements AgentHost {
127
126
  signal.throwIfAborted();
128
127
  const child = this.spawn(d, generation);
129
128
  await new Promise<void>((resolveResult, reject) => { child.once("spawn", resolveResult); child.once("error", reject); });
130
- requireThat(child.pid, "ACP worker 没有进程身份。");
131
- try { this.files.write(d.agentId, "acp-process.json", { generation, pid: child.pid, startedAt: Date.now() }, acpProcess); }
132
- catch (error) {
133
- try { process.kill(-child.pid, "SIGKILL"); } catch (failure) { if ((failure as NodeJS.ErrnoException).code !== "ESRCH") throw new AggregateError([error, failure], "ACP 启动与清理失败。"); }
129
+ const pid = child.pid;
130
+ requireThat(pid, "ACP worker 没有进程身份。");
131
+ try {
132
+ this.files.control(() => {
133
+ const w = this.files.worker(d.agentId);
134
+ if (w.generation === generation) {
135
+ w.pid = pid;
136
+ this.files.write(d.agentId, "worker.json", w, workerRecord);
137
+ }
138
+ });
139
+ } catch (error) {
140
+ try { process.kill(-pid, "SIGKILL"); } catch (failure) { if ((failure as NodeJS.ErrnoException).code !== "ESRCH") throw new AggregateError([error, failure], "ACP 启动与清理失败。"); }
134
141
  throw error;
135
142
  }
136
- if (child.connected) child.disconnect(); child.unref();
143
+ if (child.connected) child.disconnect();
144
+ child.unref();
137
145
  if (signal.aborted) { await this.release(d.agentId, generation); signal.throwIfAborted(); }
138
146
  }
139
147
 
@@ -153,11 +161,4 @@ export class AcpWorkerHost implements AgentHost {
153
161
  const current = this.process(id);
154
162
  if (current?.generation === generation && current.pid === record.pid) terminate("SIGKILL");
155
163
  }
156
-
157
- report(d: AgentDescriptor, _reference: AgentSessionReference, leaf: string) {
158
- requireThat(leaf.startsWith("acp:"), "ACP 报告引用无效。");
159
- const cycleId = fileId(leaf.slice(4)), report = this.files.read(d.agentId, join("reports", cycleId + ".json"), acpReport);
160
- requireThat(report.cycleId === cycleId, "ACP 报告周期不匹配。");
161
- return report.text;
162
- }
163
164
  }
@@ -26,7 +26,7 @@ export const claudeAcpHarness: AcpHarnessAdapter = {
26
26
  },
27
27
  async prepareLaunch(context) {
28
28
  const base = defaultPrepareLaunch(context);
29
- const claude = await claudeOptions(base.command, context.cwd, context.options.thinking, context.features?.skills !== false);
29
+ const claude = await claudeOptions(base.command, context.workspace, context.options.thinking, context.features?.skills !== false);
30
30
  return {
31
31
  ...base,
32
32
  ...(claude.thinking ? { defaultThinking: claude.thinking } : {}),
@@ -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 = [
@@ -9,7 +9,7 @@ import type { AgentDescriptor } from "../../../model/agent.js";
9
9
  import { requireThat } from "../../../common/validation.js";
10
10
 
11
11
  function validateHeader(d: AgentDescriptor, header: SessionHeader) {
12
- requireThat(header.id === d.agentId && header.cwd === d.cwd && header.parentSession === d.parentSessionId &&
12
+ requireThat(header.id === d.agentId && header.cwd === d.workspace && header.parentSession === d.parentSessionId &&
13
13
  header.origin === "subagent" && !header.isSeeded, "dsh 专家会话身份、父会话或工作目录不匹配。");
14
14
  }
15
15
 
@@ -50,7 +50,7 @@ export async function openDshAgent(ctx: Context, d: AgentDescriptor, parent: Age
50
50
  return resume
51
51
  ? ctx.agents.resume({ resumeSessionId: SessionId(d.agentId), parentAgent: parent, agentOptions, setup: compose, signal })
52
52
  : ctx.agents.create({ sessionId: SessionId(d.agentId), parentAgent: parent,
53
- meta: { cwd: d.cwd, parentSession: parent.id, origin: "subagent", delegationDepth: 1 },
53
+ meta: { cwd: d.workspace, parentSession: parent.id, origin: "subagent", delegationDepth: 1 },
54
54
  agentOptions, setup: compose, signal });
55
55
  }
56
56
 
@@ -10,8 +10,8 @@ import { requireThat } from "../../common/validation.js";
10
10
  import { packageVersion } from "../../common/version.js";
11
11
 
12
12
  /** Check exact installed manifests, never resolve dependencies in an ancestor workspace. */
13
- export async function minimumCliRelease(root: string, plugins: Record<string, string>): Promise<string | undefined> {
14
- const versions = Object.values(plugins);
13
+ export async function minimumCliRelease(root: string): Promise<string | undefined> {
14
+ const versions: string[] = [];
15
15
  if (process.env.PBOT_PLUGIN_VERSION) versions.push(process.env.PBOT_PLUGIN_VERSION);
16
16
  for (const prefix of ["", ".pi/npm"]) {
17
17
  const path = join(root, prefix, "node_modules/personal-bot/package.json");
@@ -10,20 +10,20 @@ export const claudeInstaller: HostInstaller = {
10
10
  return {
11
11
  host: this.host,
12
12
  state: context.explicit ? "failed" : "skipped",
13
- scope: "user",
13
+ scope: "project",
14
14
  detail: "未找到 Claude Code CLI(claude)。请先安装 Claude Code 后重试。",
15
15
  };
16
16
  }
17
17
  await context.run(
18
18
  claude,
19
- ["plugin", "install", "personal-bot", "--marketplace", claudeMarketplace, "--yes"],
19
+ ["plugin", "install", "personal-bot", "--marketplace", claudeMarketplace, "--scope", "project", "--yes"],
20
20
  context.workspace,
21
21
  );
22
22
  return {
23
23
  host: this.host,
24
24
  state: "installed",
25
- scope: "user",
26
- detail: `已通过 claude plugin install 从 ${claudeMarketplace} 安装 personal-bot。`,
25
+ scope: "project",
26
+ detail: `已通过 claude plugin install(project 作用域)从 ${claudeMarketplace} 安装 personal-bot。`,
27
27
  nextStep: "在 Claude Code 目标工作区执行 /personal-bot:pbot init 启用 Personal Bot。",
28
28
  };
29
29
  },
@@ -22,7 +22,7 @@ export const qoderInstaller: HostInstaller = {
22
22
  return {
23
23
  host: this.host,
24
24
  state: context.explicit ? "failed" : "skipped",
25
- scope: "user",
25
+ scope: "project",
26
26
  detail: "未找到 Qoder CLI(qodercli)。请先安装 Qoder CLI 后重试。",
27
27
  };
28
28
  }
@@ -32,17 +32,17 @@ export const qoderInstaller: HostInstaller = {
32
32
  return {
33
33
  host: this.host,
34
34
  state: "failed",
35
- scope: "user",
35
+ scope: "project",
36
36
  detail: `缺少 Qoder CLI 插件构建产物:${pluginDir}。请先运行 npm run build。`,
37
37
  };
38
38
  }
39
- await context.run(qodercli, ["plugin", "install", pluginDir], context.workspace);
39
+ await context.run(qodercli, ["plugin", "install", pluginDir, "--scope", "project"], context.workspace);
40
40
  return {
41
41
  host: this.host,
42
42
  state: "installed",
43
43
  version: bundledVersion,
44
- scope: "user",
45
- detail: `已通过 qodercli plugin install 安装 Qoder CLI 插件(${bundledVersion})。`,
44
+ scope: "project",
45
+ detail: `已通过 qodercli plugin install(project 作用域)安装 Qoder CLI 插件(${bundledVersion})。`,
46
46
  nextStep: "在目标工作区执行 pbot plugin qoder init 启用 Personal Bot。",
47
47
  };
48
48
  },
@@ -4,6 +4,11 @@ import { gte, lt, valid } from "semver";
4
4
  import { object } from "../../../common/json.js";
5
5
  import type { HostUpgradeContext, HostUpgradeResult, HostUpgrader } from "../../../model/installation.js";
6
6
 
7
+ interface AntigravityPluginEntry {
8
+ name: string;
9
+ version?: string;
10
+ }
11
+
7
12
  async function readManifestVersion(path: string): Promise<string | undefined> {
8
13
  try {
9
14
  const data: unknown = JSON.parse(await readFile(path, "utf8"));
@@ -14,15 +19,61 @@ async function readManifestVersion(path: string): Promise<string | undefined> {
14
19
  }
15
20
  }
16
21
 
22
+ function parsePluginList(raw: string): AntigravityPluginEntry[] {
23
+ const parsed: unknown = JSON.parse(raw);
24
+ const items = Array.isArray(parsed)
25
+ ? parsed
26
+ : object(parsed) && Array.isArray(parsed.plugins)
27
+ ? parsed.plugins
28
+ : [];
29
+ const entries: AntigravityPluginEntry[] = [];
30
+ for (const item of items) {
31
+ if (!object(item) || typeof item.name !== "string") continue;
32
+ entries.push({
33
+ name: item.name,
34
+ ...(typeof item.version === "string" ? { version: item.version } : {}),
35
+ });
36
+ }
37
+ return entries;
38
+ }
39
+
17
40
  export const antigravityUpgrader: HostUpgrader = {
18
41
  host: "antigravity",
19
42
  async upgrade(context: HostUpgradeContext): Promise<HostUpgradeResult> {
20
- if (context.currentVersion && valid(context.currentVersion) && gte(context.currentVersion, context.targetVersion)) {
43
+ const agy = context.env.PBOT_AGY_COMMAND || await context.findExecutable("agy");
44
+ if (!agy) {
45
+ return {
46
+ host: this.host,
47
+ state: "skipped",
48
+ detail: "未找到 Antigravity CLI(agy),已跳过。",
49
+ };
50
+ }
51
+ let entries: AntigravityPluginEntry[];
52
+ try {
53
+ const raw = await context.run(agy, ["plugin", "list", "--json"], context.workspace);
54
+ entries = parsePluginList(raw);
55
+ } catch (error) {
56
+ return {
57
+ host: this.host,
58
+ state: "failed",
59
+ detail: `查询 Antigravity 插件列表失败:${error instanceof Error ? error.message : String(error)}`,
60
+ };
61
+ }
62
+ const entry = entries.find(item => item.name === "personal-bot");
63
+ if (!entry) {
64
+ return {
65
+ host: this.host,
66
+ state: "skipped",
67
+ detail: "未在 Antigravity 插件列表中找到 personal-bot,已跳过。",
68
+ };
69
+ }
70
+ const installedVersion = entry.version;
71
+ if (installedVersion && valid(installedVersion) && gte(installedVersion, context.targetVersion)) {
21
72
  return {
22
73
  host: this.host,
23
74
  state: "up-to-date",
24
- previousVersion: context.currentVersion,
25
- version: context.currentVersion,
75
+ previousVersion: installedVersion,
76
+ version: installedVersion,
26
77
  scope: "user",
27
78
  detail: "已是最新版本。",
28
79
  };
@@ -33,7 +84,7 @@ export const antigravityUpgrader: HostUpgrader = {
33
84
  return {
34
85
  host: this.host,
35
86
  state: "skipped",
36
- ...(context.currentVersion ? { previousVersion: context.currentVersion } : {}),
87
+ ...(installedVersion ? { previousVersion: installedVersion } : {}),
37
88
  detail: `缺少 Antigravity 插件构建产物:${pluginDir}`,
38
89
  };
39
90
  }
@@ -41,24 +92,15 @@ export const antigravityUpgrader: HostUpgrader = {
41
92
  return {
42
93
  host: this.host,
43
94
  state: "skipped",
44
- ...(context.currentVersion ? { previousVersion: context.currentVersion } : {}),
95
+ ...(installedVersion ? { previousVersion: installedVersion } : {}),
45
96
  detail: `当前本地包产物版本为 ${bundledVersion},低于目标版本 ${context.targetVersion};请先更新全局 personal-bot 包。`,
46
97
  };
47
98
  }
48
- const agy = context.env.PBOT_AGY_COMMAND || await context.findExecutable("agy");
49
- if (!agy) {
50
- return {
51
- host: this.host,
52
- state: "skipped",
53
- ...(context.currentVersion ? { previousVersion: context.currentVersion } : {}),
54
- detail: "未找到 Antigravity CLI(agy),已跳过。",
55
- };
56
- }
57
99
  await context.run(agy, ["plugin", "install", pluginDir], context.workspace);
58
100
  return {
59
101
  host: this.host,
60
102
  state: "updated",
61
- ...(context.currentVersion ? { previousVersion: context.currentVersion } : {}),
103
+ ...(installedVersion ? { previousVersion: installedVersion } : {}),
62
104
  version: bundledVersion,
63
105
  scope: "user",
64
106
  detail: `已通过 agy plugin install 更新到 ${bundledVersion}。`,
@@ -61,7 +61,6 @@ export const claudeUpgrader: HostUpgrader = {
61
61
  return {
62
62
  host: this.host,
63
63
  state: "skipped",
64
- ...(context.currentVersion ? { previousVersion: context.currentVersion } : {}),
65
64
  detail: "未找到 Claude Code CLI(claude),已跳过。",
66
65
  };
67
66
  }
@@ -73,7 +72,6 @@ export const claudeUpgrader: HostUpgrader = {
73
72
  return {
74
73
  host: this.host,
75
74
  state: "failed",
76
- ...(context.currentVersion ? { previousVersion: context.currentVersion } : {}),
77
75
  detail: `查询 Claude 插件列表失败:${error instanceof Error ? error.message : String(error)}`,
78
76
  };
79
77
  }
@@ -82,11 +80,10 @@ export const claudeUpgrader: HostUpgrader = {
82
80
  return {
83
81
  host: this.host,
84
82
  state: "skipped",
85
- ...(context.currentVersion ? { previousVersion: context.currentVersion } : {}),
86
83
  detail: "未在 Claude 插件列表中找到 personal-bot(可能通过 --plugin-dir 本地加载),已跳过。",
87
84
  };
88
85
  }
89
- const installedVersion = entry.version ?? context.currentVersion;
86
+ const installedVersion = entry.version;
90
87
  const scope = entry.scope ?? "user";
91
88
  if (installedVersion && valid(installedVersion) && gte(installedVersion, context.targetVersion)) {
92
89
  return {
@@ -4,6 +4,13 @@ import { gte, lt, valid } from "semver";
4
4
  import { object } from "../../../common/json.js";
5
5
  import type { HostUpgradeContext, HostUpgradeResult, HostUpgrader } from "../../../model/installation.js";
6
6
 
7
+ interface CodexPluginEntry {
8
+ id: string;
9
+ name?: string;
10
+ version?: string;
11
+ installed?: boolean;
12
+ }
13
+
7
14
  async function readManifestVersion(path: string): Promise<string | undefined> {
8
15
  try {
9
16
  const data: unknown = JSON.parse(await readFile(path, "utf8"));
@@ -14,15 +21,87 @@ async function readManifestVersion(path: string): Promise<string | undefined> {
14
21
  }
15
22
  }
16
23
 
24
+ function parsePluginList(raw: string): CodexPluginEntry[] {
25
+ const parsed: unknown = JSON.parse(raw);
26
+ const items = Array.isArray(parsed)
27
+ ? parsed
28
+ : object(parsed) && Array.isArray(parsed.installed)
29
+ ? parsed.installed
30
+ : object(parsed) && Array.isArray(parsed.plugins)
31
+ ? parsed.plugins
32
+ : [];
33
+ const entries: CodexPluginEntry[] = [];
34
+ for (const item of items) {
35
+ if (!object(item)) continue;
36
+ const id = typeof item.pluginId === "string"
37
+ ? item.pluginId
38
+ : typeof item.id === "string"
39
+ ? item.id
40
+ : typeof item.name === "string"
41
+ ? item.name
42
+ : undefined;
43
+ if (!id) continue;
44
+ entries.push({
45
+ id,
46
+ ...(typeof item.name === "string" ? { name: item.name } : {}),
47
+ ...(typeof item.version === "string" ? { version: item.version } : {}),
48
+ ...(typeof item.installed === "boolean" ? { installed: item.installed } : {}),
49
+ });
50
+ }
51
+ return entries;
52
+ }
53
+
54
+ function isMissingMarketplaceError(error: unknown): boolean {
55
+ const message = error instanceof Error ? error.message : String(error);
56
+ return /marketplace.*(not found|unknown|does not exist|not configured)|unknown marketplace/i.test(message);
57
+ }
58
+
17
59
  export const codexUpgrader: HostUpgrader = {
18
60
  host: "codex",
19
61
  async upgrade(context: HostUpgradeContext): Promise<HostUpgradeResult> {
20
- if (context.currentVersion && valid(context.currentVersion) && gte(context.currentVersion, context.targetVersion)) {
62
+ const codex = context.env.PBOT_CODEX_COMMAND || await context.findExecutable("codex");
63
+ if (!codex) {
64
+ return {
65
+ host: this.host,
66
+ state: "skipped",
67
+ detail: "未找到 Codex CLI(codex),已跳过。",
68
+ };
69
+ }
70
+ let entries: CodexPluginEntry[];
71
+ try {
72
+ const raw = await context.run(codex, ["plugin", "list", "-m", "pbot-local", "--json"], context.workspace);
73
+ entries = parsePluginList(raw);
74
+ } catch (error) {
75
+ if (isMissingMarketplaceError(error)) {
76
+ return {
77
+ host: this.host,
78
+ state: "skipped",
79
+ detail: "未在 Codex 插件列表中找到 personal-bot,已跳过。",
80
+ };
81
+ }
82
+ return {
83
+ host: this.host,
84
+ state: "failed",
85
+ detail: `查询 Codex 插件列表失败:${error instanceof Error ? error.message : String(error)}`,
86
+ };
87
+ }
88
+ const entry = entries.find(item =>
89
+ item.installed !== false
90
+ && (item.name === "personal-bot" || item.id === "personal-bot" || item.id.startsWith("personal-bot@")));
91
+ if (!entry) {
92
+ return {
93
+ host: this.host,
94
+ state: "skipped",
95
+ detail: "未在 Codex 插件列表中找到 personal-bot,已跳过。",
96
+ };
97
+ }
98
+ const installedVersion = entry.version;
99
+ if (installedVersion && valid(installedVersion) && gte(installedVersion, context.targetVersion)) {
21
100
  return {
22
101
  host: this.host,
23
102
  state: "up-to-date",
24
- previousVersion: context.currentVersion,
25
- version: context.currentVersion,
103
+ previousVersion: installedVersion,
104
+ version: installedVersion,
26
105
  scope: "user",
27
106
  detail: "已是最新版本。",
28
107
  };
@@ -33,7 +112,7 @@ export const codexUpgrader: HostUpgrader = {
33
112
  return {
34
113
  host: this.host,
35
114
  state: "skipped",
36
- ...(context.currentVersion ? { previousVersion: context.currentVersion } : {}),
115
+ ...(installedVersion ? { previousVersion: installedVersion } : {}),
37
116
  detail: `缺少 Codex 插件构建产物:${marketplaceDir}`,
38
117
  };
39
118
  }
@@ -41,19 +120,10 @@ export const codexUpgrader: HostUpgrader = {
41
120
  return {
42
121
  host: this.host,
43
122
  state: "skipped",
44
- ...(context.currentVersion ? { previousVersion: context.currentVersion } : {}),
123
+ ...(installedVersion ? { previousVersion: installedVersion } : {}),
45
124
  detail: `当前本地包产物版本为 ${bundledVersion},低于目标版本 ${context.targetVersion};请先更新全局 personal-bot 包。`,
46
125
  };
47
126
  }
48
- const codex = context.env.PBOT_CODEX_COMMAND || await context.findExecutable("codex");
49
- if (!codex) {
50
- return {
51
- host: this.host,
52
- state: "skipped",
53
- ...(context.currentVersion ? { previousVersion: context.currentVersion } : {}),
54
- detail: "未找到 Codex CLI(codex),已跳过。",
55
- };
56
- }
57
127
  try {
58
128
  await context.run(codex, ["plugin", "marketplace", "add", marketplaceDir], context.workspace);
59
129
  } catch {
@@ -63,7 +133,7 @@ export const codexUpgrader: HostUpgrader = {
63
133
  return {
64
134
  host: this.host,
65
135
  state: "updated",
66
- ...(context.currentVersion ? { previousVersion: context.currentVersion } : {}),
136
+ ...(installedVersion ? { previousVersion: installedVersion } : {}),
67
137
  version: bundledVersion,
68
138
  scope: "user",
69
139
  detail: `已通过 codex plugin add 更新到 ${bundledVersion}。`,
@@ -1,42 +1,64 @@
1
1
  import { gte, valid } from "semver";
2
+ import { object } from "../../../common/json.js";
2
3
  import type { HostUpgradeContext, HostUpgradeResult, HostUpgrader } from "../../../model/installation.js";
3
4
 
4
- export function inferDshProfile(bindingPath?: string): string | undefined {
5
- if (!bindingPath) return undefined;
6
- const normalized = bindingPath.replaceAll("\\", "/");
7
- const match = /\/profiles\/([^/]+)\/node_modules\/personal-bot\/package\.json$/.exec(normalized);
8
- return match?.[1];
5
+ function parseInstalledVersion(raw: string): string | undefined {
6
+ const trimmed = raw.trim();
7
+ if (!trimmed) return undefined;
8
+ const parsed: unknown = JSON.parse(trimmed);
9
+ const items = Array.isArray(parsed) ? parsed : [parsed];
10
+ for (const item of items) {
11
+ if (!object(item)) continue;
12
+ const deps = item.dependencies;
13
+ if (!object(deps)) continue;
14
+ const pkg = deps["personal-bot"];
15
+ if (object(pkg) && typeof pkg.version === "string" && valid(pkg.version)) return pkg.version;
16
+ }
17
+ return undefined;
9
18
  }
10
19
 
11
20
  export const dshUpgrader: HostUpgrader = {
12
21
  host: "dsh",
13
22
  async upgrade(context: HostUpgradeContext): Promise<HostUpgradeResult> {
14
- if (context.currentVersion && valid(context.currentVersion) && gte(context.currentVersion, context.targetVersion)) {
23
+ const profile = context.options.dshProfile || "pbot";
24
+ const scope = `profile:${profile}`;
25
+ const dsh = context.env.PBOT_DSH_COMMAND || await context.findExecutable("dsh");
26
+ if (!dsh) {
15
27
  return {
16
28
  host: this.host,
17
- state: "up-to-date",
18
- previousVersion: context.currentVersion,
19
- version: context.currentVersion,
20
- detail: "已是最新版本。",
29
+ state: "skipped",
30
+ scope,
31
+ detail: "未找到 dsh CLI(dsh),已跳过。",
21
32
  };
22
33
  }
23
- const profile = context.options.dshProfile || inferDshProfile(context.bindingPath);
24
- if (!profile) {
34
+ let installedVersion: string | undefined;
35
+ try {
36
+ const raw = await context.run(dsh, ["plugin", "--profile", profile, "list", "personal-bot", "--json"], context.workspace);
37
+ installedVersion = parseInstalledVersion(raw);
38
+ } catch (error) {
25
39
  return {
26
40
  host: this.host,
27
- state: "skipped",
28
- ...(context.currentVersion ? { previousVersion: context.currentVersion } : {}),
29
- detail: "无法自动识别 dsh profile;请传入 --dsh-profile <名称> 或手动执行:dsh plugin --profile <名称> update personal-bot --latest",
41
+ state: "failed",
42
+ scope,
43
+ detail: `查询 dsh profile "${profile}" 插件列表失败:${error instanceof Error ? error.message : String(error)}`,
30
44
  };
31
45
  }
32
- const dsh = context.env.PBOT_DSH_COMMAND || await context.findExecutable("dsh");
33
- if (!dsh) {
46
+ if (!installedVersion) {
34
47
  return {
35
48
  host: this.host,
36
49
  state: "skipped",
37
- ...(context.currentVersion ? { previousVersion: context.currentVersion } : {}),
38
- scope: `profile:${profile}`,
39
- detail: "未找到 dsh CLI(dsh),已跳过。",
50
+ scope,
51
+ detail: `dsh profile "${profile}" 中未安装 personal-bot,已跳过。`,
52
+ };
53
+ }
54
+ if (gte(installedVersion, context.targetVersion)) {
55
+ return {
56
+ host: this.host,
57
+ state: "up-to-date",
58
+ previousVersion: installedVersion,
59
+ version: installedVersion,
60
+ scope,
61
+ detail: "已是最新版本。",
40
62
  };
41
63
  }
42
64
  try {
@@ -45,17 +67,17 @@ export const dshUpgrader: HostUpgrader = {
45
67
  return {
46
68
  host: this.host,
47
69
  state: "failed",
48
- ...(context.currentVersion ? { previousVersion: context.currentVersion } : {}),
49
- scope: `profile:${profile}`,
70
+ previousVersion: installedVersion,
71
+ scope,
50
72
  detail: `${error instanceof Error ? error.message : String(error)}(提示:更新 dsh 插件前需先停止对应 profile 的 dsh 服务)`,
51
73
  };
52
74
  }
53
75
  return {
54
76
  host: this.host,
55
77
  state: "updated",
56
- ...(context.currentVersion ? { previousVersion: context.currentVersion } : {}),
78
+ previousVersion: installedVersion,
57
79
  version: context.targetVersion,
58
- scope: `profile:${profile}`,
80
+ scope,
59
81
  detail: `已更新 dsh profile "${profile}" 中的 personal-bot。`,
60
82
  nextStep: `重新启动 dsh --profile ${profile} 使新版本生效。`,
61
83
  };