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
@@ -1,4 +1,5 @@
1
1
  import { requireThat } from "../../common/validation.js";
2
+ import { resolveAcpHarness } from "./registry.js";
2
3
  function optionFor(options, category) {
3
4
  const ids = category === "model" ? ["model"] : ["thought_level", "thinking", "reasoning_effort", "effort"];
4
5
  return options.find((option) => option.type === "select" && ids.includes(option.id)) ??
@@ -8,53 +9,87 @@ function values(option) {
8
9
  return [...new Map(option.options.flatMap(item => "options" in item ? item.options : [item]).map(item => [item.value, item])).values()];
9
10
  }
10
11
  function modelIdentity(backend, value) {
11
- if (backend === "dsh") {
12
- try {
13
- const parts = JSON.parse(value);
14
- if (Array.isArray(parts) && parts.length === 2 && parts.every(part => typeof part === "string" && part.length > 0)) {
15
- return { provider: parts[0], model: parts[1] };
16
- }
17
- }
18
- catch { /* Unencoded identifiers remain usable as exact ACP option values. */ }
19
- }
20
- if (backend === "pi") {
21
- const separator = value.indexOf("/");
22
- if (separator > 0)
23
- return { provider: value.slice(0, separator), model: value.slice(separator + 1) };
24
- }
25
- return { model: value };
12
+ const harness = resolveAcpHarness(backend);
13
+ return harness.parseModelValue ? harness.parseModelValue(value) : { model: value };
26
14
  }
27
- /** Resolve a native model ID against the peer's advertised values. */
15
+ /** Case, spacing and punctuation-insensitive form so "Opus 4.5" meets "claude-opus-4-5". */
16
+ const compact = (value) => value.toLowerCase().replace(/[^\p{L}\p{N}]+/gu, "");
17
+ const listing = (items) => items.map(item => item.name && item.name !== item.value ? `${item.value}(${item.name})` : item.value).join(", ");
18
+ /** Resolve a native model ID against the peer's advertised values using the harness adapter. */
28
19
  export function acpModelValue(backend, options, model, provider) {
29
20
  const option = optionFor(options, "model");
30
21
  requireThat(option, "ACP 后端未提供可选择的模型。");
31
22
  const choices = values(option);
32
- if (backend === "pi" && provider) {
33
- const qualified = choices.find(item => item.value === provider + "/" + model);
23
+ const harness = resolveAcpHarness(backend);
24
+ const formatted = harness.formatModelQuery?.(model, provider);
25
+ if (formatted) {
26
+ const qualified = choices.find(item => item.value === formatted);
34
27
  if (qualified)
35
28
  return { configId: option.id, value: qualified.value };
36
29
  }
37
- const available = choices.map(item => ({ ...modelIdentity(backend, item.value), value: item.value }));
38
- let matches = available.filter(item => (item.value === model || item.model === model) && (!provider || item.provider === provider));
39
- const exact = matches.filter(item => item.value === model);
40
- if (exact.length)
41
- matches = exact;
30
+ const entries = choices.map(item => ({ ...modelIdentity(backend, item.value), value: item.value, name: item.name }));
31
+ const matchEntries = (pool, target) => {
32
+ let matched = pool.filter(item => item.value === target || item.model === target);
33
+ const exact = matched.filter(item => item.value === target);
34
+ if (exact.length)
35
+ matched = exact;
36
+ if (!matched.length) {
37
+ // Users name models loosely; accept a unique case-insensitive or partial match on the value, model ID or display name.
38
+ const query = compact(target);
39
+ if (query) {
40
+ const keys = (item) => [item.value, item.model, item.name].map(compact);
41
+ matched = pool.filter(item => keys(item).includes(query));
42
+ if (!matched.length && query.length >= 2)
43
+ matched = pool.filter(item => keys(item).some(key => key.includes(query)));
44
+ }
45
+ }
46
+ return matched;
47
+ };
48
+ const filterByProvider = (targetProvider) => {
49
+ const exactProvider = entries.filter(item => item.provider === targetProvider);
50
+ if (exactProvider.length)
51
+ return exactProvider;
52
+ const providerQuery = compact(targetProvider);
53
+ return providerQuery ? entries.filter(item => item.provider && compact(item.provider) === providerQuery) : [];
54
+ };
55
+ const available = provider ? filterByProvider(provider) : entries;
56
+ let matches = matchEntries(available, model);
57
+ if (!matches.length && !provider && model.includes("/")) {
58
+ // Support "provider/model" syntax for multi-provider harnesses without requiring a separate provider parameter.
59
+ for (let index = model.indexOf("/"); index > 0; index = model.indexOf("/", index + 1)) {
60
+ const candidateProvider = model.slice(0, index);
61
+ const candidateModel = model.slice(index + 1);
62
+ if (!candidateModel)
63
+ continue;
64
+ const scoped = filterByProvider(candidateProvider);
65
+ if (!scoped.length)
66
+ continue;
67
+ const scopedMatches = matchEntries(scoped, candidateModel);
68
+ if (scopedMatches.length) {
69
+ matches = scopedMatches;
70
+ break;
71
+ }
72
+ }
73
+ }
42
74
  if (matches.length > 1 && !provider) {
43
75
  const current = modelIdentity(backend, option.currentValue);
44
76
  const sameProvider = matches.filter(item => item.provider === current.provider);
45
77
  if (sameProvider.length === 1)
46
78
  matches = sameProvider;
47
79
  }
48
- requireThat(matches.length, "ACP 模型不可用:" + [provider, model].filter(Boolean).join("/") + ";可用值:" + available.map(item => item.value).join(", "));
49
- requireThat(matches.length === 1, "多个 ACP 提供方包含该模型,请指定 provider 或完整模型值:" + matches.map(item => item.value).join(", "));
80
+ const all = choices.map(item => ({ value: item.value, name: item.name }));
81
+ requireThat(matches.length, "ACP 模型不可用:" + [provider, model].filter(Boolean).join("/") + ";可用值:" + listing(all));
82
+ requireThat(matches.length === 1, "多个模型与该名称匹配,请指定完整模型值(或 provider/model):" + listing(matches));
50
83
  return { configId: option.id, value: matches[0].value };
51
84
  }
52
85
  export function acpThinkingValue(options, thinking) {
53
86
  const option = optionFor(options, "thought_level");
54
87
  requireThat(option, "目标模型未提供可选择的思考等级。");
55
88
  const available = values(option);
56
- const chosen = available.find(item => item.value === thinking);
57
- requireThat(chosen, "ACP 思考等级不可用:" + thinking + ";可用值:" + available.map(item => item.value).join(", "));
89
+ const query = compact(thinking);
90
+ const chosen = available.find(item => item.value === thinking) ??
91
+ (query ? (([match, ...rest]) => match && !rest.length ? match : undefined)(available.filter(item => compact(item.value) === query || compact(item.name) === query)) : undefined);
92
+ requireThat(chosen, "ACP 思考等级不可用:" + thinking + ";可用值:" + listing(available));
58
93
  return { configId: option.id, value: chosen.value };
59
94
  }
60
95
  export function acpModelSelection(backend, options, effectiveThinking) {
@@ -63,3 +98,14 @@ export function acpModelSelection(backend, options, effectiveThinking) {
63
98
  : thinking && effectiveThinking && values(thinking).some(item => item.value === effectiveThinking) ? effectiveThinking : thinking?.currentValue;
64
99
  return { ...(model ? modelIdentity(backend, model.currentValue) : {}), ...(selectedThinking ? { thinking: selectedThinking } : {}) };
65
100
  }
101
+ /** Advertised model and thinking choices, for callers that must pick valid values. */
102
+ export function acpChoices(options) {
103
+ const choice = (item) => ({ value: item.value, name: item.name, ...(item.description ? { description: item.description } : {}) });
104
+ const model = optionFor(options, "model"), thinking = optionFor(options, "thought_level");
105
+ return {
106
+ models: model ? values(model).map(choice) : [],
107
+ thinking: thinking ? values(thinking).map(choice) : [],
108
+ ...(model ? { currentModel: model.currentValue } : {}),
109
+ ...(thinking ? { currentThinking: thinking.currentValue } : {}),
110
+ };
111
+ }
@@ -0,0 +1,18 @@
1
+ import type { AcpBackend, AcpHarnessAdapter } from "../../model/acp.js";
2
+ /** Extensible registry of ACP harness adapters; arbitrary custom harnesses resolve to generic ACP v1. */
3
+ export declare class AcpHarnessRegistry {
4
+ #private;
5
+ constructor(initial?: readonly AcpHarnessAdapter[]);
6
+ register(adapter: AcpHarnessAdapter): this;
7
+ unregister(id: AcpBackend): boolean;
8
+ get(id: AcpBackend): AcpHarnessAdapter | undefined;
9
+ resolve(id: AcpBackend): AcpHarnessAdapter;
10
+ list(): AcpBackend[];
11
+ /** Map a caller-supplied name ("Claude Code", "agy") to a backend ID; configured names win over aliases. */
12
+ canonical(name: string, configured?: readonly string[]): AcpBackend;
13
+ }
14
+ export declare const acpHarnesses: AcpHarnessRegistry;
15
+ export declare const registerAcpHarness: (adapter: AcpHarnessAdapter) => AcpHarnessRegistry;
16
+ export declare const getAcpHarness: (id: AcpBackend) => AcpHarnessAdapter | undefined;
17
+ export declare const resolveAcpHarness: (id: AcpBackend) => AcpHarnessAdapter;
18
+ export declare const listAcpHarnesses: () => string[];
@@ -0,0 +1,50 @@
1
+ import { isAcpBackend, requireThat } from "../../common/validation.js";
2
+ import { claudeAcpHarness } from "./harnesses/claude.js";
3
+ import { dshAcpHarness } from "./harnesses/dsh.js";
4
+ import { createGenericAcpHarness } from "./harnesses/generic.js";
5
+ import { piAcpHarness } from "./harnesses/pi.js";
6
+ import { standardAcpPresets } from "./harnesses/presets.js";
7
+ /** Extensible registry of ACP harness adapters; arbitrary custom harnesses resolve to generic ACP v1. */
8
+ export class AcpHarnessRegistry {
9
+ #adapters = new Map();
10
+ constructor(initial = []) {
11
+ for (const adapter of initial)
12
+ this.register(adapter);
13
+ }
14
+ register(adapter) {
15
+ requireThat(isAcpBackend(adapter.id), "ACP harness 标识无效:" + String(adapter.id));
16
+ this.#adapters.set(adapter.id, adapter);
17
+ return this;
18
+ }
19
+ unregister(id) {
20
+ return this.#adapters.delete(id);
21
+ }
22
+ get(id) {
23
+ return this.#adapters.get(id);
24
+ }
25
+ resolve(id) {
26
+ requireThat(isAcpBackend(id), "无效的 ACP harness 标识:" + String(id));
27
+ return this.#adapters.get(id) ?? createGenericAcpHarness(id);
28
+ }
29
+ list() {
30
+ return [...this.#adapters.keys()];
31
+ }
32
+ /** Map a caller-supplied name ("Claude Code", "agy") to a backend ID; configured names win over aliases. */
33
+ canonical(name, configured = []) {
34
+ const normalized = name.trim().toLowerCase().replace(/[\s_]+/g, "-");
35
+ if (configured.includes(normalized) || this.#adapters.has(normalized))
36
+ return normalized;
37
+ const compact = normalized.replace(/-/g, "");
38
+ return [...this.#adapters.values()].find(adapter => adapter.id.replace(/-/g, "") === compact || adapter.aliases?.some(alias => alias === normalized || alias.replace(/-/g, "") === compact))?.id ?? normalized;
39
+ }
40
+ }
41
+ export const acpHarnesses = new AcpHarnessRegistry([
42
+ piAcpHarness,
43
+ dshAcpHarness,
44
+ claudeAcpHarness,
45
+ ...standardAcpPresets,
46
+ ]);
47
+ export const registerAcpHarness = (adapter) => acpHarnesses.register(adapter);
48
+ export const getAcpHarness = (id) => acpHarnesses.get(id);
49
+ export const resolveAcpHarness = (id) => acpHarnesses.resolve(id);
50
+ export const listAcpHarnesses = () => acpHarnesses.list();
@@ -1 +1,16 @@
1
- export declare function agentText(agent: "coordinator" | "general-purpose", root: string, host?: "pi" | "dsh" | "claude"): Promise<string>;
1
+ import type { HostId, WorkspaceContext, WorkspaceRole } from "../model/plugin-host.js";
2
+ import type { WorkspaceSkillMeta } from "../model/workspace-mcp.js";
3
+ export declare function readOptionalFile(path: string): Promise<string>;
4
+ export declare function readLocalRole(agent: WorkspaceRole, root: string): Promise<string>;
5
+ export declare function agentText(agent: WorkspaceRole, root: string, coordinatorPrompt?: string): Promise<string>;
6
+ export declare function formatWorkspaceSkills(skills: readonly WorkspaceSkillMeta[]): string;
7
+ export declare function loadWorkspaceContext(options: {
8
+ host: HostId;
9
+ root: string;
10
+ role: WorkspaceRole;
11
+ coordinatorPrompt?: string;
12
+ includePrompts?: boolean;
13
+ includeRootAgents?: boolean;
14
+ localRoleOnly?: boolean;
15
+ workspaceSkills?: readonly WorkspaceSkillMeta[];
16
+ }): Promise<WorkspaceContext>;
@@ -2,19 +2,55 @@ import { readFile } from "node:fs/promises";
2
2
  import { join } from "node:path";
3
3
  import { resourceRoot } from "../common/paths.js";
4
4
  import { requireThat } from "../common/validation.js";
5
- export async function agentText(agent, root, host = "pi") {
6
- requireThat(agent === "coordinator" || agent === "general-purpose", "未知职责。");
7
- let text = await readFile(join(resourceRoot, "agents", agent + ".md"), "utf8");
8
- if (agent === "coordinator")
9
- text += "\n\n" + await readFile(join(resourceRoot, "prompts", host === "claude" ? "claude-coordinator.md" : "native-coordinator.md"), "utf8");
5
+ export async function readOptionalFile(path) {
10
6
  try {
11
- const local = await readFile(join(root, "agents", agent + ".md"), "utf8");
12
- text += "\n\n工作区职责补充:\n" + local;
7
+ return await readFile(path, "utf8");
13
8
  }
14
9
  catch (error) {
15
- if (error.code !== "ENOENT")
16
- throw error;
10
+ if (error.code === "ENOENT")
11
+ return "";
12
+ throw error;
17
13
  }
14
+ }
15
+ export async function readLocalRole(agent, root) {
16
+ const local = await readOptionalFile(join(root, "agents", agent + ".md"));
17
+ return local.trim() ? "工作区职责补充:\n" + local : "";
18
+ }
19
+ export async function agentText(agent, root, coordinatorPrompt = "plugin-coordinator.md") {
20
+ requireThat(agent === "coordinator" || agent === "general-purpose", "未知职责。");
21
+ let text = await readFile(join(resourceRoot, "agents", agent + ".md"), "utf8");
22
+ if (agent === "coordinator") {
23
+ text += "\n\n" + await readFile(join(resourceRoot, "prompts", coordinatorPrompt), "utf8");
24
+ }
25
+ const local = await readLocalRole(agent, root);
26
+ if (local)
27
+ text += "\n\n" + local;
18
28
  requireThat(text.trim(), "专家职责为空。");
19
29
  return text;
20
30
  }
31
+ export function formatWorkspaceSkills(skills) {
32
+ if (!skills.length)
33
+ return "";
34
+ const lines = skills.map(skill => `- **${skill.name}**(\`${skill.path}\`):${skill.description}`);
35
+ return "## 工作区技能\n\n以下为工作区自有专业方法(位于 `.agents/skills/`),匹配任务时按需读取对应 `SKILL.md` 正文:\n" + lines.join("\n");
36
+ }
37
+ export async function loadWorkspaceContext(options) {
38
+ const { host, root, role, coordinatorPrompt, includePrompts = true, includeRootAgents = false, localRoleOnly = false, workspaceSkills = [], } = options;
39
+ const [workspace, roleText, rootAgents] = includePrompts
40
+ ? await Promise.all([
41
+ readFile(join(resourceRoot, "prompts/workspace.md"), "utf8"),
42
+ localRoleOnly ? readLocalRole(role, root) : agentText(role, root, coordinatorPrompt),
43
+ includeRootAgents ? readOptionalFile(join(root, "AGENTS.md")) : Promise.resolve(""),
44
+ ])
45
+ : ["", "", ""];
46
+ const skillsSection = formatWorkspaceSkills(workspaceSkills);
47
+ const environment = { host, workspaceRoot: root, resourceRoot };
48
+ const text = [
49
+ workspace,
50
+ roleText,
51
+ rootAgents,
52
+ skillsSection,
53
+ "## 环境\n\n" + JSON.stringify(environment),
54
+ ].filter(Boolean).join("\n\n");
55
+ return { workspace, role: roleText, rootAgents, workspaceSkills: [...workspaceSkills], environment, text };
56
+ }
@@ -0,0 +1,4 @@
1
+ import * as McpClient from "@deepseek-ai/dsh-mcp-client";
2
+ import type { ResolvedWorkspaceMcpServer } from "../../model/workspace-mcp.js";
3
+ /** Translate a resolved workspace MCP entry into dsh's native `@deepseek-ai/dsh-mcp-client` config. */
4
+ export declare function toDshMcpConfig(server: ResolvedWorkspaceMcpServer): McpClient.Config;
@@ -0,0 +1,28 @@
1
+ import * as McpClient from "@deepseek-ai/dsh-mcp-client";
2
+ /** Translate a resolved workspace MCP entry into dsh's native `@deepseek-ai/dsh-mcp-client` config. */
3
+ export function toDshMcpConfig(server) {
4
+ if (server.transport === "http") {
5
+ return McpClient.Config({
6
+ transport: "streamable-http",
7
+ serverName: server.name,
8
+ url: server.url,
9
+ headers: { ...server.headers },
10
+ toolCallTimeoutMs: server.timeout * 1000,
11
+ failOnStartupError: false,
12
+ });
13
+ }
14
+ return McpClient.Config({
15
+ transport: "stdio",
16
+ serverName: server.name,
17
+ command: server.command,
18
+ args: [...server.args],
19
+ env: {
20
+ ...(process.env.PATH ? { PATH: process.env.PATH } : {}),
21
+ ...(process.env.HOME ? { HOME: process.env.HOME } : {}),
22
+ ...server.env,
23
+ },
24
+ cwd: server.cwd,
25
+ toolCallTimeoutMs: server.timeout * 1000,
26
+ failOnStartupError: false,
27
+ });
28
+ }
@@ -1,6 +1,6 @@
1
1
  import type { Context } from "@deepseek-ai/cordis";
2
2
  import type { Agent } from "@deepseek-ai/dsh-agent";
3
3
  import type { AgentOptions } from "../../model/agent.js";
4
- export declare function dshResources(ctx: Context, _agent: Agent, root: string, role: "coordinator" | "general-purpose", check: () => void): Promise<void>;
5
- /** Map the expert's native loadout; this is not isolation from Bash, CLI, or MCP. */
6
- export declare function dshExpertTools(ctx: Context, agent: Agent, options: AgentOptions): boolean;
4
+ export declare function dshResources(ctx: Context, _agent: Agent, root: string, role: "coordinator" | "general-purpose", check: () => void, coordinatorPrompt?: string): Promise<void>;
5
+ /** Map an ACP dsh worker's native loadout without interfering with coordinator sessions. */
6
+ export declare function dshExpertTools(ctx: Context, agent: Agent, options: AgentOptions): void;
@@ -3,36 +3,45 @@ import { join } from "node:path";
3
3
  import { agentText } from "../agent-resources.js";
4
4
  import { resourceRoot } from "../../common/paths.js";
5
5
  import { requireThat } from "../../common/validation.js";
6
- export async function dshResources(ctx, _agent, root, role, check) {
7
- const read = () => Promise.all([agentText(role, root), readFile(join(resourceRoot, "prompts/workspace.md"), "utf8")]);
6
+ import { isMcpWorkerTool } from "../../model/acp.js";
7
+ export async function dshResources(ctx, _agent, root, role, check, coordinatorPrompt = "history-coordinator.md") {
8
+ const read = () => Promise.all([agentText(role, root, coordinatorPrompt), readFile(join(resourceRoot, "prompts/workspace.md"), "utf8")]);
8
9
  const [text, workspace] = await read();
9
10
  check();
10
11
  ctx.systemPrompt.section({ name: "pbot:role", order: 1, text, interpolate: false });
11
12
  ctx.systemPrompt.section({ name: "pbot:workspace", order: 2, text: workspace, interpolate: false });
12
- ctx.systemPrompt.context({ name: "pbot:environment", order: 300, required: true, interpolate: false,
13
- text: JSON.stringify({ workspaceRoot: root, resourceRoot }) });
13
+ ctx.systemPrompt.context({
14
+ name: "pbot:environment", order: 300, required: true, interpolate: false,
15
+ text: JSON.stringify({ host: "dsh", workspaceRoot: root, resourceRoot }),
16
+ });
14
17
  ctx.on("system-prompt/assemble", async (_assembly, _context, next) => {
15
18
  check();
16
19
  const [roleText, workspaceText] = await read();
17
20
  check();
18
21
  const assembly = await next();
19
- return { ...assembly, sections: assembly.sections.map(section => section.name === "pbot:role" ? { ...section, text: roleText }
20
- : section.name === "pbot:workspace" ? { ...section, text: workspaceText } : section) };
22
+ return {
23
+ ...assembly,
24
+ sections: assembly.sections.map(section => section.name === "pbot:role" ? { ...section, text: roleText }
25
+ : section.name === "pbot:workspace" ? { ...section, text: workspaceText } : section),
26
+ };
21
27
  });
22
28
  }
23
- /** Map the expert's native loadout; this is not isolation from Bash, CLI, or MCP. */
29
+ /** Map an ACP dsh worker's native loadout without interfering with coordinator sessions. */
24
30
  export function dshExpertTools(ctx, agent, options) {
25
31
  const names = new Set(ctx.tools.definitions(agent).map(tool => tool.name));
26
- const forbidden = new Set(["pbot_agent", "pbot_team", "pbot_history", "subagent", "subagent_fork", "list_subagent_models", "list_agents", "send_message", "interrupt_agent"]);
32
+ const forbidden = new Set([
33
+ "pbot_history",
34
+ "subagent", "subagent_fork", "list_subagent_models", "list_agents", "send_message", "interrupt_agent",
35
+ ]);
27
36
  if (options.noSkills)
28
37
  forbidden.add("skill");
38
+ const isForbidden = (name) => forbidden.has(name) || isMcpWorkerTool(name);
29
39
  if (options.tools) {
30
40
  for (const name of options.tools)
31
- requireThat((names.has(name) || name === "pbot_team_message") && !forbidden.has(name), "专家工具不可用:" + name);
32
- ctx.tools.restrict({ allow: options.tools.filter(name => name !== "pbot_team_message") });
41
+ requireThat(names.has(name) && !isForbidden(name), "专家工具不可用:" + name);
42
+ ctx.tools.restrict({ allow: options.tools });
33
43
  }
34
- const deny = [...forbidden].filter(name => names.has(name));
44
+ const deny = [...names].filter(isForbidden);
35
45
  if (deny.length)
36
46
  ctx.tools.restrict({ deny });
37
- return !options.tools || options.tools.includes("pbot_team_message");
38
47
  }
@@ -1,4 +1,8 @@
1
1
  import type { Context } from "@deepseek-ai/cordis";
2
2
  import type { Agent } from "@deepseek-ai/dsh-agent";
3
+ export interface DshSkillsOptions {
4
+ /** Also register `<workspaceRoot>/.agents/skills` (useful when agent cwd is nested inside the workspace). */
5
+ workspaceRoot?: string;
6
+ }
3
7
  /** Keep bundled methods local to this Agent without overriding its native project/user methods. */
4
- export declare function registerDshSkills(ctx: Context, agent: Agent): void;
8
+ export declare function registerDshSkills(ctx: Context, agent: Agent, options?: DshSkillsOptions): void;
@@ -3,23 +3,27 @@ import { scopeParentOf } from "@deepseek-ai/dsh-scope";
3
3
  import { FileSystemSkillProvider } from "@deepseek-ai/dsh-skill-filesystem";
4
4
  import { resourceRoot } from "../../common/paths.js";
5
5
  /** Keep bundled methods local to this Agent without overriding its native project/user methods. */
6
- export function registerDshSkills(ctx, agent) {
6
+ export function registerDshSkills(ctx, agent, options = {}) {
7
+ const customSkillDirs = options.workspaceRoot ? [join(options.workspaceRoot, ".agents", "skills")] : undefined;
7
8
  let filesystem;
8
9
  ctx.skills.registerProvider(control => {
9
10
  filesystem = new FileSystemSkillProvider(ctx, control, {
10
- providerName: "pbot", includeDefaultRoots: false, bundledSkillDir: join(resourceRoot, "skills"),
11
+ providerName: "pbot",
12
+ includeDefaultRoots: false,
13
+ bundledSkillDir: join(resourceRoot, "skills"),
14
+ ...(customSkillDirs ? { customSkillDirs } : {}),
11
15
  });
12
16
  return {
13
17
  name: "pbot",
14
- async list(options) {
15
- const inherited = await ctx.skills.snapshot({ ...options, scope: scopeParentOf(agent) });
18
+ async list(listOptions) {
19
+ const inherited = await ctx.skills.snapshot({ ...listOptions, scope: scopeParentOf(agent) });
16
20
  const preferred = new Set(inherited.skills.filter(skill => skill.provider !== "pbot").map(skill => skill.name));
17
- const listed = await filesystem.list(options);
21
+ const listed = await filesystem.list(listOptions);
18
22
  const candidates = Array.isArray(listed) ? listed : listed.candidates;
19
23
  return { candidates: candidates.filter(skill => !preferred.has(skill.name)),
20
24
  complete: inherited.complete && (Array.isArray(listed) || listed.complete) };
21
25
  },
22
- get: (candidate, options) => filesystem.get(candidate, options),
26
+ get: (candidate, getOptions) => filesystem.get(candidate, getOptions),
23
27
  };
24
28
  });
25
29
  ctx.effect(() => () => filesystem.dispose());
@@ -0,0 +1,4 @@
1
+ import type { PluginHostAdapter } from "../../model/plugin-host.js";
2
+ export declare function antigravityWorkspaceRoot(cwd: string, payload?: unknown): Promise<string>;
3
+ export declare const antigravityAdapter: PluginHostAdapter;
4
+ export declare const antigravitySkillPath: (pluginRoot: string, skill: string) => string;
@@ -0,0 +1,79 @@
1
+ import { realpath, stat } from "node:fs/promises";
2
+ import { isAbsolute, join, relative, resolve, sep } from "node:path";
3
+ import { object } from "../../common/json.js";
4
+ import { resourceRoot } from "../../common/paths.js";
5
+ import { requireThat } from "../../common/validation.js";
6
+ const supportedEvents = ["SessionStart", "PreToolUse"];
7
+ function workspaceFromPayload(cwd, payload) {
8
+ if (object(payload) && Array.isArray(payload.workspacePaths)) {
9
+ const first = payload.workspacePaths.find(value => typeof value === "string" && value.length > 0);
10
+ if (typeof first === "string")
11
+ return first;
12
+ }
13
+ return cwd;
14
+ }
15
+ function skillFromReadPath(targetPath, pluginRoot = process.env.PLUGIN_ROOT || resolve(resourceRoot, "..")) {
16
+ const skillsRoot = resolve(pluginRoot, "skills");
17
+ const rel = relative(skillsRoot, resolve(targetPath));
18
+ if (!rel || rel.startsWith("..") || isAbsolute(rel))
19
+ return undefined;
20
+ const skill = rel.split(sep)[0];
21
+ if (!skill || skill === "pbot")
22
+ return undefined;
23
+ return skill;
24
+ }
25
+ function isPreToolUse(payload) {
26
+ return object(payload) && payload.hookEventName === "PreToolUse";
27
+ }
28
+ export async function antigravityWorkspaceRoot(cwd, payload) {
29
+ const directory = workspaceFromPayload(cwd, payload);
30
+ requireThat(isAbsolute(directory), "Antigravity 工作区需要绝对路径。");
31
+ const root = await realpath(directory);
32
+ requireThat((await stat(root)).isDirectory(), "Antigravity 工作区需要目录。");
33
+ return root;
34
+ }
35
+ export const antigravityAdapter = {
36
+ host: "antigravity",
37
+ nativeRootAgents: true,
38
+ nativeWorkspaceSkills: true,
39
+ coordinatorPrompt: "plugin-coordinator.md",
40
+ initCommandHint: "/pbot init",
41
+ usage: "用法:node <插件目录>/lib/plugin.js antigravity init|status",
42
+ resolveRoot(cwd, rawPayload) {
43
+ return antigravityWorkspaceRoot(cwd, rawPayload);
44
+ },
45
+ parseEvent(value) {
46
+ requireThat(object(value) && typeof value.hookEventName === "string", "Antigravity hook 输入无效。");
47
+ const event = value.hookEventName;
48
+ requireThat(supportedEvents.includes(event), "Antigravity hook 事件未支持。");
49
+ const cwd = typeof value.cwd === "string" && value.cwd ? value.cwd : workspaceFromPayload("", value);
50
+ requireThat(cwd, "Antigravity hook 缺少工作目录。");
51
+ if (event === "SessionStart") {
52
+ return { kind: "inject-context", role: "coordinator", cwd, raw: value };
53
+ }
54
+ if (!object(value.toolCall) || typeof value.toolCall.name !== "string" || !object(value.toolCall.args)) {
55
+ return { kind: "ignore" };
56
+ }
57
+ const { name, args } = value.toolCall;
58
+ if (name === "read_file" && typeof args.Path === "string") {
59
+ const skill = skillFromReadPath(args.Path);
60
+ if (skill)
61
+ return { kind: "check-skill", skill, cwd, raw: value };
62
+ }
63
+ return { kind: "ignore" };
64
+ },
65
+ formatPass(payload) {
66
+ return isPreToolUse(payload) ? { decision: "allow" } : {};
67
+ },
68
+ formatContext(_event, context) {
69
+ return {
70
+ injectSteps: [
71
+ { systemMessage: { systemMessage: context.text } },
72
+ ],
73
+ };
74
+ },
75
+ formatDeny(_event, reason) {
76
+ return { decision: "deny", reason };
77
+ },
78
+ };
79
+ export const antigravitySkillPath = (pluginRoot, skill) => join(pluginRoot, "skills", skill, "SKILL.md");
@@ -0,0 +1,3 @@
1
+ import type { PluginHostAdapter } from "../../model/plugin-host.js";
2
+ export declare function claudeWorkspaceRoot(cwd: string, projectDirectory?: string | undefined): Promise<string>;
3
+ export declare const claudeAdapter: PluginHostAdapter;
@@ -0,0 +1,60 @@
1
+ import { realpath, stat } from "node:fs/promises";
2
+ import { isAbsolute } from "node:path";
3
+ import { object } from "../../common/json.js";
4
+ import { requireThat } from "../../common/validation.js";
5
+ const supportedEvents = ["UserPromptSubmit", "PreToolUse", "UserPromptExpansion"];
6
+ export async function claudeWorkspaceRoot(cwd, projectDirectory = process.env.CLAUDE_PROJECT_DIR) {
7
+ const directory = projectDirectory || cwd;
8
+ requireThat(isAbsolute(directory), "Claude 工作区需要绝对路径。");
9
+ const root = await realpath(directory);
10
+ requireThat((await stat(root)).isDirectory(), "Claude 工作区需要目录。");
11
+ return root;
12
+ }
13
+ export const claudeAdapter = {
14
+ host: "claude",
15
+ nativeRootAgents: false,
16
+ nativeWorkspaceSkills: false,
17
+ coordinatorPrompt: "plugin-coordinator.md",
18
+ initCommandHint: "/personal-bot:pbot init",
19
+ usage: "用法:node <插件目录>/lib/claude.js init|status",
20
+ resolveRoot(cwd) {
21
+ return claudeWorkspaceRoot(cwd);
22
+ },
23
+ parseEvent(value) {
24
+ requireThat(object(value) && typeof value.hook_event_name === "string", "Claude hook 输入无效。");
25
+ const event = value.hook_event_name;
26
+ requireThat(supportedEvents.includes(event), "Claude hook 事件未支持。");
27
+ if (event === "PreToolUse" || event === "UserPromptExpansion") {
28
+ const skill = event === "UserPromptExpansion"
29
+ ? value.expansion_type === "slash_command" ? value.command_name : undefined
30
+ : value.tool_name === "Skill" && object(value.tool_input) ? value.tool_input.skill : undefined;
31
+ if (typeof skill !== "string" || !skill.startsWith("personal-bot:") || skill === "personal-bot:pbot")
32
+ return { kind: "ignore" };
33
+ requireThat(typeof value.cwd === "string", "Claude hook 缺少工作目录。");
34
+ return { kind: "check-skill", skill, cwd: value.cwd, raw: value };
35
+ }
36
+ // Leave Claude's native subagents untouched; only inject coordinator context into main sessions.
37
+ if (typeof value.agent_id === "string")
38
+ return { kind: "ignore" };
39
+ requireThat(typeof value.cwd === "string", "Claude hook 缺少工作目录。");
40
+ return { kind: "inject-context", role: "coordinator", cwd: value.cwd, raw: value };
41
+ },
42
+ formatPass() {
43
+ return {};
44
+ },
45
+ formatContext(event, context) {
46
+ const raw = event.raw;
47
+ return {
48
+ hookSpecificOutput: {
49
+ hookEventName: raw.hook_event_name,
50
+ additionalContext: context.text,
51
+ },
52
+ };
53
+ },
54
+ formatDeny(event, reason) {
55
+ const raw = event.raw;
56
+ return raw.hook_event_name === "UserPromptExpansion"
57
+ ? { decision: "block", reason }
58
+ : { hookSpecificOutput: { hookEventName: raw.hook_event_name, permissionDecision: "deny", permissionDecisionReason: reason } };
59
+ },
60
+ };
@@ -0,0 +1,15 @@
1
+ import type { PluginHostAdapter, PluginHostId } from "../../model/plugin-host.js";
2
+ /** Extensible registry of hook-based plugin host adapters; runtime never branches on host IDs. */
3
+ export declare class PluginHostRegistry {
4
+ #private;
5
+ constructor(initial?: readonly PluginHostAdapter[]);
6
+ register(adapter: PluginHostAdapter): this;
7
+ unregister(host: PluginHostId): boolean;
8
+ get(host: PluginHostId): PluginHostAdapter | undefined;
9
+ require(host: PluginHostId): PluginHostAdapter;
10
+ list(): PluginHostId[];
11
+ }
12
+ export declare const pluginHosts: PluginHostRegistry;
13
+ export declare const registerPluginHost: (adapter: PluginHostAdapter) => PluginHostRegistry;
14
+ export declare const getPluginHost: (host: PluginHostId) => PluginHostAdapter | undefined;
15
+ export declare const listPluginHosts: () => string[];