personal-bot 0.2.20 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (343) hide show
  1. package/.claude-plugin/marketplace.json +3 -3
  2. package/.claude-plugin/plugin.json +2 -5
  3. package/.mcp.json +11 -0
  4. package/CONTEXT.md +17 -73
  5. package/README.md +41 -120
  6. package/README.zh-CN.md +41 -120
  7. package/docs/README.md +31 -23
  8. package/docs/architecture/design.md +74 -0
  9. package/docs/architecture/extensibility.md +78 -0
  10. package/docs/architecture/model-context.md +31 -0
  11. package/docs/architecture/model-instruction-guidelines.md +34 -0
  12. package/docs/architecture/principles.md +33 -0
  13. package/docs/guides/capabilities.md +36 -0
  14. package/docs/guides/cross-harness-workers.md +83 -0
  15. package/docs/guides/history.md +25 -0
  16. package/docs/guides/workspace-configuration.md +102 -0
  17. package/docs/hosts/antigravity.md +52 -0
  18. package/docs/hosts/claude-code.md +47 -0
  19. package/docs/hosts/dsh.md +67 -0
  20. package/docs/hosts/pi.md +49 -0
  21. package/docs/maintainers/release.md +59 -0
  22. package/hooks/hooks.json +0 -3
  23. package/lib/antigravity-plugin/hooks.json +23 -0
  24. package/lib/antigravity-plugin/lib/claude.d.ts +1 -0
  25. package/lib/antigravity-plugin/lib/claude.js +13 -0
  26. package/lib/antigravity-plugin/lib/common/json.d.ts +6 -0
  27. package/lib/antigravity-plugin/lib/common/json.js +16 -0
  28. package/lib/antigravity-plugin/lib/common/paths.d.ts +1 -0
  29. package/lib/antigravity-plugin/lib/common/paths.js +2 -0
  30. package/lib/antigravity-plugin/lib/common/validation.d.ts +3 -0
  31. package/lib/antigravity-plugin/lib/common/validation.js +8 -0
  32. package/lib/antigravity-plugin/lib/common/version.d.ts +3 -0
  33. package/lib/antigravity-plugin/lib/common/version.js +13 -0
  34. package/lib/antigravity-plugin/lib/extension/acp-worker.js +11597 -0
  35. package/lib/antigravity-plugin/lib/extension/mcp.js +2715 -0
  36. package/lib/antigravity-plugin/lib/extension/plugin-runtime.d.ts +10 -0
  37. package/lib/antigravity-plugin/lib/extension/plugin-runtime.js +67 -0
  38. package/lib/antigravity-plugin/lib/integrations/agent-resources.d.ts +16 -0
  39. package/lib/antigravity-plugin/lib/integrations/agent-resources.js +56 -0
  40. package/lib/antigravity-plugin/lib/integrations/hosts/antigravity.d.ts +4 -0
  41. package/lib/antigravity-plugin/lib/integrations/hosts/antigravity.js +79 -0
  42. package/lib/antigravity-plugin/lib/integrations/hosts/claude.d.ts +3 -0
  43. package/lib/antigravity-plugin/lib/integrations/hosts/claude.js +60 -0
  44. package/lib/antigravity-plugin/lib/integrations/hosts/registry.d.ts +15 -0
  45. package/lib/antigravity-plugin/lib/integrations/hosts/registry.js +34 -0
  46. package/lib/antigravity-plugin/lib/model/acp.d.ts +164 -0
  47. package/lib/antigravity-plugin/lib/model/acp.js +12 -0
  48. package/lib/antigravity-plugin/lib/model/plugin-host.d.ts +48 -0
  49. package/lib/antigravity-plugin/lib/model/workspace-config.d.ts +24 -0
  50. package/lib/antigravity-plugin/lib/model/workspace-config.js +1 -0
  51. package/lib/antigravity-plugin/lib/model/workspace-mcp.d.ts +51 -0
  52. package/lib/antigravity-plugin/lib/model/workspace-mcp.js +4 -0
  53. package/lib/antigravity-plugin/lib/plugin.d.ts +1 -0
  54. package/lib/antigravity-plugin/lib/plugin.js +17 -0
  55. package/lib/antigravity-plugin/lib/services/workspace/workspace-config.d.ts +8 -0
  56. package/lib/antigravity-plugin/lib/services/workspace/workspace-config.js +95 -0
  57. package/lib/antigravity-plugin/lib/services/workspace/workspace-preparation.d.ts +3 -0
  58. package/lib/antigravity-plugin/lib/services/workspace/workspace-preparation.js +26 -0
  59. package/lib/antigravity-plugin/lib/services/workspace/workspace-skills.d.ts +8 -0
  60. package/lib/antigravity-plugin/lib/services/workspace/workspace-skills.js +91 -0
  61. package/lib/antigravity-plugin/lib/storage/atomic-json.d.ts +11 -0
  62. package/lib/antigravity-plugin/lib/storage/atomic-json.js +101 -0
  63. package/lib/antigravity-plugin/mcp_config.json +13 -0
  64. package/lib/antigravity-plugin/package.json +6 -0
  65. package/lib/antigravity-plugin/plugin.json +7 -0
  66. package/lib/antigravity-plugin/resources/agents/coordinator.md +11 -0
  67. package/{resources/claude → lib/antigravity-plugin/resources}/agents/general-purpose.md +0 -5
  68. package/lib/antigravity-plugin/resources/prompts/plugin-coordinator.md +1 -0
  69. package/lib/antigravity-plugin/resources/prompts/workspace.md +31 -0
  70. package/lib/antigravity-plugin/resources/references/compute-finance.md +22 -0
  71. package/lib/antigravity-plugin/resources/references/compute.md +16 -0
  72. package/lib/antigravity-plugin/resources/references/task-conductor.md +25 -0
  73. package/lib/antigravity-plugin/resources/templates/workspace-agents.md +21 -0
  74. package/lib/antigravity-plugin/skills/pbot/SKILL.md +16 -0
  75. package/lib/antigravity-plugin/skills/project-maintenance/SKILL.md +35 -0
  76. package/lib/antigravity-plugin/skills/provider-connections/SKILL.md +42 -0
  77. package/lib/claude.js +4 -11
  78. package/lib/client.js +14 -531
  79. package/lib/common/markdown.js +2 -3
  80. package/lib/common/validation.d.ts +2 -0
  81. package/lib/common/validation.js +4 -0
  82. package/lib/extension/acp-member.d.ts +2 -0
  83. package/lib/extension/acp-member.js +9 -8
  84. package/lib/extension/acp-worker.js +11578 -121
  85. package/lib/extension/dsh/acp-member.js +26 -2
  86. package/lib/extension/dsh/command.js +19 -57
  87. package/lib/extension/dsh/history.js +2 -4
  88. package/lib/extension/dsh/management.d.ts +0 -2
  89. package/lib/extension/dsh/management.js +27 -126
  90. package/lib/extension/dsh/workspace.d.ts +5 -47
  91. package/lib/extension/dsh/workspace.js +76 -108
  92. package/lib/extension/mcp-bridge.d.ts +41 -0
  93. package/lib/extension/mcp-bridge.js +412 -0
  94. package/lib/extension/mcp-workers.d.ts +980 -0
  95. package/lib/extension/mcp-workers.js +882 -0
  96. package/lib/extension/mcp.js +2715 -0
  97. package/lib/extension/plugin-runtime.d.ts +10 -0
  98. package/lib/extension/plugin-runtime.js +67 -0
  99. package/lib/extension/setup-cli.js +215 -2
  100. package/lib/integrations/acp/agents.d.ts +10 -11
  101. package/lib/integrations/acp/agents.js +65 -33
  102. package/lib/integrations/acp/claude.d.ts +2 -2
  103. package/lib/integrations/acp/claude.js +5 -3
  104. package/lib/integrations/acp/connection.d.ts +17 -4
  105. package/lib/integrations/acp/connection.js +53 -27
  106. package/lib/integrations/acp/executable.d.ts +3 -0
  107. package/lib/integrations/acp/executable.js +42 -0
  108. package/lib/integrations/acp/harnesses/claude.d.ts +2 -0
  109. package/lib/integrations/acp/harnesses/claude.js +49 -0
  110. package/lib/integrations/acp/harnesses/dsh.d.ts +2 -0
  111. package/lib/integrations/acp/harnesses/dsh.js +35 -0
  112. package/lib/integrations/acp/harnesses/generic.d.ts +13 -0
  113. package/lib/integrations/acp/harnesses/generic.js +37 -0
  114. package/lib/integrations/acp/harnesses/pi.d.ts +2 -0
  115. package/lib/integrations/acp/harnesses/pi.js +34 -0
  116. package/lib/integrations/acp/harnesses/presets.d.ts +3 -0
  117. package/lib/integrations/acp/harnesses/presets.js +20 -0
  118. package/lib/integrations/acp/launch.d.ts +33 -4
  119. package/lib/integrations/acp/launch.js +60 -48
  120. package/lib/integrations/acp/mcp.d.ts +6 -0
  121. package/lib/integrations/acp/mcp.js +40 -0
  122. package/lib/integrations/acp/model-selection.d.ts +9 -2
  123. package/lib/integrations/acp/model-selection.js +73 -27
  124. package/lib/integrations/acp/registry.d.ts +18 -0
  125. package/lib/integrations/acp/registry.js +50 -0
  126. package/lib/integrations/agent-resources.d.ts +16 -1
  127. package/lib/integrations/agent-resources.js +45 -9
  128. package/lib/integrations/dsh/mcp.d.ts +4 -0
  129. package/lib/integrations/dsh/mcp.js +28 -0
  130. package/lib/integrations/dsh/resources.d.ts +3 -3
  131. package/lib/integrations/dsh/resources.js +21 -12
  132. package/lib/integrations/dsh/skills.d.ts +5 -1
  133. package/lib/integrations/dsh/skills.js +10 -6
  134. package/lib/integrations/hosts/antigravity.d.ts +4 -0
  135. package/lib/integrations/hosts/antigravity.js +79 -0
  136. package/lib/integrations/hosts/claude.d.ts +3 -0
  137. package/lib/integrations/hosts/claude.js +60 -0
  138. package/lib/integrations/hosts/registry.d.ts +15 -0
  139. package/lib/integrations/hosts/registry.js +34 -0
  140. package/lib/model/acp.d.ts +107 -2
  141. package/lib/model/acp.js +12 -1
  142. package/lib/model/agent.d.ts +35 -33
  143. package/lib/model/plugin-host.d.ts +48 -0
  144. package/lib/model/plugin-host.js +1 -0
  145. package/lib/model/workspace-config.d.ts +12 -0
  146. package/lib/model/workspace-mcp.d.ts +51 -0
  147. package/lib/model/workspace-mcp.js +4 -0
  148. package/lib/plugin.d.ts +1 -0
  149. package/lib/plugin.js +17 -0
  150. package/lib/services/agents/acp-run.d.ts +13 -1
  151. package/lib/services/agents/acp-run.js +30 -2
  152. package/lib/services/agents/agent-service.d.ts +35 -120
  153. package/lib/services/agents/agent-service.js +156 -160
  154. package/lib/services/installation/setup-service.js +17 -1
  155. package/lib/services/workspace/workspace-config.d.ts +2 -1
  156. package/lib/services/workspace/workspace-config.js +43 -9
  157. package/lib/services/workspace/workspace-mcp.d.ts +14 -0
  158. package/lib/services/workspace/workspace-mcp.js +200 -0
  159. package/lib/services/workspace/workspace-skills.d.ts +8 -0
  160. package/lib/services/workspace/workspace-skills.js +91 -0
  161. package/lib/storage/acp-files.d.ts +3 -1
  162. package/lib/storage/acp-files.js +32 -2
  163. package/lib/storage/acp-history.d.ts +3 -2
  164. package/lib/storage/acp-history.js +19 -7
  165. package/lib/storage/agent-files.d.ts +8 -8
  166. package/lib/storage/agent-files.js +27 -47
  167. package/lib/tools/history/contract.d.ts +1 -1
  168. package/lib/tools/history/contract.js +17 -11
  169. package/lib/ui/dsh/index.js +8 -3
  170. package/lib/ui/dsh/management.d.ts +1 -1
  171. package/lib/ui/dsh/management.js +24 -456
  172. package/lib/ui/dsh/remote.d.ts +0 -2
  173. package/lib/ui/dsh/remote.js +1 -1
  174. package/package.json +12 -7
  175. package/resources/agents/coordinator.md +2 -2
  176. package/resources/antigravity/skills/pbot/SKILL.md +16 -0
  177. package/resources/claude/skills/pbot/SKILL.md +1 -1
  178. package/resources/prompts/history-coordinator.md +1 -0
  179. package/resources/prompts/plugin-coordinator.md +1 -0
  180. package/resources/prompts/workspace.md +9 -8
  181. package/resources/references/compute.md +9 -11
  182. package/resources/references/task-conductor.md +12 -26
  183. package/resources/skills/project-maintenance/SKILL.md +16 -21
  184. package/resources/skills/provider-connections/SKILL.md +24 -40
  185. package/resources/templates/workspace-agents.md +4 -0
  186. package/scripts/README.md +17 -34
  187. package/src/claude.ts +4 -8
  188. package/src/common/markdown.ts +2 -3
  189. package/src/common/validation.ts +6 -0
  190. package/src/extension/acp-member.ts +9 -8
  191. package/src/extension/acp-worker.ts +239 -97
  192. package/src/extension/command.ts +38 -36
  193. package/src/extension/dsh/acp-member.ts +21 -2
  194. package/src/extension/dsh/command.ts +21 -51
  195. package/src/extension/dsh/files.ts +1 -0
  196. package/src/extension/dsh/history.ts +9 -6
  197. package/src/extension/dsh/management.ts +27 -58
  198. package/src/extension/dsh/workspace.ts +88 -99
  199. package/src/extension/events.ts +13 -10
  200. package/src/extension/history.ts +2 -50
  201. package/src/extension/lifecycle.ts +37 -22
  202. package/src/extension/mcp-bridge.ts +412 -0
  203. package/src/extension/mcp-workers.ts +941 -0
  204. package/src/extension/pi-acp-member.ts +29 -5
  205. package/src/extension/plugin-runtime.ts +63 -0
  206. package/src/extension/setup-cli.ts +186 -2
  207. package/src/integrations/acp/agents.ts +70 -24
  208. package/src/integrations/acp/claude.ts +11 -4
  209. package/src/integrations/acp/connection.ts +63 -25
  210. package/src/integrations/acp/executable.ts +41 -0
  211. package/src/integrations/acp/harnesses/claude.ts +50 -0
  212. package/src/integrations/acp/harnesses/dsh.ts +40 -0
  213. package/src/integrations/acp/harnesses/generic.ts +52 -0
  214. package/src/integrations/acp/harnesses/pi.ts +35 -0
  215. package/src/integrations/acp/harnesses/presets.ts +22 -0
  216. package/src/integrations/acp/launch.ts +69 -47
  217. package/src/integrations/acp/mcp.ts +43 -0
  218. package/src/integrations/acp/model-selection.ts +68 -25
  219. package/src/integrations/acp/registry.ts +60 -0
  220. package/src/integrations/agent-resources.ts +70 -6
  221. package/src/integrations/dsh/mcp.ts +30 -0
  222. package/src/integrations/dsh/resources.ts +28 -13
  223. package/src/integrations/dsh/skills.ts +16 -6
  224. package/src/integrations/hosts/antigravity.ts +83 -0
  225. package/src/integrations/hosts/claude.ts +62 -0
  226. package/src/integrations/hosts/registry.ts +42 -0
  227. package/src/integrations/pi/mcp.ts +26 -0
  228. package/src/mcp.ts +14 -0
  229. package/src/model/acp.ts +113 -3
  230. package/src/model/agent.ts +18 -14
  231. package/src/model/plugin-host.ts +39 -0
  232. package/src/model/workspace-config.ts +14 -0
  233. package/src/model/workspace-mcp.ts +64 -0
  234. package/src/pbot.ts +69 -20
  235. package/src/plugin.ts +19 -0
  236. package/src/services/agents/acp-run.ts +35 -3
  237. package/src/services/agents/agent-service.ts +180 -160
  238. package/src/services/installation/setup-service.ts +17 -2
  239. package/src/services/workspace/workspace-config.ts +46 -8
  240. package/src/services/workspace/workspace-mcp.ts +242 -0
  241. package/src/services/workspace/workspace-skills.ts +78 -0
  242. package/src/storage/acp-files.ts +32 -3
  243. package/src/storage/acp-history.ts +18 -7
  244. package/src/storage/agent-files.ts +27 -41
  245. package/src/tools/history/contract.ts +17 -11
  246. package/src/tools/register.ts +4 -8
  247. package/src/ui/dsh/index.ts +8 -3
  248. package/src/ui/dsh/management.ts +40 -282
  249. package/src/ui/dsh/remote.ts +2 -2
  250. package/docs/adr/0001-claude-skill-discovery.md +0 -3
  251. package/docs/adr/0002-claude-native-collaboration.md +0 -3
  252. package/docs/agent-collaboration.md +0 -190
  253. package/docs/architecture-guidelines.md +0 -37
  254. package/docs/capability-design.md +0 -55
  255. package/docs/claude-code-design.md +0 -44
  256. package/docs/claude-code.md +0 -57
  257. package/docs/dsh.md +0 -337
  258. package/docs/file-storage.md +0 -97
  259. package/docs/history.md +0 -54
  260. package/docs/installation-design.md +0 -86
  261. package/docs/interaction-design.md +0 -21
  262. package/docs/model-context.md +0 -76
  263. package/docs/model-instruction-guidelines.md +0 -51
  264. package/docs/release.md +0 -108
  265. package/docs/technical-design.md +0 -163
  266. package/docs/workspace-configuration.md +0 -79
  267. package/lib/extension/claude-hooks.d.ts +0 -9
  268. package/lib/extension/claude-hooks.js +0 -78
  269. package/lib/extension/dsh/agent-events.d.ts +0 -24
  270. package/lib/extension/dsh/agent-events.js +0 -242
  271. package/lib/extension/dsh/agent-runtime.d.ts +0 -49
  272. package/lib/extension/dsh/agent-runtime.js +0 -351
  273. package/lib/integrations/dsh/dsh-agents.d.ts +0 -30
  274. package/lib/integrations/dsh/dsh-agents.js +0 -104
  275. package/lib/integrations/dsh/input.d.ts +0 -21
  276. package/lib/integrations/dsh/input.js +0 -62
  277. package/lib/integrations/dsh/notifications.d.ts +0 -8
  278. package/lib/integrations/dsh/notifications.js +0 -55
  279. package/lib/integrations/dsh/session.d.ts +0 -14
  280. package/lib/integrations/dsh/session.js +0 -60
  281. package/lib/integrations/team-context.d.ts +0 -18
  282. package/lib/integrations/team-context.js +0 -61
  283. package/lib/model/team.d.ts +0 -85
  284. package/lib/services/agents/agent-notices.d.ts +0 -13
  285. package/lib/services/agents/agent-notices.js +0 -25
  286. package/lib/services/agents/start-options.d.ts +0 -4
  287. package/lib/services/agents/start-options.js +0 -20
  288. package/lib/services/agents/team-service.d.ts +0 -168
  289. package/lib/services/agents/team-service.js +0 -345
  290. package/lib/storage/team-files.d.ts +0 -16
  291. package/lib/storage/team-files.js +0 -111
  292. package/lib/tools/agents/actions.d.ts +0 -62
  293. package/lib/tools/agents/actions.js +0 -62
  294. package/lib/tools/agents/contract.d.ts +0 -181
  295. package/lib/tools/agents/contract.js +0 -84
  296. package/lib/tools/agents/dsh-tool.d.ts +0 -5
  297. package/lib/tools/agents/dsh-tool.js +0 -34
  298. package/lib/tools/result.d.ts +0 -18
  299. package/lib/tools/result.js +0 -10
  300. package/lib/tools/teams/actions.d.ts +0 -23
  301. package/lib/tools/teams/actions.js +0 -40
  302. package/lib/tools/teams/contract.d.ts +0 -201
  303. package/lib/tools/teams/contract.js +0 -91
  304. package/lib/tools/teams/dsh-tool.d.ts +0 -8
  305. package/lib/tools/teams/dsh-tool.js +0 -39
  306. package/lib/ui/dsh/attachments.d.ts +0 -5
  307. package/lib/ui/dsh/attachments.js +0 -39
  308. package/resources/prompts/claude-coordinator.md +0 -1
  309. package/resources/prompts/native-coordinator.md +0 -1
  310. package/resources/prompts/team-member.md +0 -7
  311. package/src/extension/agent-events.ts +0 -210
  312. package/src/extension/agents-command.ts +0 -89
  313. package/src/extension/claude-hooks.ts +0 -74
  314. package/src/extension/dsh/agent-events.ts +0 -148
  315. package/src/extension/dsh/agent-runtime.ts +0 -252
  316. package/src/extension/subagent-entry.ts +0 -270
  317. package/src/extension/teams-command.ts +0 -67
  318. package/src/integrations/dsh/dsh-agents.ts +0 -97
  319. package/src/integrations/dsh/input.ts +0 -66
  320. package/src/integrations/dsh/notifications.ts +0 -46
  321. package/src/integrations/pi/agent-context.ts +0 -18
  322. package/src/integrations/pi/agent-input.ts +0 -19
  323. package/src/integrations/pi/pi-agents.ts +0 -84
  324. package/src/integrations/pi/team-context.ts +0 -26
  325. package/src/integrations/team-context.ts +0 -64
  326. package/src/model/team.ts +0 -29
  327. package/src/services/agents/agent-notices.ts +0 -28
  328. package/src/services/agents/start-options.ts +0 -19
  329. package/src/services/agents/team-service.ts +0 -275
  330. package/src/storage/team-files.ts +0 -93
  331. package/src/tools/agents/actions.ts +0 -57
  332. package/src/tools/agents/contract.ts +0 -101
  333. package/src/tools/agents/dsh-tool.ts +0 -37
  334. package/src/tools/agents/tool.ts +0 -20
  335. package/src/tools/teams/actions.ts +0 -34
  336. package/src/tools/teams/contract.ts +0 -109
  337. package/src/tools/teams/dsh-tool.ts +0 -45
  338. package/src/tools/teams/tool.ts +0 -29
  339. package/src/ui/agent-display.ts +0 -14
  340. package/src/ui/dsh/attachments.ts +0 -42
  341. package/src/ui/pi/menu.ts +0 -37
  342. package/src/ui/pi/reader.ts +0 -46
  343. /package/lib/{model/team.js → antigravity-plugin/lib/model/plugin-host.js} +0 -0
@@ -4,15 +4,17 @@ import { setTimeout as delay } from "node:timers/promises";
4
4
  import * as acp from "@agentclientprotocol/sdk";
5
5
  import { requireThat } from "../../common/validation.js";
6
6
  import { packageVersion } from "../../common/version.js";
7
- import { acpModelSelection, acpModelValue, acpThinkingValue } from "./model-selection.js";
8
- import { object } from "../../common/json.js";
7
+ import { acpChoices, acpModelSelection, acpModelValue, acpThinkingValue } from "./model-selection.js";
8
+ import { filterAcpMcpServers } from "./mcp.js";
9
+ import { resolveAcpHarness } from "./registry.js";
9
10
  export function acpFailure(error) {
10
11
  return error instanceof acp.RequestError && error.data !== undefined
11
12
  ? new Error(error.message + ":" + JSON.stringify(error.data), { cause: error }) : error;
12
13
  }
13
- /** One ACP v1 connection. The worker owns its process group and business state. */
14
- export async function openAcp(reference, cwd, env, callbacks, signal, systemPrompt, claude) {
14
+ /** One ACP v1 connection. The worker owns its process group and business state; harness hooks stay in AcpHarnessAdapter. */
15
+ export async function openAcp(reference, cwd, env, callbacks, signal, openOptions = {}) {
15
16
  signal.throwIfAborted();
17
+ const harness = openOptions.harness ?? resolveAcpHarness(reference.backend);
16
18
  const child = spawn(reference.command, reference.args, { cwd, env, stdio: ["pipe", "pipe", "pipe"] });
17
19
  const lifetime = new AbortController();
18
20
  const cancel = AbortSignal.any([signal, lifetime.signal]);
@@ -24,14 +26,23 @@ export async function openAcp(reference, cwd, env, callbacks, signal, systemProm
24
26
  let sessionId;
25
27
  let options = [];
26
28
  let resolvedModel;
27
- const selection = () => ({ ...acpModelSelection(reference.backend, options, claude?.thinking),
28
- ...(resolvedModel ? { resolvedModel } : {}) });
29
+ const selection = () => ({
30
+ ...acpModelSelection(reference.backend, options, openOptions.defaultThinking),
31
+ ...(resolvedModel ? { resolvedModel } : {}),
32
+ });
29
33
  let updating = Promise.resolve();
30
- const app = acp.client({ name: "personal-bot" })
34
+ let app = acp.client({ name: "personal-bot" })
31
35
  .onRequest(acp.methods.client.session.requestPermission, async (ctx) => {
32
36
  if (cancel.aborted || ctx.params.sessionId !== sessionId)
33
37
  return { outcome: { outcome: "cancelled" } };
34
38
  return callbacks.permission(ctx.params, cancel);
39
+ })
40
+ .onRequest(acp.methods.client.elicitation.create, async (ctx) => {
41
+ if (cancel.aborted || !callbacks.elicitation)
42
+ return { action: "cancel" };
43
+ if ("sessionId" in ctx.params && ctx.params.sessionId !== sessionId)
44
+ return { action: "cancel" };
45
+ return callbacks.elicitation(ctx.params, cancel);
35
46
  })
36
47
  .onNotification(acp.methods.client.session.update, ctx => {
37
48
  // Load may replay before its response. Output from replay never becomes a new report.
@@ -49,18 +60,21 @@ export async function openAcp(reference, cwd, env, callbacks, signal, systemProm
49
60
  });
50
61
  void updating.catch(error => lifetime.abort(error));
51
62
  return updating;
52
- })
53
- .onNotification("_claude/sdkMessage", (value) => value, ctx => {
54
- if (reference.backend !== "claude" || !object(ctx.params) || ctx.params.sessionId !== sessionId || cancel.aborted)
55
- return;
56
- const message = ctx.params.message;
57
- if (!object(message) || message.type !== "system" || message.subtype !== "init" || typeof message.model !== "string" || !message.model)
58
- return;
59
- const model = message.model;
60
- updating = updating.then(() => { resolvedModel = model; callbacks.selection?.(selection()); });
61
- void updating.catch(error => lifetime.abort(error));
62
- return updating;
63
63
  });
64
+ if (harness.customNotificationMethod && harness.parseCustomNotification) {
65
+ const parse = harness.parseCustomNotification;
66
+ app = app.onNotification(harness.customNotificationMethod, (value) => value, ctx => {
67
+ if (!sessionId || cancel.aborted)
68
+ return;
69
+ const parsed = parse(ctx.params, sessionId);
70
+ if (!parsed?.resolvedModel)
71
+ return;
72
+ const model = parsed.resolvedModel;
73
+ updating = updating.then(() => { resolvedModel = model; callbacks.selection?.(selection()); });
74
+ void updating.catch(error => lifetime.abort(error));
75
+ return updating;
76
+ });
77
+ }
64
78
  const connection = await app.connect(acp.ndJsonStream(Writable.toWeb(child.stdin), Readable.toWeb(child.stdout), { maxMessageBytes: 8 * 1024 * 1024 }));
65
79
  const abort = () => connection.close(cancel.reason);
66
80
  cancel.addEventListener("abort", abort, { once: true });
@@ -97,24 +111,35 @@ export async function openAcp(reference, cwd, env, callbacks, signal, systemProm
97
111
  let initialized;
98
112
  try {
99
113
  initialized = await connection.agent.request(acp.methods.agent.initialize, {
100
- protocolVersion: 1, clientCapabilities: {}, clientInfo: { name: "personal-bot", version: packageVersion },
114
+ protocolVersion: 1,
115
+ clientCapabilities: callbacks.elicitation ? { elicitation: { form: {}, url: {} } } : {},
116
+ clientInfo: { name: "personal-bot", version: packageVersion },
101
117
  }, { cancellationSignal: AbortSignal.any([cancel, AbortSignal.timeout(30_000)]), stopWaitingOnCancel: true });
102
118
  requireThat(initialized.protocolVersion === 1, "目标宿主没有协商 ACP v1。");
103
119
  const advertised = initialized.agentCapabilities;
104
- const capabilities = { resume: Boolean(advertised?.sessionCapabilities?.resume), load: advertised?.loadSession === true,
105
- close: Boolean(advertised?.sessionCapabilities?.close) };
106
- const setup = { cwd, mcpServers: [],
107
- ...(reference.backend === "claude" ? { _meta: { claudeCode: { options: { ...claude?.options, disallowedTools: ["Agent", "Task"] },
108
- emitRawSDKMessages: [{ type: "system", subtype: "init" }] } } } : {}), ...(systemPrompt && advertised?.sessionCapabilities?.systemPrompt ? {
109
- systemPrompt: { mode: "append", content: [{ type: "text", text: systemPrompt }] },
110
- } : {}) };
120
+ const capabilities = {
121
+ resume: Boolean(advertised?.sessionCapabilities?.resume),
122
+ load: advertised?.loadSession === true,
123
+ close: Boolean(advertised?.sessionCapabilities?.close),
124
+ };
125
+ const mcpServers = openOptions.mcpServers?.length
126
+ ? filterAcpMcpServers(openOptions.mcpServers, advertised?.mcpCapabilities)
127
+ : [];
128
+ const setup = {
129
+ cwd,
130
+ mcpServers,
131
+ ...(openOptions.sessionMeta ? { _meta: openOptions.sessionMeta } : {}),
132
+ ...(openOptions.systemPrompt && advertised?.sessionCapabilities?.systemPrompt ? {
133
+ systemPrompt: { mode: "append", content: [{ type: "text", text: openOptions.systemPrompt }] },
134
+ } : {}),
135
+ };
111
136
  if (reference.sessionId === null) {
112
137
  const created = await connection.agent.request(acp.methods.agent.session.new, setup, { cancellationSignal: AbortSignal.any([cancel, AbortSignal.timeout(30_000)]), stopWaitingOnCancel: true });
113
138
  sessionId = created.sessionId;
114
139
  options = created.configOptions ?? [];
115
140
  }
116
141
  else {
117
- requireThat(capabilities.resume || capabilities.load, "目标 ACP 后端不支持恢复已有会话。");
142
+ requireThat(capabilities.resume || capabilities.load, "目标 ACP 后端不支持恢复已有会话,请新建 worker。");
118
143
  const restored = capabilities.resume
119
144
  ? await connection.agent.request(acp.methods.agent.session.resume, { ...setup, sessionId: reference.sessionId }, { cancellationSignal: AbortSignal.any([cancel, AbortSignal.timeout(30_000)]), stopWaitingOnCancel: true })
120
145
  : await connection.agent.request(acp.methods.agent.session.load, { ...setup, sessionId: reference.sessionId }, { cancellationSignal: AbortSignal.any([cancel, AbortSignal.timeout(30_000)]), stopWaitingOnCancel: true });
@@ -127,6 +152,7 @@ export async function openAcp(reference, cwd, env, callbacks, signal, systemProm
127
152
  sessionId: activeId, capabilities, signal: connected, close, images: advertised?.promptCapabilities?.image === true,
128
153
  systemPrompt: Boolean(advertised?.sessionCapabilities?.systemPrompt),
129
154
  selection,
155
+ choices: () => acpChoices(options),
130
156
  async configure(requested) {
131
157
  requireThat(!requested.provider || requested.model, "provider 需要同时指定目标 model。");
132
158
  for (const kind of ["model", "thinking"]) {
@@ -0,0 +1,3 @@
1
+ import type { AcpBackend, AcpHarnessAdapter } from "../../model/acp.js";
2
+ export declare function findAcpExecutable(command: string): string | undefined;
3
+ export declare function acpExecutable(command: string, backend: AcpBackend, harness?: AcpHarnessAdapter): string;
@@ -0,0 +1,42 @@
1
+ import { accessSync, constants, realpathSync, statSync } from "node:fs";
2
+ import { delimiter, isAbsolute, resolve } from "node:path";
3
+ export function findAcpExecutable(command) {
4
+ const candidates = isAbsolute(command)
5
+ ? [command]
6
+ : (process.env.PATH ?? "").split(delimiter).filter(Boolean).map(directory => resolve(directory, command));
7
+ for (const candidate of candidates) {
8
+ try {
9
+ accessSync(candidate, constants.X_OK);
10
+ if (statSync(candidate).isFile())
11
+ return realpathSync(candidate);
12
+ }
13
+ catch (error) {
14
+ if (!["ENOENT", "ENOTDIR", "EACCES", "EPERM"].includes(error.code ?? ""))
15
+ throw error;
16
+ }
17
+ }
18
+ return undefined;
19
+ }
20
+ export function acpExecutable(command, backend, harness) {
21
+ const found = findAcpExecutable(command);
22
+ if (found)
23
+ return found;
24
+ const nativePi = backend === "pi" && command === "pi";
25
+ const targetCommand = harness?.defaultCommand?.command ?? command;
26
+ const targetArgs = harness?.defaultCommand?.args ?? [];
27
+ const install = nativePi
28
+ ? "npm install -g @earendil-works/pi-coding-agent"
29
+ : harness?.installHint ?? `请确认 ${backend} 对应的 ACP 可执行文件已安装。`;
30
+ const configured = JSON.stringify({ command: "/absolute/path/to/" + targetCommand, args: targetArgs });
31
+ const pathHint = nativePi
32
+ ? "Pi 已安装但 PATH 不可见时,启动主宿主前将 PI_ACP_PI_COMMAND 设置为 pi 的绝对路径。"
33
+ : "已安装但 PATH 不可见时,在 .pbot/config.json 设置 acp." + backend + ":" + configured + ",command 使用实际绝对路径。";
34
+ throw new Error([
35
+ "未找到子代理程序:" + command + "。",
36
+ "安装提示:" + install,
37
+ ...(harness?.configureHint ? [harness.configureHint] : []),
38
+ "检查安装路径:command -v " + (nativePi ? "pi" : targetCommand) + (!nativePi && backend === "pi" ? ";另用 command -v pi 检查 Pi。" : "。"),
39
+ pathHint,
40
+ "安装后重试原 start 请求;PATH 变化时重启主宿主。配置修改后,Pi 执行 /reload,dsh 重启宿主。",
41
+ ].join("\n"));
42
+ }
@@ -0,0 +1,2 @@
1
+ import type { AcpHarnessAdapter } from "../../../model/acp.js";
2
+ export declare const claudeAcpHarness: AcpHarnessAdapter;
@@ -0,0 +1,49 @@
1
+ import { object } from "../../../common/json.js";
2
+ import { requireThat } from "../../../common/validation.js";
3
+ import { claudeOptions } from "../claude.js";
4
+ import { defaultPrepareLaunch, filterStandardAcpOptions, validateStandardAcpOptions } from "./generic.js";
5
+ export const claudeAcpHarness = {
6
+ id: "claude",
7
+ label: "Claude Code",
8
+ aliases: ["claude-code", "claudecode"],
9
+ defaultCommand: { command: "claude-agent-acp", args: [] },
10
+ installHint: "npm install -g @agentclientprotocol/claude-agent-acp",
11
+ configureHint: "在 Claude Code 中完成登录或 API 配置,并设置默认模型。",
12
+ requireSystemPrompt: true,
13
+ nativeWorkspaceSkills: false,
14
+ customNotificationMethod: "_claude/sdkMessage",
15
+ filterStartOptions(options) {
16
+ const filtered = filterStandardAcpOptions(options);
17
+ delete filtered.provider;
18
+ return filtered;
19
+ },
20
+ validateStartOptions(options) {
21
+ validateStandardAcpOptions("claude", options);
22
+ requireThat(options.noSkills === undefined && options.tools === undefined, "Claude 子代理的技能和工具通过 Claude 原生配置选择。");
23
+ requireThat(options.provider === undefined, "Claude 子代理使用原生提供方配置;请仅指定目标 model。");
24
+ },
25
+ async prepareLaunch(context) {
26
+ const base = defaultPrepareLaunch(context);
27
+ const claude = await claudeOptions(base.command, context.cwd, context.options.thinking, context.features?.skills !== false);
28
+ return {
29
+ ...base,
30
+ ...(claude.thinking ? { defaultThinking: claude.thinking } : {}),
31
+ sessionMeta: {
32
+ claudeCode: {
33
+ options: { ...claude.options, disallowedTools: ["Agent", "Task"] },
34
+ emitRawSDKMessages: [{ type: "system", subtype: "init" }],
35
+ },
36
+ },
37
+ };
38
+ },
39
+ parseModelValue: value => ({ model: value }),
40
+ parseCustomNotification(params, sessionId) {
41
+ if (!object(params) || params.sessionId !== sessionId)
42
+ return undefined;
43
+ const message = params.message;
44
+ if (!object(message) || message.type !== "system" || message.subtype !== "init" || typeof message.model !== "string" || !message.model) {
45
+ return undefined;
46
+ }
47
+ return { resolvedModel: message.model };
48
+ },
49
+ };
@@ -0,0 +1,2 @@
1
+ import type { AcpHarnessAdapter } from "../../../model/acp.js";
2
+ export declare const dshAcpHarness: AcpHarnessAdapter;
@@ -0,0 +1,35 @@
1
+ import { writeFile } from "node:fs/promises";
2
+ import { join } from "node:path";
3
+ import { defaultPrepareLaunch, filterStandardAcpOptions, validateStandardAcpOptions } from "./generic.js";
4
+ export const dshAcpHarness = {
5
+ id: "dsh",
6
+ label: "DeepSeek dsh",
7
+ defaultCommand: { command: "dsh", args: ["--profile", "acp"] },
8
+ installHint: "npm install -g @deepseek-ai/dsh@latest",
9
+ configureHint: "按 dsh 原生方式配置目标 profile 的模型与认证。",
10
+ exactAnswer: true,
11
+ eagerSessionId: true,
12
+ nativeWorkspaceSkills: true,
13
+ nativeWorkspaceMcp: true,
14
+ filterStartOptions: filterStandardAcpOptions,
15
+ validateStartOptions: options => validateStandardAcpOptions("dsh", options),
16
+ async prepareLaunch(context) {
17
+ const base = defaultPrepareLaunch(context);
18
+ const patch = join(context.directory, "acp-dsh-patch.json");
19
+ await writeFile(patch, JSON.stringify([{ insert: [{ id: "pbot-acp-member", name: join(context.packageRoot, "lib/extension/dsh/acp-member.js") }] }]) + "\n", { mode: 0o600 });
20
+ return {
21
+ ...base,
22
+ command: { ...base.command, args: [...base.command.args, "--patch", patch] },
23
+ };
24
+ },
25
+ parseModelValue(value) {
26
+ try {
27
+ const parts = JSON.parse(value);
28
+ if (Array.isArray(parts) && parts.length === 2 && parts.every(part => typeof part === "string" && part.length > 0)) {
29
+ return { provider: parts[0], model: parts[1] };
30
+ }
31
+ }
32
+ catch { /* Unencoded identifiers remain usable as exact ACP option values. */ }
33
+ return { model: value };
34
+ },
35
+ };
@@ -0,0 +1,13 @@
1
+ import type { AcpBackend, AcpCommand, AcpHarnessAdapter, AcpLaunchContext, AcpPreparedLaunch, AcpStartOptions } from "../../../model/acp.js";
2
+ export declare function filterStandardAcpOptions(options: AcpStartOptions): AcpStartOptions;
3
+ export declare function validateStandardAcpOptions(backend: AcpBackend, options: AcpStartOptions): void;
4
+ export declare function defaultPrepareLaunch(context: AcpLaunchContext): AcpPreparedLaunch;
5
+ /** Generic ACP v1 harness adapter; works for any standard ACP v1 executable without special cases. */
6
+ export declare function createGenericAcpHarness(id: AcpBackend, preset?: {
7
+ label?: string;
8
+ aliases?: readonly string[];
9
+ defaultCommand?: AcpCommand;
10
+ installHint?: string;
11
+ configureHint?: string;
12
+ nativeWorkspaceSkills?: boolean;
13
+ }): AcpHarnessAdapter;
@@ -0,0 +1,37 @@
1
+ import { requireThat } from "../../../common/validation.js";
2
+ const piOnlyOptions = ["noExtensions", "noPromptTemplates", "noContextFiles"];
3
+ export function filterStandardAcpOptions(options) {
4
+ const result = { ...options };
5
+ for (const key of piOnlyOptions)
6
+ delete result[key];
7
+ delete result.noSkills;
8
+ delete result.tools;
9
+ return result;
10
+ }
11
+ export function validateStandardAcpOptions(backend, options) {
12
+ for (const key of piOnlyOptions) {
13
+ requireThat(options[key] === undefined, backend + " 子代理不支持启动选项:" + key);
14
+ }
15
+ }
16
+ export function defaultPrepareLaunch(context) {
17
+ return {
18
+ command: { ...context.reference, args: [...context.reference.args] },
19
+ env: { ...context.env, ...(context.reference.env ?? {}) },
20
+ };
21
+ }
22
+ /** Generic ACP v1 harness adapter; works for any standard ACP v1 executable without special cases. */
23
+ export function createGenericAcpHarness(id, preset = {}) {
24
+ return {
25
+ id,
26
+ ...(preset.label ? { label: preset.label } : {}),
27
+ ...(preset.aliases ? { aliases: preset.aliases } : {}),
28
+ ...(preset.defaultCommand ? { defaultCommand: preset.defaultCommand } : {}),
29
+ ...(preset.installHint ? { installHint: preset.installHint } : {}),
30
+ ...(preset.configureHint ? { configureHint: preset.configureHint } : {}),
31
+ ...(preset.nativeWorkspaceSkills !== undefined ? { nativeWorkspaceSkills: preset.nativeWorkspaceSkills } : {}),
32
+ filterStartOptions: filterStandardAcpOptions,
33
+ validateStartOptions: options => validateStandardAcpOptions(id, options),
34
+ prepareLaunch: defaultPrepareLaunch,
35
+ parseModelValue: value => ({ model: value }),
36
+ };
37
+ }
@@ -0,0 +1,2 @@
1
+ import type { AcpHarnessAdapter } from "../../../model/acp.js";
2
+ export declare const piAcpHarness: AcpHarnessAdapter;
@@ -0,0 +1,34 @@
1
+ import { join } from "node:path";
2
+ import { acpExecutable } from "../executable.js";
3
+ import { defaultPrepareLaunch } from "./generic.js";
4
+ export const piAcpHarness = {
5
+ id: "pi",
6
+ label: "Pi",
7
+ defaultCommand: { command: "pi-acp", args: [] },
8
+ installHint: "npm install -g pi-acp",
9
+ configureHint: "Pi 也需已安装;运行 pi 完成登录和默认模型配置。",
10
+ exactAnswer: true,
11
+ nativeWorkspaceSkills: true,
12
+ nativeWorkspaceMcp: true,
13
+ filterStartOptions: options => ({ ...options }),
14
+ prepareLaunch(context) {
15
+ const base = defaultPrepareLaunch(context);
16
+ return {
17
+ ...base,
18
+ env: {
19
+ ...base.env,
20
+ PBOT_ACP_PI_COMMAND: process.env.PI_ACP_PI_COMMAND ?? acpExecutable("pi", "pi"),
21
+ PI_ACP_PI_COMMAND: join(context.packageRoot, "bin/pbot-pi-acp.mjs"),
22
+ },
23
+ };
24
+ },
25
+ parseModelValue(value) {
26
+ const separator = value.indexOf("/");
27
+ if (separator > 0)
28
+ return { provider: value.slice(0, separator), model: value.slice(separator + 1) };
29
+ return { model: value };
30
+ },
31
+ formatModelQuery(model, provider) {
32
+ return provider ? provider + "/" + model : undefined;
33
+ },
34
+ };
@@ -0,0 +1,3 @@
1
+ import type { AcpHarnessAdapter } from "../../../model/acp.js";
2
+ /** Declarative standard ACP v1 presets requiring no host-specific adapter code. */
3
+ export declare const standardAcpPresets: readonly AcpHarnessAdapter[];
@@ -0,0 +1,20 @@
1
+ import { createGenericAcpHarness } from "./generic.js";
2
+ /** Declarative standard ACP v1 presets requiring no host-specific adapter code. */
3
+ export const standardAcpPresets = [
4
+ createGenericAcpHarness("antigravity", {
5
+ label: "Google Antigravity",
6
+ aliases: ["agy"],
7
+ defaultCommand: { command: "agy", args: ["acp"] },
8
+ installHint: "安装 Google Antigravity CLI(agy)",
9
+ configureHint: "运行 agy 完成登录与默认模型配置。",
10
+ nativeWorkspaceSkills: true,
11
+ }),
12
+ createGenericAcpHarness("codex", {
13
+ label: "OpenAI Codex",
14
+ aliases: ["openai-codex", "codex-cli"],
15
+ defaultCommand: { command: "codex-acp", args: [] },
16
+ installHint: "npm install -g @agentclientprotocol/codex-acp",
17
+ configureHint: "在 Codex 中完成登录或 API 配置。",
18
+ nativeWorkspaceSkills: true,
19
+ }),
20
+ ];
@@ -1,4 +1,33 @@
1
- import type { AcpBackend, AcpCommands, AcpSessionReference } from "../../model/acp.js";
2
- import type { AgentOptions } from "../../model/agent.js";
3
- export declare function acpExecutable(command: string, backend: AcpBackend): string;
4
- export declare function acpLaunch(backend: AcpBackend, commands: AcpCommands, options: AgentOptions): AcpSessionReference;
1
+ import type { AcpBackend, AcpCommand, AcpCommands, AcpPermissionPolicy, AcpSessionReference, AcpStartOptions } from "../../model/acp.js";
2
+ export { acpExecutable, findAcpExecutable } from "./executable.js";
3
+ /** Workspace entries override a registered default command; an entry without `command` only adjusts env or permission. */
4
+ export declare function configuredAcpCommand(backend: AcpBackend, commands?: AcpCommands): AcpCommand | undefined;
5
+ export declare function acpPermissionPolicy(backend: AcpBackend, commands?: AcpCommands): AcpPermissionPolicy;
6
+ /** Names callers may use: registered harnesses plus workspace-configured custom harnesses. */
7
+ export declare function knownAcpBackends(commands?: AcpCommands): AcpBackend[];
8
+ export declare function canonicalAcpBackend(name: string, commands?: AcpCommands): AcpBackend;
9
+ export declare function inspectAcpBackends(commands?: AcpCommands): ({
10
+ resolvedCommand: string;
11
+ available: boolean;
12
+ builtin: boolean;
13
+ configured: boolean;
14
+ permission: AcpPermissionPolicy;
15
+ command: string;
16
+ args: string[];
17
+ aliases?: string[];
18
+ label?: string;
19
+ backend: string;
20
+ } | {
21
+ installHint: string;
22
+ available: boolean;
23
+ builtin: boolean;
24
+ configured: boolean;
25
+ permission: AcpPermissionPolicy;
26
+ command: string;
27
+ args: string[];
28
+ aliases?: string[];
29
+ label?: string;
30
+ backend: string;
31
+ })[];
32
+ export declare function filterAcpStartOptions(backend: AcpBackend, options: AcpStartOptions): AcpStartOptions;
33
+ export declare function acpLaunch(backend: AcpBackend, commands: AcpCommands, options: AcpStartOptions): AcpSessionReference;
@@ -1,52 +1,64 @@
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
- const targets = {
5
- pi: { command: "pi-acp", args: [], install: "npm install -g pi-acp",
6
- configure: "Pi 也需已安装;运行 pi 完成登录和默认模型配置。" },
7
- dsh: { command: "dsh", args: ["--profile", "acp"], install: "npm install -g @deepseek-ai/dsh@latest",
8
- configure: "按 dsh 原生方式配置目标 profile 的模型与认证。" },
9
- claude: { command: "claude-agent-acp", args: [], install: "npm install -g @agentclientprotocol/claude-agent-acp",
10
- configure: "在 Claude Code 中完成登录或 API 配置,并设置默认模型。" },
11
- };
12
- export function acpExecutable(command, backend) {
13
- const candidates = isAbsolute(command) ? [command] : (process.env.PATH ?? "").split(delimiter).filter(Boolean).map(directory => resolve(directory, command));
14
- for (const candidate of candidates) {
15
- try {
16
- accessSync(candidate, constants.X_OK);
17
- if (statSync(candidate).isFile())
18
- return realpathSync(candidate);
19
- }
20
- catch (error) {
21
- if (!["ENOENT", "ENOTDIR", "EACCES"].includes(error.code ?? ""))
22
- throw error;
23
- }
24
- }
25
- const target = targets[backend], nativePi = backend === "pi" && command === "pi";
26
- const install = nativePi ? "npm install -g @earendil-works/pi-coding-agent" : target.install;
27
- const configured = JSON.stringify({ command: "/absolute/path/to/" + target.command, args: target.args });
28
- const path = nativePi ? "Pi 已安装但 PATH 不可见时,启动主宿主前将 PI_ACP_PI_COMMAND 设置为 pi 的绝对路径。"
29
- : "已安装但 PATH 不可见时,在 .pbot/config.json 设置 acp." + backend + ":" + configured + ",command 使用实际绝对路径。";
30
- throw new Error([
31
- "未找到子代理程序:" + command + "。",
32
- "在运行 Pi/dsh 的机器上安装:" + install,
33
- target.configure,
34
- "检查安装路径:command -v " + (nativePi ? "pi" : target.command) + (!nativePi && backend === "pi" ? ";另用 command -v pi 检查 Pi。" : "。"),
35
- path,
36
- "安装后重试原 start 请求;PATH 变化时重启主宿主。配置修改后,Pi 执行 /reload,dsh 重启宿主。",
37
- ].join("\n"));
1
+ import { isAcpBackend, requireThat } from "../../common/validation.js";
2
+ import { acpExecutable, findAcpExecutable } from "./executable.js";
3
+ import { acpHarnesses, resolveAcpHarness } from "./registry.js";
4
+ export { acpExecutable, findAcpExecutable } from "./executable.js";
5
+ /** Workspace entries override a registered default command; an entry without `command` only adjusts env or permission. */
6
+ export function configuredAcpCommand(backend, commands = {}) {
7
+ const entry = Object.hasOwn(commands, backend) ? commands[backend] : undefined;
8
+ const base = entry?.command ? { command: entry.command, args: entry.args ?? [] } : acpHarnesses.get(backend)?.defaultCommand;
9
+ if (!base)
10
+ return undefined;
11
+ const env = { ...base.env, ...entry?.env };
12
+ return { command: base.command, args: [...base.args], ...(Object.keys(env).length ? { env } : {}) };
13
+ }
14
+ export function acpPermissionPolicy(backend, commands = {}) {
15
+ return (Object.hasOwn(commands, backend) ? commands[backend]?.permission : undefined) ?? "ask";
16
+ }
17
+ /** Names callers may use: registered harnesses plus workspace-configured custom harnesses. */
18
+ export function knownAcpBackends(commands = {}) {
19
+ return [...new Set([...acpHarnesses.list(), ...Object.keys(commands)])].filter(backend => configuredAcpCommand(backend, commands));
20
+ }
21
+ export function canonicalAcpBackend(name, commands = {}) {
22
+ return acpHarnesses.canonical(name, Object.keys(commands));
23
+ }
24
+ export function inspectAcpBackends(commands = {}) {
25
+ return knownAcpBackends(commands).map(backend => {
26
+ const harness = acpHarnesses.get(backend);
27
+ const selected = configuredAcpCommand(backend, commands);
28
+ const resolved = findAcpExecutable(selected.command);
29
+ return {
30
+ backend,
31
+ ...(harness?.label ? { label: harness.label } : {}),
32
+ ...(harness?.aliases?.length ? { aliases: [...harness.aliases] } : {}),
33
+ available: Boolean(resolved),
34
+ builtin: Boolean(harness?.defaultCommand),
35
+ configured: Object.hasOwn(commands, backend),
36
+ permission: acpPermissionPolicy(backend, commands),
37
+ command: selected.command,
38
+ args: [...selected.args],
39
+ ...(resolved ? { resolvedCommand: resolved } : { installHint: harness?.installHint ?? "在 .pbot/config.json 的 acp 字段配置可执行命令。" }),
40
+ };
41
+ });
42
+ }
43
+ export function filterAcpStartOptions(backend, options) {
44
+ const harness = resolveAcpHarness(backend);
45
+ return harness.filterStartOptions ? harness.filterStartOptions(options) : { ...options };
38
46
  }
39
47
  export function acpLaunch(backend, commands, options) {
40
- requireThat(["pi", "dsh", "claude"].includes(backend), "未知子代理程序。");
48
+ requireThat(isAcpBackend(backend), "未知子代理程序:" + String(backend));
49
+ const harness = resolveAcpHarness(backend);
50
+ const selected = configuredAcpCommand(backend, commands);
51
+ requireThat(selected, `未知子代理程序:${backend}。可用目标:${knownAcpBackends(commands).join(", ")};自定义目标请在 .pbot/config.json 的 acp 字段中配置。`);
41
52
  requireThat(!options.provider || options.model, "provider 需要同时指定目标 model。");
42
- if (backend !== "pi")
43
- for (const key of ["noExtensions", "noPromptTemplates", "noContextFiles"]) {
44
- requireThat(options[key] === undefined, backend + " 子代理不支持启动选项:" + key);
45
- }
46
- if (backend === "claude") {
47
- requireThat(options.noSkills === undefined && options.tools === undefined, "Claude 子代理的技能和工具通过 Claude 原生配置选择。");
48
- requireThat(options.provider === undefined, "Claude 子代理使用原生提供方配置;请仅指定目标 model。");
49
- }
50
- const selected = commands[backend] ?? targets[backend];
51
- return { host: "acp", backend, command: acpExecutable(selected.command, backend), args: [...selected.args], sessionId: null };
53
+ harness.validateStartOptions?.(options);
54
+ const permission = acpPermissionPolicy(backend, commands);
55
+ return {
56
+ host: "acp",
57
+ backend,
58
+ command: acpExecutable(selected.command, backend, harness),
59
+ args: [...selected.args],
60
+ ...(selected.env ? { env: { ...selected.env } } : {}),
61
+ ...(permission !== "ask" ? { permission } : {}),
62
+ sessionId: null,
63
+ };
52
64
  }
@@ -0,0 +1,6 @@
1
+ import type * as acp from "@agentclientprotocol/sdk";
2
+ import type { ResolvedWorkspaceMcpServer } from "../../model/workspace-mcp.js";
3
+ /** Convert resolved workspace MCP entries into ACP v1 `McpServer` descriptors. */
4
+ export declare function toAcpMcpServers(servers: readonly ResolvedWorkspaceMcpServer[]): acp.McpServer[];
5
+ /** Filter ACP MCP servers to the transports advertised by the peer's `mcpCapabilities`. */
6
+ export declare function filterAcpMcpServers(servers: readonly acp.McpServer[], capabilities?: acp.McpCapabilities): acp.McpServer[];
@@ -0,0 +1,40 @@
1
+ import { isAbsolute, resolve } from "node:path";
2
+ import { findAcpExecutable } from "./executable.js";
3
+ function resolveStdioCommand(command, cwd) {
4
+ if (isAbsolute(command))
5
+ return command;
6
+ if (command.includes("/") || command.includes("\\"))
7
+ return resolve(cwd, command);
8
+ return findAcpExecutable(command) ?? command;
9
+ }
10
+ /** Convert resolved workspace MCP entries into ACP v1 `McpServer` descriptors. */
11
+ export function toAcpMcpServers(servers) {
12
+ return servers.map(server => {
13
+ if (server.transport === "http") {
14
+ return {
15
+ type: "http",
16
+ name: server.name,
17
+ url: server.url,
18
+ headers: Object.entries(server.headers).map(([name, value]) => ({ name, value })),
19
+ };
20
+ }
21
+ return {
22
+ name: server.name,
23
+ command: resolveStdioCommand(server.command, server.cwd),
24
+ args: [...server.args],
25
+ env: Object.entries(server.env).map(([name, value]) => ({ name, value })),
26
+ };
27
+ });
28
+ }
29
+ /** Filter ACP MCP servers to the transports advertised by the peer's `mcpCapabilities`. */
30
+ export function filterAcpMcpServers(servers, capabilities) {
31
+ return servers.filter(server => {
32
+ if (!("type" in server))
33
+ return true; // stdio is baseline in ACP v1.
34
+ if (server.type === "http")
35
+ return capabilities?.http === true;
36
+ if (server.type === "sse")
37
+ return capabilities?.sse === true;
38
+ return false;
39
+ });
40
+ }
@@ -1,6 +1,6 @@
1
1
  import type { SessionConfigOption } from "@agentclientprotocol/sdk";
2
- import type { AcpBackend, AcpModelSelection } from "../../model/acp.js";
3
- /** Resolve a native model ID against the peer's advertised values. */
2
+ import type { AcpBackend, AcpChoice, AcpModelSelection } from "../../model/acp.js";
3
+ /** Resolve a native model ID against the peer's advertised values using the harness adapter. */
4
4
  export declare function acpModelValue(backend: AcpBackend, options: SessionConfigOption[], model: string, provider?: string): {
5
5
  configId: string;
6
6
  value: string;
@@ -10,3 +10,10 @@ export declare function acpThinkingValue(options: SessionConfigOption[], thinkin
10
10
  value: string;
11
11
  };
12
12
  export declare function acpModelSelection(backend: AcpBackend, options: SessionConfigOption[], effectiveThinking?: string): AcpModelSelection;
13
+ /** Advertised model and thinking choices, for callers that must pick valid values. */
14
+ export declare function acpChoices(options: SessionConfigOption[]): {
15
+ currentThinking?: string;
16
+ currentModel?: string;
17
+ models: AcpChoice[];
18
+ thinking: AcpChoice[];
19
+ };