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,299 @@
1
+ import { isDeepStrictEqual } from "node:util";
2
+ import { setTimeout as delay } from "node:timers/promises";
3
+ import { requireThat } from "../../common/validation.js";
4
+ import { summaryConcurrency } from "../../model/workspace-config.js";
5
+ import { workspaceHistoryFiles } from "./workspace-history.js";
6
+ import { rawSessionSpan } from "./history-index.js";
7
+ import { resolveSummaryDimensions } from "./summary-registry.js";
8
+ const lockRetryAttempts = 5;
9
+ const lockRetryDelayMs = 40;
10
+ export const defaultSummaryReminderDays = 7;
11
+ const dayMs = 24 * 60 * 60 * 1000;
12
+ async function withSummaryLockRetry(files, dimension, operation, signal) {
13
+ for (let attempt = 0;; attempt++) {
14
+ signal?.throwIfAborted();
15
+ try {
16
+ return files.controlSummary(dimension, operation);
17
+ }
18
+ catch (error) {
19
+ const code = error.code;
20
+ if (code === "PBOT_HISTORY_BUSY" && attempt < lockRetryAttempts - 1) {
21
+ await delay(lockRetryDelayMs * (attempt + 1), undefined, { signal });
22
+ continue;
23
+ }
24
+ throw error;
25
+ }
26
+ }
27
+ }
28
+ function oldestRawTimestamp(raws) {
29
+ let oldest;
30
+ for (const raw of raws) {
31
+ if (!raw.exchanges.length)
32
+ continue;
33
+ const { from } = rawSessionSpan(raw.exchanges);
34
+ if (!from)
35
+ continue;
36
+ const parsed = Date.parse(from);
37
+ if (Number.isNaN(parsed))
38
+ continue;
39
+ if (oldest === undefined || parsed < oldest)
40
+ oldest = parsed;
41
+ }
42
+ return oldest;
43
+ }
44
+ function latestSummaryTimestamp(artifacts) {
45
+ let latest;
46
+ for (const artifact of artifacts) {
47
+ const parsed = Date.parse(artifact.updatedAt);
48
+ if (Number.isNaN(parsed))
49
+ continue;
50
+ if (latest === undefined || parsed > latest)
51
+ latest = parsed;
52
+ }
53
+ return latest;
54
+ }
55
+ function evaluateSummaryReminder(raws, allSummaries, pendingCount, options = {}) {
56
+ if (!raws.length || pendingCount <= 0)
57
+ return undefined;
58
+ const thresholdDays = options.thresholdDays ?? defaultSummaryReminderDays;
59
+ requireThat(Number.isFinite(thresholdDays) && thresholdDays > 0, "历史摘要提醒天数必须大于 0。");
60
+ const thresholdMs = thresholdDays * dayMs;
61
+ const nowMs = (options.now ?? new Date()).getTime();
62
+ const oldestRawMs = oldestRawTimestamp(raws);
63
+ if (oldestRawMs === undefined || nowMs - oldestRawMs < thresholdMs)
64
+ return undefined;
65
+ const latestSummaryMs = latestSummaryTimestamp(allSummaries);
66
+ if (latestSummaryMs !== undefined && nowMs - latestSummaryMs < thresholdMs)
67
+ return undefined;
68
+ const rawAgeDays = Math.floor((nowMs - oldestRawMs) / dayMs);
69
+ const daysSinceLastSummary = latestSummaryMs === undefined ? undefined : Math.floor((nowMs - latestSummaryMs) / dayMs);
70
+ const message = daysSinceLastSummary === undefined
71
+ ? `历史原文已累计 ${rawAgeDays} 天(待摘要 ${pendingCount} 项),尚未触发过摘要整理;可在终端运行 pbot history summary 生成摘要(Pi/dsh 可用 /pbot history summary)。`
72
+ : `历史原文已累计 ${rawAgeDays} 天,且已 ${daysSinceLastSummary} 天未触发摘要整理(待摘要 ${pendingCount} 项);可在终端运行 pbot history summary 更新摘要(Pi/dsh 可用 /pbot history summary)。`;
73
+ return {
74
+ rawCount: raws.length,
75
+ pendingCount,
76
+ oldestRawAt: new Date(oldestRawMs).toISOString(),
77
+ ...(latestSummaryMs !== undefined ? { latestSummaryAt: new Date(latestSummaryMs).toISOString() } : {}),
78
+ rawAgeDays,
79
+ ...(daysSinceLastSummary !== undefined ? { daysSinceLastSummary } : {}),
80
+ thresholdDays,
81
+ message,
82
+ };
83
+ }
84
+ /** Read-only startup probe: reminds when raw history has existed >= thresholdDays and no summary ran within thresholdDays. */
85
+ export function checkHistorySummaryReminder(root, options = {}) {
86
+ return summaryReminder(workspaceHistoryFiles(root), options);
87
+ }
88
+ export function historyStartupNotices(root) {
89
+ const notices = [];
90
+ try {
91
+ const files = workspaceHistoryFiles(root);
92
+ const migration = files.migrationNotice();
93
+ if (migration)
94
+ notices.push(migration);
95
+ const reminder = summaryReminder(files, {});
96
+ if (reminder)
97
+ notices.push(reminder.message);
98
+ }
99
+ catch { /* History diagnostics are best effort during host startup. */ }
100
+ return notices;
101
+ }
102
+ function summaryReminder(files, options) {
103
+ const raws = files.listRaw();
104
+ if (!raws.length)
105
+ return undefined;
106
+ const thresholdDays = options.thresholdDays ?? defaultSummaryReminderDays;
107
+ requireThat(Number.isFinite(thresholdDays) && thresholdDays > 0, "历史摘要提醒天数必须大于 0。");
108
+ const nowMs = (options.now ?? new Date()).getTime();
109
+ const oldestRawMs = oldestRawTimestamp(raws);
110
+ if (oldestRawMs === undefined || nowMs - oldestRawMs < thresholdDays * dayMs)
111
+ return undefined;
112
+ const { totalPending, allSummaries } = inspectDimensions(files, raws, options, []);
113
+ return evaluateSummaryReminder(raws, allSummaries, totalPending, options);
114
+ }
115
+ function inspectDimensions(files, raws, options, warnings) {
116
+ const dimensions = resolveSummaryDimensions(options.dimensions, files.layout);
117
+ const statuses = [];
118
+ const seenDimensions = new Set();
119
+ const summariesByDimension = new Map();
120
+ const allSummaries = [];
121
+ let totalPending = 0;
122
+ const loadDimension = (dimId) => {
123
+ const cached = summariesByDimension.get(dimId);
124
+ if (cached)
125
+ return cached;
126
+ const list = files.listSummaries(dimId);
127
+ warnings.push(...files.warnings);
128
+ const map = new Map(list.map(item => [item.id, item]));
129
+ summariesByDimension.set(dimId, map);
130
+ return map;
131
+ };
132
+ for (const dimension of dimensions) {
133
+ seenDimensions.add(dimension.id);
134
+ if (dimension.id !== "session")
135
+ loadDimension("session");
136
+ const existing = loadDimension(dimension.id);
137
+ allSummaries.push(...existing.values());
138
+ const plan = dimension.plan(raws, existing, { force: false, summariesByDimension });
139
+ totalPending += plan.tasks.length;
140
+ let pendingCreate = 0;
141
+ let pendingIncremental = 0;
142
+ let pendingRebuild = 0;
143
+ for (const task of plan.tasks) {
144
+ if (task.mode === "create")
145
+ pendingCreate++;
146
+ else if (task.mode === "incremental")
147
+ pendingIncremental++;
148
+ else
149
+ pendingRebuild++;
150
+ }
151
+ statuses.push({
152
+ dimension: dimension.id,
153
+ title: dimension.title,
154
+ description: dimension.description,
155
+ total: plan.skipped + plan.tasks.length,
156
+ ready: plan.skipped,
157
+ pendingCreate,
158
+ pendingIncremental,
159
+ pendingRebuild,
160
+ });
161
+ }
162
+ for (const dim of files.listDimensions()) {
163
+ if (seenDimensions.has(dim))
164
+ continue;
165
+ allSummaries.push(...loadDimension(dim).values());
166
+ }
167
+ return { statuses, totalPending, allSummaries };
168
+ }
169
+ /** Read-only inspection of raw archives vs derived summaries across requested dimensions. */
170
+ export function inspectWorkspaceSummaries(root, options = {}) {
171
+ const files = workspaceHistoryFiles(root);
172
+ const raws = files.listRaw();
173
+ const warnings = [...files.warnings];
174
+ const flatNotice = files.migrationNotice();
175
+ if (flatNotice)
176
+ warnings.push(flatNotice);
177
+ const { statuses, totalPending, allSummaries } = inspectDimensions(files, raws, options, warnings);
178
+ const reminder = evaluateSummaryReminder(raws, allSummaries, totalPending, options);
179
+ return {
180
+ layout: files.layout,
181
+ rawCount: raws.length,
182
+ dimensions: statuses,
183
+ warnings: [...new Set(warnings)],
184
+ ...(reminder ? { reminder } : {}),
185
+ };
186
+ }
187
+ /**
188
+ * Trigger-agnostic summary execution engine.
189
+ * Reads raw archives once, plans deduplicated incremental/full tasks per dimension,
190
+ * executes LLM calls with bounded concurrency, and persists each artifact atomically.
191
+ */
192
+ export async function runWorkspaceSummaries(options) {
193
+ const startedAt = Date.now();
194
+ const signal = options.signal ?? new AbortController().signal;
195
+ signal.throwIfAborted();
196
+ const concurrency = Math.max(1, Math.min(summaryConcurrency.max, Math.floor(options.concurrency ?? summaryConcurrency.default)));
197
+ const files = workspaceHistoryFiles(options.root);
198
+ const dimensions = resolveSummaryDimensions(options.dimensions, files.layout);
199
+ const warnings = [];
200
+ const loadSummaries = (id) => {
201
+ const items = files.listSummaries(id);
202
+ warnings.push(...files.warnings);
203
+ return new Map(items.map(item => [item.id, item]));
204
+ };
205
+ // Capture each publication baseline before reading the input it will summarize.
206
+ const plannedDimensions = dimensions.map(dimension => ({ dimension, existing: loadSummaries(dimension.id) }));
207
+ const raws = files.listRaw();
208
+ warnings.push(...files.warnings);
209
+ const flatNotice = files.migrationNotice();
210
+ if (flatNotice)
211
+ warnings.push(flatNotice);
212
+ const summariesByDimension = new Map();
213
+ const reports = [];
214
+ for (const { dimension, existing } of plannedDimensions) {
215
+ signal.throwIfAborted();
216
+ if (dimension.id !== "session")
217
+ summariesByDimension.set("session", loadSummaries("session"));
218
+ summariesByDimension.set(dimension.id, existing);
219
+ const plan = dimension.plan(raws, existing, { force: Boolean(options.force), summariesByDimension });
220
+ const report = {
221
+ dimension: dimension.id,
222
+ scanned: dimension.id === "monthly" ? (summariesByDimension.get("session")?.size ?? 0) : raws.length,
223
+ skipped: plan.skipped,
224
+ created: 0,
225
+ incremental: 0,
226
+ rebuilt: 0,
227
+ failed: [],
228
+ };
229
+ if (plan.tasks.length > 0) {
230
+ let nextIndex = 0;
231
+ let completed = 0;
232
+ const total = plan.tasks.length;
233
+ const worker = async () => {
234
+ for (;;) {
235
+ signal.throwIfAborted();
236
+ const index = nextIndex++;
237
+ if (index >= total)
238
+ return;
239
+ const task = plan.tasks[index];
240
+ try {
241
+ const request = dimension.buildRequest(task);
242
+ const output = await options.summarizer(request, signal);
243
+ signal.throwIfAborted();
244
+ const artifact = dimension.finalize(task, output, new Date().toISOString());
245
+ const published = await withSummaryLockRetry(files, dimension.id, () => {
246
+ signal.throwIfAborted();
247
+ const current = files.readSummary(dimension.id, artifact.id);
248
+ if (isDeepStrictEqual(current, existing.get(artifact.id))) {
249
+ files.saveSummary(artifact);
250
+ return artifact;
251
+ }
252
+ if (current)
253
+ existing.set(artifact.id, current);
254
+ else
255
+ existing.delete(artifact.id);
256
+ requireThat(current && isDeepStrictEqual(current.source, artifact.source), "摘要在生成期间已变更,请重新运行摘要。");
257
+ return current;
258
+ }, signal);
259
+ existing.set(artifact.id, published);
260
+ if (published !== artifact)
261
+ report.skipped++;
262
+ else if (task.mode === "create")
263
+ report.created++;
264
+ else if (task.mode === "incremental")
265
+ report.incremental++;
266
+ else
267
+ report.rebuilt++;
268
+ }
269
+ catch (error) {
270
+ if (signal.aborted)
271
+ throw error;
272
+ report.failed.push({ id: task.id, error: error instanceof Error ? error.message : String(error) });
273
+ }
274
+ finally {
275
+ completed++;
276
+ if (!signal.aborted) {
277
+ options.onProgress?.({
278
+ dimension: dimension.id,
279
+ completed,
280
+ total,
281
+ currentId: task.id,
282
+ mode: task.mode,
283
+ });
284
+ }
285
+ }
286
+ }
287
+ };
288
+ const workerCount = Math.min(concurrency, total);
289
+ await Promise.all(Array.from({ length: workerCount }, () => worker()));
290
+ }
291
+ reports.push(report);
292
+ }
293
+ requireThat(!signal.aborted, "历史摘要已取消。");
294
+ return {
295
+ dimensions: reports,
296
+ durationMs: Date.now() - startedAt,
297
+ warnings: [...new Set(warnings)],
298
+ };
299
+ }
@@ -0,0 +1,3 @@
1
+ import type { HistoryHost } from "../../model/history.js";
2
+ import { HistoryFiles } from "../../storage/history-files.js";
3
+ export declare function workspaceHistoryFiles(root: string, host?: HistoryHost): HistoryFiles;
@@ -0,0 +1,6 @@
1
+ import { join } from "node:path";
2
+ import { HistoryFiles } from "../../storage/history-files.js";
3
+ import { readWorkspaceHistoryLayoutSync } from "../workspace/workspace-config.js";
4
+ export function workspaceHistoryFiles(root, host) {
5
+ return new HistoryFiles(join(root, ".pbot/history"), host, readWorkspaceHistoryLayoutSync(root));
6
+ }
@@ -0,0 +1,3 @@
1
+ /** Each host owns its file, including when two hosts activate the same canonical workspace concurrently. */
2
+ export declare function bindWorkspacePlugin(root: string, host: string, binding?: string): void;
3
+ export declare function workspacePluginReleases(root: string): Record<string, string>;
@@ -0,0 +1,78 @@
1
+ import { createHash } from "node:crypto";
2
+ import { mkdirSync, readdirSync, readFileSync } from "node:fs";
3
+ import { homedir } from "node:os";
4
+ import { isAbsolute, join, resolve } from "node:path";
5
+ import { object } from "../../common/json.js";
6
+ import { resourceRoot } from "../../common/paths.js";
7
+ import { requireThat } from "../../common/validation.js";
8
+ import { releaseLine } from "../../common/version.js";
9
+ import { readJsonFile, writeJsonFile } from "../../storage/atomic-json.js";
10
+ function bindingDirectory(root) {
11
+ const key = createHash("sha256").update(root).digest("hex");
12
+ return join(homedir(), ".pbot", "workspaces", key);
13
+ }
14
+ // Full plugins own a local manifest. Thin clients can supply the release stamped into their cached hooks.
15
+ function pluginBinding(value) {
16
+ requireThat(typeof value === "string", "无效的插件安装记录。");
17
+ if (!isAbsolute(value))
18
+ releaseLine(value);
19
+ return value;
20
+ }
21
+ function permissionDenied(error) {
22
+ return ["EACCES", "EPERM", "EROFS"].includes(error.code ?? "");
23
+ }
24
+ /** Each host owns its file, including when two hosts activate the same canonical workspace concurrently. */
25
+ export function bindWorkspacePlugin(root, host, binding = resolve(resourceRoot, "../package.json")) {
26
+ const directory = bindingDirectory(root);
27
+ const file = encodeURIComponent(host) + ".json";
28
+ try {
29
+ if (readJsonFile(directory, file, pluginBinding) === binding)
30
+ return;
31
+ }
32
+ catch (error) {
33
+ if (permissionDenied(error))
34
+ return;
35
+ if (error.code !== "ENOENT")
36
+ throw error;
37
+ }
38
+ try {
39
+ mkdirSync(directory, { recursive: true, mode: 0o700 });
40
+ writeJsonFile(directory, file, binding, pluginBinding);
41
+ }
42
+ catch (error) {
43
+ if (!permissionDenied(error))
44
+ throw error;
45
+ }
46
+ }
47
+ export function workspacePluginReleases(root) {
48
+ const directory = bindingDirectory(root);
49
+ let files;
50
+ try {
51
+ files = readdirSync(directory);
52
+ }
53
+ catch (error) {
54
+ if (error.code === "ENOENT" || permissionDenied(error))
55
+ return {};
56
+ throw error;
57
+ }
58
+ const releases = Object.create(null);
59
+ for (const file of files.filter(name => name.endsWith(".json"))) {
60
+ const host = decodeURIComponent(file.slice(0, -5));
61
+ try {
62
+ const binding = readJsonFile(directory, file, pluginBinding);
63
+ if (!isAbsolute(binding)) {
64
+ releases[host] = binding;
65
+ continue;
66
+ }
67
+ const manifest = JSON.parse(readFileSync(binding, "utf8"));
68
+ requireThat(object(manifest) && typeof manifest.version === "string", "无效的插件安装清单:" + binding);
69
+ releaseLine(manifest.version);
70
+ releases[host] = manifest.version;
71
+ }
72
+ catch (error) {
73
+ if (error.code !== "ENOENT" && !permissionDenied(error))
74
+ throw error;
75
+ }
76
+ }
77
+ return releases;
78
+ }
@@ -1,6 +1,10 @@
1
- import type { ResolvedWorkspaceFeatures, WorkspaceConfiguration, WorkspaceFeatures } from "../../model/workspace-config.js";
1
+ import type { HistoryLayout, ResolvedWorkspaceFeatures, ResolvedWorkspaceHistoryConfig, ResolvedWorkspaceSummaryConfig, WorkspaceConfiguration, WorkspaceFeatures, WorkspaceHistoryConfig, WorkspaceSummaryConfig } from "../../model/workspace-config.js";
2
2
  export declare function workspaceFeatures(configuration?: Pick<WorkspaceConfiguration, "features"> | WorkspaceFeatures): ResolvedWorkspaceFeatures;
3
+ export declare function workspaceSummaryConfig(configuration?: Pick<WorkspaceConfiguration, "summary"> | WorkspaceSummaryConfig): ResolvedWorkspaceSummaryConfig;
4
+ export declare function workspaceHistoryConfig(configuration?: Pick<WorkspaceConfiguration, "history"> | WorkspaceHistoryConfig): ResolvedWorkspaceHistoryConfig;
3
5
  export declare function workspaceConfigPath(root: string): string;
6
+ /** Synchronous read of history.layout for storage and query callers; defaults to "monthly". */
7
+ export declare function readWorkspaceHistoryLayoutSync(root: string): HistoryLayout;
4
8
  /** Read only this workspace's configuration; parent directories never grant activation. */
5
9
  export declare function readWorkspaceConfig(root: string): Promise<WorkspaceConfiguration>;
6
10
  /** Explicit init opts in this workspace while preserving its other configuration fields. */
@@ -1,9 +1,17 @@
1
+ import { readFileSync } from "node:fs";
1
2
  import { mkdir, readFile } from "node:fs/promises";
2
3
  import { dirname, join } from "node:path";
3
4
  import { object } from "../../common/json.js";
4
- import { isAcpBackend } from "../../common/validation.js";
5
+ import { acpPermissionPolicies } from "../../model/acp.js";
6
+ import { historyLayouts, summaryConcurrency } from "../../model/workspace-config.js";
7
+ import { isAcpBackend, isOneOf } from "../../common/validation.js";
5
8
  import { readJsonFile, writeJsonFile } from "../../storage/atomic-json.js";
6
- const featureKeys = ["prompts", "skills", "mcp"];
9
+ const featureKeys = ["prompts", "skills", "mcp", "history"];
10
+ const summaryKeys = ["backend", "model", "thinking", "concurrency"];
11
+ const historyKeys = ["layout"];
12
+ function nonEmptyString(value) {
13
+ return typeof value === "string" && value.trim().length > 0 && !value.includes("\0");
14
+ }
7
15
  function config(value) {
8
16
  if (!object(value) || value.enabled !== undefined && typeof value.enabled !== "boolean") {
9
17
  throw new Error("配置必须是 JSON 对象,enabled 必须是布尔值。");
@@ -11,7 +19,7 @@ function config(value) {
11
19
  if (value.features !== undefined) {
12
20
  if (!object(value.features) ||
13
21
  Object.entries(value.features).some(([key, entry]) => !featureKeys.includes(key) || (entry !== undefined && typeof entry !== "boolean"))) {
14
- throw new Error("features 必须是 JSON 对象,仅支持 prompts、skills、mcp 布尔开关。");
22
+ throw new Error("features 必须是 JSON 对象,仅支持 prompts、skills、mcp、history 布尔开关。");
15
23
  }
16
24
  }
17
25
  if (value.acp !== undefined) {
@@ -26,12 +34,38 @@ function config(value) {
26
34
  (command.args === undefined || (Array.isArray(command.args) && command.args.every(arg => typeof arg === "string" && !arg.includes("\0"))));
27
35
  if (!object(command) || !launch ||
28
36
  (command.env !== undefined && (!object(command.env) || Object.entries(command.env).some(([k, v]) => !k || k.includes("\0") || typeof v !== "string" || v.includes("\0")))) ||
29
- (command.permission !== undefined && !["ask", "allow", "deny"].includes(String(command.permission))) ||
37
+ (command.permission !== undefined && !isOneOf(command.permission, acpPermissionPolicies)) ||
30
38
  Object.keys(command).some(key => !["command", "args", "env", "permission"].includes(key))) {
31
39
  throw new Error("ACP 配置需要 command(内置目标可省略)及可选 args 字符串数组、env 字符串映射、permission(ask、allow 或 deny)。");
32
40
  }
33
41
  }
34
42
  }
43
+ if (value.summary !== undefined) {
44
+ if (!object(value.summary) || Object.keys(value.summary).some(key => !summaryKeys.includes(key))) {
45
+ throw new Error("summary 必须是 JSON 对象,仅支持 backend、model、thinking、concurrency。");
46
+ }
47
+ if (value.summary.backend !== undefined && !isAcpBackend(value.summary.backend)) {
48
+ throw new Error("summary.backend 必须为小写字母、数字和连字符(1–64 字符)。");
49
+ }
50
+ if (value.summary.model !== undefined && !nonEmptyString(value.summary.model)) {
51
+ throw new Error("summary.model 必须是非空字符串。");
52
+ }
53
+ if (value.summary.thinking !== undefined && !nonEmptyString(value.summary.thinking)) {
54
+ throw new Error("summary.thinking 必须是非空字符串。");
55
+ }
56
+ if (value.summary.concurrency !== undefined &&
57
+ (typeof value.summary.concurrency !== "number" || !Number.isInteger(value.summary.concurrency) || value.summary.concurrency < 1 || value.summary.concurrency > summaryConcurrency.max)) {
58
+ throw new Error(`summary.concurrency 必须是 1 到 ${summaryConcurrency.max} 之间的整数。`);
59
+ }
60
+ }
61
+ if (value.history !== undefined) {
62
+ if (!object(value.history) || Object.keys(value.history).some(key => !historyKeys.includes(key))) {
63
+ throw new Error("history 必须是 JSON 对象,仅支持 layout。");
64
+ }
65
+ if (value.history.layout !== undefined && !isOneOf(value.history.layout, historyLayouts)) {
66
+ throw new Error('history.layout 必须是 "monthly" 或 "flat"。');
67
+ }
68
+ }
35
69
  return value;
36
70
  }
37
71
  export function workspaceFeatures(configuration) {
@@ -42,11 +76,43 @@ export function workspaceFeatures(configuration) {
42
76
  prompts: raw?.prompts !== false,
43
77
  skills: raw?.skills !== false,
44
78
  mcp: raw?.mcp !== false,
79
+ history: raw?.history !== false,
80
+ };
81
+ }
82
+ export function workspaceSummaryConfig(configuration) {
83
+ const raw = configuration && "summary" in configuration
84
+ ? configuration.summary
85
+ : configuration;
86
+ return {
87
+ backend: raw?.backend ?? "pi",
88
+ ...(raw?.model ? { model: raw.model } : {}),
89
+ ...(raw?.thinking ? { thinking: raw.thinking } : {}),
90
+ concurrency: raw?.concurrency ?? summaryConcurrency.default,
91
+ };
92
+ }
93
+ export function workspaceHistoryConfig(configuration) {
94
+ const raw = configuration && "history" in configuration
95
+ ? configuration.history
96
+ : configuration;
97
+ return {
98
+ layout: raw?.layout === "flat" ? "flat" : "monthly",
45
99
  };
46
100
  }
47
101
  export function workspaceConfigPath(root) {
48
102
  return join(root, ".pbot", "config.json");
49
103
  }
104
+ /** Synchronous read of history.layout for storage and query callers; defaults to "monthly". */
105
+ export function readWorkspaceHistoryLayoutSync(root) {
106
+ const path = workspaceConfigPath(root);
107
+ try {
108
+ const content = readFileSync(path, "utf8");
109
+ const parsed = config(JSON.parse(content));
110
+ return workspaceHistoryConfig(parsed.history).layout;
111
+ }
112
+ catch {
113
+ return "monthly";
114
+ }
115
+ }
50
116
  /** Read only this workspace's configuration; parent directories never grant activation. */
51
117
  export async function readWorkspaceConfig(root) {
52
118
  const path = workspaceConfigPath(root);
@@ -68,6 +134,8 @@ export async function readWorkspaceConfig(root) {
68
134
  enabled: settings.enabled === true,
69
135
  ...(settings.features ? { features: settings.features } : {}),
70
136
  ...(settings.acp ? { acp: settings.acp } : {}),
137
+ ...(settings.summary ? { summary: settings.summary } : {}),
138
+ ...(settings.history ? { history: settings.history } : {}),
71
139
  };
72
140
  }
73
141
  catch (error) {
@@ -80,16 +148,18 @@ export async function initializeWorkspaceConfig(root) {
80
148
  if (current.error)
81
149
  throw new Error(current.error);
82
150
  const hasExplicitFeatures = featureKeys.every(key => typeof current.features?.[key] === "boolean");
83
- if (current.enabled && hasExplicitFeatures)
151
+ const hasExplicitSummary = typeof current.summary?.backend === "string" && typeof current.summary?.concurrency === "number";
152
+ if (current.enabled && hasExplicitFeatures && hasExplicitSummary)
84
153
  return;
85
154
  const directory = dirname(current.path);
86
155
  await mkdir(directory, { recursive: true });
87
156
  const value = current.present ? readJsonFile(directory, "config.json", config) : {};
88
157
  const features = workspaceFeatures(value.features);
89
- const written = writeJsonFile(directory, "config.json", { ...value, enabled: true, features }, config, !current.present);
158
+ const summary = workspaceSummaryConfig(value.summary);
159
+ const written = writeJsonFile(directory, "config.json", { ...value, enabled: true, features, summary }, config, !current.present);
90
160
  if (!written)
91
161
  await initializeWorkspaceConfig(root);
92
162
  }
93
163
  export function workspaceDisabledMessage(configuration) {
94
- return configuration.error ?? `Personal Bot 未在此工作区启用。请执行 /pbot init 初始化并启用;配置文件:${configuration.path}`;
164
+ return configuration.error ?? `Personal Bot 未在此工作区启用。请在工作区根目录运行 pbot init,也可在 Pi 或 dsh 中执行 /pbot init。配置文件位于 ${configuration.path}`;
95
165
  }
@@ -0,0 +1,2 @@
1
+ export declare function mutationScope(root: string, target: string): "outside" | "inside";
2
+ export declare function authorizeMutation(root: string, path: string, change: unknown, confirm: (value: unknown) => Promise<boolean>, signal: AbortSignal): Promise<void>;
@@ -0,0 +1,17 @@
1
+ import { relative, isAbsolute } from "node:path";
2
+ import { mutationTarget } from "../../common/files.js";
3
+ import { requireThat } from "../../common/validation.js";
4
+ export function mutationScope(root, target) {
5
+ const rel = relative(root, target);
6
+ if (rel === ".." || rel.startsWith("../") || isAbsolute(rel))
7
+ return "outside";
8
+ return "inside";
9
+ }
10
+ export async function authorizeMutation(root, path, change, confirm, signal) {
11
+ signal.throwIfAborted();
12
+ const target = await mutationTarget(path), scope = mutationScope(root, target);
13
+ if (scope === "outside")
14
+ requireThat(await confirm({ path: target, change }), "用户未确认文件修改。");
15
+ signal.throwIfAborted();
16
+ requireThat(await mutationTarget(path) === target, "确认期间文件路径已变化。");
17
+ }
@@ -0,0 +1,14 @@
1
+ import type { ResolvedWorkspaceMcpServer, WorkspaceMcpConfiguration, WorkspaceMcpHttpServer, WorkspaceMcpServer } from "../../model/workspace-mcp.js";
2
+ export declare function isWorkspaceMcpServerName(name: string): boolean;
3
+ export declare function isWorkspaceMcpHttpServer(server: WorkspaceMcpServer): server is WorkspaceMcpHttpServer;
4
+ export declare function validateWorkspaceMcpServer(name: string, value: unknown): WorkspaceMcpServer;
5
+ export declare function workspaceMcpPath(root: string): string;
6
+ export declare function readWorkspaceMcpConfig(root: string): Promise<WorkspaceMcpConfiguration>;
7
+ export declare function expandEnvTemplate(value: string, env: NodeJS.ProcessEnv, context: string): string;
8
+ export declare function resolveWorkspaceMcpServer(root: string, name: string, server: WorkspaceMcpServer, env?: NodeJS.ProcessEnv): ResolvedWorkspaceMcpServer;
9
+ export declare function resolveWorkspaceMcpServers(root: string, configuration: WorkspaceMcpConfiguration, env?: NodeJS.ProcessEnv): ResolvedWorkspaceMcpServer[];
10
+ export declare function upsertWorkspaceMcpServer(root: string, name: string, server: WorkspaceMcpServer): Promise<WorkspaceMcpConfiguration>;
11
+ export declare function removeWorkspaceMcpServer(root: string, name: string): Promise<{
12
+ removed: boolean;
13
+ configuration: WorkspaceMcpConfiguration;
14
+ }>;