personal-bot 0.2.19 → 0.3.0

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 (343) hide show
  1. package/.claude-plugin/marketplace.json +3 -3
  2. package/.claude-plugin/plugin.json +2 -5
  3. package/.mcp.json +11 -0
  4. package/CONTEXT.md +17 -73
  5. package/README.md +41 -120
  6. package/README.zh-CN.md +41 -120
  7. package/docs/README.md +31 -23
  8. package/docs/architecture/design.md +74 -0
  9. package/docs/architecture/extensibility.md +78 -0
  10. package/docs/architecture/model-context.md +31 -0
  11. package/docs/architecture/model-instruction-guidelines.md +34 -0
  12. package/docs/architecture/principles.md +33 -0
  13. package/docs/guides/capabilities.md +36 -0
  14. package/docs/guides/cross-harness-workers.md +83 -0
  15. package/docs/guides/history.md +25 -0
  16. package/docs/guides/workspace-configuration.md +102 -0
  17. package/docs/hosts/antigravity.md +52 -0
  18. package/docs/hosts/claude-code.md +47 -0
  19. package/docs/hosts/dsh.md +67 -0
  20. package/docs/hosts/pi.md +49 -0
  21. package/docs/maintainers/release.md +59 -0
  22. package/hooks/hooks.json +0 -3
  23. package/lib/antigravity-plugin/hooks.json +23 -0
  24. package/lib/antigravity-plugin/lib/claude.d.ts +1 -0
  25. package/lib/antigravity-plugin/lib/claude.js +13 -0
  26. package/lib/antigravity-plugin/lib/common/json.d.ts +6 -0
  27. package/lib/antigravity-plugin/lib/common/json.js +16 -0
  28. package/lib/antigravity-plugin/lib/common/paths.d.ts +1 -0
  29. package/lib/antigravity-plugin/lib/common/paths.js +2 -0
  30. package/lib/antigravity-plugin/lib/common/validation.d.ts +3 -0
  31. package/lib/antigravity-plugin/lib/common/validation.js +8 -0
  32. package/lib/antigravity-plugin/lib/common/version.d.ts +3 -0
  33. package/lib/antigravity-plugin/lib/common/version.js +13 -0
  34. package/lib/antigravity-plugin/lib/extension/acp-worker.js +11597 -0
  35. package/lib/antigravity-plugin/lib/extension/mcp.js +2715 -0
  36. package/lib/antigravity-plugin/lib/extension/plugin-runtime.d.ts +10 -0
  37. package/lib/antigravity-plugin/lib/extension/plugin-runtime.js +67 -0
  38. package/lib/antigravity-plugin/lib/integrations/agent-resources.d.ts +16 -0
  39. package/lib/antigravity-plugin/lib/integrations/agent-resources.js +56 -0
  40. package/lib/antigravity-plugin/lib/integrations/hosts/antigravity.d.ts +4 -0
  41. package/lib/antigravity-plugin/lib/integrations/hosts/antigravity.js +79 -0
  42. package/lib/antigravity-plugin/lib/integrations/hosts/claude.d.ts +3 -0
  43. package/lib/antigravity-plugin/lib/integrations/hosts/claude.js +60 -0
  44. package/lib/antigravity-plugin/lib/integrations/hosts/registry.d.ts +15 -0
  45. package/lib/antigravity-plugin/lib/integrations/hosts/registry.js +34 -0
  46. package/lib/antigravity-plugin/lib/model/acp.d.ts +164 -0
  47. package/lib/antigravity-plugin/lib/model/acp.js +12 -0
  48. package/lib/antigravity-plugin/lib/model/plugin-host.d.ts +48 -0
  49. package/lib/antigravity-plugin/lib/model/workspace-config.d.ts +24 -0
  50. package/lib/antigravity-plugin/lib/model/workspace-config.js +1 -0
  51. package/lib/antigravity-plugin/lib/model/workspace-mcp.d.ts +51 -0
  52. package/lib/antigravity-plugin/lib/model/workspace-mcp.js +4 -0
  53. package/lib/antigravity-plugin/lib/plugin.d.ts +1 -0
  54. package/lib/antigravity-plugin/lib/plugin.js +17 -0
  55. package/lib/antigravity-plugin/lib/services/workspace/workspace-config.d.ts +8 -0
  56. package/lib/antigravity-plugin/lib/services/workspace/workspace-config.js +93 -0
  57. package/lib/antigravity-plugin/lib/services/workspace/workspace-preparation.d.ts +3 -0
  58. package/lib/antigravity-plugin/lib/services/workspace/workspace-preparation.js +26 -0
  59. package/lib/antigravity-plugin/lib/services/workspace/workspace-skills.d.ts +8 -0
  60. package/lib/antigravity-plugin/lib/services/workspace/workspace-skills.js +91 -0
  61. package/lib/antigravity-plugin/lib/storage/atomic-json.d.ts +11 -0
  62. package/lib/antigravity-plugin/lib/storage/atomic-json.js +101 -0
  63. package/lib/antigravity-plugin/mcp_config.json +13 -0
  64. package/lib/antigravity-plugin/package.json +6 -0
  65. package/lib/antigravity-plugin/plugin.json +7 -0
  66. package/lib/antigravity-plugin/resources/agents/coordinator.md +11 -0
  67. package/{resources/claude → lib/antigravity-plugin/resources}/agents/general-purpose.md +0 -5
  68. package/lib/antigravity-plugin/resources/prompts/plugin-coordinator.md +1 -0
  69. package/lib/antigravity-plugin/resources/prompts/workspace.md +31 -0
  70. package/lib/antigravity-plugin/resources/references/compute-finance.md +22 -0
  71. package/lib/antigravity-plugin/resources/references/compute.md +16 -0
  72. package/lib/antigravity-plugin/resources/references/task-conductor.md +25 -0
  73. package/lib/antigravity-plugin/resources/templates/workspace-agents.md +21 -0
  74. package/lib/antigravity-plugin/skills/pbot/SKILL.md +16 -0
  75. package/lib/antigravity-plugin/skills/project-maintenance/SKILL.md +35 -0
  76. package/lib/antigravity-plugin/skills/provider-connections/SKILL.md +42 -0
  77. package/lib/claude.js +4 -11
  78. package/lib/client.js +14 -531
  79. package/lib/common/markdown.js +2 -3
  80. package/lib/common/validation.d.ts +2 -0
  81. package/lib/common/validation.js +4 -0
  82. package/lib/extension/acp-member.d.ts +2 -0
  83. package/lib/extension/acp-member.js +9 -8
  84. package/lib/extension/acp-worker.js +11578 -121
  85. package/lib/extension/dsh/acp-member.js +26 -2
  86. package/lib/extension/dsh/command.js +19 -57
  87. package/lib/extension/dsh/history.js +2 -4
  88. package/lib/extension/dsh/management.d.ts +0 -2
  89. package/lib/extension/dsh/management.js +27 -126
  90. package/lib/extension/dsh/workspace.d.ts +5 -47
  91. package/lib/extension/dsh/workspace.js +76 -108
  92. package/lib/extension/mcp-bridge.d.ts +41 -0
  93. package/lib/extension/mcp-bridge.js +412 -0
  94. package/lib/extension/mcp-workers.d.ts +980 -0
  95. package/lib/extension/mcp-workers.js +882 -0
  96. package/lib/extension/mcp.js +2715 -0
  97. package/lib/extension/plugin-runtime.d.ts +10 -0
  98. package/lib/extension/plugin-runtime.js +67 -0
  99. package/lib/extension/setup-cli.js +215 -2
  100. package/lib/integrations/acp/agents.d.ts +10 -11
  101. package/lib/integrations/acp/agents.js +65 -33
  102. package/lib/integrations/acp/claude.d.ts +2 -2
  103. package/lib/integrations/acp/claude.js +5 -3
  104. package/lib/integrations/acp/connection.d.ts +17 -4
  105. package/lib/integrations/acp/connection.js +53 -27
  106. package/lib/integrations/acp/executable.d.ts +3 -0
  107. package/lib/integrations/acp/executable.js +42 -0
  108. package/lib/integrations/acp/harnesses/claude.d.ts +2 -0
  109. package/lib/integrations/acp/harnesses/claude.js +49 -0
  110. package/lib/integrations/acp/harnesses/dsh.d.ts +2 -0
  111. package/lib/integrations/acp/harnesses/dsh.js +35 -0
  112. package/lib/integrations/acp/harnesses/generic.d.ts +13 -0
  113. package/lib/integrations/acp/harnesses/generic.js +37 -0
  114. package/lib/integrations/acp/harnesses/pi.d.ts +2 -0
  115. package/lib/integrations/acp/harnesses/pi.js +34 -0
  116. package/lib/integrations/acp/harnesses/presets.d.ts +3 -0
  117. package/lib/integrations/acp/harnesses/presets.js +20 -0
  118. package/lib/integrations/acp/launch.d.ts +33 -4
  119. package/lib/integrations/acp/launch.js +60 -48
  120. package/lib/integrations/acp/mcp.d.ts +6 -0
  121. package/lib/integrations/acp/mcp.js +40 -0
  122. package/lib/integrations/acp/model-selection.d.ts +9 -2
  123. package/lib/integrations/acp/model-selection.js +73 -27
  124. package/lib/integrations/acp/registry.d.ts +18 -0
  125. package/lib/integrations/acp/registry.js +50 -0
  126. package/lib/integrations/agent-resources.d.ts +16 -1
  127. package/lib/integrations/agent-resources.js +45 -9
  128. package/lib/integrations/dsh/mcp.d.ts +4 -0
  129. package/lib/integrations/dsh/mcp.js +28 -0
  130. package/lib/integrations/dsh/resources.d.ts +3 -3
  131. package/lib/integrations/dsh/resources.js +21 -12
  132. package/lib/integrations/dsh/skills.d.ts +5 -1
  133. package/lib/integrations/dsh/skills.js +10 -6
  134. package/lib/integrations/hosts/antigravity.d.ts +4 -0
  135. package/lib/integrations/hosts/antigravity.js +79 -0
  136. package/lib/integrations/hosts/claude.d.ts +3 -0
  137. package/lib/integrations/hosts/claude.js +60 -0
  138. package/lib/integrations/hosts/registry.d.ts +15 -0
  139. package/lib/integrations/hosts/registry.js +34 -0
  140. package/lib/model/acp.d.ts +107 -2
  141. package/lib/model/acp.js +12 -1
  142. package/lib/model/agent.d.ts +35 -33
  143. package/lib/model/plugin-host.d.ts +48 -0
  144. package/lib/model/plugin-host.js +1 -0
  145. package/lib/model/workspace-config.d.ts +12 -0
  146. package/lib/model/workspace-mcp.d.ts +51 -0
  147. package/lib/model/workspace-mcp.js +4 -0
  148. package/lib/plugin.d.ts +1 -0
  149. package/lib/plugin.js +17 -0
  150. package/lib/services/agents/acp-run.d.ts +13 -1
  151. package/lib/services/agents/acp-run.js +30 -2
  152. package/lib/services/agents/agent-service.d.ts +35 -120
  153. package/lib/services/agents/agent-service.js +156 -160
  154. package/lib/services/installation/setup-service.js +17 -1
  155. package/lib/services/workspace/workspace-config.d.ts +2 -1
  156. package/lib/services/workspace/workspace-config.js +39 -7
  157. package/lib/services/workspace/workspace-mcp.d.ts +14 -0
  158. package/lib/services/workspace/workspace-mcp.js +200 -0
  159. package/lib/services/workspace/workspace-skills.d.ts +8 -0
  160. package/lib/services/workspace/workspace-skills.js +91 -0
  161. package/lib/storage/acp-files.d.ts +3 -1
  162. package/lib/storage/acp-files.js +32 -2
  163. package/lib/storage/acp-history.d.ts +3 -2
  164. package/lib/storage/acp-history.js +19 -7
  165. package/lib/storage/agent-files.d.ts +8 -8
  166. package/lib/storage/agent-files.js +27 -47
  167. package/lib/tools/history/contract.d.ts +1 -1
  168. package/lib/tools/history/contract.js +17 -11
  169. package/lib/ui/dsh/index.js +8 -3
  170. package/lib/ui/dsh/management.d.ts +1 -1
  171. package/lib/ui/dsh/management.js +24 -456
  172. package/lib/ui/dsh/remote.d.ts +0 -2
  173. package/lib/ui/dsh/remote.js +1 -1
  174. package/package.json +12 -7
  175. package/resources/agents/coordinator.md +2 -2
  176. package/resources/antigravity/skills/pbot/SKILL.md +16 -0
  177. package/resources/claude/skills/pbot/SKILL.md +1 -1
  178. package/resources/prompts/history-coordinator.md +1 -0
  179. package/resources/prompts/plugin-coordinator.md +1 -0
  180. package/resources/prompts/workspace.md +9 -8
  181. package/resources/references/compute.md +9 -11
  182. package/resources/references/task-conductor.md +12 -26
  183. package/resources/skills/project-maintenance/SKILL.md +17 -22
  184. package/resources/skills/provider-connections/SKILL.md +24 -40
  185. package/resources/templates/workspace-agents.md +8 -0
  186. package/scripts/README.md +17 -34
  187. package/src/claude.ts +4 -8
  188. package/src/common/markdown.ts +2 -3
  189. package/src/common/validation.ts +6 -0
  190. package/src/extension/acp-member.ts +9 -8
  191. package/src/extension/acp-worker.ts +239 -97
  192. package/src/extension/command.ts +38 -36
  193. package/src/extension/dsh/acp-member.ts +21 -2
  194. package/src/extension/dsh/command.ts +21 -51
  195. package/src/extension/dsh/files.ts +1 -0
  196. package/src/extension/dsh/history.ts +9 -6
  197. package/src/extension/dsh/management.ts +27 -58
  198. package/src/extension/dsh/workspace.ts +88 -99
  199. package/src/extension/events.ts +13 -10
  200. package/src/extension/history.ts +2 -50
  201. package/src/extension/lifecycle.ts +37 -22
  202. package/src/extension/mcp-bridge.ts +412 -0
  203. package/src/extension/mcp-workers.ts +941 -0
  204. package/src/extension/pi-acp-member.ts +29 -5
  205. package/src/extension/plugin-runtime.ts +63 -0
  206. package/src/extension/setup-cli.ts +186 -2
  207. package/src/integrations/acp/agents.ts +70 -24
  208. package/src/integrations/acp/claude.ts +11 -4
  209. package/src/integrations/acp/connection.ts +63 -25
  210. package/src/integrations/acp/executable.ts +41 -0
  211. package/src/integrations/acp/harnesses/claude.ts +50 -0
  212. package/src/integrations/acp/harnesses/dsh.ts +40 -0
  213. package/src/integrations/acp/harnesses/generic.ts +52 -0
  214. package/src/integrations/acp/harnesses/pi.ts +35 -0
  215. package/src/integrations/acp/harnesses/presets.ts +22 -0
  216. package/src/integrations/acp/launch.ts +69 -47
  217. package/src/integrations/acp/mcp.ts +43 -0
  218. package/src/integrations/acp/model-selection.ts +68 -25
  219. package/src/integrations/acp/registry.ts +60 -0
  220. package/src/integrations/agent-resources.ts +70 -6
  221. package/src/integrations/dsh/mcp.ts +30 -0
  222. package/src/integrations/dsh/resources.ts +28 -13
  223. package/src/integrations/dsh/skills.ts +16 -6
  224. package/src/integrations/hosts/antigravity.ts +83 -0
  225. package/src/integrations/hosts/claude.ts +62 -0
  226. package/src/integrations/hosts/registry.ts +42 -0
  227. package/src/integrations/pi/mcp.ts +26 -0
  228. package/src/mcp.ts +14 -0
  229. package/src/model/acp.ts +113 -3
  230. package/src/model/agent.ts +18 -14
  231. package/src/model/plugin-host.ts +39 -0
  232. package/src/model/workspace-config.ts +14 -0
  233. package/src/model/workspace-mcp.ts +64 -0
  234. package/src/pbot.ts +69 -20
  235. package/src/plugin.ts +19 -0
  236. package/src/services/agents/acp-run.ts +35 -3
  237. package/src/services/agents/agent-service.ts +180 -160
  238. package/src/services/installation/setup-service.ts +17 -2
  239. package/src/services/workspace/workspace-config.ts +42 -6
  240. package/src/services/workspace/workspace-mcp.ts +242 -0
  241. package/src/services/workspace/workspace-skills.ts +78 -0
  242. package/src/storage/acp-files.ts +32 -3
  243. package/src/storage/acp-history.ts +18 -7
  244. package/src/storage/agent-files.ts +27 -41
  245. package/src/tools/history/contract.ts +17 -11
  246. package/src/tools/register.ts +4 -8
  247. package/src/ui/dsh/index.ts +8 -3
  248. package/src/ui/dsh/management.ts +40 -282
  249. package/src/ui/dsh/remote.ts +2 -2
  250. package/docs/adr/0001-claude-skill-discovery.md +0 -3
  251. package/docs/adr/0002-claude-native-collaboration.md +0 -3
  252. package/docs/agent-collaboration.md +0 -190
  253. package/docs/architecture-guidelines.md +0 -37
  254. package/docs/capability-design.md +0 -55
  255. package/docs/claude-code-design.md +0 -44
  256. package/docs/claude-code.md +0 -57
  257. package/docs/dsh.md +0 -337
  258. package/docs/file-storage.md +0 -97
  259. package/docs/history.md +0 -54
  260. package/docs/installation-design.md +0 -86
  261. package/docs/interaction-design.md +0 -21
  262. package/docs/model-context.md +0 -76
  263. package/docs/model-instruction-guidelines.md +0 -51
  264. package/docs/release.md +0 -108
  265. package/docs/technical-design.md +0 -163
  266. package/docs/workspace-configuration.md +0 -79
  267. package/lib/extension/claude-hooks.d.ts +0 -9
  268. package/lib/extension/claude-hooks.js +0 -78
  269. package/lib/extension/dsh/agent-events.d.ts +0 -24
  270. package/lib/extension/dsh/agent-events.js +0 -242
  271. package/lib/extension/dsh/agent-runtime.d.ts +0 -49
  272. package/lib/extension/dsh/agent-runtime.js +0 -351
  273. package/lib/integrations/dsh/dsh-agents.d.ts +0 -30
  274. package/lib/integrations/dsh/dsh-agents.js +0 -104
  275. package/lib/integrations/dsh/input.d.ts +0 -21
  276. package/lib/integrations/dsh/input.js +0 -62
  277. package/lib/integrations/dsh/notifications.d.ts +0 -8
  278. package/lib/integrations/dsh/notifications.js +0 -55
  279. package/lib/integrations/dsh/session.d.ts +0 -14
  280. package/lib/integrations/dsh/session.js +0 -60
  281. package/lib/integrations/team-context.d.ts +0 -18
  282. package/lib/integrations/team-context.js +0 -61
  283. package/lib/model/team.d.ts +0 -85
  284. package/lib/services/agents/agent-notices.d.ts +0 -13
  285. package/lib/services/agents/agent-notices.js +0 -25
  286. package/lib/services/agents/start-options.d.ts +0 -4
  287. package/lib/services/agents/start-options.js +0 -20
  288. package/lib/services/agents/team-service.d.ts +0 -168
  289. package/lib/services/agents/team-service.js +0 -345
  290. package/lib/storage/team-files.d.ts +0 -16
  291. package/lib/storage/team-files.js +0 -111
  292. package/lib/tools/agents/actions.d.ts +0 -62
  293. package/lib/tools/agents/actions.js +0 -62
  294. package/lib/tools/agents/contract.d.ts +0 -181
  295. package/lib/tools/agents/contract.js +0 -84
  296. package/lib/tools/agents/dsh-tool.d.ts +0 -5
  297. package/lib/tools/agents/dsh-tool.js +0 -34
  298. package/lib/tools/result.d.ts +0 -18
  299. package/lib/tools/result.js +0 -10
  300. package/lib/tools/teams/actions.d.ts +0 -23
  301. package/lib/tools/teams/actions.js +0 -40
  302. package/lib/tools/teams/contract.d.ts +0 -201
  303. package/lib/tools/teams/contract.js +0 -91
  304. package/lib/tools/teams/dsh-tool.d.ts +0 -8
  305. package/lib/tools/teams/dsh-tool.js +0 -39
  306. package/lib/ui/dsh/attachments.d.ts +0 -5
  307. package/lib/ui/dsh/attachments.js +0 -39
  308. package/resources/prompts/claude-coordinator.md +0 -1
  309. package/resources/prompts/native-coordinator.md +0 -1
  310. package/resources/prompts/team-member.md +0 -7
  311. package/src/extension/agent-events.ts +0 -210
  312. package/src/extension/agents-command.ts +0 -89
  313. package/src/extension/claude-hooks.ts +0 -74
  314. package/src/extension/dsh/agent-events.ts +0 -148
  315. package/src/extension/dsh/agent-runtime.ts +0 -252
  316. package/src/extension/subagent-entry.ts +0 -270
  317. package/src/extension/teams-command.ts +0 -67
  318. package/src/integrations/dsh/dsh-agents.ts +0 -97
  319. package/src/integrations/dsh/input.ts +0 -66
  320. package/src/integrations/dsh/notifications.ts +0 -46
  321. package/src/integrations/pi/agent-context.ts +0 -18
  322. package/src/integrations/pi/agent-input.ts +0 -19
  323. package/src/integrations/pi/pi-agents.ts +0 -84
  324. package/src/integrations/pi/team-context.ts +0 -26
  325. package/src/integrations/team-context.ts +0 -64
  326. package/src/model/team.ts +0 -29
  327. package/src/services/agents/agent-notices.ts +0 -28
  328. package/src/services/agents/start-options.ts +0 -19
  329. package/src/services/agents/team-service.ts +0 -275
  330. package/src/storage/team-files.ts +0 -93
  331. package/src/tools/agents/actions.ts +0 -57
  332. package/src/tools/agents/contract.ts +0 -101
  333. package/src/tools/agents/dsh-tool.ts +0 -37
  334. package/src/tools/agents/tool.ts +0 -20
  335. package/src/tools/teams/actions.ts +0 -34
  336. package/src/tools/teams/contract.ts +0 -109
  337. package/src/tools/teams/dsh-tool.ts +0 -45
  338. package/src/tools/teams/tool.ts +0 -29
  339. package/src/ui/agent-display.ts +0 -14
  340. package/src/ui/dsh/attachments.ts +0 -42
  341. package/src/ui/pi/menu.ts +0 -37
  342. package/src/ui/pi/reader.ts +0 -46
  343. /package/lib/{model/team.js → antigravity-plugin/lib/model/plugin-host.js} +0 -0
@@ -1,201 +0,0 @@
1
- import { Type } from "typebox";
2
- export declare const teamDescription = "\u7EC4\u7EC7\u56FA\u5B9A\u6210\u5458\u534F\u4F5C\u3002create \u5EFA\u7ACB\u56E2\u961F\uFF0Crun \u5F00\u59CB\u4E00\u6279\u8BA8\u8BBA\u3002\u8FD0\u884C\u65F6\u5360\u7528\u6210\u5458\uFF1Bpause \u505C\u6B62\u65B0\u5B89\u6392\uFF0C\u5141\u8BB8\u5728\u9014\u5DE5\u4F5C\u6536\u5C3E\uFF0C\u4E4B\u540E\u53EF\u79C1\u4EBA send\uFF1B\u4E2D\u6B62\u6210\u5458\u7528 pbot_agent stop\u3002close \u4FDD\u7559\u6210\u5458\u548C\u5386\u53F2\uFF1B\u6362\u6210\u5458\u987B\u5173\u95ED\u65E7\u56E2\u961F\u518D\u521B\u5EFA\u3002\u7EE7\u7EED\u8BA8\u8BBA\u7528 run \u63D0\u4EA4\u65B0\u8981\u6C42\u3002\u56E2\u961F\u72B6\u6001\u4E0E\u6279\u6B21\u7528 status\uFF1B\u516C\u5171\u539F\u6587\u7528 pbot_team_message read/post\u3002";
3
- export declare const teamMessageDescription = "\u8BFB\u5199\u56E2\u961F\u516C\u5171\u539F\u6587\u3002post \u5411\u5168\u4F53\u6210\u5458\u53D1\u5E03\u4FE1\u606F\uFF0C\u9700\u8981\u5B89\u6392\u56DE\u7B54\u65F6\u7531\u4E3B\u4F1A\u8BDD\u8C03\u7528 pbot_team run\uFF1B\u6210\u5458\u53EA\u80FD\u5728\u81EA\u5DF1\u7684\u56E2\u961F\u5DE5\u4F5C\u4E2D post\u3002read \u7528 afterSeq \u7FFB\u9875\uFF0C\u957F\u6B63\u6587\u6309 seq/offset \u7EED\u8BFB\uFF0C\u5148\u8865\u5B8C nextOffset \u975E\u7A7A\u7684\u6D88\u606F\u3002";
4
- export declare const teamParametersSchema: Type.TObject<{
5
- instruction: Type.TOptional<Type.TUnion<[Type.TString, Type.TNull]>>;
6
- mode: Type.TOptional<Type.TUnion<[Type.TUnion<[Type.TLiteral<"roundRobin">, Type.TLiteral<"parallel">]>, Type.TNull]>>;
7
- rounds: Type.TOptional<Type.TUnion<[Type.TInteger, Type.TNull]>>;
8
- maxConcurrent: Type.TOptional<Type.TUnion<[Type.TInteger, Type.TNull]>>;
9
- timeoutSeconds: Type.TOptional<Type.TUnion<[Type.TInteger, Type.TNull]>>;
10
- action: Type.TUnion<Type.TLiteral<string>[]>;
11
- teamId: Type.TOptional<Type.TUnion<[Type.TString, Type.TNull]>>;
12
- name: Type.TOptional<Type.TUnion<[Type.TString, Type.TNull]>>;
13
- brief: Type.TOptional<Type.TUnion<[Type.TString, Type.TNull]>>;
14
- members: Type.TOptional<Type.TUnion<[Type.TArray<Type.TObject<{
15
- agentId: Type.TString;
16
- role: Type.TString;
17
- }>>, Type.TNull]>>;
18
- }>;
19
- export type TeamMember = {
20
- agentId: string;
21
- role: string;
22
- };
23
- export type TeamInput = {
24
- action: "create";
25
- name: string;
26
- brief: string;
27
- members: TeamMember[];
28
- } | {
29
- action: "list";
30
- } | {
31
- action: "status" | "pause" | "close";
32
- teamId: string;
33
- } | {
34
- action: "run";
35
- teamId: string;
36
- instruction: string;
37
- mode: "roundRobin" | "parallel";
38
- rounds?: number;
39
- maxConcurrent?: number;
40
- timeoutSeconds?: number;
41
- };
42
- export declare function teamInput(value: unknown): TeamInput;
43
- export declare const teamMessageParametersSchema: Type.TObject<{
44
- afterSeq: Type.TOptional<Type.TUnion<[Type.TInteger, Type.TNull]>>;
45
- seq: Type.TOptional<Type.TUnion<[Type.TInteger, Type.TNull]>>;
46
- offset: Type.TOptional<Type.TUnion<[Type.TInteger, Type.TNull]>>;
47
- limit: Type.TOptional<Type.TUnion<[Type.TInteger, Type.TNull]>>;
48
- action: Type.TUnion<[Type.TLiteral<"read">, Type.TLiteral<"post">]>;
49
- teamId: Type.TOptional<Type.TUnion<[Type.TString, Type.TNull]>>;
50
- text: Type.TOptional<Type.TUnion<[Type.TString, Type.TNull]>>;
51
- replyTo: Type.TOptional<Type.TUnion<[Type.TInteger, Type.TNull]>>;
52
- }>;
53
- export type TeamMessageInput = {
54
- action: "read";
55
- teamId: string;
56
- afterSeq?: number;
57
- seq?: number;
58
- offset?: number;
59
- limit?: number;
60
- } | {
61
- action: "post";
62
- teamId: string;
63
- text: string;
64
- replyTo?: number;
65
- };
66
- export declare function teamMessageInput(value: unknown): TeamMessageInput;
67
- export declare const teamPageSchema: Type.TObject<{
68
- teamId: Type.TString;
69
- messages: Type.TArray<Type.TObject<{
70
- seq: Type.TInteger;
71
- operationId: Type.TString;
72
- author: Type.TObject<{
73
- kind: Type.TUnion<[Type.TLiteral<"user">, Type.TLiteral<"coordinator">, Type.TLiteral<"member">]>;
74
- agentId: Type.TOptional<Type.TString>;
75
- name: Type.TString;
76
- }>;
77
- text: Type.TString;
78
- replyTo: Type.TOptional<Type.TInteger>;
79
- runId: Type.TOptional<Type.TString>;
80
- source: Type.TOptional<Type.TObject<{
81
- requestId: Type.TString;
82
- cycleId: Type.TString;
83
- }>>;
84
- offset: Type.TInteger;
85
- totalLength: Type.TInteger;
86
- nextOffset: Type.TUnion<[Type.TInteger, Type.TNull]>;
87
- }>>;
88
- lastSeq: Type.TInteger;
89
- nextAfterSeq: Type.TUnion<[Type.TInteger, Type.TNull]>;
90
- }>;
91
- export declare const teamResultSchema: Type.TUnion<[Type.TUnion<[Type.TObject<{
92
- teamId: Type.TString;
93
- name: Type.TString;
94
- brief: Type.TString;
95
- closed: Type.TBoolean;
96
- owned: Type.TLiteral<true>;
97
- members: Type.TArray<Type.TObject<{
98
- agentId: Type.TString;
99
- role: Type.TString;
100
- name: Type.TString;
101
- state: Type.TString;
102
- }>>;
103
- lastSeq: Type.TInteger;
104
- activeCount: Type.TInteger;
105
- unresolved: Type.TArray<Type.TObject<{
106
- requestId: Type.TString;
107
- agentId: Type.TString;
108
- runId: Type.TString;
109
- round: Type.TInteger;
110
- active: Type.TBoolean;
111
- state: Type.TString;
112
- cycleId: Type.TOptional<Type.TString>;
113
- }>>;
114
- run: Type.TOptional<Type.TObject<{
115
- runId: Type.TString;
116
- instruction: Type.TString;
117
- mode: Type.TUnion<[Type.TLiteral<"roundRobin">, Type.TLiteral<"parallel">]>;
118
- state: Type.TUnion<[Type.TLiteral<"running">, Type.TLiteral<"paused">, Type.TLiteral<"finished">]>;
119
- rounds: Type.TInteger;
120
- maxConcurrent: Type.TInteger;
121
- deadlineAt: Type.TNumber;
122
- scheduled: Type.TInteger;
123
- published: Type.TInteger;
124
- reason: Type.TOptional<Type.TString>;
125
- }>>;
126
- }>, Type.TObject<{
127
- teamId: Type.TString;
128
- name: Type.TString;
129
- closed: Type.TBoolean;
130
- owned: Type.TLiteral<false>;
131
- }>]>, Type.TObject<{
132
- teams: Type.TArray<Type.TUnion<[Type.TObject<{
133
- teamId: Type.TString;
134
- name: Type.TString;
135
- brief: Type.TString;
136
- closed: Type.TBoolean;
137
- owned: Type.TLiteral<true>;
138
- members: Type.TArray<Type.TObject<{
139
- agentId: Type.TString;
140
- role: Type.TString;
141
- name: Type.TString;
142
- state: Type.TString;
143
- }>>;
144
- lastSeq: Type.TInteger;
145
- activeCount: Type.TInteger;
146
- unresolved: Type.TArray<Type.TObject<{
147
- requestId: Type.TString;
148
- agentId: Type.TString;
149
- runId: Type.TString;
150
- round: Type.TInteger;
151
- active: Type.TBoolean;
152
- state: Type.TString;
153
- cycleId: Type.TOptional<Type.TString>;
154
- }>>;
155
- run: Type.TOptional<Type.TObject<{
156
- runId: Type.TString;
157
- instruction: Type.TString;
158
- mode: Type.TUnion<[Type.TLiteral<"roundRobin">, Type.TLiteral<"parallel">]>;
159
- state: Type.TUnion<[Type.TLiteral<"running">, Type.TLiteral<"paused">, Type.TLiteral<"finished">]>;
160
- rounds: Type.TInteger;
161
- maxConcurrent: Type.TInteger;
162
- deadlineAt: Type.TNumber;
163
- scheduled: Type.TInteger;
164
- published: Type.TInteger;
165
- reason: Type.TOptional<Type.TString>;
166
- }>>;
167
- }>, Type.TObject<{
168
- teamId: Type.TString;
169
- name: Type.TString;
170
- closed: Type.TBoolean;
171
- owned: Type.TLiteral<false>;
172
- }>]>>;
173
- }>]>;
174
- export declare const teamMessageResultSchema: Type.TUnion<[Type.TObject<{
175
- teamId: Type.TString;
176
- messages: Type.TArray<Type.TObject<{
177
- seq: Type.TInteger;
178
- operationId: Type.TString;
179
- author: Type.TObject<{
180
- kind: Type.TUnion<[Type.TLiteral<"user">, Type.TLiteral<"coordinator">, Type.TLiteral<"member">]>;
181
- agentId: Type.TOptional<Type.TString>;
182
- name: Type.TString;
183
- }>;
184
- text: Type.TString;
185
- replyTo: Type.TOptional<Type.TInteger>;
186
- runId: Type.TOptional<Type.TString>;
187
- source: Type.TOptional<Type.TObject<{
188
- requestId: Type.TString;
189
- cycleId: Type.TString;
190
- }>>;
191
- offset: Type.TInteger;
192
- totalLength: Type.TInteger;
193
- nextOffset: Type.TUnion<[Type.TInteger, Type.TNull]>;
194
- }>>;
195
- lastSeq: Type.TInteger;
196
- nextAfterSeq: Type.TUnion<[Type.TInteger, Type.TNull]>;
197
- }>, Type.TObject<{
198
- teamId: Type.TString;
199
- seq: Type.TInteger;
200
- status: Type.TLiteral<"stored">;
201
- }>]>;
@@ -1,91 +0,0 @@
1
- import { Type } from "../../common/typebox.js";
2
- import { schema } from "../../common/schema.js";
3
- import { inputObject, need, nullable, pick } from "../input.js";
4
- export const teamDescription = "组织固定成员协作。create 建立团队,run 开始一批讨论。运行时占用成员;pause 停止新安排,允许在途工作收尾,之后可私人 send;中止成员用 pbot_agent stop。close 保留成员和历史;换成员须关闭旧团队再创建。继续讨论用 run 提交新要求。团队状态与批次用 status;公共原文用 pbot_team_message read/post。";
5
- export const teamMessageDescription = "读写团队公共原文。post 向全体成员发布信息,需要安排回答时由主会话调用 pbot_team run;成员只能在自己的团队工作中 post。read 用 afterSeq 翻页,长正文按 seq/offset 续读,先补完 nextOffset 非空的消息。";
6
- const id = Type.String({ minLength: 1, maxLength: 128 });
7
- const text = Type.String({ minLength: 1, maxLength: 24000 });
8
- const name = Type.String({ minLength: 1, maxLength: 64, pattern: "^[^\\r\\n\\x00-\\x1f]+$" });
9
- const mode = Type.Union([Type.Literal("roundRobin"), Type.Literal("parallel")], { description: "run 必填:roundRobin 按成员顺序轮流发言;parallel 在并发上限内发言,全员本轮完成后才进入下一轮。" });
10
- const members = Type.Array(Type.Object({ agentId: id, role: Type.String({ minLength: 1, maxLength: 4000 }) }, { additionalProperties: false }), {
11
- minItems: 1, maxItems: 50, description: "仅 create,必填:当前分支中的固定成员及职责;成员须版本兼容且未加入其他未关闭团队。",
12
- });
13
- const runFields = {
14
- instruction: nullable(Type.String({ ...text, description: "仅 run,必填:本批次的任务、约束与交付要求。" })),
15
- mode: nullable(mode),
16
- rounds: nullable(Type.Integer({ minimum: 1, maximum: 10, description: "仅 run:每位成员的轮数,默认 2。" })),
17
- maxConcurrent: nullable(Type.Integer({ minimum: 1, maximum: 50, description: "仅 run:roundRobin 默认且只允许 1;parallel 默认 min(2, 成员数)。不得超过成员数;待处理和执行中的发言都计入上限。" })),
18
- timeoutSeconds: nullable(Type.Integer({ minimum: 1, maximum: 86400, description: "仅 run:整批期限,默认 900 秒,包含所有轮次和等待。到期停止安排并尝试中止尚未人工接管的工作,之后仍须核对实际状态;pause 则允许在途工作收尾。" })),
19
- };
20
- const object = (fields) => Type.Object(fields, { additionalProperties: false });
21
- export const teamParametersSchema = object({
22
- action: Type.Union(["create", "list", "status", "run", "pause", "close"].map(value => Type.Literal(value)), {
23
- description: "create 必填 name/brief/members;list 只需 action;status/pause/close 必填 teamId;run 必填 teamId/instruction/mode,可选 rounds/maxConcurrent/timeoutSeconds。动作只读取自己的字段;其他已声明字段忽略。run 前须确认所有成员存活、idle、可参与团队且无待处理私人输入,团队未关闭,也无运行批次或在途工作。close 前先暂停并等待在途工作结束。",
24
- }),
25
- teamId: nullable(id), name: nullable(name), brief: nullable(text), members: nullable(members), ...runFields,
26
- });
27
- const validTeam = schema(teamParametersSchema);
28
- export function teamInput(value) {
29
- const args = inputObject(value, validTeam, "团队参数格式无效");
30
- const action = args.action;
31
- switch (action) {
32
- case "create":
33
- return { action, name: need("create", args, "name"), brief: need("create", args, "brief"), members: need("create", args, "members") };
34
- case "list":
35
- return { action };
36
- case "status":
37
- case "pause":
38
- case "close":
39
- return { action, teamId: need(action, args, "teamId") };
40
- case "run":
41
- return { action, teamId: need("run", args, "teamId"), instruction: need("run", args, "instruction"), mode: need("run", args, "mode"),
42
- ...(args.rounds === undefined ? {} : { rounds: args.rounds }),
43
- ...(args.maxConcurrent === undefined ? {} : { maxConcurrent: args.maxConcurrent }),
44
- ...(args.timeoutSeconds === undefined ? {} : { timeoutSeconds: args.timeoutSeconds }) };
45
- default:
46
- throw new Error("未知的团队 action。");
47
- }
48
- }
49
- const page = {
50
- afterSeq: nullable(Type.Integer({ minimum: 0, description: "仅 read:读取序号大于此值的消息,默认 0,不得超过 lastSeq。返回 nextAfterSeq 用于继续消息列表;单条续读使用 seq/offset,省略 afterSeq。先补完被截断的正文,再继续列表。" })),
51
- seq: nullable(Type.Integer({ minimum: 1, description: "仅 read:指定一条消息,配合该消息的 nextOffset 续读。未指定时从 afterSeq 后顺序读取。" })),
52
- offset: nullable(Type.Integer({ minimum: 0, description: "仅 read:指定 seq 的正文 UTF-16 字符偏移,默认 0;非零时必须同时提供 seq。" })),
53
- limit: nullable(Type.Integer({ minimum: 1, maximum: 16000, description: "仅 read:本页所有消息正文合计的 UTF-16 字符上限,默认 16000,不是消息条数或 token 数;不含元数据和 Markdown 格式开销。" })),
54
- };
55
- export const teamMessageParametersSchema = object({
56
- action: Type.Union([Type.Literal("read"), Type.Literal("post")], {
57
- description: "read 必填 teamId,可选 afterSeq/seq/offset/limit;post 必填 teamId/text,可选 replyTo。动作只读取自己的字段;其他已声明字段忽略。",
58
- }), teamId: nullable(id), text: nullable(Type.String({ ...text, description: "仅 post,必填:向全体成员公开的原文。" })),
59
- replyTo: nullable(Type.Integer({ minimum: 1, description: "仅 post:回复已有消息的 seq。" })), ...page,
60
- });
61
- const validMessage = schema(teamMessageParametersSchema);
62
- export function teamMessageInput(value) {
63
- const args = inputObject(value, validMessage, "团队消息参数格式无效");
64
- if (args.action === "read")
65
- return { action: "read", teamId: need("read", args, "teamId"),
66
- ...pick(args, ["afterSeq", "seq", "offset", "limit"]) };
67
- if (args.action === "post")
68
- return { action: "post", teamId: need("post", args, "teamId"), text: need("post", args, "text"),
69
- ...(args.replyTo === undefined ? {} : { replyTo: args.replyTo }) };
70
- throw new Error("未知的团队消息 action。");
71
- }
72
- const message = object({ seq: Type.Integer(), operationId: Type.String(),
73
- author: object({ kind: Type.Union([Type.Literal("user"), Type.Literal("coordinator"), Type.Literal("member")]), agentId: Type.Optional(id), name: Type.String() }),
74
- text: Type.String(), replyTo: Type.Optional(Type.Integer()), runId: Type.Optional(id),
75
- source: Type.Optional(object({ requestId: id, cycleId: id })),
76
- offset: Type.Integer(), totalLength: Type.Integer({ description: "完整正文的 UTF-16 字符数。" }),
77
- nextOffset: Type.Union([Type.Integer(), Type.Null()], { description: "非 null 表示本条正文尚未读完;使用相同 teamId、seq 和此 offset 续读。" }) });
78
- export const teamPageSchema = object({ teamId: id, messages: Type.Array(message), lastSeq: Type.Integer(),
79
- nextAfterSeq: Type.Union([Type.Integer(), Type.Null()], { description: "后续消息列表的 afterSeq;null 只表示列表已到末尾,仍须检查每条消息的 nextOffset。指定 seq 时始终为 null。" }) });
80
- const ownedView = object({ teamId: id, name: Type.String(), brief: Type.String(), closed: Type.Boolean(), owned: Type.Literal(true),
81
- members: Type.Array(object({ agentId: id, role: Type.String(), name: Type.String(), state: Type.String() })),
82
- lastSeq: Type.Integer(), activeCount: Type.Integer({ description: "各批次仍在途的请求数;paused 时也可能大于 0。" }),
83
- unresolved: Type.Array(object({ requestId: id, agentId: id, runId: id, round: Type.Integer(), active: Type.Boolean(),
84
- state: Type.String({ description: "queued=待处理;accepted=在途;uncertain=结果未确认;cancelled=未执行或已取消;unpublished=已完成但结果尚未公开;mixed/interactive=含人工或私人工作,不自动公开;failed/interrupted=失败或中断。" }), cycleId: Type.Optional(id) }), {
85
- description: "各批次尚未确认完成且公开的请求。先核对原请求和实际结果,再决定后续操作,避免重复执行。",
86
- }),
87
- run: Type.Optional(object({ runId: id, instruction: Type.String(), mode, state: Type.Union([Type.Literal("running"), Type.Literal("paused"), Type.Literal("finished")]),
88
- rounds: Type.Integer(), maxConcurrent: Type.Integer(), deadlineAt: Type.Number(), scheduled: Type.Integer(), published: Type.Integer(), reason: Type.Optional(Type.String()) })) });
89
- const view = Type.Union([ownedView, object({ teamId: id, name: Type.String(), closed: Type.Boolean(), owned: Type.Literal(false) })]);
90
- export const teamResultSchema = Type.Union([view, object({ teams: Type.Array(view) })]);
91
- export const teamMessageResultSchema = Type.Union([teamPageSchema, object({ teamId: id, seq: Type.Integer(), status: Type.Literal("stored") })]);
@@ -1,8 +0,0 @@
1
- import type { Context } from "@deepseek-ai/cordis";
2
- import type { Agent } from "@deepseek-ai/dsh-agent";
3
- import type { TeamService } from "../../services/agents/team-service.js";
4
- import type { AgentService } from "../../services/agents/agent-service.js";
5
- import type { AgentOwner } from "../../model/agent.js";
6
- import type { TeamActor } from "../../model/team.js";
7
- export declare function registerDshTeamTool(ctx: Context, agent: Agent, service: TeamService, agents: AgentService, owner: AgentOwner, check: () => void): void;
8
- export declare function registerDshTeamMessageTool(ctx: Context, agent: Agent, service: TeamService, actor: () => TeamActor, check: () => void): void;
@@ -1,39 +0,0 @@
1
- import { dshParameters, dshOutputSchema } from "../../integrations/dsh/schema.js";
2
- import { object } from "../../common/json.js";
3
- import { requireThat } from "../../common/validation.js";
4
- import { schema } from "../../common/schema.js";
5
- import { markdownFields } from "../../common/markdown.js";
6
- import { teamMessagesMarkdown } from "../../integrations/team-context.js";
7
- import { executeTeam, executeTeamMessage } from "./actions.js";
8
- import { teamDescription, teamMessageDescription, teamInput, teamMessageInput, teamParametersSchema, teamResultSchema, teamMessageParametersSchema, teamMessageResultSchema } from "./contract.js";
9
- export function registerDshTeamTool(ctx, agent, service, agents, owner, check) {
10
- const validOutput = schema(teamResultSchema);
11
- ctx.tools.register({ name: "pbot_team", description: teamDescription, parameters: dshParameters(teamParametersSchema),
12
- output: { schema: dshOutputSchema(teamResultSchema), render: (_args, value) => [{ type: "text", text: "# 团队\n\n" + markdownFields(value) }] },
13
- async execute(args, exec) {
14
- check();
15
- exec.signal.throwIfAborted();
16
- requireThat(exec.agent === agent, "团队工具不属于当前会话。");
17
- const value = executeTeam(service, agents, teamInput(args), owner).structuredContent;
18
- requireThat(validOutput(value), "团队输出不符合契约。");
19
- return value;
20
- },
21
- });
22
- }
23
- export function registerDshTeamMessageTool(ctx, agent, service, actor, check) {
24
- const validOutput = schema(teamMessageResultSchema);
25
- ctx.tools.register({ name: "pbot_team_message", description: teamMessageDescription, parameters: dshParameters(teamMessageParametersSchema),
26
- output: {
27
- schema: dshOutputSchema(teamMessageResultSchema),
28
- render: (args, value) => [{ type: "text", text: object(args) && args.action === "read"
29
- ? teamMessagesMarkdown(value) : "# 团队消息\n\n" + markdownFields(value) }],
30
- },
31
- async execute(args, exec) {
32
- check();
33
- exec.signal.throwIfAborted();
34
- requireThat(exec.agent === agent, "团队消息工具不属于当前会话。");
35
- const value = executeTeamMessage(service, teamMessageInput(args), actor(), exec.callId).structuredContent;
36
- requireThat(validOutput(value), "团队消息输出不符合契约。");
37
- return value;
38
- }, });
39
- }
@@ -1,5 +0,0 @@
1
- import type { Context } from "@deepseek-ai/cordis";
2
- import type { CommandSubmitAttachment } from "@deepseek-ai/dsh-commands/types";
3
- import type { SessionId } from "@deepseek-ai/dsh-session/types";
4
- /** Native commands admit encoded images and resolve session-owned file receipts. */
5
- export declare function commandAttachments(ctx: Context, sessionId: SessionId, files: readonly File[], signal: AbortSignal, progress: (message: string) => void): Promise<CommandSubmitAttachment[]>;
@@ -1,39 +0,0 @@
1
- const images = new Set(["image/png", "image/jpeg", "image/webp", "image/gif"]);
2
- function encodedImage(file, signal) {
3
- signal.throwIfAborted();
4
- return new Promise((resolve, reject) => {
5
- const reader = new FileReader(), abort = () => reader.abort();
6
- signal.addEventListener("abort", abort, { once: true });
7
- reader.onloadend = () => signal.removeEventListener("abort", abort);
8
- reader.onerror = () => reject(reader.error ?? new Error("图片读取失败。"));
9
- reader.onabort = () => reject(signal.reason ?? new DOMException("图片读取已取消。", "AbortError"));
10
- reader.onload = () => {
11
- if (typeof reader.result !== "string")
12
- reject(new Error("图片读取失败。"));
13
- else
14
- resolve(reader.result.slice(reader.result.indexOf(",") + 1));
15
- };
16
- reader.readAsDataURL(file);
17
- });
18
- }
19
- /** Native commands admit encoded images and resolve session-owned file receipts. */
20
- export async function commandAttachments(ctx, sessionId, files, signal, progress) {
21
- if (files.length > 32)
22
- throw new Error("一次最多附加 32 个文件。");
23
- const attachments = [];
24
- for (const file of files) {
25
- signal.throwIfAborted();
26
- progress("正在准备附件:" + file.name);
27
- if (images.has(file.type)) {
28
- attachments.push({ type: "image", mediaType: file.type, name: file.name, data: await encodedImage(file, signal) });
29
- }
30
- else {
31
- const result = await ctx.fileUpload.upload(sessionId, file, file.name, signal, value => progress(`正在上传 ${file.name}:${value.loaded} / ${value.total ?? file.size} 字节`));
32
- if (!result.ok)
33
- throw new Error(result.error.message);
34
- attachments.push({ type: "file", receiptId: result.value.receiptId });
35
- }
36
- }
37
- signal.throwIfAborted();
38
- return attachments;
39
- }
@@ -1 +0,0 @@
1
- 需要专家协助时使用 Claude 原生 Agent 与 personal-bot:general-purpose;需要成员直接交流时使用原生团队及成员消息。原生团队的可用性与恢复遵循当前 Claude 配置。
@@ -1 +0,0 @@
1
- 需要专家协助时用 pbot_agent;团队组织与批次用 pbot_team,团队公共原文用 pbot_team_message read/post。回溯旧讨论用 pbot_history。
@@ -1,7 +0,0 @@
1
- ## 本次团队工作
2
-
3
- 按当前职责和轮次接续已有工作,用 pbot_team_message read/post 交流;发言后继续本轮任务,无需等待回应。
4
-
5
- post 和本次请求的最终答复会向全体成员公开。分享与本次协作有关的内容,省略无关的私人历史和工具输出。
6
-
7
- 需要更多上下文或正文不完整时,按返回的 seq/offset 读取原文。
@@ -1,210 +0,0 @@
1
- import { randomUUID } from "node:crypto";
2
- import type { ExtensionAPI, ExtensionContext, CustomMessageEntryDraft, SessionBoundaryDraft } from "@earendil-works/pi-coding-agent";
3
- import type { Lifecycle } from "./lifecycle.js";
4
- import type { Confirmations } from "../ui/confirmation.js";
5
- import { agentOwner, deliveredCycles } from "../integrations/pi/agent-context.js";
6
- import { agentBoard } from "../ui/agent-display.js";
7
- import { deliveredTeams } from "../integrations/pi/team-context.js";
8
- import type { TeamInput } from "../model/team.js";
9
- import { agentNotice, teamNotice } from "../services/agents/agent-notices.js";
10
- import { markdownFields } from "../common/markdown.js";
11
-
12
- export function registerAgentEvents(pi: ExtensionAPI, lifecycle: Lifecycle, confirmations: Confirmations) {
13
- let ctx: ExtensionContext | undefined, timer: ReturnType<typeof setInterval> | undefined;
14
- let paused = false, epoch = 0, refreshEpoch = 0;
15
- let refreshing: Promise<void> | undefined;
16
- let controlBusySince: number | undefined;
17
- let recoveredFailure: string | undefined;
18
- let failure: { key: string; error: string; recovery: "retry" | "repair" | "reload" } | undefined;
19
- const recordFailure = (error: unknown) => {
20
- const busy = (error as NodeJS.ErrnoException).code === "PBOT_CONTROL_BUSY";
21
- if (busy) {
22
- controlBusySince ??= Date.now();
23
- if (Date.now() - controlBusySince < 5000) return;
24
- } else controlBusySince = undefined;
25
- let recovery: "retry" | "repair" | "reload" = busy ? "retry" : "repair";
26
- try { lifecycle.active?.teams.check(); } catch { recovery = "reload"; }
27
- // A stronger recovery requirement needs a new notice even if the earlier one was delivered.
28
- if (!failure || (failure.recovery !== recovery && (failure.recovery === "retry" || recovery === "reload"))) {
29
- failure = { key: "agent-error:" + randomUUID(), error: String(error), recovery };
30
- }
31
- if (ctx?.hasUI) ctx.ui.setStatus("pbot-agents-error", String(error));
32
- };
33
- const submitting = new Map<string, number>();
34
- // Only a lock-busy, not-yet-published input is retried in this runtime. Reload discards this map.
35
- const dispatching = new Map<string, TeamInput>();
36
- let pausePending = false;
37
- const approving = new Map<string, AbortController>();
38
- const collectPermissions = () => {
39
- const instance = lifecycle.active, context = ctx, revision = epoch;
40
- if (!instance || !context) return;
41
- const requests = instance.agents.pendingPermissions(agentOwner(context));
42
- const pending = new Set(requests.map(request => request.agentId + ":" + request.requestId));
43
- for (const [key, controller] of approving) if (!pending.has(key)) { controller.abort(); approving.delete(key); }
44
- for (const request of requests) {
45
- const key = request.agentId + ":" + request.requestId;
46
- if (approving.has(key)) continue;
47
- const controller = new AbortController(); approving.set(key, controller);
48
- void (async () => {
49
- const allow = request.options.find(option => option.kind === "allow_once");
50
- const reject = request.options.find(option => option.kind === "reject_once");
51
- const accepted = context.hasUI && allow ? await confirmations.ask(context, request.name + " 请求确认", request.description,
52
- AbortSignal.any([controller.signal, instance.signal()])) : false;
53
- if (controller.signal.aborted || epoch !== revision || lifecycle.active !== instance || !ctx) return;
54
- instance.agents.answerPermission(request.agentId, request.requestId, accepted ? allow!.optionId : reject?.optionId ?? null, agentOwner(ctx));
55
- })().catch(error => { if (!controller.signal.aborted && epoch === revision) recordFailure(error); }).finally(() => {
56
- if (approving.get(key) === controller) approving.delete(key);
57
- });
58
- }
59
- };
60
- const pauseTeams = () => {
61
- const instance = lifecycle.active;
62
- if (!ctx || !instance) return;
63
- pausePending = true;
64
- try { instance.teams.pauseAll(agentOwner(ctx), "主会话中断"); pausePending = false; dispatching.clear(); }
65
- catch (error) {
66
- const busy = (error as NodeJS.ErrnoException).code === "PBOT_CONTROL_BUSY";
67
- if (!busy) instance.teams.fail(error);
68
- recordFailure(error);
69
- if (!busy) throw error;
70
- }
71
- };
72
- const collectNotification = async (): Promise<CustomMessageEntryDraft | undefined> => {
73
- const instance = lifecycle.active, revision = epoch;
74
- if (!ctx || !instance || paused || ctx.signal?.aborted) return;
75
- const delivered = new Set([...deliveredCycles(ctx), ...deliveredTeams(ctx)]), now = Date.now();
76
- for (const [key, at] of submitting) if (delivered.has(key) || now - at > 5000) submitting.delete(key);
77
- const owner = agentOwner(ctx);
78
- let note: ReturnType<typeof teamNotice> | ReturnType<typeof agentNotice> = teamNotice(
79
- instance.teams.notifications(owner, instance.agents.list(owner)), new Set([...delivered, ...submitting.keys()]));
80
- if (!note) {
81
- const links = instance.teams.links(), completions = await instance.agents.completions(owner);
82
- if (!ctx || lifecycle.active !== instance || revision !== epoch || paused || ctx.signal?.aborted) return;
83
- note = agentNotice(completions, links, new Set([...deliveredCycles(ctx), ...deliveredTeams(ctx), ...submitting.keys()]));
84
- }
85
- if (!note) return;
86
- for (const key of note.keys) submitting.set(key, Date.now());
87
- return { type: "custom_message", customType: note.kind === "teams" ? "pbot.team-results" : "pbot.agent-results",
88
- display: true, content: note.content, details: { keys: note.keys } };
89
- };
90
- const notification = async (): Promise<CustomMessageEntryDraft | undefined> => {
91
- if (!ctx || !lifecycle.active || paused || ctx.signal?.aborted) return;
92
- const instance = lifecycle.active, revision = epoch;
93
- if (!failure) {
94
- try {
95
- const message = await collectNotification();
96
- if (message) return message;
97
- if (!ctx || revision !== epoch || instance !== lifecycle.active || paused || ctx.signal?.aborted || failure || !recoveredFailure || controlBusySince !== undefined) return;
98
- const delivered = deliveredCycles(ctx), key = recoveredFailure + ":recovered";
99
- if (!delivered.has(recoveredFailure) || delivered.has(key)) return;
100
- const now = Date.now(), sent = submitting.get(key);
101
- if (sent !== undefined && now - sent < 5000) return;
102
- submitting.set(key, now);
103
- return { type: "custom_message", customType: "pbot.agent-recovered", display: true,
104
- content: "# 子会话自动跟进已恢复\n\n后台扫描已恢复。成员状态和报告可通过 pbot_agent status/read 查看。",
105
- details: { keys: [key], failureKey: recoveredFailure } };
106
- }
107
- catch (error) { if (revision !== epoch || instance !== lifecycle.active) return; recordFailure(error); }
108
- }
109
- if (!ctx || !failure || deliveredCycles(ctx).has(failure.key)) return;
110
- const now = Date.now(), sent = submitting.get(failure.key);
111
- if (sent !== undefined && now - sent < 5000) return;
112
- submitting.set(failure.key, now);
113
- const recovery = failure.recovery === "reload"
114
- ? "团队服务或协作存储已停用,修复文件后当前实例仍不可用。先按错误信息排障,再请用户在当前 Pi 会话执行 /reload;重载前不要反复调用 pbot_team。重载后用 pbot_team status 与 pbot_team_message read 核对团队状态与公共原文。"
115
- : failure.recovery === "retry"
116
- ? "团队控制锁持续被占用,后台会继续重试;锁释放后自动恢复扫描,不自动删除锁或重新提交任务。"
117
- : "报告或控制记录读取失败。先按错误信息排障;修复后后台扫描会重试。";
118
- return { type: "custom_message", customType: "pbot.agent-error", display: true,
119
- content: ["# 子会话自动跟进故障", "", recovery,
120
- ...(pausePending ? ["", "团队暂停尚未确认,不能据此开始成员私人任务。"] : []), "",
121
- "用 pbot_agent list/status 查询成员状态,pbot_agent read 读取可用报告。重试前先查看原请求结果,避免重复执行。", "",
122
- markdownFields({ error: failure.error })].join("\n"), details: { keys: [failure.key] } };
123
- };
124
- const refreshWork = async () => {
125
- const instance = lifecycle.active, revision = epoch;
126
- if (!ctx || !instance) return;
127
- try {
128
- instance.agentOwner = agentOwner(ctx);
129
- await instance.agents.refresh(instance.agentOwner);
130
- collectPermissions();
131
- const completed = await instance.agents.completions(instance.agentOwner);
132
- if (!ctx || lifecycle.active !== instance || revision !== epoch) return;
133
- const values = instance.agents.list(instance.agentOwner);
134
- try {
135
- instance.teams.recover(instance.agentOwner);
136
- if (pausePending) pauseTeams();
137
- if (!pausePending) {
138
- for (const input of instance.teams.advance(instance.agentOwner, values, completed)) dispatching.set(input.requestId, input);
139
- for (const [id, input] of dispatching) {
140
- try { instance.agents.enqueueTeam(input, instance.agentOwner); dispatching.delete(id); }
141
- catch (error) {
142
- const code = (error as NodeJS.ErrnoException).code;
143
- if (code !== "TEAM_INPUT_STALE") throw error;
144
- dispatching.delete(id); instance.teams.pauseMember(input.agentId, "安排失效;未自动重发");
145
- }
146
- }
147
- }
148
- } catch (error) {
149
- if ((error as NodeJS.ErrnoException).code !== "PBOT_CONTROL_BUSY") { instance.teams.fail(error); dispatching.clear(); }
150
- throw error;
151
- }
152
- if (ctx.hasUI) {
153
- const teams = instance.teams.list(instance.agentOwner, values);
154
- ctx.ui.setStatus("pbot-teams", teams.length ? "团队 " + teams.filter(t => t.owned && t.run?.state === "running").length + " 运行 / " + teams.length : undefined);
155
- }
156
- if (ctx.mode === "tui") ctx.ui.setWidget("pbot-agents", values.some(v => ["starting", "busy", "stopping"].includes(v.state)) ? (_tui, theme) => agentBoard(values, theme) : undefined);
157
- if (!pausePending) {
158
- if (failure) recoveredFailure = failure.key;
159
- failure = undefined; controlBusySince = undefined;
160
- if (ctx.hasUI) ctx.ui.setStatus("pbot-agents-error", undefined);
161
- }
162
- } catch (error) {
163
- if (revision !== epoch || instance !== lifecycle.active) return;
164
- recordFailure(error);
165
- }
166
- if (ctx?.isIdle() && !paused) {
167
- const message = await notification();
168
- if (message && revision === epoch && instance === lifecycle.active && ctx?.isIdle() && !paused) pi.sendMessage(message, { triggerTurn: true, deliverAs: "steer" });
169
- }
170
- };
171
- const refresh = (): Promise<void> => {
172
- if (refreshing) return refreshEpoch === epoch ? refreshing : refreshing.then(() => refresh());
173
- refreshEpoch = epoch;
174
- const revision = epoch;
175
- const pending = refreshWork().catch(error => { if (revision === epoch) recordFailure(error); }).finally(() => {
176
- if (refreshing === pending) refreshing = undefined;
177
- });
178
- refreshing = pending;
179
- return pending;
180
- };
181
- const boundary = async (outcome: string, entries: SessionBoundaryDraft[], context: ExtensionContext) => {
182
- ctx = context;
183
- if (outcome === "aborted" || ctx.signal?.aborted) { paused = true; confirmations.pause(); pauseTeams(); return; }
184
- const revision = epoch, instance = lifecycle.active;
185
- const message = await notification();
186
- if (message && revision === epoch && instance === lifecycle.active && !paused && !ctx?.signal?.aborted) return { entries: [...entries, message], continue: true };
187
- return;
188
- };
189
- pi.on("session_start", (_event, context) => {
190
- epoch++; for (const controller of approving.values()) controller.abort(); approving.clear();
191
- ctx = context; paused = false; pausePending = false; controlBusySince = undefined; failure = undefined; recoveredFailure = undefined; confirmations.resume(); submitting.clear(); dispatching.clear();
192
- if (timer) clearInterval(timer);
193
- if (lifecycle.active) { lifecycle.active.agentOwner = agentOwner(ctx); timer = setInterval(() => { void refresh(); }, 1000); timer.unref(); }
194
- return refresh();
195
- });
196
- pi.on("input", (_event, context) => { ctx = context; paused = false; confirmations.resume(); });
197
- pi.on("before_agent_start", (_event, context) => { ctx = context; });
198
- pi.on("session_tree", (_event, context) => { epoch++; for (const controller of approving.values()) controller.abort(); approving.clear(); ctx = context; submitting.clear(); return refresh(); });
199
- pi.on("turn_end", (event, context) => boundary(event.outcome, event.entries, context));
200
- pi.on("agent_before_settle", (event, context) => boundary(event.outcome, event.entries, context));
201
- pi.on("agent_settled", (event, context) => {
202
- ctx = context; if (event.aborted) { paused = true; confirmations.pause(); pauseTeams(); }
203
- });
204
- pi.on("tool_result", event => {
205
- if (event.toolName !== "pbot_agent") return;
206
- const keys = (event.details as { agentReadKeys?: string[] } | undefined)?.agentReadKeys;
207
- if (keys?.length) pi.appendEntry("pbot.agent-read", { keys, toolCallId: event.parentToolCallId ?? event.toolCallId });
208
- });
209
- pi.on("session_shutdown", () => { epoch++; for (const controller of approving.values()) controller.abort(); approving.clear(); if (timer) clearInterval(timer); timer = undefined; submitting.clear(); dispatching.clear(); pausePending = false; ctx = undefined; });
210
- }