personal-bot 0.2.20 → 0.3.1

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 +95 -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 +43 -9
  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 +16 -21
  184. package/resources/skills/provider-connections/SKILL.md +24 -40
  185. package/resources/templates/workspace-agents.md +4 -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 +46 -8
  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,23 +1,21 @@
1
+ import { existsSync } from "node:fs";
1
2
  import { realpath } from "node:fs/promises";
2
- import { dshHomePath } from "@deepseek-ai/dsh-home-paths";
3
- import { AgentBackends } from "../../integrations/acp/agents.js";
3
+ import { resolve } from "node:path";
4
+ import * as McpClient from "@deepseek-ai/dsh-mcp-client";
4
5
  import { rootAgents } from "../../integrations/dsh/root-agents.js";
5
- import { DshAgents } from "../../integrations/dsh/dsh-agents.js";
6
- import { dshResources, dshExpertTools } from "../../integrations/dsh/resources.js";
7
- import { AgentService } from "../../services/agents/agent-service.js";
8
- import { TeamService } from "../../services/agents/team-service.js";
9
- import { registerDshAgentTool } from "../../tools/agents/dsh-tool.js";
10
- import { registerDshTeamTool, registerDshTeamMessageTool } from "../../tools/teams/dsh-tool.js";
11
- import { DshAgentRuntime } from "./agent-runtime.js";
12
- import { DshAgentEvents } from "./agent-events.js";
6
+ import { dshResources } from "../../integrations/dsh/resources.js";
13
7
  import { registerDshFileEvents } from "./files.js";
14
8
  import { DshHistoryWork, registerDshHistoryEvents } from "./history.js";
15
9
  import { registerDshHistoryTool } from "../../tools/history/dsh-tool.js";
10
+ import { resourceRoot } from "../../common/paths.js";
16
11
  import { requireThat } from "../../common/validation.js";
12
+ import { toDshMcpConfig } from "../../integrations/dsh/mcp.js";
17
13
  import { registerDshSkills } from "../../integrations/dsh/skills.js";
18
- import { readWorkspaceConfig, workspaceDisabledMessage } from "../../services/workspace/workspace-config.js";
14
+ import { readWorkspaceConfig, workspaceDisabledMessage, workspaceFeatures } from "../../services/workspace/workspace-config.js";
15
+ import { readWorkspaceMcpConfig, resolveWorkspaceMcpServer } from "../../services/workspace/workspace-mcp.js";
19
16
  import { initializeWorkspace } from "../../services/workspace/workspace-preparation.js";
20
- export const dshDependencies = ["agents", "sessions", "sessionPersistence", "sessionQuery", "llm", "tools", "systemPrompt", "skills", "fs", "attachments", "workingDirectory", "approval"];
17
+ import { McpWorkerRuntime, defaultWorkerDirectory } from "../mcp-workers.js";
18
+ export const dshDependencies = ["agents", "sessions", "sessionPersistence", "sessionQuery", "llm", "tools", "systemPrompt", "skills", "fs", "workingDirectory", "approval"];
21
19
  export class DshWorkspace {
22
20
  ctx;
23
21
  root;
@@ -25,96 +23,82 @@ export class DshWorkspace {
25
23
  component;
26
24
  historyWork;
27
25
  releaseHistory;
26
+ features;
28
27
  lifetime = new AbortController();
29
- host;
30
- agents;
31
- teams;
32
28
  history;
33
- owner;
34
- #experts = new Map();
29
+ workers;
35
30
  #scope;
36
- #events;
37
31
  #closing;
38
- constructor(ctx, root, agent, component, historyWork, releaseHistory, acp) {
32
+ constructor(ctx, root, agent, component, historyWork, releaseHistory, features = workspaceFeatures()) {
39
33
  this.ctx = ctx;
40
34
  this.root = root;
41
35
  this.agent = agent;
42
36
  this.component = component;
43
37
  this.historyWork = historyWork;
44
38
  this.releaseHistory = releaseHistory;
39
+ this.features = features;
45
40
  this.history = historyWork.service;
46
- this.owner = { sessionId: agent.id, leaf: null, branch: [] };
47
- this.host = new DshAgents(ctx, agent, {
48
- setup: (d, _directory, generation) => async (agentCtx, child) => {
49
- await agentCtx.plugin({ name: "pbot-expert", inject: dshDependencies, apply: async (scope) => {
50
- const runtime = new DshAgentRuntime(scope, child, d, generation, this.agents.files, this.teams, { check: this.check, release: () => this.host.release(d.agentId, generation) });
51
- this.#experts.set(d.agentId, runtime);
52
- scope.effect(() => () => { if (this.#experts.get(d.agentId) === runtime)
53
- this.#experts.delete(d.agentId); });
54
- registerDshSkills(scope, child);
55
- await dshResources(scope, child, root, "general-purpose", runtime.check);
56
- const teamTool = dshExpertTools(scope, child, d.options);
57
- if (teamTool)
58
- registerDshTeamMessageTool(scope, child, this.teams, runtime.actor, runtime.check);
59
- registerDshFileEvents(scope, child, root, true, runtime.check);
60
- runtime.initialize(teamTool);
61
- } });
62
- return { commit: this.check };
63
- },
64
- ready: (child, generation) => {
65
- const runtime = this.#experts.get(child.id);
66
- requireThat(runtime?.generation === generation, "专家执行组件未就绪。");
67
- runtime.start();
68
- },
69
- stopping: async (child, generation) => { const runtime = this.#experts.get(child.id); if (runtime?.generation === generation)
70
- await runtime.stop(); },
71
- }, this.lifetime.signal);
72
- const directory = dshHomePath("pbot", "subagents");
73
- this.agents = new AgentService(root, directory, new AgentBackends(this.host, directory, acp));
74
- this.teams = new TeamService(root, this.agents.files, this.agents.teamFiles);
41
+ this.workers = new McpWorkerRuntime(defaultWorkerDirectory(), agent.id, "dsh");
75
42
  }
76
43
  check = () => { this.component.throwIfAborted(); this.lifetime.signal.throwIfAborted(); };
77
- get controlError() { return this.#events?.error; }
78
44
  async open() {
79
45
  this.check();
80
- this.#scope = await this.agent.ctx.plugin({ name: "pbot-coordinator", inject: dshDependencies, apply: async (ctx) => {
81
- registerDshSkills(ctx, this.agent);
82
- await dshResources(ctx, this.agent, this.root, "coordinator", this.check);
46
+ const mcpEntry = resolve(resourceRoot, "../lib/extension/mcp.js");
47
+ const workerDir = defaultWorkerDirectory();
48
+ this.#scope = await this.agent.ctx.plugin({
49
+ name: "pbot-coordinator",
50
+ inject: dshDependencies,
51
+ apply: async (ctx) => {
52
+ if (this.features.skills)
53
+ registerDshSkills(ctx, this.agent, { workspaceRoot: this.root });
54
+ if (this.features.prompts)
55
+ await dshResources(ctx, this.agent, this.root, "coordinator", this.check, "history-coordinator.md");
83
56
  registerDshFileEvents(ctx, this.agent, this.root, false, this.check);
84
- registerDshAgentTool(ctx, this.agent, this.agents, this.owner, this.check);
85
- registerDshTeamTool(ctx, this.agent, this.teams, this.agents, this.owner, this.check);
86
- registerDshTeamMessageTool(ctx, this.agent, this.teams, () => ({ kind: "coordinator", owner: this.owner }), this.check);
87
57
  registerDshHistoryTool(ctx, this.agent, this.history, this.lifetime.signal, this.check);
88
58
  registerDshHistoryEvents(ctx, this.agent, this.historyWork, this.check);
89
- this.#events = new DshAgentEvents(ctx, this.agent, this.agents, this.teams, this.owner, this.check);
90
- this.#events.start();
91
- } });
92
- this.check();
93
- }
94
- async interact(id, text, delivery, files = [], attachments = [], signal) {
95
- const view = this.agents.status(id, this.owner);
96
- if (view.transport !== "acp")
97
- return this.expert(id).interact(text, delivery, files, attachments, signal);
98
- this.check();
99
- signal.throwIfAborted();
100
- requireThat(text.length <= 24000 && files.length + attachments.length <= 32 && (!files.length || !attachments.length), "人工消息或附件参数无效。");
101
- const paths = [...files, ...attachments.map(attachment => {
102
- const path = attachment.type === "image" ? this.ctx.attachments.imageHostPath(attachment.attachment) : this.ctx.attachments.fileHostPath(attachment.attachment);
103
- requireThat(path, "该原生附件存储不提供 ACP 子进程可读取的文件路径。");
104
- return path;
105
- })];
106
- requireThat(text.trim() || paths.length, "请输入消息或附加文件。");
107
- this.teams.pauseMember(id, "成员由人工接管");
108
- return this.agents.send(id, text || "请处理所附文件。", delivery ?? "followUp", this.owner, paths);
109
- }
110
- expert(id) {
59
+ if (existsSync(mcpEntry)) {
60
+ await ctx.plugin(McpClient, McpClient.Config({
61
+ transport: "stdio",
62
+ serverName: "pbot",
63
+ command: process.execPath,
64
+ args: [mcpEntry],
65
+ env: {
66
+ ...(process.env.PATH ? { PATH: process.env.PATH } : {}),
67
+ ...(process.env.HOME ? { HOME: process.env.HOME } : {}),
68
+ ...(process.env.DSH_HOME ? { DSH_HOME: process.env.DSH_HOME } : {}),
69
+ PBOT_HOST: "dsh",
70
+ PBOT_WORKSPACE_ROOT: this.root,
71
+ PBOT_MCP_AGENT_DIR: workerDir,
72
+ PBOT_MCP_SESSION_ID: this.agent.id,
73
+ },
74
+ cwd: this.root,
75
+ toolCallTimeoutMs: 600_000,
76
+ failOnStartupError: false,
77
+ }));
78
+ }
79
+ if (this.features.mcp) {
80
+ const mcpConfig = await readWorkspaceMcpConfig(this.root);
81
+ this.check();
82
+ if (mcpConfig.error) {
83
+ this.ctx.logger.warn(mcpConfig.error);
84
+ }
85
+ else {
86
+ for (const [serverName, server] of Object.entries(mcpConfig.servers)) {
87
+ if (server.enabled === false)
88
+ continue;
89
+ try {
90
+ const resolved = resolveWorkspaceMcpServer(this.root, serverName, server);
91
+ await ctx.plugin(McpClient, toDshMcpConfig(resolved));
92
+ }
93
+ catch (error) {
94
+ this.ctx.logger.warn(error instanceof Error ? error.message : String(error));
95
+ }
96
+ }
97
+ }
98
+ }
99
+ },
100
+ });
111
101
  this.check();
112
- const view = this.agents.status(id, this.owner), runtime = this.#experts.get(id);
113
- requireThat(view.owned, "专家不属于当前父会话。");
114
- requireThat(view.alive, "专家已停止;需要明确恢复后才能对话。");
115
- requireThat(view.state !== "starting", "专家尚未就绪,请等待启动或恢复完成。");
116
- requireThat(runtime?.generation === view.generation, "原生专家由其他执行实例持有;当前组件不能接管对话。");
117
- return runtime;
118
102
  }
119
103
  close() {
120
104
  if (this.#closing)
@@ -123,30 +107,11 @@ export class DshWorkspace {
123
107
  this.#closing = (async () => {
124
108
  const errors = [];
125
109
  try {
126
- await this.#events?.close();
110
+ await this.workers.close();
127
111
  }
128
112
  catch (error) {
129
113
  errors.push(error);
130
114
  }
131
- try {
132
- this.teams.pauseAll(this.owner, "父会话或执行组件关闭");
133
- }
134
- catch (error) {
135
- errors.push(error);
136
- }
137
- try {
138
- await this.agents.close(this.owner);
139
- }
140
- catch (error) {
141
- errors.push(error);
142
- }
143
- try {
144
- await this.host.close();
145
- }
146
- catch (error) {
147
- errors.push(error);
148
- }
149
- this.teams.dispose();
150
115
  try {
151
116
  await this.#scope?.dispose();
152
117
  }
@@ -160,7 +125,7 @@ export class DshWorkspace {
160
125
  errors.push(error);
161
126
  }
162
127
  if (errors.length)
163
- throw new AggregateError(errors, "dsh 工作区关闭失败;请核对执行资源和控制记录。");
128
+ throw new AggregateError(errors, "dsh 工作区关闭失败;请核对执行资源。");
164
129
  })();
165
130
  return this.#closing;
166
131
  }
@@ -194,7 +159,9 @@ export class DshWorkspaces {
194
159
  const owned = entry;
195
160
  owned.users++;
196
161
  let released = false;
197
- return { work: owned.work, release: async () => {
162
+ return {
163
+ work: owned.work,
164
+ release: async () => {
198
165
  if (released)
199
166
  return;
200
167
  released = true;
@@ -207,11 +174,12 @@ export class DshWorkspaces {
207
174
  this.#histories.delete(root);
208
175
  }
209
176
  }
210
- } };
177
+ },
178
+ };
211
179
  }
212
180
  async open(agent) {
213
181
  this.#lifetime.signal.throwIfAborted();
214
- requireThat(rootAgents(this.ctx.agents).includes(agent), "专家不拥有协调者管理入口。");
182
+ requireThat(rootAgents(this.ctx.agents).includes(agent), "子会话不拥有协调者管理入口。");
215
183
  const current = this.#parents.get(agent);
216
184
  if (current)
217
185
  return current;
@@ -235,7 +203,7 @@ export class DshWorkspaces {
235
203
  const history = await this.history(root);
236
204
  let workspace;
237
205
  try {
238
- workspace = new DshWorkspace(this.ctx, root, agent, this.#lifetime.signal, history.work, history.release, configuration.acp);
206
+ workspace = new DshWorkspace(this.ctx, root, agent, this.#lifetime.signal, history.work, history.release, workspaceFeatures(configuration));
239
207
  const owned = workspace;
240
208
  const dispose = agent.ctx.effect(() => async () => {
241
209
  this.#parents.delete(agent);
@@ -0,0 +1,41 @@
1
+ import { resolveWorkspaceMcpServers } from "../services/workspace/workspace-mcp.js";
2
+ export declare class WorkspaceMcpBridge {
3
+ #private;
4
+ discover(root: string, serverName?: string): Promise<{
5
+ workspace: string;
6
+ configPath: string;
7
+ servers: ({
8
+ url: string;
9
+ timeout?: number;
10
+ description?: string;
11
+ name: string;
12
+ transport: string;
13
+ enabled: boolean;
14
+ } | {
15
+ command: string;
16
+ args: string[];
17
+ timeout?: number;
18
+ description?: string;
19
+ name: string;
20
+ transport: string;
21
+ enabled: boolean;
22
+ })[];
23
+ } | {
24
+ tools: unknown[];
25
+ description?: string;
26
+ workspace: string;
27
+ server: string;
28
+ transport: "stdio" | "http";
29
+ configPath?: never;
30
+ servers?: never;
31
+ }>;
32
+ call(root: string, serverName: string, toolName: string, args?: Record<string, unknown>): Promise<{
33
+ structuredContent?: {} | null;
34
+ server: string;
35
+ tool: string;
36
+ isError: boolean;
37
+ content: any[];
38
+ }>;
39
+ close(): Promise<void>;
40
+ }
41
+ export { resolveWorkspaceMcpServers };