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,115 +1,257 @@
1
- import { readFile, writeFile } from "node:fs/promises";
2
- import { dirname, join, resolve } from "node:path";
1
+ import { dirname, resolve } from "node:path";
2
+ import type { RequestPermissionRequest } from "@agentclientprotocol/sdk";
3
3
  import { AgentFiles, descriptor, launch, status } from "../storage/agent-files.js";
4
4
  import { acpModelState, acpReference } from "../storage/acp-files.js";
5
- import type { AcpModelSelection } from "../model/acp.js";
5
+ import type { AcpModelSelection, AcpSessionReference } from "../model/acp.js";
6
6
  import { AcpAgentRun } from "../services/agents/acp-run.js";
7
7
  import { openAcp } from "../integrations/acp/connection.js";
8
- import { acpExecutable } from "../integrations/acp/launch.js";
9
- import { claudeOptions } from "../integrations/acp/claude.js";
10
8
  import { acpContent } from "../integrations/acp/input.js";
11
- import { agentText } from "../integrations/agent-resources.js";
9
+ import { toAcpMcpServers } from "../integrations/acp/mcp.js";
10
+ import { resolveAcpHarness } from "../integrations/acp/registry.js";
11
+ import { loadWorkspaceContext } from "../integrations/agent-resources.js";
12
+ import { readWorkspaceConfig, workspaceFeatures } from "../services/workspace/workspace-config.js";
13
+ import { readWorkspaceMcpConfig, resolveWorkspaceMcpServers } from "../services/workspace/workspace-mcp.js";
14
+ import { discoverWorkspaceSkills } from "../services/workspace/workspace-skills.js";
15
+ import { object } from "../common/json.js";
12
16
  import { resourceRoot } from "../common/paths.js";
13
17
  import { requireThat } from "../common/validation.js";
14
18
  import { packageVersion, releaseLine } from "../common/version.js";
15
- import type { NativeAgentHost } from "../model/agent.js";
16
19
 
17
- const args = process.argv.slice(2);
18
- const option = (name: string) => args[args.indexOf(name) + 1];
19
- const directory = option("--directory"), id = option("--pbot-acp-agent"), generation = option("--generation");
20
- requireThat(directory && id && generation, "缺少 ACP worker 启动信息。");
21
- const files = new AgentFiles(dirname(directory), option("--host") as NativeAgentHost);
22
- requireThat(files.directory(id) === directory, "ACP worker 目录不匹配。");
23
- const d = files.read(id, "descriptor.json", descriptor), reference = files.read(id, "acp-session.json", acpReference);
24
- requireThat(d.agentId === id && releaseLine(d.release) === releaseLine(packageVersion), "ACP worker 身份或版本不匹配。");
25
- const validating = args.includes("--validate"), lifetime = new AbortController();
26
- let execution: AcpAgentRun | undefined;
27
- const stop = () => { void execution?.stop().catch(error => lifetime.abort(error)); if (!execution) lifetime.abort(); };
28
- process.on("SIGTERM", stop); process.on("SIGINT", stop);
20
+ const errorMessage = (error: unknown) => error instanceof Error ? error.message : String(error);
29
21
 
30
- async function main() {
31
- requireThat(files.read(id!, "launch.json", launch).generation === generation, "ACP worker 启动代次已失效。");
32
- const env = { ...process.env, PBOT_SUBAGENT_RUN_ID: id!, PBOT_SUBAGENT_DIR: directory!, PBOT_SUBAGENT_GENERATION: generation!,
33
- ...(validating ? { PBOT_ACP_VALIDATE: "1" } : {}) };
34
- const command = { ...reference, args: [...reference.args] };
35
- const packageRoot = resolve(resourceRoot, "..");
36
- if (reference.backend === "pi") {
37
- Object.assign(env, { PBOT_ACP_PI_COMMAND: process.env.PI_ACP_PI_COMMAND ?? acpExecutable("pi", "pi"),
38
- PI_ACP_PI_COMMAND: join(packageRoot, "bin/pbot-pi-acp.mjs") });
39
- }
40
- if (reference.backend === "dsh") {
41
- const patch = join(directory!, "acp-dsh-patch.json");
42
- await writeFile(patch, JSON.stringify([{ insert: [{ id: "pbot-acp-member", name: join(packageRoot, "lib/extension/dsh/acp-member.js") }] }]) + "\n", { mode: 0o600 });
43
- command.args.push("--patch", patch);
44
- }
45
- let prompt: string | undefined;
46
- if (reference.backend === "claude") {
47
- prompt = [await readFile(join(resourceRoot, "prompts/workspace.md"), "utf8"), await agentText("general-purpose", d.workspace),
48
- JSON.stringify({ workspaceRoot: d.workspace, resourceRoot })].join("\n\n");
49
- }
50
- const saveSelection = (selection: AcpModelSelection) => {
51
- if (validating) return;
52
- const run = files.read(id!, "launch.json", launch);
53
- if (run.generation === generation && !run.stop) files.write(id!, "acp-model.json", { generation, ...selection }, acpModelState);
54
- };
55
- const claude = reference.backend === "claude" ? await claudeOptions(reference, d.cwd, d.options.thinking) : undefined;
56
- const connection = await openAcp(command, d.cwd, env, {
57
- selection: saveSelection,
58
- update(update) {
59
- if (update.sessionUpdate === "agent_message_chunk" && update.content.type === "text") execution?.update({ kind: "text", text: update.content.text,
60
- ...(update.messageId ? { messageId: update.messageId } : {}) });
61
- else if (update.sessionUpdate === "agent_thought_chunk") execution?.update({ kind: "thought" });
62
- else if (update.sessionUpdate === "tool_call" || update.sessionUpdate === "tool_call_update") execution?.update({ kind: update.sessionUpdate === "tool_call" ? "tool" : "activity", activity: update.name ?? update.title ?? "工具" });
63
- },
64
- async permission(request, signal) {
65
- if (!execution) return { outcome: { outcome: "cancelled" } };
66
- const selected = await execution.permission(JSON.stringify(request.toolCall, null, 2), request.options, signal);
67
- return { outcome: selected === null ? { outcome: "cancelled" } : { outcome: "selected", optionId: selected } };
68
- },
69
- }, lifetime.signal, prompt, claude);
22
+ function sendIpc(message: unknown): Promise<void> {
23
+ return new Promise(resolveSend => {
24
+ if (!process.connected || !process.send) { resolveSend(); return; }
25
+ process.send(message, undefined, undefined, () => resolveSend());
26
+ });
27
+ }
28
+
29
+ function permissionDescription(request: RequestPermissionRequest) {
30
+ const call = request.toolCall;
31
+ const detail = call.rawInput === undefined ? "" : JSON.stringify(call.rawInput);
32
+ return [call.title ?? "工具调用", call.kind ? "类型:" + call.kind : "", call.locations?.length ? "路径:" + call.locations.map(item => item.path).join(", ") : "",
33
+ detail ? "参数:" + (detail.length > 2000 ? detail.slice(0, 2000) + "…" : detail) : ""].filter(Boolean).join("\n");
34
+ }
35
+
36
+ async function runProbe() {
37
+ const lifetime = new AbortController();
38
+ const stop = () => lifetime.abort(new Error("ACP 模型探测已取消。"));
39
+ process.on("SIGTERM", stop);
40
+ process.on("SIGINT", stop);
70
41
  try {
71
- requireThat(!prompt || reference.backend !== "claude" || connection.systemPrompt, "Claude ACP 后端需要支持 systemPrompt,以加载专家职责与工作区资料。");
72
- if (validating) { if (process.connected) process.send?.({ type: "validated" }); return; }
73
- if (reference.sessionId === null) await connection.configure(d.options);
74
- requireThat(files.read(id!, "launch.json", launch).generation === generation && !files.read(id!, "launch.json", launch).stop, "ACP 启动已取消。");
75
- files.write(id!, "acp-session.json", { ...reference, sessionId: reference.backend === "dsh" || reference.sessionId !== null ? connection.sessionId : null, capabilities: connection.capabilities }, acpReference);
76
- saveSelection(connection.selection());
77
- execution = new AcpAgentRun(files, d, generation!, {
78
- signal: connection.signal,
79
- async prompt(request) {
80
- const content = await acpContent(request, connection.images, connection.signal);
81
- const run = files.read(id!, "launch.json", launch);
82
- requireThat(run.generation === generation && !run.stop, "ACP 输入已取消或启动代次变化。");
83
- connection.signal.throwIfAborted();
84
- const saved = files.read(id!, "acp-session.json", acpReference);
85
- if (saved.sessionId === null) files.write(id!, "acp-session.json", { ...saved, sessionId: connection.sessionId }, acpReference);
86
- return connection.prompt(content);
87
- },
88
- cancel: () => connection.cancel(),
89
- }, reference.backend !== "claude");
90
- await execution.run();
42
+ const payload = await new Promise<{ reference: AcpSessionReference; cwd: string; provider?: string; model?: string }>((resolvePayload, rejectPayload) => {
43
+ const timer = setTimeout(() => rejectPayload(new Error("缺少 ACP 模型探测参数。")), 5000);
44
+ process.once("message", (value: unknown) => {
45
+ clearTimeout(timer);
46
+ if (!object(value)) { rejectPayload(new Error("ACP 模型探测参数必须是对象。")); return; }
47
+ resolvePayload(value as { reference: AcpSessionReference; cwd: string; provider?: string; model?: string });
48
+ });
49
+ process.once("disconnect", () => { clearTimeout(timer); rejectPayload(new Error("ACP 模型探测通道已断开。")); });
50
+ });
51
+ const reference = acpReference(payload.reference);
52
+ requireThat(typeof payload.cwd === "string" && payload.cwd.length > 0, "缺少 ACP 模型探测目录。");
53
+ const env: NodeJS.ProcessEnv = { ...process.env, ...(reference.env ?? {}) };
54
+ const connection = await openAcp(reference, payload.cwd, env, {
55
+ update() {},
56
+ async permission() { return { outcome: { outcome: "cancelled" } }; },
57
+ }, lifetime.signal);
58
+ try {
59
+ if (payload.model) {
60
+ await connection.configure({
61
+ ...(payload.provider ? { provider: payload.provider } : {}),
62
+ model: payload.model,
63
+ });
64
+ }
65
+ await sendIpc({
66
+ type: "models",
67
+ result: {
68
+ backend: reference.backend,
69
+ ...connection.choices(),
70
+ selection: connection.selection(),
71
+ },
72
+ });
73
+ } finally {
74
+ await connection.close();
75
+ }
76
+ } catch (error) {
77
+ await sendIpc({ type: "error", error: errorMessage(error) });
78
+ process.exitCode = 1;
91
79
  } finally {
92
- try { await connection.close(); } finally { await execution?.settled(); }
80
+ lifetime.abort();
81
+ if (process.connected) process.disconnect();
93
82
  }
94
83
  }
95
84
 
96
- try {
97
- await main();
98
- if (!validating && files.read(id, "launch.json", launch).generation === generation) {
99
- if (execution) execution.execution.save({ state: "stopped", activity: "已停止" });
100
- else files.write(id, "status.json", { generation, state: "stopped", activity: "已停止", updatedAt: Date.now() }, status);
85
+ async function runWorker(args: string[]) {
86
+ const option = (name: string) => args[args.indexOf(name) + 1];
87
+ const directory = option("--directory"), id = option("--pbot-acp-agent"), generation = option("--generation");
88
+ requireThat(directory && id && generation, "缺少 ACP worker 启动信息。");
89
+ const files = new AgentFiles(dirname(directory));
90
+ requireThat(files.directory(id) === directory, "ACP worker 目录不匹配。");
91
+ const d = files.read(id, "descriptor.json", descriptor), reference = files.read(id, "acp-session.json", acpReference);
92
+ requireThat(d.agentId === id && releaseLine(d.release) === releaseLine(packageVersion), "ACP worker 身份或版本不匹配。");
93
+ const validating = args.includes("--validate"), lifetime = new AbortController();
94
+ let execution: AcpAgentRun | undefined;
95
+ const stop = () => { void execution?.stop().catch(error => lifetime.abort(error)); if (!execution) lifetime.abort(); };
96
+ process.on("SIGTERM", stop); process.on("SIGINT", stop);
97
+
98
+ async function main() {
99
+ requireThat(files.read(id!, "launch.json", launch).generation === generation, "ACP worker 启动代次已失效。");
100
+ const harness = resolveAcpHarness(reference.backend);
101
+ const exactAnswer = Boolean(harness.exactAnswer);
102
+ const packageRoot = resolve(resourceRoot, "..");
103
+ const configuration = await readWorkspaceConfig(d.workspace);
104
+ const features = workspaceFeatures(configuration);
105
+ const baseEnv: NodeJS.ProcessEnv = {
106
+ ...process.env,
107
+ PBOT_SUBAGENT_RUN_ID: id!,
108
+ PBOT_SUBAGENT_DIR: directory!,
109
+ PBOT_SUBAGENT_GENERATION: generation!,
110
+ ...(validating ? { PBOT_ACP_VALIDATE: "1" } : {}),
111
+ };
112
+ const prepared = harness.prepareLaunch
113
+ ? await harness.prepareLaunch({ reference, cwd: d.cwd, directory: directory!, packageRoot, options: d.options, env: baseEnv, features })
114
+ : { command: { ...reference, args: [...reference.args] }, env: { ...baseEnv, ...(reference.env ?? {}) } };
115
+
116
+ let prompt: string | undefined;
117
+ if (!exactAnswer) {
118
+ const workspaceSkills = features.skills && !harness.nativeWorkspaceSkills && !d.options.noSkills
119
+ ? await discoverWorkspaceSkills(d.workspace)
120
+ : [];
121
+ if (features.prompts || workspaceSkills.length > 0) {
122
+ prompt = (await loadWorkspaceContext({
123
+ host: reference.backend,
124
+ root: d.workspace,
125
+ role: "general-purpose",
126
+ includePrompts: features.prompts,
127
+ workspaceSkills,
128
+ })).text;
129
+ }
130
+ }
131
+
132
+ let mcpServers: ReturnType<typeof toAcpMcpServers> | undefined;
133
+ if (features.mcp && !harness.nativeWorkspaceMcp && !validating) {
134
+ const mcpConfig = await readWorkspaceMcpConfig(d.workspace);
135
+ if (mcpConfig.present) {
136
+ const resolved = resolveWorkspaceMcpServers(d.workspace, mcpConfig, prepared.env);
137
+ if (resolved.length) mcpServers = toAcpMcpServers(resolved);
138
+ }
139
+ }
140
+
141
+ // Only publish acp-model.json after requested model/thinking options are applied so callers can detect startup readiness.
142
+ let configured = false;
143
+ const saveSelection = (selection: AcpModelSelection) => {
144
+ if (validating || !configured) return;
145
+ const run = files.read(id!, "launch.json", launch);
146
+ if (run.generation === generation && !run.stop) files.write(id!, "acp-model.json", { generation, ...selection }, acpModelState);
147
+ };
148
+
149
+ const connection = await openAcp(prepared.command, d.cwd, prepared.env, {
150
+ selection: saveSelection,
151
+ update(update) {
152
+ if (update.sessionUpdate === "agent_message_chunk" && update.content.type === "text") {
153
+ execution?.update({ kind: "text", text: update.content.text, ...(update.messageId ? { messageId: update.messageId } : {}) });
154
+ } else if (update.sessionUpdate === "agent_thought_chunk") {
155
+ execution?.update({ kind: "thought" });
156
+ } else if (update.sessionUpdate === "tool_call" || update.sessionUpdate === "tool_call_update") {
157
+ execution?.update({ kind: update.sessionUpdate === "tool_call" ? "tool" : "activity", activity: update.name ?? update.title ?? "工具" });
158
+ }
159
+ },
160
+ async permission(request, signal) {
161
+ if (!execution) return { outcome: { outcome: "cancelled" } };
162
+ const policy = reference.permission ?? "ask";
163
+ const pick = (...kinds: string[]) => kinds.map(kind => request.options.find(item => item.kind === kind)).find(Boolean)?.optionId;
164
+ // ask forwards the request to the parent session; allow/deny follow the workspace's explicit configuration.
165
+ const optionId = policy === "allow" ? pick("allow_once", "allow_always")
166
+ : policy === "deny" ? pick("reject_once", "reject_always")
167
+ : await execution.permission(permissionDescription(request),
168
+ request.options.map(({ optionId, name, kind }) => ({ optionId, name, kind })), signal);
169
+ return optionId ? { outcome: { outcome: "selected", optionId } } : { outcome: { outcome: "cancelled" } };
170
+ },
171
+ async elicitation(request, signal) {
172
+ if (!execution) return { action: "cancel" };
173
+ if (request.mode === "form") {
174
+ const schema = "requestedSchema" in request && object(request.requestedSchema)
175
+ ? request.requestedSchema
176
+ : { type: "object", properties: {} };
177
+ const reply = await execution.elicitation({ mode: "form", message: request.message, schema }, signal);
178
+ if (reply.action === "accept") return { action: "accept", content: reply.content ?? {} };
179
+ return reply.action === "decline" ? { action: "decline" } : { action: "cancel" };
180
+ }
181
+ if (request.mode === "url" && "url" in request && typeof request.url === "string" && request.url.length > 0) {
182
+ const reply = await execution.elicitation({ mode: "url", message: request.message, url: request.url }, signal);
183
+ if (reply.action === "accept") return { action: "accept" };
184
+ return reply.action === "decline" ? { action: "decline" } : { action: "cancel" };
185
+ }
186
+ return { action: "decline" };
187
+ },
188
+ }, lifetime.signal, {
189
+ harness,
190
+ ...(prompt ? { systemPrompt: prompt } : {}),
191
+ ...(prepared.sessionMeta ? { sessionMeta: prepared.sessionMeta } : {}),
192
+ ...(prepared.defaultThinking ? { defaultThinking: prepared.defaultThinking } : {}),
193
+ ...(mcpServers ? { mcpServers } : {}),
194
+ });
195
+
196
+ try {
197
+ requireThat(!prompt || !harness.requireSystemPrompt || connection.systemPrompt,
198
+ `${reference.backend} ACP 后端需要支持 systemPrompt,以加载专家职责与工作区资料。`);
199
+ if (validating) { await sendIpc({ type: "validated" }); return; }
200
+ if (reference.sessionId === null) await connection.configure(d.options);
201
+ requireThat(files.read(id!, "launch.json", launch).generation === generation && !files.read(id!, "launch.json", launch).stop, "ACP 启动已取消。");
202
+ files.write(id!, "acp-session.json", {
203
+ ...reference,
204
+ sessionId: harness.eagerSessionId || reference.sessionId !== null ? connection.sessionId : null,
205
+ capabilities: connection.capabilities,
206
+ }, acpReference);
207
+ configured = true;
208
+ saveSelection(connection.selection());
209
+ let promptInjected = reference.sessionId !== null || connection.systemPrompt;
210
+ execution = new AcpAgentRun(files, d, generation!, {
211
+ signal: connection.signal,
212
+ async prompt(request) {
213
+ const effective = !exactAnswer && prompt && !promptInjected
214
+ ? { ...request, message: prompt + "\n\n---\n\n" + request.message }
215
+ : request;
216
+ promptInjected = true;
217
+ const content = await acpContent(effective, connection.images, connection.signal);
218
+ const run = files.read(id!, "launch.json", launch);
219
+ requireThat(run.generation === generation && !run.stop, "ACP 输入已取消或启动代次变化。");
220
+ connection.signal.throwIfAborted();
221
+ const saved = files.read(id!, "acp-session.json", acpReference);
222
+ if (saved.sessionId === null) files.write(id!, "acp-session.json", { ...saved, sessionId: connection.sessionId }, acpReference);
223
+ return connection.prompt(content);
224
+ },
225
+ cancel: () => connection.cancel(),
226
+ }, exactAnswer);
227
+ await execution.run();
228
+ } finally {
229
+ try { await connection.close(); } finally { await execution?.settled(); }
230
+ }
101
231
  }
102
- } catch (error) {
103
- if (validating) { if (process.connected) process.send?.({ type: "error", error: String(error) }); }
104
- else if (files.read(id, "launch.json", launch).generation === generation) {
105
- const stopped = files.read(id, "launch.json", launch).stop;
106
- const patch = { state: stopped ? "stopped" as const : "error" as const, activity: stopped ? "已停止" : "ACP 执行失败", ...(stopped ? {} : { error: String(error) }) };
107
- if (execution) execution.execution.save(patch);
108
- else files.write(id, "status.json", { generation, ...patch, updatedAt: Date.now() }, status);
232
+
233
+ try {
234
+ await main();
235
+ if (!validating && files.read(id, "launch.json", launch).generation === generation) {
236
+ if (execution) execution.execution.save({ state: "stopped", activity: "已停止" });
237
+ else files.write(id, "status.json", { generation, state: "stopped", activity: "已停止", updatedAt: Date.now() }, status);
238
+ }
239
+ } catch (error) {
240
+ if (validating) { await sendIpc({ type: "error", error: errorMessage(error) }); }
241
+ else if (files.read(id, "launch.json", launch).generation === generation) {
242
+ const stopped = files.read(id, "launch.json", launch).stop;
243
+ const patch = { state: stopped ? "stopped" as const : "error" as const, activity: stopped ? "已停止" : "ACP 执行失败", ...(stopped ? {} : { error: errorMessage(error) }) };
244
+ if (execution) execution.execution.save(patch);
245
+ else files.write(id, "status.json", { generation, ...patch, updatedAt: Date.now() }, status);
246
+ }
247
+ process.exitCode = 1;
248
+ } finally {
249
+ lifetime.abort();
250
+ if (process.connected) process.disconnect();
251
+ // Keep child processes in this worker's process group so forced release covers descendants.
109
252
  }
110
- process.exitCode = 1;
111
- } finally {
112
- lifetime.abort();
113
- if (process.connected) process.disconnect();
114
- // Keep child processes in this worker's process group so forced release covers descendants.
115
253
  }
254
+
255
+ const args = process.argv.slice(2);
256
+ if (args.includes("--probe")) await runProbe();
257
+ else await runWorker(args);
@@ -1,22 +1,17 @@
1
1
  import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
2
2
  import { packageVersion } from "../common/version.js";
3
3
  import { initializeWorkspace } from "../services/workspace/workspace-preparation.js";
4
+ import { workspaceDisabledMessage } from "../services/workspace/workspace-config.js";
4
5
  import type { Confirmations } from "../ui/confirmation.js";
5
- import { readPage } from "../ui/pi/reader.js";
6
- import { choose } from "../ui/pi/menu.js";
7
- import { agentOwner } from "../integrations/pi/agent-context.js";
8
6
  import type { Lifecycle } from "./lifecycle.js";
9
- import { showAgents } from "./agents-command.js";
10
- import { showTeams } from "./teams-command.js";
11
- import { showHistory } from "./history.js";
12
- import { workspaceDisabledMessage } from "../services/workspace/workspace-config.js";
7
+ import { parseWorkerCommand } from "./mcp-workers.js";
13
8
 
14
9
  export function registerCommand(pi: ExtensionAPI, lifecycle: Lifecycle, confirmations: Confirmations) {
15
10
  pi.registerCommand("pbot", {
16
- description: "工作区、专家、团队与历史",
11
+ description: "工作区初始化、状态与跨 Harness worker 管理",
17
12
  getArgumentCompletions: prefix => {
18
13
  if (/\s/.test(prefix)) return null;
19
- return ["init", "status", "history", "agents", "teams"]
14
+ return ["init", "status", "worker"]
20
15
  .filter(command => command.startsWith(prefix)).map(command => ({ value: command, label: command }));
21
16
  },
22
17
  handler: async (args, ctx) => {
@@ -32,43 +27,50 @@ export function registerCommand(pi: ExtensionAPI, lifecycle: Lifecycle, confirma
32
27
  }
33
28
  if (!lifecycle.active) {
34
29
  const configuration = lifecycle.configuration;
35
- const status = { workspaceRoot: lifecycle.root ?? ctx.cwd, release: packageVersion, enabled: false,
30
+ const status = {
31
+ workspaceRoot: lifecycle.root ?? ctx.cwd,
32
+ release: packageVersion,
33
+ enabled: false,
36
34
  state: configuration?.error || configuration?.enabled ? "error" : "disabled",
37
- nextStep: configuration?.error ?? "/pbot init", configuration };
35
+ nextStep: configuration?.error ?? "/pbot init",
36
+ configuration,
37
+ };
38
38
  ctx.ui.notify(command === "status" ? JSON.stringify(status, null, 2)
39
39
  : configuration ? workspaceDisabledMessage(configuration) : "pbot 工作区实例不可用。", configuration?.error ? "error" : "info");
40
40
  return;
41
41
  }
42
- async function execute(command: string | undefined, argument: string) {
43
- const instance = lifecycle.get();
44
- if (command === "status" && !argument) {
45
- if (ctx.mode !== "tui") { ctx.ui.notify(JSON.stringify({ workspaceRoot: instance.root, release: packageVersion, enabled: true, state: "running", configuration: lifecycle.configuration }, null, 2), "info"); return; }
46
- const agents = instance.agents.list(agentOwner(ctx)), history = instance.history.status;
47
- await readPage(ctx, "工作区", [instance.root, "", "状态 已启动", `配置 ${lifecycle.configuration?.path ?? ""}`, `版本 ${packageVersion}`,
48
- `模型 ${ctx.model && !(ctx.model.provider === "unknown" && ctx.model.id === "unknown") ? ctx.model.provider + "/" + ctx.model.id : "未选择"}`,
49
- `专家 ${agents.length} 位 · ${agents.filter(value => value.alive).length} 位存活`,
50
- "", `历史 ${history.organizing ? "整理中" : history.pending === null ? "查询时更新索引" : history.pending + " 项待整理"}`,
51
- ...history.warnings].join("\n")); return;
42
+ const instance = lifecycle.get();
43
+ if (command === "status" && !argument) {
44
+ if (ctx.mode !== "tui") {
45
+ ctx.ui.notify(JSON.stringify({
46
+ workspaceRoot: instance.root,
47
+ release: packageVersion,
48
+ enabled: true,
49
+ state: "running",
50
+ configuration: lifecycle.configuration,
51
+ }, null, 2), "info");
52
+ return;
52
53
  }
53
- if (command === "history") { await showHistory(instance, ctx, argument); return; }
54
- if (command === "agents") { await showAgents(pi, instance, ctx, confirmations); return; }
55
- if (command === "teams") { await showTeams(pi, instance, ctx, confirmations); return; }
56
- ctx.ui.notify("/pbot init | status | history [关键词] | agents | teams", "info");
54
+ const history = instance.history.status;
55
+ ctx.ui.notify([
56
+ `工作区 ${instance.root}`,
57
+ `状态 已启动 · 版本 ${packageVersion}`,
58
+ `历史 ${history.organizing ? "整理中" : history.pending === null ? "查询时更新索引" : history.pending + " 项待整理"}`,
59
+ ...history.warnings,
60
+ ].join("\n"), "info");
61
+ return;
57
62
  }
58
- if (command || ctx.mode !== "tui") { await execute(command, argument); return; }
59
- if (confirmations.presenting) { ctx.ui.notify("请先处理待确认操作。", "info"); return; }
60
- for (;;) {
61
- const instance = lifecycle.get(), agents = instance.agents.list(agentOwner(ctx));
62
- const choices = ["专家 · " + agents.length, "团队", "历史", "工作区状态", "准备资料目录"];
63
- const choice = await choose(ctx, "Personal Bot", choices);
64
- if (!choice) return;
65
- const command = ["agents", "teams", "history", "status", "init"][choices.indexOf(choice)]!;
63
+ if (command === "worker") {
66
64
  try {
67
- if (command === "init") { await ctx.waitForIdle(); instance.check(); await initializeWorkspace(instance.root); ctx.ui.notify("资料目录已准备。", "info"); }
68
- else await execute(command, "");
65
+ const { tool, args: payload } = parseWorkerCommand(argument);
66
+ const result = await instance.workers.callTool(tool, { workspace: instance.root, ...payload });
67
+ ctx.ui.notify(JSON.stringify(result, null, 2), "info");
68
+ } catch (error) {
69
+ ctx.ui.notify(error instanceof Error ? error.message : String(error), "error");
69
70
  }
70
- catch (error) { ctx.ui.notify(error instanceof Error ? error.message : String(error), "error"); }
71
+ return;
71
72
  }
73
+ ctx.ui.notify('/pbot init | status | worker [overview|status|backends|models|create|request|response|output|close] [JSON]', "info");
72
74
  },
73
75
  });
74
76
  }
@@ -1,10 +1,13 @@
1
1
  import type { Context } from "@deepseek-ai/cordis";
2
+ import * as McpClient from "@deepseek-ai/dsh-mcp-client";
2
3
  import type { AcpInput } from "../../model/acp.js";
3
4
  import { acpMember } from "../acp-member.js";
4
5
  import { rootAgents } from "../../integrations/dsh/root-agents.js";
5
6
  import { dshResources, dshExpertTools } from "../../integrations/dsh/resources.js";
6
7
  import { registerDshSkills } from "../../integrations/dsh/skills.js";
8
+ import { toDshMcpConfig } from "../../integrations/dsh/mcp.js";
7
9
  import { finalDshAnswer } from "../../integrations/dsh/messages.js";
10
+ import { readWorkspaceMcpConfig, resolveWorkspaceMcpServer } from "../../services/workspace/workspace-mcp.js";
8
11
  import { registerDshFileEvents } from "./files.js";
9
12
  import { requireThat } from "../../common/validation.js";
10
13
 
@@ -24,9 +27,25 @@ export async function apply(ctx: Context) {
24
27
  requireThat(reference.host === "acp" && reference.backend === "dsh" && agent.session.header.cwd === member.d.cwd &&
25
28
  (reference.sessionId === null || reference.sessionId === agent.id), "dsh ACP 会话身份或工作目录不匹配。");
26
29
  await agent.ctx.plugin({ name: "pbot-acp-expert", inject, apply: async scope => {
27
- registerDshSkills(scope, agent);
30
+ if (member.features.skills) registerDshSkills(scope, agent, { workspaceRoot: member.d.workspace });
31
+ if (member.features.mcp && process.env.PBOT_ACP_VALIDATE !== "1") {
32
+ const mcpConfig = await readWorkspaceMcpConfig(member.d.workspace);
33
+ if (mcpConfig.error) {
34
+ ctx.logger.warn(mcpConfig.error);
35
+ } else {
36
+ for (const [serverName, server] of Object.entries(mcpConfig.servers)) {
37
+ if (server.enabled === false) continue;
38
+ try {
39
+ const resolved = resolveWorkspaceMcpServer(member.d.workspace, serverName, server);
40
+ await scope.plugin(McpClient, toDshMcpConfig(resolved));
41
+ } catch (error) {
42
+ ctx.logger.warn(error instanceof Error ? error.message : String(error));
43
+ }
44
+ }
45
+ }
46
+ }
28
47
  dshExpertTools(scope, agent, member.d.options);
29
- await dshResources(scope, agent, member.d.workspace, "general-purpose", member.check);
48
+ if (member.features.prompts) await dshResources(scope, agent, member.d.workspace, "general-purpose", member.check);
30
49
  registerDshFileEvents(scope, agent, member.d.workspace, true, member.check);
31
50
  let input: AcpInput | undefined, answer = "";
32
51
  scope.on("session/event", (session, event) => {
@@ -1,38 +1,27 @@
1
1
  import type { Context } from "@deepseek-ai/cordis";
2
2
  import type {} from "@deepseek-ai/dsh-commands";
3
- import { Type, type Static } from "typebox";
4
3
  import { object, json } from "../../common/json.js";
5
4
  import { requireThat } from "../../common/validation.js";
6
- import { schema } from "../../common/schema.js";
7
- import { executeAgent } from "../../tools/agents/actions.js";
8
- import { agentInput } from "../../tools/agents/contract.js";
9
- import { executeTeam, executeTeamMessage } from "../../tools/teams/actions.js";
10
- import { teamInput, teamMessageInput } from "../../tools/teams/contract.js";
11
5
  import { dshWorkspaceStatus, type PbotManagement } from "./management.js";
12
6
  import type { DshWorkspaces } from "./workspace.js";
7
+ import { parseWorkerCommand } from "../mcp-workers.js";
13
8
 
14
- const chatSchema = Type.Object({ agentId: Type.String({ minLength: 1 }), text: Type.Optional(Type.String({ maxLength: 24000 })),
15
- delivery: Type.Optional(Type.Union([Type.Literal("steer"), Type.Literal("followUp")])),
16
- files: Type.Optional(Type.Array(Type.String({ minLength: 1 }), { maxItems: 32 })) }, { additionalProperties: false });
17
- const validChat = schema(chatSchema);
18
- const approvalSchema = Type.Object({ agentId: Type.String({ minLength: 1 }), requestId: Type.String({ minLength: 1 }),
19
- optionId: Type.Union([Type.String({ minLength: 1 }), Type.Null()]) }, { additionalProperties: false });
20
- const validApproval = schema(approvalSchema);
21
- const usage = '用法:/pbot status | init | agent {"action":…} | chat {"agentId":…,"text":…} | team {"action":…} | messages {"teamId":…} | post {"teamId":…,"text":…} | history {"action":…} | records {"agentId":…}';
9
+ const usage = '用法:/pbot status | init | worker [overview|status|backends|models|create|request|response|output|close] [JSON] | history {"action":…}';
22
10
 
23
11
  export function registerDshCommand(ctx: Context, workspaces: DshWorkspaces, management: PbotManagement) {
24
- ctx.commands.register({ name: "pbot", description: "Personal Bot 工作区与协作管理", recordInput: false,
25
- input: { hint: "status | init | agent/chat/team/messages/post/history/records JSON", attachments: true },
26
- async handler({ agent, rawInput, signal, attachments, commandId }) {
12
+ ctx.commands.register({
13
+ name: "pbot",
14
+ description: "Personal Bot 工作区、跨 Harness worker 与历史管理",
15
+ recordInput: false,
16
+ input: { hint: "status | init | worker ... | history JSON", attachments: false },
17
+ async handler({ agent, rawInput, signal }) {
27
18
  signal.throwIfAborted();
28
19
  const command = rawInput.trim(), split = command.search(/\s/);
29
20
  if (!command || command === "status") {
30
- requireThat(!attachments.length, "状态查询不接受附件。");
31
21
  const status = await dshWorkspaceStatus(workspaces, agent);
32
22
  signal.throwIfAborted(); return { kind: "success", text: JSON.stringify(status, null, 2) };
33
23
  }
34
24
  if (command === "init") {
35
- requireThat(!attachments.length, "初始化不接受附件。");
36
25
  await workspaces.initialize(agent);
37
26
  signal.throwIfAborted();
38
27
  return { kind: "success", text: JSON.stringify(await dshWorkspaceStatus(workspaces, agent), null, 2) };
@@ -40,42 +29,23 @@ export function registerDshCommand(ctx: Context, workspaces: DshWorkspaces, mana
40
29
  const workspace = await workspaces.get(agent);
41
30
  signal.throwIfAborted();
42
31
  const verb = split < 0 ? command : command.slice(0, split);
43
- requireThat(verb === "chat" || !attachments.length, "输入框附件仅用于 chat 人工对话。");
44
- requireThat(split >= 0, usage);
45
- const input: unknown = JSON.parse(command.slice(split));
46
- requireThat(object(input), "命令参数必须是 JSON 对象。");
32
+ const rest = split < 0 ? "" : command.slice(split).trim();
47
33
  let result: unknown;
48
34
  switch (verb) {
49
- case "agent": {
50
- const selection = agent.model.current();
51
- const output = await executeAgent(workspace.agents, agentInput(input), workspace.owner, selection ? {
52
- provider: selection.provider, model: selection.model,
53
- ...(selection.reasoningEffort ? { thinking: selection.reasoningEffort } : {}),
54
- } : {});
55
- result = output.structuredContent; break;
35
+ case "worker": {
36
+ const { tool, args } = parseWorkerCommand(rest);
37
+ result = await workspace.workers.callTool(tool, { workspace: workspace.root, ...args });
38
+ break;
56
39
  }
57
- case "chat": {
58
- requireThat(validChat(input), "人工对话参数无效。");
59
- const args = input as Static<typeof chatSchema>;
60
- result = await workspace.interact(args.agentId, args.text ?? "", args.delivery, args.files, attachments, signal); break;
40
+ case "history": {
41
+ requireThat(rest.length > 0, usage);
42
+ const input: unknown = JSON.parse(rest);
43
+ requireThat(object(input), "命令参数必须是 JSON 对象。");
44
+ result = await management.history({ parentSessionId: agent.id, input: json(input) }, signal);
45
+ break;
61
46
  }
62
- case "approval": {
63
- requireThat(validApproval(input), "ACP 确认答复参数无效。");
64
- const args = input as Static<typeof approvalSchema>;
65
- workspace.agents.answerPermission(args.agentId, args.requestId, args.optionId, workspace.owner);
66
- result = { answered: true }; break;
67
- }
68
- case "team":
69
- result = executeTeam(workspace.teams, workspace.agents, teamInput(input), workspace.owner).structuredContent; break;
70
- case "messages":
71
- result = executeTeamMessage(workspace.teams, teamMessageInput({ ...input, action: "read" }),
72
- { kind: "coordinator", owner: workspace.owner }, commandId).structuredContent; break;
73
- case "post":
74
- result = executeTeamMessage(workspace.teams, teamMessageInput({ ...input, action: "post" }),
75
- { kind: "user", owner: workspace.owner }, commandId).structuredContent; break;
76
- case "history": result = await management.history({ parentSessionId: agent.id, input: json(input) }, signal); break;
77
- case "records": result = await management.expert({ parentSessionId: agent.id, input: json(input) }, signal); break;
78
- default: throw new Error(usage);
47
+ default:
48
+ throw new Error(usage);
79
49
  }
80
50
  workspace.check();
81
51
  return { kind: "success", text: JSON.stringify(result, null, 2) };
@@ -1,4 +1,5 @@
1
1
  import type { Context } from "@deepseek-ai/cordis";
2
+ import type {} from "@deepseek-ai/dsh-fs";
2
3
  import type { Agent } from "@deepseek-ai/dsh-agent";
3
4
  import type { ToolExecution, ToolExecutionToken } from "@deepseek-ai/dsh-tools";
4
5
  import { parsePatch } from "@deepseek-ai/dsh-fs-patch";