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,3 +1,8 @@
1
+ import type { HistoryLayout } from "./workspace-config.js";
2
+
3
+ export type { HistoryLayout };
4
+ export type HistoryHost = string;
5
+
1
6
  export interface HistoryExchange {
2
7
  entryIds: string[];
3
8
  text: string;
@@ -5,6 +10,7 @@ export interface HistoryExchange {
5
10
  to: string;
6
11
  completed: boolean;
7
12
  }
13
+
8
14
  export interface HistorySession {
9
15
  sessionId: string;
10
16
  name: string;
@@ -12,48 +18,172 @@ export interface HistorySession {
12
18
  /** Earlier partial observations replaced along the same native branch or turn; never persisted. */
13
19
  supersededEntryIds?: string[];
14
20
  }
21
+
15
22
  export interface HistoryIdentity {
16
23
  host: HistoryHost;
17
24
  id: string;
18
25
  sessionId: string;
19
26
  }
27
+
20
28
  export interface RawHistory extends HistoryIdentity {
21
29
  name: string;
22
30
  /** One entry per archived exchange; array order does not describe a conversation. */
23
31
  exchanges: (HistoryExchange & { id: string })[];
24
- /** Ordered paths observed in the native source. Legacy exchanges can have no known path. */
32
+ /** Ordered paths observed in the native source. */
25
33
  branches: string[][];
26
34
  }
27
- export interface HistorySummary extends HistoryExchange {
28
- id: string;
29
- level: number;
30
- children: string[];
31
- ready: boolean;
32
- }
33
- export interface HistoryArchive {
34
- raw: RawHistory;
35
- /** Empty if absent; null if the derived file is unreadable. */
36
- summaries: HistorySummary[] | null;
37
- }
38
- export interface HistoryNode extends HistorySummary {
39
- kind: "session" | "exchange" | "summary";
40
- parents: string[];
41
- }
42
- /** Query view and legacy on-disk format. New writers persist raw exchanges and summaries separately. */
43
- export interface HistoryRecord extends HistoryIdentity {
44
- name: string;
45
- nodes: HistoryNode[];
35
+
36
+ export interface SummarySource {
37
+ rawIds: string[];
38
+ exchangeIds: string[];
39
+ fingerprint: string;
46
40
  }
47
- export type HistoryHost = "pi" | "dsh" | "claude";
48
- export type HistoryLocation = { host: "pi"; directory: string; file?: string } |
49
- { host: "dsh"; sessionId?: string };
50
- export interface HistorySource {
51
- readonly host: HistoryLocation["host"];
52
- scan(location: HistoryLocation, signal?: AbortSignal, excluded?: ReadonlySet<string>): Promise<{ sessions: HistorySession[]; warnings: string[] }>;
41
+
42
+ export interface SummaryArtifact {
43
+ id: string;
44
+ dimension: string;
45
+ host?: HistoryHost;
46
+ sessionId?: string;
47
+ title: string;
48
+ text: string;
49
+ from: string;
50
+ to: string;
51
+ updatedAt: string;
52
+ source: SummarySource;
53
53
  }
54
+
54
55
  export interface HistorySummaryRequest {
55
56
  system: string;
56
57
  prompt: string;
57
58
  maxTokens: number;
58
59
  }
60
+
59
61
  export type HistorySummarizer = (request: HistorySummaryRequest, signal: AbortSignal) => Promise<string>;
62
+
63
+ export type SummaryTaskMode = "create" | "incremental" | "rebuild";
64
+
65
+ export interface SummaryTask {
66
+ id: string;
67
+ dimension: string;
68
+ mode: SummaryTaskMode;
69
+ title: string;
70
+ host?: HistoryHost;
71
+ sessionId?: string;
72
+ from: string;
73
+ to: string;
74
+ source: SummarySource;
75
+ exchanges: readonly (HistoryExchange & { id: string })[];
76
+ existing?: SummaryArtifact;
77
+ addedExchanges?: readonly (HistoryExchange & { id: string })[];
78
+ sourceSummaries?: readonly SummaryArtifact[];
79
+ }
80
+
81
+ export interface SummaryPlanOptions {
82
+ force?: boolean;
83
+ summariesByDimension?: ReadonlyMap<string, ReadonlyMap<string, SummaryArtifact>>;
84
+ }
85
+
86
+ export interface SummaryPlanResult {
87
+ tasks: SummaryTask[];
88
+ skipped: number;
89
+ }
90
+
91
+ export interface SummaryDimension {
92
+ readonly id: string;
93
+ readonly title: string;
94
+ readonly description: string;
95
+ readonly requiresMonthlyLayout?: boolean;
96
+ plan(
97
+ raws: readonly RawHistory[],
98
+ existing: ReadonlyMap<string, SummaryArtifact>,
99
+ options?: SummaryPlanOptions,
100
+ ): SummaryPlanResult;
101
+ buildRequest(task: SummaryTask): HistorySummaryRequest;
102
+ finalize(task: SummaryTask, output: string, now: string): SummaryArtifact;
103
+ }
104
+
105
+ export interface HistoryMigrationItem {
106
+ kind: "raw" | "summary";
107
+ dimension?: string;
108
+ id: string;
109
+ from: string;
110
+ to: string;
111
+ }
112
+
113
+ export interface HistoryMigrationConflict {
114
+ kind: "raw" | "summary";
115
+ dimension?: string;
116
+ from: string;
117
+ to: string;
118
+ reason: string;
119
+ }
120
+
121
+ export interface HistoryMigrationReport {
122
+ layout: HistoryLayout;
123
+ dryRun: boolean;
124
+ moved: HistoryMigrationItem[];
125
+ skipped: HistoryMigrationConflict[];
126
+ errors: { path: string; error: string }[];
127
+ }
128
+
129
+ export interface SummaryDimensionStatus {
130
+ dimension: string;
131
+ title: string;
132
+ description: string;
133
+ total: number;
134
+ ready: number;
135
+ pendingCreate: number;
136
+ pendingIncremental: number;
137
+ pendingRebuild: number;
138
+ }
139
+
140
+ export interface HistorySummaryReminder {
141
+ rawCount: number;
142
+ pendingCount: number;
143
+ oldestRawAt: string;
144
+ latestSummaryAt?: string;
145
+ rawAgeDays: number;
146
+ daysSinceLastSummary?: number;
147
+ thresholdDays: number;
148
+ message: string;
149
+ }
150
+
151
+ export interface SummaryRunProgress {
152
+ dimension: string;
153
+ completed: number;
154
+ total: number;
155
+ currentId: string;
156
+ mode: SummaryTaskMode;
157
+ }
158
+
159
+ export interface SummaryDimensionReport {
160
+ dimension: string;
161
+ scanned: number;
162
+ skipped: number;
163
+ created: number;
164
+ incremental: number;
165
+ rebuilt: number;
166
+ failed: { id: string; error: string }[];
167
+ }
168
+
169
+ export interface SummaryRunReport {
170
+ dimensions: SummaryDimensionReport[];
171
+ durationMs: number;
172
+ warnings: string[];
173
+ }
174
+
175
+ export const historyPageLimits = {
176
+ search: { default: 20, max: 50 },
177
+ read: { default: 12_000, max: 24_000 },
178
+ } as const;
179
+
180
+ export interface HistoryQuery {
181
+ host?: HistoryHost;
182
+ query?: string;
183
+ sessionId?: string;
184
+ dimension?: string;
185
+ from?: string;
186
+ to?: string;
187
+ offset?: number;
188
+ limit?: number;
189
+ }
@@ -0,0 +1,41 @@
1
+ export interface PluginSpec {
2
+ id: string;
3
+ label: string;
4
+ description: string;
5
+ source: string;
6
+ defaultSelected: boolean;
7
+ }
8
+ export interface InstalledPackage {
9
+ source: string;
10
+ scope: "user" | "project";
11
+ name?: string;
12
+ version?: string;
13
+ installedPath?: string;
14
+ filtered: boolean;
15
+ entry: unknown;
16
+ }
17
+ export interface PackageChoice {
18
+ plugin: PluginSpec;
19
+ required: boolean;
20
+ existing: InstalledPackage[];
21
+ selected: boolean;
22
+ keep: boolean;
23
+ target?: string;
24
+ error?: string;
25
+ }
26
+ export interface PiInstallation { command: string; root: string; version: string }
27
+ export interface SystemCommand { command: string; args: string[] }
28
+ export interface SetupPlan {
29
+ workspace: string;
30
+ pi?: PiInstallation;
31
+ piVersion: string;
32
+ tmux?: SystemCommand;
33
+ packages: PackageChoice[];
34
+ }
35
+ export interface SetupResult { name: string; state: "done" | "kept" | "skipped" | "failed"; detail: string }
36
+ export interface SetupOperations {
37
+ installTmux(command: SystemCommand): Promise<void>;
38
+ ensurePi(existing: PiInstallation | undefined, version: string): Promise<PiInstallation>;
39
+ installPackage(pi: PiInstallation, workspace: string, choice: PackageChoice): Promise<string>;
40
+ verifyKeptPackage(pi: PiInstallation, workspace: string, choice: PackageChoice): Promise<string>;
41
+ }
@@ -1,3 +1,4 @@
1
+ import type { HistorySession } from "./history.js";
1
2
  import type { WorkspaceSkillMeta } from "./workspace-mcp.js";
2
3
 
3
4
  export type HostId = string;
@@ -19,20 +20,47 @@ export interface WorkspaceContext {
19
20
  text: string;
20
21
  }
21
22
 
23
+ export type HistoryCapture =
24
+ | {
25
+ kind: "input";
26
+ sessionId: string;
27
+ turnId?: string;
28
+ text: string;
29
+ timestamp?: string;
30
+ }
31
+ | {
32
+ kind: "answer";
33
+ sessionId: string;
34
+ turnId?: string;
35
+ userText?: string;
36
+ assistantText: string;
37
+ completed: boolean;
38
+ isContinuation?: boolean;
39
+ timestamp?: string;
40
+ }
41
+ | {
42
+ kind: "session";
43
+ session: HistorySession;
44
+ };
45
+
22
46
  export type HostEvent =
23
47
  | { kind: "ignore" }
24
- | { kind: "inject-context"; role: WorkspaceRole; localRoleOnly?: boolean; cwd: string; raw: unknown }
25
- | { kind: "check-skill"; skill: string; cwd: string; raw: unknown };
48
+ | { kind: "inject-context"; role: WorkspaceRole; localRoleOnly?: boolean; isSessionStart?: boolean; noticesOnly?: boolean; cwd: string; raw: unknown }
49
+ | { kind: "check-skill"; skill: string; cwd: string; raw: unknown }
50
+ | { kind: "record-history"; cwd: string; raw: unknown };
26
51
 
27
52
  export interface PluginHostAdapter {
28
53
  readonly host: PluginHostId;
29
54
  readonly nativeRootAgents: boolean;
55
+ readonly indexBundledSkills?: boolean;
30
56
  readonly nativeWorkspaceSkills?: boolean;
31
57
  readonly coordinatorPrompt?: string;
32
58
  readonly initCommandHint: string;
33
59
  readonly usage: string;
60
+ boundWorkspaceRoot?(): string | undefined;
34
61
  resolveRoot(cwd: string, rawPayload?: unknown): Promise<string>;
35
62
  parseEvent(payload: unknown): HostEvent;
63
+ extractHistory?(event: Extract<HostEvent, { kind: "inject-context" | "record-history" }>): Promise<HistoryCapture | undefined>;
36
64
  formatPass(payload: unknown): Record<string, unknown>;
37
65
  formatContext(event: Extract<HostEvent, { kind: "inject-context" }>, context: WorkspaceContext): Record<string, unknown>;
38
66
  formatDeny(event: Extract<HostEvent, { kind: "check-skill" }>, reason: string): Record<string, unknown>;
@@ -4,25 +4,49 @@ export interface WorkspaceFeatures {
4
4
  prompts?: boolean;
5
5
  skills?: boolean;
6
6
  mcp?: boolean;
7
+ history?: boolean;
7
8
  }
8
9
 
9
- export interface ResolvedWorkspaceFeatures {
10
- readonly prompts: boolean;
11
- readonly skills: boolean;
12
- readonly mcp: boolean;
10
+ export type ResolvedWorkspaceFeatures = Readonly<Required<WorkspaceFeatures>>;
11
+
12
+ export const summaryConcurrency = { default: 3, max: 8 } as const;
13
+
14
+ export interface WorkspaceSummaryConfig {
15
+ backend?: string;
16
+ model?: string;
17
+ thinking?: string;
18
+ concurrency?: number;
19
+ }
20
+
21
+ export interface ResolvedWorkspaceSummaryConfig {
22
+ readonly backend: string;
23
+ readonly model?: string;
24
+ readonly thinking?: string;
25
+ readonly concurrency: number;
26
+ }
27
+
28
+ export const historyLayouts = ["monthly", "flat"] as const;
29
+ export type HistoryLayout = typeof historyLayouts[number];
30
+
31
+ export interface WorkspaceHistoryConfig {
32
+ layout?: HistoryLayout;
33
+ }
34
+
35
+ export interface ResolvedWorkspaceHistoryConfig {
36
+ readonly layout: HistoryLayout;
13
37
  }
14
38
 
15
39
  export interface WorkspaceConfig {
16
40
  enabled?: boolean;
17
41
  features?: WorkspaceFeatures;
18
42
  acp?: AcpCommands;
43
+ summary?: WorkspaceSummaryConfig;
44
+ history?: WorkspaceHistoryConfig;
19
45
  }
20
46
 
21
- export interface WorkspaceConfiguration {
47
+ export interface WorkspaceConfiguration extends WorkspaceConfig {
22
48
  path: string;
23
49
  present: boolean;
24
50
  enabled: boolean;
25
51
  error?: string;
26
- features?: WorkspaceFeatures;
27
- acp?: AcpCommands;
28
52
  }
package/src/pbot.ts CHANGED
@@ -1,21 +1,14 @@
1
- import { existsSync } from "node:fs";
2
- import { join, resolve } from "node:path";
3
1
  import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
4
- import { resourceRoot } from "./common/paths.js";
5
- import { Confirmations } from "./ui/confirmation.js";
6
- import { ToolRegistry, mainTools } from "./tools/register.js";
7
- import { Lifecycle, WorkspaceInstance } from "./extension/lifecycle.js";
8
- import { registerCommand } from "./extension/command.js";
9
- import { registerEvents } from "./extension/events.js";
10
- import { registerHistoryEvents } from "./extension/history.js";
11
- import { McpWorkerRuntime, defaultWorkerDirectory } from "./extension/mcp-workers.js";
12
- import { HistoryService } from "./services/history/history-service.js";
2
+ import { Confirmations } from "./ui/pi/confirmation.js";
3
+ import { registerPiHistoryTool } from "./tools/history/pi-tool.js";
4
+ import { Lifecycle, WorkspaceInstance } from "./extension/hosts/pi/lifecycle.js";
5
+ import { registerCommand } from "./extension/hosts/pi/command.js";
6
+ import { registerEvents } from "./extension/hosts/pi/events.js";
7
+ import { registerHistoryEvents } from "./extension/hosts/pi/history.js";
8
+ import { McpWorkerRuntime, defaultWorkerDirectory } from "./extension/mcp/workers.js";
13
9
  import { workspaceFeatures } from "./services/workspace/workspace-config.js";
14
- import { readWorkspaceMcpConfig, resolveWorkspaceMcpServer } from "./services/workspace/workspace-mcp.js";
15
- import { HistoryFiles } from "./storage/history-files.js";
16
- import { PiHistory } from "./integrations/pi/history.js";
17
- import { toPiMcpConfig } from "./integrations/pi/mcp.js";
18
- import { acpHistorySessions } from "./storage/acp-history.js";
10
+ import { loadNativeWorkspaceServers } from "./extension/hosts/workspace-mcp.js";
11
+ import { toPiMcpConfig } from "./integrations/hosts/pi/mcp.js";
19
12
 
20
13
  const mcpServerName = "pbot";
21
14
 
@@ -23,59 +16,38 @@ export default function pbot(pi: ExtensionAPI) {
23
16
  // The explicitly loaded child entry owns the child; normal discovery never grants main privileges.
24
17
  if (process.env.PBOT_SUBAGENT_RUN_ID) return;
25
18
  const confirmations = new Confirmations();
26
- const registry = new ToolRegistry(pi);
27
- const mcpEntry = resolve(resourceRoot, "../lib/extension/mcp.js");
19
+ let hideHistory: (() => void) | undefined;
28
20
  const registeredMcpServers: string[] = [];
29
21
 
30
22
  const lifecycle = new Lifecycle(
31
23
  (root, sessionId, configuration) => {
32
24
  const workerDir = defaultWorkerDirectory();
33
25
  const workers = new McpWorkerRuntime(workerDir, sessionId, "pi");
34
- const history = new HistoryService(
35
- root,
36
- new HistoryFiles(join(root, ".pbot/history"), "pi"),
37
- new PiHistory(root),
38
- [new HistoryFiles(join(root, ".pbot/history"), "dsh"), new HistoryFiles(join(root, ".pbot/history"), "claude")],
39
- () => acpHistorySessions({ mcp: workerDir }),
40
- );
41
- return new WorkspaceInstance(root, sessionId, history, workers, workspaceFeatures(configuration));
26
+ return new WorkspaceInstance(root, sessionId, workers, workspaceFeatures(configuration));
42
27
  },
43
28
  async instance => {
44
- registry.register(mainTools(instance.history, instance));
45
- if (existsSync(mcpEntry)) {
29
+ if (instance.features.history) hideHistory = registerPiHistoryTool(pi, instance.root, instance);
30
+ const server = instance.workers.nativeServer(instance.root);
31
+ if (server) {
46
32
  pi.registerMcpServer(mcpServerName, {
47
33
  type: "stdio",
48
- command: process.execPath,
49
- args: [mcpEntry],
50
- env: {
51
- PBOT_HOST: "pi",
52
- PBOT_WORKSPACE_ROOT: instance.root,
53
- PBOT_MCP_AGENT_DIR: defaultWorkerDirectory(),
54
- PBOT_MCP_SESSION_ID: instance.sessionId,
55
- },
34
+ ...server,
56
35
  exposure: "direct",
57
36
  timeout: 600,
58
- description: "跨代理程序委派(worker_*)与工作区统一 MCP 桥接(workspace_mcp_*)",
37
+ description: "跨代理程序委派(worker_*)",
59
38
  });
60
39
  registeredMcpServers.push(mcpServerName);
61
40
  }
62
41
  if (instance.features.mcp) {
63
- const mcpConfig = await readWorkspaceMcpConfig(instance.root);
64
- instance.check();
65
- if (!mcpConfig.error) {
66
- for (const [name, server] of Object.entries(mcpConfig.servers)) {
67
- if (server.enabled === false) continue;
68
- try {
69
- const resolved = resolveWorkspaceMcpServer(instance.root, name, server);
70
- pi.registerMcpServer(resolved.name, toPiMcpConfig(resolved));
71
- registeredMcpServers.push(resolved.name);
72
- } catch { /* Keep the workspace active even if one external MCP env var is unset. */ }
73
- }
74
- }
42
+ await loadNativeWorkspaceServers(instance.root, server => {
43
+ pi.registerMcpServer(server.name, toPiMcpConfig(server));
44
+ registeredMcpServers.push(server.name);
45
+ }, { check: () => instance.check() });
75
46
  }
76
47
  },
77
48
  () => {
78
- registry.hide();
49
+ hideHistory?.();
50
+ hideHistory = undefined;
79
51
  for (const name of registeredMcpServers.splice(0)) {
80
52
  pi.unregisterMcpServer(name);
81
53
  }
package/src/plugin.ts CHANGED
@@ -1,14 +1,14 @@
1
1
  import { realpathSync } from "node:fs";
2
2
  import { pathToFileURL } from "node:url";
3
3
  import { requireThat } from "./common/validation.js";
4
- import { runPluginHost } from "./extension/plugin-runtime.js";
5
- import { listPluginHosts, pluginHosts } from "./integrations/hosts/registry.js";
4
+ import { runPluginHost, type ReplayPluginHook } from "./extension/hosts/plugin-runtime.js";
5
+ import { listPluginHosts, pluginHosts } from "./integrations/hosts/plugin-registry.js";
6
6
 
7
- export async function main(args: readonly string[]): Promise<void> {
7
+ export async function main(args: readonly string[], replayHook?: ReplayPluginHook): Promise<void> {
8
8
  const [host, ...rest] = args;
9
9
  const adapter = host ? pluginHosts.get(host) : undefined;
10
10
  requireThat(adapter, `用法:node <插件目录>/lib/plugin.js <${listPluginHosts().join("|")}> hook|init|status`);
11
- await runPluginHost(adapter, rest);
11
+ await runPluginHost(adapter, rest, replayHook);
12
12
  }
13
13
 
14
14
  if (process.argv[1] && import.meta.url === pathToFileURL(realpathSync(process.argv[1])).href) {
@@ -5,24 +5,14 @@ import { object } from "../../common/json.js";
5
5
  import { packageVersion, releaseLine } from "../../common/version.js";
6
6
  import { requireThat } from "../../common/validation.js";
7
7
  import { AgentFiles, descriptor, launch, status, cycle } from "../../storage/agent-files.js";
8
- import type { AgentOwner, AgentOptions, AgentPendingRequest, AgentResponseInput, AgentStartOptions, AgentDescriptor, AgentCycle, AgentSessionReference, AgentView } from "../../model/agent.js";
9
- import type { AcpBackend, AcpSessionReference } from "../../model/acp.js";
8
+ import type { AgentOwner, AgentOptions, AgentMessage, AgentPendingRequest, AgentResponseInput, AgentStartOptions, AgentDescriptor, AgentCycle, AgentHost, AgentView } from "../../model/agent.js";
10
9
  import { acpElicitationReply, acpModelState, acpPermissionReply, acpReference } from "../../storage/acp-files.js";
11
10
 
12
- export interface AgentHost {
13
- available(backend: AcpBackend): void;
14
- filterOptions?(backend: AcpBackend, options: AgentOptions): AgentOptions;
15
- prepare(backend: AcpBackend, options: AgentOptions): AcpSessionReference;
16
- alive(id: string): boolean;
17
- validateSession(value: AgentDescriptor, reference: AgentSessionReference): void | Promise<void>;
18
- launch(value: AgentDescriptor, directory: string, generation: string, reference: AgentSessionReference, resume: boolean, signal: AbortSignal): void | Promise<void>;
19
- release(id: string, generation: string): void | Promise<void>;
20
- report(value: AgentDescriptor, reference: AgentSessionReference, leaf: string): string | Promise<string>;
21
- }
11
+ export type { AgentHost } from "../../model/agent.js";
22
12
 
23
13
  /** Host-neutral lifecycle manager for cross-harness ACP workers. */
24
14
  export class AgentService {
25
- readonly files: AgentFiles;
15
+ private readonly files: AgentFiles;
26
16
  #closed = false;
27
17
  #preserve = false;
28
18
  readonly #starting = new Map<string, { generation: string; controller: AbortController; stage: "validate" | "launch" }>();
@@ -218,7 +208,7 @@ export class AgentService {
218
208
  try { await operation; } finally { this.#launches.delete(operation); }
219
209
  }
220
210
 
221
- send(id: string, text: string, delivery: "steer" | "followUp", owner: AgentOwner, attachments: readonly string[] = []) {
211
+ send(id: string, text: string, delivery: AgentMessage["delivery"], owner: AgentOwner, attachments: readonly string[] = []) {
222
212
  const d = this.get(id, owner);
223
213
  return this.files.control(() => {
224
214
  requireThat(this.alive(id) && this.#starting.get(id)?.stage !== "validate" && !this.files.read(id, "launch.json", launch).stop, "worker 已停止或仍在恢复校验,请等待显式恢复完成。");
@@ -298,7 +288,12 @@ export class AgentService {
298
288
  }
299
289
 
300
290
  cycles(id: string, owner: AgentOwner): AgentCycle[] {
301
- const d = this.get(id, owner), view = this.view(d, owner), values = this.files.completions(id);
291
+ return this.cyclesFor(this.view(this.get(id, owner), owner));
292
+ }
293
+
294
+ private cyclesFor(view: AgentView): AgentCycle[] {
295
+ const id = view.agentId;
296
+ const values = this.files.completions(id);
302
297
  if (view.cycle && !values.some(c => c.cycleId === view.cycle!.cycleId)) {
303
298
  values.push(view.state === "stopped" || view.state === "error" ? { ...view.cycle, state: "interrupted", finishedAt: view.cycle.finishedAt ?? Date.now() } : view.cycle);
304
299
  }
@@ -321,9 +316,26 @@ export class AgentService {
321
316
  return values;
322
317
  }
323
318
 
319
+ private snapshot(id: string, owner: AgentOwner) {
320
+ const view = this.view(this.get(id, owner), owner);
321
+ const cycles = this.cyclesFor(view);
322
+ const latest = cycles.at(-1);
323
+ return { current: latest ? { ...view, cycle: latest } : view, cycles };
324
+ }
325
+
324
326
  status(id: string, owner: AgentOwner) {
325
- const d = this.get(id, owner), latest = this.cycles(id, owner).at(-1);
326
- return { ...this.view(d, owner), ...(latest ? { cycle: latest } : {}) };
327
+ return this.snapshot(id, owner).current;
328
+ }
329
+
330
+ outputStatus(id: string, owner: AgentOwner, requestId?: string) {
331
+ const { current, cycles } = this.snapshot(id, owner);
332
+ const request = requestId ?? this.files.messages(id).findLast(item => item.generation === current.generation)?.requestId;
333
+ const cycle = request
334
+ ? cycles.find(item => item.generation === current.generation && item.requestIds.includes(request))
335
+ : current.cycle;
336
+ const stopped = current.state === "stopped" || current.state === "error";
337
+ const terminal = request ? stopped && !cycle : stopped || (current.state === "idle" && !cycle);
338
+ return { current, cycle, terminal };
327
339
  }
328
340
 
329
341
  async read(id: string, owner: AgentOwner, cycleId?: string, offset = 0, limit = 16000) {
@@ -0,0 +1,91 @@
1
+ import { randomUUID } from "node:crypto";
2
+ import { isDeepStrictEqual } from "node:util";
3
+ import type { HistoryExchange, HistoryHost, HistorySession, RawHistory } from "../../model/history.js";
4
+ import type { HistoryCapture } from "../../model/plugin-host.js";
5
+ import { workspaceHistoryFiles } from "./workspace-history.js";
6
+ import { indexHistory, orderedRawExchanges } from "./history-index.js";
7
+
8
+ function orderedExchanges(raw?: RawHistory): HistoryExchange[] {
9
+ if (!raw) return [];
10
+ return orderedRawExchanges(raw).map(({ entryIds, text, from, to, completed }) => ({
11
+ entryIds: [...entryIds],
12
+ text,
13
+ from,
14
+ to,
15
+ completed,
16
+ }));
17
+ }
18
+
19
+ function replaceAssistantSuffix(text: string, assistantText: string): string {
20
+ const marker = "\n\n助手:\n";
21
+ const section = `助手:\n${assistantText}`;
22
+ if (text === section || text.endsWith("\n\n" + section)) return text;
23
+ if (!text || text.startsWith("助手:\n")) return section;
24
+ const index = text.lastIndexOf(marker);
25
+ if (index >= 0) return text.slice(0, index) + marker + assistantText;
26
+ return text + marker + assistantText;
27
+ }
28
+
29
+ function buildSession(host: HistoryHost, capture: HistoryCapture, previous?: RawHistory): HistorySession | undefined {
30
+ if (capture.kind === "session") {
31
+ return capture.session.branches.length ? capture.session : undefined;
32
+ }
33
+ const timestamp = capture.timestamp ?? new Date().toISOString();
34
+ const branch = orderedExchanges(previous);
35
+ // entryIds already identify native observations on disk. A turn keeps its ID
36
+ // across steering, attachment-only inputs and Stop hooks arriving out of order.
37
+ const turnEntry = capture.turnId ? `${host}:turn:${capture.turnId}` : undefined;
38
+ const turn = turnEntry ? branch.find(item => item.entryIds.includes(turnEntry)) : undefined;
39
+ const entryId = () => turnEntry ?? `${host}:${Date.now()}:${randomUUID().slice(0, 8)}`;
40
+ if (capture.kind === "input") {
41
+ const text = capture.text.trim();
42
+ if (!text && !turnEntry) return undefined;
43
+ const input = "用户:\n" + (text || "(无文本输入)");
44
+ if (turn) {
45
+ turn.text += "\n\n" + input;
46
+ turn.to = timestamp;
47
+ turn.completed = false;
48
+ } else {
49
+ branch.push({ entryIds: [entryId()], text: input, from: timestamp, to: timestamp, completed: false });
50
+ }
51
+ return { sessionId: capture.sessionId, name: previous?.name ?? "", branches: [branch] };
52
+ }
53
+ const assistantText = capture.assistantText.trim();
54
+ if (!assistantText) return undefined;
55
+ const target = turnEntry ? turn : branch.at(-1);
56
+ if (target && (turnEntry || !target.completed || capture.isContinuation)) {
57
+ const updated = turnEntry && !target.completed
58
+ ? target.text + "\n\n助手:\n" + assistantText
59
+ : replaceAssistantSuffix(target.text, assistantText);
60
+ if (target.text === updated && target.completed === capture.completed) return undefined;
61
+ target.text = updated;
62
+ target.to = timestamp;
63
+ target.completed = capture.completed;
64
+ } else {
65
+ const userText = capture.userText?.trim();
66
+ branch.push({
67
+ entryIds: [entryId()],
68
+ text: userText ? `用户:\n${userText}\n\n助手:\n${assistantText}` : `助手:\n${assistantText}`,
69
+ from: timestamp,
70
+ to: timestamp,
71
+ completed: capture.completed,
72
+ });
73
+ }
74
+ return { sessionId: capture.sessionId, name: previous?.name ?? "", branches: [branch] };
75
+ }
76
+
77
+ /** Persist a host raw history observation atomically into .pbot/history/raw/. */
78
+ export function recordHistoryCapture(root: string, host: HistoryHost, capture: HistoryCapture): void {
79
+ const sessionId = capture.kind === "session" ? capture.session.sessionId : capture.sessionId;
80
+ if (!sessionId) return;
81
+ const files = workspaceHistoryFiles(root, host);
82
+ files.control(() => {
83
+ const previous = files.listRaw(host).find(raw => raw.sessionId === sessionId);
84
+ if (!previous && files.rawWarnings.length) return;
85
+ const session = buildSession(host, capture, previous);
86
+ if (!session || !session.branches.length) return;
87
+ const raw = indexHistory(session, previous, host);
88
+ if (isDeepStrictEqual(raw, previous)) return;
89
+ files.saveRaw(raw);
90
+ });
91
+ }