@uniqbit/mate-core 0.20.0 → 0.21.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/claude-capability-plugins/companion-mentions/.claude-plugin/plugin.json +1 -1
- package/claude-capability-plugins/companion-mentions/hooks/register.ts +1 -1
- package/claude-plugin/hooks/hooks.json +10 -1
- package/claude-plugin/hooks/rtk-worktree-git.mjs +58 -0
- package/opencode-plugin/src/server.ts +9 -2
- package/package.json +2 -1
- package/src/cli/commands/artifact/delivery/environment.ts +28 -8
- package/src/cli/commands/artifact/delivery/link.ts +28 -9
- package/src/cli/commands/artifact/delivery/output.ts +7 -0
- package/src/cli/commands/companion/update.ts +2 -19
- package/src/cli/commands/factory/factory.ts +11 -1
- package/src/cli/commands/install.ts +47 -36
- package/src/cli/commands/launch/claude.ts +2 -0
- package/src/cli/commands/launch/shared.ts +33 -6
- package/src/cli/commands/plugin/install.ts +27 -11
- package/src/cli/commands/report/index.ts +180 -184
- package/src/cli/commands/report/markdown.ts +67 -72
- package/src/cli/commands/shared/companion-selection.ts +3 -1
- package/src/cli/commands/studio/access.ts +6 -14
- package/src/cli/commands/studio/areas.ts +112 -33
- package/src/cli/commands/studio/companion-add.ts +87 -0
- package/src/cli/commands/studio/companion-removal.ts +15 -8
- package/src/cli/commands/studio/factory-credential.ts +1 -15
- package/src/cli/commands/studio/factory-git-tokens.ts +40 -0
- package/src/cli/commands/studio/factory-relay.ts +18 -0
- package/src/cli/commands/studio/graph-model.ts +61 -0
- package/src/cli/commands/studio/graph.ts +336 -0
- package/src/cli/commands/studio/index.ts +4 -4
- package/src/cli/commands/studio/payload.ts +42 -15
- package/src/cli/commands/studio/repository-add.ts +116 -0
- package/src/cli/commands/studio/routes.ts +6 -0
- package/src/cli/commands/studio/selection.ts +12 -3
- package/src/cli/commands/studio/server.ts +127 -5
- package/src/cli/commands/studio/services.ts +40 -0
- package/src/cli/commands/studio/terminal.ts +45 -3
- package/src/cli/commands/studio/views/vault/markdown-tree.ts +84 -3
- package/src/cli/commands/studio/workset-session.ts +47 -14
- package/src/cli/commands/unwrap.ts +3 -0
- package/src/cli/commands/update.ts +2 -0
- package/src/cli/commands/vscode/release-vsix.json +4 -0
- package/src/cli/commands/vscode/setup.ts +71 -13
- package/src/cli/commands/vscode/vsix.ts +48 -7
- package/src/cli/commands/working/cleanup.ts +40 -8
- package/src/cli/commands/working/worktree.ts +176 -35
- package/src/cli/main.ts +17 -2
- package/src/cli/usage.ts +1 -1
- package/src/hooks/rtk-worktree-git.ts +48 -0
- package/src/hooks/validate-artifact-path.ts +38 -7
- package/src/lib/delivery/branch-template.ts +122 -0
- package/src/lib/delivery/branches.ts +21 -16
- package/src/lib/delivery/checkout.ts +102 -0
- package/src/lib/delivery/environment.ts +2 -0
- package/src/lib/delivery/merge-git.ts +13 -1
- package/src/lib/delivery/record-delivery.ts +83 -29
- package/src/lib/delivery/record.ts +15 -3
- package/src/lib/delivery/resolve-branch.ts +157 -110
- package/src/lib/factory/attach-client.ts +11 -1
- package/src/lib/factory/broker.ts +37 -40
- package/src/lib/factory/client.ts +22 -1
- package/src/lib/factory/clone-url.ts +39 -0
- package/src/lib/factory/command.ts +21 -5
- package/src/lib/factory/git-auth.ts +61 -0
- package/src/lib/factory/git-credential-store.ts +181 -0
- package/src/lib/factory/ids.ts +12 -2
- package/src/lib/factory/outcomes/actions.ts +20 -4
- package/src/lib/factory/outcomes/index.ts +77 -11
- package/src/lib/factory/outcomes/lifecycle.ts +9 -2
- package/src/lib/factory/outcomes/sessions.ts +23 -1
- package/src/lib/factory/prepare.ts +9 -3
- package/src/lib/factory/runner/scheduler.ts +96 -14
- package/src/lib/factory/runner/workflow.ts +5 -1
- package/src/lib/factory/runtime.ts +143 -43
- package/src/lib/orchestrator/companion-hub.ts +6 -1
- package/src/lib/orchestrator/engine-floor.ts +48 -0
- package/src/lib/orchestrator/launcher.ts +34 -1
- package/src/lib/orchestrator/projection-claude-commands.ts +2 -2
- package/src/lib/orchestrator/projection-claude-entry.ts +42 -21
- package/src/lib/orchestrator/projection-claude-links.ts +32 -8
- package/src/lib/orchestrator/projection-claude-skills.ts +2 -2
- package/src/lib/orchestrator/projection-entries.ts +22 -18
- package/src/lib/orchestrator/projection-opencode-copies.ts +65 -21
- package/src/lib/orchestrator/projection-runtime-documents.ts +66 -43
- package/src/lib/orchestrator/projection-types.ts +28 -1
- package/src/lib/orchestrator/refresh-working-claude-links.ts +3 -1
- package/src/lib/orchestrator/session-prepare.ts +6 -1
- package/src/lib/orchestrator/setup-compatibilities.ts +1 -1
- package/src/lib/orchestrator/types.ts +4 -0
- package/src/lib/orchestrator/umbrella-checkouts.ts +102 -0
- package/src/lib/orchestrator/working-repo-projection.ts +24 -4
- package/src/lib/orchestrator/wrap-pass.ts +1 -0
- package/src/lib/public-npm.ts +95 -50
- package/src/lib/session-state.ts +72 -2
- package/src/lib/update-checker.ts +7 -1
- package/src/lib/usage/aggregate.ts +202 -0
- package/src/lib/usage/cache.ts +87 -0
- package/src/lib/usage/claude-pricing.ts +71 -0
- package/src/lib/usage/claude.ts +189 -0
- package/src/lib/usage/collect.ts +56 -0
- package/src/lib/usage/opencode.ts +188 -0
- package/src/lib/usage/records.ts +80 -0
- package/src/lib/usage/rtk-database.ts +72 -0
- package/src/lib/usage/savings.ts +209 -0
- package/src/lib/usage/scope.ts +182 -0
- package/src/lib/usage/source.ts +102 -0
- package/src/lib/usage/types.ts +143 -0
- package/src/lib/usage/window.ts +37 -0
- package/src/lib/workset/factory-local.ts +157 -0
- package/src/lib/workset/record.ts +25 -11
- package/src/lib/workset/repositories.ts +118 -25
- package/src/lib/workset/worktree-include.ts +161 -0
- package/src/lib/workset/worktree-index.ts +6 -2
- package/src/lib/workset/worktree.ts +591 -101
- package/src/opencode/companion-hooks.ts +46 -8
- package/src/opencode/companion-policy.ts +18 -5
- package/src/opencode/enter-worktree.ts +254 -6
- package/src/opencode/session-register.ts +2 -2
- package/src/runtime/claude-bg-isolation.ts +138 -0
- package/src/runtime/companion-git.ts +10 -2
- package/src/runtime/companion-guidance.ts +17 -4
- package/src/runtime/current-branch.ts +16 -2
- package/src/runtime/entered-worktree.ts +24 -0
- package/src/runtime/git-tracked.ts +60 -0
- package/src/runtime/repo-destination.ts +72 -0
- package/src/runtime/repo-local.ts +25 -3
- package/src/runtime/rtk-git-guard.ts +66 -0
- package/src/runtime/runtime-document-manifest.ts +229 -19
- package/src/runtime/runtime-document-manifest.typecheck.ts +10 -0
- package/src/runtime/secret-guard.ts +9 -2
- package/src/runtime/secret-policy-weakening.ts +122 -0
- package/src/runtime/serving-claude-wrap.ts +15 -2
- package/src/runtime/umbrella-folder.ts +56 -0
- package/src/runtime/wrap-state.ts +5 -13
- package/src/studio.ts +37 -0
- package/src/templates/mate-skills/agents/mate-apply-change/SKILL.md +61 -6
- package/src/templates/mate-skills/agents/mate-explore-change/SKILL.md +8 -4
- package/src/templates/mate-skills/agents/mate-propose-change/SKILL.md +9 -5
- package/src/templates/mate-skills/agents/mate-publish-artifact/SKILL.md +5 -4
- package/src/templates/mate-skills/agents/mate-show-me/SKILL.md +10 -4
- package/src/templates/mate-skills/agents/mate-simplify-code/SKILL.md +5 -1
- package/src/templates/mate-skills/claude/mate-apply-change/SKILL.md +61 -6
- package/src/templates/mate-skills/claude/mate-explore-change/SKILL.md +8 -4
- package/src/templates/mate-skills/claude/mate-propose-change/SKILL.md +9 -5
- package/src/templates/mate-skills/claude/mate-publish-artifact/SKILL.md +5 -4
- package/src/templates/mate-skills/claude/mate-show-me/SKILL.md +10 -4
- package/src/templates/mate-skills/claude/mate-simplify-code/SKILL.md +5 -1
- package/src/tools/setup/__snapshots__/runtime-surface-golden.test.ts.snap +307 -42
- package/src/tools/setup/capabilities/rtk.ts +93 -1
- package/src/tools/setup/dynamic-plugins/audiences.ts +65 -21
- package/src/tools/setup/dynamic-plugins/frozen.ts +32 -13
- package/src/tools/setup/dynamic-plugins/hydrate.ts +4 -4
- package/src/tools/setup/dynamic-plugins/install.ts +24 -22
- package/src/tools/setup/dynamic-plugins/loader.ts +11 -7
- package/src/tools/setup/dynamic-plugins/paths.ts +30 -10
- package/src/tools/setup/dynamic-plugins/verify.ts +10 -7
- package/src/tools/setup/dynamic-plugins/workspaces.ts +153 -0
- package/src/tools/setup/mate.ts +3 -3
- package/src/tools/setup/plugins/gitignore.ts +15 -9
- package/src/tools/setup/providers/claude-plugin-hooks.ts +12 -0
- package/src/tools/setup/providers/claude.ts +25 -3
- package/src/tools/setup/utils.ts +4 -2
- package/src/tools/setup/working-repo-cleanup.ts +2 -2
- package/src/tools/setup/working-repo-local-state.ts +2 -0
- package/src/tools/setup.ts +25 -14
- package/studio-dist/client/assets/app-D9cw6szy.css +2 -0
- package/studio-dist/client/assets/artifacts-WD2ZXYrx.js +1 -0
- package/studio-dist/client/assets/button-Br0O1sXw.js +1 -0
- package/studio-dist/client/assets/combobox-DA7RAUUZ.js +1 -0
- package/studio-dist/client/assets/companion-view-CrabvxS8.js +1 -0
- package/studio-dist/client/assets/factory-DGS0E16C.js +6 -0
- package/studio-dist/client/assets/fields-6aXBpFhJ.js +1 -0
- package/studio-dist/client/assets/getting-started-Clde4w6P.js +1 -0
- package/studio-dist/client/assets/getting-started-D6kgWwWZ.js +1 -0
- package/studio-dist/client/assets/getting-started._topic-BiunccbT.js +1 -0
- package/studio-dist/client/assets/getting-started.index-DpiNoGw8.js +1 -0
- package/studio-dist/client/assets/graph-B_TCBVbu.js +2 -0
- package/studio-dist/client/assets/graph-canvas-Ba37Y5AE.js +3242 -0
- package/studio-dist/client/assets/guides-Du_RtJxP.js +1 -0
- package/studio-dist/client/assets/index-Df8L1LQa.js +40 -0
- package/studio-dist/client/assets/jsx-runtime-MZURdZre.js +1 -0
- package/studio-dist/client/assets/markdown-view-BOX6x0rL.js +1 -0
- package/studio-dist/client/assets/panel-dbmCx7Mx.js +1 -0
- package/studio-dist/client/assets/queries-RvHeXY12.js +1 -0
- package/studio-dist/client/assets/react-3QStrcDO.js +27 -0
- package/studio-dist/client/assets/report-url-XRL0x1SY.js +1 -0
- package/studio-dist/client/assets/reports-r3IK7Doz.js +1 -0
- package/studio-dist/client/assets/routes-C0A5LTFc.js +1 -0
- package/studio-dist/client/assets/select-CnaMd617.js +1 -0
- package/studio-dist/client/assets/skills-CzjzHpBT.js +1 -0
- package/studio-dist/client/assets/specs-B0ldF_6J.js +1 -0
- package/studio-dist/client/assets/specs-view-BnCLA0gW.js +1 -0
- package/studio-dist/client/assets/spinner-Dcm3fqK1.js +1 -0
- package/studio-dist/client/assets/steps-C0p2N1Pb.js +1 -0
- package/studio-dist/client/assets/store-Dw34catY.js +1 -0
- package/studio-dist/client/assets/studio-Cpz_HRHp.js +100 -0
- package/studio-dist/client/assets/studio-queries-ibmpFo6R.js +2 -0
- package/studio-dist/client/assets/usage-C2QJ_0IZ.js +55 -0
- package/studio-dist/client/assets/useAnchoredPopupScrollLock-Bj-FWb8z.js +1 -0
- package/studio-dist/client/assets/useMutation-aAr2uiay.js +1 -0
- package/studio-dist/client/assets/useSelector-AYcH7lB0.js +2 -0
- package/studio-dist/client/assets/vault-BGcxkSIY.js +1 -0
- package/studio-dist/client/assets/warnings-R1cE1rLf.js +1 -0
- package/studio-dist/client/assets/workflow-C2qTrMDH.js +1 -0
- package/studio-dist/server/assets/__23tanstack-start-server-fn-resolver-Bn896ZYj.js +122 -0
- package/studio-dist/server/assets/_tanstack-start-manifest_v.js +102 -35
- package/studio-dist/server/assets/{actions-Bvgj9eb8.js → actions-DYSv-9VV.js} +10 -4
- package/studio-dist/server/assets/artifacts-DnF9L3dZ.js +216 -0
- package/studio-dist/server/assets/{button-CIJqAhni.js → button-CgOIVdmD.js} +13 -1702
- package/studio-dist/server/assets/combobox-DV_s9W0s.js +483 -0
- package/studio-dist/server/assets/{companion-view-DISASvdJ.js → companion-view-BKVXD3TO.js} +3 -3
- package/studio-dist/server/assets/companions-C7fctnU9.js +31 -0
- package/studio-dist/server/assets/{createServerRpc-tK2lE9R2.js → createServerRpc-bFKFpGFG.js} +1 -1
- package/studio-dist/server/assets/{factory-DUTa0eDs.js → factory-C7Ybg0xG.js} +1256 -353
- package/studio-dist/server/assets/{factory-DGPmNGbo.js → factory-Df5uAHjb.js} +53 -6
- package/studio-dist/server/assets/fields-BbieQTD0.js +1190 -0
- package/studio-dist/server/assets/getting-started-B136TP57.js +4 -0
- package/studio-dist/server/assets/getting-started-CRxMWorQ.js +67 -0
- package/studio-dist/server/assets/getting-started._topic-DJKQAzYl.js +13 -0
- package/studio-dist/server/assets/getting-started.index-D84gec1t.js +13 -0
- package/studio-dist/server/assets/graph-CSje3029.js +801 -0
- package/studio-dist/server/assets/graph-DDZzXM1L.js +16 -0
- package/studio-dist/server/assets/graph-canvas-22bWB5-2.js +21066 -0
- package/studio-dist/server/assets/graph-wire-BdSUx0G5.js +58 -0
- package/studio-dist/server/assets/guides-D9dk1Frq.js +13 -0
- package/studio-dist/server/assets/guides-IE-19POz.js +5 -0
- package/studio-dist/server/assets/guides.server-vcYRY5wx.js +66 -0
- package/studio-dist/server/assets/jsx-runtime-Bt0s0YKS.js +451 -0
- package/studio-dist/server/assets/{markdown-view-Bn7xPdks.js → markdown-view-BR8dJ7aR.js} +28 -9
- package/studio-dist/server/assets/{panel-3Jmn4awF.js → panel-BR_t9iMM.js} +4 -4
- package/studio-dist/server/assets/queries-DWoTin-q.js +32 -0
- package/studio-dist/server/assets/react-CdqSUhaL.js +89 -0
- package/studio-dist/server/assets/redirect-BaZ_QyqF.js +39 -0
- package/studio-dist/server/assets/report-url-BUXPcE_8.js +9 -0
- package/studio-dist/server/assets/{reports-D6YMqhnO.js → reports-CQ9qQ1-n.js} +9 -10
- package/studio-dist/server/assets/{reports-C06RXVE2.js → reports-dYDEoBeq.js} +3 -3
- package/studio-dist/server/assets/{router-C8MGqlAY.js → router-DkRHNTpE.js} +787 -2862
- package/studio-dist/server/assets/{routes-BcFgvqf7.js → routes-B6GfOew4.js} +22 -171
- package/studio-dist/server/assets/{search-JAKurDNh.js → search-BJnWLfkG.js} +21 -2
- package/studio-dist/server/assets/select-Af7Wibii.js +1609 -0
- package/studio-dist/server/assets/{shell-DS3wUexh.js → shell-Hq-hXgnT.js} +6 -5
- package/studio-dist/server/assets/{skills-BEnOxiDl.js → skills-B7nEuVbx.js} +9 -8
- package/studio-dist/server/assets/{skills-CtrBAtX3.js → skills-B_YYL7q8.js} +3 -3
- package/studio-dist/server/assets/specs-BpLUFntA.js +51 -0
- package/studio-dist/server/assets/specs-view-0peMVd22.js +426 -0
- package/studio-dist/server/assets/spinner-CdwJW4VB.js +20 -0
- package/studio-dist/server/assets/{steps-Dq_CwY_s.js → steps-D56DApvK.js} +1 -1
- package/studio-dist/server/assets/store-Cs17okNG.js +280 -0
- package/studio-dist/server/assets/studio-CAcKp3bM.js +10340 -0
- package/studio-dist/server/assets/studio-queries-BtRGzDdh.js +1451 -0
- package/studio-dist/server/assets/usage-COdjd1gD.js +25570 -0
- package/studio-dist/server/assets/usage-f6pqE1tm.js +24 -0
- package/studio-dist/server/assets/useAnchoredPopupScrollLock-DlBKHRw7.js +756 -0
- package/studio-dist/server/assets/useMutation-DzTZGenE.js +690 -0
- package/studio-dist/server/assets/{__23tanstack-start-server-fn-resolver-M2GBs8s3.js → useSelector-DUmCUXAs.js} +4 -668
- package/studio-dist/server/assets/{vault-Fvxt2Tzl.js → vault-BDuIUq0F.js} +8 -5
- package/studio-dist/server/assets/{vault-BmWnryh3.js → vault-BVLp6zu3.js} +3 -3
- package/studio-dist/server/assets/{views-BgYa-za2.js → views-flRUr21z.js} +4 -4
- package/studio-dist/server/assets/{warnings-DzR6fyZh.js → warnings-CDy9pdgL.js} +3 -2
- package/studio-dist/server/assets/{delivery-path-C29fBynY.js → workflow-D9GKI2EV.js} +132 -106
- package/studio-dist/server/server.js +582 -8
- package/src/cli/commands/report/collector.ts +0 -288
- package/studio-dist/client/assets/app-CdPiFv59.css +0 -2
- package/studio-dist/client/assets/button-BIIHE0EQ.js +0 -3
- package/studio-dist/client/assets/companion-view-DM6YyXaR.js +0 -1
- package/studio-dist/client/assets/delivery-path-DELxj0Av.js +0 -1
- package/studio-dist/client/assets/factory-BZy0E8ty.js +0 -4
- package/studio-dist/client/assets/index-B3wkMzjA.js +0 -40
- package/studio-dist/client/assets/markdown-view-pQ2Qp_i5.js +0 -1
- package/studio-dist/client/assets/panel-CbajlC3p.js +0 -1
- package/studio-dist/client/assets/prepaint-CwSrpdFA.js +0 -27
- package/studio-dist/client/assets/react-CN2GSx7x.js +0 -1
- package/studio-dist/client/assets/reports-DllhYQ5_.js +0 -1
- package/studio-dist/client/assets/rolldown-runtime-WkwZ5CU-.js +0 -1
- package/studio-dist/client/assets/routes-COm-G3mK.js +0 -1
- package/studio-dist/client/assets/skills-DmWAy-jZ.js +0 -1
- package/studio-dist/client/assets/specs-BG3Wi3ln.js +0 -1
- package/studio-dist/client/assets/steps-DFsH3Neu.js +0 -1
- package/studio-dist/client/assets/vault-B2q1nBY5.js +0 -1
- package/studio-dist/client/assets/warnings-BSXIyuSQ.js +0 -1
- package/studio-dist/client/assets/workflow-DlsQD6Hc.js +0 -1
- package/studio-dist/server/assets/companions-BYbHWKOZ.js +0 -15
- package/studio-dist/server/assets/createServerFn-F5sAOF8V.js +0 -459
- package/studio-dist/server/assets/prepaint-DJfTQ_VH.js +0 -45
- package/studio-dist/server/assets/react-Ce6dj15C.js +0 -46
- package/studio-dist/server/assets/rolldown-runtime-DYf_mQCB.js +0 -34
- package/studio-dist/server/assets/specs-C8rv34-5.js +0 -211
- package/studio-dist/server/assets/studio-BeltxxKt.js +0 -216
- 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 {
|
|
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
|
-
*
|
|
107
|
-
*
|
|
108
|
-
*
|
|
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
|
|
111
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
175
|
-
|
|
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)
|
|
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
|
|
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
|
-
|
|
122
|
+
workspaceRoot: string,
|
|
115
123
|
declarations: PluginDeclaration[],
|
|
116
124
|
deps: FrozenInstallDeps = {},
|
|
117
125
|
): Promise<PluginInstallResult[]> {
|
|
118
|
-
const
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
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 =
|
|
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 {
|
|
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
|
|
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
|
|
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
|
-
|
|
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
|
|
100
|
-
* `.mate/plugins
|
|
101
|
-
* → declared version, sorted by name) and diffs it against the
|
|
102
|
-
* current `package.json` plus each package's actual installed
|
|
103
|
-
* identical, fully-installed map with no moving-tag declaration
|
|
104
|
-
* `canary`) skips the install entirely
|
|
105
|
-
*
|
|
106
|
-
*
|
|
107
|
-
*
|
|
108
|
-
*
|
|
109
|
-
*
|
|
110
|
-
*
|
|
111
|
-
* own ambient npm config, or a
|
|
112
|
-
*
|
|
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
|
-
|
|
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(
|
|
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(
|
|
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
|
|
36
|
-
*
|
|
37
|
-
*
|
|
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 \`${
|
|
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(
|
|
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
|
-
/**
|
|
6
|
-
|
|
7
|
-
|
|
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
|
-
/**
|
|
11
|
-
export function
|
|
12
|
-
return path.join(
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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,
|
|
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
|
|
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
|
}
|