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,83 +0,0 @@
1
- import { realpath, stat } from "node:fs/promises";
2
- import { isAbsolute, join, relative, resolve, sep } from "node:path";
3
- import { object } from "../../common/json.js";
4
- import { resourceRoot } from "../../common/paths.js";
5
- import { requireThat } from "../../common/validation.js";
6
- import type { HostEvent, PluginHostAdapter } from "../../model/plugin-host.js";
7
-
8
- const supportedEvents = ["SessionStart", "PreToolUse"];
9
-
10
- function workspaceFromPayload(cwd: string, payload?: unknown): string {
11
- if (object(payload) && Array.isArray(payload.workspacePaths)) {
12
- const first = payload.workspacePaths.find(value => typeof value === "string" && value.length > 0);
13
- if (typeof first === "string") return first;
14
- }
15
- return cwd;
16
- }
17
-
18
- function skillFromReadPath(targetPath: string, pluginRoot = process.env.PLUGIN_ROOT || resolve(resourceRoot, "..")): string | undefined {
19
- const skillsRoot = resolve(pluginRoot, "skills");
20
- const rel = relative(skillsRoot, resolve(targetPath));
21
- if (!rel || rel.startsWith("..") || isAbsolute(rel)) return undefined;
22
- const skill = rel.split(sep)[0];
23
- if (!skill || skill === "pbot") return undefined;
24
- return skill;
25
- }
26
-
27
- function isPreToolUse(payload: unknown): boolean {
28
- return object(payload) && payload.hookEventName === "PreToolUse";
29
- }
30
-
31
- export async function antigravityWorkspaceRoot(cwd: string, payload?: unknown): Promise<string> {
32
- const directory = workspaceFromPayload(cwd, payload);
33
- requireThat(isAbsolute(directory), "Antigravity 工作区需要绝对路径。");
34
- const root = await realpath(directory);
35
- requireThat((await stat(root)).isDirectory(), "Antigravity 工作区需要目录。");
36
- return root;
37
- }
38
-
39
- export const antigravityAdapter: PluginHostAdapter = {
40
- host: "antigravity",
41
- nativeRootAgents: true,
42
- nativeWorkspaceSkills: true,
43
- coordinatorPrompt: "plugin-coordinator.md",
44
- initCommandHint: "/pbot init",
45
- usage: "用法:node <插件目录>/lib/plugin.js antigravity init|status",
46
- resolveRoot(cwd, rawPayload) {
47
- return antigravityWorkspaceRoot(cwd, rawPayload);
48
- },
49
- parseEvent(value): HostEvent {
50
- requireThat(object(value) && typeof value.hookEventName === "string", "Antigravity hook 输入无效。");
51
- const event = value.hookEventName;
52
- requireThat(supportedEvents.includes(event), "Antigravity hook 事件未支持。");
53
- const cwd = typeof value.cwd === "string" && value.cwd ? value.cwd : workspaceFromPayload("", value);
54
- requireThat(cwd, "Antigravity hook 缺少工作目录。");
55
- if (event === "SessionStart") {
56
- return { kind: "inject-context", role: "coordinator", cwd, raw: value };
57
- }
58
- if (!object(value.toolCall) || typeof value.toolCall.name !== "string" || !object(value.toolCall.args)) {
59
- return { kind: "ignore" };
60
- }
61
- const { name, args } = value.toolCall;
62
- if (name === "read_file" && typeof args.Path === "string") {
63
- const skill = skillFromReadPath(args.Path);
64
- if (skill) return { kind: "check-skill", skill, cwd, raw: value };
65
- }
66
- return { kind: "ignore" };
67
- },
68
- formatPass(payload) {
69
- return isPreToolUse(payload) ? { decision: "allow" } : {};
70
- },
71
- formatContext(_event, context) {
72
- return {
73
- injectSteps: [
74
- { systemMessage: { systemMessage: context.text } },
75
- ],
76
- };
77
- },
78
- formatDeny(_event, reason) {
79
- return { decision: "deny", reason };
80
- },
81
- };
82
-
83
- export const antigravitySkillPath = (pluginRoot: string, skill: string) => join(pluginRoot, "skills", skill, "SKILL.md");
@@ -1,62 +0,0 @@
1
- import { realpath, stat } from "node:fs/promises";
2
- import { isAbsolute } from "node:path";
3
- import { object } from "../../common/json.js";
4
- import { requireThat } from "../../common/validation.js";
5
- import type { HostEvent, PluginHostAdapter } from "../../model/plugin-host.js";
6
-
7
- const supportedEvents = ["UserPromptSubmit", "PreToolUse", "UserPromptExpansion"];
8
-
9
- export async function claudeWorkspaceRoot(cwd: string, projectDirectory = process.env.CLAUDE_PROJECT_DIR): Promise<string> {
10
- const directory = projectDirectory || cwd;
11
- requireThat(isAbsolute(directory), "Claude 工作区需要绝对路径。");
12
- const root = await realpath(directory);
13
- requireThat((await stat(root)).isDirectory(), "Claude 工作区需要目录。");
14
- return root;
15
- }
16
-
17
- export const claudeAdapter: PluginHostAdapter = {
18
- host: "claude",
19
- nativeRootAgents: false,
20
- nativeWorkspaceSkills: false,
21
- coordinatorPrompt: "plugin-coordinator.md",
22
- initCommandHint: "/personal-bot:pbot init",
23
- usage: "用法:node <插件目录>/lib/claude.js init|status",
24
- resolveRoot(cwd) {
25
- return claudeWorkspaceRoot(cwd);
26
- },
27
- parseEvent(value): HostEvent {
28
- requireThat(object(value) && typeof value.hook_event_name === "string", "Claude hook 输入无效。");
29
- const event = value.hook_event_name;
30
- requireThat(supportedEvents.includes(event), "Claude hook 事件未支持。");
31
- if (event === "PreToolUse" || event === "UserPromptExpansion") {
32
- const skill = event === "UserPromptExpansion"
33
- ? value.expansion_type === "slash_command" ? value.command_name : undefined
34
- : value.tool_name === "Skill" && object(value.tool_input) ? value.tool_input.skill : undefined;
35
- if (typeof skill !== "string" || !skill.startsWith("personal-bot:") || skill === "personal-bot:pbot") return { kind: "ignore" };
36
- requireThat(typeof value.cwd === "string", "Claude hook 缺少工作目录。");
37
- return { kind: "check-skill", skill, cwd: value.cwd, raw: value };
38
- }
39
- // Leave Claude's native subagents untouched; only inject coordinator context into main sessions.
40
- if (typeof value.agent_id === "string") return { kind: "ignore" };
41
- requireThat(typeof value.cwd === "string", "Claude hook 缺少工作目录。");
42
- return { kind: "inject-context", role: "coordinator", cwd: value.cwd, raw: value };
43
- },
44
- formatPass() {
45
- return {};
46
- },
47
- formatContext(event, context) {
48
- const raw = event.raw as { hook_event_name: string };
49
- return {
50
- hookSpecificOutput: {
51
- hookEventName: raw.hook_event_name,
52
- additionalContext: context.text,
53
- },
54
- };
55
- },
56
- formatDeny(event, reason) {
57
- const raw = event.raw as { hook_event_name: string };
58
- return raw.hook_event_name === "UserPromptExpansion"
59
- ? { decision: "block", reason }
60
- : { hookSpecificOutput: { hookEventName: raw.hook_event_name, permissionDecision: "deny", permissionDecisionReason: reason } };
61
- },
62
- };
@@ -1,99 +0,0 @@
1
- import { readFile } from "node:fs/promises";
2
- import { parseSessionEntries, SessionManager, type ExtensionContext, type SessionEntry, type SessionMessageEntry } from "@earendil-works/pi-coding-agent";
3
- import type { HistoryExchange, HistoryLocation, HistorySession, HistorySource, HistorySummarizer } from "../../model/history.js";
4
- import { requireThat } from "../../common/validation.js";
5
- import { reduceHistorySummary } from "../history-summary.js";
6
-
7
- function text(content: unknown): string {
8
- if (typeof content === "string") return content;
9
- if (!Array.isArray(content)) return "";
10
- return content.flatMap(block => block.type === "text" ? [String(block.text)] : block.type === "image" ? ["[图片]"] : []).join("\n");
11
- }
12
- function exchanges(branch: SessionEntry[]) {
13
- const result: HistoryExchange[] = [], supersededEntryIds: string[] = [];
14
- let users: SessionMessageEntry[] = [], partial: SessionMessageEntry | undefined, observed: string[] = [];
15
- const finish = (answer?: SessionMessageEntry, completed = false) => {
16
- if (!users.length) return;
17
- const entries = [...users, ...(answer ? [answer] : [])];
18
- result.push({ entryIds: entries.map(entry => entry.id), from: users[0]!.timestamp, to: entries.at(-1)!.timestamp, completed,
19
- text: users.map(entry => "用户:\n" + text("content" in entry.message ? entry.message.content : "")).join("\n\n") +
20
- (answer && "content" in answer.message ? "\n\n助手:\n" + text(answer.message.content) : "") });
21
- supersededEntryIds.push(...observed.filter(id => id !== entries.at(-1)!.id));
22
- users = []; partial = undefined; observed = [];
23
- };
24
- for (const entry of branch) {
25
- if (entry.type !== "message") continue;
26
- const message = entry.message;
27
- if (message.role === "user") {
28
- if (partial?.message.role === "assistant" && ["aborted", "error"].includes(partial.message.stopReason)) finish(partial);
29
- if (!partial) observed.push(entry.id);
30
- users.push(entry);
31
- } else if (message.role === "assistant" && users.length) {
32
- partial = entry; observed.push(entry.id);
33
- if (message.stopReason === "stop" && !message.content.some(block => block.type === "toolCall")) finish(entry, true);
34
- }
35
- }
36
- finish(partial);
37
- return { exchanges: result, supersededEntryIds };
38
- }
39
-
40
- /** Parse in memory; never open a writable SessionManager or migrate native JSONL. */
41
- export function projectHistory(content: string): HistorySession {
42
- const parsed = parseSessionEntries(content), header = parsed[0];
43
- requireThat(header?.type === "session", "缺少 Pi 会话头。");
44
- const manager = SessionManager.inMemory(header.cwd, undefined, parsed), entries = manager.getEntries();
45
- const parents = new Set(entries.map(entry => entry.parentId));
46
- const tips = entries.filter(entry => !parents.has(entry.id));
47
- const branches = tips.map(tip => exchanges(manager.getBranch(tip.id)));
48
- return { sessionId: header.id, name: manager.getSessionName() ?? "", branches: branches.map(value => value.exchanges).filter(branch => branch.length),
49
- supersededEntryIds: [...new Set(branches.flatMap(value => value.supersededEntryIds))] };
50
- }
51
-
52
- export const historyLocation = (ctx: ExtensionContext): HistoryLocation => {
53
- const file = ctx.sessionManager.getSessionFile();
54
- return { host: "pi", directory: ctx.sessionManager.getSessionDir(), ...(file ? { file } : {}) };
55
- };
56
- export class PiHistory implements HistorySource {
57
- readonly host = "pi";
58
- constructor(private readonly root: string, private readonly relatedFiles: () => string[] = () => []) {}
59
- async scan(location: HistoryLocation, signal?: AbortSignal, excluded?: ReadonlySet<string>) {
60
- requireThat(location.host === "pi", "Pi 历史只读取 Pi 原生会话。");
61
- const lists = await Promise.all([SessionManager.list(this.root, undefined, undefined, signal),
62
- SessionManager.list(this.root, location.directory, undefined, signal)]);
63
- const files = new Set([...this.relatedFiles(), ...(location.file ? [location.file] : [])]);
64
- for (const session of lists.flat()) {
65
- if (excluded?.has(session.id)) files.delete(session.path);
66
- else files.add(session.path);
67
- }
68
- const sessions: HistorySession[] = [], warnings: string[] = [];
69
- for (const file of files) {
70
- signal?.throwIfAborted();
71
- try {
72
- const session = projectHistory(await readFile(file, { encoding: "utf8", signal }));
73
- if (session.branches.length && !excluded?.has(session.sessionId)) sessions.push(session);
74
- } catch (error) {
75
- signal?.throwIfAborted();
76
- // Pi reserves a filename before the first message; copied archives may also outlive their native files.
77
- if ((error as NodeJS.ErrnoException).code !== "ENOENT") warnings.push(`${file}: ${String(error)}`);
78
- }
79
- }
80
- return { sessions, warnings };
81
- }
82
- }
83
-
84
- export async function historySummarizer(ctx: ExtensionContext): Promise<HistorySummarizer> {
85
- const model = ctx.model;
86
- requireThat(model, "请先选择 Pi 模型。");
87
- const budget = Math.max(2000, Math.min(24000, Math.floor(model.contextWindow / 2)));
88
- const ask: HistorySummarizer = async ({ system, prompt, maxTokens }, signal) => {
89
- signal.throwIfAborted();
90
- const response = await ctx.modelRegistry.streamSimple(model, { systemPrompt: system,
91
- messages: [{ role: "user", content: prompt, timestamp: Date.now() }] }, { signal, reasoning: "low", maxTokens, transport: "sse" }).result();
92
- signal.throwIfAborted();
93
- requireThat(response.stopReason === "stop", response.errorMessage ?? "历史摘要未完成:" + response.stopReason);
94
- const answer = response.content.filter(part => part.type === "text").map(part => part.text).join("\n").trim();
95
- requireThat(answer, "历史摘要为空。");
96
- return answer;
97
- };
98
- return reduceHistorySummary(budget, ask);
99
- }
@@ -1,195 +0,0 @@
1
- import { readFileSync } from "node:fs";
2
- import { join } from "node:path";
3
- import { isDeepStrictEqual } from "node:util";
4
- import type { HistoryArchive, HistoryHost, HistoryIdentity, HistoryLocation, HistoryNode, HistoryRecord, HistorySession, HistorySource, HistorySummarizer } from "../../model/history.js";
5
- import type { HistoryFiles } from "../../storage/history-files.js";
6
- import { resourceRoot } from "../../common/paths.js";
7
- import { requireThat } from "../../common/validation.js";
8
- import { historySummaries, historyView, indexHistory, retainHistorySummaries } from "./history-index.js";
9
-
10
- export interface HistoryQuery { host?: HistoryHost; query?: string; sessionId?: string; from?: string; to?: string; offset?: number; limit?: number }
11
- type LocatedRecord = { host: HistoryHost; record: HistoryRecord };
12
- type HistoryReader = Pick<HistoryFiles, "host" | "list" | "warnings">;
13
- const page = <T>(values: T[], offset: number, limit: number) => ({ values: values.slice(offset, offset + limit),
14
- nextOffset: offset + limit < values.length ? offset + limit : null });
15
- const brief = ({ host, record }: LocatedRecord, node: HistoryNode) => ({ host, id: node.id, kind: node.kind, sessionId: record.sessionId,
16
- name: record.name, preview: node.text.replace(/\s+/g, " ").slice(0, 100), from: node.from, to: node.to, ready: node.ready, completed: node.completed });
17
- const view = ({ raw, summaries }: HistoryArchive): LocatedRecord => ({ host: raw.host, record: historyView(raw, summaries) });
18
- const summarySource = (node: HistoryNode) => [node.id, node.kind, node.level, node.entryIds, node.children, node.text, node.from, node.to, node.completed, node.ready];
19
-
20
- function nextSummary(archives: HistoryArchive[]) {
21
- for (const { raw, summaries } of archives) {
22
- if (summaries === null) continue;
23
- const record = historyView(raw, summaries), lookup = new Map(record.nodes.map(node => [node.id, node]));
24
- const node = record.nodes.find(node => node.kind === "summary" && !node.ready && node.children.every(id => lookup.get(id)!.ready));
25
- if (node) return { record, node, children: node.children.map(id => lookup.get(id)!) };
26
- }
27
- }
28
-
29
- /** Validate the exact target and ordered inputs under the source lock. Only publish the derived file. */
30
- export function commitHistorySummary(files: Pick<HistoryFiles, "control" | "list" | "saveSummaries">, identity: HistoryIdentity,
31
- expected: HistoryNode, children: readonly HistoryNode[], text: string, signal?: AbortSignal): HistoryRecord | undefined {
32
- return files.control(() => {
33
- signal?.throwIfAborted();
34
- const current = files.list().find(({ raw }) => raw.host === identity.host && raw.id === identity.id && raw.sessionId === identity.sessionId);
35
- if (!current || current.summaries === null) return;
36
- const record = historyView(current.raw, current.summaries), lookup = new Map(record.nodes.map(node => [node.id, node]));
37
- const node = lookup.get(expected.id);
38
- if (!node || node.kind !== "summary" || node.ready || !isDeepStrictEqual(summarySource(node), summarySource(expected)) ||
39
- !isDeepStrictEqual(node.children, children.map(child => child.id))) return;
40
- for (const child of children) {
41
- const input = lookup.get(child.id);
42
- if (!input?.ready || !isDeepStrictEqual(summarySource(input), summarySource(child))) return;
43
- }
44
- requireThat(text.trim(), "历史摘要为空。");
45
- node.text = text.trim(); node.ready = true;
46
- files.saveSummaries(current.raw, historySummaries(record));
47
- return record;
48
- });
49
- }
50
-
51
- export class HistoryService {
52
- #records: LocatedRecord[] = [];
53
- #closed = false;
54
- #loaded = false;
55
- #refresh: Promise<void> | undefined;
56
- #work: Promise<void> | undefined;
57
- readonly #controller = new AbortController();
58
- #sourceWarnings: string[] = [];
59
- #summaryError: string | undefined;
60
- constructor(readonly root: string, private readonly files: HistoryFiles, private readonly source: HistorySource,
61
- private readonly otherFiles: readonly HistoryReader[] = [],
62
- private readonly acpSessions?: () => { ids: Record<HistoryHost, ReadonlySet<string>>; warnings: string[] }) {
63
- requireThat((source.host === "pi" || source.host === "dsh") && source.host === files.host &&
64
- new Set([files.host, ...otherFiles.map(value => value.host)]).size === otherFiles.length + 1,
65
- "历史来源与归档目录不匹配。");
66
- }
67
- check() { requireThat(!this.#closed, "历史服务已关闭。"); }
68
- get warnings() { return [...new Set([...this.#sourceWarnings, ...this.files.warnings, ...this.otherFiles.flatMap(value => value.warnings),
69
- ...(this.#summaryError ? [this.files.host + " 摘要:" + this.#summaryError] : [])])]; }
70
- get status() { return { loaded: this.#loaded, organizing: Boolean(this.#work), pending: this.#loaded ? this.#records.filter(value => value.host === this.files.host)
71
- .reduce((total, value) => total + value.record.nodes.filter(node => node.kind === "summary" && !node.ready).length, 0) : null, warnings: this.warnings }; }
72
- refresh(location: HistoryLocation, signal?: AbortSignal): Promise<void> {
73
- this.check(); requireThat(location.host === this.source.host, "历史位置与来源不匹配。");
74
- // Each caller keeps its own cancellation. A closed page cannot cancel a server-owned refresh.
75
- const work = (this.#refresh ?? Promise.resolve()).catch(() => {}).then(() => this.load(location, signal));
76
- this.#refresh = work;
77
- return work.finally(() => { if (this.#refresh === work) this.#refresh = undefined; });
78
- }
79
- private async load(location: HistoryLocation, signal?: AbortSignal) {
80
- this.check(); signal?.throwIfAborted();
81
- const warnings: string[] = [], records: LocatedRecord[] = [];
82
- const warning = (host: HistoryHost, error: unknown) => { this.check(); signal?.throwIfAborted(); warnings.push(host + ": " + String(error)); };
83
- let known: HistoryArchive[] = [], sessions: HistorySession[] = [];
84
- try {
85
- try { this.files.migrate(this.root); } finally { known = this.files.list(this.root); }
86
- const scanned = await this.source.scan(location, signal, this.acpSessions?.().ids[this.files.host]); sessions = scanned.sessions;
87
- warnings.push(...scanned.warnings.map(value => this.files.host + ": " + value));
88
- } catch (error) { warning(this.files.host, error); }
89
- this.check(); signal?.throwIfAborted();
90
- // The worker binds the actual backend ID before delivery, possibly during the native scan.
91
- const excluded = this.acpSessions?.();
92
- if (excluded) {
93
- warnings.push(...excluded.warnings);
94
- sessions = sessions.filter(session => !excluded.ids[this.files.host].has(session.sessionId));
95
- }
96
- const visible = ({ raw }: HistoryArchive) => !excluded?.ids[raw.host].has(raw.sessionId);
97
- try {
98
- if (sessions.length) {
99
- const before = new Map(known.map(({ raw }) => [raw.sessionId, raw]));
100
- known = this.files.control(() => {
101
- this.check(); signal?.throwIfAborted();
102
- const current = new Map(this.files.list().map(archive => [archive.raw.sessionId, archive]));
103
- for (const session of sessions) {
104
- const previous = current.get(session.sessionId);
105
- // A damaged raw file may own this session; a damaged summary cannot own a root ID.
106
- if (!previous && this.files.rawWarnings.length) continue;
107
- if (!isDeepStrictEqual(before.get(session.sessionId), previous?.raw)) continue;
108
- const raw = indexHistory(session, previous?.raw, this.files.host);
109
- if (isDeepStrictEqual(raw, previous?.raw)) continue;
110
- let summaries = previous ? previous.summaries : [];
111
- if (previous && summaries?.length) {
112
- const retained = retainHistorySummaries(previous.raw, raw, summaries);
113
- // Invalidate first: even an interrupted two-file update cannot attach old text to a corrected exchange.
114
- if (!isDeepStrictEqual(summaries, retained)) this.files.saveSummaries(previous.raw, retained);
115
- summaries = retained;
116
- }
117
- this.files.saveRaw(raw);
118
- current.set(session.sessionId, { raw, summaries });
119
- }
120
- return [...current.values()];
121
- });
122
- }
123
- } catch (error) { warning(this.files.host, error); }
124
- records.push(...known.filter(visible).map(view));
125
- for (const files of this.otherFiles) {
126
- try { records.push(...files.list(this.root).filter(visible).map(view)); }
127
- catch (error) { warning(files.host, error); }
128
- }
129
- this.check(); signal?.throwIfAborted(); this.#records = records; this.#sourceWarnings = warnings; this.#loaded = true;
130
- }
131
- search({ host, query = "", sessionId, from, to, offset = 0, limit = 20 }: HistoryQuery = {}) {
132
- this.check();
133
- const needle = query.trim().toLowerCase(), after = from === undefined ? -Infinity : Date.parse(from), before = to === undefined ? Infinity : Date.parse(to);
134
- requireThat(!Number.isNaN(after) && !Number.isNaN(before) && after <= before, "时间范围无效,请使用 ISO 日期或时间。");
135
- const matches = this.#records.filter(value => (!host || value.host === host) && (!sessionId || value.record.sessionId === sessionId)).flatMap(value => value.record.nodes
136
- .filter(node => (needle ? node.kind !== "session" && node.ready && node.text.toLowerCase().includes(needle) : node.kind === "session") &&
137
- Date.parse(node.to) >= after && Date.parse(node.from) <= before)
138
- .map(node => {
139
- const start = Math.max(0, node.text.toLowerCase().indexOf(needle) - 80);
140
- return { ...brief(value, node), parents: node.parents, snippet: node.text.slice(start, start + 400) };
141
- })).sort((a, b) => b.to.localeCompare(a.to) || a.id.localeCompare(b.id));
142
- const result = page(matches, offset, limit);
143
- return { matches: result.values, total: matches.length, nextOffset: result.nextOffset, warnings: this.warnings };
144
- }
145
- private find(id: string, host?: HistoryHost) {
146
- const values = this.#records.filter(value => (!host || value.host === host) && value.record.nodes.some(node => node.id === id));
147
- requireThat(values.length, "历史节点不存在,请重新搜索。");
148
- requireThat(values.length === 1, "历史节点来源不明确,请指定 host。");
149
- const value = values[0]!, node = value.record.nodes.find(node => node.id === id)!;
150
- return { value, node };
151
- }
152
- read(id: string, offset = 0, limit = 12000, childrenOffset = 0, host?: HistoryHost) {
153
- this.check();
154
- const { value, node } = this.find(id, host), lookup = new Map(value.record.nodes.map(node => [node.id, node]));
155
- requireThat(offset <= node.text.length, "读取位置超出正文。");
156
- if (offset && /[\uDC00-\uDFFF]/.test(node.text[offset] ?? "")) offset--;
157
- let end = Math.min(node.text.length, offset + limit);
158
- if (end < node.text.length && /[\uD800-\uDBFF]/.test(node.text[end - 1] ?? "")) end += end - offset === 1 ? 1 : -1;
159
- const children = page(node.children, childrenOffset, 20);
160
- return { ...brief(value, node), text: node.text.slice(offset, end), totalLength: node.text.length,
161
- nextOffset: end < node.text.length ? end : null,
162
- parents: node.parents.map(id => brief(value, lookup.get(id)!)), children: children.values.map(id => brief(value, lookup.get(id)!)),
163
- nextChildrenOffset: children.nextOffset, source: { host: value.host, sessionId: value.record.sessionId, entryIds: node.entryIds }, warnings: this.warnings };
164
- }
165
- /** Retain exact inputs only for this call; model work never holds the source write lock. */
166
- organize(summarize: HistorySummarizer, signal: AbortSignal): Promise<void> {
167
- this.check();
168
- const active = AbortSignal.any([signal, this.#controller.signal]);
169
- const run = async () => {
170
- for (;;) {
171
- this.check(); active.throwIfAborted();
172
- const archives = this.files.list(), excluded = this.acpSessions?.().ids[this.files.host];
173
- const pending = nextSummary(archives.filter(({ raw }) => !excluded?.has(raw.sessionId)));
174
- if (!pending) return;
175
- const { record, node, children } = pending;
176
- const text = await summarize({ system: readFileSync(join(resourceRoot, "prompts/history-summary.md"), "utf8"), maxTokens: 2048,
177
- prompt: children.map(child => `[${child.from} — ${child.to}${child.completed ? "" : ";未完成"}]\n${child.text}`).join("\n\n") }, active);
178
- this.check(); active.throwIfAborted();
179
- const committed = commitHistorySummary(this.files, record, node, children, text, active);
180
- if (!committed) return;
181
- this.#records = this.#records.map(value => value.host === this.files.host && value.record.id === committed.id ? { host: value.host, record: committed } : value);
182
- }
183
- };
184
- const work = (this.#work ?? Promise.resolve()).catch(() => {}).then(run).then(() => { this.#summaryError = undefined; }).catch(error => {
185
- if (!active.aborted && !this.#closed) this.#summaryError = String(error);
186
- throw error;
187
- });
188
- this.#work = work;
189
- return work.finally(() => { if (this.#work === work) this.#work = undefined; });
190
- }
191
- async close() {
192
- this.#closed = true; this.#controller.abort();
193
- await Promise.allSettled([this.#work, this.#refresh]); this.#records = []; this.#loaded = false;
194
- }
195
- }
@@ -1,49 +0,0 @@
1
- import { readdirSync } from "node:fs";
2
- import { homedir } from "node:os";
3
- import { join } from "node:path";
4
- import { fileURLToPath } from "node:url";
5
- import type { HistoryHost } from "../model/history.js";
6
- import { readJsonFile } from "./atomic-json.js";
7
- import { acpReference } from "./acp-files.js";
8
- import { isHistoryHost } from "./history-format.js";
9
-
10
- function memberDirectory(home: string, host: "pi" | "dsh") {
11
- if (host === "pi" && home.startsWith("file://")) return join(fileURLToPath(home), "pbot/subagents");
12
- const tilde = home === "~" || home.startsWith("~/") || ((host === "dsh" || process.platform === "win32") && home.startsWith("~\\"));
13
- return join(tilde ? join(homedir(), home.slice(2)) : home, "pbot/subagents");
14
- }
15
-
16
- function defaultMcpWorkerDirectories(): string[] {
17
- const dirs = [join(homedir(), ".pbot/subagents")];
18
- if (process.env.PBOT_MCP_AGENT_DIR) dirs.push(process.env.PBOT_MCP_AGENT_DIR);
19
- if (process.env.PLUGIN_DATA) dirs.push(join(process.env.PLUGIN_DATA, "subagents"));
20
- return dirs;
21
- }
22
-
23
- /** Exclude ACP worker sessions owned by MCP or legacy Pi/dsh control directories from native history. */
24
- export function acpHistorySessions(directories: { pi?: string; dsh?: string; mcp?: string } = {}) {
25
- const ids: Record<HistoryHost, Set<string>> = { pi: new Set(), dsh: new Set(), claude: new Set() };
26
- const warnings: string[] = [];
27
- const warn = (path: string, error: unknown) => {
28
- if ((error as NodeJS.ErrnoException).code !== "ENOENT") warnings.push(path + ": " + String(error));
29
- };
30
- const homes = { pi: process.env.PI_CODING_AGENT_DIR || "~/.pi/agent", dsh: process.env.DSH_HOME?.trim() ? process.env.DSH_HOME : "~/.dsh" };
31
- const scanDirs = new Set<string>([
32
- directories.pi ?? memberDirectory(homes.pi, "pi"),
33
- directories.dsh ?? memberDirectory(homes.dsh, "dsh"),
34
- ...(directories.mcp ? [directories.mcp] : defaultMcpWorkerDirectories()),
35
- ]);
36
- for (const directory of scanDirs) {
37
- try {
38
- for (const entry of readdirSync(directory, { withFileTypes: true })) {
39
- if (!entry.isDirectory() || entry.name.startsWith(".")) continue;
40
- const path = join(directory, entry.name);
41
- try {
42
- const ref = readJsonFile(path, "acp-session.json", acpReference);
43
- if (ref.sessionId !== null && isHistoryHost(ref.backend)) ids[ref.backend].add(ref.sessionId);
44
- } catch (error) { warn(path, error); }
45
- }
46
- } catch (error) { warn(directory, error); }
47
- }
48
- return { ids, warnings };
49
- }
@@ -1,7 +0,0 @@
1
-
2
- /** Each tool is bound to one workspace instance, not a mutable global lookup. */
3
- export interface CallAccess {
4
- check(): void;
5
- signal(signal?: AbortSignal): AbortSignal;
6
- authorizeFile(path: string, change: unknown, confirm: (value: unknown) => Promise<boolean>, signal: AbortSignal): Promise<void>;
7
- }
@@ -1,19 +0,0 @@
1
- import { defineTool } from "@earendil-works/pi-coding-agent";
2
- import type { HistoryService } from "../../services/history/history-service.js";
3
- import type { CallAccess } from "../access.js";
4
- import { historyLocation } from "../../integrations/pi/history.js";
5
- import { markdownResult } from "../result.js";
6
- import { historyDescription, historyInput, historyParameters, historyResultSchema } from "./contract.js";
7
- import { executeHistory } from "./actions.js";
8
-
9
- export function historyTool(service: HistoryService, access: CallAccess) {
10
- return defineTool({ name: "pbot_history", label: "历史对话", description: historyDescription,
11
- parameters: historyParameters, outputSchema: historyResultSchema,
12
- async execute(_id, args, signal, _update, ctx) {
13
- access.check();
14
- const result = await executeHistory(service, historyInput(args), historyLocation(ctx), signal);
15
- access.check();
16
- return markdownResult(result, args.action === "search" ? "历史搜索" : "历史正文");
17
- },
18
- });
19
- }
@@ -1,22 +0,0 @@
1
- import type { ExtensionAPI, ToolDefinition } from "@earendil-works/pi-coding-agent";
2
- import type { CallAccess } from "./access.js";
3
- import type { HistoryService } from "../services/history/history-service.js";
4
- import { historyTool } from "./history/tool.js";
5
-
6
- export function mainTools(history: HistoryService, access: CallAccess): ToolDefinition[] {
7
- return [historyTool(history, access)];
8
- }
9
-
10
- export class ToolRegistry {
11
- readonly #registered = new Map<string, ToolDefinition>();
12
- constructor(private readonly pi: ExtensionAPI) {}
13
- register(tools: ToolDefinition[]) {
14
- for (const definition of tools) {
15
- const tool = { ...definition, namespace: { name: "pbot", description: "工作区历史查询。" } };
16
- this.#registered.set(tool.name, tool); this.pi.registerTool(tool);
17
- }
18
- }
19
- hide() {
20
- for (const tool of this.#registered.values()) this.pi.registerTool({ ...tool, exposure: "hidden" });
21
- }
22
- }
@@ -1,12 +0,0 @@
1
- const states: Record<string, string> = {
2
- starting: "启动中", busy: "执行中", idle: "待命", stopping: "停止中", stopped: "已停止", error: "需要处理",
3
- running: "进行中", paused: "已暂停", finished: "已结束", completed: "已完成", failed: "失败",
4
- cancelled: "已取消", interrupted: "已中断",
5
- open: "待安排", closed: "已关闭",
6
- };
7
- export const stateLabel = (state: unknown) => states[String(state)] ?? String(state ?? "未知");
8
- export const oneLine = (value: string) => value.replace(/\s+/g, " ").trim();
9
- export function duration(milliseconds: number) {
10
- const seconds = Math.max(0, Math.floor(milliseconds / 1000));
11
- return seconds < 60 ? `${seconds} 秒` : seconds < 3600 ? `${Math.floor(seconds / 60)} 分钟` : `${Math.floor(seconds / 3600)} 小时 ${Math.floor(seconds % 3600 / 60)} 分钟`;
12
- }
File without changes
File without changes