personal-bot 0.3.7 → 0.4.1

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 (172) hide show
  1. package/.claude-plugin/marketplace.json +3 -3
  2. package/.claude-plugin/plugin.json +2 -2
  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/architecture/design.md +2 -2
  7. package/docs/architecture/extensibility.md +4 -4
  8. package/docs/architecture/model-context.md +6 -3
  9. package/docs/guides/cross-harness-workers.md +5 -5
  10. package/docs/guides/history.md +1 -3
  11. package/docs/guides/workspace-configuration.md +5 -5
  12. package/docs/hosts/claude-code.md +3 -3
  13. package/docs/hosts/codex-qoder.md +4 -2
  14. package/hooks/hooks.json +3 -0
  15. package/lib/antigravity-plugin/bin/pbot-pi-acp.mjs +1 -1
  16. package/lib/antigravity-plugin/lib/extension/acp/member.d.ts +1 -1
  17. package/lib/antigravity-plugin/lib/extension/acp/member.js +11 -10
  18. package/lib/antigravity-plugin/lib/extension/acp-worker.js +349 -204
  19. package/lib/antigravity-plugin/lib/extension/cli.js +596 -572
  20. package/lib/antigravity-plugin/lib/extension/hosts/dsh/acp-member.js +1 -1
  21. package/lib/antigravity-plugin/lib/extension/hosts/pi/acp-member.js +3 -4
  22. package/lib/antigravity-plugin/lib/extension/hosts/plugin-runtime.js +1 -12
  23. package/lib/antigravity-plugin/lib/extension/mcp.js +463 -379
  24. package/lib/antigravity-plugin/lib/integrations/agent-resources.d.ts +2 -2
  25. package/lib/antigravity-plugin/lib/integrations/agent-resources.js +3 -3
  26. package/lib/antigravity-plugin/lib/integrations/hosts/antigravity/adapter.js +0 -1
  27. package/lib/antigravity-plugin/lib/integrations/hosts/claude/adapter.js +1 -2
  28. package/lib/antigravity-plugin/lib/integrations/hosts/dsh/resources.d.ts +1 -1
  29. package/lib/antigravity-plugin/lib/integrations/hosts/prompt-hooks.js +4 -7
  30. package/lib/antigravity-plugin/lib/model/acp.d.ts +29 -35
  31. package/lib/antigravity-plugin/lib/model/agent.d.ts +33 -17
  32. package/lib/antigravity-plugin/lib/model/agent.js +0 -1
  33. package/lib/antigravity-plugin/lib/services/history/summary-dimensions/monthly.js +1 -1
  34. package/lib/antigravity-plugin/lib/services/history/summary-dimensions/session.js +6 -3
  35. package/lib/antigravity-plugin/lib/services/history/summary-runner.js +3 -3
  36. package/lib/antigravity-plugin/lib/storage/acp-files.d.ts +5 -8
  37. package/lib/antigravity-plugin/lib/storage/acp-files.js +34 -40
  38. package/lib/antigravity-plugin/lib/storage/agent-files.d.ts +19 -10
  39. package/lib/antigravity-plugin/lib/storage/agent-files.js +147 -43
  40. package/lib/antigravity-plugin/lib/storage/history-files.js +3 -2
  41. package/lib/antigravity-plugin/package.json +1 -1
  42. package/lib/antigravity-plugin/plugin.json +2 -2
  43. package/lib/antigravity-plugin/resources/agents/coordinator.md +2 -4
  44. package/lib/antigravity-plugin/resources/agents/general-purpose.md +2 -4
  45. package/lib/antigravity-plugin/resources/prompts/history-monthly-summary.md +6 -11
  46. package/lib/antigravity-plugin/resources/prompts/history-summary.md +6 -11
  47. package/lib/antigravity-plugin/resources/prompts/plugin-coordinator.md +1 -1
  48. package/lib/antigravity-plugin/resources/prompts/workspace.md +16 -23
  49. package/lib/antigravity-plugin/resources/skills/project-maintenance/SKILL.md +14 -21
  50. package/lib/antigravity-plugin/resources/skills/provider-connections/SKILL.md +23 -36
  51. package/lib/antigravity-plugin/resources/templates/workspace-agents.md +5 -13
  52. package/lib/antigravity-plugin/skills/pbot/SKILL.md +6 -23
  53. package/lib/antigravity-plugin/skills/project-maintenance/SKILL.md +14 -21
  54. package/lib/antigravity-plugin/skills/provider-connections/SKILL.md +23 -36
  55. package/lib/codex-marketplace/plugins/personal-bot/.codex-plugin/plugin.json +2 -2
  56. package/lib/codex-marketplace/plugins/personal-bot/.mcp.json +2 -2
  57. package/lib/codex-marketplace/plugins/personal-bot/hooks/hooks.json +3 -3
  58. package/lib/codex-marketplace/plugins/personal-bot/skills/pbot/SKILL.md +11 -3
  59. package/lib/extension/acp/member.d.ts +1 -1
  60. package/lib/extension/acp/member.js +11 -10
  61. package/lib/extension/acp/worker.js +34 -33
  62. package/lib/extension/acp-worker.js +349 -204
  63. package/lib/extension/cli.js +596 -572
  64. package/lib/extension/hosts/dsh/acp-member.js +1 -1
  65. package/lib/extension/hosts/dsh/command.js +2 -2
  66. package/lib/extension/hosts/dsh/workspace.js +5 -5
  67. package/lib/extension/hosts/pi/acp-member.js +3 -4
  68. package/lib/extension/hosts/plugin-runtime.js +1 -12
  69. package/lib/extension/mcp/tool-contract.d.ts +8 -50
  70. package/lib/extension/mcp/tool-contract.js +61 -107
  71. package/lib/extension/mcp/workers.d.ts +7 -27
  72. package/lib/extension/mcp/workers.js +40 -24
  73. package/lib/extension/mcp.js +463 -379
  74. package/lib/integrations/acp/agents.d.ts +2 -3
  75. package/lib/integrations/acp/agents.js +22 -22
  76. package/lib/integrations/acp/harnesses/claude.js +1 -1
  77. package/lib/integrations/agent-resources.d.ts +2 -2
  78. package/lib/integrations/agent-resources.js +3 -3
  79. package/lib/integrations/hosts/antigravity/adapter.js +0 -1
  80. package/lib/integrations/hosts/claude/adapter.js +1 -2
  81. package/lib/integrations/hosts/dsh/resources.d.ts +1 -1
  82. package/lib/integrations/hosts/prompt-hooks.js +4 -7
  83. package/lib/model/acp.d.ts +29 -35
  84. package/lib/model/agent.d.ts +33 -17
  85. package/lib/model/agent.js +0 -1
  86. package/lib/qoder-plugin/.mcp.json +2 -2
  87. package/lib/qoder-plugin/.qoder-plugin/plugin.json +2 -2
  88. package/lib/qoder-plugin/hooks/hooks.json +3 -3
  89. package/lib/qoder-plugin/skills/pbot/SKILL.md +11 -3
  90. package/lib/services/agents/acp-run.d.ts +6 -4
  91. package/lib/services/agents/acp-run.js +62 -43
  92. package/lib/services/agents/agent-run.d.ts +10 -6
  93. package/lib/services/agents/agent-run.js +142 -65
  94. package/lib/services/agents/agent-service.d.ts +3 -21
  95. package/lib/services/agents/agent-service.js +182 -128
  96. package/lib/services/history/summary-dimensions/monthly.js +1 -1
  97. package/lib/services/history/summary-dimensions/session.js +6 -3
  98. package/lib/services/history/summary-runner.js +3 -3
  99. package/lib/storage/acp-files.d.ts +5 -8
  100. package/lib/storage/acp-files.js +34 -40
  101. package/lib/storage/agent-files.d.ts +19 -10
  102. package/lib/storage/agent-files.js +147 -43
  103. package/lib/storage/history-files.js +3 -2
  104. package/lib/tools/history/contract.d.ts +1 -1
  105. package/lib/tools/history/contract.js +14 -16
  106. package/package.json +2 -2
  107. package/resources/agents/coordinator.md +2 -4
  108. package/resources/agents/general-purpose.md +2 -4
  109. package/resources/antigravity/skills/pbot/SKILL.md +6 -23
  110. package/resources/claude/skills/pbot/SKILL.md +6 -23
  111. package/resources/plugin/skills/pbot/SKILL.md +11 -3
  112. package/resources/prompts/history-coordinator.md +1 -1
  113. package/resources/prompts/history-monthly-summary.md +6 -11
  114. package/resources/prompts/history-summary.md +6 -11
  115. package/resources/prompts/plugin-coordinator.md +1 -1
  116. package/resources/prompts/workspace.md +16 -23
  117. package/resources/skills/project-maintenance/SKILL.md +14 -21
  118. package/resources/skills/provider-connections/SKILL.md +23 -36
  119. package/resources/templates/workspace-agents.md +5 -13
  120. package/src/extension/acp/member.ts +14 -11
  121. package/src/extension/acp/worker.ts +31 -28
  122. package/src/extension/cli/commands/mcp.ts +1 -1
  123. package/src/extension/cli/commands/upgrade.ts +8 -36
  124. package/src/extension/cli/commands/workspace.ts +3 -8
  125. package/src/extension/cli/index.ts +1 -2
  126. package/src/extension/hosts/dsh/acp-member.ts +1 -1
  127. package/src/extension/hosts/dsh/command.ts +2 -2
  128. package/src/extension/hosts/dsh/workspace.ts +5 -4
  129. package/src/extension/hosts/pi/acp-member.ts +3 -4
  130. package/src/extension/hosts/pi/command.ts +2 -2
  131. package/src/extension/hosts/pi/events.ts +1 -1
  132. package/src/extension/hosts/pi/lifecycle.ts +0 -2
  133. package/src/extension/hosts/plugin-runtime.ts +1 -11
  134. package/src/extension/mcp/tool-contract.ts +61 -108
  135. package/src/extension/mcp/workers.ts +39 -24
  136. package/src/integrations/acp/agents.ts +28 -27
  137. package/src/integrations/acp/harnesses/claude.ts +1 -1
  138. package/src/integrations/agent-resources.ts +5 -5
  139. package/src/integrations/hosts/antigravity/adapter.ts +0 -1
  140. package/src/integrations/hosts/claude/adapter.ts +1 -2
  141. package/src/integrations/hosts/dsh/resources.ts +1 -1
  142. package/src/integrations/hosts/dsh/session.ts +2 -2
  143. package/src/integrations/hosts/prompt-hooks.ts +3 -6
  144. package/src/integrations/installation/cli-update.ts +2 -2
  145. package/src/integrations/installation/installers/claude.ts +4 -4
  146. package/src/integrations/installation/installers/qoder.ts +5 -5
  147. package/src/integrations/installation/upgraders/antigravity.ts +57 -15
  148. package/src/integrations/installation/upgraders/claude.ts +1 -4
  149. package/src/integrations/installation/upgraders/codex.ts +85 -15
  150. package/src/integrations/installation/upgraders/dsh.ts +46 -24
  151. package/src/integrations/installation/upgraders/pi.ts +18 -11
  152. package/src/integrations/installation/upgraders/qoder.ts +95 -20
  153. package/src/model/acp.ts +27 -29
  154. package/src/model/agent.ts +80 -16
  155. package/src/model/installation.ts +0 -2
  156. package/src/pbot.ts +3 -3
  157. package/src/services/agents/acp-run.ts +81 -49
  158. package/src/services/agents/agent-run.ts +154 -56
  159. package/src/services/agents/agent-service.ts +206 -135
  160. package/src/services/history/summary-dimensions/monthly.ts +1 -1
  161. package/src/services/history/summary-dimensions/session.ts +6 -3
  162. package/src/services/history/summary-runner.ts +3 -3
  163. package/src/services/installation/upgrade-service.ts +1 -5
  164. package/src/storage/acp-files.ts +50 -45
  165. package/src/storage/agent-files.ts +159 -46
  166. package/src/storage/history-files.ts +3 -2
  167. package/src/tools/history/contract.ts +14 -16
  168. package/lib/antigravity-plugin/lib/services/workspace/plugin-releases.d.ts +0 -15
  169. package/lib/antigravity-plugin/lib/services/workspace/plugin-releases.js +0 -126
  170. package/lib/services/workspace/plugin-releases.d.ts +0 -15
  171. package/lib/services/workspace/plugin-releases.js +0 -126
  172. package/src/services/workspace/plugin-releases.ts +0 -121
@@ -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
  };
@@ -42,24 +42,31 @@ async function readLocalPiVersion(workspace: string): Promise<string | undefined
42
42
  export const piUpgrader: HostUpgrader = {
43
43
  host: "pi",
44
44
  async upgrade(context: HostUpgradeContext): Promise<HostUpgradeResult> {
45
- const current = await readLocalPiVersion(context.workspace) ?? context.currentVersion;
46
- if (current && valid(current) && gte(current, context.targetVersion)) {
45
+ if (await hasCustomOnlySource(context.workspace)) {
47
46
  return {
48
47
  host: this.host,
49
- state: "up-to-date",
50
- previousVersion: current,
51
- version: current,
48
+ state: "skipped",
52
49
  scope: "local",
53
- detail: "已是最新版本。",
50
+ detail: "工作区 Pi 配置中的 personal-bot 使用非 npm 自定义来源,已保留当前配置。",
54
51
  };
55
52
  }
56
- if (await hasCustomOnlySource(context.workspace)) {
53
+ const current = await readLocalPiVersion(context.workspace);
54
+ if (!current) {
57
55
  return {
58
56
  host: this.host,
59
57
  state: "skipped",
60
- ...(current ? { previousVersion: current } : {}),
61
58
  scope: "local",
62
- detail: "工作区 Pi 配置中的 personal-bot 使用非 npm 自定义来源,已保留当前配置。",
59
+ detail: "当前工作区未通过 Pi 安装 personal-bot,已跳过。",
60
+ };
61
+ }
62
+ if (gte(current, context.targetVersion)) {
63
+ return {
64
+ host: this.host,
65
+ state: "up-to-date",
66
+ previousVersion: current,
67
+ version: current,
68
+ scope: "local",
69
+ detail: "已是最新版本。",
63
70
  };
64
71
  }
65
72
  const pi = context.env.PBOT_PI_COMMAND || await context.findExecutable("pi");
@@ -67,7 +74,7 @@ export const piUpgrader: HostUpgrader = {
67
74
  return {
68
75
  host: this.host,
69
76
  state: "skipped",
70
- ...(current ? { previousVersion: current } : {}),
77
+ previousVersion: current,
71
78
  scope: "local",
72
79
  detail: "未找到 Pi CLI(pi),已跳过。",
73
80
  };
@@ -77,7 +84,7 @@ export const piUpgrader: HostUpgrader = {
77
84
  return {
78
85
  host: this.host,
79
86
  state: "updated",
80
- ...(current ? { previousVersion: current } : {}),
87
+ previousVersion: current,
81
88
  version: installed,
82
89
  scope: "local",
83
90
  detail: `已通过 pi install --local 更新工作区 personal-bot 到 ${installed}。`,
@@ -1,9 +1,17 @@
1
- import { readFile } from "node:fs/promises";
1
+ import { readFile, realpath } from "node:fs/promises";
2
2
  import { join } from "node:path";
3
3
  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 QoderPluginEntry {
8
+ id: string;
9
+ name?: string;
10
+ version?: string;
11
+ scope?: string;
12
+ projectPath?: string;
13
+ }
14
+
7
15
  async function readManifestVersion(path: string): Promise<string | undefined> {
8
16
  try {
9
17
  const data: unknown = JSON.parse(await readFile(path, "utf8"));
@@ -14,16 +22,90 @@ async function readManifestVersion(path: string): Promise<string | undefined> {
14
22
  }
15
23
  }
16
24
 
25
+ function parsePluginList(raw: string): QoderPluginEntry[] {
26
+ const parsed: unknown = JSON.parse(raw);
27
+ const items = Array.isArray(parsed)
28
+ ? parsed
29
+ : object(parsed) && Array.isArray(parsed.plugins)
30
+ ? parsed.plugins
31
+ : [];
32
+ const entries: QoderPluginEntry[] = [];
33
+ for (const item of items) {
34
+ if (!object(item)) continue;
35
+ const id = typeof item.id === "string" ? item.id : typeof item.name === "string" ? item.name : undefined;
36
+ if (!id) continue;
37
+ entries.push({
38
+ id,
39
+ ...(typeof item.name === "string" ? { name: item.name } : {}),
40
+ ...(typeof item.version === "string" ? { version: item.version } : {}),
41
+ ...(typeof item.scope === "string" ? { scope: item.scope } : {}),
42
+ ...(typeof item.projectPath === "string" ? { projectPath: item.projectPath } : {}),
43
+ });
44
+ }
45
+ return entries;
46
+ }
47
+
48
+ async function resolvePathSafe(value: string): Promise<string> {
49
+ try { return await realpath(value); } catch { return value; }
50
+ }
51
+
52
+ async function selectMatchingEntry(entries: QoderPluginEntry[], workspace: string): Promise<QoderPluginEntry | undefined> {
53
+ const canonicalWorkspace = await resolvePathSafe(workspace);
54
+ const candidates = entries.filter(entry =>
55
+ entry.name === "personal-bot" || entry.id === "personal-bot" || entry.id.startsWith("personal-bot@"));
56
+ if (!candidates.length) return undefined;
57
+ const scopedMatches: QoderPluginEntry[] = [];
58
+ for (const entry of candidates) {
59
+ if (!entry.projectPath) {
60
+ scopedMatches.push(entry);
61
+ continue;
62
+ }
63
+ if (await resolvePathSafe(entry.projectPath) === canonicalWorkspace) scopedMatches.push(entry);
64
+ }
65
+ const priority = new Map<string, number>([["local", 0], ["project", 1], ["user", 2]]);
66
+ scopedMatches.sort((a, b) => (priority.get(a.scope ?? "") ?? 9) - (priority.get(b.scope ?? "") ?? 9));
67
+ return scopedMatches[0];
68
+ }
69
+
17
70
  export const qoderUpgrader: HostUpgrader = {
18
71
  host: "qoder",
19
72
  async upgrade(context: HostUpgradeContext): Promise<HostUpgradeResult> {
20
- if (context.currentVersion && valid(context.currentVersion) && gte(context.currentVersion, context.targetVersion)) {
73
+ const qodercli = context.env.PBOT_QODER_COMMAND || await context.findExecutable("qodercli");
74
+ if (!qodercli) {
75
+ return {
76
+ host: this.host,
77
+ state: "skipped",
78
+ detail: "未找到 Qoder CLI(qodercli),已跳过。",
79
+ };
80
+ }
81
+ let entries: QoderPluginEntry[];
82
+ try {
83
+ const raw = await context.run(qodercli, ["plugin", "list", "--json"], context.workspace);
84
+ entries = parsePluginList(raw);
85
+ } catch (error) {
86
+ return {
87
+ host: this.host,
88
+ state: "failed",
89
+ detail: `查询 Qoder CLI 插件列表失败:${error instanceof Error ? error.message : String(error)}`,
90
+ };
91
+ }
92
+ const entry = await selectMatchingEntry(entries, context.workspace);
93
+ if (!entry) {
94
+ return {
95
+ host: this.host,
96
+ state: "skipped",
97
+ detail: "未在 Qoder CLI 插件列表中找到 personal-bot,已跳过。",
98
+ };
99
+ }
100
+ const installedVersion = entry.version;
101
+ const scope = entry.scope ?? "user";
102
+ if (installedVersion && valid(installedVersion) && gte(installedVersion, context.targetVersion)) {
21
103
  return {
22
104
  host: this.host,
23
105
  state: "up-to-date",
24
- previousVersion: context.currentVersion,
25
- version: context.currentVersion,
26
- scope: "user",
106
+ previousVersion: installedVersion,
107
+ version: installedVersion,
108
+ scope,
27
109
  detail: "已是最新版本。",
28
110
  };
29
111
  }
@@ -33,7 +115,8 @@ export const qoderUpgrader: HostUpgrader = {
33
115
  return {
34
116
  host: this.host,
35
117
  state: "skipped",
36
- ...(context.currentVersion ? { previousVersion: context.currentVersion } : {}),
118
+ ...(installedVersion ? { previousVersion: installedVersion } : {}),
119
+ scope,
37
120
  detail: `缺少 Qoder CLI 插件构建产物:${pluginDir}`,
38
121
  };
39
122
  }
@@ -41,27 +124,19 @@ export const qoderUpgrader: HostUpgrader = {
41
124
  return {
42
125
  host: this.host,
43
126
  state: "skipped",
44
- ...(context.currentVersion ? { previousVersion: context.currentVersion } : {}),
127
+ ...(installedVersion ? { previousVersion: installedVersion } : {}),
128
+ scope,
45
129
  detail: `当前本地包产物版本为 ${bundledVersion},低于目标版本 ${context.targetVersion};请先更新全局 personal-bot 包。`,
46
130
  };
47
131
  }
48
- const qodercli = context.env.PBOT_QODER_COMMAND || await context.findExecutable("qodercli");
49
- if (!qodercli) {
50
- return {
51
- host: this.host,
52
- state: "skipped",
53
- ...(context.currentVersion ? { previousVersion: context.currentVersion } : {}),
54
- detail: "未找到 Qoder CLI(qodercli),已跳过。",
55
- };
56
- }
57
- await context.run(qodercli, ["plugin", "install", pluginDir], context.workspace);
132
+ await context.run(qodercli, ["plugin", "install", pluginDir, "--scope", scope], context.workspace);
58
133
  return {
59
134
  host: this.host,
60
135
  state: "updated",
61
- ...(context.currentVersion ? { previousVersion: context.currentVersion } : {}),
136
+ ...(installedVersion ? { previousVersion: installedVersion } : {}),
62
137
  version: bundledVersion,
63
- scope: "user",
64
- detail: `已通过 qodercli plugin install 更新到 ${bundledVersion}。`,
138
+ scope,
139
+ detail: `已按原有作用域(${scope})通过 qodercli plugin install 更新到 ${bundledVersion}。`,
65
140
  nextStep: "重启 Qoder CLI 会话使新版本生效。",
66
141
  };
67
142
  },
package/src/model/acp.ts CHANGED
@@ -46,8 +46,6 @@ export interface AcpModelsResult {
46
46
  currentThinking?: string;
47
47
  selection: AcpModelSelection;
48
48
  }
49
- export interface AcpModelState extends AcpModelSelection { generation: string }
50
- export interface AcpProcess { generation: string; pid: number; startedAt: number }
51
49
  export interface AcpInput { generation: string; requestId: string }
52
50
  export const acpAnswerStates = ["completed", "failed", "cancelled"] as const;
53
51
  export interface AcpAnswer extends AcpInput {
@@ -55,14 +53,6 @@ export interface AcpAnswer extends AcpInput {
55
53
  state: typeof acpAnswerStates[number];
56
54
  error?: string;
57
55
  }
58
- export interface AcpReport { generation: string; cycleId: string; text: string }
59
- export interface AcpPermission {
60
- generation: string;
61
- requestId: string;
62
- description: string;
63
- options: { optionId: string; name: string; kind: string }[];
64
- }
65
- export interface AcpPermissionReply { generation: string; requestId: string; optionId: string | null }
66
56
  export const acpElicitationActions = ["accept", "decline", "cancel"] as const;
67
57
  export type AcpElicitationAction = typeof acpElicitationActions[number];
68
58
  export type AcpElicitationValue = string | number | boolean | string[];
@@ -72,29 +62,37 @@ export function isAcpElicitationValue(value: unknown): value is AcpElicitationVa
72
62
  }
73
63
 
74
64
  export type AcpElicitationContent = Record<string, AcpElicitationValue>;
75
- export interface AcpElicitation {
76
- generation: string;
77
- requestId: string;
78
- mode: "form" | "url";
79
- message: string;
80
- schema?: Record<string, unknown>;
81
- url?: string;
82
- }
83
- export interface AcpElicitationReply {
84
- generation: string;
85
- requestId: string;
86
- action: AcpElicitationAction;
87
- content?: AcpElicitationContent;
88
- }
65
+ export type AcpInteraction =
66
+ | {
67
+ generation: string;
68
+ requestId: string;
69
+ kind: "permission";
70
+ description: string;
71
+ options: { optionId: string; name: string; kind: string }[];
72
+ }
73
+ | {
74
+ generation: string;
75
+ requestId: string;
76
+ kind: "form";
77
+ message: string;
78
+ schema: Record<string, unknown>;
79
+ }
80
+ | {
81
+ generation: string;
82
+ requestId: string;
83
+ kind: "url";
84
+ message: string;
85
+ url: string;
86
+ };
87
+ export type AcpInteractionReply =
88
+ | { generation: string; requestId: string; kind: "permission"; optionId: string | null }
89
+ | { generation: string; requestId: string; kind: "form"; action: AcpElicitationAction; content?: AcpElicitationContent }
90
+ | { generation: string; requestId: string; kind: "url"; action: AcpElicitationAction };
89
91
 
90
92
  export interface AcpStartOptions {
91
- name?: string;
92
- message?: string;
93
- files?: string[];
94
93
  provider?: string;
95
94
  model?: string;
96
95
  thinking?: string;
97
- cwd?: string;
98
96
  tools?: string[];
99
97
  noExtensions?: boolean;
100
98
  noSkills?: boolean;
@@ -104,7 +102,7 @@ export interface AcpStartOptions {
104
102
 
105
103
  export interface AcpLaunchContext {
106
104
  readonly reference: AcpSessionReference;
107
- readonly cwd: string;
105
+ readonly workspace: string;
108
106
  readonly directory: string;
109
107
  readonly packageRoot: string;
110
108
  readonly options: AcpStartOptions;