personal-bot 0.3.2 → 0.3.4

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 (318) hide show
  1. package/.claude-plugin/marketplace.json +2 -2
  2. package/.claude-plugin/plugin.json +2 -1
  3. package/DISCLAIMER.md +17 -0
  4. package/LICENSE +21 -0
  5. package/README.md +15 -5
  6. package/README.zh-CN.md +15 -5
  7. package/bin/pbot-pi-acp.mjs +1 -1
  8. package/bin/pbot.mjs +22 -2
  9. package/docs/README.md +2 -0
  10. package/docs/architecture/design.md +16 -16
  11. package/docs/architecture/extensibility.md +29 -2
  12. package/docs/architecture/model-context.md +3 -2
  13. package/docs/architecture/principles.md +2 -2
  14. package/docs/guides/capabilities.md +1 -1
  15. package/docs/guides/cross-harness-workers.md +3 -1
  16. package/docs/guides/history.md +30 -7
  17. package/docs/guides/workspace-configuration.md +20 -3
  18. package/docs/hosts/antigravity.md +1 -1
  19. package/docs/hosts/claude-code.md +1 -1
  20. package/docs/hosts/codex-qoder.md +63 -0
  21. package/docs/maintainers/architecture-governance.md +78 -0
  22. package/lib/antigravity-plugin/DISCLAIMER.md +17 -0
  23. package/lib/antigravity-plugin/LICENSE +21 -0
  24. package/lib/antigravity-plugin/bin/pbot-pi-acp.mjs +36 -0
  25. package/lib/antigravity-plugin/lib/common/files.d.ts +2 -0
  26. package/lib/antigravity-plugin/lib/common/files.js +44 -0
  27. package/lib/antigravity-plugin/lib/common/validation.d.ts +4 -0
  28. package/lib/antigravity-plugin/lib/common/validation.js +8 -0
  29. package/lib/antigravity-plugin/lib/extension/acp/member.d.ts +18 -0
  30. package/lib/antigravity-plugin/lib/extension/acp/member.js +44 -0
  31. package/lib/antigravity-plugin/lib/extension/acp-worker.js +71 -45
  32. package/lib/antigravity-plugin/lib/extension/hosts/dsh/acp-entry.d.ts +1 -0
  33. package/lib/antigravity-plugin/lib/extension/hosts/dsh/acp-entry.js +22 -0
  34. package/lib/antigravity-plugin/lib/extension/hosts/dsh/acp-member.d.ts +4 -0
  35. package/lib/antigravity-plugin/lib/extension/hosts/dsh/acp-member.js +58 -0
  36. package/lib/antigravity-plugin/lib/extension/hosts/dsh/files.d.ts +5 -0
  37. package/lib/antigravity-plugin/lib/extension/hosts/dsh/files.js +67 -0
  38. package/lib/antigravity-plugin/lib/extension/hosts/pi/acp-member.d.ts +3 -0
  39. package/lib/antigravity-plugin/lib/extension/hosts/pi/acp-member.js +100 -0
  40. package/lib/antigravity-plugin/lib/extension/hosts/plugin-runtime.d.ts +3 -1
  41. package/lib/antigravity-plugin/lib/extension/hosts/plugin-runtime.js +37 -22
  42. package/lib/antigravity-plugin/lib/extension/hosts/workspace-mcp.d.ts +6 -0
  43. package/lib/antigravity-plugin/lib/extension/hosts/workspace-mcp.js +21 -0
  44. package/lib/antigravity-plugin/lib/extension/mcp.js +2577 -2255
  45. package/lib/antigravity-plugin/lib/extension/workspace-cli.js +20171 -0
  46. package/lib/antigravity-plugin/lib/integrations/agent-resources.js +1 -1
  47. package/lib/antigravity-plugin/lib/integrations/hosts/claude/adapter.js +7 -59
  48. package/lib/antigravity-plugin/lib/integrations/hosts/codex/adapter.d.ts +2 -0
  49. package/lib/antigravity-plugin/lib/integrations/hosts/codex/adapter.js +14 -0
  50. package/lib/antigravity-plugin/lib/integrations/hosts/dsh/mcp.d.ts +4 -0
  51. package/lib/antigravity-plugin/lib/integrations/hosts/dsh/mcp.js +28 -0
  52. package/lib/antigravity-plugin/lib/integrations/hosts/dsh/messages.d.ts +36 -0
  53. package/lib/antigravity-plugin/lib/integrations/hosts/dsh/messages.js +11 -0
  54. package/lib/antigravity-plugin/lib/integrations/hosts/dsh/resources.d.ts +6 -0
  55. package/lib/antigravity-plugin/lib/integrations/hosts/dsh/resources.js +47 -0
  56. package/lib/antigravity-plugin/lib/integrations/hosts/dsh/root-agents.d.ts +4 -0
  57. package/lib/antigravity-plugin/lib/integrations/hosts/dsh/root-agents.js +3 -0
  58. package/lib/antigravity-plugin/lib/integrations/hosts/dsh/skills.d.ts +8 -0
  59. package/lib/antigravity-plugin/lib/integrations/hosts/dsh/skills.js +31 -0
  60. package/lib/antigravity-plugin/lib/integrations/hosts/pi/agent-tools.d.ts +3 -0
  61. package/lib/antigravity-plugin/lib/integrations/hosts/pi/agent-tools.js +32 -0
  62. package/lib/antigravity-plugin/lib/integrations/hosts/pi/mcp.d.ts +4 -0
  63. package/lib/antigravity-plugin/lib/integrations/hosts/pi/mcp.js +23 -0
  64. package/lib/antigravity-plugin/lib/integrations/hosts/plugin-registry.d.ts +1 -0
  65. package/lib/antigravity-plugin/lib/integrations/hosts/plugin-registry.js +8 -1
  66. package/lib/antigravity-plugin/lib/integrations/hosts/prompt-hooks.d.ts +76 -0
  67. package/lib/antigravity-plugin/lib/integrations/hosts/prompt-hooks.js +76 -0
  68. package/lib/antigravity-plugin/lib/integrations/hosts/qoder/adapter.d.ts +2 -0
  69. package/lib/antigravity-plugin/lib/integrations/hosts/qoder/adapter.js +16 -0
  70. package/lib/antigravity-plugin/lib/model/acp.d.ts +7 -3
  71. package/lib/antigravity-plugin/lib/model/acp.js +8 -0
  72. package/lib/antigravity-plugin/lib/model/agent.d.ts +121 -0
  73. package/lib/antigravity-plugin/lib/model/agent.js +4 -0
  74. package/lib/antigravity-plugin/lib/model/history.d.ts +10 -0
  75. package/lib/antigravity-plugin/lib/model/history.js +4 -1
  76. package/lib/antigravity-plugin/lib/model/plugin-host.d.ts +5 -0
  77. package/lib/antigravity-plugin/lib/model/workspace-config.d.ts +8 -12
  78. package/lib/antigravity-plugin/lib/model/workspace-config.js +2 -1
  79. package/lib/antigravity-plugin/lib/plugin.d.ts +2 -1
  80. package/lib/antigravity-plugin/lib/plugin.js +2 -2
  81. package/lib/antigravity-plugin/lib/services/history/history-capture.js +34 -22
  82. package/lib/antigravity-plugin/lib/services/history/summary-registry.js +2 -3
  83. package/lib/antigravity-plugin/lib/services/history/summary-runner.d.ts +2 -5
  84. package/lib/antigravity-plugin/lib/services/history/summary-runner.js +72 -74
  85. package/lib/antigravity-plugin/lib/services/history/workspace-history.d.ts +3 -0
  86. package/lib/antigravity-plugin/lib/services/history/workspace-history.js +6 -0
  87. package/lib/antigravity-plugin/lib/services/workspace/plugin-releases.d.ts +15 -0
  88. package/lib/antigravity-plugin/lib/services/workspace/plugin-releases.js +126 -0
  89. package/lib/antigravity-plugin/lib/services/workspace/workspace-config.js +9 -8
  90. package/lib/antigravity-plugin/lib/services/workspace/workspace-files.d.ts +2 -0
  91. package/lib/antigravity-plugin/lib/services/workspace/workspace-files.js +17 -0
  92. package/lib/antigravity-plugin/lib/services/workspace/workspace-mcp.d.ts +14 -0
  93. package/lib/antigravity-plugin/lib/services/workspace/workspace-mcp.js +193 -0
  94. package/lib/antigravity-plugin/lib/services/workspace/workspace-skills.d.ts +1 -0
  95. package/lib/antigravity-plugin/lib/services/workspace/workspace-skills.js +4 -2
  96. package/lib/antigravity-plugin/lib/storage/acp-files.d.ts +11 -0
  97. package/lib/antigravity-plugin/lib/storage/acp-files.js +75 -0
  98. package/lib/antigravity-plugin/lib/storage/agent-files.d.ts +31 -0
  99. package/lib/antigravity-plugin/lib/storage/agent-files.js +159 -0
  100. package/lib/antigravity-plugin/lib/storage/atomic-json.d.ts +3 -1
  101. package/lib/antigravity-plugin/lib/storage/atomic-json.js +43 -3
  102. package/lib/antigravity-plugin/lib/storage/history-files.d.ts +2 -1
  103. package/lib/antigravity-plugin/lib/storage/history-files.js +21 -15
  104. package/lib/antigravity-plugin/lib/storage/history-format.d.ts +2 -3
  105. package/lib/antigravity-plugin/lib/storage/history-format.js +5 -7
  106. package/lib/antigravity-plugin/package.json +1 -1
  107. package/lib/antigravity-plugin/plugin.json +1 -1
  108. package/lib/antigravity-plugin/resources/prompts/history-monthly-summary.md +13 -0
  109. package/lib/antigravity-plugin/resources/prompts/history-summary.md +13 -0
  110. package/lib/antigravity-plugin/resources/prompts/plugin-coordinator.md +1 -0
  111. package/lib/antigravity-plugin/resources/skills/.claude-plugin/plugin.json +4 -0
  112. package/lib/antigravity-plugin/resources/skills/project-maintenance/SKILL.md +35 -0
  113. package/lib/antigravity-plugin/resources/skills/provider-connections/SKILL.md +52 -0
  114. package/lib/antigravity-plugin/skills/pbot/SKILL.md +11 -1
  115. package/lib/client.js +22 -50
  116. package/lib/codex-marketplace/.agents/plugins/marketplace.json +17 -0
  117. package/lib/codex-marketplace/plugins/personal-bot/.codex-plugin/plugin.json +7 -0
  118. package/lib/codex-marketplace/plugins/personal-bot/.mcp.json +17 -0
  119. package/lib/codex-marketplace/plugins/personal-bot/DISCLAIMER.md +17 -0
  120. package/lib/codex-marketplace/plugins/personal-bot/LICENSE +21 -0
  121. package/lib/codex-marketplace/plugins/personal-bot/hooks/hooks.json +37 -0
  122. package/lib/codex-marketplace/plugins/personal-bot/skills/pbot/SKILL.md +9 -0
  123. package/lib/codex-marketplace/plugins/personal-bot/skills/pbot/agents/openai.yaml +2 -0
  124. package/lib/common/validation.d.ts +4 -0
  125. package/lib/common/validation.js +8 -0
  126. package/lib/dsh.js +2 -2
  127. package/lib/extension/acp/member.d.ts +1 -1
  128. package/lib/extension/acp-worker.js +71 -45
  129. package/lib/extension/history/command.d.ts +37 -0
  130. package/lib/extension/history/command.js +57 -0
  131. package/lib/extension/hosts/dsh/acp-entry.d.ts +1 -0
  132. package/lib/extension/hosts/dsh/acp-entry.js +22 -0
  133. package/lib/extension/hosts/dsh/acp-member.js +4 -18
  134. package/lib/extension/hosts/dsh/command.d.ts +1 -2
  135. package/lib/extension/hosts/dsh/command.js +5 -49
  136. package/lib/extension/hosts/dsh/workspace.js +13 -44
  137. package/lib/extension/hosts/pi/acp-member.d.ts +3 -0
  138. package/lib/extension/hosts/pi/acp-member.js +100 -0
  139. package/lib/extension/hosts/plugin-runtime.d.ts +3 -1
  140. package/lib/extension/hosts/plugin-runtime.js +37 -22
  141. package/lib/extension/hosts/workspace-mcp.d.ts +6 -0
  142. package/lib/extension/hosts/workspace-mcp.js +21 -0
  143. package/lib/extension/mcp/bridge.d.ts +6 -8
  144. package/lib/extension/mcp/bridge.js +66 -84
  145. package/lib/extension/mcp/tool-contract.d.ts +735 -0
  146. package/lib/extension/mcp/tool-contract.js +441 -0
  147. package/lib/extension/mcp/workers.d.ts +29 -742
  148. package/lib/extension/mcp/workers.js +75 -525
  149. package/lib/extension/mcp.js +2577 -2255
  150. package/lib/extension/setup/cli.js +15 -0
  151. package/lib/extension/setup/upgrade.js +153 -0
  152. package/lib/extension/workspace-cli.js +20171 -0
  153. package/lib/integrations/acp/agents.d.ts +2 -3
  154. package/lib/integrations/acp/harnesses/dsh.js +1 -1
  155. package/lib/integrations/acp/harnesses/presets.js +8 -0
  156. package/lib/integrations/acp/history-summary.js +2 -1
  157. package/lib/integrations/acp/launch.d.ts +2 -2
  158. package/lib/integrations/agent-resources.js +1 -1
  159. package/lib/integrations/hosts/claude/adapter.js +7 -59
  160. package/lib/integrations/hosts/codex/adapter.d.ts +2 -0
  161. package/lib/integrations/hosts/codex/adapter.js +14 -0
  162. package/lib/integrations/hosts/pi/agent-tools.d.ts +3 -0
  163. package/lib/integrations/hosts/pi/agent-tools.js +32 -0
  164. package/lib/integrations/hosts/pi/mcp.d.ts +4 -0
  165. package/lib/integrations/hosts/pi/mcp.js +23 -0
  166. package/lib/integrations/hosts/plugin-registry.d.ts +1 -0
  167. package/lib/integrations/hosts/plugin-registry.js +8 -1
  168. package/lib/integrations/hosts/prompt-hooks.d.ts +76 -0
  169. package/lib/integrations/hosts/prompt-hooks.js +76 -0
  170. package/lib/integrations/hosts/qoder/adapter.d.ts +2 -0
  171. package/lib/integrations/hosts/qoder/adapter.js +16 -0
  172. package/lib/integrations/installation/cli-update.js +146 -0
  173. package/lib/integrations/installation/upgraders/antigravity.js +67 -0
  174. package/lib/integrations/installation/upgraders/claude.js +123 -0
  175. package/lib/integrations/installation/upgraders/codex.js +73 -0
  176. package/lib/integrations/installation/upgraders/dsh.js +62 -0
  177. package/lib/integrations/installation/upgraders/pi.js +90 -0
  178. package/lib/integrations/installation/upgraders/qoder.js +67 -0
  179. package/lib/integrations/installation/upgraders/registry.js +40 -0
  180. package/lib/model/acp.d.ts +7 -3
  181. package/lib/model/acp.js +8 -0
  182. package/lib/model/agent.d.ts +18 -4
  183. package/lib/model/agent.js +4 -1
  184. package/lib/model/history.d.ts +10 -0
  185. package/lib/model/history.js +4 -1
  186. package/lib/model/installation.js +1 -0
  187. package/lib/model/plugin-host.d.ts +5 -0
  188. package/lib/model/workspace-config.d.ts +8 -12
  189. package/lib/model/workspace-config.js +2 -1
  190. package/lib/plugin.d.ts +2 -1
  191. package/lib/plugin.js +2 -2
  192. package/lib/qoder-plugin/.mcp.json +17 -0
  193. package/lib/qoder-plugin/.qoder-plugin/plugin.json +7 -0
  194. package/lib/qoder-plugin/DISCLAIMER.md +17 -0
  195. package/lib/qoder-plugin/LICENSE +21 -0
  196. package/lib/qoder-plugin/hooks/hooks.json +37 -0
  197. package/lib/qoder-plugin/skills/pbot/SKILL.md +9 -0
  198. package/lib/services/agents/agent-service.d.ts +15 -45
  199. package/lib/services/agents/agent-service.js +22 -3
  200. package/lib/services/history/history-capture.js +34 -22
  201. package/lib/services/history/history-migrate.js +26 -60
  202. package/lib/services/history/history-query.js +38 -57
  203. package/lib/services/history/summary-command.d.ts +1 -1
  204. package/lib/services/history/summary-command.js +8 -7
  205. package/lib/services/history/summary-registry.js +2 -3
  206. package/lib/services/history/summary-runner.d.ts +2 -5
  207. package/lib/services/history/summary-runner.js +72 -74
  208. package/lib/services/history/workspace-history.d.ts +3 -0
  209. package/lib/services/history/workspace-history.js +6 -0
  210. package/lib/services/installation/setup-service.js +4 -1
  211. package/lib/services/installation/upgrade-service.js +95 -0
  212. package/lib/services/workspace/plugin-releases.d.ts +15 -0
  213. package/lib/services/workspace/plugin-releases.js +126 -0
  214. package/lib/services/workspace/workspace-config.js +9 -8
  215. package/lib/services/workspace/workspace-mcp.js +22 -29
  216. package/lib/services/workspace/workspace-skills.d.ts +1 -0
  217. package/lib/services/workspace/workspace-skills.js +4 -2
  218. package/lib/storage/acp-files.js +7 -12
  219. package/lib/storage/agent-files.js +6 -5
  220. package/lib/storage/atomic-json.d.ts +3 -1
  221. package/lib/storage/atomic-json.js +43 -3
  222. package/lib/storage/history-files.d.ts +2 -1
  223. package/lib/storage/history-files.js +21 -15
  224. package/lib/storage/history-format.d.ts +2 -3
  225. package/lib/storage/history-format.js +5 -7
  226. package/lib/tools/history/contract.d.ts +3 -11
  227. package/lib/tools/history/contract.js +8 -7
  228. package/lib/ui/dsh/elements.d.ts +2 -5
  229. package/lib/ui/dsh/elements.js +3 -16
  230. package/lib/ui/dsh/management.js +9 -9
  231. package/lib/ui/dsh/styles.d.ts +1 -1
  232. package/lib/ui/dsh/styles.js +5 -33
  233. package/package.json +4 -1
  234. package/resources/antigravity/skills/pbot/SKILL.md +11 -1
  235. package/resources/claude/skills/pbot/SKILL.md +11 -1
  236. package/resources/plugin/skills/pbot/SKILL.md +9 -0
  237. package/resources/prompts/history-coordinator.md +1 -0
  238. package/resources/prompts/plugin-coordinator.md +1 -0
  239. package/scripts/README.md +3 -2
  240. package/src/common/validation.ts +10 -0
  241. package/src/dsh.ts +2 -2
  242. package/src/extension/history/command.ts +68 -0
  243. package/src/extension/hosts/dsh/acp-entry.ts +21 -0
  244. package/src/extension/hosts/dsh/acp-member.ts +4 -15
  245. package/src/extension/hosts/dsh/command.ts +6 -46
  246. package/src/extension/hosts/dsh/workspace.ts +12 -38
  247. package/src/extension/hosts/pi/acp-member.ts +4 -10
  248. package/src/extension/hosts/pi/command.ts +14 -63
  249. package/src/extension/hosts/pi/events.ts +2 -8
  250. package/src/extension/hosts/pi/lifecycle.ts +3 -2
  251. package/src/extension/hosts/plugin-runtime.ts +39 -19
  252. package/src/extension/hosts/workspace-mcp.ts +25 -0
  253. package/src/extension/mcp/bridge.ts +80 -80
  254. package/src/extension/mcp/tool-contract.ts +462 -0
  255. package/src/extension/mcp/workers.ts +81 -551
  256. package/src/extension/setup/cli.ts +11 -1
  257. package/src/extension/setup/upgrade.ts +158 -0
  258. package/src/extension/setup/workspace-cli.ts +167 -0
  259. package/src/integrations/acp/agents.ts +2 -3
  260. package/src/integrations/acp/harnesses/dsh.ts +1 -1
  261. package/src/integrations/acp/harnesses/presets.ts +8 -0
  262. package/src/integrations/acp/history-summary.ts +2 -1
  263. package/src/integrations/agent-resources.ts +1 -1
  264. package/src/integrations/hosts/claude/adapter.ts +7 -53
  265. package/src/integrations/hosts/codex/adapter.ts +16 -0
  266. package/src/integrations/hosts/plugin-registry.ts +9 -1
  267. package/src/integrations/hosts/prompt-hooks.ts +72 -0
  268. package/src/integrations/hosts/qoder/adapter.ts +19 -0
  269. package/src/integrations/installation/cli-update.ts +144 -0
  270. package/src/integrations/installation/pi-bridge.ts +1 -1
  271. package/src/integrations/installation/pi-setup.ts +1 -1
  272. package/src/integrations/installation/processes.ts +1 -1
  273. package/src/integrations/installation/upgraders/antigravity.ts +68 -0
  274. package/src/integrations/installation/upgraders/claude.ts +123 -0
  275. package/src/integrations/installation/upgraders/codex.ts +73 -0
  276. package/src/integrations/installation/upgraders/dsh.ts +63 -0
  277. package/src/integrations/installation/upgraders/pi.ts +87 -0
  278. package/src/integrations/installation/upgraders/qoder.ts +68 -0
  279. package/src/integrations/installation/upgraders/registry.ts +48 -0
  280. package/src/model/acp.ts +11 -3
  281. package/src/model/agent.ts +20 -4
  282. package/src/model/history.ts +5 -0
  283. package/src/model/installation.ts +86 -0
  284. package/src/model/plugin-host.ts +5 -1
  285. package/src/model/workspace-config.ts +6 -12
  286. package/src/pbot.ts +13 -32
  287. package/src/plugin.ts +3 -3
  288. package/src/services/agents/agent-service.ts +29 -17
  289. package/src/services/history/history-capture.ts +30 -22
  290. package/src/services/history/history-migrate.ts +23 -50
  291. package/src/services/history/history-query.ts +34 -48
  292. package/src/services/history/summary-command.ts +9 -8
  293. package/src/services/history/summary-registry.ts +2 -3
  294. package/src/services/history/summary-runner.ts +72 -81
  295. package/src/services/history/workspace-history.ts +8 -0
  296. package/src/services/installation/setup-service.ts +9 -43
  297. package/src/services/installation/upgrade-service.ts +127 -0
  298. package/src/services/workspace/plugin-releases.ts +121 -0
  299. package/src/services/workspace/workspace-config.ts +9 -8
  300. package/src/services/workspace/workspace-mcp.ts +23 -28
  301. package/src/services/workspace/workspace-skills.ts +5 -2
  302. package/src/storage/acp-files.ts +7 -12
  303. package/src/storage/agent-files.ts +6 -5
  304. package/src/storage/atomic-json.ts +31 -4
  305. package/src/storage/history-files.ts +22 -15
  306. package/src/storage/history-format.ts +6 -8
  307. package/src/tools/history/contract.ts +9 -9
  308. package/src/tools/history/pi-tool.ts +6 -4
  309. package/src/ui/dsh/elements.ts +5 -12
  310. package/src/ui/dsh/management.ts +10 -10
  311. package/src/ui/dsh/styles.ts +5 -33
  312. package/lib/antigravity-plugin/lib/services/history/history-migrate.d.ts +0 -12
  313. package/lib/antigravity-plugin/lib/services/history/history-migrate.js +0 -88
  314. package/lib/ui/presentation.d.ts +0 -3
  315. package/lib/ui/presentation.js +0 -12
  316. package/src/tools/access.ts +0 -7
  317. package/src/tools/register.ts +0 -21
  318. package/src/ui/presentation.ts +0 -12
@@ -0,0 +1,441 @@
1
+ import { object } from "../../common/json.js";
2
+ import { requireThat } from "../../common/validation.js";
3
+ import { inspectAcpBackends } from "../../integrations/acp/launch.js";
4
+ import { historyPageLimits } from "../../model/history.js";
5
+ import { acpElicitationActions } from "../../model/acp.js";
6
+ export const defaultWaitMs = 50_000;
7
+ export const maxWaitMs = 600_000;
8
+ export const discoverTargets = ["overview", "workers", "backends", "models"];
9
+ function formatBackendItem(entry, defaultBackend) {
10
+ const tags = [];
11
+ if (entry.label)
12
+ tags.push(entry.label);
13
+ if (entry.backend === defaultBackend)
14
+ tags.push("当前");
15
+ return tags.length ? `${entry.backend}(${tags.join(",")})` : entry.backend;
16
+ }
17
+ function summarizeBackends(commands = {}, defaultBackend) {
18
+ const entries = inspectAcpBackends(commands);
19
+ const available = entries.filter(item => item.available);
20
+ const unavailable = entries.filter(item => !item.available);
21
+ const availableText = available.map(item => formatBackendItem(item, defaultBackend)).join("、");
22
+ const unavailableText = unavailable.map(item => formatBackendItem(item, defaultBackend)).join("、");
23
+ const overview = available.length
24
+ ? unavailable.length
25
+ ? `当前可用助手:${availableText};暂不可用:${unavailableText}。`
26
+ : `当前可用助手:${availableText}。`
27
+ : `当前无可用外部助手(暂不可用:${unavailableText})。`;
28
+ const availableIds = available.map(item => item.backend).join("、");
29
+ return { overview, availableIds };
30
+ }
31
+ function workspaceProperty(workspaceBound) {
32
+ return {
33
+ type: "string",
34
+ description: workspaceBound
35
+ ? "目标工作区根目录的绝对路径;默认使用当前工作区,通常省略。"
36
+ : "目标工作区根目录的绝对路径(如上下文中提供了 workspaceRoot 则传该路径);请显式传入。",
37
+ };
38
+ }
39
+ export function buildPbotWorkerTools(commands = {}, defaultBackend, workspaceBound = false) {
40
+ const { overview, availableIds } = summarizeBackends(commands, defaultBackend);
41
+ const modelsBackendHint = defaultBackend
42
+ ? `省略时默认查 ${defaultBackend}`
43
+ : "必填";
44
+ const workspace = workspaceProperty(workspaceBound);
45
+ return [
46
+ {
47
+ name: "worker_create",
48
+ description: "启动一个独立的外部 AI 助手会话(worker),用于将任务委派给其他助手或指定模型/思考深度来独立处理(如按用户要求切换助手、获取独立审查或第二意见、并行分担子任务)。" +
49
+ "本工具仅建立会话并返回 workerId,随后通过 worker_request 发送具体任务。不需要借助其他助手时,优先自行完成或使用当前内置子代理。\n" +
50
+ overview,
51
+ annotations: {
52
+ title: "Create Worker",
53
+ readOnlyHint: false,
54
+ destructiveHint: false,
55
+ idempotentHint: false,
56
+ openWorldHint: true,
57
+ },
58
+ inputSchema: {
59
+ type: "object",
60
+ additionalProperties: false,
61
+ required: ["backend"],
62
+ properties: {
63
+ backend: {
64
+ type: "string",
65
+ description: "要启动的外部助手标识(不区分大小写,支持常见别名,如 claude-code、agy)。",
66
+ },
67
+ model: {
68
+ type: "string",
69
+ description: "仅用户明确要求特定模型时指定(支持模型 ID、显示名或 provider/model,不区分大小写);不确定可用值时先用 worker_discover(target=\"models\") 查询;不填则使用该助手默认模型。",
70
+ },
71
+ thinking: {
72
+ type: "string",
73
+ description: "仅用户明确要求思考深度时指定(如 low / medium / high / xhigh / max,不区分大小写);不填则使用默认设置。",
74
+ },
75
+ cwd: {
76
+ type: "string",
77
+ description: "助手执行任务时的工作目录(绝对路径或相对工作区的路径),默认为当前工作区根目录。",
78
+ },
79
+ workspace,
80
+ },
81
+ },
82
+ },
83
+ {
84
+ name: "worker_close",
85
+ description: "结束不再需要的外部助手会话并释放资源。若该助手支持会话恢复,后续仍可直接用 worker_request 在原上下文中继续对话。",
86
+ annotations: {
87
+ title: "Close Worker",
88
+ readOnlyHint: false,
89
+ destructiveHint: true,
90
+ idempotentHint: true,
91
+ openWorldHint: false,
92
+ },
93
+ inputSchema: {
94
+ type: "object",
95
+ additionalProperties: false,
96
+ required: ["workerId"],
97
+ properties: {
98
+ workerId: {
99
+ type: "string",
100
+ description: "要结束的助手会话 ID(来自 worker_create 或 worker_discover)。",
101
+ },
102
+ workspace,
103
+ },
104
+ },
105
+ },
106
+ {
107
+ name: "worker_request",
108
+ description: "向指定的外部助手派发任务,或在同一上下文中追问与补充要求,并获取执行结果(已关闭但支持恢复的会话会自动续接)。" +
109
+ `默认最多等待 ${defaultWaitMs / 1000} 秒返回结果;将 waitMs 设为 0 可立即返回并转入后台执行,适合耗时任务或多助手并行。` +
110
+ "若返回 timedOut 或结果含 nextOffset,用 worker_output 继续等待或翻页;若返回 needsResponse,先向用户确认再用 worker_response 回复。",
111
+ annotations: {
112
+ title: "Send Request to Worker",
113
+ readOnlyHint: false,
114
+ destructiveHint: false,
115
+ idempotentHint: false,
116
+ openWorldHint: true,
117
+ },
118
+ inputSchema: {
119
+ type: "object",
120
+ additionalProperties: false,
121
+ required: ["workerId", "message"],
122
+ properties: {
123
+ workerId: {
124
+ type: "string",
125
+ description: "目标助手会话 ID(来自 worker_create 或 worker_discover)。",
126
+ },
127
+ message: {
128
+ type: "string",
129
+ description: "要发送的任务说明或追问内容。外部助手看不到你与用户的对话历史,首次派发时请写清背景、目标、相关文件路径、约束条件和期望产出。",
130
+ },
131
+ waitMs: {
132
+ type: "integer",
133
+ minimum: 0,
134
+ maximum: maxWaitMs,
135
+ description: `最多等待结果的毫秒数(默认 ${defaultWaitMs});设为 0 可立即返回并在后台执行。`,
136
+ },
137
+ workspace,
138
+ },
139
+ },
140
+ },
141
+ {
142
+ name: "worker_response",
143
+ description: "当外部助手在执行过程中暂停并请求确认或补充信息(返回 needsResponse: true)时,向其提交决定以继续执行。" +
144
+ "支持三类请求:操作授权(kind=\"permission\")、问答表单(kind=\"form\")和链接确认(kind=\"url\")。" +
145
+ `提交前先向用户确认;提交后默认最多等待 ${defaultWaitMs / 1000} 秒返回后续结果(waitMs 设为 0 立即返回)。`,
146
+ annotations: {
147
+ title: "Respond to Worker Request",
148
+ readOnlyHint: false,
149
+ destructiveHint: false,
150
+ idempotentHint: false,
151
+ openWorldHint: true,
152
+ },
153
+ inputSchema: {
154
+ type: "object",
155
+ additionalProperties: false,
156
+ required: ["workerId", "action"],
157
+ properties: {
158
+ workerId: {
159
+ type: "string",
160
+ description: "等待回复的助手会话 ID。",
161
+ },
162
+ action: {
163
+ type: "string",
164
+ enum: [...acpElicitationActions],
165
+ description: "处理方式:accept 表示同意授权、提交表单回答或确认链接;decline 表示拒绝;cancel 表示取消本次请求。",
166
+ },
167
+ requestId: {
168
+ type: "string",
169
+ description: "要回复的请求 ID(来自 pendingRequests[].requestId);仅一条待处理请求时可省略,多条时必填。",
170
+ },
171
+ optionId: {
172
+ type: "string",
173
+ description: "仅授权请求(kind=\"permission\")且 action 不为 cancel 时可用:指定选项 ID(来自 pendingRequests[].options[].optionId),省略时默认单次允许或拒绝。",
174
+ },
175
+ content: {
176
+ type: "object",
177
+ additionalProperties: true,
178
+ description: "仅表单提问(kind=\"form\")且 action=\"accept\" 时可用:按 pendingRequests[].schema.properties 填写的回答对象(值为字符串、数字、布尔值或字符串数组)。",
179
+ },
180
+ waitMs: {
181
+ type: "integer",
182
+ minimum: 0,
183
+ maximum: maxWaitMs,
184
+ description: `提交回复后最多等待后续结果的毫秒数(默认 ${defaultWaitMs});设为 0 立即返回。`,
185
+ },
186
+ workspace,
187
+ },
188
+ },
189
+ },
190
+ {
191
+ name: "worker_output",
192
+ description: "获取或等待外部助手的最新执行结果。用于收取后台任务的产出、在等待超时(timedOut)后继续等待,或在长结果分页(含 nextOffset)时读取后续内容。" +
193
+ "任务仍在运行时会等待其完成(也可能返回 timedOut 或 needsResponse),已结束则立即返回。",
194
+ annotations: {
195
+ title: "Get Worker Output",
196
+ readOnlyHint: true,
197
+ destructiveHint: false,
198
+ idempotentHint: true,
199
+ openWorldHint: false,
200
+ },
201
+ inputSchema: {
202
+ type: "object",
203
+ additionalProperties: false,
204
+ required: ["workerId"],
205
+ properties: {
206
+ workerId: {
207
+ type: "string",
208
+ description: "要等待或获取结果的助手会话 ID。",
209
+ },
210
+ offset: {
211
+ type: "integer",
212
+ minimum: 0,
213
+ description: "结果读取起始位置(默认 0);翻页读取剩余内容时传入上次返回的 nextOffset。",
214
+ },
215
+ waitMs: {
216
+ type: "integer",
217
+ minimum: 0,
218
+ maximum: maxWaitMs,
219
+ description: `任务仍在运行时最多等待的毫秒数(默认 ${defaultWaitMs});任务已结束或翻页读取时会立即返回。`,
220
+ },
221
+ workspace,
222
+ },
223
+ },
224
+ },
225
+ {
226
+ name: "worker_discover",
227
+ description: "了解当前可以委派哪些外部助手、查看已有助手会话的运行状态以便复用,或查询某个助手支持的模型与思考深度选项。" +
228
+ "默认(target=\"overview\")同时返回可用助手与已有会话;仅在需要核对模型或思考深度可选值时再查 target=\"models\"(耗时较长)。",
229
+ annotations: {
230
+ title: "Discover Workers, Backends & Models",
231
+ readOnlyHint: true,
232
+ destructiveHint: false,
233
+ idempotentHint: true,
234
+ openWorldHint: false,
235
+ },
236
+ inputSchema: {
237
+ type: "object",
238
+ additionalProperties: false,
239
+ required: [],
240
+ properties: {
241
+ target: {
242
+ type: "string",
243
+ enum: [...discoverTargets],
244
+ description: "查询范围,默认 \"overview\"(同时返回可用助手与已有会话);\"workers\" 查全部或单个会话状态;\"backends\" 查可用助手列表;\"models\" 查指定助手支持的模型与思考深度。",
245
+ },
246
+ workerId: {
247
+ type: "string",
248
+ description: "仅 target=\"workers\" 可用:指定单个助手会话 ID;不填则列出全部。",
249
+ },
250
+ backend: {
251
+ type: "string",
252
+ description: availableIds
253
+ ? `仅 target="models" 可用(${modelsBackendHint}):目标外部助手标识,支持常见别名;当前可用:${availableIds}。`
254
+ : `仅 target="models" 可用(${modelsBackendHint}):目标外部助手标识,支持常见别名。`,
255
+ },
256
+ model: {
257
+ type: "string",
258
+ description: "仅 target=\"models\" 可用:指定模型以查看该模型支持的思考深度选项。",
259
+ },
260
+ workspace,
261
+ },
262
+ },
263
+ },
264
+ ];
265
+ }
266
+ export function buildWorkspaceMcpTools(workspaceBound = false) {
267
+ const workspace = workspaceProperty(workspaceBound);
268
+ return [
269
+ {
270
+ name: "workspace_mcp_discover",
271
+ description: "发现当前工作区共享的外部工具服务(MCP)及其可用工具。不传 server 时列出可用服务;传入 server 时返回该服务提供的工具清单与参数说明。",
272
+ annotations: {
273
+ title: "Discover Workspace MCP Servers & Tools",
274
+ readOnlyHint: true,
275
+ destructiveHint: false,
276
+ idempotentHint: true,
277
+ openWorldHint: true,
278
+ },
279
+ inputSchema: {
280
+ type: "object",
281
+ additionalProperties: false,
282
+ required: [],
283
+ properties: {
284
+ server: {
285
+ type: "string",
286
+ description: "目标工具服务名称;不填时列出工作区全部可用服务。",
287
+ },
288
+ workspace,
289
+ },
290
+ },
291
+ },
292
+ {
293
+ name: "workspace_mcp_call",
294
+ description: "调用当前工作区共享的外部工具服务(MCP)中的指定工具,用于访问工作区接入的外部能力与数据源。" +
295
+ "不确定工具名或参数格式时,先用 workspace_mcp_discover(server) 查询。",
296
+ annotations: {
297
+ title: "Call Workspace MCP Tool",
298
+ readOnlyHint: false,
299
+ destructiveHint: false,
300
+ idempotentHint: false,
301
+ openWorldHint: true,
302
+ },
303
+ inputSchema: {
304
+ type: "object",
305
+ additionalProperties: false,
306
+ required: ["server", "tool"],
307
+ properties: {
308
+ server: {
309
+ type: "string",
310
+ description: "目标工具服务名称(可通过 workspace_mcp_discover 获取)。",
311
+ },
312
+ tool: {
313
+ type: "string",
314
+ description: "要调用的工具名称。",
315
+ },
316
+ arguments: {
317
+ type: "object",
318
+ additionalProperties: true,
319
+ description: "传给目标工具的参数对象,不填则为空对象。",
320
+ },
321
+ workspace,
322
+ },
323
+ },
324
+ },
325
+ ];
326
+ }
327
+ export function buildHistoryMcpTools(workspaceBound = false) {
328
+ const workspace = workspaceProperty(workspaceBound);
329
+ return [
330
+ {
331
+ name: "history_search",
332
+ description: "搜索当前工作区跨宿主(pi、dsh、claude、antigravity 等)的历史问答与摘要归档。省略 query 时列出各会话;传入 query 按不区分大小写的连续关键词匹配原文与摘要。",
333
+ annotations: {
334
+ title: "Search Workspace History",
335
+ readOnlyHint: true,
336
+ destructiveHint: false,
337
+ idempotentHint: true,
338
+ openWorldHint: false,
339
+ },
340
+ inputSchema: {
341
+ type: "object",
342
+ additionalProperties: false,
343
+ required: [],
344
+ properties: {
345
+ host: {
346
+ type: "string",
347
+ description: "可选来源筛选(如 pi、dsh、claude、antigravity);省略查全部宿主。",
348
+ },
349
+ dimension: {
350
+ type: "string",
351
+ description: "可选范围筛选:raw 表示仅搜原文,或指定摘要维度(如 monthly、session);省略查全部原文与维度摘要。",
352
+ },
353
+ query: {
354
+ type: "string",
355
+ description: "不区分大小写的连续关键词;省略时列出各会话(或指定维度摘要)。",
356
+ },
357
+ sessionId: {
358
+ type: "string",
359
+ description: "限定在指定原始会话 ID 内搜索。",
360
+ },
361
+ from: {
362
+ type: "string",
363
+ description: "ISO 日期或时间下界。",
364
+ },
365
+ to: {
366
+ type: "string",
367
+ description: "ISO 日期或时间上界。",
368
+ },
369
+ offset: {
370
+ type: "integer",
371
+ minimum: 0,
372
+ description: "匹配结果偏移,默认 0。",
373
+ },
374
+ limit: {
375
+ type: "integer",
376
+ minimum: 1,
377
+ maximum: historyPageLimits.search.max,
378
+ description: `最多返回条数(1–${historyPageLimits.search.max}),默认 ${historyPageLimits.search.default}。`,
379
+ },
380
+ workspace,
381
+ },
382
+ },
383
+ },
384
+ {
385
+ name: "history_read",
386
+ description: "按节点 id 读取当前工作区历史归档的正文与上下级节点(monthly、session、summary、exchange),支持从月度汇总下钻至单会话摘要与原始问答。正文过长时用 nextOffset 续读,子节点过多时用 nextChildrenOffset 续读。",
387
+ annotations: {
388
+ title: "Read Workspace History Node",
389
+ readOnlyHint: true,
390
+ destructiveHint: false,
391
+ idempotentHint: true,
392
+ openWorldHint: false,
393
+ },
394
+ inputSchema: {
395
+ type: "object",
396
+ additionalProperties: false,
397
+ required: ["id"],
398
+ properties: {
399
+ id: {
400
+ type: "string",
401
+ description: "history_search 或上下级返回的节点 id。",
402
+ },
403
+ host: {
404
+ type: "string",
405
+ description: "跨来源 ID 冲突时显式指定来源宿主。",
406
+ },
407
+ offset: {
408
+ type: "integer",
409
+ minimum: 0,
410
+ description: "正文字符偏移,默认 0。",
411
+ },
412
+ limit: {
413
+ type: "integer",
414
+ minimum: 1,
415
+ maximum: historyPageLimits.read.max,
416
+ description: `正文字符数(1–${historyPageLimits.read.max}),默认 ${historyPageLimits.read.default}。`,
417
+ },
418
+ childrenOffset: {
419
+ type: "integer",
420
+ minimum: 0,
421
+ description: "子节点列表偏移,默认 0;续读传上页 nextChildrenOffset。",
422
+ },
423
+ workspace,
424
+ },
425
+ },
426
+ },
427
+ ];
428
+ }
429
+ export const pbotWorkerTools = buildPbotWorkerTools();
430
+ const definitions = [...pbotWorkerTools, ...buildWorkspaceMcpTools(), ...buildHistoryMcpTools()];
431
+ const toolsByName = new Map(definitions.map(({ name, inputSchema }) => [name, { name, fields: new Set(Object.keys(inputSchema.properties)) }]));
432
+ export function parseMcpToolCall(name, args) {
433
+ const tool = toolsByName.get(name);
434
+ requireThat(tool, `未知工具:${name}(可用:${[...toolsByName.keys()].join(", ")})。`);
435
+ requireThat(object(args), "工具参数必须是对象。");
436
+ const unknown = Object.entries(args)
437
+ .filter(([key, value]) => value !== undefined && !tool.fields.has(key))
438
+ .map(([key]) => key);
439
+ requireThat(unknown.length === 0, `未知参数:${unknown.join(", ")}(${name} 可用参数:${[...tool.fields].join(", ")})。`);
440
+ return { name: tool.name, args };
441
+ }