personal-bot 0.3.1 → 0.3.3

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 (436) 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 +27 -11
  8. package/bin/pbot.mjs +22 -2
  9. package/docs/README.md +3 -1
  10. package/docs/architecture/design.md +37 -24
  11. package/docs/architecture/extensibility.md +27 -19
  12. package/docs/architecture/model-context.md +4 -3
  13. package/docs/architecture/principles.md +5 -4
  14. package/docs/guides/capabilities.md +4 -4
  15. package/docs/guides/cross-harness-workers.md +3 -1
  16. package/docs/guides/history.md +73 -16
  17. package/docs/guides/workspace-configuration.md +35 -6
  18. package/docs/hosts/antigravity.md +2 -0
  19. package/docs/hosts/claude-code.md +1 -1
  20. package/docs/hosts/codex-qoder.md +63 -0
  21. package/docs/hosts/dsh.md +1 -1
  22. package/docs/hosts/pi.md +1 -1
  23. package/docs/maintainers/architecture-governance.md +78 -0
  24. package/hooks/hooks.json +3 -0
  25. package/lib/antigravity-plugin/DISCLAIMER.md +17 -0
  26. package/lib/antigravity-plugin/LICENSE +21 -0
  27. package/lib/antigravity-plugin/bin/pbot-pi-acp.mjs +36 -0
  28. package/lib/antigravity-plugin/hooks.json +7 -0
  29. package/lib/antigravity-plugin/lib/claude.js +2 -2
  30. package/lib/antigravity-plugin/lib/common/files.d.ts +2 -0
  31. package/lib/antigravity-plugin/lib/common/files.js +44 -0
  32. package/lib/antigravity-plugin/lib/common/validation.d.ts +4 -0
  33. package/lib/antigravity-plugin/lib/common/validation.js +8 -0
  34. package/lib/{extension/acp-member.d.ts → antigravity-plugin/lib/extension/acp/member.d.ts} +5 -5
  35. package/lib/{extension/acp-member.js → antigravity-plugin/lib/extension/acp/member.js} +6 -6
  36. package/lib/antigravity-plugin/lib/extension/acp-worker.js +222 -51
  37. package/lib/antigravity-plugin/lib/extension/hosts/dsh/acp-entry.d.ts +1 -0
  38. package/lib/antigravity-plugin/lib/extension/hosts/dsh/acp-entry.js +22 -0
  39. package/lib/{extension → antigravity-plugin/lib/extension/hosts}/dsh/acp-member.js +11 -25
  40. package/lib/{extension → antigravity-plugin/lib/extension/hosts}/dsh/files.js +3 -3
  41. package/lib/antigravity-plugin/lib/extension/hosts/pi/acp-member.d.ts +3 -0
  42. package/lib/antigravity-plugin/lib/extension/hosts/pi/acp-member.js +100 -0
  43. package/lib/antigravity-plugin/lib/extension/hosts/plugin-runtime.d.ts +12 -0
  44. package/lib/antigravity-plugin/lib/extension/hosts/plugin-runtime.js +101 -0
  45. package/lib/antigravity-plugin/lib/extension/hosts/workspace-mcp.d.ts +6 -0
  46. package/lib/antigravity-plugin/lib/extension/hosts/workspace-mcp.js +21 -0
  47. package/lib/antigravity-plugin/lib/extension/mcp.js +2705 -1348
  48. package/lib/antigravity-plugin/lib/extension/workspace-cli.js +20127 -0
  49. package/lib/antigravity-plugin/lib/integrations/agent-resources.d.ts +1 -0
  50. package/lib/antigravity-plugin/lib/integrations/agent-resources.js +6 -2
  51. package/lib/antigravity-plugin/lib/integrations/hosts/antigravity/adapter.d.ts +6 -0
  52. package/lib/antigravity-plugin/lib/integrations/hosts/antigravity/adapter.js +171 -0
  53. package/lib/antigravity-plugin/lib/integrations/hosts/{claude.d.ts → claude/adapter.d.ts} +1 -1
  54. package/lib/antigravity-plugin/lib/integrations/hosts/claude/adapter.js +36 -0
  55. package/lib/antigravity-plugin/lib/integrations/hosts/codex/adapter.d.ts +2 -0
  56. package/lib/antigravity-plugin/lib/integrations/hosts/codex/adapter.js +14 -0
  57. package/lib/{integrations → antigravity-plugin/lib/integrations/hosts}/dsh/mcp.d.ts +1 -1
  58. package/lib/{integrations → antigravity-plugin/lib/integrations/hosts}/dsh/resources.d.ts +1 -1
  59. package/lib/{integrations → antigravity-plugin/lib/integrations/hosts}/dsh/resources.js +4 -4
  60. package/lib/{integrations → antigravity-plugin/lib/integrations/hosts}/dsh/skills.js +1 -1
  61. package/lib/antigravity-plugin/lib/integrations/hosts/pi/agent-tools.d.ts +3 -0
  62. package/lib/antigravity-plugin/lib/integrations/hosts/pi/agent-tools.js +32 -0
  63. package/lib/antigravity-plugin/lib/integrations/hosts/pi/mcp.d.ts +4 -0
  64. package/lib/antigravity-plugin/lib/integrations/hosts/pi/mcp.js +23 -0
  65. package/lib/antigravity-plugin/lib/integrations/hosts/{registry.d.ts → plugin-registry.d.ts} +1 -0
  66. package/lib/{integrations/hosts/registry.js → antigravity-plugin/lib/integrations/hosts/plugin-registry.js} +10 -3
  67. package/lib/antigravity-plugin/lib/integrations/hosts/prompt-hooks.d.ts +76 -0
  68. package/lib/antigravity-plugin/lib/integrations/hosts/prompt-hooks.js +76 -0
  69. package/lib/antigravity-plugin/lib/integrations/hosts/qoder/adapter.d.ts +2 -0
  70. package/lib/antigravity-plugin/lib/integrations/hosts/qoder/adapter.js +16 -0
  71. package/lib/antigravity-plugin/lib/model/acp.d.ts +7 -3
  72. package/lib/antigravity-plugin/lib/model/acp.js +8 -0
  73. package/lib/antigravity-plugin/lib/model/agent.d.ts +121 -0
  74. package/lib/antigravity-plugin/lib/model/agent.js +4 -0
  75. package/lib/antigravity-plugin/lib/model/history.d.ts +179 -0
  76. package/lib/antigravity-plugin/lib/model/history.js +4 -0
  77. package/lib/antigravity-plugin/lib/model/plugin-host.d.ts +31 -0
  78. package/lib/antigravity-plugin/lib/model/workspace-config.d.ts +28 -7
  79. package/lib/antigravity-plugin/lib/model/workspace-config.js +2 -1
  80. package/lib/antigravity-plugin/lib/plugin.d.ts +2 -1
  81. package/lib/antigravity-plugin/lib/plugin.js +4 -4
  82. package/lib/antigravity-plugin/lib/services/history/history-capture.d.ts +4 -0
  83. package/lib/antigravity-plugin/lib/services/history/history-capture.js +98 -0
  84. package/lib/antigravity-plugin/lib/services/history/history-index.d.ts +17 -0
  85. package/lib/antigravity-plugin/lib/services/history/history-index.js +112 -0
  86. package/lib/antigravity-plugin/lib/services/history/summary-dimensions/monthly.d.ts +7 -0
  87. package/lib/antigravity-plugin/lib/services/history/summary-dimensions/monthly.js +121 -0
  88. package/lib/antigravity-plugin/lib/services/history/summary-dimensions/session.d.ts +7 -0
  89. package/lib/antigravity-plugin/lib/services/history/summary-dimensions/session.js +124 -0
  90. package/lib/antigravity-plugin/lib/services/history/summary-registry.d.ts +7 -0
  91. package/lib/antigravity-plugin/lib/services/history/summary-registry.js +35 -0
  92. package/lib/antigravity-plugin/lib/services/history/summary-runner.d.ts +34 -0
  93. package/lib/antigravity-plugin/lib/services/history/summary-runner.js +299 -0
  94. package/lib/antigravity-plugin/lib/services/history/workspace-history.d.ts +3 -0
  95. package/lib/antigravity-plugin/lib/services/history/workspace-history.js +6 -0
  96. package/lib/antigravity-plugin/lib/services/workspace/plugin-releases.d.ts +3 -0
  97. package/lib/antigravity-plugin/lib/services/workspace/plugin-releases.js +78 -0
  98. package/lib/antigravity-plugin/lib/services/workspace/workspace-config.d.ts +5 -1
  99. package/lib/antigravity-plugin/lib/services/workspace/workspace-config.js +77 -7
  100. package/lib/antigravity-plugin/lib/services/workspace/workspace-files.d.ts +2 -0
  101. package/lib/antigravity-plugin/lib/services/workspace/workspace-files.js +17 -0
  102. package/lib/antigravity-plugin/lib/services/workspace/workspace-mcp.d.ts +14 -0
  103. package/lib/antigravity-plugin/lib/services/workspace/workspace-mcp.js +193 -0
  104. package/lib/antigravity-plugin/lib/services/workspace/workspace-skills.d.ts +1 -0
  105. package/lib/antigravity-plugin/lib/services/workspace/workspace-skills.js +4 -2
  106. package/lib/antigravity-plugin/lib/storage/acp-files.d.ts +11 -0
  107. package/lib/antigravity-plugin/lib/storage/acp-files.js +75 -0
  108. package/lib/antigravity-plugin/lib/storage/agent-files.d.ts +31 -0
  109. package/lib/antigravity-plugin/lib/storage/agent-files.js +159 -0
  110. package/lib/antigravity-plugin/lib/storage/atomic-json.d.ts +3 -1
  111. package/lib/antigravity-plugin/lib/storage/atomic-json.js +43 -3
  112. package/lib/antigravity-plugin/lib/storage/file-access.d.ts +2 -0
  113. package/lib/antigravity-plugin/lib/storage/file-access.js +26 -0
  114. package/lib/antigravity-plugin/lib/storage/history-files.d.ts +55 -0
  115. package/lib/antigravity-plugin/lib/storage/history-files.js +473 -0
  116. package/lib/antigravity-plugin/lib/storage/history-format.d.ts +5 -0
  117. package/lib/antigravity-plugin/lib/storage/history-format.js +60 -0
  118. package/lib/antigravity-plugin/package.json +1 -1
  119. package/lib/antigravity-plugin/plugin.json +1 -1
  120. package/lib/antigravity-plugin/resources/prompts/history-monthly-summary.md +13 -0
  121. package/lib/antigravity-plugin/resources/prompts/history-summary.md +13 -0
  122. package/lib/antigravity-plugin/resources/prompts/plugin-coordinator.md +1 -0
  123. package/lib/antigravity-plugin/resources/skills/.claude-plugin/plugin.json +4 -0
  124. package/lib/antigravity-plugin/resources/skills/project-maintenance/SKILL.md +35 -0
  125. package/lib/antigravity-plugin/resources/skills/provider-connections/SKILL.md +52 -0
  126. package/lib/antigravity-plugin/skills/pbot/SKILL.md +11 -1
  127. package/lib/antigravity-plugin/skills/provider-connections/SKILL.md +22 -12
  128. package/lib/claude.js +2 -2
  129. package/lib/client.js +42 -60
  130. package/lib/codex-marketplace/.agents/plugins/marketplace.json +17 -0
  131. package/lib/codex-marketplace/plugins/personal-bot/.codex-plugin/plugin.json +7 -0
  132. package/lib/codex-marketplace/plugins/personal-bot/.mcp.json +17 -0
  133. package/lib/codex-marketplace/plugins/personal-bot/DISCLAIMER.md +17 -0
  134. package/lib/codex-marketplace/plugins/personal-bot/LICENSE +21 -0
  135. package/lib/codex-marketplace/plugins/personal-bot/hooks/hooks.json +37 -0
  136. package/lib/codex-marketplace/plugins/personal-bot/skills/pbot/SKILL.md +9 -0
  137. package/lib/codex-marketplace/plugins/personal-bot/skills/pbot/agents/openai.yaml +2 -0
  138. package/lib/common/validation.d.ts +4 -0
  139. package/lib/common/validation.js +8 -0
  140. package/lib/dsh.js +6 -6
  141. package/lib/extension/acp/member.d.ts +18 -0
  142. package/lib/extension/acp/member.js +44 -0
  143. package/lib/extension/acp/worker.js +384 -0
  144. package/lib/extension/acp-worker.js +222 -51
  145. package/lib/extension/history/command.d.ts +37 -0
  146. package/lib/extension/history/command.js +57 -0
  147. package/lib/extension/hosts/dsh/acp-entry.d.ts +1 -0
  148. package/lib/extension/hosts/dsh/acp-entry.js +22 -0
  149. package/lib/extension/hosts/dsh/acp-member.d.ts +4 -0
  150. package/lib/extension/hosts/dsh/acp-member.js +58 -0
  151. package/lib/extension/{dsh → hosts/dsh}/command.d.ts +1 -2
  152. package/lib/extension/{dsh → hosts/dsh}/command.js +9 -11
  153. package/lib/extension/hosts/dsh/files.d.ts +5 -0
  154. package/lib/extension/hosts/dsh/files.js +67 -0
  155. package/lib/extension/hosts/dsh/history.d.ts +4 -0
  156. package/lib/extension/hosts/dsh/history.js +62 -0
  157. package/lib/extension/{dsh → hosts/dsh}/management.d.ts +1 -1
  158. package/lib/extension/{dsh → hosts/dsh}/management.js +12 -10
  159. package/lib/extension/{dsh → hosts/dsh}/workspace.d.ts +3 -9
  160. package/lib/extension/{dsh → hosts/dsh}/workspace.js +30 -99
  161. package/lib/extension/hosts/pi/acp-member.d.ts +3 -0
  162. package/lib/extension/hosts/pi/acp-member.js +100 -0
  163. package/lib/extension/hosts/plugin-runtime.d.ts +12 -0
  164. package/lib/extension/hosts/plugin-runtime.js +101 -0
  165. package/lib/extension/hosts/workspace-mcp.d.ts +6 -0
  166. package/lib/extension/hosts/workspace-mcp.js +21 -0
  167. package/lib/extension/{mcp-bridge.d.ts → mcp/bridge.d.ts} +7 -9
  168. package/lib/extension/{mcp-bridge.js → mcp/bridge.js} +70 -88
  169. package/lib/extension/{mcp-workers.d.ts → mcp/tool-contract.d.ts} +129 -374
  170. package/lib/extension/mcp/tool-contract.js +441 -0
  171. package/lib/extension/mcp/workers.d.ts +487 -0
  172. package/lib/extension/mcp/workers.js +598 -0
  173. package/lib/extension/mcp.js +2705 -1348
  174. package/lib/extension/{setup-cli.js → setup/cli.js} +12 -9
  175. package/lib/extension/workspace-cli.js +20127 -0
  176. package/lib/integrations/acp/agents.d.ts +2 -3
  177. package/lib/integrations/acp/connection.d.ts +11 -10
  178. package/lib/integrations/acp/connection.js +6 -0
  179. package/lib/integrations/acp/harnesses/claude.js +1 -1
  180. package/lib/integrations/acp/harnesses/dsh.js +1 -1
  181. package/lib/integrations/acp/harnesses/presets.js +8 -0
  182. package/lib/integrations/acp/history-summary.d.ts +17 -0
  183. package/lib/integrations/acp/history-summary.js +101 -0
  184. package/lib/integrations/acp/launch.d.ts +2 -2
  185. package/lib/integrations/agent-resources.d.ts +1 -0
  186. package/lib/integrations/agent-resources.js +6 -2
  187. package/lib/integrations/hosts/antigravity/adapter.d.ts +6 -0
  188. package/lib/integrations/hosts/antigravity/adapter.js +171 -0
  189. package/lib/integrations/hosts/{claude.d.ts → claude/adapter.d.ts} +1 -1
  190. package/lib/integrations/hosts/claude/adapter.js +36 -0
  191. package/lib/integrations/hosts/codex/adapter.d.ts +2 -0
  192. package/lib/integrations/hosts/codex/adapter.js +14 -0
  193. package/lib/integrations/hosts/dsh/mcp.d.ts +4 -0
  194. package/lib/integrations/hosts/dsh/mcp.js +28 -0
  195. package/lib/integrations/hosts/dsh/messages.d.ts +36 -0
  196. package/lib/integrations/hosts/dsh/messages.js +11 -0
  197. package/lib/integrations/hosts/dsh/resources.d.ts +6 -0
  198. package/lib/integrations/hosts/dsh/resources.js +47 -0
  199. package/lib/integrations/hosts/dsh/root-agents.d.ts +4 -0
  200. package/lib/integrations/hosts/dsh/root-agents.js +3 -0
  201. package/lib/integrations/{dsh → hosts/dsh}/schema.js +1 -1
  202. package/lib/integrations/hosts/dsh/skills.d.ts +8 -0
  203. package/lib/integrations/hosts/dsh/skills.js +31 -0
  204. package/lib/integrations/hosts/pi/agent-tools.d.ts +3 -0
  205. package/lib/integrations/hosts/pi/agent-tools.js +32 -0
  206. package/lib/integrations/hosts/pi/mcp.d.ts +4 -0
  207. package/lib/integrations/hosts/pi/mcp.js +23 -0
  208. package/lib/integrations/hosts/{registry.d.ts → plugin-registry.d.ts} +1 -0
  209. package/lib/{antigravity-plugin/lib/integrations/hosts/registry.js → integrations/hosts/plugin-registry.js} +10 -3
  210. package/lib/integrations/hosts/prompt-hooks.d.ts +76 -0
  211. package/lib/integrations/hosts/prompt-hooks.js +76 -0
  212. package/lib/integrations/hosts/qoder/adapter.d.ts +2 -0
  213. package/lib/integrations/hosts/qoder/adapter.js +16 -0
  214. package/lib/integrations/installation/pi-setup.js +1 -1
  215. package/lib/model/acp.d.ts +7 -3
  216. package/lib/model/acp.js +8 -0
  217. package/lib/model/agent.d.ts +18 -4
  218. package/lib/model/agent.js +4 -1
  219. package/lib/model/history.d.ts +143 -34
  220. package/lib/model/history.js +4 -1
  221. package/lib/model/installation.js +1 -0
  222. package/lib/model/plugin-host.d.ts +31 -0
  223. package/lib/model/workspace-config.d.ts +28 -7
  224. package/lib/model/workspace-config.js +2 -1
  225. package/lib/plugin.d.ts +2 -1
  226. package/lib/plugin.js +4 -4
  227. package/lib/qoder-plugin/.mcp.json +17 -0
  228. package/lib/qoder-plugin/.qoder-plugin/plugin.json +7 -0
  229. package/lib/qoder-plugin/DISCLAIMER.md +17 -0
  230. package/lib/qoder-plugin/LICENSE +21 -0
  231. package/lib/qoder-plugin/hooks/hooks.json +37 -0
  232. package/lib/qoder-plugin/skills/pbot/SKILL.md +9 -0
  233. package/lib/services/agents/agent-run.d.ts +1 -1
  234. package/lib/services/agents/agent-service.d.ts +15 -45
  235. package/lib/services/agents/agent-service.js +22 -3
  236. package/lib/services/history/history-capture.d.ts +4 -0
  237. package/lib/services/history/history-capture.js +98 -0
  238. package/lib/services/history/history-index.d.ts +16 -7
  239. package/lib/services/history/history-index.js +48 -70
  240. package/lib/services/history/history-migrate.d.ts +12 -0
  241. package/lib/services/history/history-migrate.js +54 -0
  242. package/lib/services/history/history-query.d.ts +51 -0
  243. package/lib/services/history/history-query.js +352 -0
  244. package/lib/services/history/summary-command.d.ts +20 -0
  245. package/lib/services/history/summary-command.js +69 -0
  246. package/lib/services/history/summary-dimensions/monthly.d.ts +7 -0
  247. package/lib/services/history/summary-dimensions/monthly.js +121 -0
  248. package/lib/services/history/summary-dimensions/session.d.ts +7 -0
  249. package/lib/services/history/summary-dimensions/session.js +124 -0
  250. package/lib/services/history/summary-registry.d.ts +7 -0
  251. package/lib/services/history/summary-registry.js +35 -0
  252. package/lib/services/history/summary-runner.d.ts +34 -0
  253. package/lib/services/history/summary-runner.js +299 -0
  254. package/lib/services/history/workspace-history.d.ts +3 -0
  255. package/lib/services/history/workspace-history.js +6 -0
  256. package/lib/services/workspace/plugin-releases.d.ts +3 -0
  257. package/lib/services/workspace/plugin-releases.js +78 -0
  258. package/lib/services/workspace/workspace-config.d.ts +5 -1
  259. package/lib/services/workspace/workspace-config.js +77 -7
  260. package/lib/services/workspace/workspace-mcp.js +22 -29
  261. package/lib/services/workspace/workspace-skills.d.ts +1 -0
  262. package/lib/services/workspace/workspace-skills.js +4 -2
  263. package/lib/storage/acp-files.js +7 -12
  264. package/lib/storage/agent-files.js +6 -5
  265. package/lib/storage/atomic-json.d.ts +3 -1
  266. package/lib/storage/atomic-json.js +43 -3
  267. package/lib/storage/history-files.d.ts +46 -9
  268. package/lib/storage/history-files.js +382 -250
  269. package/lib/storage/history-format.d.ts +3 -13
  270. package/lib/storage/history-format.js +26 -52
  271. package/lib/tools/history/actions.d.ts +3 -68
  272. package/lib/tools/history/actions.js +7 -5
  273. package/lib/tools/history/contract.d.ts +16 -17
  274. package/lib/tools/history/contract.js +63 -22
  275. package/lib/tools/history/dsh-tool.d.ts +1 -2
  276. package/lib/tools/history/dsh-tool.js +11 -5
  277. package/lib/ui/dsh/elements.d.ts +2 -5
  278. package/lib/ui/dsh/elements.js +3 -16
  279. package/lib/ui/dsh/management.js +26 -13
  280. package/lib/ui/dsh/styles.d.ts +1 -1
  281. package/lib/ui/dsh/styles.js +5 -33
  282. package/package.json +4 -1
  283. package/resources/antigravity/skills/pbot/SKILL.md +11 -1
  284. package/resources/claude/skills/pbot/SKILL.md +11 -1
  285. package/resources/plugin/skills/pbot/SKILL.md +9 -0
  286. package/resources/prompts/history-coordinator.md +2 -1
  287. package/resources/prompts/history-monthly-summary.md +13 -0
  288. package/resources/prompts/history-summary.md +10 -4
  289. package/resources/prompts/plugin-coordinator.md +1 -0
  290. package/resources/skills/provider-connections/SKILL.md +22 -12
  291. package/scripts/README.md +3 -2
  292. package/src/claude.ts +2 -2
  293. package/src/common/validation.ts +10 -0
  294. package/src/dsh.ts +6 -6
  295. package/src/extension/{acp-member.ts → acp/member.ts} +7 -7
  296. package/src/extension/{acp-worker.ts → acp/worker.ts} +131 -17
  297. package/src/extension/history/command.ts +68 -0
  298. package/src/extension/hosts/dsh/acp-entry.ts +21 -0
  299. package/src/extension/{dsh → hosts/dsh}/acp-member.ts +12 -23
  300. package/src/extension/{dsh → hosts/dsh}/command.ts +10 -12
  301. package/src/extension/{dsh → hosts/dsh}/files.ts +3 -3
  302. package/src/extension/hosts/dsh/history.ts +67 -0
  303. package/src/extension/{dsh → hosts/dsh}/management.ts +11 -9
  304. package/src/extension/{dsh → hosts/dsh}/workspace.ts +31 -76
  305. package/src/extension/{pi-acp-member.ts → hosts/pi/acp-member.ts} +12 -18
  306. package/src/extension/{command.ts → hosts/pi/command.ts} +44 -11
  307. package/src/extension/{events.ts → hosts/pi/events.ts} +8 -4
  308. package/src/extension/hosts/pi/history.ts +45 -0
  309. package/src/extension/{lifecycle.ts → hosts/pi/lifecycle.ts} +9 -12
  310. package/src/extension/hosts/plugin-runtime.ts +96 -0
  311. package/src/extension/hosts/workspace-mcp.ts +25 -0
  312. package/src/extension/{mcp-bridge.ts → mcp/bridge.ts} +85 -85
  313. package/src/extension/mcp/tool-contract.ts +462 -0
  314. package/src/extension/{mcp-workers.ts → mcp/workers.ts} +151 -448
  315. package/src/extension/{setup-cli.ts → setup/cli.ts} +14 -11
  316. package/src/extension/setup/workspace-cli.ts +159 -0
  317. package/src/integrations/acp/agents.ts +2 -3
  318. package/src/integrations/acp/connection.ts +6 -0
  319. package/src/integrations/acp/harnesses/claude.ts +1 -1
  320. package/src/integrations/acp/harnesses/dsh.ts +1 -1
  321. package/src/integrations/acp/harnesses/presets.ts +8 -0
  322. package/src/integrations/acp/history-summary.ts +109 -0
  323. package/src/integrations/agent-resources.ts +7 -1
  324. package/src/integrations/hosts/antigravity/adapter.ts +161 -0
  325. package/src/integrations/hosts/claude/adapter.ts +39 -0
  326. package/src/integrations/hosts/codex/adapter.ts +16 -0
  327. package/src/integrations/{dsh → hosts/dsh}/mcp.ts +1 -1
  328. package/src/integrations/{dsh → hosts/dsh}/resources.ts +5 -5
  329. package/src/integrations/{dsh → hosts/dsh}/schema.ts +1 -1
  330. package/src/integrations/{dsh → hosts/dsh}/session.ts +2 -2
  331. package/src/integrations/{dsh → hosts/dsh}/skills.ts +1 -1
  332. package/src/integrations/{pi → hosts/pi}/mcp.ts +1 -1
  333. package/src/integrations/{pi → hosts/pi}/skills.ts +1 -1
  334. package/src/integrations/hosts/{registry.ts → plugin-registry.ts} +11 -3
  335. package/src/integrations/hosts/prompt-hooks.ts +72 -0
  336. package/src/integrations/hosts/qoder/adapter.ts +19 -0
  337. package/src/integrations/installation/cli-update.ts +116 -0
  338. package/src/integrations/installation/pi-bridge.ts +1 -1
  339. package/src/integrations/installation/pi-setup.ts +2 -2
  340. package/src/integrations/installation/processes.ts +1 -1
  341. package/src/mcp.ts +1 -1
  342. package/src/model/acp.ts +11 -3
  343. package/src/model/agent.ts +20 -4
  344. package/src/model/history.ts +156 -26
  345. package/src/model/installation.ts +41 -0
  346. package/src/model/plugin-host.ts +30 -2
  347. package/src/model/workspace-config.ts +31 -7
  348. package/src/pbot.ts +22 -50
  349. package/src/plugin.ts +4 -4
  350. package/src/services/agents/agent-service.ts +29 -17
  351. package/src/services/history/history-capture.ts +91 -0
  352. package/src/services/history/history-index.ts +48 -62
  353. package/src/services/history/history-migrate.ts +62 -0
  354. package/src/services/history/history-query.ts +401 -0
  355. package/src/services/history/summary-command.ts +70 -0
  356. package/src/services/history/summary-dimensions/monthly.ts +139 -0
  357. package/src/services/history/summary-dimensions/session.ts +149 -0
  358. package/src/services/history/summary-registry.ts +43 -0
  359. package/src/services/history/summary-runner.ts +343 -0
  360. package/src/services/history/workspace-history.ts +8 -0
  361. package/src/services/installation/setup-service.ts +2 -41
  362. package/src/services/workspace/plugin-releases.ts +68 -0
  363. package/src/services/workspace/workspace-config.ts +95 -8
  364. package/src/services/workspace/workspace-mcp.ts +23 -28
  365. package/src/services/workspace/workspace-skills.ts +5 -2
  366. package/src/storage/acp-files.ts +7 -12
  367. package/src/storage/agent-files.ts +6 -5
  368. package/src/storage/atomic-json.ts +31 -4
  369. package/src/storage/history-files.ts +416 -189
  370. package/src/storage/history-format.ts +45 -61
  371. package/src/tools/history/actions.ts +8 -6
  372. package/src/tools/history/contract.ts +70 -25
  373. package/src/tools/history/dsh-tool.ts +17 -8
  374. package/src/tools/history/pi-tool.ts +23 -0
  375. package/src/ui/dsh/elements.ts +5 -12
  376. package/src/ui/dsh/management.ts +36 -20
  377. package/src/ui/dsh/styles.ts +5 -33
  378. package/src/ui/{confirmation.ts → pi/confirmation.ts} +1 -1
  379. package/lib/antigravity-plugin/lib/extension/plugin-runtime.d.ts +0 -10
  380. package/lib/antigravity-plugin/lib/extension/plugin-runtime.js +0 -67
  381. package/lib/antigravity-plugin/lib/integrations/hosts/antigravity.d.ts +0 -4
  382. package/lib/antigravity-plugin/lib/integrations/hosts/antigravity.js +0 -79
  383. package/lib/antigravity-plugin/lib/integrations/hosts/claude.js +0 -60
  384. package/lib/extension/dsh/history.d.ts +0 -15
  385. package/lib/extension/dsh/history.js +0 -87
  386. package/lib/extension/mcp-workers.js +0 -882
  387. package/lib/extension/plugin-runtime.d.ts +0 -10
  388. package/lib/extension/plugin-runtime.js +0 -67
  389. package/lib/integrations/dsh/history-summary.d.ts +0 -11
  390. package/lib/integrations/dsh/history-summary.js +0 -36
  391. package/lib/integrations/dsh/history.d.ts +0 -16
  392. package/lib/integrations/dsh/history.js +0 -167
  393. package/lib/integrations/history-summary.d.ts +0 -4
  394. package/lib/integrations/history-summary.js +0 -32
  395. package/lib/integrations/hosts/antigravity.d.ts +0 -4
  396. package/lib/integrations/hosts/antigravity.js +0 -79
  397. package/lib/integrations/hosts/claude.js +0 -60
  398. package/lib/services/history/history-service.d.ts +0 -106
  399. package/lib/services/history/history-service.js +0 -242
  400. package/lib/storage/acp-history.d.ts +0 -10
  401. package/lib/storage/acp-history.js +0 -57
  402. package/lib/ui/presentation.d.ts +0 -3
  403. package/lib/ui/presentation.js +0 -12
  404. package/src/extension/dsh/history.ts +0 -74
  405. package/src/extension/history.ts +0 -26
  406. package/src/extension/plugin-runtime.ts +0 -63
  407. package/src/integrations/dsh/history-summary.ts +0 -39
  408. package/src/integrations/dsh/history.ts +0 -84
  409. package/src/integrations/history-summary.ts +0 -30
  410. package/src/integrations/hosts/antigravity.ts +0 -83
  411. package/src/integrations/hosts/claude.ts +0 -62
  412. package/src/integrations/pi/history.ts +0 -99
  413. package/src/services/history/history-service.ts +0 -195
  414. package/src/storage/acp-history.ts +0 -49
  415. package/src/tools/access.ts +0 -7
  416. package/src/tools/history/tool.ts +0 -19
  417. package/src/tools/register.ts +0 -22
  418. package/src/ui/presentation.ts +0 -12
  419. /package/lib/{extension → antigravity-plugin/lib/extension/hosts}/dsh/acp-member.d.ts +0 -0
  420. /package/lib/{extension → antigravity-plugin/lib/extension/hosts}/dsh/files.d.ts +0 -0
  421. /package/lib/{integrations → antigravity-plugin/lib/integrations/hosts}/dsh/mcp.js +0 -0
  422. /package/lib/{integrations → antigravity-plugin/lib/integrations/hosts}/dsh/messages.d.ts +0 -0
  423. /package/lib/{integrations → antigravity-plugin/lib/integrations/hosts}/dsh/messages.js +0 -0
  424. /package/lib/{integrations → antigravity-plugin/lib/integrations/hosts}/dsh/root-agents.d.ts +0 -0
  425. /package/lib/{integrations → antigravity-plugin/lib/integrations/hosts}/dsh/root-agents.js +0 -0
  426. /package/lib/{integrations → antigravity-plugin/lib/integrations/hosts}/dsh/skills.d.ts +0 -0
  427. /package/lib/extension/{acp-worker.d.ts → acp/worker.d.ts} +0 -0
  428. /package/lib/extension/{setup-guard.js → setup/guard.js} +0 -0
  429. /package/lib/integrations/acp/{claude.d.ts → claude-settings.d.ts} +0 -0
  430. /package/lib/integrations/acp/{claude.js → claude-settings.js} +0 -0
  431. /package/lib/integrations/{dsh → hosts/dsh}/schema.d.ts +0 -0
  432. /package/src/extension/{setup-guard.ts → setup/guard.ts} +0 -0
  433. /package/src/integrations/acp/{claude.ts → claude-settings.ts} +0 -0
  434. /package/src/integrations/{dsh → hosts/dsh}/messages.ts +0 -0
  435. /package/src/integrations/{dsh → hosts/dsh}/root-agents.ts +0 -0
  436. /package/src/integrations/{pi → hosts/pi}/agent-tools.ts +0 -0
@@ -1,30 +1,27 @@
1
- import { existsSync } from "node:fs";
2
1
  import { realpath } from "node:fs/promises";
3
- import { resolve } from "node:path";
4
2
  import type { Agent } from "@deepseek-ai/dsh-agent";
5
3
  import type { Context } from "@deepseek-ai/cordis";
6
4
  import * as McpClient from "@deepseek-ai/dsh-mcp-client";
7
- import { rootAgents } from "../../integrations/dsh/root-agents.js";
8
- import { dshResources } from "../../integrations/dsh/resources.js";
5
+ import { rootAgents } from "../../../integrations/hosts/dsh/root-agents.js";
6
+ import { dshResources } from "../../../integrations/hosts/dsh/resources.js";
9
7
  import { registerDshFileEvents } from "./files.js";
10
- import { DshHistoryWork, registerDshHistoryEvents } from "./history.js";
11
- import type { HistoryService } from "../../services/history/history-service.js";
12
- import { registerDshHistoryTool } from "../../tools/history/dsh-tool.js";
13
- import { resourceRoot } from "../../common/paths.js";
14
- import { requireThat } from "../../common/validation.js";
15
- import { toDshMcpConfig } from "../../integrations/dsh/mcp.js";
16
- import { registerDshSkills } from "../../integrations/dsh/skills.js";
17
- import { readWorkspaceConfig, workspaceDisabledMessage, workspaceFeatures } from "../../services/workspace/workspace-config.js";
18
- import { readWorkspaceMcpConfig, resolveWorkspaceMcpServer } from "../../services/workspace/workspace-mcp.js";
19
- import type { ResolvedWorkspaceFeatures, WorkspaceConfiguration } from "../../model/workspace-config.js";
20
- import { initializeWorkspace } from "../../services/workspace/workspace-preparation.js";
21
- import { McpWorkerRuntime, defaultWorkerDirectory } from "../mcp-workers.js";
8
+ import { registerDshHistoryEvents } from "./history.js";
9
+ import { registerDshHistoryTool } from "../../../tools/history/dsh-tool.js";
10
+ import { requireThat } from "../../../common/validation.js";
11
+ import { toDshMcpConfig } from "../../../integrations/hosts/dsh/mcp.js";
12
+ import { registerDshSkills } from "../../../integrations/hosts/dsh/skills.js";
13
+ import { bindWorkspacePlugin } from "../../../services/workspace/plugin-releases.js";
14
+ import { readWorkspaceConfig, workspaceDisabledMessage, workspaceFeatures } from "../../../services/workspace/workspace-config.js";
15
+ import { loadNativeWorkspaceServers } from "../workspace-mcp.js";
16
+ import type { ResolvedWorkspaceFeatures, WorkspaceConfiguration } from "../../../model/workspace-config.js";
17
+ import { initializeWorkspace } from "../../../services/workspace/workspace-preparation.js";
18
+ import { historyStartupNotices } from "../../../services/history/summary-runner.js";
19
+ import { McpWorkerRuntime, defaultWorkerDirectory } from "../../mcp/workers.js";
22
20
 
23
21
  export const dshDependencies = ["agents", "sessions", "sessionPersistence", "sessionQuery", "llm", "tools", "systemPrompt", "skills", "fs", "workingDirectory", "approval"];
24
22
 
25
23
  export class DshWorkspace {
26
24
  readonly lifetime = new AbortController();
27
- readonly history: HistoryService;
28
25
  readonly workers: McpWorkerRuntime;
29
26
  #scope: { dispose(): Promise<void> } | undefined;
30
27
  #closing: Promise<void> | undefined;
@@ -34,11 +31,8 @@ export class DshWorkspace {
34
31
  readonly root: string,
35
32
  readonly agent: Agent,
36
33
  readonly component: AbortSignal,
37
- private readonly historyWork: DshHistoryWork,
38
- private readonly releaseHistory: () => Promise<void>,
39
34
  readonly features: ResolvedWorkspaceFeatures = workspaceFeatures(),
40
35
  ) {
41
- this.history = historyWork.service;
42
36
  this.workers = new McpWorkerRuntime(defaultWorkerDirectory(), agent.id, "dsh");
43
37
  }
44
38
 
@@ -46,8 +40,6 @@ export class DshWorkspace {
46
40
 
47
41
  async open() {
48
42
  this.check();
49
- const mcpEntry = resolve(resourceRoot, "../lib/extension/mcp.js");
50
- const workerDir = defaultWorkerDirectory();
51
43
  this.#scope = await this.agent.ctx.plugin({
52
44
  name: "pbot-coordinator",
53
45
  inject: dshDependencies,
@@ -55,22 +47,22 @@ export class DshWorkspace {
55
47
  if (this.features.skills) registerDshSkills(ctx, this.agent, { workspaceRoot: this.root });
56
48
  if (this.features.prompts) await dshResources(ctx, this.agent, this.root, "coordinator", this.check, "history-coordinator.md");
57
49
  registerDshFileEvents(ctx, this.agent, this.root, false, this.check);
58
- registerDshHistoryTool(ctx, this.agent, this.history, this.lifetime.signal, this.check);
59
- registerDshHistoryEvents(ctx, this.agent, this.historyWork, this.check);
60
- if (existsSync(mcpEntry)) {
50
+ if (this.features.history) {
51
+ registerDshHistoryTool(ctx, this.agent, this.root, this.lifetime.signal, this.check);
52
+ registerDshHistoryEvents(ctx, this.agent, this.root);
53
+ for (const notice of historyStartupNotices(this.root)) this.ctx.logger.info(notice);
54
+ }
55
+ const server = this.workers.nativeServer(this.root);
56
+ if (server) {
61
57
  await ctx.plugin(McpClient, McpClient.Config({
62
58
  transport: "stdio",
63
59
  serverName: "pbot",
64
- command: process.execPath,
65
- args: [mcpEntry],
60
+ ...server,
66
61
  env: {
67
62
  ...(process.env.PATH ? { PATH: process.env.PATH } : {}),
68
63
  ...(process.env.HOME ? { HOME: process.env.HOME } : {}),
69
64
  ...(process.env.DSH_HOME ? { DSH_HOME: process.env.DSH_HOME } : {}),
70
- PBOT_HOST: "dsh",
71
- PBOT_WORKSPACE_ROOT: this.root,
72
- PBOT_MCP_AGENT_DIR: workerDir,
73
- PBOT_MCP_SESSION_ID: this.agent.id,
65
+ ...server.env,
74
66
  },
75
67
  cwd: this.root,
76
68
  toolCallTimeoutMs: 600_000,
@@ -78,21 +70,9 @@ export class DshWorkspace {
78
70
  }));
79
71
  }
80
72
  if (this.features.mcp) {
81
- const mcpConfig = await readWorkspaceMcpConfig(this.root);
82
- this.check();
83
- if (mcpConfig.error) {
84
- this.ctx.logger.warn(mcpConfig.error);
85
- } else {
86
- for (const [serverName, server] of Object.entries(mcpConfig.servers)) {
87
- if (server.enabled === false) continue;
88
- try {
89
- const resolved = resolveWorkspaceMcpServer(this.root, serverName, server);
90
- await ctx.plugin(McpClient, toDshMcpConfig(resolved));
91
- } catch (error) {
92
- this.ctx.logger.warn(error instanceof Error ? error.message : String(error));
93
- }
94
- }
95
- }
73
+ await loadNativeWorkspaceServers(this.root, async server => {
74
+ await ctx.plugin(McpClient, toDshMcpConfig(server));
75
+ }, { check: this.check, warn: message => this.ctx.logger.warn(message) });
96
76
  }
97
77
  },
98
78
  });
@@ -106,7 +86,6 @@ export class DshWorkspace {
106
86
  const errors: unknown[] = [];
107
87
  try { await this.workers.close(); } catch (error) { errors.push(error); }
108
88
  try { await this.#scope?.dispose(); } catch (error) { errors.push(error); }
109
- try { await this.releaseHistory(); } catch (error) { errors.push(error); }
110
89
  if (errors.length) throw new AggregateError(errors, "dsh 工作区关闭失败;请核对执行资源。");
111
90
  })();
112
91
  return this.#closing;
@@ -118,33 +97,10 @@ export class DshWorkspaces {
118
97
  readonly #initializing = new Map<string, Promise<void>>();
119
98
  readonly #configurations = new Map<Agent, { root: string; configuration: WorkspaceConfiguration }>();
120
99
  readonly #parentEffects = new Map<Agent, () => Promise<void>>();
121
- readonly #histories = new Map<string, { work: DshHistoryWork; users: number }>();
122
100
  readonly #lifetime = new AbortController();
123
101
  #closing: Promise<void> | undefined;
124
102
  constructor(readonly ctx: Context) {}
125
103
 
126
- private async history(root: string): Promise<{ work: DshHistoryWork; release(): Promise<void> }> {
127
- this.#lifetime.signal.throwIfAborted();
128
- let entry = this.#histories.get(root);
129
- if (entry && entry.users === 0) {
130
- await entry.work.close(); this.#lifetime.signal.throwIfAborted();
131
- if (this.#histories.get(root) === entry) this.#histories.delete(root);
132
- return this.history(root);
133
- }
134
- if (!entry) { entry = { work: new DshHistoryWork(this.ctx, root), users: 0 }; this.#histories.set(root, entry); }
135
- const owned = entry; owned.users++;
136
- let released = false;
137
- return {
138
- work: owned.work,
139
- release: async () => {
140
- if (released) return; released = true;
141
- if (--owned.users === 0) {
142
- try { await owned.work.close(); } finally { if (this.#histories.get(root) === owned) this.#histories.delete(root); }
143
- }
144
- },
145
- };
146
- }
147
-
148
104
  async open(agent: Agent) {
149
105
  this.#lifetime.signal.throwIfAborted();
150
106
  requireThat(rootAgents(this.ctx.agents).includes(agent), "子会话不拥有协调者管理入口。");
@@ -164,10 +120,10 @@ export class DshWorkspaces {
164
120
  this.#parentEffects.set(agent, dispose);
165
121
  return undefined;
166
122
  }
167
- const history = await this.history(root);
168
123
  let workspace: DshWorkspace | undefined;
169
124
  try {
170
- workspace = new DshWorkspace(this.ctx, root, agent, this.#lifetime.signal, history.work, history.release, workspaceFeatures(configuration));
125
+ bindWorkspacePlugin(root, "dsh");
126
+ workspace = new DshWorkspace(this.ctx, root, agent, this.#lifetime.signal, workspaceFeatures(configuration));
171
127
  const owned = workspace;
172
128
  const dispose = agent.ctx.effect(() => async () => {
173
129
  this.#parents.delete(agent); this.#configurations.delete(agent); this.#parentEffects.delete(agent); await owned.close();
@@ -178,7 +134,7 @@ export class DshWorkspaces {
178
134
  } catch (error) {
179
135
  try {
180
136
  const dispose = this.#parentEffects.get(agent);
181
- if (dispose) await dispose(); else if (workspace) await workspace.close(); else await history.release();
137
+ if (dispose) await dispose(); else if (workspace) await workspace.close();
182
138
  } catch (cleanup) { throw new AggregateError([error, cleanup], "dsh 工作区装配与清理均未完成。"); }
183
139
  throw error;
184
140
  }
@@ -240,10 +196,9 @@ export class DshWorkspaces {
240
196
  const opened = await Promise.allSettled(this.#parents.values());
241
197
  const closed = await Promise.allSettled(opened.flatMap(value => value.status === "fulfilled" && value.value ? [value.value.close()] : []));
242
198
  const effects = await Promise.allSettled([...this.#parentEffects.values()].map(dispose => dispose()));
243
- const histories = await Promise.allSettled([...this.#histories.values()].map(value => value.work.close()));
244
- const errors = [...new Set([...closed, ...effects, ...histories].flatMap(value => value.status === "rejected" ? [value.reason] : []))];
199
+ const errors = [...new Set([...closed, ...effects].flatMap(value => value.status === "rejected" ? [value.reason] : []))];
245
200
  if (errors.length) throw new AggregateError(errors, "部分 dsh 工作区未能完成关闭。");
246
- } finally { this.#parents.clear(); this.#configurations.clear(); this.#parentEffects.clear(); this.#histories.clear(); }
201
+ } finally { this.#parents.clear(); this.#configurations.clear(); this.#parentEffects.clear(); }
247
202
  })();
248
203
  return this.#closing;
249
204
  }
@@ -1,16 +1,17 @@
1
+ import type { ResolvedWorkspaceMcpServer } from "../../../model/workspace-mcp.js";
1
2
  import { stat } from "node:fs/promises";
2
3
  import { realpathSync } from "node:fs";
3
4
  import { join } from "node:path";
4
5
  import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
5
- import { isMcpWorkerTool, type AcpInput } from "../model/acp.js";
6
- import { acpMember } from "./acp-member.js";
7
- import { agentFileTools } from "../integrations/pi/agent-tools.js";
8
- import { toPiMcpConfig } from "../integrations/pi/mcp.js";
9
- import { authorizeMutation } from "../services/workspace/workspace-files.js";
10
- import { readWorkspaceMcpConfig, resolveWorkspaceMcpServer } from "../services/workspace/workspace-mcp.js";
11
- import { resourceRoot } from "../common/paths.js";
12
- import { launch } from "../storage/agent-files.js";
13
- import { requireThat } from "../common/validation.js";
6
+ import { isMcpWorkerTool, type AcpInput } from "../../../model/acp.js";
7
+ import { acpMember } from "../../acp/member.js";
8
+ import { agentFileTools } from "../../../integrations/hosts/pi/agent-tools.js";
9
+ import { toPiMcpConfig } from "../../../integrations/hosts/pi/mcp.js";
10
+ import { authorizeMutation } from "../../../services/workspace/workspace-files.js";
11
+ import { loadNativeWorkspaceServers } from "../workspace-mcp.js";
12
+ import { resourceRoot } from "../../../common/paths.js";
13
+ import { launch } from "../../../storage/agent-files.js";
14
+ import { requireThat } from "../../../common/validation.js";
14
15
 
15
16
  const isBlockedTool = (name: string) => name === "pbot_history" || isMcpWorkerTool(name);
16
17
 
@@ -24,16 +25,9 @@ export default async function piAcpMember(pi: ExtensionAPI) {
24
25
  requireThat(reference.host === "acp" && reference.backend === "pi" && realpathSync(ctx.cwd) === member.d.cwd &&
25
26
  (reference.sessionId === null || reference.sessionId === ctx.sessionManager.getSessionId()), "Pi ACP 会话身份或工作目录不匹配。");
26
27
  };
27
- const workspaceMcpServers: ReturnType<typeof resolveWorkspaceMcpServer>[] = [];
28
+ const workspaceMcpServers: ResolvedWorkspaceMcpServer[] = [];
28
29
  if (member.features.mcp && process.env.PBOT_ACP_VALIDATE !== "1") {
29
- const mcpConfig = await readWorkspaceMcpConfig(member.d.workspace);
30
- if (!mcpConfig.error) {
31
- for (const [name, server] of Object.entries(mcpConfig.servers)) {
32
- if (server.enabled === false) continue;
33
- try { workspaceMcpServers.push(resolveWorkspaceMcpServer(member.d.workspace, name, server)); }
34
- catch { /* Leave individual misconfigured servers unavailable without aborting the worker. */ }
35
- }
36
- }
30
+ await loadNativeWorkspaceServers(member.d.workspace, server => { workspaceMcpServers.push(server); });
37
31
  }
38
32
  pi.on("resources_discover", async () => {
39
33
  if (!member.features.skills || member.d.options.noSkills) return {};
@@ -1,17 +1,32 @@
1
+ import { inspectWorkspaceSummaries } from "../../../services/history/summary-runner.js";
2
+ import { workspaceDisabledMessage } from "../../../services/workspace/workspace-config.js";
1
3
  import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
2
- import { packageVersion } from "../common/version.js";
3
- import { initializeWorkspace } from "../services/workspace/workspace-preparation.js";
4
- import { workspaceDisabledMessage } from "../services/workspace/workspace-config.js";
5
- import type { Confirmations } from "../ui/confirmation.js";
4
+ import { packageVersion } from "../../../common/version.js";
5
+ import { initializeWorkspace } from "../../../services/workspace/workspace-preparation.js";
6
+ import type { Confirmations } from "../../../ui/pi/confirmation.js";
6
7
  import type { Lifecycle } from "./lifecycle.js";
7
- import { parseWorkerCommand } from "./mcp-workers.js";
8
+ import { runHistoryCommand } from "../../history/command.js";
9
+ import { parseWorkerCommand } from "../../mcp/workers.js";
10
+
11
+ function formatHistoryStatusLine(root: string): string[] {
12
+ const status = inspectWorkspaceSummaries(root);
13
+ const parts = status.dimensions.map(dim => {
14
+ const pending = dim.pendingCreate + dim.pendingIncremental + dim.pendingRebuild;
15
+ return `${dim.dimension} ${dim.ready}/${dim.total}` + (pending ? `(待处理 ${pending})` : "");
16
+ });
17
+ return [
18
+ `历史 原始会话 ${status.rawCount}` + (parts.length ? ` · ${parts.join(",")}` : ""),
19
+ ...(status.reminder ? [`提示 ${status.reminder.message}`] : []),
20
+ ...status.warnings,
21
+ ];
22
+ }
8
23
 
9
24
  export function registerCommand(pi: ExtensionAPI, lifecycle: Lifecycle, confirmations: Confirmations) {
10
25
  pi.registerCommand("pbot", {
11
- description: "工作区初始化、状态与跨 Harness worker 管理",
26
+ description: "工作区初始化、状态、历史摘要与跨 Harness worker 管理",
12
27
  getArgumentCompletions: prefix => {
13
28
  if (/\s/.test(prefix)) return null;
14
- return ["init", "status", "worker"]
29
+ return ["init", "status", "history", "worker"]
15
30
  .filter(command => command.startsWith(prefix)).map(command => ({ value: command, label: command }));
16
31
  },
17
32
  handler: async (args, ctx) => {
@@ -48,18 +63,36 @@ export function registerCommand(pi: ExtensionAPI, lifecycle: Lifecycle, confirma
48
63
  enabled: true,
49
64
  state: "running",
50
65
  configuration: lifecycle.configuration,
66
+ ...(instance.features.history ? { history: inspectWorkspaceSummaries(instance.root) } : {}),
51
67
  }, null, 2), "info");
52
68
  return;
53
69
  }
54
- const history = instance.history.status;
55
70
  ctx.ui.notify([
56
71
  `工作区 ${instance.root}`,
57
72
  `状态 已启动 · 版本 ${packageVersion}`,
58
- `历史 ${history.organizing ? "整理中" : history.pending === null ? "查询时更新索引" : history.pending + " 项待整理"}`,
59
- ...history.warnings,
73
+ ...(instance.features.history ? formatHistoryStatusLine(instance.root) : ["历史 已停用"]),
60
74
  ].join("\n"), "info");
61
75
  return;
62
76
  }
77
+ if (command === "history") {
78
+ try {
79
+ const result = await runHistoryCommand(instance, argument, instance.signal(), {
80
+ start: backend => ctx.ui.setStatus("pbot-history", `历史摘要生成中 (${backend})`),
81
+ update: progress => {
82
+ if (lifecycle.active === instance) {
83
+ ctx.ui.setStatus("pbot-history", `历史摘要 ${progress.dimension} (${progress.completed}/${progress.total})`);
84
+ }
85
+ },
86
+ finish: () => {
87
+ if (lifecycle.active === instance) ctx.ui.setStatus("pbot-history", undefined);
88
+ },
89
+ });
90
+ ctx.ui.notify(JSON.stringify(result, null, 2), "info");
91
+ } catch (error) {
92
+ ctx.ui.notify(error instanceof Error ? error.message : String(error), "error");
93
+ }
94
+ return;
95
+ }
63
96
  if (command === "worker") {
64
97
  try {
65
98
  const { tool, args: payload } = parseWorkerCommand(argument);
@@ -70,7 +103,7 @@ export function registerCommand(pi: ExtensionAPI, lifecycle: Lifecycle, confirma
70
103
  }
71
104
  return;
72
105
  }
73
- ctx.ui.notify('/pbot init | status | worker [overview|status|backends|models|create|request|response|output|close] [JSON]', "info");
106
+ ctx.ui.notify('/pbot init | status | history [summary [维度] [--force] [--backend <acp>] [--model <model>]|migrate [--dry-run]|status|list|JSON] | worker [overview|status|backends|models|create|request|response|output|close] [JSON]', "info");
74
107
  },
75
108
  });
76
109
  }
@@ -2,11 +2,12 @@ import { join, resolve } from "node:path";
2
2
  import { homedir } from "node:os";
3
3
  import { fileURLToPath } from "node:url";
4
4
  import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
5
- import { loadWorkspaceContext } from "../integrations/agent-resources.js";
6
- import type { Confirmations } from "../ui/confirmation.js";
5
+ import { loadWorkspaceContext } from "../../../integrations/agent-resources.js";
6
+ import type { Confirmations } from "../../../ui/pi/confirmation.js";
7
7
  import type { Lifecycle } from "./lifecycle.js";
8
- import { readWorkspaceConfig, workspaceDisabledMessage } from "../services/workspace/workspace-config.js";
9
- import { workspaceSkillPaths } from "../integrations/pi/skills.js";
8
+ import { readWorkspaceConfig, workspaceDisabledMessage } from "../../../services/workspace/workspace-config.js";
9
+ import { historyStartupNotices } from "../../../services/history/summary-runner.js";
10
+ import { workspaceSkillPaths } from "../../../integrations/hosts/pi/skills.js";
10
11
 
11
12
  export function registerEvents(pi: ExtensionAPI, lifecycle: Lifecycle, confirmations: Confirmations) {
12
13
  pi.on("session_start", async (_event, ctx) => {
@@ -18,6 +19,9 @@ export function registerEvents(pi: ExtensionAPI, lifecycle: Lifecycle, confirmat
18
19
  return;
19
20
  }
20
21
  ctx.ui.setStatus("pbot", "PBot 已启动");
22
+ if (lifecycle.active.features.history && ctx.hasUI) {
23
+ for (const notice of historyStartupNotices(lifecycle.active.root)) ctx.ui.notify(notice, "info");
24
+ }
21
25
  } catch (error) {
22
26
  ctx.ui.setStatus("pbot", "PBot 启动失败");
23
27
  if (ctx.hasUI) ctx.ui.notify(error instanceof Error ? error.message : "pbot 启动失败。", "error");
@@ -0,0 +1,45 @@
1
+ import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
2
+ import { recordHistoryCapture } from "../../../services/history/history-capture.js";
3
+ import type { Lifecycle } from "./lifecycle.js";
4
+
5
+ function messageText(content: unknown): string {
6
+ if (typeof content === "string") return content;
7
+ if (!Array.isArray(content)) return "";
8
+ return content.flatMap(block => block?.type === "text" ? [String(block.text)] : block?.type === "image" ? ["[图片]"] : []).join("\n");
9
+ }
10
+
11
+ /** Capture main-session raw Q&A exchanges into .pbot/history/raw/. Summaries run on explicit trigger. */
12
+ export function registerHistoryEvents(pi: ExtensionAPI, lifecycle: Lifecycle) {
13
+ pi.on("before_agent_start", (event, ctx) => {
14
+ const instance = lifecycle.active;
15
+ if (!instance || !instance.features.history || event.messageType !== "user") return;
16
+ const text = event.prompt.trim();
17
+ if (!text) return;
18
+ try {
19
+ recordHistoryCapture(instance.root, "pi", {
20
+ kind: "input",
21
+ sessionId: ctx.sessionManager.getSessionId(),
22
+ text,
23
+ });
24
+ } catch { /* Never block a user turn if history persistence fails. */ }
25
+ });
26
+
27
+ pi.on("agent_end", (event, ctx) => {
28
+ const instance = lifecycle.active;
29
+ if (!instance || !instance.features.history) return;
30
+ const assistant = [...event.messages].reverse().find(message => message.role === "assistant");
31
+ if (!assistant || !("content" in assistant)) return;
32
+ const text = messageText(assistant.content).trim();
33
+ if (!text) return;
34
+ const completed = "stopReason" in assistant && assistant.stopReason === "stop" &&
35
+ !(Array.isArray(assistant.content) && assistant.content.some(block => block.type === "toolCall"));
36
+ try {
37
+ recordHistoryCapture(instance.root, "pi", {
38
+ kind: "answer",
39
+ sessionId: ctx.sessionManager.getSessionId(),
40
+ assistantText: text,
41
+ completed,
42
+ });
43
+ } catch { /* Never block turn completion if history persistence fails. */ }
44
+ });
45
+ }
@@ -1,13 +1,12 @@
1
1
  import { realpath } from "node:fs/promises";
2
- import { requireThat } from "../common/validation.js";
3
- import { authorizeMutation } from "../services/workspace/workspace-files.js";
4
- import type { CallAccess } from "../tools/access.js";
5
- import type { HistoryService } from "../services/history/history-service.js";
6
- import { readWorkspaceConfig, workspaceDisabledMessage, workspaceFeatures } from "../services/workspace/workspace-config.js";
7
- import type { ResolvedWorkspaceFeatures, WorkspaceConfiguration } from "../model/workspace-config.js";
8
- import type { McpWorkerRuntime } from "./mcp-workers.js";
2
+ import { requireThat } from "../../../common/validation.js";
3
+ import { bindWorkspacePlugin } from "../../../services/workspace/plugin-releases.js";
4
+ import { authorizeMutation } from "../../../services/workspace/workspace-files.js";
5
+ import { readWorkspaceConfig, workspaceDisabledMessage, workspaceFeatures } from "../../../services/workspace/workspace-config.js";
6
+ import type { ResolvedWorkspaceFeatures, WorkspaceConfiguration } from "../../../model/workspace-config.js";
7
+ import type { McpWorkerRuntime } from "../../mcp/workers.js";
9
8
 
10
- export class WorkspaceInstance implements CallAccess {
9
+ export class WorkspaceInstance {
11
10
  readonly #controller = new AbortController();
12
11
  #work = new AbortController();
13
12
  #closing: Promise<void> | undefined;
@@ -15,7 +14,6 @@ export class WorkspaceInstance implements CallAccess {
15
14
  constructor(
16
15
  readonly root: string,
17
16
  readonly sessionId: string,
18
- readonly history: HistoryService,
19
17
  readonly workers: McpWorkerRuntime,
20
18
  readonly features: ResolvedWorkspaceFeatures = workspaceFeatures(),
21
19
  ) {}
@@ -45,9 +43,7 @@ export class WorkspaceInstance implements CallAccess {
45
43
  this.#controller.abort();
46
44
  this.#work.abort();
47
45
  this.#closing = (async () => {
48
- const results = await Promise.allSettled([this.workers.close(preserveWorkers), this.history.close()]);
49
- const errors = results.filter(result => result.status === "rejected").map(result => result.reason);
50
- if (errors.length) throw new AggregateError(errors, "工作区关闭失败。");
46
+ await this.workers.close(preserveWorkers);
51
47
  })();
52
48
  return this.#closing;
53
49
  }
@@ -77,6 +73,7 @@ export class Lifecycle {
77
73
  this.root = await realpath(root);
78
74
  this.configuration = await readWorkspaceConfig(this.root);
79
75
  if (!this.configuration.enabled) return;
76
+ bindWorkspacePlugin(this.root, "pi");
80
77
  const instance = this.create(this.root, sessionId, this.configuration);
81
78
  this.#active = instance;
82
79
  try { await this.register(instance); }
@@ -0,0 +1,96 @@
1
+ import { join } from "node:path";
2
+ import { resourceRoot } from "../../common/paths.js";
3
+ import { packageVersion } from "../../common/version.js";
4
+ import { requireThat } from "../../common/validation.js";
5
+ import { loadWorkspaceContext } from "../../integrations/agent-resources.js";
6
+ import type { PluginHostAdapter } from "../../model/plugin-host.js";
7
+ import { recordHistoryCapture } from "../../services/history/history-capture.js";
8
+ import { historyStartupNotices } from "../../services/history/summary-runner.js";
9
+ import { bindWorkspacePlugin } from "../../services/workspace/plugin-releases.js";
10
+ import { readWorkspaceConfig, workspaceFeatures } from "../../services/workspace/workspace-config.js";
11
+ import { initializeWorkspace } from "../../services/workspace/workspace-preparation.js";
12
+ import { discoverSkills, discoverWorkspaceSkills } from "../../services/workspace/workspace-skills.js";
13
+
14
+ function disabledMessage(adapter: PluginHostAdapter, configuration: Awaited<ReturnType<typeof readWorkspaceConfig>>) {
15
+ return configuration.error ?? `Personal Bot 未在此工作区启用。运行 ${adapter.initCommandHint};配置文件:${configuration.path}`;
16
+ }
17
+
18
+ export async function pluginCommand(adapter: PluginHostAdapter, args: readonly string[], cwd: string) {
19
+ const root = await adapter.resolveRoot(cwd);
20
+ const action = args.join(" ");
21
+ requireThat(["init", "status"].includes(action), adapter.usage);
22
+ if (action === "init") {
23
+ await initializeWorkspace(root);
24
+ bindWorkspacePlugin(root, adapter.host, process.env.PBOT_PLUGIN_MANIFEST || process.env.PBOT_PLUGIN_VERSION);
25
+ }
26
+ const configuration = await readWorkspaceConfig(root);
27
+ return { version: packageVersion, workspaceRoot: root, resourceRoot, configuration };
28
+ }
29
+
30
+ export type ReplayPluginHook = (root: string, input: string) => Promise<number | undefined>;
31
+
32
+ export async function runPluginHost(adapter: PluginHostAdapter, args: readonly string[], replay?: ReplayPluginHook): Promise<void> {
33
+ if (args[0] === "hook") {
34
+ let input = "";
35
+ process.stdin.setEncoding("utf8");
36
+ for await (const chunk of process.stdin) input += String(chunk);
37
+ const result = await pluginHook(adapter, JSON.parse(input), replay && (root => replay(root, input)));
38
+ if (typeof result === "number") process.exitCode = result;
39
+ else process.stdout.write(JSON.stringify(result) + "\n");
40
+ } else {
41
+ process.stdout.write(JSON.stringify(await pluginCommand(adapter, args, process.cwd()), null, 2) + "\n");
42
+ }
43
+ }
44
+
45
+ /** Shared hook execution engine; host-specific protocols stay in PluginHostAdapter implementations. */
46
+ export function pluginHook(adapter: PluginHostAdapter, payload: unknown): Promise<Record<string, unknown>>;
47
+ export function pluginHook(adapter: PluginHostAdapter, payload: unknown, replay: ((root: string) => Promise<number | undefined>) | undefined): Promise<Record<string, unknown> | number>;
48
+ export async function pluginHook(adapter: PluginHostAdapter, payload: unknown, replay?: (root: string) => Promise<number | undefined>) {
49
+ if (process.env.PBOT_SUBAGENT_RUN_ID) return adapter.formatPass(payload);
50
+ const event = adapter.parseEvent(payload);
51
+ if (event.kind === "ignore") return adapter.formatPass(payload);
52
+ const root = await adapter.resolveRoot(event.cwd, event.raw);
53
+ const configuration = await readWorkspaceConfig(root);
54
+ if (configuration.enabled && replay) {
55
+ const code = await replay(root);
56
+ if (code !== undefined) return code;
57
+ }
58
+ const features = workspaceFeatures(configuration);
59
+ if (event.kind === "check-skill") {
60
+ if (!configuration.enabled) return adapter.formatDeny(event, disabledMessage(adapter, configuration));
61
+ if (!features.skills) return adapter.formatDeny(event, `Personal Bot 工作区技能已在 ${configuration.path} 中停用(features.skills: false)。`);
62
+ return adapter.formatPass(payload);
63
+ }
64
+ if (!configuration.enabled) return adapter.formatPass(payload);
65
+ if (event.kind === "inject-context") bindWorkspacePlugin(root, adapter.host, process.env.PBOT_PLUGIN_MANIFEST || process.env.PBOT_PLUGIN_VERSION);
66
+ if (features.history && adapter.extractHistory) {
67
+ try {
68
+ const capture = await adapter.extractHistory(event);
69
+ if (capture) recordHistoryCapture(root, adapter.host, capture);
70
+ } catch { /* Never block a host turn if history persistence encounters a transient error or busy lock. */ }
71
+ }
72
+ if (event.kind === "record-history") return adapter.formatPass(payload);
73
+ const includePrompts = features.prompts && !event.noticesOnly;
74
+ const includeSkills = features.skills && !event.noticesOnly;
75
+ const workspaceSkills = includeSkills && !adapter.nativeWorkspaceSkills
76
+ ? await discoverWorkspaceSkills(root)
77
+ : [];
78
+ if (includeSkills && adapter.indexBundledSkills) {
79
+ const directory = join(resourceRoot, "skills");
80
+ workspaceSkills.push(...await discoverSkills(directory, directory));
81
+ }
82
+ const notices = event.isSessionStart && features.history ? historyStartupNotices(root) : [];
83
+ if (!includePrompts && !workspaceSkills.length && !notices.length) return adapter.formatPass(payload);
84
+ const context = await loadWorkspaceContext({
85
+ host: adapter.host,
86
+ root,
87
+ role: event.role,
88
+ ...(adapter.coordinatorPrompt ? { coordinatorPrompt: adapter.coordinatorPrompt } : {}),
89
+ includePrompts,
90
+ includeRootAgents: includePrompts && !adapter.nativeRootAgents,
91
+ ...(event.localRoleOnly ? { localRoleOnly: true } : {}),
92
+ workspaceSkills,
93
+ notices,
94
+ });
95
+ return adapter.formatContext(event, context);
96
+ }
@@ -0,0 +1,25 @@
1
+ import type { ResolvedWorkspaceMcpServer } from "../../model/workspace-mcp.js";
2
+ import { readWorkspaceMcpConfig, resolveWorkspaceMcpServer } from "../../services/workspace/workspace-mcp.js";
3
+
4
+ /** A native host can keep its other tools when one workspace server cannot be mounted. */
5
+ export async function loadNativeWorkspaceServers(
6
+ root: string,
7
+ mount: (server: ResolvedWorkspaceMcpServer) => void | Promise<void>,
8
+ options: { check?: () => void; warn?: (message: string) => void } = {},
9
+ ) {
10
+ const config = await readWorkspaceMcpConfig(root);
11
+ options.check?.();
12
+ if (config.error) {
13
+ options.warn?.(config.error);
14
+ return;
15
+ }
16
+ for (const [name, server] of Object.entries(config.servers)) {
17
+ if (server.enabled === false) continue;
18
+ options.check?.();
19
+ try {
20
+ await mount(resolveWorkspaceMcpServer(root, name, server));
21
+ } catch (error) {
22
+ options.warn?.(error instanceof Error ? error.message : String(error));
23
+ }
24
+ }
25
+ }