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

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 (181) 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 +16 -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/factory-host.ts +6 -0
  18. package/src/index.ts +1 -0
  19. package/src/lib/delivery/merge-git.ts +31 -7
  20. package/src/lib/delivery/overlap.ts +14 -1
  21. package/src/lib/delivery/repository-access.ts +11 -6
  22. package/src/lib/delivery/staging/apply-chain.ts +25 -7
  23. package/src/lib/delivery/staging/linked-merges.ts +175 -0
  24. package/src/lib/delivery/staging/naming.ts +3 -0
  25. package/src/lib/delivery/staging/openspec-type.ts +38 -7
  26. package/src/lib/delivery/staging/pending.ts +153 -11
  27. package/src/lib/delivery/staging/preflight.ts +239 -0
  28. package/src/lib/delivery/staging/project.ts +243 -104
  29. package/src/lib/delivery/staging/replay.ts +5 -3
  30. package/src/lib/delivery/staging/settle-linked.ts +5 -119
  31. package/src/lib/delivery/staging/submit.ts +139 -18
  32. package/src/lib/delivery/submit-change.ts +163 -37
  33. package/src/lib/friction/mark.ts +49 -11
  34. package/src/lib/friction/view/read.ts +10 -1
  35. package/src/lib/openspec-cli.ts +10 -5
  36. package/src/lib/skills-cli.ts +38 -0
  37. package/src/lib/tool-manifest.ts +73 -0
  38. package/src/lib/triage/context.ts +138 -12
  39. package/src/lib/triage/prepare.ts +19 -4
  40. package/src/plugin-api.ts +1 -0
  41. package/src/runtime/command-arg.ts +15 -0
  42. package/src/runtime/companion-guidance.ts +1 -1
  43. package/src/runtime/friction-log.ts +41 -17
  44. package/src/runtime/friction-recorder.ts +15 -2
  45. package/src/runtime/git-tracked.ts +13 -2
  46. package/src/studio.ts +6 -1
  47. package/src/templates/capabilities/openspec-cap/mate-minimal/schema.yaml +5 -1
  48. package/src/templates/capabilities/react-doctor/mate-react-doctor/SKILL.md +28 -0
  49. package/src/templates/mate-skills/agents/mate-apply-change/SKILL.md +42 -4
  50. package/src/templates/mate-skills/agents/mate-archive-change/SKILL.md +27 -2
  51. package/src/templates/mate-skills/agents/mate-backfill-spec/SKILL.md +23 -1
  52. package/src/templates/mate-skills/agents/mate-clarify-intent/SKILL.md +26 -1
  53. package/src/templates/mate-skills/agents/mate-domain-modeling/SKILL.md +28 -0
  54. package/src/templates/mate-skills/agents/mate-explore-change/SKILL.md +28 -3
  55. package/src/templates/mate-skills/agents/mate-grill-me/SKILL.md +28 -0
  56. package/src/templates/mate-skills/agents/mate-grill-with-docs/SKILL.md +28 -0
  57. package/src/templates/mate-skills/agents/mate-grilling/SKILL.md +25 -0
  58. package/src/templates/mate-skills/agents/mate-interview-me/SKILL.md +28 -0
  59. package/src/templates/mate-skills/agents/mate-propose-change/SKILL.md +28 -3
  60. package/src/templates/mate-skills/agents/mate-publish-artifact/SKILL.md +28 -6
  61. package/src/templates/mate-skills/agents/mate-show-me/SKILL.md +27 -2
  62. package/src/templates/mate-skills/agents/mate-simplify-code/SKILL.md +28 -0
  63. package/src/templates/mate-skills/agents/mate-submit-change/SKILL.md +24 -2
  64. package/src/templates/mate-skills/claude/mate-apply-change/SKILL.md +42 -4
  65. package/src/templates/mate-skills/claude/mate-archive-change/SKILL.md +27 -2
  66. package/src/templates/mate-skills/claude/mate-backfill-spec/SKILL.md +23 -1
  67. package/src/templates/mate-skills/claude/mate-clarify-intent/SKILL.md +26 -1
  68. package/src/templates/mate-skills/claude/mate-domain-modeling/SKILL.md +28 -0
  69. package/src/templates/mate-skills/claude/mate-explore-change/SKILL.md +28 -3
  70. package/src/templates/mate-skills/claude/mate-grill-me/SKILL.md +28 -0
  71. package/src/templates/mate-skills/claude/mate-grill-with-docs/SKILL.md +28 -0
  72. package/src/templates/mate-skills/claude/mate-grilling/SKILL.md +25 -0
  73. package/src/templates/mate-skills/claude/mate-interview-me/SKILL.md +28 -0
  74. package/src/templates/mate-skills/claude/mate-propose-change/SKILL.md +28 -3
  75. package/src/templates/mate-skills/claude/mate-publish-artifact/SKILL.md +28 -6
  76. package/src/templates/mate-skills/claude/mate-show-me/SKILL.md +27 -2
  77. package/src/templates/mate-skills/claude/mate-simplify-code/SKILL.md +28 -0
  78. package/src/templates/mate-skills/claude/mate-submit-change/SKILL.md +24 -2
  79. package/src/templates/triage/PLAYBOOK.md +9 -1
  80. package/src/tools/setup/__snapshots__/runtime-surface-golden.test.ts.snap +108 -108
  81. package/src/tools/setup/capabilities/graphify.ts +23 -1
  82. package/src/tools/setup/capabilities/rtk.ts +27 -86
  83. package/src/tools/setup/capabilities/tokensave.ts +76 -54
  84. package/src/tools/setup/dynamic-plugins/audiences.ts +28 -14
  85. package/src/tools/setup/dynamic-plugins/hydrate.ts +32 -14
  86. package/src/tools/setup/dynamic-plugins/install.ts +2 -0
  87. package/src/tools/setup/dynamic-plugins/installed.ts +73 -0
  88. package/src/tools/setup/dynamic-plugins/loader.ts +12 -10
  89. package/src/tools/setup/dynamic-plugins/local.ts +492 -0
  90. package/src/tools/setup/dynamic-plugins/paths.ts +34 -6
  91. package/src/tools/setup/dynamic-plugins/verify.ts +34 -14
  92. package/src/tools/setup/dynamic-plugins/workspaces.ts +17 -8
  93. package/src/tools/setup/mate.ts +26 -1
  94. package/src/tools/setup/plugins/gitignore.ts +45 -12
  95. package/src/tools/setup/service.ts +8 -0
  96. package/src/tools/setup/utils.ts +10 -1
  97. package/studio-dist/client/assets/app-ggXJ_QVh.css +2 -0
  98. package/studio-dist/client/assets/button-amJ3g5oD.js +1 -0
  99. package/studio-dist/client/assets/cn-BQPKiwI4.js +1 -0
  100. package/studio-dist/client/assets/combobox-CJ7aGFid.js +1 -0
  101. package/studio-dist/client/assets/{companion-view-DINdPF-b.js → companion-view-C_N237bf.js} +1 -1
  102. package/studio-dist/client/assets/fields-BAiGkJ5N.js +1 -0
  103. package/studio-dist/client/assets/friction-DqOU59v7.js +1 -0
  104. package/studio-dist/client/assets/getting-started-yp42dj5S.js +1 -0
  105. package/studio-dist/client/assets/{getting-started._topic-DVB8e5R9.js → getting-started._topic-C9zVXz_m.js} +1 -1
  106. package/studio-dist/client/assets/{getting-started.index-DQvLHEr1.js → getting-started.index-DWbDKICP.js} +1 -1
  107. package/studio-dist/client/assets/graph-BYaD_5Bq.js +2 -0
  108. package/studio-dist/client/assets/{graph-canvas-DIcAqwtK.js → graph-canvas-ySGKMhmk.js} +1 -1
  109. package/studio-dist/client/assets/index-Qx7reRPD.js +40 -0
  110. package/studio-dist/client/assets/panel-C4bf_h2W.js +1 -0
  111. package/studio-dist/client/assets/plugins._service._view-y6f2FDAB.js +1 -0
  112. package/studio-dist/client/assets/reports-JFSwSueq.js +1 -0
  113. package/studio-dist/client/assets/routes-BdOWSgzK.js +1 -0
  114. package/studio-dist/client/assets/select-BHYYWPhK.js +1 -0
  115. package/studio-dist/client/assets/skills-Bo9FLsBd.js +1 -0
  116. package/studio-dist/client/assets/{specs-Dl8HfGlU.js → specs-BrCOjOch.js} +1 -1
  117. package/studio-dist/client/assets/specs-view-CdE2rlli.js +1 -0
  118. package/studio-dist/client/assets/{store-DyXbi6o9.js → store-C3vJq8Wj.js} +1 -1
  119. package/studio-dist/client/assets/{usage-Blcl8kA_.js → usage-BLsLy0nN.js} +13 -13
  120. package/studio-dist/client/assets/{useAnchoredPopupScrollLock-BBXJpX5L.js → useAnchoredPopupScrollLock-DC7f8GOp.js} +1 -1
  121. package/studio-dist/client/assets/useMutation-uJUrejsi.js +1 -0
  122. package/studio-dist/client/assets/vault-BB1B_OhR.js +1 -0
  123. package/studio-dist/client/assets/warnings-CqOOGlPD.js +1 -0
  124. package/studio-dist/client/assets/workflow-BFzmI-06.js +1 -0
  125. package/studio-dist/server/assets/{__23tanstack-start-server-fn-resolver-JoHQ5ihx.js → __23tanstack-start-server-fn-resolver-gVfW5vIV.js} +1 -1
  126. package/studio-dist/server/assets/_tanstack-start-manifest_v.js +42 -42
  127. package/studio-dist/server/assets/{button-B7e1fRyW.js → button-D6bvrFmm.js} +3 -3480
  128. package/studio-dist/server/assets/cn-FXJAM0KO.js +5528 -0
  129. package/studio-dist/server/assets/{combobox--S_OmUfh.js → combobox-D2MbYV1O.js} +6 -5
  130. package/studio-dist/server/assets/{companion-view-D-vGM55e.js → companion-view-Mf1ANbMb.js} +2 -2
  131. package/studio-dist/server/assets/{fields-B4qM2ZwC.js → fields-B4mAPETz.js} +2 -1
  132. package/studio-dist/server/assets/{friction-sLxaWY-H.js → friction-9a5S1m7U.js} +54 -14
  133. package/studio-dist/server/assets/{getting-started-Cq5Pcnsr.js → getting-started-RU6tYU2Q.js} +2 -2
  134. package/studio-dist/server/assets/{getting-started._topic-CmWdl3u3.js → getting-started._topic-C02HGrC6.js} +2 -2
  135. package/studio-dist/server/assets/{getting-started.index-AB8xpTFY.js → getting-started.index-EzLRosbb.js} +2 -2
  136. package/studio-dist/server/assets/{graph-C_Hn-Wf_.js → graph-CZ2H9Fzr.js} +7 -6
  137. package/studio-dist/server/assets/{graph-canvas-BthrSmPS.js → graph-canvas-rP5TT14Z.js} +1 -1
  138. package/studio-dist/server/assets/{guides-BVQ4pt5B.js → guides-BGftp4wf.js} +1 -1
  139. package/studio-dist/server/assets/{markdown-view-rwiiVcPC.js → markdown-view-CArpV-CS.js} +1 -1
  140. package/studio-dist/server/assets/{panel-CUxRIpYL.js → panel-DR0iq46J.js} +4 -3
  141. package/studio-dist/server/assets/{plugins._service._view-BSvGnlhU.js → plugins._service._view-n7u2k5dF.js} +7 -4
  142. package/studio-dist/server/assets/{queries-S_Pl90IG.js → queries-D-yVP9i0.js} +1 -1
  143. package/studio-dist/server/assets/{reports-CJpAItPk.js → reports-C2SmTgqh.js} +6 -5
  144. package/studio-dist/server/assets/{router-DF0etoNa.js → router-CPt0TAk_.js} +54 -29
  145. package/studio-dist/server/assets/{routes-6ylCLkyg.js → routes-CwH8LEy2.js} +8 -7
  146. package/studio-dist/server/assets/{select-CjuKScan.js → select-C3i6TTX-.js} +5 -4
  147. package/studio-dist/server/assets/{shell-DLkP7wG9.js → shell-CagqZZMZ.js} +2 -1
  148. package/studio-dist/server/assets/{skills-zeU80A9S.js → skills-C21Mg_8-.js} +7 -6
  149. package/studio-dist/server/assets/{specs-DDBNT_v1.js → specs-DetoMiaB.js} +3 -3
  150. package/studio-dist/server/assets/{specs-view-exvmWdg0.js → specs-view-CmbfLDwN.js} +9 -8
  151. package/studio-dist/server/assets/{store-kS7zk0Hr.js → store-aC-I6f6o.js} +1 -1
  152. package/studio-dist/server/assets/{studio-queries-qOXOYoPt.js → studio-queries-Dqf-3nzj.js} +1 -1
  153. package/studio-dist/server/assets/{usage-C2um7YiV.js → usage-CS4CBK9D.js} +9 -9
  154. package/studio-dist/server/assets/{useAnchoredPopupScrollLock-kQBB3y_b.js → useAnchoredPopupScrollLock-BjMNgXv9.js} +2 -2
  155. package/studio-dist/server/assets/{useMutation-C-WO6hCM.js → useMutation-DpBIuWXt.js} +2 -2
  156. package/studio-dist/server/assets/{vault-B8vgVIH9.js → vault-DVQidlId.js} +6 -6
  157. package/studio-dist/server/assets/{warnings-BxK4VfV5.js → warnings-C7hgXpdk.js} +2 -1
  158. package/studio-dist/server/assets/{workflow-BrTK632u.js → workflow-6dZZ1ofw.js} +7 -6
  159. package/studio-dist/server/server.js +2 -2
  160. package/tool-manifest.yaml +85 -0
  161. package/studio-dist/client/assets/app-aIwDxf48.css +0 -2
  162. package/studio-dist/client/assets/button-CX0sWAJl.js +0 -1
  163. package/studio-dist/client/assets/combobox-BmA8RjOc.js +0 -1
  164. package/studio-dist/client/assets/fields-BobQ7zRF.js +0 -1
  165. package/studio-dist/client/assets/friction-YdYd3zaz.js +0 -1
  166. package/studio-dist/client/assets/getting-started-CY7NEtTw.js +0 -1
  167. package/studio-dist/client/assets/graph-DbNnR884.js +0 -2
  168. package/studio-dist/client/assets/index-CysBCSxM.js +0 -40
  169. package/studio-dist/client/assets/panel-Csr49lBo.js +0 -1
  170. package/studio-dist/client/assets/plugins._service._view-CEA_CcPe.js +0 -1
  171. package/studio-dist/client/assets/reports-CLdgxxkg.js +0 -1
  172. package/studio-dist/client/assets/routes-DGilWbDE.js +0 -1
  173. package/studio-dist/client/assets/select-DdebbX7K.js +0 -1
  174. package/studio-dist/client/assets/skills-C3zNkU8g.js +0 -1
  175. package/studio-dist/client/assets/specs-view-B_n0Pekv.js +0 -1
  176. package/studio-dist/client/assets/useBaseQuery-C2cjmeH2.js +0 -1
  177. package/studio-dist/client/assets/useMutation-DI6LbvVa.js +0 -1
  178. package/studio-dist/client/assets/vault-Cb9DmM1i.js +0 -1
  179. package/studio-dist/client/assets/warnings-B-rvoW8q.js +0 -1
  180. package/studio-dist/client/assets/workflow-DN5T19jd.js +0 -1
  181. 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);
@@ -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
 
@@ -102,26 +103,29 @@ export function effectivePluginDeclarations(raw: unknown, audience: string | nul
102
103
  return [...pluginList(normalizeBaseAudience(raw)), ...pluginList(audienceEntry(raw, audience))];
103
104
  }
104
105
 
105
- /** The ordinary install that writes and installs `audience`'s workspace (`null`: the shared one). */
106
- export function audienceInstallCommand(audience: string | null): string {
106
+ /** The ordinary install that writes and installs the workspace of `origin`. */
107
+ export function pluginInstallCommand(origin: PluginOrigin): string {
107
108
  const install = `${FRAMEWORK_NAME} install`;
108
- return audience === null ? install : `${AUDIENCE_ENV}=${audience} ${install}`;
109
+ return origin.kind === "audience" ? `${AUDIENCE_ENV}=${origin.name} ${install}` : install;
109
110
  }
110
111
 
111
112
  /** A raw `plugins` entry with the workspace it installs into and loads from. */
112
113
  export interface OriginPluginEntry {
113
114
  entry: unknown;
114
- /** `null` for a base plugin, else the audience declaring it. */
115
- audience: string | null;
115
+ origin: PluginOrigin;
116
116
  }
117
117
 
118
118
  /** `effectivePluginDeclarations`, each entry keeping its origin. */
119
119
  export function effectivePluginEntries(raw: unknown, audience: string | null): OriginPluginEntry[] {
120
120
  const active = resolveAudience(raw, audience);
121
121
  const name = active.ok ? active.active : null;
122
+ const origin = audienceOrigin(name);
122
123
  return [
123
- ...pluginList(normalizeBaseAudience(raw)).map((entry) => ({ entry, audience: null })),
124
- ...pluginList(audienceEntry(raw, name)).map((entry) => ({ entry, audience: name })),
124
+ ...pluginList(normalizeBaseAudience(raw)).map((entry) => ({
125
+ entry,
126
+ origin: BASE_PLUGIN_ORIGIN,
127
+ })),
128
+ ...pluginList(audienceEntry(raw, name)).map((entry) => ({ entry, origin })),
125
129
  ];
126
130
  }
127
131
 
@@ -159,13 +163,23 @@ export function pluginInstallTargets(
159
163
 
160
164
  /** Packages declared under any audience, the ones that never belong in the shared workspace. */
161
165
  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;
166
+ return new Set(
167
+ declaredAudiences(raw).flatMap((name) => packageNames(pluginList(audienceEntry(raw, name)))),
168
+ );
169
+ }
170
+
171
+ /** Packages `framework.yaml` declares in the base list or under any audience. */
172
+ export function committedPluginPackages(raw: unknown): Set<string> {
173
+ return new Set([
174
+ ...audiencePluginPackages(raw),
175
+ ...packageNames(pluginList(normalizeBaseAudience(raw))),
176
+ ]);
177
+ }
178
+
179
+ function packageNames(entries: unknown[]): string[] {
180
+ return entries.flatMap((entry) =>
181
+ isRecord(entry) && typeof entry.package === "string" ? [entry.package] : [],
182
+ );
169
183
  }
170
184
 
171
185
  /** Operator-facing message for a `MATE_AUDIENCE` the companion does not declare. */
@@ -15,10 +15,11 @@ import {
15
15
  resolveAudience,
16
16
  } from "./audiences";
17
17
  import { validateDeclaration } from "./declarations";
18
+ import { admitLocalPlugin, readLoadableEntries } from "./local";
18
19
  import { loadDynamicPlugin, type DynamicPluginLoadDeps } from "./loader";
19
20
 
20
- // Packages already registered in this process; re-hydration (e.g. right after
21
- // an install inside the same run) only picks up plugins that failed before.
21
+ // Packages already registered or refused in this process; re-hydration (e.g.
22
+ // right after an install inside the same run) only picks up plugins that failed to load.
22
23
  const hydratedPackages = new Set<string>();
23
24
 
24
25
  export function resetDynamicPluginHydration(): void {
@@ -31,6 +32,8 @@ export interface HydrateDynamicPluginsDeps extends DynamicPluginLoadDeps {
31
32
  companionPath?: string;
32
33
  registry?: PluginRegistry;
33
34
  warn?: (message: string) => void;
35
+ /** `false` for a frozen restore, which never reads `framework.local.yaml`. */
36
+ includeLocal?: boolean;
34
37
  }
35
38
 
36
39
  /**
@@ -72,7 +75,8 @@ function activateDeclaredPlugin(plugin: Plugin): Plugin {
72
75
  /**
73
76
  * Registers the companion's effective plugins (base plus the active
74
77
  * `MATE_AUDIENCE`) into the active registry — compiled-in plugins first
75
- * (they are already registered), declared order after. Runs before cap-command detection on every invocation. No-op
78
+ * (they are already registered), declared order after, this machine's local
79
+ * plugins last. Runs before cap-command detection on every invocation. No-op
76
80
  * without a companion or `plugins:` entries; all diagnostics go to stderr;
77
81
  * never throws.
78
82
  */
@@ -90,12 +94,17 @@ export async function hydrateDynamicPlugins(deps: HydrateDynamicPluginsDeps = {}
90
94
  if (!audience.ok) {
91
95
  warn(`${describeUnknownAudience(audience)}; applying the base configuration only`);
92
96
  }
93
- const entries = effectivePluginEntries(raw, audience.ok ? audience.active : null);
97
+ const active = audience.ok ? audience.active : null;
98
+ const { entries, problems } =
99
+ deps.includeLocal === false
100
+ ? { entries: effectivePluginEntries(raw, active), problems: [] }
101
+ : await readLoadableEntries(companionPath, raw, active);
102
+ for (const problem of problems) warn(problem.message);
94
103
  if (entries.length === 0) return;
95
104
 
96
105
  const registry = deps.registry ?? getActiveDistribution().registry;
97
106
 
98
- for (const { entry, audience: origin } of entries) {
107
+ for (const { entry, origin } of entries) {
99
108
  const { declaration, error } = validateDeclaration(entry);
100
109
  if (!declaration) {
101
110
  if (error) warn(error);
@@ -110,18 +119,27 @@ export async function hydrateDynamicPlugins(deps: HydrateDynamicPluginsDeps = {}
110
119
  continue;
111
120
  }
112
121
 
113
- const namespace = result.plugin.cliNamespace ?? result.plugin.id;
114
- const holder = registry
115
- .getAll()
116
- .find((existing) => (existing.cliNamespace ?? existing.id) === namespace);
117
- if (holder) {
118
- warn(
119
- `plugin "${declaration.package}" ("${result.plugin.id}") claims cap namespace "${namespace}" already registered by "${holder.id}"; first registration wins.`,
120
- );
122
+ let plugin: Plugin | null = result.plugin;
123
+ if (origin.kind === "local") {
124
+ plugin = admitLocalPlugin(registry, plugin, declaration.package, warn);
125
+ if (!plugin) {
126
+ hydratedPackages.add(declaration.package);
127
+ continue;
128
+ }
129
+ } else {
130
+ const namespace = plugin.cliNamespace ?? plugin.id;
131
+ const holder = registry
132
+ .getAll()
133
+ .find((existing) => (existing.cliNamespace ?? existing.id) === namespace);
134
+ if (holder) {
135
+ warn(
136
+ `plugin "${declaration.package}" ("${plugin.id}") claims cap namespace "${namespace}" already registered by "${holder.id}"; first registration wins.`,
137
+ );
138
+ }
121
139
  }
122
140
 
123
141
  registry.register({
124
- plugin: activateDeclaredPlugin(result.plugin),
142
+ plugin: activateDeclaredPlugin(plugin),
125
143
  policy: declaration.policy ?? "optional",
126
144
  });
127
145
  hydratedPackages.add(declaration.package);
@@ -24,6 +24,8 @@ export interface PluginInstallResult {
24
24
  status: "installed" | "unchanged" | "failed";
25
25
  resolvedVersion?: string;
26
26
  error?: string;
27
+ /** Mate refused before npm ran, so registry advice does not apply. */
28
+ refused?: boolean;
27
29
  }
28
30
 
29
31
  /**
@@ -0,0 +1,73 @@
1
+ import fs from "node:fs/promises";
2
+ import path from "node:path";
3
+
4
+ import { effectivePluginEntries, readFrameworkRaw, resolveAudience } from "./audiences";
5
+ import { validateDeclaration } from "./declarations";
6
+ import { readLoadableEntries } from "./local";
7
+ import { pluginPackageRoot, type PluginOrigin } from "./paths";
8
+
9
+ /** One effective plugin that is installed in the workspace of its origin. */
10
+ export interface InstalledPluginPackage {
11
+ /** The declared package name. */
12
+ package: string;
13
+ /** The installed `package.json` version; empty when it names none. */
14
+ version: string;
15
+ /** The package directory. */
16
+ root: string;
17
+ origin: PluginOrigin;
18
+ }
19
+
20
+ export interface InstalledPluginsOptions {
21
+ /** The active audience; null or an undeclared one lists the base plugins only. */
22
+ audience?: string | null;
23
+ /** Also list this machine's local plugins (default true). */
24
+ includeLocal?: boolean;
25
+ }
26
+
27
+ /**
28
+ * The companion's effective plugins that are installed, in hydration order: base, the
29
+ * active audience's, then local ones. Reads `framework.yaml` and each package's
30
+ * `package.json` only, never plugin code. A declared plugin that is not installed, or whose
31
+ * `package.json` is unreadable, is left out. An unreadable companion lists none.
32
+ */
33
+ export async function installedPluginPackages(
34
+ companionPath: string,
35
+ options: InstalledPluginsOptions = {},
36
+ ): Promise<InstalledPluginPackage[]> {
37
+ let raw: unknown;
38
+ try {
39
+ raw = await readFrameworkRaw(companionPath);
40
+ } catch {
41
+ return [];
42
+ }
43
+ const audience = resolveAudience(raw, options.audience ?? null);
44
+ const active = audience.ok ? audience.active : null;
45
+ const entries =
46
+ options.includeLocal === false
47
+ ? effectivePluginEntries(raw, active)
48
+ : (await readLoadableEntries(companionPath, raw, active)).entries;
49
+
50
+ const seen = new Set<string>();
51
+ const installed: InstalledPluginPackage[] = [];
52
+ for (const { entry, origin } of entries) {
53
+ const { declaration } = validateDeclaration(entry);
54
+ if (!declaration || seen.has(declaration.package)) continue;
55
+ seen.add(declaration.package);
56
+ const root = pluginPackageRoot(companionPath, declaration.package, origin);
57
+ let manifest: unknown;
58
+ try {
59
+ // oxlint-disable-next-line no-await-in-loop -- declared order is part of the contract
60
+ manifest = JSON.parse(await fs.readFile(path.join(root, "package.json"), "utf8"));
61
+ } catch {
62
+ continue;
63
+ }
64
+ const version = (manifest as { version?: unknown } | null)?.version;
65
+ installed.push({
66
+ package: declaration.package,
67
+ version: typeof version === "string" ? version : "",
68
+ root,
69
+ origin,
70
+ });
71
+ }
72
+ return installed;
73
+ }