@uniqbit/mate-core 0.20.0 → 0.21.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 (286) hide show
  1. package/claude-capability-plugins/companion-mentions/.claude-plugin/plugin.json +1 -1
  2. package/claude-capability-plugins/companion-mentions/hooks/register.ts +1 -1
  3. package/claude-plugin/hooks/hooks.json +10 -1
  4. package/claude-plugin/hooks/rtk-worktree-git.mjs +58 -0
  5. package/opencode-plugin/src/server.ts +9 -2
  6. package/package.json +2 -1
  7. package/src/cli/commands/artifact/delivery/environment.ts +28 -8
  8. package/src/cli/commands/artifact/delivery/link.ts +28 -9
  9. package/src/cli/commands/artifact/delivery/output.ts +7 -0
  10. package/src/cli/commands/companion/update.ts +2 -19
  11. package/src/cli/commands/factory/factory.ts +11 -1
  12. package/src/cli/commands/install.ts +47 -36
  13. package/src/cli/commands/launch/claude.ts +2 -0
  14. package/src/cli/commands/launch/shared.ts +33 -6
  15. package/src/cli/commands/plugin/install.ts +27 -11
  16. package/src/cli/commands/report/index.ts +180 -184
  17. package/src/cli/commands/report/markdown.ts +67 -72
  18. package/src/cli/commands/shared/companion-selection.ts +3 -1
  19. package/src/cli/commands/studio/access.ts +6 -14
  20. package/src/cli/commands/studio/areas.ts +112 -33
  21. package/src/cli/commands/studio/companion-add.ts +87 -0
  22. package/src/cli/commands/studio/companion-removal.ts +15 -8
  23. package/src/cli/commands/studio/factory-credential.ts +1 -15
  24. package/src/cli/commands/studio/factory-git-tokens.ts +40 -0
  25. package/src/cli/commands/studio/factory-relay.ts +18 -0
  26. package/src/cli/commands/studio/graph-model.ts +61 -0
  27. package/src/cli/commands/studio/graph.ts +336 -0
  28. package/src/cli/commands/studio/index.ts +4 -4
  29. package/src/cli/commands/studio/payload.ts +42 -15
  30. package/src/cli/commands/studio/repository-add.ts +116 -0
  31. package/src/cli/commands/studio/routes.ts +6 -0
  32. package/src/cli/commands/studio/selection.ts +12 -3
  33. package/src/cli/commands/studio/server.ts +127 -5
  34. package/src/cli/commands/studio/services.ts +40 -0
  35. package/src/cli/commands/studio/terminal.ts +45 -3
  36. package/src/cli/commands/studio/views/vault/markdown-tree.ts +84 -3
  37. package/src/cli/commands/studio/workset-session.ts +47 -14
  38. package/src/cli/commands/unwrap.ts +3 -0
  39. package/src/cli/commands/update.ts +2 -0
  40. package/src/cli/commands/vscode/release-vsix.json +4 -0
  41. package/src/cli/commands/vscode/setup.ts +71 -13
  42. package/src/cli/commands/vscode/vsix.ts +48 -7
  43. package/src/cli/commands/working/cleanup.ts +40 -8
  44. package/src/cli/commands/working/worktree.ts +176 -35
  45. package/src/cli/main.ts +17 -2
  46. package/src/cli/usage.ts +1 -1
  47. package/src/hooks/rtk-worktree-git.ts +48 -0
  48. package/src/hooks/validate-artifact-path.ts +38 -7
  49. package/src/lib/delivery/branch-template.ts +122 -0
  50. package/src/lib/delivery/branches.ts +21 -16
  51. package/src/lib/delivery/checkout.ts +102 -0
  52. package/src/lib/delivery/environment.ts +2 -0
  53. package/src/lib/delivery/merge-git.ts +13 -1
  54. package/src/lib/delivery/record-delivery.ts +83 -29
  55. package/src/lib/delivery/record.ts +15 -3
  56. package/src/lib/delivery/resolve-branch.ts +157 -110
  57. package/src/lib/factory/attach-client.ts +11 -1
  58. package/src/lib/factory/broker.ts +37 -40
  59. package/src/lib/factory/client.ts +22 -1
  60. package/src/lib/factory/clone-url.ts +39 -0
  61. package/src/lib/factory/command.ts +21 -5
  62. package/src/lib/factory/git-auth.ts +61 -0
  63. package/src/lib/factory/git-credential-store.ts +181 -0
  64. package/src/lib/factory/ids.ts +12 -2
  65. package/src/lib/factory/outcomes/actions.ts +20 -4
  66. package/src/lib/factory/outcomes/index.ts +77 -11
  67. package/src/lib/factory/outcomes/lifecycle.ts +9 -2
  68. package/src/lib/factory/outcomes/sessions.ts +23 -1
  69. package/src/lib/factory/prepare.ts +9 -3
  70. package/src/lib/factory/runner/scheduler.ts +96 -14
  71. package/src/lib/factory/runner/workflow.ts +5 -1
  72. package/src/lib/factory/runtime.ts +143 -43
  73. package/src/lib/orchestrator/companion-hub.ts +6 -1
  74. package/src/lib/orchestrator/engine-floor.ts +48 -0
  75. package/src/lib/orchestrator/launcher.ts +34 -1
  76. package/src/lib/orchestrator/projection-claude-commands.ts +2 -2
  77. package/src/lib/orchestrator/projection-claude-entry.ts +42 -21
  78. package/src/lib/orchestrator/projection-claude-links.ts +32 -8
  79. package/src/lib/orchestrator/projection-claude-skills.ts +2 -2
  80. package/src/lib/orchestrator/projection-entries.ts +22 -18
  81. package/src/lib/orchestrator/projection-opencode-copies.ts +65 -21
  82. package/src/lib/orchestrator/projection-runtime-documents.ts +66 -43
  83. package/src/lib/orchestrator/projection-types.ts +28 -1
  84. package/src/lib/orchestrator/refresh-working-claude-links.ts +3 -1
  85. package/src/lib/orchestrator/session-prepare.ts +6 -1
  86. package/src/lib/orchestrator/setup-compatibilities.ts +1 -1
  87. package/src/lib/orchestrator/types.ts +4 -0
  88. package/src/lib/orchestrator/umbrella-checkouts.ts +102 -0
  89. package/src/lib/orchestrator/working-repo-projection.ts +24 -4
  90. package/src/lib/orchestrator/wrap-pass.ts +1 -0
  91. package/src/lib/public-npm.ts +95 -50
  92. package/src/lib/session-state.ts +72 -2
  93. package/src/lib/update-checker.ts +7 -1
  94. package/src/lib/usage/aggregate.ts +202 -0
  95. package/src/lib/usage/cache.ts +87 -0
  96. package/src/lib/usage/claude-pricing.ts +71 -0
  97. package/src/lib/usage/claude.ts +189 -0
  98. package/src/lib/usage/collect.ts +56 -0
  99. package/src/lib/usage/opencode.ts +188 -0
  100. package/src/lib/usage/records.ts +80 -0
  101. package/src/lib/usage/rtk-database.ts +72 -0
  102. package/src/lib/usage/savings.ts +209 -0
  103. package/src/lib/usage/scope.ts +182 -0
  104. package/src/lib/usage/source.ts +102 -0
  105. package/src/lib/usage/types.ts +143 -0
  106. package/src/lib/usage/window.ts +37 -0
  107. package/src/lib/workset/factory-local.ts +157 -0
  108. package/src/lib/workset/record.ts +25 -11
  109. package/src/lib/workset/repositories.ts +118 -25
  110. package/src/lib/workset/worktree-include.ts +161 -0
  111. package/src/lib/workset/worktree-index.ts +6 -2
  112. package/src/lib/workset/worktree.ts +591 -101
  113. package/src/opencode/companion-hooks.ts +46 -8
  114. package/src/opencode/companion-policy.ts +18 -5
  115. package/src/opencode/enter-worktree.ts +254 -6
  116. package/src/opencode/session-register.ts +2 -2
  117. package/src/runtime/claude-bg-isolation.ts +138 -0
  118. package/src/runtime/companion-git.ts +10 -2
  119. package/src/runtime/companion-guidance.ts +17 -4
  120. package/src/runtime/current-branch.ts +16 -2
  121. package/src/runtime/entered-worktree.ts +24 -0
  122. package/src/runtime/git-tracked.ts +60 -0
  123. package/src/runtime/repo-destination.ts +72 -0
  124. package/src/runtime/repo-local.ts +25 -3
  125. package/src/runtime/rtk-git-guard.ts +66 -0
  126. package/src/runtime/runtime-document-manifest.ts +229 -19
  127. package/src/runtime/runtime-document-manifest.typecheck.ts +10 -0
  128. package/src/runtime/secret-guard.ts +9 -2
  129. package/src/runtime/secret-policy-weakening.ts +122 -0
  130. package/src/runtime/serving-claude-wrap.ts +15 -2
  131. package/src/runtime/umbrella-folder.ts +56 -0
  132. package/src/runtime/wrap-state.ts +5 -13
  133. package/src/studio.ts +37 -0
  134. package/src/templates/mate-skills/agents/mate-apply-change/SKILL.md +61 -6
  135. package/src/templates/mate-skills/agents/mate-explore-change/SKILL.md +8 -4
  136. package/src/templates/mate-skills/agents/mate-propose-change/SKILL.md +9 -5
  137. package/src/templates/mate-skills/agents/mate-publish-artifact/SKILL.md +5 -4
  138. package/src/templates/mate-skills/agents/mate-show-me/SKILL.md +10 -4
  139. package/src/templates/mate-skills/agents/mate-simplify-code/SKILL.md +5 -1
  140. package/src/templates/mate-skills/claude/mate-apply-change/SKILL.md +61 -6
  141. package/src/templates/mate-skills/claude/mate-explore-change/SKILL.md +8 -4
  142. package/src/templates/mate-skills/claude/mate-propose-change/SKILL.md +9 -5
  143. package/src/templates/mate-skills/claude/mate-publish-artifact/SKILL.md +5 -4
  144. package/src/templates/mate-skills/claude/mate-show-me/SKILL.md +10 -4
  145. package/src/templates/mate-skills/claude/mate-simplify-code/SKILL.md +5 -1
  146. package/src/tools/setup/__snapshots__/runtime-surface-golden.test.ts.snap +305 -42
  147. package/src/tools/setup/capabilities/rtk.ts +93 -1
  148. package/src/tools/setup/dynamic-plugins/audiences.ts +65 -21
  149. package/src/tools/setup/dynamic-plugins/frozen.ts +32 -13
  150. package/src/tools/setup/dynamic-plugins/hydrate.ts +4 -4
  151. package/src/tools/setup/dynamic-plugins/install.ts +24 -22
  152. package/src/tools/setup/dynamic-plugins/loader.ts +11 -7
  153. package/src/tools/setup/dynamic-plugins/paths.ts +30 -10
  154. package/src/tools/setup/dynamic-plugins/verify.ts +10 -7
  155. package/src/tools/setup/dynamic-plugins/workspaces.ts +153 -0
  156. package/src/tools/setup/mate.ts +3 -3
  157. package/src/tools/setup/plugins/gitignore.ts +15 -9
  158. package/src/tools/setup/providers/claude-plugin-hooks.ts +12 -0
  159. package/src/tools/setup/providers/claude.ts +25 -3
  160. package/src/tools/setup/utils.ts +4 -2
  161. package/src/tools/setup/working-repo-cleanup.ts +2 -2
  162. package/src/tools/setup.ts +25 -14
  163. package/studio-dist/client/assets/app-D9cw6szy.css +2 -0
  164. package/studio-dist/client/assets/artifacts-WD2ZXYrx.js +1 -0
  165. package/studio-dist/client/assets/button-Br0O1sXw.js +1 -0
  166. package/studio-dist/client/assets/combobox-DA7RAUUZ.js +1 -0
  167. package/studio-dist/client/assets/companion-view-CrabvxS8.js +1 -0
  168. package/studio-dist/client/assets/factory-DGS0E16C.js +6 -0
  169. package/studio-dist/client/assets/fields-6aXBpFhJ.js +1 -0
  170. package/studio-dist/client/assets/getting-started-Clde4w6P.js +1 -0
  171. package/studio-dist/client/assets/getting-started-D6kgWwWZ.js +1 -0
  172. package/studio-dist/client/assets/getting-started._topic-BiunccbT.js +1 -0
  173. package/studio-dist/client/assets/getting-started.index-DpiNoGw8.js +1 -0
  174. package/studio-dist/client/assets/graph-B_TCBVbu.js +2 -0
  175. package/studio-dist/client/assets/graph-canvas-Ba37Y5AE.js +3242 -0
  176. package/studio-dist/client/assets/guides-Du_RtJxP.js +1 -0
  177. package/studio-dist/client/assets/index-Df8L1LQa.js +40 -0
  178. package/studio-dist/client/assets/jsx-runtime-MZURdZre.js +1 -0
  179. package/studio-dist/client/assets/markdown-view-BOX6x0rL.js +1 -0
  180. package/studio-dist/client/assets/panel-dbmCx7Mx.js +1 -0
  181. package/studio-dist/client/assets/queries-RvHeXY12.js +1 -0
  182. package/studio-dist/client/assets/react-3QStrcDO.js +27 -0
  183. package/studio-dist/client/assets/report-url-XRL0x1SY.js +1 -0
  184. package/studio-dist/client/assets/reports-r3IK7Doz.js +1 -0
  185. package/studio-dist/client/assets/routes-C0A5LTFc.js +1 -0
  186. package/studio-dist/client/assets/select-CnaMd617.js +1 -0
  187. package/studio-dist/client/assets/skills-CzjzHpBT.js +1 -0
  188. package/studio-dist/client/assets/specs-B0ldF_6J.js +1 -0
  189. package/studio-dist/client/assets/specs-view-BnCLA0gW.js +1 -0
  190. package/studio-dist/client/assets/spinner-Dcm3fqK1.js +1 -0
  191. package/studio-dist/client/assets/steps-C0p2N1Pb.js +1 -0
  192. package/studio-dist/client/assets/store-Dw34catY.js +1 -0
  193. package/studio-dist/client/assets/studio-Cpz_HRHp.js +100 -0
  194. package/studio-dist/client/assets/studio-queries-ibmpFo6R.js +2 -0
  195. package/studio-dist/client/assets/usage-C2QJ_0IZ.js +55 -0
  196. package/studio-dist/client/assets/useAnchoredPopupScrollLock-Bj-FWb8z.js +1 -0
  197. package/studio-dist/client/assets/useMutation-aAr2uiay.js +1 -0
  198. package/studio-dist/client/assets/useSelector-AYcH7lB0.js +2 -0
  199. package/studio-dist/client/assets/vault-BGcxkSIY.js +1 -0
  200. package/studio-dist/client/assets/warnings-R1cE1rLf.js +1 -0
  201. package/studio-dist/client/assets/workflow-C2qTrMDH.js +1 -0
  202. package/studio-dist/server/assets/__23tanstack-start-server-fn-resolver-Bn896ZYj.js +122 -0
  203. package/studio-dist/server/assets/_tanstack-start-manifest_v.js +102 -35
  204. package/studio-dist/server/assets/{actions-Bvgj9eb8.js → actions-DYSv-9VV.js} +10 -4
  205. package/studio-dist/server/assets/artifacts-DnF9L3dZ.js +216 -0
  206. package/studio-dist/server/assets/{button-CIJqAhni.js → button-CgOIVdmD.js} +13 -1702
  207. package/studio-dist/server/assets/combobox-DV_s9W0s.js +483 -0
  208. package/studio-dist/server/assets/{companion-view-DISASvdJ.js → companion-view-BKVXD3TO.js} +3 -3
  209. package/studio-dist/server/assets/companions-C7fctnU9.js +31 -0
  210. package/studio-dist/server/assets/{createServerRpc-tK2lE9R2.js → createServerRpc-bFKFpGFG.js} +1 -1
  211. package/studio-dist/server/assets/{factory-DUTa0eDs.js → factory-C7Ybg0xG.js} +1256 -353
  212. package/studio-dist/server/assets/{factory-DGPmNGbo.js → factory-Df5uAHjb.js} +53 -6
  213. package/studio-dist/server/assets/fields-BbieQTD0.js +1190 -0
  214. package/studio-dist/server/assets/getting-started-B136TP57.js +4 -0
  215. package/studio-dist/server/assets/getting-started-CRxMWorQ.js +67 -0
  216. package/studio-dist/server/assets/getting-started._topic-DJKQAzYl.js +13 -0
  217. package/studio-dist/server/assets/getting-started.index-D84gec1t.js +13 -0
  218. package/studio-dist/server/assets/graph-CSje3029.js +801 -0
  219. package/studio-dist/server/assets/graph-DDZzXM1L.js +16 -0
  220. package/studio-dist/server/assets/graph-canvas-22bWB5-2.js +21066 -0
  221. package/studio-dist/server/assets/graph-wire-BdSUx0G5.js +58 -0
  222. package/studio-dist/server/assets/guides-D9dk1Frq.js +13 -0
  223. package/studio-dist/server/assets/guides-IE-19POz.js +5 -0
  224. package/studio-dist/server/assets/guides.server-vcYRY5wx.js +66 -0
  225. package/studio-dist/server/assets/jsx-runtime-Bt0s0YKS.js +451 -0
  226. package/studio-dist/server/assets/{markdown-view-Bn7xPdks.js → markdown-view-BR8dJ7aR.js} +28 -9
  227. package/studio-dist/server/assets/{panel-3Jmn4awF.js → panel-BR_t9iMM.js} +4 -4
  228. package/studio-dist/server/assets/queries-DWoTin-q.js +32 -0
  229. package/studio-dist/server/assets/react-CdqSUhaL.js +89 -0
  230. package/studio-dist/server/assets/redirect-BaZ_QyqF.js +39 -0
  231. package/studio-dist/server/assets/report-url-BUXPcE_8.js +9 -0
  232. package/studio-dist/server/assets/{reports-D6YMqhnO.js → reports-CQ9qQ1-n.js} +9 -10
  233. package/studio-dist/server/assets/{reports-C06RXVE2.js → reports-dYDEoBeq.js} +3 -3
  234. package/studio-dist/server/assets/{router-C8MGqlAY.js → router-DkRHNTpE.js} +787 -2862
  235. package/studio-dist/server/assets/{routes-BcFgvqf7.js → routes-B6GfOew4.js} +22 -171
  236. package/studio-dist/server/assets/{search-JAKurDNh.js → search-BJnWLfkG.js} +21 -2
  237. package/studio-dist/server/assets/select-Af7Wibii.js +1609 -0
  238. package/studio-dist/server/assets/{shell-DS3wUexh.js → shell-Hq-hXgnT.js} +6 -5
  239. package/studio-dist/server/assets/{skills-BEnOxiDl.js → skills-B7nEuVbx.js} +9 -8
  240. package/studio-dist/server/assets/{skills-CtrBAtX3.js → skills-B_YYL7q8.js} +3 -3
  241. package/studio-dist/server/assets/specs-BpLUFntA.js +51 -0
  242. package/studio-dist/server/assets/specs-view-0peMVd22.js +426 -0
  243. package/studio-dist/server/assets/spinner-CdwJW4VB.js +20 -0
  244. package/studio-dist/server/assets/{steps-Dq_CwY_s.js → steps-D56DApvK.js} +1 -1
  245. package/studio-dist/server/assets/store-Cs17okNG.js +280 -0
  246. package/studio-dist/server/assets/studio-CAcKp3bM.js +10340 -0
  247. package/studio-dist/server/assets/studio-queries-BtRGzDdh.js +1451 -0
  248. package/studio-dist/server/assets/usage-COdjd1gD.js +25570 -0
  249. package/studio-dist/server/assets/usage-f6pqE1tm.js +24 -0
  250. package/studio-dist/server/assets/useAnchoredPopupScrollLock-DlBKHRw7.js +756 -0
  251. package/studio-dist/server/assets/useMutation-DzTZGenE.js +690 -0
  252. package/studio-dist/server/assets/{__23tanstack-start-server-fn-resolver-M2GBs8s3.js → useSelector-DUmCUXAs.js} +4 -668
  253. package/studio-dist/server/assets/{vault-Fvxt2Tzl.js → vault-BDuIUq0F.js} +8 -5
  254. package/studio-dist/server/assets/{vault-BmWnryh3.js → vault-BVLp6zu3.js} +3 -3
  255. package/studio-dist/server/assets/{views-BgYa-za2.js → views-flRUr21z.js} +4 -4
  256. package/studio-dist/server/assets/{warnings-DzR6fyZh.js → warnings-CDy9pdgL.js} +3 -2
  257. package/studio-dist/server/assets/{delivery-path-C29fBynY.js → workflow-D9GKI2EV.js} +132 -106
  258. package/studio-dist/server/server.js +582 -8
  259. package/src/cli/commands/report/collector.ts +0 -288
  260. package/studio-dist/client/assets/app-CdPiFv59.css +0 -2
  261. package/studio-dist/client/assets/button-BIIHE0EQ.js +0 -3
  262. package/studio-dist/client/assets/companion-view-DM6YyXaR.js +0 -1
  263. package/studio-dist/client/assets/delivery-path-DELxj0Av.js +0 -1
  264. package/studio-dist/client/assets/factory-BZy0E8ty.js +0 -4
  265. package/studio-dist/client/assets/index-B3wkMzjA.js +0 -40
  266. package/studio-dist/client/assets/markdown-view-pQ2Qp_i5.js +0 -1
  267. package/studio-dist/client/assets/panel-CbajlC3p.js +0 -1
  268. package/studio-dist/client/assets/prepaint-CwSrpdFA.js +0 -27
  269. package/studio-dist/client/assets/react-CN2GSx7x.js +0 -1
  270. package/studio-dist/client/assets/reports-DllhYQ5_.js +0 -1
  271. package/studio-dist/client/assets/rolldown-runtime-WkwZ5CU-.js +0 -1
  272. package/studio-dist/client/assets/routes-COm-G3mK.js +0 -1
  273. package/studio-dist/client/assets/skills-DmWAy-jZ.js +0 -1
  274. package/studio-dist/client/assets/specs-BG3Wi3ln.js +0 -1
  275. package/studio-dist/client/assets/steps-DFsH3Neu.js +0 -1
  276. package/studio-dist/client/assets/vault-B2q1nBY5.js +0 -1
  277. package/studio-dist/client/assets/warnings-BSXIyuSQ.js +0 -1
  278. package/studio-dist/client/assets/workflow-DlsQD6Hc.js +0 -1
  279. package/studio-dist/server/assets/companions-BYbHWKOZ.js +0 -15
  280. package/studio-dist/server/assets/createServerFn-F5sAOF8V.js +0 -459
  281. package/studio-dist/server/assets/prepaint-DJfTQ_VH.js +0 -45
  282. package/studio-dist/server/assets/react-Ce6dj15C.js +0 -46
  283. package/studio-dist/server/assets/rolldown-runtime-DYf_mQCB.js +0 -34
  284. package/studio-dist/server/assets/specs-C8rv34-5.js +0 -211
  285. package/studio-dist/server/assets/studio-BeltxxKt.js +0 -216
  286. package/studio-dist/server/assets/workflow-liRYecHk.js +0 -73
@@ -1,7 +1,18 @@
1
+ import { spawnSync } from "node:child_process";
2
+ import fs from "node:fs";
3
+ import os from "node:os";
4
+ import path from "node:path";
5
+
1
6
  import type { CapabilityPlugin, RuntimeContributionsByRuntime, SetupContext } from "../plugin";
2
7
  import type { InstallRequirement } from "../install-contract";
3
- import { isCommandOnPath, runShellCommand, runShellCommandSilently } from "../utils";
8
+ import {
9
+ isCommandOnPath,
10
+ resolveCommandOnPath,
11
+ runShellCommand,
12
+ runShellCommandSilently,
13
+ } from "../utils";
4
14
  import { confirm } from "../../../cli/confirm";
15
+ import { errorMessage } from "../../../runtime/error-message";
5
16
  import { isDeclinedByMember, type ReadMemberChoices } from "../../../lib/member-choices";
6
17
 
7
18
  const RTK_INSTALL_CMD_BREW = "brew install rtk-ai/tap/rtk";
@@ -26,6 +37,51 @@ function defaultIsBrewAvailable(): boolean {
26
37
  return isCommandOnPath("brew", process.env.PATH ?? "");
27
38
  }
28
39
 
40
+ /**
41
+ * The Homebrew formula `binary` comes from (`rtk` or `<tap>/rtk`), read from its keg's
42
+ * install receipt; null when it is no Homebrew keg.
43
+ */
44
+ function defaultBrewFormulaOf(binary: string): string | null {
45
+ // <prefix>/Cellar/rtk/<version>/bin/rtk
46
+ const keg = path.dirname(path.dirname(fs.realpathSync(binary)));
47
+ const formulaDir = path.dirname(keg);
48
+ if (path.basename(formulaDir) !== "rtk" || path.basename(path.dirname(formulaDir)) !== "Cellar") {
49
+ return null;
50
+ }
51
+ let tap: unknown;
52
+ try {
53
+ const receipt = JSON.parse(fs.readFileSync(path.join(keg, "INSTALL_RECEIPT.json"), "utf8"));
54
+ tap = receipt?.source?.tap;
55
+ } catch {
56
+ // no readable receipt: the formula's bare name
57
+ }
58
+ return typeof tap === "string" && tap !== "homebrew/core" ? `${tap}/rtk` : "rtk";
59
+ }
60
+
61
+ /** The latest release tag, from the `/releases/latest` redirect GitHub answers without rate limit. */
62
+ async function defaultLatestRtkTag(): Promise<string | null> {
63
+ const response = await fetch("https://github.com/rtk-ai/rtk/releases/latest", {
64
+ redirect: "manual",
65
+ signal: AbortSignal.timeout(5_000),
66
+ });
67
+ return response.headers.get("location")?.match(/\/tag\/(v[\w.-]+)$/)?.[1] ?? null;
68
+ }
69
+
70
+ /** The version `binary --version` reports (`rtk 1.1.0`), else null. */
71
+ function defaultInstalledRtkVersion(binary: string): string | null {
72
+ const result = spawnSync(binary, ["--version"], {
73
+ encoding: "utf8",
74
+ stdio: ["ignore", "pipe", "ignore"],
75
+ timeout: 5_000,
76
+ });
77
+ return result.stdout?.match(/\d+\.\d+\.\d+\S*/)?.[0] ?? null;
78
+ }
79
+
80
+ /** The first `rtk` on PATH, as PATH names it. */
81
+ function defaultRtkBinaryPath(): string | null {
82
+ return resolveCommandOnPath("rtk", process.env.PATH ?? "") ?? null;
83
+ }
84
+
29
85
  export type RtkDeps = {
30
86
  confirm?: typeof confirm;
31
87
  isRtkOnPath?: () => boolean;
@@ -33,6 +89,11 @@ export type RtkDeps = {
33
89
  runRtkInstallCmd?: (cmd: string) => Promise<void>;
34
90
  runRtkCommandSilently?: (cmd: string) => Promise<void>;
35
91
  readMemberChoices?: ReadMemberChoices;
92
+ rtkBinaryPath?: () => string | null;
93
+ brewFormulaOf?: (binary: string) => string | null;
94
+ latestRtkTag?: () => Promise<string | null>;
95
+ installedRtkVersion?: (binary: string) => string | null;
96
+ homeDir?: () => string;
36
97
  };
37
98
 
38
99
  export function createRtkPlugin(deps: RtkDeps = {}): CapabilityPlugin {
@@ -41,6 +102,36 @@ export function createRtkPlugin(deps: RtkDeps = {}): CapabilityPlugin {
41
102
  const checkBrew = deps.isBrewAvailable ?? defaultIsBrewAvailable;
42
103
  const runRtkInstall = deps.runRtkInstallCmd ?? runShellCommand;
43
104
  const runSilently = deps.runRtkCommandSilently ?? runShellCommandSilently;
105
+ /**
106
+ * The command that upgrades the `rtk` on PATH through the channel that installed it:
107
+ * its Homebrew formula, or, for the installer's default `~/.local/bin/rtk`, the
108
+ * installer of a newer release, pinned to its tag. Null for any other installation,
109
+ * such as Cargo's, which is left alone.
110
+ */
111
+ const rtkUpgradeCommand = async (): Promise<string | null> => {
112
+ const binary = (deps.rtkBinaryPath ?? defaultRtkBinaryPath)();
113
+ if (!binary) return null;
114
+ const formula = (deps.brewFormulaOf ?? defaultBrewFormulaOf)(binary);
115
+ if (formula) return `brew upgrade ${formula}`;
116
+ const home = (deps.homeDir ?? os.homedir)();
117
+ if (path.resolve(binary) !== path.join(home, ".local", "bin", "rtk")) return null;
118
+ const tag = await (deps.latestRtkTag ?? defaultLatestRtkTag)();
119
+ const installed = (deps.installedRtkVersion ?? defaultInstalledRtkVersion)(binary);
120
+ if (!tag || tag.replace(/^v/, "") === installed) return null;
121
+ return `curl -fsSL https://raw.githubusercontent.com/rtk-ai/rtk/${tag}/install.sh | RTK_VERSION=${tag} sh`;
122
+ };
123
+
124
+ /** Best-effort, as TokenSave's: a failure warns and keeps the installed version. */
125
+ const upgradeRtk = async (): Promise<void> => {
126
+ try {
127
+ const command = await rtkUpgradeCommand();
128
+ if (command) await runSilently(command);
129
+ } catch (error) {
130
+ process.stderr.write(
131
+ `rtk: automatic upgrade failed: ${errorMessage(error)} - continuing with the installed version\n`,
132
+ );
133
+ }
134
+ };
44
135
  const hasOtherActiveRtkProvider = (currentProviderId: string, activeProviders: string[]) =>
45
136
  Object.keys(RTK_INIT_COMMANDS).some(
46
137
  (providerId) => providerId !== currentProviderId && activeProviders.includes(providerId),
@@ -71,6 +162,7 @@ export function createRtkPlugin(deps: RtkDeps = {}): CapabilityPlugin {
71
162
  detect: checkRtkPath,
72
163
  install: () => runRtkInstall(command),
73
164
  verify: checkRtkPath,
165
+ update: upgradeRtk,
74
166
  },
75
167
  ];
76
168
  },
@@ -102,24 +102,70 @@ export function effectivePluginDeclarations(raw: unknown, audience: string | nul
102
102
  return [...pluginList(normalizeBaseAudience(raw)), ...pluginList(audienceEntry(raw, audience))];
103
103
  }
104
104
 
105
+ /** The ordinary install that writes and installs `audience`'s workspace (`null`: the shared one). */
106
+ export function audienceInstallCommand(audience: string | null): string {
107
+ const install = `${FRAMEWORK_NAME} install`;
108
+ return audience === null ? install : `${AUDIENCE_ENV}=${audience} ${install}`;
109
+ }
110
+
111
+ /** A raw `plugins` entry with the workspace it installs into and loads from. */
112
+ export interface OriginPluginEntry {
113
+ entry: unknown;
114
+ /** `null` for a base plugin, else the audience declaring it. */
115
+ audience: string | null;
116
+ }
117
+
118
+ /** `effectivePluginDeclarations`, each entry keeping its origin. */
119
+ export function effectivePluginEntries(raw: unknown, audience: string | null): OriginPluginEntry[] {
120
+ const active = resolveAudience(raw, audience);
121
+ const name = active.ok ? active.active : null;
122
+ return [
123
+ ...pluginList(normalizeBaseAudience(raw)).map((entry) => ({ entry, audience: null })),
124
+ ...pluginList(audienceEntry(raw, name)).map((entry) => ({ entry, audience: name })),
125
+ ];
126
+ }
127
+
128
+ /** One plugin workspace an install run owns. */
129
+ export interface PluginInstallTarget {
130
+ /** `null` for the shared workspace, else the audience's own. */
131
+ audience: string | null;
132
+ declarations: PluginDeclaration[];
133
+ }
134
+
105
135
  /**
106
- * Base plugins followed by every audience's, for installation only: a
107
- * package shared by audiences appears once since validation guarantees one
108
- * version. Runtime declarations must come from `effectivePluginDeclarations`.
136
+ * Install targets of an already validated config: the base plugins, plus the
137
+ * active audience's. No other audience is a target, so a run can neither
138
+ * install nor relock it. `base` and an undeclared audience select none.
109
139
  */
110
- export function allPluginDeclarations(raw: unknown): unknown[] {
111
- const all = [...pluginList(normalizeBaseAudience(raw))];
140
+ export function pluginInstallTargets(
141
+ config: unknown,
142
+ audience: string | null,
143
+ ): PluginInstallTarget[] {
144
+ const targets: PluginInstallTarget[] = [
145
+ {
146
+ audience: null,
147
+ declarations: pluginList(normalizeBaseAudience(config)) as PluginDeclaration[],
148
+ },
149
+ ];
150
+ const resolved = resolveAudience(config, audience);
151
+ if (resolved.ok && resolved.active !== null) {
152
+ targets.push({
153
+ audience: resolved.active,
154
+ declarations: pluginList(audienceEntry(config, resolved.active)) as PluginDeclaration[],
155
+ });
156
+ }
157
+ return targets;
158
+ }
159
+
160
+ /** Packages declared under any audience, the ones that never belong in the shared workspace. */
161
+ export function audiencePluginPackages(raw: unknown): Set<string> {
162
+ const packages = new Set<string>();
112
163
  for (const name of declaredAudiences(raw)) {
113
- all.push(...pluginList(audienceEntry(raw, name)));
164
+ for (const entry of pluginList(audienceEntry(raw, name))) {
165
+ if (isRecord(entry) && typeof entry.package === "string") packages.add(entry.package);
166
+ }
114
167
  }
115
- const seen = new Set<string>();
116
- return all.filter((entry) => {
117
- if (!isRecord(entry) || typeof entry.package !== "string") return true;
118
- const key = `${entry.package}@${String(entry.version)}`;
119
- if (seen.has(key)) return false;
120
- seen.add(key);
121
- return true;
122
- });
168
+ return packages;
123
169
  }
124
170
 
125
171
  /** Operator-facing message for a `MATE_AUDIENCE` the companion does not declare. */
@@ -130,11 +176,6 @@ export function describeUnknownAudience(
130
176
  return `unknown audience "${resolution.requested}" (${AUDIENCE_ENV}); declared audiences: ${declared}`;
131
177
  }
132
178
 
133
- /** Install-time declarations of an already validated config: base plus every audience. */
134
- export function installPluginDeclarations(config: unknown): PluginDeclaration[] {
135
- return allPluginDeclarations(config) as PluginDeclaration[];
136
- }
137
-
138
179
  /**
139
180
  * The active audience's Studio default agent, else the base one. Returned
140
181
  * as found: the caller owns rejecting a value that is not a safe name.
@@ -171,6 +212,9 @@ export async function readEffectiveDeclarations(
171
212
  return effectivePluginDeclarations(await readFrameworkRaw(companionPath), audience);
172
213
  }
173
214
 
174
- export async function readAllDeclarations(companionPath: string): Promise<unknown[]> {
175
- return allPluginDeclarations(await readFrameworkRaw(companionPath));
215
+ export async function readEffectiveEntries(
216
+ companionPath: string,
217
+ audience: string | null,
218
+ ): Promise<OriginPluginEntry[]> {
219
+ return effectivePluginEntries(await readFrameworkRaw(companionPath), audience);
176
220
  }
@@ -2,9 +2,9 @@ import { spawnSync } from "node:child_process";
2
2
  import fs from "node:fs/promises";
3
3
  import path from "node:path";
4
4
 
5
+ import { FRAMEWORK_NAME } from "../../../framework";
5
6
  import type { PluginDeclaration } from "../../../lib/orchestrator/types";
6
7
  import type { NpmInstallRunner, PluginInstallResult } from "./install";
7
- import { dynamicPluginsWorkspaceRoot } from "./paths";
8
8
 
9
9
  /** Raised before anything is installed: manifest or lockfile inputs are unusable. */
10
10
  export class FrozenInstallError extends Error {}
@@ -13,6 +13,10 @@ export interface FrozenInstallDeps {
13
13
  /** Restores the exact locked tree; defaults to `npm ci`. */
14
14
  runNpmCi?: NpmInstallRunner;
15
15
  env?: Record<string, string | undefined>;
16
+ /** Ordinary install that writes this workspace's manifest and lockfile; named when one is missing. */
17
+ relockCommand?: string;
18
+ /** Packages declared under an audience; one recorded in this workspace marks an unmigrated companion. */
19
+ audiencePackages?: ReadonlySet<string>;
16
20
  }
17
21
 
18
22
  interface LockEntry {
@@ -78,7 +82,11 @@ function sameMap(a: Record<string, string>, b: Record<string, string>): string[]
78
82
  */
79
83
  async function treeMismatches(workspaceRoot: string, lock: Lockfile): Promise<string[]> {
80
84
  const hiddenText = await readText(path.join(workspaceRoot, "node_modules", ".package-lock.json"));
81
- if (hiddenText === null) return ["installed tree has no install record"];
85
+ if (hiddenText === null) {
86
+ // npm leaves no tree behind for a lockfile that locks nothing.
87
+ const locksPackages = Object.keys(lock.packages ?? {}).some((key) => key !== "");
88
+ return locksPackages ? ["installed tree has no install record"] : [];
89
+ }
82
90
  let hidden: Lockfile;
83
91
  try {
84
92
  hidden = JSON.parse(hiddenText) as Lockfile;
@@ -105,17 +113,17 @@ async function treeMismatches(workspaceRoot: string, lock: Lockfile): Promise<st
105
113
  }
106
114
 
107
115
  /**
108
- * Deployment restore: installs exactly what the committed lockfile records.
116
+ * Deployment restore of one workspace: installs exactly what its committed lockfile records.
109
117
  * Inputs are validated before npm runs — the workspace manifest against the declarations, and the lockfile against the
110
118
  * manifest — and neither tracked file is ever rewritten. An installed tree is
111
119
  * reused only when it matches the lockfile's versions and integrity.
112
120
  */
113
121
  export async function installDeclaredPluginsFrozen(
114
- companionPath: string,
122
+ workspaceRoot: string,
115
123
  declarations: PluginDeclaration[],
116
124
  deps: FrozenInstallDeps = {},
117
125
  ): Promise<PluginInstallResult[]> {
118
- const workspaceRoot = dynamicPluginsWorkspaceRoot(companionPath);
126
+ const relock = deps.relockCommand ?? `${FRAMEWORK_NAME} install`;
119
127
  const sorted = declarations.toSorted((a, b) => a.package.localeCompare(b.package));
120
128
  const desired: Record<string, string> = {};
121
129
  for (const declaration of sorted) desired[declaration.package] = declaration.version;
@@ -123,22 +131,33 @@ export async function installDeclaredPluginsFrozen(
123
131
  const manifestFile = path.join(workspaceRoot, "package.json");
124
132
  const lockFile = path.join(workspaceRoot, "package-lock.json");
125
133
  const [manifestText, lockText] = await Promise.all([readText(manifestFile), readText(lockFile)]);
134
+ // Nothing declared and nothing recorded: there is no workspace to restore.
135
+ if (sorted.length === 0 && manifestText === null) return [];
126
136
  if (manifestText === null) {
127
137
  throw new FrozenInstallError(
128
- `${manifestFile} is missing; commit the plugin workspace manifest in the companion's authoring flow`,
129
- );
130
- }
131
- if (lockText === null) {
132
- throw new FrozenInstallError(
133
- `${lockFile} is missing; commit the plugin lockfile in the companion's authoring flow`,
138
+ `${manifestFile} is missing; commit the plugin workspace manifest in the companion's authoring flow (\`${relock}\` writes it)`,
134
139
  );
135
140
  }
136
141
 
137
142
  const manifest = parseJson<{ dependencies?: Record<string, string> }>(manifestText, manifestFile);
138
- const manifestDrift = sameMap(desired, manifest.dependencies ?? {});
143
+ const recorded = manifest.dependencies ?? {};
144
+ const manifestDrift = sameMap(desired, recorded);
139
145
  if (manifestDrift.length > 0) {
146
+ const misplaced = Object.keys(recorded)
147
+ .filter((name) => deps.audiencePackages?.has(name))
148
+ .toSorted();
149
+ const migration =
150
+ misplaced.length > 0
151
+ ? `; ${misplaced.join(", ")} ${misplaced.length > 1 ? "are" : "is"} declared under an audience and no longer belong${misplaced.length > 1 ? "" : "s"} in ${manifestFile}: run \`${FRAMEWORK_NAME} install\` to migrate the companion, then commit the result`
152
+ : "";
153
+ throw new FrozenInstallError(
154
+ `plugin workspace manifest disagrees with framework.yaml: ${manifestDrift.join("; ")}${migration}`,
155
+ );
156
+ }
157
+ if (lockText === null) {
158
+ if (sorted.length === 0) return [];
140
159
  throw new FrozenInstallError(
141
- `plugin workspace manifest disagrees with framework.yaml: ${manifestDrift.join("; ")}`,
160
+ `${lockFile} is missing; commit the plugin lockfile in the companion's authoring flow (\`${relock}\` writes it)`,
142
161
  );
143
162
  }
144
163
  const lock = parseJson<Lockfile>(lockText, lockFile);
@@ -9,7 +9,7 @@ import type { Plugin } from "../plugin";
9
9
  import type { PluginRegistry } from "../registry";
10
10
  import {
11
11
  describeUnknownAudience,
12
- effectivePluginDeclarations,
12
+ effectivePluginEntries,
13
13
  readAudienceSelection,
14
14
  readFrameworkRaw,
15
15
  resolveAudience,
@@ -90,12 +90,12 @@ export async function hydrateDynamicPlugins(deps: HydrateDynamicPluginsDeps = {}
90
90
  if (!audience.ok) {
91
91
  warn(`${describeUnknownAudience(audience)}; applying the base configuration only`);
92
92
  }
93
- const entries = effectivePluginDeclarations(raw, audience.ok ? audience.active : null);
93
+ const entries = effectivePluginEntries(raw, audience.ok ? audience.active : null);
94
94
  if (entries.length === 0) return;
95
95
 
96
96
  const registry = deps.registry ?? getActiveDistribution().registry;
97
97
 
98
- for (const entry of entries) {
98
+ for (const { entry, audience: origin } of entries) {
99
99
  const { declaration, error } = validateDeclaration(entry);
100
100
  if (!declaration) {
101
101
  if (error) warn(error);
@@ -104,7 +104,7 @@ export async function hydrateDynamicPlugins(deps: HydrateDynamicPluginsDeps = {}
104
104
  if (hydratedPackages.has(declaration.package)) continue;
105
105
 
106
106
  // oxlint-disable-next-line no-await-in-loop -- declared order is part of the contract
107
- const result = await loadDynamicPlugin(companionPath, declaration, deps);
107
+ const result = await loadDynamicPlugin(companionPath, declaration, deps, origin);
108
108
  if (!result.ok) {
109
109
  warn(result.warning);
110
110
  continue;
@@ -3,7 +3,7 @@ import fs from "node:fs/promises";
3
3
  import path from "node:path";
4
4
 
5
5
  import type { PluginDeclaration } from "../../../lib/orchestrator/types";
6
- import { dynamicPluginsWorkspaceRoot, pluginPackageRoot } from "./paths";
6
+ import { workspacePackageRoot } from "./paths";
7
7
 
8
8
  export type NpmInstallRunner = (
9
9
  workspaceRoot: string,
@@ -27,7 +27,7 @@ export interface PluginInstallResult {
27
27
  }
28
28
 
29
29
  /**
30
- * Runs `npm <command>` in the shared plugin workspace, honoring the user's ambient
30
+ * Runs `npm <command>` in a plugin workspace, honoring the user's ambient
31
31
  * registry/auth config. `--loglevel=error` keeps npm's own error in stderr for the report.
32
32
  */
33
33
  function runNpm(
@@ -51,7 +51,7 @@ function runNpm(
51
51
  return { ok: true };
52
52
  }
53
53
 
54
- /** Runs `npm install` for the shared plugin workspace. */
54
+ /** Runs `npm install` for one plugin workspace. */
55
55
  const defaultNpmInstall: NpmInstallRunner = (workspaceRoot) => runNpm(workspaceRoot, "install");
56
56
 
57
57
  /** Version literals treated as moving targets: re-resolved via `npm update` on every run. */
@@ -72,7 +72,10 @@ async function readInstalledVersion(packageRoot: string): Promise<string | null>
72
72
  }
73
73
  }
74
74
 
75
- async function readWorkspaceDependencies(workspaceRoot: string): Promise<Record<string, string>> {
75
+ /** The `dependencies` map a workspace manifest records; empty when there is no manifest. */
76
+ export async function readWorkspaceDependencies(
77
+ workspaceRoot: string,
78
+ ): Promise<Record<string, string>> {
76
79
  try {
77
80
  const manifest = JSON.parse(
78
81
  await fs.readFile(path.join(workspaceRoot, "package.json"), "utf8"),
@@ -96,29 +99,28 @@ async function writeWorkspaceManifest(
96
99
  }
97
100
 
98
101
  /**
99
- * Installs every declared plugin into one shared workspace at
100
- * `.mate/plugins/`. Builds a single `dependencies` map (package
101
- * → declared version, sorted by name) and diffs it against the workspace's
102
- * current `package.json` plus each package's actual installed presence; an
103
- * identical, fully-installed map with no moving-tag declaration (`latest` or
104
- * `canary`) skips the install entirely. Otherwise the map is written and
105
- * `npm install` runs once for the whole workspace. Moving-tag-declared
106
- * plugins additionally get an `npm update` every run, regardless of whether
107
- * the map changed, so they re-resolve on every run. The shared, committed
108
- * `package-lock.json` is the sole reproducibility record; nothing else pins
109
- * versions. Private
110
- * registries are never Mate's concern: installs run through the operator's
111
- * own ambient npm config, or a project-local, gitignored `.npmrc` dropped
112
- * next to the workspace's `package.json`.
102
+ * Installs the declared plugins of one workspace: the shared one at
103
+ * `.mate/plugins/` or an audience's below it. Builds a single `dependencies`
104
+ * map (package → declared version, sorted by name) and diffs it against the
105
+ * workspace's current `package.json` plus each package's actual installed
106
+ * presence; an identical, fully-installed map with no moving-tag declaration
107
+ * (`latest` or `canary`) skips the install entirely, so an empty list writes
108
+ * nothing unless the manifest still lists dependencies to prune. Otherwise
109
+ * the map is written and `npm install` runs once for the whole workspace.
110
+ * Moving-tag-declared plugins additionally get an `npm update` every run,
111
+ * regardless of whether the map changed, so they re-resolve on every run. The
112
+ * workspace's committed `package-lock.json` is the sole reproducibility
113
+ * record; nothing else pins versions. Private registries are never Mate's
114
+ * concern: installs run through the operator's own ambient npm config, or a
115
+ * project-local, gitignored `.npmrc` in the shared workspace.
113
116
  */
114
117
  export async function installDeclaredPlugins(
115
- companionPath: string,
118
+ workspaceRoot: string,
116
119
  declarations: PluginDeclaration[],
117
120
  deps: PluginInstallDeps = {},
118
121
  ): Promise<PluginInstallResult[]> {
119
122
  const runNpmInstall = deps.runNpmInstall ?? defaultNpmInstall;
120
123
  const runNpmUpdate = deps.runNpmUpdate ?? defaultNpmUpdate;
121
- const workspaceRoot = dynamicPluginsWorkspaceRoot(companionPath);
122
124
 
123
125
  const sorted = declarations.toSorted((a, b) => a.package.localeCompare(b.package));
124
126
  const desired: Record<string, string> = {};
@@ -128,7 +130,7 @@ export async function installDeclaredPlugins(
128
130
  readWorkspaceDependencies(workspaceRoot),
129
131
  Promise.all(
130
132
  sorted.map((declaration) =>
131
- readInstalledVersion(pluginPackageRoot(companionPath, declaration.package)),
133
+ readInstalledVersion(workspacePackageRoot(workspaceRoot, declaration.package)),
132
134
  ),
133
135
  ),
134
136
  ]);
@@ -163,7 +165,7 @@ export async function installDeclaredPlugins(
163
165
 
164
166
  const resolvedVersions = await Promise.all(
165
167
  sorted.map((declaration) =>
166
- readInstalledVersion(pluginPackageRoot(companionPath, declaration.package)),
168
+ readInstalledVersion(workspacePackageRoot(workspaceRoot, declaration.package)),
167
169
  ),
168
170
  );
169
171
 
@@ -3,7 +3,6 @@ import { createRequire } from "node:module";
3
3
  import path from "node:path";
4
4
  import { pathToFileURL } from "node:url";
5
5
 
6
- import { FRAMEWORK_NAME } from "../../../framework";
7
6
  import type { PluginDeclaration } from "../../../lib/orchestrator/types";
8
7
  import type { Plugin } from "../plugin";
9
8
  import { resolveEffectivePluginConfig } from "./config-resolution";
@@ -13,6 +12,7 @@ import {
13
12
  type CreatePlugin,
14
13
  type PluginHost,
15
14
  } from "./host";
15
+ import { audienceInstallCommand } from "./audiences";
16
16
  import { dynamicPluginsWorkspaceRoot, pluginPackageRoot } from "./paths";
17
17
 
18
18
  interface PluginManifest {
@@ -32,9 +32,10 @@ function isRecord(value: unknown): value is Record<string, unknown> {
32
32
  }
33
33
 
34
34
  /**
35
- * Loads one declared plugin from the shared workspace: installed-presence
36
- * check, API version gate before import, entry-point resolution via the
37
- * shared workspace's own module resolver, dynamic import, factory
35
+ * Loads one declared plugin from the workspace of its origin (`audience`:
36
+ * `null` for a base plugin, else the audience declaring it): installed-presence
37
+ * check, API version gate before import, entry-point resolution via that
38
+ * workspace's own module resolver, dynamic import, factory
38
39
  * resolution, effective config, factory invocation. Every failure class
39
40
  * returns a single warning instead of throwing, so one broken plugin never
40
41
  * takes down the CLI.
@@ -43,9 +44,10 @@ export async function loadDynamicPlugin(
43
44
  companionPath: string,
44
45
  declaration: PluginDeclaration,
45
46
  deps: DynamicPluginLoadDeps = {},
47
+ audience: string | null = null,
46
48
  ): Promise<DynamicPluginLoadResult> {
47
49
  const name = declaration.package;
48
- const packageRoot = pluginPackageRoot(companionPath, name);
50
+ const packageRoot = pluginPackageRoot(companionPath, name, audience);
49
51
 
50
52
  let manifest: PluginManifest;
51
53
  try {
@@ -55,7 +57,7 @@ export async function loadDynamicPlugin(
55
57
  } catch {
56
58
  return {
57
59
  ok: false,
58
- warning: `plugin "${name}" is not installed; run \`${FRAMEWORK_NAME} install\`.`,
60
+ warning: `plugin "${name}" is not installed; run \`${audienceInstallCommand(audience)}\`.`,
59
61
  };
60
62
  }
61
63
 
@@ -79,7 +81,9 @@ export async function loadDynamicPlugin(
79
81
  let entryPath: string;
80
82
  try {
81
83
  const workspaceRequire = createRequire(
82
- pathToFileURL(path.join(dynamicPluginsWorkspaceRoot(companionPath), "package.json")),
84
+ pathToFileURL(
85
+ path.join(dynamicPluginsWorkspaceRoot(companionPath, audience), "package.json"),
86
+ ),
83
87
  );
84
88
  entryPath = workspaceRequire.resolve(name);
85
89
  } catch (error) {
@@ -2,18 +2,35 @@ import path from "node:path";
2
2
 
3
3
  import { FRAMEWORK_NAME } from "../../../framework";
4
4
 
5
- /** Shared workspace root: one package.json + node_modules for every declared plugin. */
6
- export function dynamicPluginsWorkspaceRoot(companionPath: string): string {
7
- return path.join(companionPath, `.${FRAMEWORK_NAME}`, "plugins");
5
+ /**
6
+ * A plugin workspace (package.json, lockfile, node_modules): the shared one
7
+ * for base plugins, or `audiences/<name>/` below it for one audience's.
8
+ */
9
+ export function dynamicPluginsWorkspaceRoot(
10
+ companionPath: string,
11
+ audience: string | null = null,
12
+ ): string {
13
+ const shared = path.join(companionPath, `.${FRAMEWORK_NAME}`, "plugins");
14
+ return audience === null ? shared : path.join(shared, "audiences", audience);
8
15
  }
9
16
 
10
- /** Root of one installed plugin package inside the shared workspace's node_modules. */
11
- export function pluginPackageRoot(companionPath: string, packageName: string): string {
12
- return path.join(
13
- dynamicPluginsWorkspaceRoot(companionPath),
14
- "node_modules",
15
- ...packageName.split("/"),
16
- );
17
+ /** Parent of every audience workspace. */
18
+ export function audienceWorkspacesRoot(companionPath: string): string {
19
+ return path.join(dynamicPluginsWorkspaceRoot(companionPath), "audiences");
20
+ }
21
+
22
+ /** Root of one installed package inside a workspace's node_modules. */
23
+ export function workspacePackageRoot(workspaceRoot: string, packageName: string): string {
24
+ return path.join(workspaceRoot, "node_modules", ...packageName.split("/"));
25
+ }
26
+
27
+ /** Root of one installed plugin package in the workspace of its origin. */
28
+ export function pluginPackageRoot(
29
+ companionPath: string,
30
+ packageName: string,
31
+ audience: string | null = null,
32
+ ): string {
33
+ return workspacePackageRoot(dynamicPluginsWorkspaceRoot(companionPath, audience), packageName);
17
34
  }
18
35
 
19
36
  /** Gitignored per-machine override file deep-merged over committed plugin config. */
@@ -26,3 +43,6 @@ export const PLUGIN_LOCAL_OVERRIDES_GITIGNORE_ENTRY = `.${FRAMEWORK_NAME}/config
26
43
 
27
44
  /** Companion-relative gitignore entry for the shared workspace's local, never-committed registry credentials. */
28
45
  export const PLUGIN_WORKSPACE_NPMRC_GITIGNORE_ENTRY = `.${FRAMEWORK_NAME}/plugins/.npmrc`;
46
+
47
+ /** Companion-relative gitignore entry for the registry file linked into every audience workspace. */
48
+ export const PLUGIN_AUDIENCE_NPMRC_GITIGNORE_ENTRY = `.${FRAMEWORK_NAME}/plugins/audiences/*/.npmrc`;
@@ -2,7 +2,7 @@ import fs from "node:fs/promises";
2
2
 
3
3
  import { FRAMEWORK_NAME } from "../../../framework";
4
4
  import type { PluginDeclaration } from "../../../lib/orchestrator/types";
5
- import { readAudienceSelection, readEffectiveDeclarations } from "./audiences";
5
+ import { readAudienceSelection, readEffectiveEntries } from "./audiences";
6
6
  import { validateDeclaration } from "./declarations";
7
7
  import { loadDynamicPlugin, type DynamicPluginLoadDeps } from "./loader";
8
8
  import { pluginPackageRoot } from "./paths";
@@ -38,18 +38,21 @@ export async function inspectDeclaredPlugins(
38
38
  const env = deps.env ?? process.env;
39
39
  const failures: PluginVerificationFailure[] = [];
40
40
  const capabilities: string[] = [];
41
- const declarations: PluginDeclaration[] = [];
42
- for (const entry of await readEffectiveDeclarations(companionPath, readAudienceSelection(env))) {
41
+ const declarations: Array<{ declaration: PluginDeclaration; audience: string | null }> = [];
42
+ for (const { entry, audience } of await readEffectiveEntries(
43
+ companionPath,
44
+ readAudienceSelection(env),
45
+ )) {
43
46
  const { declaration, error } = validateDeclaration(entry);
44
- if (declaration) declarations.push(declaration);
47
+ if (declaration) declarations.push({ declaration, audience });
45
48
  else failures.push({ package: "(malformed entry)", reason: error ?? "invalid plugins entry" });
46
49
  }
47
50
 
48
- for (const declaration of declarations) {
51
+ for (const { declaration, audience } of declarations) {
49
52
  const name = declaration.package;
50
53
  // oxlint-disable-next-line no-await-in-loop -- declared order is part of the contract
51
54
  const installed = await fs
52
- .access(pluginPackageRoot(companionPath, name))
55
+ .access(pluginPackageRoot(companionPath, name, audience))
53
56
  .then(() => true)
54
57
  .catch(() => false);
55
58
  if (!installed) {
@@ -60,7 +63,7 @@ export async function inspectDeclaredPlugins(
60
63
  continue;
61
64
  }
62
65
  // oxlint-disable-next-line no-await-in-loop -- declared order is part of the contract
63
- const result = await loadDynamicPlugin(companionPath, declaration, { ...deps, env });
66
+ const result = await loadDynamicPlugin(companionPath, declaration, { ...deps, env }, audience);
64
67
  if (!result.ok) failures.push({ package: name, reason: result.warning });
65
68
  else if (result.plugin.kind === "capability") capabilities.push(result.plugin.id);
66
69
  }