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
@@ -0,0 +1,121 @@
1
+ import type { AcpBackend, AcpElicitationAction, AcpElicitationContent, AcpModelSelection, AcpSessionReference, AcpStartOptions } from "./acp.js";
2
+ export type AgentOptions = AcpStartOptions;
3
+ export interface AgentStartOptions extends AgentOptions {
4
+ backend: AcpBackend;
5
+ }
6
+ export interface AgentOwner {
7
+ sessionId: string;
8
+ leaf: string | null;
9
+ branch: string[];
10
+ }
11
+ export interface AgentDescriptor {
12
+ agentId: string;
13
+ release: string;
14
+ workspace: string;
15
+ cwd: string;
16
+ parentSessionId: string;
17
+ parentLeaf: string | null;
18
+ createdAt: number;
19
+ options: AgentOptions;
20
+ }
21
+ export type AgentSessionReference = AcpSessionReference;
22
+ export interface AgentLaunch {
23
+ generation: string;
24
+ name: string;
25
+ sequence: number;
26
+ stop: boolean;
27
+ startedAt: number;
28
+ }
29
+ export declare const messageDeliveries: readonly ["steer", "followUp"];
30
+ export declare const cycleStates: readonly ["running", "completed", "failed", "cancelled", "interrupted"];
31
+ export declare const cycleSources: readonly ["parent", "interactive", "mixed"];
32
+ export declare const agentStates: readonly ["starting", "busy", "idle", "stopping", "stopped", "error"];
33
+ export interface AgentMessage {
34
+ requestId: string;
35
+ generation: string;
36
+ sequence: number;
37
+ message: string;
38
+ delivery: typeof messageDeliveries[number];
39
+ files: string[];
40
+ }
41
+ export interface AgentCycle {
42
+ cycleId: string;
43
+ generation: string;
44
+ startedAt: number;
45
+ finishedAt?: number;
46
+ state: typeof cycleStates[number];
47
+ leaf: string | null;
48
+ requestIds: string[];
49
+ source: typeof cycleSources[number];
50
+ error?: string;
51
+ }
52
+ export interface AgentStatus {
53
+ generation: string;
54
+ state: typeof agentStates[number];
55
+ activity: string;
56
+ updatedAt: number;
57
+ accepted?: string[];
58
+ cycle?: AgentCycle;
59
+ error?: string;
60
+ }
61
+ export interface AgentView extends AgentDescriptor {
62
+ name: string;
63
+ generation: string;
64
+ state: AgentStatus["state"];
65
+ activity: string;
66
+ alive: boolean;
67
+ backend: AcpBackend;
68
+ transport: "acp";
69
+ selection?: AcpModelSelection;
70
+ capabilities: {
71
+ steer: boolean;
72
+ resume: boolean;
73
+ transcript: boolean;
74
+ };
75
+ cycle?: AgentCycle;
76
+ error?: string;
77
+ owned: boolean;
78
+ pendingRequests?: AgentPendingRequest[];
79
+ }
80
+ export type AgentPendingRequest = {
81
+ requestId: string;
82
+ kind: "permission";
83
+ description: string;
84
+ options: {
85
+ optionId: string;
86
+ name: string;
87
+ kind: string;
88
+ }[];
89
+ } | {
90
+ requestId: string;
91
+ kind: "form";
92
+ message: string;
93
+ schema: Record<string, unknown>;
94
+ } | {
95
+ requestId: string;
96
+ kind: "url";
97
+ message: string;
98
+ url: string;
99
+ };
100
+ export interface AgentResponseInput {
101
+ requestId?: string;
102
+ action: AcpElicitationAction;
103
+ optionId?: string;
104
+ content?: AcpElicitationContent;
105
+ }
106
+ export interface AgentCompletion {
107
+ agentId: string;
108
+ name: string;
109
+ cycle: AgentCycle;
110
+ report: string;
111
+ }
112
+ export interface AgentHost {
113
+ available(backend: AcpBackend): void;
114
+ filterOptions?(backend: AcpBackend, options: AgentOptions): AgentOptions;
115
+ prepare(backend: AcpBackend, options: AgentOptions): AcpSessionReference;
116
+ alive(id: string): boolean;
117
+ validateSession(value: AgentDescriptor, reference: AgentSessionReference): void | Promise<void>;
118
+ launch(value: AgentDescriptor, directory: string, generation: string, reference: AgentSessionReference, resume: boolean, signal: AbortSignal): void | Promise<void>;
119
+ release(id: string, generation: string): void | Promise<void>;
120
+ report(value: AgentDescriptor, reference: AgentSessionReference, leaf: string): string | Promise<string>;
121
+ }
@@ -0,0 +1,4 @@
1
+ export const messageDeliveries = ["steer", "followUp"];
2
+ export const cycleStates = ["running", "completed", "failed", "cancelled", "interrupted"];
3
+ export const cycleSources = ["parent", "interactive", "mixed"];
4
+ export const agentStates = ["starting", "busy", "idle", "stopping", "stopped", "error"];
@@ -0,0 +1,179 @@
1
+ import type { HistoryLayout } from "./workspace-config.js";
2
+ export type { HistoryLayout };
3
+ export type HistoryHost = string;
4
+ export interface HistoryExchange {
5
+ entryIds: string[];
6
+ text: string;
7
+ from: string;
8
+ to: string;
9
+ completed: boolean;
10
+ }
11
+ export interface HistorySession {
12
+ sessionId: string;
13
+ name: string;
14
+ branches: HistoryExchange[][];
15
+ /** Earlier partial observations replaced along the same native branch or turn; never persisted. */
16
+ supersededEntryIds?: string[];
17
+ }
18
+ export interface HistoryIdentity {
19
+ host: HistoryHost;
20
+ id: string;
21
+ sessionId: string;
22
+ }
23
+ export interface RawHistory extends HistoryIdentity {
24
+ name: string;
25
+ /** One entry per archived exchange; array order does not describe a conversation. */
26
+ exchanges: (HistoryExchange & {
27
+ id: string;
28
+ })[];
29
+ /** Ordered paths observed in the native source. */
30
+ branches: string[][];
31
+ }
32
+ export interface SummarySource {
33
+ rawIds: string[];
34
+ exchangeIds: string[];
35
+ fingerprint: string;
36
+ }
37
+ export interface SummaryArtifact {
38
+ id: string;
39
+ dimension: string;
40
+ host?: HistoryHost;
41
+ sessionId?: string;
42
+ title: string;
43
+ text: string;
44
+ from: string;
45
+ to: string;
46
+ updatedAt: string;
47
+ source: SummarySource;
48
+ }
49
+ export interface HistorySummaryRequest {
50
+ system: string;
51
+ prompt: string;
52
+ maxTokens: number;
53
+ }
54
+ export type HistorySummarizer = (request: HistorySummaryRequest, signal: AbortSignal) => Promise<string>;
55
+ export type SummaryTaskMode = "create" | "incremental" | "rebuild";
56
+ export interface SummaryTask {
57
+ id: string;
58
+ dimension: string;
59
+ mode: SummaryTaskMode;
60
+ title: string;
61
+ host?: HistoryHost;
62
+ sessionId?: string;
63
+ from: string;
64
+ to: string;
65
+ source: SummarySource;
66
+ exchanges: readonly (HistoryExchange & {
67
+ id: string;
68
+ })[];
69
+ existing?: SummaryArtifact;
70
+ addedExchanges?: readonly (HistoryExchange & {
71
+ id: string;
72
+ })[];
73
+ sourceSummaries?: readonly SummaryArtifact[];
74
+ }
75
+ export interface SummaryPlanOptions {
76
+ force?: boolean;
77
+ summariesByDimension?: ReadonlyMap<string, ReadonlyMap<string, SummaryArtifact>>;
78
+ }
79
+ export interface SummaryPlanResult {
80
+ tasks: SummaryTask[];
81
+ skipped: number;
82
+ }
83
+ export interface SummaryDimension {
84
+ readonly id: string;
85
+ readonly title: string;
86
+ readonly description: string;
87
+ readonly requiresMonthlyLayout?: boolean;
88
+ plan(raws: readonly RawHistory[], existing: ReadonlyMap<string, SummaryArtifact>, options?: SummaryPlanOptions): SummaryPlanResult;
89
+ buildRequest(task: SummaryTask): HistorySummaryRequest;
90
+ finalize(task: SummaryTask, output: string, now: string): SummaryArtifact;
91
+ }
92
+ export interface HistoryMigrationItem {
93
+ kind: "raw" | "summary";
94
+ dimension?: string;
95
+ id: string;
96
+ from: string;
97
+ to: string;
98
+ }
99
+ export interface HistoryMigrationConflict {
100
+ kind: "raw" | "summary";
101
+ dimension?: string;
102
+ from: string;
103
+ to: string;
104
+ reason: string;
105
+ }
106
+ export interface HistoryMigrationReport {
107
+ layout: HistoryLayout;
108
+ dryRun: boolean;
109
+ moved: HistoryMigrationItem[];
110
+ skipped: HistoryMigrationConflict[];
111
+ errors: {
112
+ path: string;
113
+ error: string;
114
+ }[];
115
+ }
116
+ export interface SummaryDimensionStatus {
117
+ dimension: string;
118
+ title: string;
119
+ description: string;
120
+ total: number;
121
+ ready: number;
122
+ pendingCreate: number;
123
+ pendingIncremental: number;
124
+ pendingRebuild: number;
125
+ }
126
+ export interface HistorySummaryReminder {
127
+ rawCount: number;
128
+ pendingCount: number;
129
+ oldestRawAt: string;
130
+ latestSummaryAt?: string;
131
+ rawAgeDays: number;
132
+ daysSinceLastSummary?: number;
133
+ thresholdDays: number;
134
+ message: string;
135
+ }
136
+ export interface SummaryRunProgress {
137
+ dimension: string;
138
+ completed: number;
139
+ total: number;
140
+ currentId: string;
141
+ mode: SummaryTaskMode;
142
+ }
143
+ export interface SummaryDimensionReport {
144
+ dimension: string;
145
+ scanned: number;
146
+ skipped: number;
147
+ created: number;
148
+ incremental: number;
149
+ rebuilt: number;
150
+ failed: {
151
+ id: string;
152
+ error: string;
153
+ }[];
154
+ }
155
+ export interface SummaryRunReport {
156
+ dimensions: SummaryDimensionReport[];
157
+ durationMs: number;
158
+ warnings: string[];
159
+ }
160
+ export declare const historyPageLimits: {
161
+ readonly search: {
162
+ readonly default: 20;
163
+ readonly max: 50;
164
+ };
165
+ readonly read: {
166
+ readonly default: 12000;
167
+ readonly max: 24000;
168
+ };
169
+ };
170
+ export interface HistoryQuery {
171
+ host?: HistoryHost;
172
+ query?: string;
173
+ sessionId?: string;
174
+ dimension?: string;
175
+ from?: string;
176
+ to?: string;
177
+ offset?: number;
178
+ limit?: number;
179
+ }
@@ -0,0 +1,4 @@
1
+ export const historyPageLimits = {
2
+ search: { default: 20, max: 50 },
3
+ read: { default: 12_000, max: 24_000 },
4
+ };
@@ -1,3 +1,4 @@
1
+ import type { HistorySession } from "./history.js";
1
2
  import type { WorkspaceSkillMeta } from "./workspace-mcp.js";
2
3
  export type HostId = string;
3
4
  export type PluginHostId = string;
@@ -15,12 +16,33 @@ export interface WorkspaceContext {
15
16
  environment: WorkspaceEnvironment;
16
17
  text: string;
17
18
  }
19
+ export type HistoryCapture = {
20
+ kind: "input";
21
+ sessionId: string;
22
+ turnId?: string;
23
+ text: string;
24
+ timestamp?: string;
25
+ } | {
26
+ kind: "answer";
27
+ sessionId: string;
28
+ turnId?: string;
29
+ userText?: string;
30
+ assistantText: string;
31
+ completed: boolean;
32
+ isContinuation?: boolean;
33
+ timestamp?: string;
34
+ } | {
35
+ kind: "session";
36
+ session: HistorySession;
37
+ };
18
38
  export type HostEvent = {
19
39
  kind: "ignore";
20
40
  } | {
21
41
  kind: "inject-context";
22
42
  role: WorkspaceRole;
23
43
  localRoleOnly?: boolean;
44
+ isSessionStart?: boolean;
45
+ noticesOnly?: boolean;
24
46
  cwd: string;
25
47
  raw: unknown;
26
48
  } | {
@@ -28,16 +50,25 @@ export type HostEvent = {
28
50
  skill: string;
29
51
  cwd: string;
30
52
  raw: unknown;
53
+ } | {
54
+ kind: "record-history";
55
+ cwd: string;
56
+ raw: unknown;
31
57
  };
32
58
  export interface PluginHostAdapter {
33
59
  readonly host: PluginHostId;
34
60
  readonly nativeRootAgents: boolean;
61
+ readonly indexBundledSkills?: boolean;
35
62
  readonly nativeWorkspaceSkills?: boolean;
36
63
  readonly coordinatorPrompt?: string;
37
64
  readonly initCommandHint: string;
38
65
  readonly usage: string;
66
+ boundWorkspaceRoot?(): string | undefined;
39
67
  resolveRoot(cwd: string, rawPayload?: unknown): Promise<string>;
40
68
  parseEvent(payload: unknown): HostEvent;
69
+ extractHistory?(event: Extract<HostEvent, {
70
+ kind: "inject-context" | "record-history";
71
+ }>): Promise<HistoryCapture | undefined>;
41
72
  formatPass(payload: unknown): Record<string, unknown>;
42
73
  formatContext(event: Extract<HostEvent, {
43
74
  kind: "inject-context";
@@ -3,22 +3,43 @@ export interface WorkspaceFeatures {
3
3
  prompts?: boolean;
4
4
  skills?: boolean;
5
5
  mcp?: boolean;
6
+ history?: boolean;
6
7
  }
7
- export interface ResolvedWorkspaceFeatures {
8
- readonly prompts: boolean;
9
- readonly skills: boolean;
10
- readonly mcp: boolean;
8
+ export type ResolvedWorkspaceFeatures = Readonly<Required<WorkspaceFeatures>>;
9
+ export declare const summaryConcurrency: {
10
+ readonly default: 3;
11
+ readonly max: 8;
12
+ };
13
+ export interface WorkspaceSummaryConfig {
14
+ backend?: string;
15
+ model?: string;
16
+ thinking?: string;
17
+ concurrency?: number;
18
+ }
19
+ export interface ResolvedWorkspaceSummaryConfig {
20
+ readonly backend: string;
21
+ readonly model?: string;
22
+ readonly thinking?: string;
23
+ readonly concurrency: number;
24
+ }
25
+ export declare const historyLayouts: readonly ["monthly", "flat"];
26
+ export type HistoryLayout = typeof historyLayouts[number];
27
+ export interface WorkspaceHistoryConfig {
28
+ layout?: HistoryLayout;
29
+ }
30
+ export interface ResolvedWorkspaceHistoryConfig {
31
+ readonly layout: HistoryLayout;
11
32
  }
12
33
  export interface WorkspaceConfig {
13
34
  enabled?: boolean;
14
35
  features?: WorkspaceFeatures;
15
36
  acp?: AcpCommands;
37
+ summary?: WorkspaceSummaryConfig;
38
+ history?: WorkspaceHistoryConfig;
16
39
  }
17
- export interface WorkspaceConfiguration {
40
+ export interface WorkspaceConfiguration extends WorkspaceConfig {
18
41
  path: string;
19
42
  present: boolean;
20
43
  enabled: boolean;
21
44
  error?: string;
22
- features?: WorkspaceFeatures;
23
- acp?: AcpCommands;
24
45
  }
@@ -1 +1,2 @@
1
- export {};
1
+ export const summaryConcurrency = { default: 3, max: 8 };
2
+ export const historyLayouts = ["monthly", "flat"];
@@ -1 +1,2 @@
1
- export declare function main(args: readonly string[]): Promise<void>;
1
+ import { type ReplayPluginHook } from "./extension/hosts/plugin-runtime.js";
2
+ export declare function main(args: readonly string[], replayHook?: ReplayPluginHook): Promise<void>;
@@ -1,13 +1,13 @@
1
1
  import { realpathSync } from "node:fs";
2
2
  import { pathToFileURL } from "node:url";
3
3
  import { requireThat } from "./common/validation.js";
4
- import { runPluginHost } from "./extension/plugin-runtime.js";
5
- import { listPluginHosts, pluginHosts } from "./integrations/hosts/registry.js";
6
- export async function main(args) {
4
+ import { runPluginHost } from "./extension/hosts/plugin-runtime.js";
5
+ import { listPluginHosts, pluginHosts } from "./integrations/hosts/plugin-registry.js";
6
+ export async function main(args, replayHook) {
7
7
  const [host, ...rest] = args;
8
8
  const adapter = host ? pluginHosts.get(host) : undefined;
9
9
  requireThat(adapter, `用法:node <插件目录>/lib/plugin.js <${listPluginHosts().join("|")}> hook|init|status`);
10
- await runPluginHost(adapter, rest);
10
+ await runPluginHost(adapter, rest, replayHook);
11
11
  }
12
12
  if (process.argv[1] && import.meta.url === pathToFileURL(realpathSync(process.argv[1])).href) {
13
13
  void main(process.argv.slice(2)).catch(error => {
@@ -0,0 +1,4 @@
1
+ import type { HistoryHost } from "../../model/history.js";
2
+ import type { HistoryCapture } from "../../model/plugin-host.js";
3
+ /** Persist a host raw history observation atomically into .pbot/history/raw/. */
4
+ export declare function recordHistoryCapture(root: string, host: HistoryHost, capture: HistoryCapture): void;
@@ -0,0 +1,98 @@
1
+ import { randomUUID } from "node:crypto";
2
+ import { isDeepStrictEqual } from "node:util";
3
+ import { workspaceHistoryFiles } from "./workspace-history.js";
4
+ import { indexHistory, orderedRawExchanges } from "./history-index.js";
5
+ function orderedExchanges(raw) {
6
+ if (!raw)
7
+ return [];
8
+ return orderedRawExchanges(raw).map(({ entryIds, text, from, to, completed }) => ({
9
+ entryIds: [...entryIds],
10
+ text,
11
+ from,
12
+ to,
13
+ completed,
14
+ }));
15
+ }
16
+ function replaceAssistantSuffix(text, assistantText) {
17
+ const marker = "\n\n助手:\n";
18
+ const section = `助手:\n${assistantText}`;
19
+ if (text === section || text.endsWith("\n\n" + section))
20
+ return text;
21
+ if (!text || text.startsWith("助手:\n"))
22
+ return section;
23
+ const index = text.lastIndexOf(marker);
24
+ if (index >= 0)
25
+ return text.slice(0, index) + marker + assistantText;
26
+ return text + marker + assistantText;
27
+ }
28
+ function buildSession(host, capture, previous) {
29
+ if (capture.kind === "session") {
30
+ return capture.session.branches.length ? capture.session : undefined;
31
+ }
32
+ const timestamp = capture.timestamp ?? new Date().toISOString();
33
+ const branch = orderedExchanges(previous);
34
+ // entryIds already identify native observations on disk. A turn keeps its ID
35
+ // across steering, attachment-only inputs and Stop hooks arriving out of order.
36
+ const turnEntry = capture.turnId ? `${host}:turn:${capture.turnId}` : undefined;
37
+ const turn = turnEntry ? branch.find(item => item.entryIds.includes(turnEntry)) : undefined;
38
+ const entryId = () => turnEntry ?? `${host}:${Date.now()}:${randomUUID().slice(0, 8)}`;
39
+ if (capture.kind === "input") {
40
+ const text = capture.text.trim();
41
+ if (!text && !turnEntry)
42
+ return undefined;
43
+ const input = "用户:\n" + (text || "(无文本输入)");
44
+ if (turn) {
45
+ turn.text += "\n\n" + input;
46
+ turn.to = timestamp;
47
+ turn.completed = false;
48
+ }
49
+ else {
50
+ branch.push({ entryIds: [entryId()], text: input, from: timestamp, to: timestamp, completed: false });
51
+ }
52
+ return { sessionId: capture.sessionId, name: previous?.name ?? "", branches: [branch] };
53
+ }
54
+ const assistantText = capture.assistantText.trim();
55
+ if (!assistantText)
56
+ return undefined;
57
+ const target = turnEntry ? turn : branch.at(-1);
58
+ if (target && (turnEntry || !target.completed || capture.isContinuation)) {
59
+ const updated = turnEntry && !target.completed
60
+ ? target.text + "\n\n助手:\n" + assistantText
61
+ : replaceAssistantSuffix(target.text, assistantText);
62
+ if (target.text === updated && target.completed === capture.completed)
63
+ return undefined;
64
+ target.text = updated;
65
+ target.to = timestamp;
66
+ target.completed = capture.completed;
67
+ }
68
+ else {
69
+ const userText = capture.userText?.trim();
70
+ branch.push({
71
+ entryIds: [entryId()],
72
+ text: userText ? `用户:\n${userText}\n\n助手:\n${assistantText}` : `助手:\n${assistantText}`,
73
+ from: timestamp,
74
+ to: timestamp,
75
+ completed: capture.completed,
76
+ });
77
+ }
78
+ return { sessionId: capture.sessionId, name: previous?.name ?? "", branches: [branch] };
79
+ }
80
+ /** Persist a host raw history observation atomically into .pbot/history/raw/. */
81
+ export function recordHistoryCapture(root, host, capture) {
82
+ const sessionId = capture.kind === "session" ? capture.session.sessionId : capture.sessionId;
83
+ if (!sessionId)
84
+ return;
85
+ const files = workspaceHistoryFiles(root, host);
86
+ files.control(() => {
87
+ const previous = files.listRaw(host).find(raw => raw.sessionId === sessionId);
88
+ if (!previous && files.rawWarnings.length)
89
+ return;
90
+ const session = buildSession(host, capture, previous);
91
+ if (!session || !session.branches.length)
92
+ return;
93
+ const raw = indexHistory(session, previous, host);
94
+ if (isDeepStrictEqual(raw, previous))
95
+ return;
96
+ files.saveRaw(raw);
97
+ });
98
+ }
@@ -0,0 +1,17 @@
1
+ import type { HistoryExchange, HistoryHost, HistorySession, RawHistory } from "../../model/history.js";
2
+ /** Merge a native session observation into its raw archive without modifying persisted order invariants. */
3
+ export declare function indexHistory(session: HistorySession, previous?: RawHistory, host?: HistoryHost): RawHistory;
4
+ /** Return deduplicated exchanges in conversation order (branch order first, then any unbranched entries by timestamp). */
5
+ export declare function orderedRawExchanges(raw: RawHistory): (HistoryExchange & {
6
+ id: string;
7
+ })[];
8
+ export declare function rawSessionTitle(raw: RawHistory): string;
9
+ export declare function rawSessionSpan(exchanges: readonly HistoryExchange[]): {
10
+ from: string;
11
+ to: string;
12
+ completed: boolean;
13
+ };
14
+ /** Stable SHA-256 fingerprint over ordered exchange contents for exact deduplication and prefix matching. */
15
+ export declare function fingerprintExchanges(exchanges: readonly (HistoryExchange & {
16
+ id: string;
17
+ })[]): string;