@uniqbit/mate-core 1.0.0-canary.7 → 1.0.0-canary.9

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 (225) hide show
  1. package/claude-capability-plugins/companion-mentions/.claude-plugin/plugin.json +1 -1
  2. package/package.json +6 -3
  3. package/src/cli/commands/artifact/delivery/submit.ts +6 -4
  4. package/src/cli/commands/artifact/finish/command.ts +28 -11
  5. package/src/cli/commands/artifact/pending/command.ts +71 -7
  6. package/src/cli/commands/cap/tokensave.ts +2 -2
  7. package/src/cli/commands/companion/update.ts +2 -3
  8. package/src/cli/commands/doctor.ts +33 -4
  9. package/src/cli/commands/install.ts +8 -4
  10. package/src/cli/commands/plugin/install.ts +82 -35
  11. package/src/cli/commands/studio/service-host.ts +3 -0
  12. package/src/cli/commands/triage.ts +32 -11
  13. package/src/cli/commands/vscode/release-vsix.json +2 -2
  14. package/src/cli/install-plan.tsx +3 -0
  15. package/src/cli/main.ts +51 -7
  16. package/src/cli/usage.ts +3 -3
  17. package/src/create-mate.ts +4 -1
  18. package/src/factory-host.ts +6 -0
  19. package/src/index.ts +1 -0
  20. package/src/lib/delivery/merge-git.ts +31 -7
  21. package/src/lib/delivery/overlap.ts +14 -1
  22. package/src/lib/delivery/repository-access.ts +11 -6
  23. package/src/lib/delivery/staging/apply-chain.ts +25 -7
  24. package/src/lib/delivery/staging/linked-merges.ts +175 -0
  25. package/src/lib/delivery/staging/naming.ts +3 -0
  26. package/src/lib/delivery/staging/openspec-type.ts +38 -7
  27. package/src/lib/delivery/staging/pending.ts +153 -11
  28. package/src/lib/delivery/staging/preflight.ts +239 -0
  29. package/src/lib/delivery/staging/project.ts +243 -104
  30. package/src/lib/delivery/staging/replay.ts +5 -3
  31. package/src/lib/delivery/staging/settle-linked.ts +5 -119
  32. package/src/lib/delivery/staging/submit.ts +139 -18
  33. package/src/lib/delivery/submit-change.ts +163 -37
  34. package/src/lib/friction/mark.ts +49 -11
  35. package/src/lib/friction/view/read.ts +10 -1
  36. package/src/lib/mcp-manager/resolve.ts +70 -0
  37. package/src/lib/mcp-manager/store.ts +109 -0
  38. package/src/lib/mcp-manager/types.ts +58 -0
  39. package/src/lib/mcp-manager/validate.ts +246 -0
  40. package/src/lib/openspec-cli.ts +10 -5
  41. package/src/lib/orchestrator/config-store.ts +30 -7
  42. package/src/lib/orchestrator/engine-floor.ts +16 -4
  43. package/src/lib/orchestrator/engine-guard.ts +7 -1
  44. package/src/lib/orchestrator/types.ts +4 -0
  45. package/src/lib/skills-cli.ts +38 -0
  46. package/src/lib/tool-manifest.ts +73 -0
  47. package/src/lib/triage/context.ts +138 -12
  48. package/src/lib/triage/prepare.ts +19 -4
  49. package/src/plugin-api.ts +1 -0
  50. package/src/runtime/command-arg.ts +15 -0
  51. package/src/runtime/companion-guidance.ts +1 -1
  52. package/src/runtime/friction-log.ts +41 -17
  53. package/src/runtime/friction-recorder.ts +15 -2
  54. package/src/runtime/git-tracked.ts +13 -2
  55. package/src/runtime/workflow/turn.ts +14 -12
  56. package/src/studio.ts +23 -1
  57. package/src/templates/capabilities/openspec-cap/mate-minimal/schema.yaml +5 -1
  58. package/src/templates/capabilities/react-doctor/mate-react-doctor/SKILL.md +28 -0
  59. package/src/templates/mate-skills/agents/mate-apply-change/SKILL.md +42 -4
  60. package/src/templates/mate-skills/agents/mate-archive-change/SKILL.md +27 -2
  61. package/src/templates/mate-skills/agents/mate-backfill-spec/SKILL.md +23 -1
  62. package/src/templates/mate-skills/agents/mate-clarify-intent/SKILL.md +26 -1
  63. package/src/templates/mate-skills/agents/mate-domain-modeling/SKILL.md +28 -0
  64. package/src/templates/mate-skills/agents/mate-explore-change/SKILL.md +28 -3
  65. package/src/templates/mate-skills/agents/mate-grill-me/SKILL.md +28 -0
  66. package/src/templates/mate-skills/agents/mate-grill-with-docs/SKILL.md +28 -0
  67. package/src/templates/mate-skills/agents/mate-grilling/SKILL.md +25 -0
  68. package/src/templates/mate-skills/agents/mate-interview-me/SKILL.md +28 -0
  69. package/src/templates/mate-skills/agents/mate-propose-change/SKILL.md +28 -3
  70. package/src/templates/mate-skills/agents/mate-publish-artifact/SKILL.md +28 -6
  71. package/src/templates/mate-skills/agents/mate-show-me/SKILL.md +27 -2
  72. package/src/templates/mate-skills/agents/mate-simplify-code/SKILL.md +28 -0
  73. package/src/templates/mate-skills/agents/mate-submit-change/SKILL.md +24 -2
  74. package/src/templates/mate-skills/claude/mate-apply-change/SKILL.md +42 -4
  75. package/src/templates/mate-skills/claude/mate-archive-change/SKILL.md +27 -2
  76. package/src/templates/mate-skills/claude/mate-backfill-spec/SKILL.md +23 -1
  77. package/src/templates/mate-skills/claude/mate-clarify-intent/SKILL.md +26 -1
  78. package/src/templates/mate-skills/claude/mate-domain-modeling/SKILL.md +28 -0
  79. package/src/templates/mate-skills/claude/mate-explore-change/SKILL.md +28 -3
  80. package/src/templates/mate-skills/claude/mate-grill-me/SKILL.md +28 -0
  81. package/src/templates/mate-skills/claude/mate-grill-with-docs/SKILL.md +28 -0
  82. package/src/templates/mate-skills/claude/mate-grilling/SKILL.md +25 -0
  83. package/src/templates/mate-skills/claude/mate-interview-me/SKILL.md +28 -0
  84. package/src/templates/mate-skills/claude/mate-propose-change/SKILL.md +28 -3
  85. package/src/templates/mate-skills/claude/mate-publish-artifact/SKILL.md +28 -6
  86. package/src/templates/mate-skills/claude/mate-show-me/SKILL.md +27 -2
  87. package/src/templates/mate-skills/claude/mate-simplify-code/SKILL.md +28 -0
  88. package/src/templates/mate-skills/claude/mate-submit-change/SKILL.md +24 -2
  89. package/src/templates/triage/PLAYBOOK.md +9 -1
  90. package/src/tools/setup/__snapshots__/runtime-surface-golden.test.ts.snap +108 -108
  91. package/src/tools/setup/capabilities/graphify.ts +23 -1
  92. package/src/tools/setup/capabilities/mcp-manager.ts +74 -0
  93. package/src/tools/setup/capabilities/rtk.ts +27 -86
  94. package/src/tools/setup/capabilities/tokensave.ts +76 -54
  95. package/src/tools/setup/context-services.ts +35 -6
  96. package/src/tools/setup/dynamic-plugins/audiences.ts +31 -16
  97. package/src/tools/setup/dynamic-plugins/hydrate.ts +32 -14
  98. package/src/tools/setup/dynamic-plugins/install.ts +2 -0
  99. package/src/tools/setup/dynamic-plugins/installed.ts +73 -0
  100. package/src/tools/setup/dynamic-plugins/loader.ts +12 -10
  101. package/src/tools/setup/dynamic-plugins/local.ts +492 -0
  102. package/src/tools/setup/dynamic-plugins/paths.ts +34 -6
  103. package/src/tools/setup/dynamic-plugins/verify.ts +34 -14
  104. package/src/tools/setup/dynamic-plugins/workspaces.ts +17 -8
  105. package/src/tools/setup/engine.ts +55 -3
  106. package/src/tools/setup/mate.ts +26 -1
  107. package/src/tools/setup/plugin.ts +14 -0
  108. package/src/tools/setup/plugins/gitignore.ts +45 -12
  109. package/src/tools/setup/providers/claude-format.ts +39 -2
  110. package/src/tools/setup/providers/claude.ts +10 -0
  111. package/src/tools/setup/providers/opencode-format.ts +13 -3
  112. package/src/tools/setup/service.ts +8 -0
  113. package/src/tools/setup/utils.ts +10 -1
  114. package/studio-dist/client/assets/app-ggXJ_QVh.css +2 -0
  115. package/studio-dist/client/assets/button-C9SQW3kI.js +1 -0
  116. package/studio-dist/client/assets/cn-DC80MJV0.js +1 -0
  117. package/studio-dist/client/assets/combobox-D7mKYCBb.js +1 -0
  118. package/studio-dist/client/assets/{companion-view-DINdPF-b.js → companion-view-C1F0_jbt.js} +1 -1
  119. package/studio-dist/client/assets/fields-CEep8IFT.js +1 -0
  120. package/studio-dist/client/assets/friction-D9dBU7WN.js +1 -0
  121. package/studio-dist/client/assets/getting-started-BDyGvHhc.js +1 -0
  122. package/studio-dist/client/assets/{getting-started-djaQeWlu.js → getting-started-BN4aTpsz.js} +1 -1
  123. package/studio-dist/client/assets/getting-started._topic-B9ajbF4o.js +1 -0
  124. package/studio-dist/client/assets/getting-started.index-CYiBPtb7.js +1 -0
  125. package/studio-dist/client/assets/graph-ah7ZXfTa.js +2 -0
  126. package/studio-dist/client/assets/{graph-canvas-DIcAqwtK.js → graph-canvas-Be5qgdDt.js} +1 -1
  127. package/studio-dist/client/assets/guides-CsL0660B.js +1 -0
  128. package/studio-dist/client/assets/index-zmRH87D4.js +40 -0
  129. package/studio-dist/client/assets/{markdown-view-jMiaBTSO.js → markdown-view-dku7MGPn.js} +1 -1
  130. package/studio-dist/client/assets/panel-COgk0vP5.js +1 -0
  131. package/studio-dist/client/assets/plugins._service._view-Cn3WBHab.js +1 -0
  132. package/studio-dist/client/assets/{prepaint-CKsXyJOR.js → prepaint-BkoDSw5X.js} +1 -1
  133. package/studio-dist/client/assets/{queries-Dfp5deWj.js → queries-CMvC2OkU.js} +1 -1
  134. package/studio-dist/client/assets/reports-C_AqLBYH.js +1 -0
  135. package/studio-dist/client/assets/routes-BokQmHtC.js +1 -0
  136. package/studio-dist/client/assets/{search-CXosfvYh.js → search-DxidNK2M.js} +1 -1
  137. package/studio-dist/client/assets/select-CYFCbHUd.js +1 -0
  138. package/studio-dist/client/assets/skills-R3vttWHM.js +1 -0
  139. package/studio-dist/client/assets/{specs-Dl8HfGlU.js → specs-Bqd1ajyD.js} +1 -1
  140. package/studio-dist/client/assets/specs-view-znqFPx9p.js +1 -0
  141. package/studio-dist/client/assets/{steps-CKUno4lh.js → steps-tVDWn7j6.js} +1 -1
  142. package/studio-dist/client/assets/{store-DyXbi6o9.js → store-BYnEU33C.js} +1 -1
  143. package/studio-dist/client/assets/studio-ndtFcS2Y.js +100 -0
  144. package/studio-dist/client/assets/{studio-queries-BflKt9va.js → studio-queries-CkUSByy7.js} +1 -1
  145. package/studio-dist/client/assets/{usage-Blcl8kA_.js → usage-Kuhr8dSl.js} +13 -13
  146. package/studio-dist/client/assets/{useAnchoredPopupScrollLock-BBXJpX5L.js → useAnchoredPopupScrollLock-dc_kP4Go.js} +1 -1
  147. package/studio-dist/client/assets/useMutation-CqtM9COw.js +1 -0
  148. package/studio-dist/client/assets/vault-CSP8kwRg.js +1 -0
  149. package/studio-dist/client/assets/warnings-Cnw99ugO.js +1 -0
  150. package/studio-dist/client/assets/workflow-BPJAmmZi.js +1 -0
  151. package/studio-dist/server/assets/{__23tanstack-start-server-fn-resolver-JoHQ5ihx.js → __23tanstack-start-server-fn-resolver-CS3QRY4Q.js} +18 -18
  152. package/studio-dist/server/assets/_tanstack-start-manifest_v.js +58 -58
  153. package/studio-dist/server/assets/{button-B7e1fRyW.js → button-Ct_WeYLc.js} +3 -3480
  154. package/studio-dist/server/assets/cn-DWFJaP_9.js +5528 -0
  155. package/studio-dist/server/assets/{combobox--S_OmUfh.js → combobox-17vO5Uz8.js} +6 -5
  156. package/studio-dist/server/assets/{companion-view-D-vGM55e.js → companion-view-JkxnGLlp.js} +2 -2
  157. package/studio-dist/server/assets/{companions-Dr6IpNAb.js → companions-YNLsbnch.js} +1 -1
  158. package/studio-dist/server/assets/{fields-B4qM2ZwC.js → fields-VytPpqBq.js} +2 -1
  159. package/studio-dist/server/assets/{friction-sLxaWY-H.js → friction-B6osqFSm.js} +56 -16
  160. package/studio-dist/server/assets/{friction-CWOTjpCV.js → friction-BW86PCPM.js} +2 -2
  161. package/studio-dist/server/assets/{getting-started-Cq5Pcnsr.js → getting-started-CFHSeX5h.js} +2 -2
  162. package/studio-dist/server/assets/{getting-started._topic-CmWdl3u3.js → getting-started._topic-BK2eU6AS.js} +2 -2
  163. package/studio-dist/server/assets/{getting-started.index-AB8xpTFY.js → getting-started.index-DZLuXnNO.js} +2 -2
  164. package/studio-dist/server/assets/{graph-C_Hn-Wf_.js → graph-BJVZBevL.js} +8 -7
  165. package/studio-dist/server/assets/{graph-B11ITte0.js → graph-DGZHV-Ek.js} +1 -1
  166. package/studio-dist/server/assets/{graph-canvas-BthrSmPS.js → graph-canvas-lrNT6jbl.js} +2 -2
  167. package/studio-dist/server/assets/{guides-B8HdeK_C.js → guides-CEwLOZb9.js} +1 -1
  168. package/studio-dist/server/assets/{guides-BVQ4pt5B.js → guides-_G8Vucsk.js} +1 -1
  169. package/studio-dist/server/assets/{guides.server-DqFQAStf.js → guides.server-ZWFKX2XJ.js} +1 -1
  170. package/studio-dist/server/assets/{markdown-view-rwiiVcPC.js → markdown-view-Bmjghg_Z.js} +1 -1
  171. package/studio-dist/server/assets/{panel-CUxRIpYL.js → panel-DvRjyil3.js} +4 -3
  172. package/studio-dist/server/assets/{plugins._service._view-BSvGnlhU.js → plugins._service._view-B32LzraG.js} +8 -5
  173. package/studio-dist/server/assets/{prepaint-B28ClcPN.js → prepaint-BEHwKl51.js} +1 -1
  174. package/studio-dist/server/assets/{queries-S_Pl90IG.js → queries-D6Vq0AuZ.js} +1 -1
  175. package/studio-dist/server/assets/{reports-B9k98oE6.js → reports-DDaH5k0H.js} +1 -1
  176. package/studio-dist/server/assets/{reports-CJpAItPk.js → reports-Dn92pLap.js} +7 -6
  177. package/studio-dist/server/assets/{router-DF0etoNa.js → router-Bjf4S9tO.js} +57 -32
  178. package/studio-dist/server/assets/{routes-6ylCLkyg.js → routes-B4sNiE0X.js} +8 -7
  179. package/studio-dist/server/assets/{search-b-yQesv3.js → search-DKeJRvg8.js} +1 -1
  180. package/studio-dist/server/assets/{select-CjuKScan.js → select-CVHYL7oR.js} +5 -4
  181. package/studio-dist/server/assets/{shell-DLkP7wG9.js → shell-BxbYYaAk.js} +4 -3
  182. package/studio-dist/server/assets/{skills-zeU80A9S.js → skills-B4-0qpqN.js} +8 -7
  183. package/studio-dist/server/assets/{skills-DGg0mWDM.js → skills-Bj8eOgzR.js} +1 -1
  184. package/studio-dist/server/assets/{specs-DDBNT_v1.js → specs-rfMug6qW.js} +4 -4
  185. package/studio-dist/server/assets/{specs-view-exvmWdg0.js → specs-view-qi1SE1Sl.js} +10 -9
  186. package/studio-dist/server/assets/{steps-D1tYAyWZ.js → steps-rger6HJc.js} +1 -1
  187. package/studio-dist/server/assets/{store-kS7zk0Hr.js → store-Dg9T7oWs.js} +1 -1
  188. package/studio-dist/server/assets/{studio-qRvQjRpz.js → studio-D79JzDLc.js} +1347 -0
  189. package/studio-dist/server/assets/{studio-queries-qOXOYoPt.js → studio-queries-CeFfmIuM.js} +3 -3
  190. package/studio-dist/server/assets/{usage-C2um7YiV.js → usage-BJgYWRCX.js} +10 -10
  191. package/studio-dist/server/assets/{usage-Cwle9-xY.js → usage-Dw_UQFX-.js} +1 -1
  192. package/studio-dist/server/assets/{useAnchoredPopupScrollLock-kQBB3y_b.js → useAnchoredPopupScrollLock-ciS_sEq3.js} +2 -2
  193. package/studio-dist/server/assets/{useMutation-C-WO6hCM.js → useMutation-DnWK0PhO.js} +2 -2
  194. package/studio-dist/server/assets/{vault-CEBBRLMb.js → vault-BzarssiL.js} +1 -1
  195. package/studio-dist/server/assets/{vault-B8vgVIH9.js → vault-CvlrLd2H.js} +6 -6
  196. package/studio-dist/server/assets/{views-UgO0Qz_g.js → views-CAxwKHMK.js} +2 -2
  197. package/studio-dist/server/assets/{warnings-BxK4VfV5.js → warnings-BpVCugHm.js} +2 -1
  198. package/studio-dist/server/assets/{workflow-BrTK632u.js → workflow-BdrzcCt8.js} +9 -8
  199. package/studio-dist/server/server.js +2 -2
  200. package/tool-manifest.yaml +85 -0
  201. package/studio-dist/client/assets/app-aIwDxf48.css +0 -2
  202. package/studio-dist/client/assets/button-CX0sWAJl.js +0 -1
  203. package/studio-dist/client/assets/combobox-BmA8RjOc.js +0 -1
  204. package/studio-dist/client/assets/fields-BobQ7zRF.js +0 -1
  205. package/studio-dist/client/assets/friction-YdYd3zaz.js +0 -1
  206. package/studio-dist/client/assets/getting-started-CY7NEtTw.js +0 -1
  207. package/studio-dist/client/assets/getting-started._topic-DVB8e5R9.js +0 -1
  208. package/studio-dist/client/assets/getting-started.index-DQvLHEr1.js +0 -1
  209. package/studio-dist/client/assets/graph-DbNnR884.js +0 -2
  210. package/studio-dist/client/assets/guides-D6T6W_jV.js +0 -1
  211. package/studio-dist/client/assets/index-CysBCSxM.js +0 -40
  212. package/studio-dist/client/assets/panel-Csr49lBo.js +0 -1
  213. package/studio-dist/client/assets/plugins._service._view-CEA_CcPe.js +0 -1
  214. package/studio-dist/client/assets/reports-CLdgxxkg.js +0 -1
  215. package/studio-dist/client/assets/routes-DGilWbDE.js +0 -1
  216. package/studio-dist/client/assets/select-DdebbX7K.js +0 -1
  217. package/studio-dist/client/assets/skills-C3zNkU8g.js +0 -1
  218. package/studio-dist/client/assets/specs-view-B_n0Pekv.js +0 -1
  219. package/studio-dist/client/assets/studio-0ueISxwP.js +0 -100
  220. package/studio-dist/client/assets/useBaseQuery-C2cjmeH2.js +0 -1
  221. package/studio-dist/client/assets/useMutation-DI6LbvVa.js +0 -1
  222. package/studio-dist/client/assets/vault-Cb9DmM1i.js +0 -1
  223. package/studio-dist/client/assets/warnings-B-rvoW8q.js +0 -1
  224. package/studio-dist/client/assets/workflow-DN5T19jd.js +0 -1
  225. package/studio-dist/server/assets/useBaseQuery--iH3rd-T.js +0 -2051
@@ -1,5 +1,3 @@
1
- import { spawnSync } from "node:child_process";
2
- import fs from "node:fs";
3
1
  import os from "node:os";
4
2
  import path from "node:path";
5
3
 
@@ -7,18 +5,20 @@ import type { CapabilityPlugin, RuntimeContributionsByRuntime, SetupContext } fr
7
5
  import type { InstallRequirement } from "../install-contract";
8
6
  import { hasRtkCapability } from "../../../runtime/companion-guidance";
9
7
  import {
8
+ installedVersionOutput,
10
9
  isCommandOnPath,
11
10
  resolveCommandOnPath,
12
11
  runShellCommand,
13
12
  runShellCommandSilently,
14
13
  } from "../utils";
15
14
  import { confirm } from "../../../cli/confirm";
16
- import { errorMessage } from "../../../runtime/error-message";
17
15
  import { isDeclinedByMember, type ReadMemberChoices } from "../../../lib/member-choices";
16
+ import { toolVersion, warnOnVersionDrift } from "../../../lib/tool-manifest";
18
17
 
19
- const RTK_INSTALL_CMD_BREW = "brew install rtk-ai/tap/rtk";
20
- const RTK_INSTALL_CMD_FALLBACK =
21
- "curl -fsSL https://raw.githubusercontent.com/rtk-ai/rtk/refs/heads/master/install.sh | sh";
18
+ const RTK_VERSION = toolVersion("rtk");
19
+ // The release's installer with RTK_VERSION installs that release and checks its checksum;
20
+ // Homebrew would install the latest formula instead.
21
+ const RTK_INSTALL_CMD = `curl -fsSL https://raw.githubusercontent.com/rtk-ai/rtk/v${RTK_VERSION}/install.sh | RTK_VERSION=v${RTK_VERSION} sh`;
22
22
 
23
23
  const RTK_INIT_COMMANDS: Record<string, string> = {
24
24
  claude: "rtk init -g --auto-patch",
@@ -30,52 +30,20 @@ const RTK_UNINSTALL_COMMANDS: Record<string, string> = {
30
30
  opencode: "rtk init -g --uninstall --opencode",
31
31
  };
32
32
 
33
- function defaultIsRtkOnPath(): boolean {
34
- return isCommandOnPath("rtk", process.env.PATH ?? "");
35
- }
36
-
37
- function defaultIsBrewAvailable(): boolean {
38
- return isCommandOnPath("brew", process.env.PATH ?? "");
33
+ /** Where the pinned installer puts `rtk`; it only prints a PATH hint, so a fresh install may be off PATH. */
34
+ function rtkInstallDir(): string {
35
+ return process.env.RTK_INSTALL_DIR || path.join(os.homedir(), ".local", "bin");
39
36
  }
40
37
 
41
38
  /**
42
- * The Homebrew formula `binary` comes from (`rtk` or `<tap>/rtk`), read from its keg's
43
- * install receipt; null when it is no Homebrew keg.
39
+ * True when `rtk` is on PATH or in its install directory; the latter is appended to this
40
+ * process's PATH, last, so its other binaries never shadow the member's.
44
41
  */
45
- function defaultBrewFormulaOf(binary: string): string | null {
46
- // <prefix>/Cellar/rtk/<version>/bin/rtk
47
- const keg = path.dirname(path.dirname(fs.realpathSync(binary)));
48
- const formulaDir = path.dirname(keg);
49
- if (path.basename(formulaDir) !== "rtk" || path.basename(path.dirname(formulaDir)) !== "Cellar") {
50
- return null;
51
- }
52
- let tap: unknown;
53
- try {
54
- const receipt = JSON.parse(fs.readFileSync(path.join(keg, "INSTALL_RECEIPT.json"), "utf8"));
55
- tap = receipt?.source?.tap;
56
- } catch {
57
- // no readable receipt: the formula's bare name
58
- }
59
- return typeof tap === "string" && tap !== "homebrew/core" ? `${tap}/rtk` : "rtk";
60
- }
61
-
62
- /** The latest release tag, from the `/releases/latest` redirect GitHub answers without rate limit. */
63
- async function defaultLatestRtkTag(): Promise<string | null> {
64
- const response = await fetch("https://github.com/rtk-ai/rtk/releases/latest", {
65
- redirect: "manual",
66
- signal: AbortSignal.timeout(5_000),
67
- });
68
- return response.headers.get("location")?.match(/\/tag\/(v[\w.-]+)$/)?.[1] ?? null;
69
- }
70
-
71
- /** The version `binary --version` reports (`rtk 1.1.0`), else null. */
72
- function defaultInstalledRtkVersion(binary: string): string | null {
73
- const result = spawnSync(binary, ["--version"], {
74
- encoding: "utf8",
75
- stdio: ["ignore", "pipe", "ignore"],
76
- timeout: 5_000,
77
- });
78
- return result.stdout?.match(/\d+\.\d+\.\d+\S*/)?.[0] ?? null;
42
+ function locateRtk(installDir: string): boolean {
43
+ if (isCommandOnPath("rtk", process.env.PATH ?? "")) return true;
44
+ if (!isCommandOnPath("rtk", installDir)) return false;
45
+ process.env.PATH = [process.env.PATH, installDir].filter(Boolean).join(path.delimiter);
46
+ return true;
79
47
  }
80
48
 
81
49
  /** The first `rtk` on PATH, as PATH names it. */
@@ -86,15 +54,13 @@ function defaultRtkBinaryPath(): string | null {
86
54
  export type RtkDeps = {
87
55
  confirm?: typeof confirm;
88
56
  isRtkOnPath?: () => boolean;
89
- isBrewAvailable?: () => boolean;
57
+ /** Probed when `rtk` is not on PATH; defaults to the installer's target. */
58
+ installDir?: string;
90
59
  runRtkInstallCmd?: (cmd: string) => Promise<void>;
91
60
  runRtkCommandSilently?: (cmd: string) => Promise<void>;
92
61
  readMemberChoices?: ReadMemberChoices;
93
62
  rtkBinaryPath?: () => string | null;
94
- brewFormulaOf?: (binary: string) => string | null;
95
- latestRtkTag?: () => Promise<string | null>;
96
- installedRtkVersion?: (binary: string) => string | null;
97
- homeDir?: () => string;
63
+ installedRtkVersion?: (binary: string) => Promise<string | null>;
98
64
  };
99
65
 
100
66
  /**
@@ -115,39 +81,14 @@ function endsRtkUse(providerId: string, ctx: SetupContext): boolean {
115
81
 
116
82
  export function createRtkPlugin(deps: RtkDeps = {}): CapabilityPlugin {
117
83
  const askConfirm = deps.confirm ?? confirm;
118
- const checkRtkPath = deps.isRtkOnPath ?? defaultIsRtkOnPath;
119
- const checkBrew = deps.isBrewAvailable ?? defaultIsBrewAvailable;
84
+ const checkRtkPath = deps.isRtkOnPath ?? (() => locateRtk(deps.installDir ?? rtkInstallDir()));
120
85
  const runRtkInstall = deps.runRtkInstallCmd ?? runShellCommand;
121
86
  const runSilently = deps.runRtkCommandSilently ?? runShellCommandSilently;
122
- /**
123
- * The command that upgrades the `rtk` on PATH through the channel that installed it:
124
- * its Homebrew formula, or, for the installer's default `~/.local/bin/rtk`, the
125
- * installer of a newer release, pinned to its tag. Null for any other installation,
126
- * such as Cargo's, which is left alone.
127
- */
128
- const rtkUpgradeCommand = async (): Promise<string | null> => {
87
+ const checkRtkVersion = async (): Promise<void> => {
129
88
  const binary = (deps.rtkBinaryPath ?? defaultRtkBinaryPath)();
130
- if (!binary) return null;
131
- const formula = (deps.brewFormulaOf ?? defaultBrewFormulaOf)(binary);
132
- if (formula) return `brew upgrade ${formula}`;
133
- const home = (deps.homeDir ?? os.homedir)();
134
- if (path.resolve(binary) !== path.join(home, ".local", "bin", "rtk")) return null;
135
- const tag = await (deps.latestRtkTag ?? defaultLatestRtkTag)();
136
- const installed = (deps.installedRtkVersion ?? defaultInstalledRtkVersion)(binary);
137
- if (!tag || tag.replace(/^v/, "") === installed) return null;
138
- return `curl -fsSL https://raw.githubusercontent.com/rtk-ai/rtk/${tag}/install.sh | RTK_VERSION=${tag} sh`;
139
- };
140
-
141
- /** Best-effort, as TokenSave's: a failure warns and keeps the installed version. */
142
- const upgradeRtk = async (): Promise<void> => {
143
- try {
144
- const command = await rtkUpgradeCommand();
145
- if (command) await runSilently(command);
146
- } catch (error) {
147
- process.stderr.write(
148
- `rtk: automatic upgrade failed: ${errorMessage(error)} - continuing with the installed version\n`,
149
- );
150
- }
89
+ if (!binary) return;
90
+ const installed = await (deps.installedRtkVersion ?? installedVersionOutput)(binary);
91
+ warnOnVersionDrift("rtk", installed, RTK_INSTALL_CMD, binary);
151
92
  };
152
93
 
153
94
  return {
@@ -161,7 +102,7 @@ export function createRtkPlugin(deps: RtkDeps = {}): CapabilityPlugin {
161
102
  return { claude: { permissionEntries: ["Bash(rtk:*)"] } };
162
103
  },
163
104
  getInstallRequirements: (): InstallRequirement[] => {
164
- const command = checkBrew() ? RTK_INSTALL_CMD_BREW : RTK_INSTALL_CMD_FALLBACK;
105
+ const command = RTK_INSTALL_CMD;
165
106
  return [
166
107
  {
167
108
  id: "capability:rtk",
@@ -174,7 +115,7 @@ export function createRtkPlugin(deps: RtkDeps = {}): CapabilityPlugin {
174
115
  detect: checkRtkPath,
175
116
  install: () => runRtkInstall(command),
176
117
  verify: checkRtkPath,
177
- update: upgradeRtk,
118
+ update: checkRtkVersion,
178
119
  },
179
120
  ];
180
121
  },
@@ -182,7 +123,7 @@ export function createRtkPlugin(deps: RtkDeps = {}): CapabilityPlugin {
182
123
  if (checkRtkPath() || ctx.mode !== "setup") return;
183
124
  if (await isDeclinedByMember(ctx.companionPath, ["rtk"], deps.readMemberChoices)) return;
184
125
 
185
- const command = checkBrew() ? RTK_INSTALL_CMD_BREW : RTK_INSTALL_CMD_FALLBACK;
126
+ const command = RTK_INSTALL_CMD;
186
127
  process.stdout.write(`rtk binary not found. To install:\n ${command}\n`);
187
128
  if (await askConfirm("Run this install command now?")) {
188
129
  await runRtkInstall(command);
@@ -7,6 +7,12 @@ import path from "node:path";
7
7
  import { parse as parseJsonc } from "jsonc-parser";
8
8
 
9
9
  import { isDeclinedByMember, readMemberChoices } from "../../../lib/member-choices";
10
+ import {
11
+ readToolManifest,
12
+ toolNotice,
13
+ toolVersion,
14
+ warnOnVersionDrift,
15
+ } from "../../../lib/tool-manifest";
10
16
  import { resolveSecretPolicy } from "../../../runtime/policy";
11
17
  import { DEFAULT_SECRET_DENY_PATTERNS, type SecretPolicy } from "../../../runtime/secret-patterns";
12
18
  import type { InstallRequirement } from "../install-contract";
@@ -21,14 +27,15 @@ export const TOKENSAVE_STORE_DIR = ".tokensave";
21
27
  export const TOKENSAVE_STORE_CONFIG_FILE = "config.json";
22
28
  /** The index itself: `tokensave sync` refuses a store without it. */
23
29
  const TOKENSAVE_STORE_DATABASE_FILE = "tokensave.db";
24
- export const TOKENSAVE_MIN_RUST_VERSION = "1.91.0";
30
+ export const TOKENSAVE_MIN_RUST_VERSION = tokensaveMinRustVersion();
25
31
  /** Single-graph posture Mate owns in the per-project store config; every other key is left as found. */
26
32
  const TOKENSAVE_OWNED_POSTURE = { auto_track: false, suppress_scope_warning: true } as const;
27
33
  const TOKENSAVE_BRANCH_META_FILE = "branch-meta.json";
28
34
  const TOKENSAVE_DISABLED_BRANCH_META_FILE = "branch-meta.json.mate-disabled";
29
35
  const TOKENSAVE_STORE_EXCLUDE_ENTRY = `${TOKENSAVE_STORE_DIR}/`;
30
36
  const TOKENSAVE_BREW_INSTALL_CMD = "brew install aovestdipaperino/tap/tokensave";
31
- const TOKENSAVE_CARGO_INSTALL_CMD = "cargo install --locked tokensave";
37
+ const TOKENSAVE_VERSION = toolVersion("tokensave");
38
+ const TOKENSAVE_CARGO_INSTALL_CMD = `cargo install --locked tokensave --version ${TOKENSAVE_VERSION}`;
32
39
  const TOKENSAVE_SCOOP_INSTALL_CMD =
33
40
  "scoop bucket add tokensave https://github.com/aovestdipaperino/scoop-bucket && scoop install tokensave";
34
41
 
@@ -69,6 +76,7 @@ export const tokensaveDeps = {
69
76
  encoding: "utf8",
70
77
  stdio: ["ignore", "pipe", "pipe"],
71
78
  env: process.env,
79
+ timeout: 5_000,
72
80
  });
73
81
  return {
74
82
  ok: result.status === 0 && !result.error,
@@ -119,24 +127,19 @@ async function cleanupRepoLocalTokensaveArtifacts(repoPath: string): Promise<voi
119
127
  }
120
128
  }
121
129
 
122
- async function tokensaveInstalled(repoPath: string): Promise<boolean> {
130
+ /** What `tokensave --version` prints, or null when the binary cannot run. */
131
+ function tokensaveVersionOutput(repoPath: string): string | null {
123
132
  const result = tokensaveDeps.run(["--version"], repoPath);
124
- return result.ok;
133
+ return result.ok ? result.stdout : null;
125
134
  }
126
135
 
127
- /**
128
- * Upgrades the installed binary without making setup depend on network
129
- * availability. Never passes `--kill`: it stops every tokensave process on the
130
- * machine, including MCP servers of running agent sessions. Without a TTY,
131
- * tokensave upgrades and leaves them running.
132
- */
133
- async function upgradeTokensave(repoPath: string): Promise<void> {
134
- const result = tokensaveDeps.run(["upgrade"], repoPath);
135
- if (result.ok) return;
136
-
137
- const detail = result.stderr.trim();
138
- process.stderr.write(
139
- `tokensave: automatic upgrade failed${detail ? `: ${detail}` : ""} - continuing with the installed version\n`,
136
+ /** Homebrew and Scoop cannot install an older formula, so the warning always names Cargo. */
137
+ function warnOnTokensaveDrift(versionOutput: string | null): void {
138
+ warnOnVersionDrift(
139
+ "tokensave",
140
+ versionOutput,
141
+ TOKENSAVE_CARGO_INSTALL_CMD,
142
+ resolveCommandOnPath("tokensave", tokensaveDeps.pathValue()),
140
143
  );
141
144
  }
142
145
 
@@ -233,6 +236,14 @@ export async function isTokensaveAgentIntegrated(agent: string): Promise<boolean
233
236
  return true;
234
237
  }
235
238
 
239
+ /** `rust_version` of the pinned TokenSave entry in the tool manifest. */
240
+ function tokensaveMinRustVersion(): string {
241
+ const value = readToolManifest().tools.tokensave?.rust_version;
242
+ if (typeof value !== "string")
243
+ throw new Error("tool manifest names no rust_version for tokensave");
244
+ return value;
245
+ }
246
+
236
247
  function getCargoRustVersionError(): string | undefined {
237
248
  const result = tokensaveDeps.rustcVersion();
238
249
  const version = `${result.stdout}\n${result.stderr}`.match(/\brustc\s+(\d+)\.(\d+)\.(\d+)/);
@@ -252,50 +263,57 @@ function getCargoRustVersionError(): string | undefined {
252
263
  function getTokensaveInstallPlan(): { command: string; run: () => Promise<void> } | undefined {
253
264
  const pathValue = tokensaveDeps.pathValue();
254
265
  const platform = tokensaveDeps.platform();
255
-
266
+ // Homebrew and Scoop install the latest release, not the pinned one.
267
+ let latest: { command: string; run: () => Promise<void> } | undefined;
256
268
  if (platform === "darwin" && tokensaveDeps.isCommandOnPath("brew", pathValue)) {
257
- return {
269
+ latest = {
258
270
  command: TOKENSAVE_BREW_INSTALL_CMD,
259
271
  run: () => tokensaveDeps.runCommand("brew", ["install", "aovestdipaperino/tap/tokensave"]),
260
272
  };
261
- }
262
-
263
- if (platform === "win32" && tokensaveDeps.isCommandOnPath("scoop", pathValue)) {
264
- return {
273
+ } else if (platform === "win32" && tokensaveDeps.isCommandOnPath("scoop", pathValue)) {
274
+ latest = {
265
275
  command: TOKENSAVE_SCOOP_INSTALL_CMD,
266
276
  run: () => tokensaveDeps.runShellCommand(TOKENSAVE_SCOOP_INSTALL_CMD),
267
277
  };
268
278
  }
279
+ if (!tokensaveDeps.isCommandOnPath("cargo", pathValue)) return latest;
269
280
 
270
- if (tokensaveDeps.isCommandOnPath("cargo", pathValue)) {
271
- return {
272
- command: TOKENSAVE_CARGO_INSTALL_CMD,
273
- run: async () => {
274
- const rustVersionError = getCargoRustVersionError();
275
- if (rustVersionError) throw new Error(rustVersionError);
276
- await tokensaveDeps.runCommand("cargo", ["install", "--locked", "tokensave"]);
277
- },
278
- };
279
- }
280
-
281
- return undefined;
281
+ return {
282
+ command: TOKENSAVE_CARGO_INSTALL_CMD,
283
+ run: async () => {
284
+ // Probed here, not while planning: launch preflight builds this plan on every launch,
285
+ // and its fingerprint must not change with the rustc version.
286
+ const rustVersionError = getCargoRustVersionError();
287
+ if (rustVersionError) {
288
+ if (!latest) throw new Error(rustVersionError);
289
+ toolNotice(
290
+ `tokensave: ${rustVersionError} Installing the latest release instead with: ${latest.command}\n`,
291
+ );
292
+ await latest.run();
293
+ return;
294
+ }
295
+ await tokensaveDeps.runCommand("cargo", [
296
+ "install",
297
+ "--locked",
298
+ "tokensave",
299
+ "--version",
300
+ TOKENSAVE_VERSION,
301
+ ]);
302
+ },
303
+ };
282
304
  }
283
305
 
284
- export async function ensureTokensaveInstalled(
285
- repoPath: string,
286
- options: { upgrade?: boolean } = {},
287
- ): Promise<boolean> {
288
- if (await tokensaveInstalled(repoPath)) {
289
- if (options.upgrade) await upgradeTokensave(repoPath);
290
- return true;
291
- }
306
+ /** Installs TokenSave when it is missing; returns its `--version` output, or null when unavailable. */
307
+ async function installTokensaveIfMissing(repoPath: string): Promise<string | null> {
308
+ const present = tokensaveVersionOutput(repoPath);
309
+ if (present !== null) return present;
292
310
 
293
311
  const installPlan = getTokensaveInstallPlan();
294
312
  if (!installPlan) {
295
313
  process.stderr.write(
296
314
  "tokensave binary not found and no supported installer is available on PATH. Install it manually: https://github.com/aovestdipaperino/tokensave\n",
297
315
  );
298
- return false;
316
+ return null;
299
317
  }
300
318
 
301
319
  process.stdout.write(`tokensave binary not found. Installing with:\n ${installPlan.command}\n`);
@@ -306,17 +324,20 @@ export async function ensureTokensaveInstalled(
306
324
  process.stderr.write(
307
325
  `tokensave: install failed${detail} - install manually with \`${installPlan.command}\`\n`,
308
326
  );
309
- return false;
327
+ return null;
310
328
  }
311
329
 
312
- if (!(await tokensaveInstalled(repoPath))) {
330
+ const installed = tokensaveVersionOutput(repoPath);
331
+ if (installed === null) {
313
332
  process.stderr.write(
314
333
  "tokensave install completed but the binary is still not available on PATH\n",
315
334
  );
316
- return false;
317
335
  }
336
+ return installed;
337
+ }
318
338
 
319
- return true;
339
+ export async function ensureTokensaveInstalled(repoPath: string): Promise<boolean> {
340
+ return (await installTokensaveIfMissing(repoPath)) !== null;
320
341
  }
321
342
 
322
343
  export async function ensureTokensaveStoreExcluded(repoPath: string): Promise<void> {
@@ -478,7 +499,7 @@ export function createTokensavePlugin(): CapabilityPlugin {
478
499
  group: "companion",
479
500
  source: "TokenSave capability",
480
501
  recommendedBy: ["tokensave"],
481
- command: plan?.command ?? "cargo install tokensave",
502
+ command: plan?.command ?? TOKENSAVE_CARGO_INSTALL_CMD,
482
503
  fingerprint: `tokensave:${plan?.command ?? "manual"}`,
483
504
  detect: () => tokensaveDeps.run(["--version"], process.cwd()).ok,
484
505
  install: async () => {
@@ -490,7 +511,7 @@ export function createTokensavePlugin(): CapabilityPlugin {
490
511
  await plan.run();
491
512
  },
492
513
  verify: () => tokensaveDeps.run(["--version"], process.cwd()).ok,
493
- update: () => upgradeTokensave(process.cwd()),
514
+ update: async () => warnOnTokensaveDrift(tokensaveVersionOutput(process.cwd())),
494
515
  },
495
516
  ...(config.allowedAgents ?? [])
496
517
  .filter((agent) => TOKENSAVE_SUPPORTED_AGENTS.has(agent))
@@ -578,10 +599,11 @@ export function createTokensavePlugin(): CapabilityPlugin {
578
599
  ["tokensave"],
579
600
  tokensaveDeps.readMemberChoices,
580
601
  ));
581
- const installed = mayInstall
582
- ? await ensureTokensaveInstalled(targetPath, { upgrade: true })
583
- : await tokensaveInstalled(targetPath);
584
- if (!installed) return;
602
+ const versionOutput = mayInstall
603
+ ? await installTokensaveIfMissing(targetPath)
604
+ : tokensaveVersionOutput(targetPath);
605
+ if (versionOutput === null) return;
606
+ if (ctx.mode === "setup") warnOnTokensaveDrift(versionOutput);
585
607
  await ensureTokensaveBranchingPosture(targetPath, resolveSecretPolicy(ctx.companionPath));
586
608
  if (ctx.mode === "setup") {
587
609
  installTokensaveAgentIntegrations(ctx.activeProviders, targetPath);
@@ -199,6 +199,8 @@ export interface PluginContextServices {
199
199
  services: { mcp: McpService; instructions: InstructionsService; templates: TemplatesService };
200
200
  /** MCP server names and instruction block keys registered during this run. */
201
201
  registered: { mcpServers: Set<string>; instructionBlocks: Set<string> };
202
+ /** Set by `mcp.withhold`: finalize keeps this plugin's previous MCP servers and their record. */
203
+ mcpWithheld?: boolean;
202
204
  }
203
205
 
204
206
  export interface ContextServiceMediatorOptions {
@@ -207,6 +209,8 @@ export interface ContextServiceMediatorOptions {
207
209
  hostingProviders: HostingProvider[];
208
210
  assetOverrideRoots?: string[];
209
211
  warn(message: string): void;
212
+ /** MCP server names enabled Capabilities declare as contributions, by name to plugin id. */
213
+ declaredMcpOwners?(): Promise<ReadonlyMap<string, string>>;
210
214
  }
211
215
 
212
216
  /**
@@ -244,11 +248,25 @@ export class ContextServiceMediator {
244
248
  );
245
249
  return;
246
250
  }
251
+ if (entry?.mcpWithheld) return;
247
252
  for (const provider of hosts) {
248
253
  await provider.hosting.mcp?.register(ctx, descriptor);
249
254
  }
250
255
  registered.mcpServers.add(descriptor.name);
251
256
  },
257
+ owners: async () => {
258
+ const owners = new Map(await this.options.declaredMcpOwners?.());
259
+ for (const [otherId, other] of this.byPlugin) {
260
+ if (otherId === pluginId) continue;
261
+ for (const name of other.registered.mcpServers) owners.set(name, otherId);
262
+ }
263
+ owners.forEach((owner, name) => owner === pluginId && owners.delete(name));
264
+ return owners;
265
+ },
266
+ withhold: (reason: string) => {
267
+ if (entry) entry.mcpWithheld = true;
268
+ warn(reason);
269
+ },
252
270
  };
253
271
 
254
272
  const instructions: InstructionsService = {
@@ -297,6 +315,13 @@ export class ContextServiceMediator {
297
315
  return entry;
298
316
  }
299
317
 
318
+ /** MCP server names any plugin registered in this pass. */
319
+ registeredMcpServers(): Set<string> {
320
+ return new Set(
321
+ [...this.byPlugin.values()].flatMap((entry) => [...entry.registered.mcpServers]),
322
+ );
323
+ }
324
+
300
325
  /**
301
326
  * Reconcile the bookkeeping manifest: remove provider entries that were
302
327
  * previously registered but not re-registered in this run, then persist the
@@ -307,11 +332,17 @@ export class ContextServiceMediator {
307
332
  const manifestPath = getContextServicesManifestPath(ctx.companionPath, frameworkName);
308
333
  const manifest = await loadManifest(manifestPath);
309
334
 
335
+ /** A name that moved to another plugin this pass is that plugin's now, never removed. */
336
+ const registeredThisPass = this.registeredMcpServers();
337
+
310
338
  for (const [pluginId, entry] of this.byPlugin) {
311
339
  const previous = manifest.plugins[pluginId] ?? {};
312
- const staleMcpServers = (previous.mcpServers ?? []).filter(
313
- (name) => !entry.registered.mcpServers.has(name),
314
- );
340
+ const mcpServers = entry.mcpWithheld
341
+ ? (previous.mcpServers ?? [])
342
+ : [...entry.registered.mcpServers];
343
+ const staleMcpServers = entry.mcpWithheld
344
+ ? []
345
+ : (previous.mcpServers ?? []).filter((name) => !registeredThisPass.has(name));
315
346
  const staleBlocks = (previous.instructionBlocks ?? []).filter(
316
347
  (blockKey) => !entry.registered.instructionBlocks.has(blockKey),
317
348
  );
@@ -329,9 +360,7 @@ export class ContextServiceMediator {
329
360
  }
330
361
 
331
362
  const record: PluginServiceRecord = {};
332
- if (entry.registered.mcpServers.size > 0) {
333
- record.mcpServers = [...entry.registered.mcpServers];
334
- }
363
+ if (mcpServers.length > 0) record.mcpServers = mcpServers;
335
364
  if (entry.registered.instructionBlocks.size > 0) {
336
365
  record.instructionBlocks = [...entry.registered.instructionBlocks];
337
366
  }
@@ -5,6 +5,7 @@ import { parse } from "yaml";
5
5
 
6
6
  import { FRAMEWORK_NAME } from "../../../framework";
7
7
  import { ConfigError, type PluginDeclaration } from "../../../lib/orchestrator/types";
8
+ import { audienceOrigin, BASE_PLUGIN_ORIGIN, type PluginOrigin } from "./paths";
8
9
 
9
10
  export const AUDIENCE_ENV = "MATE_AUDIENCE";
10
11
 
@@ -15,7 +16,7 @@ export const AUDIENCE_ENV = "MATE_AUDIENCE";
15
16
  export const BASE_AUDIENCE = "base";
16
17
 
17
18
  /** The keys 0.18.4 moved under `audiences.base`; companion-wide keys stayed at the root. */
18
- export const BASE_AUDIENCE_KEYS = ["capabilities", "plugins", "studio"] as const;
19
+ export const BASE_AUDIENCE_KEYS = ["capabilities", "plugins", "studio", "mcpManager"] as const;
19
20
 
20
21
  export type AudienceResolution =
21
22
  | { ok: true; active: string | null }
@@ -29,7 +30,8 @@ function pluginList(value: unknown): unknown[] {
29
30
  return isRecord(value) && Array.isArray(value.plugins) ? value.plugins : [];
30
31
  }
31
32
 
32
- function audienceEntry(raw: unknown, audience: string | null): unknown {
33
+ /** The raw entry of a declared audience; undefined for none, `base` or an undeclared one. */
34
+ export function audienceEntry(raw: unknown, audience: string | null): unknown {
33
35
  if (audience === null || audience === BASE_AUDIENCE) return undefined;
34
36
  if (!isRecord(raw) || !isRecord(raw.audiences)) return undefined;
35
37
  return Object.hasOwn(raw.audiences, audience) ? raw.audiences[audience] : undefined;
@@ -102,26 +104,29 @@ export function effectivePluginDeclarations(raw: unknown, audience: string | nul
102
104
  return [...pluginList(normalizeBaseAudience(raw)), ...pluginList(audienceEntry(raw, audience))];
103
105
  }
104
106
 
105
- /** The ordinary install that writes and installs `audience`'s workspace (`null`: the shared one). */
106
- export function audienceInstallCommand(audience: string | null): string {
107
+ /** The ordinary install that writes and installs the workspace of `origin`. */
108
+ export function pluginInstallCommand(origin: PluginOrigin): string {
107
109
  const install = `${FRAMEWORK_NAME} install`;
108
- return audience === null ? install : `${AUDIENCE_ENV}=${audience} ${install}`;
110
+ return origin.kind === "audience" ? `${AUDIENCE_ENV}=${origin.name} ${install}` : install;
109
111
  }
110
112
 
111
113
  /** A raw `plugins` entry with the workspace it installs into and loads from. */
112
114
  export interface OriginPluginEntry {
113
115
  entry: unknown;
114
- /** `null` for a base plugin, else the audience declaring it. */
115
- audience: string | null;
116
+ origin: PluginOrigin;
116
117
  }
117
118
 
118
119
  /** `effectivePluginDeclarations`, each entry keeping its origin. */
119
120
  export function effectivePluginEntries(raw: unknown, audience: string | null): OriginPluginEntry[] {
120
121
  const active = resolveAudience(raw, audience);
121
122
  const name = active.ok ? active.active : null;
123
+ const origin = audienceOrigin(name);
122
124
  return [
123
- ...pluginList(normalizeBaseAudience(raw)).map((entry) => ({ entry, audience: null })),
124
- ...pluginList(audienceEntry(raw, name)).map((entry) => ({ entry, audience: name })),
125
+ ...pluginList(normalizeBaseAudience(raw)).map((entry) => ({
126
+ entry,
127
+ origin: BASE_PLUGIN_ORIGIN,
128
+ })),
129
+ ...pluginList(audienceEntry(raw, name)).map((entry) => ({ entry, origin })),
125
130
  ];
126
131
  }
127
132
 
@@ -159,13 +164,23 @@ export function pluginInstallTargets(
159
164
 
160
165
  /** Packages declared under any audience, the ones that never belong in the shared workspace. */
161
166
  export function audiencePluginPackages(raw: unknown): Set<string> {
162
- const packages = new Set<string>();
163
- for (const name of declaredAudiences(raw)) {
164
- for (const entry of pluginList(audienceEntry(raw, name))) {
165
- if (isRecord(entry) && typeof entry.package === "string") packages.add(entry.package);
166
- }
167
- }
168
- return packages;
167
+ return new Set(
168
+ declaredAudiences(raw).flatMap((name) => packageNames(pluginList(audienceEntry(raw, name)))),
169
+ );
170
+ }
171
+
172
+ /** Packages `framework.yaml` declares in the base list or under any audience. */
173
+ export function committedPluginPackages(raw: unknown): Set<string> {
174
+ return new Set([
175
+ ...audiencePluginPackages(raw),
176
+ ...packageNames(pluginList(normalizeBaseAudience(raw))),
177
+ ]);
178
+ }
179
+
180
+ function packageNames(entries: unknown[]): string[] {
181
+ return entries.flatMap((entry) =>
182
+ isRecord(entry) && typeof entry.package === "string" ? [entry.package] : [],
183
+ );
169
184
  }
170
185
 
171
186
  /** Operator-facing message for a `MATE_AUDIENCE` the companion does not declare. */