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,242 +0,0 @@
1
- import { readFileSync } from "node:fs";
2
- import { join } from "node:path";
3
- import { isDeepStrictEqual } from "node:util";
4
- import { resourceRoot } from "../../common/paths.js";
5
- import { requireThat } from "../../common/validation.js";
6
- import { historySummaries, historyView, indexHistory, retainHistorySummaries } from "./history-index.js";
7
- const page = (values, offset, limit) => ({ values: values.slice(offset, offset + limit),
8
- nextOffset: offset + limit < values.length ? offset + limit : null });
9
- const brief = ({ host, record }, node) => ({ host, id: node.id, kind: node.kind, sessionId: record.sessionId,
10
- name: record.name, preview: node.text.replace(/\s+/g, " ").slice(0, 100), from: node.from, to: node.to, ready: node.ready, completed: node.completed });
11
- const view = ({ raw, summaries }) => ({ host: raw.host, record: historyView(raw, summaries) });
12
- const summarySource = (node) => [node.id, node.kind, node.level, node.entryIds, node.children, node.text, node.from, node.to, node.completed, node.ready];
13
- function nextSummary(archives) {
14
- for (const { raw, summaries } of archives) {
15
- if (summaries === null)
16
- continue;
17
- const record = historyView(raw, summaries), lookup = new Map(record.nodes.map(node => [node.id, node]));
18
- const node = record.nodes.find(node => node.kind === "summary" && !node.ready && node.children.every(id => lookup.get(id).ready));
19
- if (node)
20
- return { record, node, children: node.children.map(id => lookup.get(id)) };
21
- }
22
- }
23
- /** Validate the exact target and ordered inputs under the source lock. Only publish the derived file. */
24
- export function commitHistorySummary(files, identity, expected, children, text, signal) {
25
- return files.control(() => {
26
- signal?.throwIfAborted();
27
- const current = files.list().find(({ raw }) => raw.host === identity.host && raw.id === identity.id && raw.sessionId === identity.sessionId);
28
- if (!current || current.summaries === null)
29
- return;
30
- const record = historyView(current.raw, current.summaries), lookup = new Map(record.nodes.map(node => [node.id, node]));
31
- const node = lookup.get(expected.id);
32
- if (!node || node.kind !== "summary" || node.ready || !isDeepStrictEqual(summarySource(node), summarySource(expected)) ||
33
- !isDeepStrictEqual(node.children, children.map(child => child.id)))
34
- return;
35
- for (const child of children) {
36
- const input = lookup.get(child.id);
37
- if (!input?.ready || !isDeepStrictEqual(summarySource(input), summarySource(child)))
38
- return;
39
- }
40
- requireThat(text.trim(), "历史摘要为空。");
41
- node.text = text.trim();
42
- node.ready = true;
43
- files.saveSummaries(current.raw, historySummaries(record));
44
- return record;
45
- });
46
- }
47
- export class HistoryService {
48
- root;
49
- files;
50
- source;
51
- otherFiles;
52
- acpSessions;
53
- #records = [];
54
- #closed = false;
55
- #loaded = false;
56
- #refresh;
57
- #work;
58
- #controller = new AbortController();
59
- #sourceWarnings = [];
60
- #summaryError;
61
- constructor(root, files, source, otherFiles = [], acpSessions) {
62
- this.root = root;
63
- this.files = files;
64
- this.source = source;
65
- this.otherFiles = otherFiles;
66
- this.acpSessions = acpSessions;
67
- requireThat((source.host === "pi" || source.host === "dsh") && source.host === files.host &&
68
- new Set([files.host, ...otherFiles.map(value => value.host)]).size === otherFiles.length + 1, "历史来源与归档目录不匹配。");
69
- }
70
- check() { requireThat(!this.#closed, "历史服务已关闭。"); }
71
- get warnings() {
72
- return [...new Set([...this.#sourceWarnings, ...this.files.warnings, ...this.otherFiles.flatMap(value => value.warnings),
73
- ...(this.#summaryError ? [this.files.host + " 摘要:" + this.#summaryError] : [])])];
74
- }
75
- get status() {
76
- return { loaded: this.#loaded, organizing: Boolean(this.#work), pending: this.#loaded ? this.#records.filter(value => value.host === this.files.host)
77
- .reduce((total, value) => total + value.record.nodes.filter(node => node.kind === "summary" && !node.ready).length, 0) : null, warnings: this.warnings };
78
- }
79
- refresh(location, signal) {
80
- this.check();
81
- requireThat(location.host === this.source.host, "历史位置与来源不匹配。");
82
- // Each caller keeps its own cancellation. A closed page cannot cancel a server-owned refresh.
83
- const work = (this.#refresh ?? Promise.resolve()).catch(() => { }).then(() => this.load(location, signal));
84
- this.#refresh = work;
85
- return work.finally(() => { if (this.#refresh === work)
86
- this.#refresh = undefined; });
87
- }
88
- async load(location, signal) {
89
- this.check();
90
- signal?.throwIfAborted();
91
- const warnings = [], records = [];
92
- const warning = (host, error) => { this.check(); signal?.throwIfAborted(); warnings.push(host + ": " + String(error)); };
93
- let known = [], sessions = [];
94
- try {
95
- try {
96
- this.files.migrate(this.root);
97
- }
98
- finally {
99
- known = this.files.list(this.root);
100
- }
101
- const scanned = await this.source.scan(location, signal, this.acpSessions?.().ids[this.files.host]);
102
- sessions = scanned.sessions;
103
- warnings.push(...scanned.warnings.map(value => this.files.host + ": " + value));
104
- }
105
- catch (error) {
106
- warning(this.files.host, error);
107
- }
108
- this.check();
109
- signal?.throwIfAborted();
110
- // The worker binds the actual backend ID before delivery, possibly during the native scan.
111
- const excluded = this.acpSessions?.();
112
- if (excluded) {
113
- warnings.push(...excluded.warnings);
114
- sessions = sessions.filter(session => !excluded.ids[this.files.host].has(session.sessionId));
115
- }
116
- const visible = ({ raw }) => !excluded?.ids[raw.host].has(raw.sessionId);
117
- try {
118
- if (sessions.length) {
119
- const before = new Map(known.map(({ raw }) => [raw.sessionId, raw]));
120
- known = this.files.control(() => {
121
- this.check();
122
- signal?.throwIfAborted();
123
- const current = new Map(this.files.list().map(archive => [archive.raw.sessionId, archive]));
124
- for (const session of sessions) {
125
- const previous = current.get(session.sessionId);
126
- // A damaged raw file may own this session; a damaged summary cannot own a root ID.
127
- if (!previous && this.files.rawWarnings.length)
128
- continue;
129
- if (!isDeepStrictEqual(before.get(session.sessionId), previous?.raw))
130
- continue;
131
- const raw = indexHistory(session, previous?.raw, this.files.host);
132
- if (isDeepStrictEqual(raw, previous?.raw))
133
- continue;
134
- let summaries = previous ? previous.summaries : [];
135
- if (previous && summaries?.length) {
136
- const retained = retainHistorySummaries(previous.raw, raw, summaries);
137
- // Invalidate first: even an interrupted two-file update cannot attach old text to a corrected exchange.
138
- if (!isDeepStrictEqual(summaries, retained))
139
- this.files.saveSummaries(previous.raw, retained);
140
- summaries = retained;
141
- }
142
- this.files.saveRaw(raw);
143
- current.set(session.sessionId, { raw, summaries });
144
- }
145
- return [...current.values()];
146
- });
147
- }
148
- }
149
- catch (error) {
150
- warning(this.files.host, error);
151
- }
152
- records.push(...known.filter(visible).map(view));
153
- for (const files of this.otherFiles) {
154
- try {
155
- records.push(...files.list(this.root).filter(visible).map(view));
156
- }
157
- catch (error) {
158
- warning(files.host, error);
159
- }
160
- }
161
- this.check();
162
- signal?.throwIfAborted();
163
- this.#records = records;
164
- this.#sourceWarnings = warnings;
165
- this.#loaded = true;
166
- }
167
- search({ host, query = "", sessionId, from, to, offset = 0, limit = 20 } = {}) {
168
- this.check();
169
- const needle = query.trim().toLowerCase(), after = from === undefined ? -Infinity : Date.parse(from), before = to === undefined ? Infinity : Date.parse(to);
170
- requireThat(!Number.isNaN(after) && !Number.isNaN(before) && after <= before, "时间范围无效,请使用 ISO 日期或时间。");
171
- const matches = this.#records.filter(value => (!host || value.host === host) && (!sessionId || value.record.sessionId === sessionId)).flatMap(value => value.record.nodes
172
- .filter(node => (needle ? node.kind !== "session" && node.ready && node.text.toLowerCase().includes(needle) : node.kind === "session") &&
173
- Date.parse(node.to) >= after && Date.parse(node.from) <= before)
174
- .map(node => {
175
- const start = Math.max(0, node.text.toLowerCase().indexOf(needle) - 80);
176
- return { ...brief(value, node), parents: node.parents, snippet: node.text.slice(start, start + 400) };
177
- })).sort((a, b) => b.to.localeCompare(a.to) || a.id.localeCompare(b.id));
178
- const result = page(matches, offset, limit);
179
- return { matches: result.values, total: matches.length, nextOffset: result.nextOffset, warnings: this.warnings };
180
- }
181
- find(id, host) {
182
- const values = this.#records.filter(value => (!host || value.host === host) && value.record.nodes.some(node => node.id === id));
183
- requireThat(values.length, "历史节点不存在,请重新搜索。");
184
- requireThat(values.length === 1, "历史节点来源不明确,请指定 host。");
185
- const value = values[0], node = value.record.nodes.find(node => node.id === id);
186
- return { value, node };
187
- }
188
- read(id, offset = 0, limit = 12000, childrenOffset = 0, host) {
189
- this.check();
190
- const { value, node } = this.find(id, host), lookup = new Map(value.record.nodes.map(node => [node.id, node]));
191
- requireThat(offset <= node.text.length, "读取位置超出正文。");
192
- if (offset && /[\uDC00-\uDFFF]/.test(node.text[offset] ?? ""))
193
- offset--;
194
- let end = Math.min(node.text.length, offset + limit);
195
- if (end < node.text.length && /[\uD800-\uDBFF]/.test(node.text[end - 1] ?? ""))
196
- end += end - offset === 1 ? 1 : -1;
197
- const children = page(node.children, childrenOffset, 20);
198
- return { ...brief(value, node), text: node.text.slice(offset, end), totalLength: node.text.length,
199
- nextOffset: end < node.text.length ? end : null,
200
- parents: node.parents.map(id => brief(value, lookup.get(id))), children: children.values.map(id => brief(value, lookup.get(id))),
201
- nextChildrenOffset: children.nextOffset, source: { host: value.host, sessionId: value.record.sessionId, entryIds: node.entryIds }, warnings: this.warnings };
202
- }
203
- /** Retain exact inputs only for this call; model work never holds the source write lock. */
204
- organize(summarize, signal) {
205
- this.check();
206
- const active = AbortSignal.any([signal, this.#controller.signal]);
207
- const run = async () => {
208
- for (;;) {
209
- this.check();
210
- active.throwIfAborted();
211
- const archives = this.files.list(), excluded = this.acpSessions?.().ids[this.files.host];
212
- const pending = nextSummary(archives.filter(({ raw }) => !excluded?.has(raw.sessionId)));
213
- if (!pending)
214
- return;
215
- const { record, node, children } = pending;
216
- const text = await summarize({ system: readFileSync(join(resourceRoot, "prompts/history-summary.md"), "utf8"), maxTokens: 2048,
217
- prompt: children.map(child => `[${child.from} — ${child.to}${child.completed ? "" : ";未完成"}]\n${child.text}`).join("\n\n") }, active);
218
- this.check();
219
- active.throwIfAborted();
220
- const committed = commitHistorySummary(this.files, record, node, children, text, active);
221
- if (!committed)
222
- return;
223
- this.#records = this.#records.map(value => value.host === this.files.host && value.record.id === committed.id ? { host: value.host, record: committed } : value);
224
- }
225
- };
226
- const work = (this.#work ?? Promise.resolve()).catch(() => { }).then(run).then(() => { this.#summaryError = undefined; }).catch(error => {
227
- if (!active.aborted && !this.#closed)
228
- this.#summaryError = String(error);
229
- throw error;
230
- });
231
- this.#work = work;
232
- return work.finally(() => { if (this.#work === work)
233
- this.#work = undefined; });
234
- }
235
- async close() {
236
- this.#closed = true;
237
- this.#controller.abort();
238
- await Promise.allSettled([this.#work, this.#refresh]);
239
- this.#records = [];
240
- this.#loaded = false;
241
- }
242
- }
@@ -1,10 +0,0 @@
1
- import type { HistoryHost } from "../model/history.js";
2
- /** Exclude ACP worker sessions owned by MCP or legacy Pi/dsh control directories from native history. */
3
- export declare function acpHistorySessions(directories?: {
4
- pi?: string;
5
- dsh?: string;
6
- mcp?: string;
7
- }): {
8
- ids: Record<HistoryHost, Set<string>>;
9
- warnings: string[];
10
- };
@@ -1,57 +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 { readJsonFile } from "./atomic-json.js";
6
- import { acpReference } from "./acp-files.js";
7
- import { isHistoryHost } from "./history-format.js";
8
- function memberDirectory(home, host) {
9
- if (host === "pi" && home.startsWith("file://"))
10
- return join(fileURLToPath(home), "pbot/subagents");
11
- const tilde = home === "~" || home.startsWith("~/") || ((host === "dsh" || process.platform === "win32") && home.startsWith("~\\"));
12
- return join(tilde ? join(homedir(), home.slice(2)) : home, "pbot/subagents");
13
- }
14
- function defaultMcpWorkerDirectories() {
15
- const dirs = [join(homedir(), ".pbot/subagents")];
16
- if (process.env.PBOT_MCP_AGENT_DIR)
17
- dirs.push(process.env.PBOT_MCP_AGENT_DIR);
18
- if (process.env.PLUGIN_DATA)
19
- dirs.push(join(process.env.PLUGIN_DATA, "subagents"));
20
- return dirs;
21
- }
22
- /** Exclude ACP worker sessions owned by MCP or legacy Pi/dsh control directories from native history. */
23
- export function acpHistorySessions(directories = {}) {
24
- const ids = { pi: new Set(), dsh: new Set(), claude: new Set() };
25
- const warnings = [];
26
- const warn = (path, error) => {
27
- if (error.code !== "ENOENT")
28
- 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([
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("."))
40
- continue;
41
- const path = join(directory, entry.name);
42
- try {
43
- const ref = readJsonFile(path, "acp-session.json", acpReference);
44
- if (ref.sessionId !== null && isHistoryHost(ref.backend))
45
- ids[ref.backend].add(ref.sessionId);
46
- }
47
- catch (error) {
48
- warn(path, error);
49
- }
50
- }
51
- }
52
- catch (error) {
53
- warn(directory, error);
54
- }
55
- }
56
- return { ids, warnings };
57
- }
@@ -1,3 +0,0 @@
1
- export declare const stateLabel: (state: unknown) => string;
2
- export declare const oneLine: (value: string) => string;
3
- export declare function duration(milliseconds: number): string;
@@ -1,12 +0,0 @@
1
- const states = {
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) => states[String(state)] ?? String(state ?? "未知");
8
- export const oneLine = (value) => value.replace(/\s+/g, " ").trim();
9
- export function duration(milliseconds) {
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
- }
@@ -1,74 +0,0 @@
1
- import { join } from "node:path";
2
- import type { Context } from "@deepseek-ai/cordis";
3
- import type { Agent } from "@deepseek-ai/dsh-agent";
4
- import { acpHistorySessions } from "../../storage/acp-history.js";
5
- import { HistoryFiles } from "../../storage/history-files.js";
6
- import { HistoryService } from "../../services/history/history-service.js";
7
- import { DshHistory } from "../../integrations/dsh/history.js";
8
- import { dshHistorySummarizer } from "../../integrations/dsh/history-summary.js";
9
- import { finalDshAnswer } from "../../integrations/dsh/messages.js";
10
- import { defaultWorkerDirectory } from "../mcp-workers.js";
11
-
12
- /** One server-owned organizer per workspace, shared by its parent Sessions. */
13
- export class DshHistoryWork {
14
- readonly service: HistoryService;
15
- readonly #parents = new Set<Agent>();
16
- #controller: AbortController | undefined;
17
- #work: Promise<void> | undefined;
18
- #closing: Promise<void> | undefined;
19
-
20
- constructor(private readonly ctx: Context, root: string) {
21
- this.service = new HistoryService(
22
- root,
23
- new HistoryFiles(join(root, ".pbot/history"), "dsh"),
24
- new DshHistory(ctx, root),
25
- [new HistoryFiles(join(root, ".pbot/history"), "pi"), new HistoryFiles(join(root, ".pbot/history"), "claude")],
26
- () => acpHistorySessions({ mcp: defaultWorkerDirectory() }),
27
- );
28
- }
29
-
30
- attach(agent: Agent) { this.#parents.add(agent); return () => { this.#parents.delete(agent); }; }
31
- cancel() { this.#controller?.abort(); }
32
- schedule(agent: Agent) {
33
- if (this.#closing || [...this.#parents].some(parent => parent.status !== "idle" || parent.inbox.nextTurn.length || parent.inbox.nextStep.length)) return;
34
- this.cancel();
35
- const controller = new AbortController(), selection = agent.model.current(), sessionId = agent.id;
36
- this.#controller = controller;
37
- const signal = controller.signal;
38
- const work = (this.#work ?? Promise.resolve()).catch(() => {}).then(async () => {
39
- signal.throwIfAborted();
40
- await this.service.refresh({ host: "dsh", sessionId }, signal);
41
- signal.throwIfAborted();
42
- await this.service.organize(dshHistorySummarizer(this.ctx, selection, sessionId), signal);
43
- }).catch(error => { if (!signal.aborted) this.ctx.logger.warn("pbot 历史整理未完成:" + String(error)); });
44
- this.#work = work;
45
- void work.finally(() => { if (this.#work === work) { this.#work = undefined; this.#controller = undefined; } });
46
- }
47
- close() {
48
- if (this.#closing) return this.#closing;
49
- this.cancel();
50
- this.#closing = (async () => { await this.#work; await this.service.close(); this.#parents.clear(); })();
51
- return this.#closing;
52
- }
53
- }
54
-
55
- export function registerDshHistoryEvents(ctx: Context, agent: Agent, work: DshHistoryWork, check: () => void) {
56
- let normal = false, final = false;
57
- ctx.effect(() => work.attach(agent));
58
- ctx.on("session/event", (session, event) => {
59
- if (session !== agent.session) return;
60
- if (event.type === "turn/start") { normal = false; final = false; }
61
- if (event.type === "assistant/message") final = Boolean(finalDshAnswer(event).trim());
62
- if (event.type === "agent/inbox/spliced" && event.data.inserted.some(message => message.source.kind === "user")) { normal = false; work.cancel(); }
63
- if (event.type === "turn/end") normal = event.data.reason.kind === "completed" && final;
64
- });
65
- ctx.on("agent/pre-step", async (_payload, next) => { work.cancel(); check(); return next(); });
66
- ctx.on("agent/status", ({ agent: changed, status }) => {
67
- if (changed !== agent || status !== "idle" || !normal) return;
68
- normal = false;
69
- if (!agent.inbox.nextTurn.length && !agent.inbox.nextStep.length) {
70
- try { check(); } catch (error) { if ((error as Error).name === "AbortError") return; throw error; }
71
- work.schedule(agent);
72
- }
73
- });
74
- }
@@ -1,26 +0,0 @@
1
- import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
2
- import { historyLocation, historySummarizer } from "../integrations/pi/history.js";
3
- import type { Lifecycle } from "./lifecycle.js";
4
-
5
- export function registerHistoryEvents(pi: ExtensionAPI, lifecycle: Lifecycle) {
6
- pi.on("session_start", async (_event, ctx) => {
7
- const instance = lifecycle.active;
8
- if (!instance) return;
9
- try { await instance.history.refresh(historyLocation(ctx), instance.signal()); }
10
- catch (error) { ctx.ui.notify("历史索引:" + String(error), "warning"); }
11
- });
12
- pi.on("agent_settled", (event, ctx) => {
13
- const instance = lifecycle.active;
14
- if (!instance || event.aborted) return;
15
- const signal = instance.signal();
16
- void (async () => {
17
- await instance.history.refresh(historyLocation(ctx), signal);
18
- signal.throwIfAborted();
19
- const summarize = await historySummarizer(ctx);
20
- ctx.ui.setStatus("pbot-history", "历史整理中");
21
- await instance.history.organize(summarize, signal);
22
- })().catch(error => {
23
- if (!signal.aborted) ctx.ui.notify("历史摘要暂未完成,下次交互结束后重试:" + String(error), "warning");
24
- }).finally(() => { if (lifecycle.active === instance) ctx.ui.setStatus("pbot-history", undefined); });
25
- });
26
- }
@@ -1,63 +0,0 @@
1
- import { resourceRoot } from "../common/paths.js";
2
- import { packageVersion } from "../common/version.js";
3
- import { requireThat } from "../common/validation.js";
4
- import { loadWorkspaceContext } from "../integrations/agent-resources.js";
5
- import type { PluginHostAdapter } from "../model/plugin-host.js";
6
- import { readWorkspaceConfig, workspaceFeatures } from "../services/workspace/workspace-config.js";
7
- import { initializeWorkspace } from "../services/workspace/workspace-preparation.js";
8
- import { discoverWorkspaceSkills } from "../services/workspace/workspace-skills.js";
9
-
10
- function disabledMessage(adapter: PluginHostAdapter, configuration: Awaited<ReturnType<typeof readWorkspaceConfig>>) {
11
- return configuration.error ?? `Personal Bot 未在此工作区启用。运行 ${adapter.initCommandHint};配置文件:${configuration.path}`;
12
- }
13
-
14
- export async function pluginCommand(adapter: PluginHostAdapter, args: readonly string[], cwd: string) {
15
- const root = await adapter.resolveRoot(cwd);
16
- const action = args.join(" ");
17
- requireThat(["init", "status"].includes(action), adapter.usage);
18
- if (action === "init") await initializeWorkspace(root);
19
- const configuration = await readWorkspaceConfig(root);
20
- return { version: packageVersion, workspaceRoot: root, resourceRoot, configuration };
21
- }
22
-
23
- export async function runPluginHost(adapter: PluginHostAdapter, args: readonly string[]): Promise<void> {
24
- if (args[0] === "hook") {
25
- let input = "";
26
- process.stdin.setEncoding("utf8");
27
- for await (const chunk of process.stdin) input += String(chunk);
28
- process.stdout.write(JSON.stringify(await pluginHook(adapter, JSON.parse(input))) + "\n");
29
- } else {
30
- process.stdout.write(JSON.stringify(await pluginCommand(adapter, args, process.cwd()), null, 2) + "\n");
31
- }
32
- }
33
-
34
- /** Shared hook execution engine; host-specific protocols stay in PluginHostAdapter implementations. */
35
- export async function pluginHook(adapter: PluginHostAdapter, payload: unknown): Promise<Record<string, unknown>> {
36
- if (process.env.PBOT_SUBAGENT_RUN_ID) return adapter.formatPass(payload);
37
- const event = adapter.parseEvent(payload);
38
- if (event.kind === "ignore") return adapter.formatPass(payload);
39
- const root = await adapter.resolveRoot(event.cwd, event.raw);
40
- const configuration = await readWorkspaceConfig(root);
41
- const features = workspaceFeatures(configuration);
42
- if (event.kind === "check-skill") {
43
- if (!configuration.enabled) return adapter.formatDeny(event, disabledMessage(adapter, configuration));
44
- if (!features.skills) return adapter.formatDeny(event, `Personal Bot 工作区技能已在 ${configuration.path} 中停用(features.skills: false)。`);
45
- return adapter.formatPass(payload);
46
- }
47
- if (!configuration.enabled) return adapter.formatPass(payload);
48
- const workspaceSkills = features.skills && !adapter.nativeWorkspaceSkills
49
- ? await discoverWorkspaceSkills(root)
50
- : [];
51
- if (!features.prompts && !workspaceSkills.length) return adapter.formatPass(payload);
52
- const context = await loadWorkspaceContext({
53
- host: adapter.host,
54
- root,
55
- role: event.role,
56
- ...(adapter.coordinatorPrompt ? { coordinatorPrompt: adapter.coordinatorPrompt } : {}),
57
- includePrompts: features.prompts,
58
- includeRootAgents: features.prompts && !adapter.nativeRootAgents,
59
- ...(event.localRoleOnly ? { localRoleOnly: true } : {}),
60
- workspaceSkills,
61
- });
62
- return adapter.formatContext(event, context);
63
- }
@@ -1,39 +0,0 @@
1
- import type { Context } from "@deepseek-ai/cordis";
2
- import type { Agent } from "@deepseek-ai/dsh-agent";
3
- import type { SessionId } from "@deepseek-ai/dsh-session";
4
- import { BlockAssembler, type PreparedLlmCall } from "@deepseek-ai/dsh-llm";
5
- import type { HistorySummarizer } from "../../model/history.js";
6
- import { requireThat } from "../../common/validation.js";
7
- import { reduceHistorySummary } from "../history-summary.js";
8
-
9
- declare module "@deepseek-ai/dsh-llm" {
10
- interface LlmRequestPurposeMap { "pbot-history": true }
11
- }
12
-
13
- /** Independent text calls through the host's routing and authentication; no Agent or Session messages. */
14
- export function dshHistorySummarizer(ctx: Context, selection: ReturnType<Agent["model"]["current"]>, sessionId: SessionId): HistorySummarizer {
15
- return async (request, signal) => {
16
- requireThat(selection, "请先选择 dsh 模型。"); signal.throwIfAborted();
17
- const prepare = () => ctx.llm.prepareCall({ provider: selection.provider, model: selection.model, maxTokens: request.maxTokens }, signal,
18
- (controls, model) => ({ ...controls, ...(model.reasoning?.efforts[0] ? { reasoningEffort: model.reasoning.efforts[0].id } : {}) }));
19
- let first: PreparedLlmCall | undefined = await prepare();
20
- const budget = Math.max(2000, Math.min(24000, Math.floor((first.context?.contextWindow ?? 12000) / 2)));
21
- const ask: HistorySummarizer = async ({ system, prompt }, signal) => {
22
- signal.throwIfAborted();
23
- const prepared = first ?? await prepare(); first = undefined;
24
- const assembler = new BlockAssembler(); let finished = false;
25
- for await (const chunk of prepared.stream({ ...prepared.config, system, sessionId, purpose: "pbot-history", signal, tools: [],
26
- messages: [{ role: "user", content: [{ type: "text", text: prompt }] }] })) {
27
- signal.throwIfAborted(); assembler.push(chunk); if (chunk.type === "finish") finished = true;
28
- }
29
- signal.throwIfAborted();
30
- const reason = assembler.finish;
31
- requireThat(finished && reason.kind === "stop", reason.kind === "error" || reason.kind === "aborted" ? reason.failure.message : "历史摘要未正常结束:" + reason.kind);
32
- const blocks = assembler.blocks();
33
- requireThat(!blocks.some(block => block.type === "tool-call"), "历史摘要不能执行工具。");
34
- const answer = blocks.filter(block => block.type === "text").map(block => block.text).join("\n").trim();
35
- requireThat(answer, "历史摘要为空。"); return answer;
36
- };
37
- return reduceHistorySummary(budget, ask)(request, signal);
38
- };
39
- }
@@ -1,84 +0,0 @@
1
- import { realpath } from "node:fs/promises";
2
- import type { Context } from "@deepseek-ai/cordis";
3
- import type { SessionEvent, SessionHeader } from "@deepseek-ai/dsh-session";
4
- import { SessionId } from "@deepseek-ai/dsh-session";
5
- import type {} from "@deepseek-ai/dsh-session-query";
6
- import type { HistoryExchange, HistoryLocation, HistorySession, HistorySource } from "../../model/history.js";
7
- import { requireThat } from "../../common/validation.js";
8
- import { finalDshAnswer } from "./messages.js";
9
-
10
- type Question = Extract<SessionEvent, { type: "user/message" }>;
11
- type Answer = Extract<SessionEvent, { type: "assistant/message" }>;
12
- const text = (content: Question["data"]["content"]) => content.flatMap(block => block.type === "text" ? [block.text] :
13
- block.type === "image" ? ["[图片 " + (block.attachment.name ?? block.attachment.attachmentId) + "]"] :
14
- block.type === "file" ? ["[附件 " + (block.attachment.name ?? block.attachment.attachmentId) + "]"] : []).join("\n");
15
-
16
- /** Archive questions and the final/partial answer; raw tool records stay in the native log. */
17
- export function projectDshHistory(header: SessionHeader, events: readonly SessionEvent[], name = ""): HistorySession {
18
- const exchanges: HistoryExchange[] = [], supersededEntryIds: string[] = [];
19
- let users: Question[] = [], answer: Answer | undefined, observed: string[] = [];
20
- const finish = (completed = false) => {
21
- if (users.length) {
22
- const entries = [...users, ...(answer ? [answer] : [])];
23
- const body = answer ? answer.data.message.content.filter(block => block.type === "text").map(block => block.text).join("\n") : "";
24
- exchanges.push({ entryIds: entries.map(event => "dsh:" + event.seq), from: new Date(users[0]!.time).toISOString(),
25
- to: new Date(entries.at(-1)!.time).toISOString(),
26
- completed: completed && Boolean(answer && finalDshAnswer(answer).trim()),
27
- text: users.map(event => (event.data.source.kind === "user" ? "用户:\n" : "协调者要求:\n") + text(event.data.content)).join("\n\n") +
28
- (body ? "\n\n助手:\n" + body : "") });
29
- }
30
- const last = (answer ?? users.at(-1))?.seq;
31
- supersededEntryIds.push(...observed.filter(id => id !== "dsh:" + last));
32
- users = []; answer = undefined; observed = [];
33
- };
34
- for (const event of events) {
35
- if (event.type === "turn/start") finish();
36
- else if (event.type === "user/message" && ["user", "pbot-input"].includes(event.data.source.kind)) {
37
- if (!answer) observed.push("dsh:" + event.seq);
38
- users.push(event);
39
- } else if (event.type === "assistant/message" && users.length) {
40
- answer = event; observed.push("dsh:" + event.seq);
41
- }
42
- else if (event.type === "turn/end") finish(event.data.reason.kind === "completed");
43
- }
44
- finish();
45
- return { sessionId: header.id, name, branches: exchanges.length ? [exchanges] : [], supersededEntryIds };
46
- }
47
-
48
- export class DshHistory implements HistorySource {
49
- readonly host = "dsh";
50
- constructor(private readonly ctx: Context, private readonly root: string, private readonly relatedSessions: () => string[] = () => []) {}
51
- async scan(location: HistoryLocation, signal?: AbortSignal, excluded?: ReadonlySet<string>) {
52
- requireThat(location.host === "dsh", "dsh 历史只读取 dsh 原生会话。");
53
- signal?.throwIfAborted();
54
- const records = (await this.ctx.sessionQuery.listSessions(signal)).filter(record => !excluded?.has(record.header.id));
55
- const selected = new Set<string>(), warnings: string[] = [];
56
- // Expert records also name ACP members and sessions that dsh no longer stores; only real dsh sessions are readable.
57
- const stored = new Set<string>(records.map(record => record.header.id));
58
- try { for (const id of this.relatedSessions()) if (stored.has(id)) selected.add(id); } catch (error) { warnings.push("专家引用:" + String(error)); }
59
- if (location.sessionId && !excluded?.has(location.sessionId)) selected.add(location.sessionId);
60
- for (const record of records) {
61
- signal?.throwIfAborted();
62
- if ((record.header.origin !== "subagent" || !record.header.parentSession) && record.header.cwd &&
63
- await realpath(record.header.cwd).catch(() => record.header.cwd) === this.root) selected.add(record.header.id);
64
- }
65
- // Native subagents may use a different cwd while still belonging to a workspace's parent.
66
- for (let changed = true; changed;) {
67
- changed = false;
68
- for (const record of records) if (record.header.origin === "subagent" && record.header.parentSession && selected.has(record.header.parentSession) && !selected.has(record.header.id)) {
69
- selected.add(record.header.id); changed = true;
70
- }
71
- }
72
- const sessions: HistorySession[] = [];
73
- for (const id of selected) {
74
- signal?.throwIfAborted();
75
- try {
76
- using observation = await this.ctx.sessionQuery.observeSession(SessionId(id), { ...(signal ? { signal } : {}), projectionMode: "none" });
77
- const title = await this.ctx.sessionQuery.readTitle(SessionId(id), signal);
78
- const session = projectDshHistory(observation.header, observation.events, title?.title);
79
- if (session.branches.length) sessions.push(session);
80
- } catch (error) { signal?.throwIfAborted(); warnings.push(id + ": " + String(error)); }
81
- }
82
- return { sessions, warnings };
83
- }
84
- }
@@ -1,30 +0,0 @@
1
- import type { HistorySummarizer } from "../model/history.js";
2
-
3
- /** Split Pi/dsh summary inputs within the model's character budget. */
4
- export function splitHistorySummary(text: string, budget: number): string[] {
5
- if (!Number.isInteger(budget) || budget < 2) throw new Error("历史摘要分段预算无效。");
6
- const parts: string[] = [];
7
- for (let offset = 0; offset < text.length;) {
8
- let end = Math.min(text.length, offset + budget);
9
- if (end < text.length && /[\uD800-\uDBFF]/.test(text[end - 1]!)) end--;
10
- parts.push(text.slice(offset, end)); offset = end;
11
- }
12
- return parts;
13
- }
14
-
15
- export function reduceHistorySummary(budget: number, ask: HistorySummarizer): HistorySummarizer {
16
- return async (request, signal) => {
17
- let text = request.prompt;
18
- while (text.length > budget) {
19
- const parts: string[] = [];
20
- for (const prompt of splitHistorySummary(text, budget)) {
21
- signal.throwIfAborted();
22
- parts.push(await ask({ ...request, prompt }, signal));
23
- }
24
- const smaller = parts.join("\n\n");
25
- if (smaller.length >= text.length) throw new Error("历史摘要未缩短,稍后重试。");
26
- text = smaller;
27
- }
28
- signal.throwIfAborted(); return ask({ ...request, prompt: text }, signal);
29
- };
30
- }