personal-bot 0.3.1 → 0.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (436) hide show
  1. package/.claude-plugin/marketplace.json +2 -2
  2. package/.claude-plugin/plugin.json +2 -1
  3. package/DISCLAIMER.md +17 -0
  4. package/LICENSE +21 -0
  5. package/README.md +15 -5
  6. package/README.zh-CN.md +15 -5
  7. package/bin/pbot-pi-acp.mjs +27 -11
  8. package/bin/pbot.mjs +22 -2
  9. package/docs/README.md +3 -1
  10. package/docs/architecture/design.md +37 -24
  11. package/docs/architecture/extensibility.md +27 -19
  12. package/docs/architecture/model-context.md +4 -3
  13. package/docs/architecture/principles.md +5 -4
  14. package/docs/guides/capabilities.md +4 -4
  15. package/docs/guides/cross-harness-workers.md +3 -1
  16. package/docs/guides/history.md +73 -16
  17. package/docs/guides/workspace-configuration.md +35 -6
  18. package/docs/hosts/antigravity.md +2 -0
  19. package/docs/hosts/claude-code.md +1 -1
  20. package/docs/hosts/codex-qoder.md +63 -0
  21. package/docs/hosts/dsh.md +1 -1
  22. package/docs/hosts/pi.md +1 -1
  23. package/docs/maintainers/architecture-governance.md +78 -0
  24. package/hooks/hooks.json +3 -0
  25. package/lib/antigravity-plugin/DISCLAIMER.md +17 -0
  26. package/lib/antigravity-plugin/LICENSE +21 -0
  27. package/lib/antigravity-plugin/bin/pbot-pi-acp.mjs +36 -0
  28. package/lib/antigravity-plugin/hooks.json +7 -0
  29. package/lib/antigravity-plugin/lib/claude.js +2 -2
  30. package/lib/antigravity-plugin/lib/common/files.d.ts +2 -0
  31. package/lib/antigravity-plugin/lib/common/files.js +44 -0
  32. package/lib/antigravity-plugin/lib/common/validation.d.ts +4 -0
  33. package/lib/antigravity-plugin/lib/common/validation.js +8 -0
  34. package/lib/{extension/acp-member.d.ts → antigravity-plugin/lib/extension/acp/member.d.ts} +5 -5
  35. package/lib/{extension/acp-member.js → antigravity-plugin/lib/extension/acp/member.js} +6 -6
  36. package/lib/antigravity-plugin/lib/extension/acp-worker.js +222 -51
  37. package/lib/antigravity-plugin/lib/extension/hosts/dsh/acp-entry.d.ts +1 -0
  38. package/lib/antigravity-plugin/lib/extension/hosts/dsh/acp-entry.js +22 -0
  39. package/lib/{extension → antigravity-plugin/lib/extension/hosts}/dsh/acp-member.js +11 -25
  40. package/lib/{extension → antigravity-plugin/lib/extension/hosts}/dsh/files.js +3 -3
  41. package/lib/antigravity-plugin/lib/extension/hosts/pi/acp-member.d.ts +3 -0
  42. package/lib/antigravity-plugin/lib/extension/hosts/pi/acp-member.js +100 -0
  43. package/lib/antigravity-plugin/lib/extension/hosts/plugin-runtime.d.ts +12 -0
  44. package/lib/antigravity-plugin/lib/extension/hosts/plugin-runtime.js +101 -0
  45. package/lib/antigravity-plugin/lib/extension/hosts/workspace-mcp.d.ts +6 -0
  46. package/lib/antigravity-plugin/lib/extension/hosts/workspace-mcp.js +21 -0
  47. package/lib/antigravity-plugin/lib/extension/mcp.js +2705 -1348
  48. package/lib/antigravity-plugin/lib/extension/workspace-cli.js +20127 -0
  49. package/lib/antigravity-plugin/lib/integrations/agent-resources.d.ts +1 -0
  50. package/lib/antigravity-plugin/lib/integrations/agent-resources.js +6 -2
  51. package/lib/antigravity-plugin/lib/integrations/hosts/antigravity/adapter.d.ts +6 -0
  52. package/lib/antigravity-plugin/lib/integrations/hosts/antigravity/adapter.js +171 -0
  53. package/lib/antigravity-plugin/lib/integrations/hosts/{claude.d.ts → claude/adapter.d.ts} +1 -1
  54. package/lib/antigravity-plugin/lib/integrations/hosts/claude/adapter.js +36 -0
  55. package/lib/antigravity-plugin/lib/integrations/hosts/codex/adapter.d.ts +2 -0
  56. package/lib/antigravity-plugin/lib/integrations/hosts/codex/adapter.js +14 -0
  57. package/lib/{integrations → antigravity-plugin/lib/integrations/hosts}/dsh/mcp.d.ts +1 -1
  58. package/lib/{integrations → antigravity-plugin/lib/integrations/hosts}/dsh/resources.d.ts +1 -1
  59. package/lib/{integrations → antigravity-plugin/lib/integrations/hosts}/dsh/resources.js +4 -4
  60. package/lib/{integrations → antigravity-plugin/lib/integrations/hosts}/dsh/skills.js +1 -1
  61. package/lib/antigravity-plugin/lib/integrations/hosts/pi/agent-tools.d.ts +3 -0
  62. package/lib/antigravity-plugin/lib/integrations/hosts/pi/agent-tools.js +32 -0
  63. package/lib/antigravity-plugin/lib/integrations/hosts/pi/mcp.d.ts +4 -0
  64. package/lib/antigravity-plugin/lib/integrations/hosts/pi/mcp.js +23 -0
  65. package/lib/antigravity-plugin/lib/integrations/hosts/{registry.d.ts → plugin-registry.d.ts} +1 -0
  66. package/lib/{integrations/hosts/registry.js → antigravity-plugin/lib/integrations/hosts/plugin-registry.js} +10 -3
  67. package/lib/antigravity-plugin/lib/integrations/hosts/prompt-hooks.d.ts +76 -0
  68. package/lib/antigravity-plugin/lib/integrations/hosts/prompt-hooks.js +76 -0
  69. package/lib/antigravity-plugin/lib/integrations/hosts/qoder/adapter.d.ts +2 -0
  70. package/lib/antigravity-plugin/lib/integrations/hosts/qoder/adapter.js +16 -0
  71. package/lib/antigravity-plugin/lib/model/acp.d.ts +7 -3
  72. package/lib/antigravity-plugin/lib/model/acp.js +8 -0
  73. package/lib/antigravity-plugin/lib/model/agent.d.ts +121 -0
  74. package/lib/antigravity-plugin/lib/model/agent.js +4 -0
  75. package/lib/antigravity-plugin/lib/model/history.d.ts +179 -0
  76. package/lib/antigravity-plugin/lib/model/history.js +4 -0
  77. package/lib/antigravity-plugin/lib/model/plugin-host.d.ts +31 -0
  78. package/lib/antigravity-plugin/lib/model/workspace-config.d.ts +28 -7
  79. package/lib/antigravity-plugin/lib/model/workspace-config.js +2 -1
  80. package/lib/antigravity-plugin/lib/plugin.d.ts +2 -1
  81. package/lib/antigravity-plugin/lib/plugin.js +4 -4
  82. package/lib/antigravity-plugin/lib/services/history/history-capture.d.ts +4 -0
  83. package/lib/antigravity-plugin/lib/services/history/history-capture.js +98 -0
  84. package/lib/antigravity-plugin/lib/services/history/history-index.d.ts +17 -0
  85. package/lib/antigravity-plugin/lib/services/history/history-index.js +112 -0
  86. package/lib/antigravity-plugin/lib/services/history/summary-dimensions/monthly.d.ts +7 -0
  87. package/lib/antigravity-plugin/lib/services/history/summary-dimensions/monthly.js +121 -0
  88. package/lib/antigravity-plugin/lib/services/history/summary-dimensions/session.d.ts +7 -0
  89. package/lib/antigravity-plugin/lib/services/history/summary-dimensions/session.js +124 -0
  90. package/lib/antigravity-plugin/lib/services/history/summary-registry.d.ts +7 -0
  91. package/lib/antigravity-plugin/lib/services/history/summary-registry.js +35 -0
  92. package/lib/antigravity-plugin/lib/services/history/summary-runner.d.ts +34 -0
  93. package/lib/antigravity-plugin/lib/services/history/summary-runner.js +299 -0
  94. package/lib/antigravity-plugin/lib/services/history/workspace-history.d.ts +3 -0
  95. package/lib/antigravity-plugin/lib/services/history/workspace-history.js +6 -0
  96. package/lib/antigravity-plugin/lib/services/workspace/plugin-releases.d.ts +3 -0
  97. package/lib/antigravity-plugin/lib/services/workspace/plugin-releases.js +78 -0
  98. package/lib/antigravity-plugin/lib/services/workspace/workspace-config.d.ts +5 -1
  99. package/lib/antigravity-plugin/lib/services/workspace/workspace-config.js +77 -7
  100. package/lib/antigravity-plugin/lib/services/workspace/workspace-files.d.ts +2 -0
  101. package/lib/antigravity-plugin/lib/services/workspace/workspace-files.js +17 -0
  102. package/lib/antigravity-plugin/lib/services/workspace/workspace-mcp.d.ts +14 -0
  103. package/lib/antigravity-plugin/lib/services/workspace/workspace-mcp.js +193 -0
  104. package/lib/antigravity-plugin/lib/services/workspace/workspace-skills.d.ts +1 -0
  105. package/lib/antigravity-plugin/lib/services/workspace/workspace-skills.js +4 -2
  106. package/lib/antigravity-plugin/lib/storage/acp-files.d.ts +11 -0
  107. package/lib/antigravity-plugin/lib/storage/acp-files.js +75 -0
  108. package/lib/antigravity-plugin/lib/storage/agent-files.d.ts +31 -0
  109. package/lib/antigravity-plugin/lib/storage/agent-files.js +159 -0
  110. package/lib/antigravity-plugin/lib/storage/atomic-json.d.ts +3 -1
  111. package/lib/antigravity-plugin/lib/storage/atomic-json.js +43 -3
  112. package/lib/antigravity-plugin/lib/storage/file-access.d.ts +2 -0
  113. package/lib/antigravity-plugin/lib/storage/file-access.js +26 -0
  114. package/lib/antigravity-plugin/lib/storage/history-files.d.ts +55 -0
  115. package/lib/antigravity-plugin/lib/storage/history-files.js +473 -0
  116. package/lib/antigravity-plugin/lib/storage/history-format.d.ts +5 -0
  117. package/lib/antigravity-plugin/lib/storage/history-format.js +60 -0
  118. package/lib/antigravity-plugin/package.json +1 -1
  119. package/lib/antigravity-plugin/plugin.json +1 -1
  120. package/lib/antigravity-plugin/resources/prompts/history-monthly-summary.md +13 -0
  121. package/lib/antigravity-plugin/resources/prompts/history-summary.md +13 -0
  122. package/lib/antigravity-plugin/resources/prompts/plugin-coordinator.md +1 -0
  123. package/lib/antigravity-plugin/resources/skills/.claude-plugin/plugin.json +4 -0
  124. package/lib/antigravity-plugin/resources/skills/project-maintenance/SKILL.md +35 -0
  125. package/lib/antigravity-plugin/resources/skills/provider-connections/SKILL.md +52 -0
  126. package/lib/antigravity-plugin/skills/pbot/SKILL.md +11 -1
  127. package/lib/antigravity-plugin/skills/provider-connections/SKILL.md +22 -12
  128. package/lib/claude.js +2 -2
  129. package/lib/client.js +42 -60
  130. package/lib/codex-marketplace/.agents/plugins/marketplace.json +17 -0
  131. package/lib/codex-marketplace/plugins/personal-bot/.codex-plugin/plugin.json +7 -0
  132. package/lib/codex-marketplace/plugins/personal-bot/.mcp.json +17 -0
  133. package/lib/codex-marketplace/plugins/personal-bot/DISCLAIMER.md +17 -0
  134. package/lib/codex-marketplace/plugins/personal-bot/LICENSE +21 -0
  135. package/lib/codex-marketplace/plugins/personal-bot/hooks/hooks.json +37 -0
  136. package/lib/codex-marketplace/plugins/personal-bot/skills/pbot/SKILL.md +9 -0
  137. package/lib/codex-marketplace/plugins/personal-bot/skills/pbot/agents/openai.yaml +2 -0
  138. package/lib/common/validation.d.ts +4 -0
  139. package/lib/common/validation.js +8 -0
  140. package/lib/dsh.js +6 -6
  141. package/lib/extension/acp/member.d.ts +18 -0
  142. package/lib/extension/acp/member.js +44 -0
  143. package/lib/extension/acp/worker.js +384 -0
  144. package/lib/extension/acp-worker.js +222 -51
  145. package/lib/extension/history/command.d.ts +37 -0
  146. package/lib/extension/history/command.js +57 -0
  147. package/lib/extension/hosts/dsh/acp-entry.d.ts +1 -0
  148. package/lib/extension/hosts/dsh/acp-entry.js +22 -0
  149. package/lib/extension/hosts/dsh/acp-member.d.ts +4 -0
  150. package/lib/extension/hosts/dsh/acp-member.js +58 -0
  151. package/lib/extension/{dsh → hosts/dsh}/command.d.ts +1 -2
  152. package/lib/extension/{dsh → hosts/dsh}/command.js +9 -11
  153. package/lib/extension/hosts/dsh/files.d.ts +5 -0
  154. package/lib/extension/hosts/dsh/files.js +67 -0
  155. package/lib/extension/hosts/dsh/history.d.ts +4 -0
  156. package/lib/extension/hosts/dsh/history.js +62 -0
  157. package/lib/extension/{dsh → hosts/dsh}/management.d.ts +1 -1
  158. package/lib/extension/{dsh → hosts/dsh}/management.js +12 -10
  159. package/lib/extension/{dsh → hosts/dsh}/workspace.d.ts +3 -9
  160. package/lib/extension/{dsh → hosts/dsh}/workspace.js +30 -99
  161. package/lib/extension/hosts/pi/acp-member.d.ts +3 -0
  162. package/lib/extension/hosts/pi/acp-member.js +100 -0
  163. package/lib/extension/hosts/plugin-runtime.d.ts +12 -0
  164. package/lib/extension/hosts/plugin-runtime.js +101 -0
  165. package/lib/extension/hosts/workspace-mcp.d.ts +6 -0
  166. package/lib/extension/hosts/workspace-mcp.js +21 -0
  167. package/lib/extension/{mcp-bridge.d.ts → mcp/bridge.d.ts} +7 -9
  168. package/lib/extension/{mcp-bridge.js → mcp/bridge.js} +70 -88
  169. package/lib/extension/{mcp-workers.d.ts → mcp/tool-contract.d.ts} +129 -374
  170. package/lib/extension/mcp/tool-contract.js +441 -0
  171. package/lib/extension/mcp/workers.d.ts +487 -0
  172. package/lib/extension/mcp/workers.js +598 -0
  173. package/lib/extension/mcp.js +2705 -1348
  174. package/lib/extension/{setup-cli.js → setup/cli.js} +12 -9
  175. package/lib/extension/workspace-cli.js +20127 -0
  176. package/lib/integrations/acp/agents.d.ts +2 -3
  177. package/lib/integrations/acp/connection.d.ts +11 -10
  178. package/lib/integrations/acp/connection.js +6 -0
  179. package/lib/integrations/acp/harnesses/claude.js +1 -1
  180. package/lib/integrations/acp/harnesses/dsh.js +1 -1
  181. package/lib/integrations/acp/harnesses/presets.js +8 -0
  182. package/lib/integrations/acp/history-summary.d.ts +17 -0
  183. package/lib/integrations/acp/history-summary.js +101 -0
  184. package/lib/integrations/acp/launch.d.ts +2 -2
  185. package/lib/integrations/agent-resources.d.ts +1 -0
  186. package/lib/integrations/agent-resources.js +6 -2
  187. package/lib/integrations/hosts/antigravity/adapter.d.ts +6 -0
  188. package/lib/integrations/hosts/antigravity/adapter.js +171 -0
  189. package/lib/integrations/hosts/{claude.d.ts → claude/adapter.d.ts} +1 -1
  190. package/lib/integrations/hosts/claude/adapter.js +36 -0
  191. package/lib/integrations/hosts/codex/adapter.d.ts +2 -0
  192. package/lib/integrations/hosts/codex/adapter.js +14 -0
  193. package/lib/integrations/hosts/dsh/mcp.d.ts +4 -0
  194. package/lib/integrations/hosts/dsh/mcp.js +28 -0
  195. package/lib/integrations/hosts/dsh/messages.d.ts +36 -0
  196. package/lib/integrations/hosts/dsh/messages.js +11 -0
  197. package/lib/integrations/hosts/dsh/resources.d.ts +6 -0
  198. package/lib/integrations/hosts/dsh/resources.js +47 -0
  199. package/lib/integrations/hosts/dsh/root-agents.d.ts +4 -0
  200. package/lib/integrations/hosts/dsh/root-agents.js +3 -0
  201. package/lib/integrations/{dsh → hosts/dsh}/schema.js +1 -1
  202. package/lib/integrations/hosts/dsh/skills.d.ts +8 -0
  203. package/lib/integrations/hosts/dsh/skills.js +31 -0
  204. package/lib/integrations/hosts/pi/agent-tools.d.ts +3 -0
  205. package/lib/integrations/hosts/pi/agent-tools.js +32 -0
  206. package/lib/integrations/hosts/pi/mcp.d.ts +4 -0
  207. package/lib/integrations/hosts/pi/mcp.js +23 -0
  208. package/lib/integrations/hosts/{registry.d.ts → plugin-registry.d.ts} +1 -0
  209. package/lib/{antigravity-plugin/lib/integrations/hosts/registry.js → integrations/hosts/plugin-registry.js} +10 -3
  210. package/lib/integrations/hosts/prompt-hooks.d.ts +76 -0
  211. package/lib/integrations/hosts/prompt-hooks.js +76 -0
  212. package/lib/integrations/hosts/qoder/adapter.d.ts +2 -0
  213. package/lib/integrations/hosts/qoder/adapter.js +16 -0
  214. package/lib/integrations/installation/pi-setup.js +1 -1
  215. package/lib/model/acp.d.ts +7 -3
  216. package/lib/model/acp.js +8 -0
  217. package/lib/model/agent.d.ts +18 -4
  218. package/lib/model/agent.js +4 -1
  219. package/lib/model/history.d.ts +143 -34
  220. package/lib/model/history.js +4 -1
  221. package/lib/model/installation.js +1 -0
  222. package/lib/model/plugin-host.d.ts +31 -0
  223. package/lib/model/workspace-config.d.ts +28 -7
  224. package/lib/model/workspace-config.js +2 -1
  225. package/lib/plugin.d.ts +2 -1
  226. package/lib/plugin.js +4 -4
  227. package/lib/qoder-plugin/.mcp.json +17 -0
  228. package/lib/qoder-plugin/.qoder-plugin/plugin.json +7 -0
  229. package/lib/qoder-plugin/DISCLAIMER.md +17 -0
  230. package/lib/qoder-plugin/LICENSE +21 -0
  231. package/lib/qoder-plugin/hooks/hooks.json +37 -0
  232. package/lib/qoder-plugin/skills/pbot/SKILL.md +9 -0
  233. package/lib/services/agents/agent-run.d.ts +1 -1
  234. package/lib/services/agents/agent-service.d.ts +15 -45
  235. package/lib/services/agents/agent-service.js +22 -3
  236. package/lib/services/history/history-capture.d.ts +4 -0
  237. package/lib/services/history/history-capture.js +98 -0
  238. package/lib/services/history/history-index.d.ts +16 -7
  239. package/lib/services/history/history-index.js +48 -70
  240. package/lib/services/history/history-migrate.d.ts +12 -0
  241. package/lib/services/history/history-migrate.js +54 -0
  242. package/lib/services/history/history-query.d.ts +51 -0
  243. package/lib/services/history/history-query.js +352 -0
  244. package/lib/services/history/summary-command.d.ts +20 -0
  245. package/lib/services/history/summary-command.js +69 -0
  246. package/lib/services/history/summary-dimensions/monthly.d.ts +7 -0
  247. package/lib/services/history/summary-dimensions/monthly.js +121 -0
  248. package/lib/services/history/summary-dimensions/session.d.ts +7 -0
  249. package/lib/services/history/summary-dimensions/session.js +124 -0
  250. package/lib/services/history/summary-registry.d.ts +7 -0
  251. package/lib/services/history/summary-registry.js +35 -0
  252. package/lib/services/history/summary-runner.d.ts +34 -0
  253. package/lib/services/history/summary-runner.js +299 -0
  254. package/lib/services/history/workspace-history.d.ts +3 -0
  255. package/lib/services/history/workspace-history.js +6 -0
  256. package/lib/services/workspace/plugin-releases.d.ts +3 -0
  257. package/lib/services/workspace/plugin-releases.js +78 -0
  258. package/lib/services/workspace/workspace-config.d.ts +5 -1
  259. package/lib/services/workspace/workspace-config.js +77 -7
  260. package/lib/services/workspace/workspace-mcp.js +22 -29
  261. package/lib/services/workspace/workspace-skills.d.ts +1 -0
  262. package/lib/services/workspace/workspace-skills.js +4 -2
  263. package/lib/storage/acp-files.js +7 -12
  264. package/lib/storage/agent-files.js +6 -5
  265. package/lib/storage/atomic-json.d.ts +3 -1
  266. package/lib/storage/atomic-json.js +43 -3
  267. package/lib/storage/history-files.d.ts +46 -9
  268. package/lib/storage/history-files.js +382 -250
  269. package/lib/storage/history-format.d.ts +3 -13
  270. package/lib/storage/history-format.js +26 -52
  271. package/lib/tools/history/actions.d.ts +3 -68
  272. package/lib/tools/history/actions.js +7 -5
  273. package/lib/tools/history/contract.d.ts +16 -17
  274. package/lib/tools/history/contract.js +63 -22
  275. package/lib/tools/history/dsh-tool.d.ts +1 -2
  276. package/lib/tools/history/dsh-tool.js +11 -5
  277. package/lib/ui/dsh/elements.d.ts +2 -5
  278. package/lib/ui/dsh/elements.js +3 -16
  279. package/lib/ui/dsh/management.js +26 -13
  280. package/lib/ui/dsh/styles.d.ts +1 -1
  281. package/lib/ui/dsh/styles.js +5 -33
  282. package/package.json +4 -1
  283. package/resources/antigravity/skills/pbot/SKILL.md +11 -1
  284. package/resources/claude/skills/pbot/SKILL.md +11 -1
  285. package/resources/plugin/skills/pbot/SKILL.md +9 -0
  286. package/resources/prompts/history-coordinator.md +2 -1
  287. package/resources/prompts/history-monthly-summary.md +13 -0
  288. package/resources/prompts/history-summary.md +10 -4
  289. package/resources/prompts/plugin-coordinator.md +1 -0
  290. package/resources/skills/provider-connections/SKILL.md +22 -12
  291. package/scripts/README.md +3 -2
  292. package/src/claude.ts +2 -2
  293. package/src/common/validation.ts +10 -0
  294. package/src/dsh.ts +6 -6
  295. package/src/extension/{acp-member.ts → acp/member.ts} +7 -7
  296. package/src/extension/{acp-worker.ts → acp/worker.ts} +131 -17
  297. package/src/extension/history/command.ts +68 -0
  298. package/src/extension/hosts/dsh/acp-entry.ts +21 -0
  299. package/src/extension/{dsh → hosts/dsh}/acp-member.ts +12 -23
  300. package/src/extension/{dsh → hosts/dsh}/command.ts +10 -12
  301. package/src/extension/{dsh → hosts/dsh}/files.ts +3 -3
  302. package/src/extension/hosts/dsh/history.ts +67 -0
  303. package/src/extension/{dsh → hosts/dsh}/management.ts +11 -9
  304. package/src/extension/{dsh → hosts/dsh}/workspace.ts +31 -76
  305. package/src/extension/{pi-acp-member.ts → hosts/pi/acp-member.ts} +12 -18
  306. package/src/extension/{command.ts → hosts/pi/command.ts} +44 -11
  307. package/src/extension/{events.ts → hosts/pi/events.ts} +8 -4
  308. package/src/extension/hosts/pi/history.ts +45 -0
  309. package/src/extension/{lifecycle.ts → hosts/pi/lifecycle.ts} +9 -12
  310. package/src/extension/hosts/plugin-runtime.ts +96 -0
  311. package/src/extension/hosts/workspace-mcp.ts +25 -0
  312. package/src/extension/{mcp-bridge.ts → mcp/bridge.ts} +85 -85
  313. package/src/extension/mcp/tool-contract.ts +462 -0
  314. package/src/extension/{mcp-workers.ts → mcp/workers.ts} +151 -448
  315. package/src/extension/{setup-cli.ts → setup/cli.ts} +14 -11
  316. package/src/extension/setup/workspace-cli.ts +159 -0
  317. package/src/integrations/acp/agents.ts +2 -3
  318. package/src/integrations/acp/connection.ts +6 -0
  319. package/src/integrations/acp/harnesses/claude.ts +1 -1
  320. package/src/integrations/acp/harnesses/dsh.ts +1 -1
  321. package/src/integrations/acp/harnesses/presets.ts +8 -0
  322. package/src/integrations/acp/history-summary.ts +109 -0
  323. package/src/integrations/agent-resources.ts +7 -1
  324. package/src/integrations/hosts/antigravity/adapter.ts +161 -0
  325. package/src/integrations/hosts/claude/adapter.ts +39 -0
  326. package/src/integrations/hosts/codex/adapter.ts +16 -0
  327. package/src/integrations/{dsh → hosts/dsh}/mcp.ts +1 -1
  328. package/src/integrations/{dsh → hosts/dsh}/resources.ts +5 -5
  329. package/src/integrations/{dsh → hosts/dsh}/schema.ts +1 -1
  330. package/src/integrations/{dsh → hosts/dsh}/session.ts +2 -2
  331. package/src/integrations/{dsh → hosts/dsh}/skills.ts +1 -1
  332. package/src/integrations/{pi → hosts/pi}/mcp.ts +1 -1
  333. package/src/integrations/{pi → hosts/pi}/skills.ts +1 -1
  334. package/src/integrations/hosts/{registry.ts → plugin-registry.ts} +11 -3
  335. package/src/integrations/hosts/prompt-hooks.ts +72 -0
  336. package/src/integrations/hosts/qoder/adapter.ts +19 -0
  337. package/src/integrations/installation/cli-update.ts +116 -0
  338. package/src/integrations/installation/pi-bridge.ts +1 -1
  339. package/src/integrations/installation/pi-setup.ts +2 -2
  340. package/src/integrations/installation/processes.ts +1 -1
  341. package/src/mcp.ts +1 -1
  342. package/src/model/acp.ts +11 -3
  343. package/src/model/agent.ts +20 -4
  344. package/src/model/history.ts +156 -26
  345. package/src/model/installation.ts +41 -0
  346. package/src/model/plugin-host.ts +30 -2
  347. package/src/model/workspace-config.ts +31 -7
  348. package/src/pbot.ts +22 -50
  349. package/src/plugin.ts +4 -4
  350. package/src/services/agents/agent-service.ts +29 -17
  351. package/src/services/history/history-capture.ts +91 -0
  352. package/src/services/history/history-index.ts +48 -62
  353. package/src/services/history/history-migrate.ts +62 -0
  354. package/src/services/history/history-query.ts +401 -0
  355. package/src/services/history/summary-command.ts +70 -0
  356. package/src/services/history/summary-dimensions/monthly.ts +139 -0
  357. package/src/services/history/summary-dimensions/session.ts +149 -0
  358. package/src/services/history/summary-registry.ts +43 -0
  359. package/src/services/history/summary-runner.ts +343 -0
  360. package/src/services/history/workspace-history.ts +8 -0
  361. package/src/services/installation/setup-service.ts +2 -41
  362. package/src/services/workspace/plugin-releases.ts +68 -0
  363. package/src/services/workspace/workspace-config.ts +95 -8
  364. package/src/services/workspace/workspace-mcp.ts +23 -28
  365. package/src/services/workspace/workspace-skills.ts +5 -2
  366. package/src/storage/acp-files.ts +7 -12
  367. package/src/storage/agent-files.ts +6 -5
  368. package/src/storage/atomic-json.ts +31 -4
  369. package/src/storage/history-files.ts +416 -189
  370. package/src/storage/history-format.ts +45 -61
  371. package/src/tools/history/actions.ts +8 -6
  372. package/src/tools/history/contract.ts +70 -25
  373. package/src/tools/history/dsh-tool.ts +17 -8
  374. package/src/tools/history/pi-tool.ts +23 -0
  375. package/src/ui/dsh/elements.ts +5 -12
  376. package/src/ui/dsh/management.ts +36 -20
  377. package/src/ui/dsh/styles.ts +5 -33
  378. package/src/ui/{confirmation.ts → pi/confirmation.ts} +1 -1
  379. package/lib/antigravity-plugin/lib/extension/plugin-runtime.d.ts +0 -10
  380. package/lib/antigravity-plugin/lib/extension/plugin-runtime.js +0 -67
  381. package/lib/antigravity-plugin/lib/integrations/hosts/antigravity.d.ts +0 -4
  382. package/lib/antigravity-plugin/lib/integrations/hosts/antigravity.js +0 -79
  383. package/lib/antigravity-plugin/lib/integrations/hosts/claude.js +0 -60
  384. package/lib/extension/dsh/history.d.ts +0 -15
  385. package/lib/extension/dsh/history.js +0 -87
  386. package/lib/extension/mcp-workers.js +0 -882
  387. package/lib/extension/plugin-runtime.d.ts +0 -10
  388. package/lib/extension/plugin-runtime.js +0 -67
  389. package/lib/integrations/dsh/history-summary.d.ts +0 -11
  390. package/lib/integrations/dsh/history-summary.js +0 -36
  391. package/lib/integrations/dsh/history.d.ts +0 -16
  392. package/lib/integrations/dsh/history.js +0 -167
  393. package/lib/integrations/history-summary.d.ts +0 -4
  394. package/lib/integrations/history-summary.js +0 -32
  395. package/lib/integrations/hosts/antigravity.d.ts +0 -4
  396. package/lib/integrations/hosts/antigravity.js +0 -79
  397. package/lib/integrations/hosts/claude.js +0 -60
  398. package/lib/services/history/history-service.d.ts +0 -106
  399. package/lib/services/history/history-service.js +0 -242
  400. package/lib/storage/acp-history.d.ts +0 -10
  401. package/lib/storage/acp-history.js +0 -57
  402. package/lib/ui/presentation.d.ts +0 -3
  403. package/lib/ui/presentation.js +0 -12
  404. package/src/extension/dsh/history.ts +0 -74
  405. package/src/extension/history.ts +0 -26
  406. package/src/extension/plugin-runtime.ts +0 -63
  407. package/src/integrations/dsh/history-summary.ts +0 -39
  408. package/src/integrations/dsh/history.ts +0 -84
  409. package/src/integrations/history-summary.ts +0 -30
  410. package/src/integrations/hosts/antigravity.ts +0 -83
  411. package/src/integrations/hosts/claude.ts +0 -62
  412. package/src/integrations/pi/history.ts +0 -99
  413. package/src/services/history/history-service.ts +0 -195
  414. package/src/storage/acp-history.ts +0 -49
  415. package/src/tools/access.ts +0 -7
  416. package/src/tools/history/tool.ts +0 -19
  417. package/src/tools/register.ts +0 -22
  418. package/src/ui/presentation.ts +0 -12
  419. /package/lib/{extension → antigravity-plugin/lib/extension/hosts}/dsh/acp-member.d.ts +0 -0
  420. /package/lib/{extension → antigravity-plugin/lib/extension/hosts}/dsh/files.d.ts +0 -0
  421. /package/lib/{integrations → antigravity-plugin/lib/integrations/hosts}/dsh/mcp.js +0 -0
  422. /package/lib/{integrations → antigravity-plugin/lib/integrations/hosts}/dsh/messages.d.ts +0 -0
  423. /package/lib/{integrations → antigravity-plugin/lib/integrations/hosts}/dsh/messages.js +0 -0
  424. /package/lib/{integrations → antigravity-plugin/lib/integrations/hosts}/dsh/root-agents.d.ts +0 -0
  425. /package/lib/{integrations → antigravity-plugin/lib/integrations/hosts}/dsh/root-agents.js +0 -0
  426. /package/lib/{integrations → antigravity-plugin/lib/integrations/hosts}/dsh/skills.d.ts +0 -0
  427. /package/lib/extension/{acp-worker.d.ts → acp/worker.d.ts} +0 -0
  428. /package/lib/extension/{setup-guard.js → setup/guard.js} +0 -0
  429. /package/lib/integrations/acp/{claude.d.ts → claude-settings.d.ts} +0 -0
  430. /package/lib/integrations/acp/{claude.js → claude-settings.js} +0 -0
  431. /package/lib/integrations/{dsh → hosts/dsh}/schema.d.ts +0 -0
  432. /package/src/extension/{setup-guard.ts → setup/guard.ts} +0 -0
  433. /package/src/integrations/acp/{claude.ts → claude-settings.ts} +0 -0
  434. /package/src/integrations/{dsh → hosts/dsh}/messages.ts +0 -0
  435. /package/src/integrations/{dsh → hosts/dsh}/root-agents.ts +0 -0
  436. /package/src/integrations/{pi → hosts/pi}/agent-tools.ts +0 -0
@@ -1,46 +1,7 @@
1
1
  import { npmName, ordinaryNpm } from "../../common/package-source.js";
2
+ import type { InstalledPackage, PackageChoice, PiInstallation, PluginSpec, SetupOperations, SetupPlan, SetupResult } from "../../model/installation.js";
2
3
 
3
- export interface PluginSpec {
4
- id: string;
5
- label: string;
6
- description: string;
7
- source: string;
8
- defaultSelected: boolean;
9
- }
10
- export interface InstalledPackage {
11
- source: string;
12
- scope: "user" | "project";
13
- name?: string;
14
- version?: string;
15
- installedPath?: string;
16
- filtered: boolean;
17
- entry: unknown;
18
- }
19
- export interface PackageChoice {
20
- plugin: PluginSpec;
21
- required: boolean;
22
- existing: InstalledPackage[];
23
- selected: boolean;
24
- keep: boolean;
25
- target?: string;
26
- error?: string;
27
- }
28
- export interface PiInstallation { command: string; root: string; version: string }
29
- export interface SystemCommand { command: string; args: string[] }
30
- export interface SetupPlan {
31
- workspace: string;
32
- pi?: PiInstallation;
33
- piVersion: string;
34
- tmux?: SystemCommand;
35
- packages: PackageChoice[];
36
- }
37
- export interface SetupResult { name: string; state: "done" | "kept" | "skipped" | "failed"; detail: string }
38
- export interface SetupOperations {
39
- installTmux(command: SystemCommand): Promise<void>;
40
- ensurePi(existing: PiInstallation | undefined, version: string): Promise<PiInstallation>;
41
- installPackage(pi: PiInstallation, workspace: string, choice: PackageChoice): Promise<string>;
42
- verifyKeptPackage(pi: PiInstallation, workspace: string, choice: PackageChoice): Promise<string>;
43
- }
4
+ export type { InstalledPackage, PackageChoice, PiInstallation, PluginSpec, SetupOperations, SetupPlan, SetupResult, SystemCommand } from "../../model/installation.js";
44
5
 
45
6
  export const pbotPackage: PluginSpec = {
46
7
  id: "pbot", label: "Personal Bot", description: "工作区个人助手", source: "npm:personal-bot", defaultSelected: true,
@@ -0,0 +1,68 @@
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
+
11
+ function bindingDirectory(root: string) {
12
+ const key = createHash("sha256").update(root).digest("hex");
13
+ return join(homedir(), ".pbot", "workspaces", key);
14
+ }
15
+
16
+ // Full plugins own a local manifest. Thin clients can supply the release stamped into their cached hooks.
17
+ function pluginBinding(value: unknown): string {
18
+ requireThat(typeof value === "string", "无效的插件安装记录。");
19
+ if (!isAbsolute(value)) releaseLine(value);
20
+ return value;
21
+ }
22
+
23
+ function permissionDenied(error: unknown): boolean {
24
+ return ["EACCES", "EPERM", "EROFS"].includes((error as NodeJS.ErrnoException).code ?? "");
25
+ }
26
+
27
+ /** Each host owns its file, including when two hosts activate the same canonical workspace concurrently. */
28
+ export function bindWorkspacePlugin(root: string, host: string, binding = resolve(resourceRoot, "../package.json")): void {
29
+ const directory = bindingDirectory(root);
30
+ const file = encodeURIComponent(host) + ".json";
31
+ try {
32
+ if (readJsonFile(directory, file, pluginBinding) === binding) return;
33
+ } catch (error) {
34
+ if (permissionDenied(error)) return;
35
+ if ((error as NodeJS.ErrnoException).code !== "ENOENT") throw error;
36
+ }
37
+ try {
38
+ mkdirSync(directory, { recursive: true, mode: 0o700 });
39
+ writeJsonFile(directory, file, binding, pluginBinding);
40
+ } catch (error) {
41
+ if (!permissionDenied(error)) throw error;
42
+ }
43
+ }
44
+
45
+ export function workspacePluginReleases(root: string): Record<string, string> {
46
+ const directory = bindingDirectory(root);
47
+ let files: string[];
48
+ try { files = readdirSync(directory); }
49
+ catch (error) {
50
+ if ((error as NodeJS.ErrnoException).code === "ENOENT" || permissionDenied(error)) return {};
51
+ throw error;
52
+ }
53
+ const releases: Record<string, string> = Object.create(null);
54
+ for (const file of files.filter(name => name.endsWith(".json"))) {
55
+ const host = decodeURIComponent(file.slice(0, -5));
56
+ try {
57
+ const binding = readJsonFile(directory, file, pluginBinding);
58
+ if (!isAbsolute(binding)) { releases[host] = binding; continue; }
59
+ const manifest: unknown = JSON.parse(readFileSync(binding, "utf8"));
60
+ requireThat(object(manifest) && typeof manifest.version === "string", "无效的插件安装清单:" + binding);
61
+ releaseLine(manifest.version);
62
+ releases[host] = manifest.version;
63
+ } catch (error) {
64
+ if ((error as NodeJS.ErrnoException).code !== "ENOENT" && !permissionDenied(error)) throw error;
65
+ }
66
+ }
67
+ return releases;
68
+ }
@@ -1,11 +1,30 @@
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
- import type { ResolvedWorkspaceFeatures, WorkspaceConfig, WorkspaceConfiguration, WorkspaceFeatures } from "../../model/workspace-config.js";
9
+ import type {
10
+ HistoryLayout,
11
+ ResolvedWorkspaceFeatures,
12
+ ResolvedWorkspaceHistoryConfig,
13
+ ResolvedWorkspaceSummaryConfig,
14
+ WorkspaceConfig,
15
+ WorkspaceConfiguration,
16
+ WorkspaceFeatures,
17
+ WorkspaceHistoryConfig,
18
+ WorkspaceSummaryConfig,
19
+ } from "../../model/workspace-config.js";
7
20
 
8
- const featureKeys = ["prompts", "skills", "mcp"] as const;
21
+ const featureKeys = ["prompts", "skills", "mcp", "history"] as const;
22
+ const summaryKeys = ["backend", "model", "thinking", "concurrency"] as const;
23
+ const historyKeys = ["layout"] as const;
24
+
25
+ function nonEmptyString(value: unknown): value is string {
26
+ return typeof value === "string" && value.trim().length > 0 && !value.includes("\0");
27
+ }
9
28
 
10
29
  function config(value: unknown): Record<string, unknown> {
11
30
  if (!object(value) || value.enabled !== undefined && typeof value.enabled !== "boolean") {
@@ -14,7 +33,7 @@ function config(value: unknown): Record<string, unknown> {
14
33
  if (value.features !== undefined) {
15
34
  if (!object(value.features) ||
16
35
  Object.entries(value.features).some(([key, entry]) => !(featureKeys as readonly string[]).includes(key) || (entry !== undefined && typeof entry !== "boolean"))) {
17
- throw new Error("features 必须是 JSON 对象,仅支持 prompts、skills、mcp 布尔开关。");
36
+ throw new Error("features 必须是 JSON 对象,仅支持 prompts、skills、mcp、history 布尔开关。");
18
37
  }
19
38
  }
20
39
  if (value.acp !== undefined) {
@@ -29,12 +48,38 @@ function config(value: unknown): Record<string, unknown> {
29
48
  (command.args === undefined || (Array.isArray(command.args) && command.args.every(arg => typeof arg === "string" && !arg.includes("\0"))));
30
49
  if (!object(command) || !launch ||
31
50
  (command.env !== undefined && (!object(command.env) || Object.entries(command.env).some(([k, v]) => !k || k.includes("\0") || typeof v !== "string" || v.includes("\0")))) ||
32
- (command.permission !== undefined && !["ask", "allow", "deny"].includes(String(command.permission))) ||
51
+ (command.permission !== undefined && !isOneOf(command.permission, acpPermissionPolicies)) ||
33
52
  Object.keys(command).some(key => !["command", "args", "env", "permission"].includes(key))) {
34
53
  throw new Error("ACP 配置需要 command(内置目标可省略)及可选 args 字符串数组、env 字符串映射、permission(ask、allow 或 deny)。");
35
54
  }
36
55
  }
37
56
  }
57
+ if (value.summary !== undefined) {
58
+ if (!object(value.summary) || Object.keys(value.summary).some(key => !(summaryKeys as readonly string[]).includes(key))) {
59
+ throw new Error("summary 必须是 JSON 对象,仅支持 backend、model、thinking、concurrency。");
60
+ }
61
+ if (value.summary.backend !== undefined && !isAcpBackend(value.summary.backend)) {
62
+ throw new Error("summary.backend 必须为小写字母、数字和连字符(1–64 字符)。");
63
+ }
64
+ if (value.summary.model !== undefined && !nonEmptyString(value.summary.model)) {
65
+ throw new Error("summary.model 必须是非空字符串。");
66
+ }
67
+ if (value.summary.thinking !== undefined && !nonEmptyString(value.summary.thinking)) {
68
+ throw new Error("summary.thinking 必须是非空字符串。");
69
+ }
70
+ if (value.summary.concurrency !== undefined &&
71
+ (typeof value.summary.concurrency !== "number" || !Number.isInteger(value.summary.concurrency) || value.summary.concurrency < 1 || value.summary.concurrency > summaryConcurrency.max)) {
72
+ throw new Error(`summary.concurrency 必须是 1 到 ${summaryConcurrency.max} 之间的整数。`);
73
+ }
74
+ }
75
+ if (value.history !== undefined) {
76
+ if (!object(value.history) || Object.keys(value.history).some(key => !(historyKeys as readonly string[]).includes(key))) {
77
+ throw new Error("history 必须是 JSON 对象,仅支持 layout。");
78
+ }
79
+ if (value.history.layout !== undefined && !isOneOf(value.history.layout, historyLayouts)) {
80
+ throw new Error('history.layout 必须是 "monthly" 或 "flat"。');
81
+ }
82
+ }
38
83
  return value;
39
84
  }
40
85
 
@@ -46,6 +91,32 @@ export function workspaceFeatures(configuration?: Pick<WorkspaceConfiguration, "
46
91
  prompts: raw?.prompts !== false,
47
92
  skills: raw?.skills !== false,
48
93
  mcp: raw?.mcp !== false,
94
+ history: raw?.history !== false,
95
+ };
96
+ }
97
+
98
+ export function workspaceSummaryConfig(
99
+ configuration?: Pick<WorkspaceConfiguration, "summary"> | WorkspaceSummaryConfig,
100
+ ): ResolvedWorkspaceSummaryConfig {
101
+ const raw: WorkspaceSummaryConfig | undefined = configuration && "summary" in configuration
102
+ ? configuration.summary
103
+ : configuration as WorkspaceSummaryConfig | undefined;
104
+ return {
105
+ backend: raw?.backend ?? "pi",
106
+ ...(raw?.model ? { model: raw.model } : {}),
107
+ ...(raw?.thinking ? { thinking: raw.thinking } : {}),
108
+ concurrency: raw?.concurrency ?? summaryConcurrency.default,
109
+ };
110
+ }
111
+
112
+ export function workspaceHistoryConfig(
113
+ configuration?: Pick<WorkspaceConfiguration, "history"> | WorkspaceHistoryConfig,
114
+ ): ResolvedWorkspaceHistoryConfig {
115
+ const raw: WorkspaceHistoryConfig | undefined = configuration && "history" in configuration
116
+ ? configuration.history
117
+ : configuration as WorkspaceHistoryConfig | undefined;
118
+ return {
119
+ layout: raw?.layout === "flat" ? "flat" : "monthly",
49
120
  };
50
121
  }
51
122
 
@@ -53,6 +124,18 @@ export function workspaceConfigPath(root: string): string {
53
124
  return join(root, ".pbot", "config.json");
54
125
  }
55
126
 
127
+ /** Synchronous read of history.layout for storage and query callers; defaults to "monthly". */
128
+ export function readWorkspaceHistoryLayoutSync(root: string): HistoryLayout {
129
+ const path = workspaceConfigPath(root);
130
+ try {
131
+ const content = readFileSync(path, "utf8");
132
+ const parsed = config(JSON.parse(content)) as WorkspaceConfig;
133
+ return workspaceHistoryConfig(parsed.history).layout;
134
+ } catch {
135
+ return "monthly";
136
+ }
137
+ }
138
+
56
139
  /** Read only this workspace's configuration; parent directories never grant activation. */
57
140
  export async function readWorkspaceConfig(root: string): Promise<WorkspaceConfiguration> {
58
141
  const path = workspaceConfigPath(root);
@@ -71,6 +154,8 @@ export async function readWorkspaceConfig(root: string): Promise<WorkspaceConfig
71
154
  enabled: settings.enabled === true,
72
155
  ...(settings.features ? { features: settings.features } : {}),
73
156
  ...(settings.acp ? { acp: settings.acp } : {}),
157
+ ...(settings.summary ? { summary: settings.summary } : {}),
158
+ ...(settings.history ? { history: settings.history } : {}),
74
159
  };
75
160
  } catch (error) {
76
161
  return { path, present: true, enabled: false, error: `工作区配置无效 ${path}: ${String(error)}` };
@@ -82,15 +167,17 @@ export async function initializeWorkspaceConfig(root: string): Promise<void> {
82
167
  const current = await readWorkspaceConfig(root);
83
168
  if (current.error) throw new Error(current.error);
84
169
  const hasExplicitFeatures = featureKeys.every(key => typeof current.features?.[key] === "boolean");
85
- if (current.enabled && hasExplicitFeatures) return;
170
+ const hasExplicitSummary = typeof current.summary?.backend === "string" && typeof current.summary?.concurrency === "number";
171
+ if (current.enabled && hasExplicitFeatures && hasExplicitSummary) return;
86
172
  const directory = dirname(current.path);
87
173
  await mkdir(directory, { recursive: true });
88
174
  const value = current.present ? readJsonFile(directory, "config.json", config) : {};
89
175
  const features = workspaceFeatures((value as WorkspaceConfig).features);
90
- const written = writeJsonFile(directory, "config.json", { ...value, enabled: true, features }, config, !current.present);
176
+ const summary = workspaceSummaryConfig((value as WorkspaceConfig).summary);
177
+ const written = writeJsonFile(directory, "config.json", { ...value, enabled: true, features, summary }, config, !current.present);
91
178
  if (!written) await initializeWorkspaceConfig(root);
92
179
  }
93
180
 
94
181
  export function workspaceDisabledMessage(configuration: WorkspaceConfiguration): string {
95
- return configuration.error ?? `Personal Bot 未在此工作区启用。请执行 /pbot init 初始化并启用;配置文件:${configuration.path}`;
182
+ return configuration.error ?? `Personal Bot 未在此工作区启用。请在工作区根目录运行 pbot init,也可在 Pi 或 dsh 中执行 /pbot init。配置文件位于 ${configuration.path}`;
96
183
  }
@@ -10,7 +10,7 @@ import type {
10
10
  WorkspaceMcpServer,
11
11
  WorkspaceMcpStdioServer,
12
12
  } from "../../model/workspace-mcp.js";
13
- import { readJsonFile, writeJsonFile } from "../../storage/atomic-json.js";
13
+ import { updateJsonFile } from "../../storage/atomic-json.js";
14
14
 
15
15
  const serverNamePattern = /^[A-Za-z0-9][A-Za-z0-9_-]{0,31}$/;
16
16
  const reservedServerNames = new Set(["pbot"]);
@@ -29,13 +29,11 @@ export function isWorkspaceMcpHttpServer(server: WorkspaceMcpServer): server is
29
29
 
30
30
  function validateStringRecord(value: unknown, label: string): Record<string, string> {
31
31
  requireThat(object(value), `${label} 必须是字符串映射。`);
32
- const result: Record<string, string> = {};
33
- for (const [key, entry] of Object.entries(value)) {
32
+ return Object.fromEntries(Object.entries(value).map(([key, entry]) => {
34
33
  requireThat(key.length > 0 && !key.includes("\0") && typeof entry === "string" && !entry.includes("\0"),
35
34
  `${label}.${key} 必须是非空键与无空字节字符串值。`);
36
- result[key] = entry;
37
- }
38
- return result;
35
+ return [key, entry];
36
+ }));
39
37
  }
40
38
 
41
39
  export function validateWorkspaceMcpServer(name: string, value: unknown): WorkspaceMcpServer {
@@ -117,7 +115,7 @@ function validateMcpFile(value: unknown): WorkspaceMcpConfig {
117
115
  for (const [name, entry] of Object.entries(rawServers)) {
118
116
  servers[name] = validateWorkspaceMcpServer(name, entry);
119
117
  }
120
- return { mcpServers: servers };
118
+ return { ...value, mcpServers: servers };
121
119
  }
122
120
 
123
121
  export function workspaceMcpPath(root: string): string {
@@ -148,6 +146,11 @@ export function expandEnvTemplate(value: string, env: NodeJS.ProcessEnv, context
148
146
  });
149
147
  }
150
148
 
149
+ function expandEnvRecord(values: Record<string, string> | undefined, env: NodeJS.ProcessEnv, context: string) {
150
+ return Object.fromEntries(Object.entries(values ?? {}).map(([key, value]) =>
151
+ [key, expandEnvTemplate(value, env, `${context}.${key}`)]));
152
+ }
153
+
151
154
  export function resolveWorkspaceMcpServer(
152
155
  root: string,
153
156
  name: string,
@@ -158,15 +161,11 @@ export function resolveWorkspaceMcpServer(
158
161
  if (isWorkspaceMcpHttpServer(server)) {
159
162
  const url = expandEnvTemplate(server.url, env, `MCP 服务 "${name}" 的 url`);
160
163
  requireThat(/^https?:\/\/.+/.test(url), `MCP 服务 "${name}" 展开后的 url 必须以 http:// 或 https:// 开头。`);
161
- const headers: Record<string, string> = {};
162
- for (const [key, value] of Object.entries(server.headers ?? {})) {
163
- headers[key] = expandEnvTemplate(value, env, `MCP 服务 "${name}" 的 headers.${key}`);
164
- }
165
164
  return {
166
165
  transport: "http",
167
166
  name,
168
167
  url,
169
- headers,
168
+ headers: expandEnvRecord(server.headers, env, `MCP 服务 "${name}" 的 headers`),
170
169
  ...(server.description ? { description: server.description } : {}),
171
170
  timeout,
172
171
  };
@@ -174,17 +173,13 @@ export function resolveWorkspaceMcpServer(
174
173
 
175
174
  const command = expandEnvTemplate(server.command, env, `MCP 服务 "${name}" 的 command`);
176
175
  const args = (server.args ?? []).map((arg, index) => expandEnvTemplate(arg, env, `MCP 服务 "${name}" 的 args[${index}]`));
177
- const resolvedEnv: Record<string, string> = {};
178
- for (const [key, value] of Object.entries(server.env ?? {})) {
179
- resolvedEnv[key] = expandEnvTemplate(value, env, `MCP 服务 "${name}" 的 env.${key}`);
180
- }
181
176
  const cwd = server.cwd ? resolve(root, expandEnvTemplate(server.cwd, env, `MCP 服务 "${name}" 的 cwd`)) : root;
182
177
  return {
183
178
  transport: "stdio",
184
179
  name,
185
180
  command,
186
181
  args,
187
- env: resolvedEnv,
182
+ env: expandEnvRecord(server.env, env, `MCP 服务 "${name}" 的 env`),
188
183
  cwd,
189
184
  ...(server.description ? { description: server.description } : {}),
190
185
  timeout,
@@ -215,10 +210,10 @@ export async function upsertWorkspaceMcpServer(
215
210
  if (current.error) throw new Error(current.error);
216
211
  const directory = dirname(current.path);
217
212
  await mkdir(directory, { recursive: true });
218
- const existing = current.present ? readJsonFile(directory, "mcp.json", validateMcpFile) : { mcpServers: {} };
219
- const next: WorkspaceMcpConfig = { mcpServers: { ...existing.mcpServers, [name]: validated } };
220
- const written = writeJsonFile(directory, "mcp.json", next, validateMcpFile, !current.present);
221
- if (!written) return upsertWorkspaceMcpServer(root, name, server);
213
+ await updateJsonFile(directory, "mcp.json", validateMcpFile, existing => ({
214
+ ...existing,
215
+ mcpServers: { ...existing?.mcpServers, [name]: validated },
216
+ }));
222
217
  return readWorkspaceMcpConfig(root);
223
218
  }
224
219
 
@@ -232,11 +227,11 @@ export async function removeWorkspaceMcpServer(
232
227
  return { removed: false, configuration: current };
233
228
  }
234
229
  const directory = dirname(current.path);
235
- const existing = readJsonFile(directory, "mcp.json", validateMcpFile);
236
- if (!Object.hasOwn(existing.mcpServers, name)) {
237
- return { removed: false, configuration: await readWorkspaceMcpConfig(root) };
238
- }
239
- const remaining = Object.fromEntries(Object.entries(existing.mcpServers).filter(([key]) => key !== name));
240
- writeJsonFile(directory, "mcp.json", { mcpServers: remaining }, validateMcpFile);
241
- return { removed: true, configuration: await readWorkspaceMcpConfig(root) };
230
+ const removed = await updateJsonFile(directory, "mcp.json", validateMcpFile, existing => {
231
+ if (!existing || !Object.hasOwn(existing.mcpServers, name)) return undefined;
232
+ const remaining = { ...existing.mcpServers };
233
+ delete remaining[name];
234
+ return { ...existing, mcpServers: remaining };
235
+ });
236
+ return { removed, configuration: await readWorkspaceMcpConfig(root) };
242
237
  }
@@ -51,7 +51,10 @@ export function parseSkillFrontmatter(content: string): { name?: string; descrip
51
51
 
52
52
  /** Scan `<workspace>/.agents/skills/<dir>/SKILL.md` for workspace-authored skills. */
53
53
  export async function discoverWorkspaceSkills(root: string): Promise<WorkspaceSkillMeta[]> {
54
- const skillsDir = join(root, ".agents", "skills");
54
+ return discoverSkills(join(root, ".agents", "skills"), ".agents/skills");
55
+ }
56
+
57
+ export async function discoverSkills(skillsDir: string, indexPath: string): Promise<WorkspaceSkillMeta[]> {
55
58
  let entries;
56
59
  try { entries = await readdir(skillsDir, { withFileTypes: true }); }
57
60
  catch (error) {
@@ -70,7 +73,7 @@ export async function discoverWorkspaceSkills(root: string): Promise<WorkspaceSk
70
73
  results.push({
71
74
  name: meta.name,
72
75
  description: meta.description,
73
- path: `.agents/skills/${entry.name}/SKILL.md`,
76
+ path: join(indexPath, entry.name, "SKILL.md"),
74
77
  });
75
78
  }
76
79
  results.sort((a, b) => a.name.localeCompare(b.name));
@@ -1,7 +1,8 @@
1
1
  import { isAbsolute } from "node:path";
2
2
  import { object } from "../common/json.js";
3
- import { isAcpBackend, requireThat } from "../common/validation.js";
3
+ import { isAcpBackend, isOneOf, requireThat } from "../common/validation.js";
4
4
  import { fileId } from "./file-access.js";
5
+ import { acpAnswerStates, acpElicitationActions, acpPermissionPolicies, isAcpElicitationValue } from "../model/acp.js";
5
6
  import type { AcpAnswer, AcpElicitation, AcpElicitationReply, AcpInput, AcpPermission, AcpPermissionReply, AcpModelState, AcpProcess, AcpReport, AcpSessionReference } from "../model/acp.js";
6
7
 
7
8
  const text = (value: unknown): value is string => typeof value === "string" && value.length > 0 && !value.includes("\0");
@@ -12,7 +13,7 @@ export function acpReference(value: unknown): AcpSessionReference {
12
13
  if (value.env !== undefined) {
13
14
  requireThat(object(value.env) && Object.entries(value.env).every(([k, v]) => text(k) && typeof v === "string" && !v.includes("\0")), "ACP 环境变量配置无效。");
14
15
  }
15
- requireThat(value.permission === undefined || ["ask", "allow", "deny"].includes(String(value.permission)), "ACP 权限策略无效。");
16
+ requireThat(value.permission === undefined || isOneOf(value.permission, acpPermissionPolicies), "ACP 权限策略无效。");
16
17
  const capabilities = value.capabilities;
17
18
  if (capabilities !== undefined) requireThat(object(capabilities) &&
18
19
  ["resume", "load", "close"].every(key => typeof capabilities[key] === "boolean"), "ACP 会话能力无效。");
@@ -33,7 +34,7 @@ export function acpInput(value: unknown): AcpInput {
33
34
  }
34
35
  export function acpAnswer(value: unknown): AcpAnswer {
35
36
  acpInput(value);
36
- requireThat(object(value) && typeof value.answer === "string" && ["completed", "failed", "cancelled"].includes(String(value.state)) &&
37
+ requireThat(object(value) && typeof value.answer === "string" && isOneOf(value.state, acpAnswerStates) &&
37
38
  (value.error === undefined || typeof value.error === "string"), "ACP 最终回答无效。");
38
39
  return value as unknown as AcpAnswer;
39
40
  }
@@ -44,7 +45,7 @@ export function acpReport(value: unknown): AcpReport {
44
45
  export function acpPermission(value: unknown): AcpPermission {
45
46
  acpInput(value);
46
47
  requireThat(object(value) && typeof value.description === "string" && Array.isArray(value.options) && value.options.every(option =>
47
- object(option) && text(option.optionId) && text(option.name) && ["allow_once", "allow_always", "reject_once", "reject_always"].includes(String(option.kind))), "ACP 确认请求无效。");
48
+ object(option) && text(option.optionId) && text(option.name) && isOneOf(option.kind, ["allow_once", "allow_always", "reject_once", "reject_always"])), "ACP 确认请求无效。");
48
49
  return value as unknown as AcpPermission;
49
50
  }
50
51
  export function acpPermissionReply(value: unknown): AcpPermissionReply {
@@ -52,12 +53,6 @@ export function acpPermissionReply(value: unknown): AcpPermissionReply {
52
53
  requireThat(object(value) && (value.optionId === null || text(value.optionId)), "ACP 确认答复无效。");
53
54
  return value as unknown as AcpPermissionReply;
54
55
  }
55
- function elicitationValue(value: unknown): boolean {
56
- return typeof value === "string"
57
- || (typeof value === "number" && Number.isFinite(value))
58
- || typeof value === "boolean"
59
- || (Array.isArray(value) && value.every(item => typeof item === "string"));
60
- }
61
56
  export function acpElicitation(value: unknown): AcpElicitation {
62
57
  acpInput(value);
63
58
  requireThat(object(value) && (value.mode === "form" || value.mode === "url") && typeof value.message === "string", "ACP 交互请求无效。");
@@ -70,10 +65,10 @@ export function acpElicitation(value: unknown): AcpElicitation {
70
65
  }
71
66
  export function acpElicitationReply(value: unknown): AcpElicitationReply {
72
67
  acpInput(value);
73
- requireThat(object(value) && ["accept", "decline", "cancel"].includes(String(value.action)), "ACP 交互答复无效。");
68
+ requireThat(object(value) && isOneOf(value.action, acpElicitationActions), "ACP 交互答复无效。");
74
69
  if (value.content !== undefined) {
75
70
  requireThat(value.action === "accept" && object(value.content) &&
76
- Object.values(value.content).every(elicitationValue), "ACP 表单答复 content 无效。");
71
+ Object.values(value.content).every(isAcpElicitationValue), "ACP 表单答复 content 无效。");
77
72
  }
78
73
  return value as unknown as AcpElicitationReply;
79
74
  }
@@ -2,9 +2,10 @@ import { existsSync, mkdirSync, readdirSync, rmSync } from "node:fs";
2
2
  import { join } from "node:path";
3
3
  import { randomUUID } from "node:crypto";
4
4
  import { canonical, object } from "../common/json.js";
5
- import { requireThat } from "../common/validation.js";
5
+ import { isOneOf, requireThat } from "../common/validation.js";
6
6
  import { readJsonFile, writeJsonFile } from "./atomic-json.js";
7
7
  import { fileId, privateDirectory } from "./file-access.js";
8
+ import { agentStates, cycleSources, cycleStates, messageDeliveries } from "../model/agent.js";
8
9
  import type { AgentDescriptor, AgentLaunch, AgentMessage, AgentStatus, AgentCycle, AgentSessionReference } from "../model/agent.js";
9
10
  import type { AcpSessionReference } from "../model/acp.js";
10
11
  import { acpElicitation, acpPermission, acpReference } from "./acp-files.js";
@@ -22,18 +23,18 @@ export function launch(v: unknown): AgentLaunch {
22
23
  }
23
24
  export function message(v: unknown): AgentMessage {
24
25
  requireThat(object(v) && text(v.requestId) && text(v.generation) && Number.isSafeInteger(v.sequence) && typeof v.message === "string" &&
25
- ["steer", "followUp"].includes(String(v.delivery)) && Array.isArray(v.files) && v.files.every(text), "子会话消息无效。");
26
+ isOneOf(v.delivery, messageDeliveries) && Array.isArray(v.files) && v.files.every(text), "子会话消息无效。");
26
27
  return v as unknown as AgentMessage;
27
28
  }
28
29
  export function cycle(v: unknown): AgentCycle {
29
30
  requireThat(object(v) && text(v.cycleId) && text(v.generation) && number(v.startedAt) &&
30
- ["running", "completed", "failed", "cancelled", "interrupted"].includes(String(v.state)) &&
31
+ isOneOf(v.state, cycleStates) &&
31
32
  (v.leaf === null || text(v.leaf)) && Array.isArray(v.requestIds) && v.requestIds.every(text) &&
32
- ["parent", "interactive", "mixed"].includes(String(v.source)) && (v.finishedAt === undefined || number(v.finishedAt)), "子会话周期无效。");
33
+ isOneOf(v.source, cycleSources) && (v.finishedAt === undefined || number(v.finishedAt)), "子会话周期无效。");
33
34
  return v as unknown as AgentCycle;
34
35
  }
35
36
  export function status(v: unknown): AgentStatus {
36
- requireThat(object(v) && text(v.generation) && ["starting", "busy", "idle", "stopping", "stopped", "error"].includes(String(v.state)) &&
37
+ requireThat(object(v) && text(v.generation) && isOneOf(v.state, agentStates) &&
37
38
  typeof v.activity === "string" && number(v.updatedAt), "子会话状态无效。");
38
39
  if (v.cycle) cycle(v.cycle); return v as unknown as AgentStatus;
39
40
  }
@@ -1,12 +1,13 @@
1
- import { constants, closeSync, fstatSync, fsyncSync, linkSync, lstatSync, openSync, readFileSync, realpathSync,
2
- renameSync, unlinkSync, writeFileSync } from "node:fs";
1
+ import { constants, closeSync, fstatSync, fsyncSync, linkSync, lstatSync, mkdirSync, openSync, readFileSync, realpathSync,
2
+ renameSync, rmdirSync, unlinkSync, writeFileSync } from "node:fs";
3
3
  import { dirname, join } from "node:path";
4
+ import { setTimeout as delay } from "node:timers/promises";
4
5
  import { randomUUID } from "node:crypto";
5
6
  import { canonical } from "../common/json.js";
6
7
  import { requireThat } from "../common/validation.js";
7
8
 
8
9
  /** The root must already exist. Never follow aliases inside internal storage. */
9
- export function internalPath(directory: string, relative: string): string {
10
+ export function internalPath(directory: string, relative: string, allowMissingParents = false): string {
10
11
  const parts = relative.split("/");
11
12
  requireThat(parts.every(part => part && part !== "." && part !== ".." && !/[\\\x00-\x1f]/.test(part)), "内部状态路径无效。");
12
13
  const info = lstatSync(directory);
@@ -18,7 +19,7 @@ export function internalPath(directory: string, relative: string): string {
18
19
  const info = lstatSync(path);
19
20
  requireThat(!info.isSymbolicLink() && (index === parts.length - 1 ? info.isFile() : info.isDirectory()), "内部状态不能使用符号链接或特殊文件。");
20
21
  } catch (error) {
21
- if ((error as NodeJS.ErrnoException).code !== "ENOENT" || index !== parts.length - 1) throw error;
22
+ if ((error as NodeJS.ErrnoException).code !== "ENOENT" || (!allowMissingParents && index !== parts.length - 1)) throw error;
22
23
  }
23
24
  }
24
25
  return path;
@@ -72,3 +73,29 @@ export function writeJsonFile<T>(directory: string, relative: string, value: unk
72
73
  catch (error) { if ((error as NodeJS.ErrnoException).code !== "ENOENT") throw error; }
73
74
  }
74
75
  }
76
+
77
+ /** Serialize a read-modify-write across processes. An undefined replacement means no change. */
78
+ export async function updateJsonFile<T>(directory: string, relative: string, validate: (value: unknown) => T,
79
+ update: (current: T | undefined) => T | undefined): Promise<boolean> {
80
+ const lock = internalPath(directory, relative) + ".lock";
81
+ const deadline = Date.now() + 3000;
82
+ for (;;) {
83
+ try { mkdirSync(lock, { mode: 0o700 }); break; }
84
+ catch (error) {
85
+ if ((error as NodeJS.ErrnoException).code !== "EEXIST") throw error;
86
+ if (Date.now() >= deadline) throw new Error(`写锁被占用:${lock}。若写入进程已退出,可手动移除遗留锁目录。`);
87
+ await delay(25);
88
+ }
89
+ }
90
+ try {
91
+ for (;;) {
92
+ let current: T | undefined;
93
+ try { current = readJsonFile(directory, relative, validate); }
94
+ catch (error) { if ((error as NodeJS.ErrnoException).code !== "ENOENT") throw error; }
95
+ const next = update(current);
96
+ if (next === undefined) return false;
97
+ if (writeJsonFile(directory, relative, next, validate, current === undefined)) return true;
98
+ // An external writer created the file first. Apply the edit to its value.
99
+ }
100
+ } finally { rmdirSync(lock); }
101
+ }