personal-bot 0.2.20 → 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 +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 +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
@@ -2,13 +2,13 @@ import { spawn } from "node:child_process";
2
2
  import { Readable, Writable } from "node:stream";
3
3
  import { setTimeout as delay } from "node:timers/promises";
4
4
  import * as acp from "@agentclientprotocol/sdk";
5
- import type { AcpModelSelection, AcpSessionReference } from "../../model/acp.js";
5
+ import type { AcpHarnessAdapter, AcpModelSelection, AcpSessionReference } from "../../model/acp.js";
6
6
  import type { AgentOptions } from "../../model/agent.js";
7
7
  import { requireThat } from "../../common/validation.js";
8
8
  import { packageVersion } from "../../common/version.js";
9
- import { acpModelSelection, acpModelValue, acpThinkingValue } from "./model-selection.js";
10
- import type { ClaudeConfiguration } from "./claude.js";
11
- import { object } from "../../common/json.js";
9
+ import { acpChoices, acpModelSelection, acpModelValue, acpThinkingValue } from "./model-selection.js";
10
+ import { filterAcpMcpServers } from "./mcp.js";
11
+ import { resolveAcpHarness } from "./registry.js";
12
12
 
13
13
  export function acpFailure(error: unknown): unknown {
14
14
  return error instanceof acp.RequestError && error.data !== undefined
@@ -19,12 +19,28 @@ export interface AcpCallbacks {
19
19
  update(update: acp.SessionUpdate): void | Promise<void>;
20
20
  selection?(selection: AcpModelSelection): void;
21
21
  permission(request: acp.RequestPermissionRequest, signal: AbortSignal): Promise<acp.RequestPermissionResponse>;
22
+ elicitation?(request: acp.CreateElicitationRequest, signal: AbortSignal): Promise<acp.CreateElicitationResponse>;
22
23
  }
23
24
 
24
- /** One ACP v1 connection. The worker owns its process group and business state. */
25
- export async function openAcp(reference: AcpSessionReference, cwd: string, env: NodeJS.ProcessEnv,
26
- callbacks: AcpCallbacks, signal: AbortSignal, systemPrompt?: string, claude?: ClaudeConfiguration) {
25
+ export interface OpenAcpOptions {
26
+ readonly harness?: AcpHarnessAdapter;
27
+ readonly systemPrompt?: string;
28
+ readonly sessionMeta?: Record<string, unknown>;
29
+ readonly defaultThinking?: string;
30
+ readonly mcpServers?: readonly acp.McpServer[];
31
+ }
32
+
33
+ /** One ACP v1 connection. The worker owns its process group and business state; harness hooks stay in AcpHarnessAdapter. */
34
+ export async function openAcp(
35
+ reference: AcpSessionReference,
36
+ cwd: string,
37
+ env: NodeJS.ProcessEnv,
38
+ callbacks: AcpCallbacks,
39
+ signal: AbortSignal,
40
+ openOptions: OpenAcpOptions = {},
41
+ ) {
27
42
  signal.throwIfAborted();
43
+ const harness = openOptions.harness ?? resolveAcpHarness(reference.backend);
28
44
  const child = spawn(reference.command, reference.args, { cwd, env, stdio: ["pipe", "pipe", "pipe"] });
29
45
  const lifetime = new AbortController();
30
46
  const cancel = AbortSignal.any([signal, lifetime.signal]);
@@ -36,14 +52,21 @@ export async function openAcp(reference: AcpSessionReference, cwd: string, env:
36
52
  let sessionId: string | undefined;
37
53
  let options: acp.SessionConfigOption[] = [];
38
54
  let resolvedModel: string | undefined;
39
- const selection = (): AcpModelSelection => ({ ...acpModelSelection(reference.backend, options, claude?.thinking),
40
- ...(resolvedModel ? { resolvedModel } : {}) });
55
+ const selection = (): AcpModelSelection => ({
56
+ ...acpModelSelection(reference.backend, options, openOptions.defaultThinking),
57
+ ...(resolvedModel ? { resolvedModel } : {}),
58
+ });
41
59
  let updating = Promise.resolve();
42
- const app = acp.client({ name: "personal-bot" })
60
+ let app = acp.client({ name: "personal-bot" })
43
61
  .onRequest(acp.methods.client.session.requestPermission, async ctx => {
44
62
  if (cancel.aborted || ctx.params.sessionId !== sessionId) return { outcome: { outcome: "cancelled" as const } };
45
63
  return callbacks.permission(ctx.params, cancel);
46
64
  })
65
+ .onRequest(acp.methods.client.elicitation.create, async ctx => {
66
+ if (cancel.aborted || !callbacks.elicitation) return { action: "cancel" as const };
67
+ if ("sessionId" in ctx.params && ctx.params.sessionId !== sessionId) return { action: "cancel" as const };
68
+ return callbacks.elicitation(ctx.params, cancel);
69
+ })
47
70
  .onNotification(acp.methods.client.session.update, ctx => {
48
71
  // Load may replay before its response. Output from replay never becomes a new report.
49
72
  if (ctx.params.sessionId !== sessionId || cancel.aborted) return;
@@ -58,16 +81,19 @@ export async function openAcp(reference: AcpSessionReference, cwd: string, env:
58
81
  });
59
82
  void updating.catch(error => lifetime.abort(error));
60
83
  return updating;
61
- })
62
- .onNotification("_claude/sdkMessage", (value: unknown) => value, ctx => {
63
- if (reference.backend !== "claude" || !object(ctx.params) || ctx.params.sessionId !== sessionId || cancel.aborted) return;
64
- const message = ctx.params.message;
65
- if (!object(message) || message.type !== "system" || message.subtype !== "init" || typeof message.model !== "string" || !message.model) return;
66
- const model = message.model;
84
+ });
85
+ if (harness.customNotificationMethod && harness.parseCustomNotification) {
86
+ const parse = harness.parseCustomNotification;
87
+ app = app.onNotification(harness.customNotificationMethod, (value: unknown) => value, ctx => {
88
+ if (!sessionId || cancel.aborted) return;
89
+ const parsed = parse(ctx.params, sessionId);
90
+ if (!parsed?.resolvedModel) return;
91
+ const model = parsed.resolvedModel;
67
92
  updating = updating.then(() => { resolvedModel = model; callbacks.selection?.(selection()); });
68
93
  void updating.catch(error => lifetime.abort(error));
69
94
  return updating;
70
95
  });
96
+ }
71
97
  const connection = await app.connect(acp.ndJsonStream(Writable.toWeb(child.stdin), Readable.toWeb(child.stdout) as ReadableStream<Uint8Array>, { maxMessageBytes: 8 * 1024 * 1024 }));
72
98
  const abort = () => connection.close(cancel.reason);
73
99
  cancel.addEventListener("abort", abort, { once: true });
@@ -94,22 +120,33 @@ export async function openAcp(reference: AcpSessionReference, cwd: string, env:
94
120
  let initialized: acp.InitializeResponse | undefined;
95
121
  try {
96
122
  initialized = await connection.agent.request(acp.methods.agent.initialize, {
97
- protocolVersion: 1, clientCapabilities: {}, clientInfo: { name: "personal-bot", version: packageVersion },
123
+ protocolVersion: 1,
124
+ clientCapabilities: callbacks.elicitation ? { elicitation: { form: {}, url: {} } } : {},
125
+ clientInfo: { name: "personal-bot", version: packageVersion },
98
126
  }, { cancellationSignal: AbortSignal.any([cancel, AbortSignal.timeout(30_000)]), stopWaitingOnCancel: true });
99
127
  requireThat(initialized.protocolVersion === 1, "目标宿主没有协商 ACP v1。");
100
128
  const advertised = initialized.agentCapabilities;
101
- const capabilities = { resume: Boolean(advertised?.sessionCapabilities?.resume), load: advertised?.loadSession === true,
102
- close: Boolean(advertised?.sessionCapabilities?.close) };
103
- const setup = { cwd, mcpServers: [],
104
- ...(reference.backend === "claude" ? { _meta: { claudeCode: { options: { ...claude?.options, disallowedTools: ["Agent", "Task"] },
105
- emitRawSDKMessages: [{ type: "system", subtype: "init" }] } } } : {}), ...(systemPrompt && advertised?.sessionCapabilities?.systemPrompt ? {
106
- systemPrompt: { mode: "append" as const, content: [{ type: "text" as const, text: systemPrompt }] },
107
- } : {}) };
129
+ const capabilities = {
130
+ resume: Boolean(advertised?.sessionCapabilities?.resume),
131
+ load: advertised?.loadSession === true,
132
+ close: Boolean(advertised?.sessionCapabilities?.close),
133
+ };
134
+ const mcpServers = openOptions.mcpServers?.length
135
+ ? filterAcpMcpServers(openOptions.mcpServers, advertised?.mcpCapabilities)
136
+ : [];
137
+ const setup = {
138
+ cwd,
139
+ mcpServers,
140
+ ...(openOptions.sessionMeta ? { _meta: openOptions.sessionMeta } : {}),
141
+ ...(openOptions.systemPrompt && advertised?.sessionCapabilities?.systemPrompt ? {
142
+ systemPrompt: { mode: "append" as const, content: [{ type: "text" as const, text: openOptions.systemPrompt }] },
143
+ } : {}),
144
+ };
108
145
  if (reference.sessionId === null) {
109
146
  const created = await connection.agent.request<acp.NewSessionResponse>(acp.methods.agent.session.new, setup, { cancellationSignal: AbortSignal.any([cancel, AbortSignal.timeout(30_000)]), stopWaitingOnCancel: true });
110
147
  sessionId = created.sessionId; options = created.configOptions ?? [];
111
148
  } else {
112
- requireThat(capabilities.resume || capabilities.load, "目标 ACP 后端不支持恢复已有会话。");
149
+ requireThat(capabilities.resume || capabilities.load, "目标 ACP 后端不支持恢复已有会话,请新建 worker。");
113
150
  const restored = capabilities.resume
114
151
  ? await connection.agent.request<acp.ResumeSessionResponse>(acp.methods.agent.session.resume, { ...setup, sessionId: reference.sessionId }, { cancellationSignal: AbortSignal.any([cancel, AbortSignal.timeout(30_000)]), stopWaitingOnCancel: true })
115
152
  : await connection.agent.request<acp.LoadSessionResponse>(acp.methods.agent.session.load, { ...setup, sessionId: reference.sessionId }, { cancellationSignal: AbortSignal.any([cancel, AbortSignal.timeout(30_000)]), stopWaitingOnCancel: true });
@@ -121,6 +158,7 @@ export async function openAcp(reference: AcpSessionReference, cwd: string, env:
121
158
  sessionId: activeId, capabilities, signal: connected, close, images: advertised?.promptCapabilities?.image === true,
122
159
  systemPrompt: Boolean(advertised?.sessionCapabilities?.systemPrompt),
123
160
  selection,
161
+ choices: () => acpChoices(options),
124
162
  async configure(requested: AgentOptions) {
125
163
  requireThat(!requested.provider || requested.model, "provider 需要同时指定目标 model。");
126
164
  for (const kind of ["model", "thinking"] as const) {
@@ -0,0 +1,41 @@
1
+ import { accessSync, constants, realpathSync, statSync } from "node:fs";
2
+ import { delimiter, isAbsolute, resolve } from "node:path";
3
+ import type { AcpBackend, AcpHarnessAdapter } from "../../model/acp.js";
4
+
5
+ export function findAcpExecutable(command: string): string | undefined {
6
+ const candidates = isAbsolute(command)
7
+ ? [command]
8
+ : (process.env.PATH ?? "").split(delimiter).filter(Boolean).map(directory => resolve(directory, command));
9
+ for (const candidate of candidates) {
10
+ try {
11
+ accessSync(candidate, constants.X_OK);
12
+ if (statSync(candidate).isFile()) return realpathSync(candidate);
13
+ } catch (error) {
14
+ if (!["ENOENT", "ENOTDIR", "EACCES", "EPERM"].includes((error as NodeJS.ErrnoException).code ?? "")) throw error;
15
+ }
16
+ }
17
+ return undefined;
18
+ }
19
+
20
+ export function acpExecutable(command: string, backend: AcpBackend, harness?: AcpHarnessAdapter): string {
21
+ const found = findAcpExecutable(command);
22
+ if (found) return found;
23
+ const nativePi = backend === "pi" && command === "pi";
24
+ const targetCommand = harness?.defaultCommand?.command ?? command;
25
+ const targetArgs = harness?.defaultCommand?.args ?? [];
26
+ const install = nativePi
27
+ ? "npm install -g @earendil-works/pi-coding-agent"
28
+ : harness?.installHint ?? `请确认 ${backend} 对应的 ACP 可执行文件已安装。`;
29
+ const configured = JSON.stringify({ command: "/absolute/path/to/" + targetCommand, args: targetArgs });
30
+ const pathHint = nativePi
31
+ ? "Pi 已安装但 PATH 不可见时,启动主宿主前将 PI_ACP_PI_COMMAND 设置为 pi 的绝对路径。"
32
+ : "已安装但 PATH 不可见时,在 .pbot/config.json 设置 acp." + backend + ":" + configured + ",command 使用实际绝对路径。";
33
+ throw new Error([
34
+ "未找到子代理程序:" + command + "。",
35
+ "安装提示:" + install,
36
+ ...(harness?.configureHint ? [harness.configureHint] : []),
37
+ "检查安装路径:command -v " + (nativePi ? "pi" : targetCommand) + (!nativePi && backend === "pi" ? ";另用 command -v pi 检查 Pi。" : "。"),
38
+ pathHint,
39
+ "安装后重试原 start 请求;PATH 变化时重启主宿主。配置修改后,Pi 执行 /reload,dsh 重启宿主。",
40
+ ].join("\n"));
41
+ }
@@ -0,0 +1,50 @@
1
+ import { object } from "../../../common/json.js";
2
+ import { requireThat } from "../../../common/validation.js";
3
+ import type { AcpHarnessAdapter } from "../../../model/acp.js";
4
+ import { claudeOptions } from "../claude.js";
5
+ import { defaultPrepareLaunch, filterStandardAcpOptions, validateStandardAcpOptions } from "./generic.js";
6
+
7
+ export const claudeAcpHarness: AcpHarnessAdapter = {
8
+ id: "claude",
9
+ label: "Claude Code",
10
+ aliases: ["claude-code", "claudecode"],
11
+ defaultCommand: { command: "claude-agent-acp", args: [] },
12
+ installHint: "npm install -g @agentclientprotocol/claude-agent-acp",
13
+ configureHint: "在 Claude Code 中完成登录或 API 配置,并设置默认模型。",
14
+ requireSystemPrompt: true,
15
+ nativeWorkspaceSkills: false,
16
+ customNotificationMethod: "_claude/sdkMessage",
17
+ filterStartOptions(options) {
18
+ const filtered = filterStandardAcpOptions(options);
19
+ delete filtered.provider;
20
+ return filtered;
21
+ },
22
+ validateStartOptions(options) {
23
+ validateStandardAcpOptions("claude", options);
24
+ requireThat(options.noSkills === undefined && options.tools === undefined, "Claude 子代理的技能和工具通过 Claude 原生配置选择。");
25
+ requireThat(options.provider === undefined, "Claude 子代理使用原生提供方配置;请仅指定目标 model。");
26
+ },
27
+ async prepareLaunch(context) {
28
+ const base = defaultPrepareLaunch(context);
29
+ const claude = await claudeOptions(base.command, context.cwd, context.options.thinking, context.features?.skills !== false);
30
+ return {
31
+ ...base,
32
+ ...(claude.thinking ? { defaultThinking: claude.thinking } : {}),
33
+ sessionMeta: {
34
+ claudeCode: {
35
+ options: { ...claude.options, disallowedTools: ["Agent", "Task"] },
36
+ emitRawSDKMessages: [{ type: "system", subtype: "init" }],
37
+ },
38
+ },
39
+ };
40
+ },
41
+ parseModelValue: value => ({ model: value }),
42
+ parseCustomNotification(params, sessionId) {
43
+ if (!object(params) || params.sessionId !== sessionId) return undefined;
44
+ const message = params.message;
45
+ if (!object(message) || message.type !== "system" || message.subtype !== "init" || typeof message.model !== "string" || !message.model) {
46
+ return undefined;
47
+ }
48
+ return { resolvedModel: message.model };
49
+ },
50
+ };
@@ -0,0 +1,40 @@
1
+ import { writeFile } from "node:fs/promises";
2
+ import { join } from "node:path";
3
+ import type { AcpHarnessAdapter } from "../../../model/acp.js";
4
+ import { defaultPrepareLaunch, filterStandardAcpOptions, validateStandardAcpOptions } from "./generic.js";
5
+
6
+ export const dshAcpHarness: AcpHarnessAdapter = {
7
+ id: "dsh",
8
+ label: "DeepSeek dsh",
9
+ defaultCommand: { command: "dsh", args: ["--profile", "acp"] },
10
+ installHint: "npm install -g @deepseek-ai/dsh@latest",
11
+ configureHint: "按 dsh 原生方式配置目标 profile 的模型与认证。",
12
+ exactAnswer: true,
13
+ eagerSessionId: true,
14
+ nativeWorkspaceSkills: true,
15
+ nativeWorkspaceMcp: true,
16
+ filterStartOptions: filterStandardAcpOptions,
17
+ validateStartOptions: options => validateStandardAcpOptions("dsh", options),
18
+ async prepareLaunch(context) {
19
+ const base = defaultPrepareLaunch(context);
20
+ const patch = join(context.directory, "acp-dsh-patch.json");
21
+ await writeFile(
22
+ patch,
23
+ JSON.stringify([{ insert: [{ id: "pbot-acp-member", name: join(context.packageRoot, "lib/extension/dsh/acp-member.js") }] }]) + "\n",
24
+ { mode: 0o600 },
25
+ );
26
+ return {
27
+ ...base,
28
+ command: { ...base.command, args: [...base.command.args, "--patch", patch] },
29
+ };
30
+ },
31
+ parseModelValue(value) {
32
+ try {
33
+ const parts: unknown = JSON.parse(value);
34
+ if (Array.isArray(parts) && parts.length === 2 && parts.every(part => typeof part === "string" && part.length > 0)) {
35
+ return { provider: parts[0], model: parts[1] };
36
+ }
37
+ } catch { /* Unencoded identifiers remain usable as exact ACP option values. */ }
38
+ return { model: value };
39
+ },
40
+ };
@@ -0,0 +1,52 @@
1
+ import { requireThat } from "../../../common/validation.js";
2
+ import type { AcpBackend, AcpCommand, AcpHarnessAdapter, AcpLaunchContext, AcpPreparedLaunch, AcpStartOptions } from "../../../model/acp.js";
3
+
4
+ const piOnlyOptions = ["noExtensions", "noPromptTemplates", "noContextFiles"] as const;
5
+
6
+ export function filterStandardAcpOptions(options: AcpStartOptions): AcpStartOptions {
7
+ const result: AcpStartOptions = { ...options };
8
+ for (const key of piOnlyOptions) delete result[key];
9
+ delete result.noSkills;
10
+ delete result.tools;
11
+ return result;
12
+ }
13
+
14
+ export function validateStandardAcpOptions(backend: AcpBackend, options: AcpStartOptions): void {
15
+ for (const key of piOnlyOptions) {
16
+ requireThat(options[key] === undefined, backend + " 子代理不支持启动选项:" + key);
17
+ }
18
+ }
19
+
20
+ export function defaultPrepareLaunch(context: AcpLaunchContext): AcpPreparedLaunch {
21
+ return {
22
+ command: { ...context.reference, args: [...context.reference.args] },
23
+ env: { ...context.env, ...(context.reference.env ?? {}) },
24
+ };
25
+ }
26
+
27
+ /** Generic ACP v1 harness adapter; works for any standard ACP v1 executable without special cases. */
28
+ export function createGenericAcpHarness(
29
+ id: AcpBackend,
30
+ preset: {
31
+ label?: string;
32
+ aliases?: readonly string[];
33
+ defaultCommand?: AcpCommand;
34
+ installHint?: string;
35
+ configureHint?: string;
36
+ nativeWorkspaceSkills?: boolean;
37
+ } = {},
38
+ ): AcpHarnessAdapter {
39
+ return {
40
+ id,
41
+ ...(preset.label ? { label: preset.label } : {}),
42
+ ...(preset.aliases ? { aliases: preset.aliases } : {}),
43
+ ...(preset.defaultCommand ? { defaultCommand: preset.defaultCommand } : {}),
44
+ ...(preset.installHint ? { installHint: preset.installHint } : {}),
45
+ ...(preset.configureHint ? { configureHint: preset.configureHint } : {}),
46
+ ...(preset.nativeWorkspaceSkills !== undefined ? { nativeWorkspaceSkills: preset.nativeWorkspaceSkills } : {}),
47
+ filterStartOptions: filterStandardAcpOptions,
48
+ validateStartOptions: options => validateStandardAcpOptions(id, options),
49
+ prepareLaunch: defaultPrepareLaunch,
50
+ parseModelValue: value => ({ model: value }),
51
+ };
52
+ }
@@ -0,0 +1,35 @@
1
+ import { join } from "node:path";
2
+ import type { AcpHarnessAdapter } from "../../../model/acp.js";
3
+ import { acpExecutable } from "../executable.js";
4
+ import { defaultPrepareLaunch } from "./generic.js";
5
+
6
+ export const piAcpHarness: AcpHarnessAdapter = {
7
+ id: "pi",
8
+ label: "Pi",
9
+ defaultCommand: { command: "pi-acp", args: [] },
10
+ installHint: "npm install -g pi-acp",
11
+ configureHint: "Pi 也需已安装;运行 pi 完成登录和默认模型配置。",
12
+ exactAnswer: true,
13
+ nativeWorkspaceSkills: true,
14
+ nativeWorkspaceMcp: true,
15
+ filterStartOptions: options => ({ ...options }),
16
+ prepareLaunch(context) {
17
+ const base = defaultPrepareLaunch(context);
18
+ return {
19
+ ...base,
20
+ env: {
21
+ ...base.env,
22
+ PBOT_ACP_PI_COMMAND: process.env.PI_ACP_PI_COMMAND ?? acpExecutable("pi", "pi"),
23
+ PI_ACP_PI_COMMAND: join(context.packageRoot, "bin/pbot-pi-acp.mjs"),
24
+ },
25
+ };
26
+ },
27
+ parseModelValue(value) {
28
+ const separator = value.indexOf("/");
29
+ if (separator > 0) return { provider: value.slice(0, separator), model: value.slice(separator + 1) };
30
+ return { model: value };
31
+ },
32
+ formatModelQuery(model, provider) {
33
+ return provider ? provider + "/" + model : undefined;
34
+ },
35
+ };
@@ -0,0 +1,22 @@
1
+ import type { AcpHarnessAdapter } from "../../../model/acp.js";
2
+ import { createGenericAcpHarness } from "./generic.js";
3
+
4
+ /** Declarative standard ACP v1 presets requiring no host-specific adapter code. */
5
+ export const standardAcpPresets: readonly AcpHarnessAdapter[] = [
6
+ createGenericAcpHarness("antigravity", {
7
+ label: "Google Antigravity",
8
+ aliases: ["agy"],
9
+ defaultCommand: { command: "agy", args: ["acp"] },
10
+ installHint: "安装 Google Antigravity CLI(agy)",
11
+ configureHint: "运行 agy 完成登录与默认模型配置。",
12
+ nativeWorkspaceSkills: true,
13
+ }),
14
+ createGenericAcpHarness("codex", {
15
+ label: "OpenAI Codex",
16
+ aliases: ["openai-codex", "codex-cli"],
17
+ defaultCommand: { command: "codex-acp", args: [] },
18
+ installHint: "npm install -g @agentclientprotocol/codex-acp",
19
+ configureHint: "在 Codex 中完成登录或 API 配置。",
20
+ nativeWorkspaceSkills: true,
21
+ }),
22
+ ];
@@ -1,50 +1,72 @@
1
- import { accessSync, constants, realpathSync, statSync } from "node:fs";
2
- import { delimiter, isAbsolute, resolve } from "node:path";
3
- import { requireThat } from "../../common/validation.js";
4
- import type { AcpBackend, AcpCommands, AcpSessionReference } from "../../model/acp.js";
5
- import type { AgentOptions } from "../../model/agent.js";
6
-
7
- const targets = {
8
- pi: { command: "pi-acp", args: [], install: "npm install -g pi-acp",
9
- configure: "Pi 也需已安装;运行 pi 完成登录和默认模型配置。" },
10
- dsh: { command: "dsh", args: ["--profile", "acp"], install: "npm install -g @deepseek-ai/dsh@latest",
11
- configure: "按 dsh 原生方式配置目标 profile 的模型与认证。" },
12
- claude: { command: "claude-agent-acp", args: [], install: "npm install -g @agentclientprotocol/claude-agent-acp",
13
- configure: "在 Claude Code 中完成登录或 API 配置,并设置默认模型。" },
14
- };
15
-
16
- export function acpExecutable(command: string, backend: AcpBackend): string {
17
- const candidates = isAbsolute(command) ? [command] : (process.env.PATH ?? "").split(delimiter).filter(Boolean).map(directory => resolve(directory, command));
18
- for (const candidate of candidates) {
19
- try {
20
- accessSync(candidate, constants.X_OK);
21
- if (statSync(candidate).isFile()) return realpathSync(candidate);
22
- } catch (error) { if (!["ENOENT", "ENOTDIR", "EACCES"].includes((error as NodeJS.ErrnoException).code ?? "")) throw error; }
23
- }
24
- const target = targets[backend], nativePi = backend === "pi" && command === "pi";
25
- const install = nativePi ? "npm install -g @earendil-works/pi-coding-agent" : target.install;
26
- const configured = JSON.stringify({ command: "/absolute/path/to/" + target.command, args: target.args });
27
- const path = nativePi ? "Pi 已安装但 PATH 不可见时,启动主宿主前将 PI_ACP_PI_COMMAND 设置为 pi 的绝对路径。"
28
- : "已安装但 PATH 不可见时,在 .pbot/config.json 设置 acp." + backend + ":" + configured + ",command 使用实际绝对路径。";
29
- throw new Error([
30
- "未找到子代理程序:" + command + "。",
31
- "在运行 Pi/dsh 的机器上安装:" + install,
32
- target.configure,
33
- "检查安装路径:command -v " + (nativePi ? "pi" : target.command) + (!nativePi && backend === "pi" ? ";另用 command -v pi 检查 Pi。" : "。"),
34
- path,
35
- "安装后重试原 start 请求;PATH 变化时重启主宿主。配置修改后,Pi 执行 /reload,dsh 重启宿主。",
36
- ].join("\n"));
1
+ import { isAcpBackend, requireThat } from "../../common/validation.js";
2
+ import type { AcpBackend, AcpCommand, AcpCommands, AcpPermissionPolicy, AcpSessionReference, AcpStartOptions } from "../../model/acp.js";
3
+ import { acpExecutable, findAcpExecutable } from "./executable.js";
4
+ import { acpHarnesses, resolveAcpHarness } from "./registry.js";
5
+
6
+ export { acpExecutable, findAcpExecutable } from "./executable.js";
7
+
8
+ /** Workspace entries override a registered default command; an entry without `command` only adjusts env or permission. */
9
+ export function configuredAcpCommand(backend: AcpBackend, commands: AcpCommands = {}): AcpCommand | undefined {
10
+ const entry = Object.hasOwn(commands, backend) ? commands[backend] : undefined;
11
+ const base = entry?.command ? { command: entry.command, args: entry.args ?? [] } : acpHarnesses.get(backend)?.defaultCommand;
12
+ if (!base) return undefined;
13
+ const env = { ...base.env, ...entry?.env };
14
+ return { command: base.command, args: [...base.args], ...(Object.keys(env).length ? { env } : {}) };
15
+ }
16
+
17
+ export function acpPermissionPolicy(backend: AcpBackend, commands: AcpCommands = {}): AcpPermissionPolicy {
18
+ return (Object.hasOwn(commands, backend) ? commands[backend]?.permission : undefined) ?? "ask";
37
19
  }
38
- export function acpLaunch(backend: AcpBackend, commands: AcpCommands, options: AgentOptions): AcpSessionReference {
39
- requireThat(["pi", "dsh", "claude"].includes(backend), "未知子代理程序。");
20
+
21
+ /** Names callers may use: registered harnesses plus workspace-configured custom harnesses. */
22
+ export function knownAcpBackends(commands: AcpCommands = {}): AcpBackend[] {
23
+ return [...new Set([...acpHarnesses.list(), ...Object.keys(commands)])].filter(backend => configuredAcpCommand(backend, commands));
24
+ }
25
+
26
+ export function canonicalAcpBackend(name: string, commands: AcpCommands = {}): AcpBackend {
27
+ return acpHarnesses.canonical(name, Object.keys(commands));
28
+ }
29
+
30
+ export function inspectAcpBackends(commands: AcpCommands = {}) {
31
+ return knownAcpBackends(commands).map(backend => {
32
+ const harness = acpHarnesses.get(backend);
33
+ const selected = configuredAcpCommand(backend, commands)!;
34
+ const resolved = findAcpExecutable(selected.command);
35
+ return {
36
+ backend,
37
+ ...(harness?.label ? { label: harness.label } : {}),
38
+ ...(harness?.aliases?.length ? { aliases: [...harness.aliases] } : {}),
39
+ available: Boolean(resolved),
40
+ builtin: Boolean(harness?.defaultCommand),
41
+ configured: Object.hasOwn(commands, backend),
42
+ permission: acpPermissionPolicy(backend, commands),
43
+ command: selected.command,
44
+ args: [...selected.args],
45
+ ...(resolved ? { resolvedCommand: resolved } : { installHint: harness?.installHint ?? "在 .pbot/config.json 的 acp 字段配置可执行命令。" }),
46
+ };
47
+ });
48
+ }
49
+
50
+ export function filterAcpStartOptions(backend: AcpBackend, options: AcpStartOptions): AcpStartOptions {
51
+ const harness = resolveAcpHarness(backend);
52
+ return harness.filterStartOptions ? harness.filterStartOptions(options) : { ...options };
53
+ }
54
+
55
+ export function acpLaunch(backend: AcpBackend, commands: AcpCommands, options: AcpStartOptions): AcpSessionReference {
56
+ requireThat(isAcpBackend(backend), "未知子代理程序:" + String(backend));
57
+ const harness = resolveAcpHarness(backend);
58
+ const selected = configuredAcpCommand(backend, commands);
59
+ requireThat(selected, `未知子代理程序:${backend}。可用目标:${knownAcpBackends(commands).join(", ")};自定义目标请在 .pbot/config.json 的 acp 字段中配置。`);
40
60
  requireThat(!options.provider || options.model, "provider 需要同时指定目标 model。");
41
- if (backend !== "pi") for (const key of ["noExtensions", "noPromptTemplates", "noContextFiles"] as const) {
42
- requireThat(options[key] === undefined, backend + " 子代理不支持启动选项:" + key);
43
- }
44
- if (backend === "claude") {
45
- requireThat(options.noSkills === undefined && options.tools === undefined, "Claude 子代理的技能和工具通过 Claude 原生配置选择。");
46
- requireThat(options.provider === undefined, "Claude 子代理使用原生提供方配置;请仅指定目标 model。");
47
- }
48
- const selected = commands[backend] ?? targets[backend];
49
- return { host: "acp", backend, command: acpExecutable(selected.command, backend), args: [...selected.args], sessionId: null };
61
+ harness.validateStartOptions?.(options);
62
+ const permission = acpPermissionPolicy(backend, commands);
63
+ return {
64
+ host: "acp",
65
+ backend,
66
+ command: acpExecutable(selected.command, backend, harness),
67
+ args: [...selected.args],
68
+ ...(selected.env ? { env: { ...selected.env } } : {}),
69
+ ...(permission !== "ask" ? { permission } : {}),
70
+ sessionId: null,
71
+ };
50
72
  }
@@ -0,0 +1,43 @@
1
+ import { isAbsolute, resolve } from "node:path";
2
+ import type * as acp from "@agentclientprotocol/sdk";
3
+ import type { ResolvedWorkspaceMcpServer } from "../../model/workspace-mcp.js";
4
+ import { findAcpExecutable } from "./executable.js";
5
+
6
+ function resolveStdioCommand(command: string, cwd: string): string {
7
+ if (isAbsolute(command)) return command;
8
+ if (command.includes("/") || command.includes("\\")) return resolve(cwd, command);
9
+ return findAcpExecutable(command) ?? command;
10
+ }
11
+
12
+ /** Convert resolved workspace MCP entries into ACP v1 `McpServer` descriptors. */
13
+ export function toAcpMcpServers(servers: readonly ResolvedWorkspaceMcpServer[]): acp.McpServer[] {
14
+ return servers.map(server => {
15
+ if (server.transport === "http") {
16
+ return {
17
+ type: "http" as const,
18
+ name: server.name,
19
+ url: server.url,
20
+ headers: Object.entries(server.headers).map(([name, value]) => ({ name, value })),
21
+ };
22
+ }
23
+ return {
24
+ name: server.name,
25
+ command: resolveStdioCommand(server.command, server.cwd),
26
+ args: [...server.args],
27
+ env: Object.entries(server.env).map(([name, value]) => ({ name, value })),
28
+ };
29
+ });
30
+ }
31
+
32
+ /** Filter ACP MCP servers to the transports advertised by the peer's `mcpCapabilities`. */
33
+ export function filterAcpMcpServers(
34
+ servers: readonly acp.McpServer[],
35
+ capabilities?: acp.McpCapabilities,
36
+ ): acp.McpServer[] {
37
+ return servers.filter(server => {
38
+ if (!("type" in server)) return true; // stdio is baseline in ACP v1.
39
+ if (server.type === "http") return capabilities?.http === true;
40
+ if (server.type === "sse") return capabilities?.sse === true;
41
+ return false;
42
+ });
43
+ }