@uniqbit/mate-core 1.0.0-canary.8 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/claude-capability-plugins/companion-mentions/.claude-plugin/plugin.json +1 -1
- package/package.json +5 -4
- package/src/cli/commands/artifact/delivery/link.ts +1 -1
- package/src/cli/commands/artifact/delivery/output.ts +10 -1
- package/src/cli/commands/artifact/delivery/resolve.ts +3 -2
- package/src/cli/commands/artifact/delivery/submit.ts +9 -4
- package/src/cli/commands/artifact/delivery/take.ts +12 -9
- package/src/cli/commands/artifact/finish/command.ts +16 -14
- package/src/cli/commands/artifact/finish/engine.ts +8 -8
- package/src/cli/commands/artifact/project/command.ts +2 -3
- package/src/cli/commands/companion/hub.ts +11 -6
- package/src/cli/commands/companion/link.ts +173 -46
- package/src/cli/commands/doctor.ts +17 -0
- package/src/cli/commands/report/contract.ts +0 -17
- package/src/cli/commands/studio/access.ts +4 -0
- package/src/cli/commands/studio/actions.ts +35 -2
- package/src/cli/commands/studio/mcp-manager.ts +162 -0
- package/src/cli/commands/studio/routes.ts +12 -0
- package/src/cli/commands/studio/selection.ts +44 -11
- package/src/cli/commands/studio/server.ts +246 -2
- package/src/cli/commands/studio/services.ts +26 -0
- package/src/cli/commands/studio/terminal-launch.ts +21 -4
- package/src/cli/commands/studio/terminal.ts +3 -14
- package/src/cli/commands/studio/work-requests.ts +9 -0
- package/src/cli/commands/studio/work.ts +473 -0
- package/src/cli/commands/vscode/release-vsix.json +2 -2
- package/src/cli/commands/working/cleanup.ts +1 -18
- package/src/cli/companion-link-wizard.tsx +158 -91
- package/src/cli/usage.ts +1 -1
- package/src/create-mate.ts +4 -1
- package/src/lib/agent-credential.ts +131 -0
- package/src/lib/credential-kinds.ts +7 -0
- package/src/lib/delivery/merge-git.ts +16 -0
- package/src/lib/delivery/record-delivery.ts +12 -6
- package/src/lib/delivery/record.ts +5 -0
- package/src/lib/delivery/refresh.ts +34 -6
- package/src/lib/delivery/staging/refs.ts +9 -4
- package/src/lib/delivery/staging/submit.ts +81 -22
- package/src/lib/mcp-manager/resolve.ts +88 -0
- package/src/lib/mcp-manager/store.ts +133 -0
- package/src/lib/mcp-manager/types.ts +72 -0
- package/src/lib/mcp-manager/validate.ts +242 -0
- package/src/lib/opencode-server.ts +2 -17
- package/src/lib/orchestrator/config-store.ts +30 -7
- package/src/lib/orchestrator/engine-floor.ts +16 -4
- package/src/lib/orchestrator/engine-guard.ts +7 -1
- package/src/lib/orchestrator/repo-local-store.ts +14 -0
- package/src/lib/orchestrator/repository-link.ts +80 -52
- package/src/lib/orchestrator/root-context.ts +17 -1
- package/src/lib/orchestrator/types.ts +4 -0
- package/src/lib/studio-chat/agent.ts +139 -0
- package/src/lib/studio-chat/companion-context.ts +136 -0
- package/src/lib/studio-chat/credential.ts +79 -0
- package/src/lib/studio-chat/harness-chat-agent.ts +334 -0
- package/src/lib/studio-chat/host-sandbox.ts +578 -0
- package/src/lib/studio-chat/prepare-bridges.ts +95 -0
- package/src/lib/studio-chat/session.ts +15 -0
- package/src/lib/studio-chat/turns.ts +112 -0
- package/src/lib/workset/claims.ts +85 -0
- package/src/lib/workset/execution.ts +71 -0
- package/src/lib/workset/git-transaction.ts +74 -0
- package/src/lib/workset/groups.ts +176 -0
- package/src/lib/workset/inventory.ts +196 -0
- package/src/lib/workset/projection.ts +237 -0
- package/src/lib/workset/record.ts +101 -36
- package/src/lib/workset/repositories.ts +24 -0
- package/src/lib/workset/sharing.ts +951 -0
- package/src/lib/workset/stages.ts +50 -14
- package/src/lib/workset/transactions.ts +158 -0
- package/src/runtime/companion-git-state.ts +1 -0
- package/src/runtime/companion-guidance.ts +2 -2
- package/src/runtime/forge-remote.ts +6 -0
- package/src/runtime/host-process.ts +28 -0
- package/src/runtime/secret-guard.ts +18 -1
- package/src/runtime/secret-patterns.ts +4 -3
- package/src/runtime/submitted-arrivals.ts +28 -2
- package/src/runtime/workflow/turn.ts +14 -12
- package/src/runtime/write-atomic.ts +2 -2
- package/src/studio.ts +61 -0
- package/src/templates/capabilities/openspec-cap/mate-full/schema.yaml +1 -1
- package/src/templates/capabilities/openspec-cap/mate-full/templates/proposal.md +1 -1
- package/src/templates/mate-skills/agents/mate-publish-artifact/SKILL.md +3 -2
- package/src/templates/mate-skills/agents/mate-submit-change/SKILL.md +5 -3
- package/src/templates/mate-skills/claude/mate-publish-artifact/SKILL.md +3 -2
- package/src/templates/mate-skills/claude/mate-submit-change/SKILL.md +5 -3
- package/src/tools/setup/__snapshots__/runtime-surface-golden.test.ts.snap +12 -12
- package/src/tools/setup/capabilities/mcp-manager.ts +73 -0
- package/src/tools/setup/context-services.ts +35 -6
- package/src/tools/setup/dynamic-plugins/audiences.ts +3 -2
- package/src/tools/setup/dynamic-plugins/declarations.ts +0 -26
- package/src/tools/setup/engine.ts +55 -3
- package/src/tools/setup/plugin.ts +14 -0
- package/src/tools/setup/plugins/gitignore.ts +1 -0
- package/src/tools/setup/providers/claude-format.ts +40 -7
- package/src/tools/setup/providers/claude.ts +38 -3
- package/src/tools/setup/providers/opencode-format.ts +13 -3
- package/src/tools/setup/providers/opencode.ts +7 -18
- package/src/tools/setup/providers/relative-path-warnings.ts +26 -0
- package/studio-dist/THIRD-PARTY-NOTICES.md +297 -0
- package/studio-dist/client/THIRD-PARTY-LICENSES.md +4294 -0
- package/studio-dist/client/assets/DialogTitle-DOhjDa7H.js +1 -0
- package/studio-dist/client/assets/app-CG3vCgyA.css +2 -0
- package/studio-dist/client/assets/bundle-mjs-CdK3cBzO.js +1 -0
- package/studio-dist/client/assets/button-upSzkd-q.js +1 -0
- package/studio-dist/client/assets/chat-DbaMXb8H.js +157 -0
- package/studio-dist/client/assets/cn-BCnYnarL.js +1 -0
- package/studio-dist/client/assets/combobox-cP9OsRf2.js +1 -0
- package/studio-dist/client/assets/{companion-view-C_N237bf.js → companion-view-B54_Lj0S.js} +1 -1
- package/studio-dist/client/assets/fields-DNZ4a89M.js +1 -0
- package/studio-dist/client/assets/friction-DgEimeDB.js +1 -0
- package/studio-dist/client/assets/getting-started-BTfYCt5s.js +1 -0
- package/studio-dist/client/assets/{getting-started-djaQeWlu.js → getting-started-CAszmdDJ.js} +1 -1
- package/studio-dist/client/assets/getting-started._topic-CHJMf0pa.js +1 -0
- package/studio-dist/client/assets/getting-started.index-MR6HftWs.js +1 -0
- package/studio-dist/client/assets/{graph-canvas-ySGKMhmk.js → graph-canvas-BdNk2F9O.js} +1 -1
- package/studio-dist/client/assets/graph-hRijsC89.js +2 -0
- package/studio-dist/client/assets/guides-CwFnh08E.js +1 -0
- package/studio-dist/client/assets/highlighted-body-JLMTFACH-BcroQey-.js +1 -0
- package/studio-dist/client/assets/index-D5oGyvG8.js +41 -0
- package/studio-dist/client/assets/{markdown-view-jMiaBTSO.js → markdown-view-CJ8JsLb7.js} +1 -1
- package/studio-dist/client/assets/marked.esm-vFuq1cCd.js +65 -0
- package/studio-dist/client/assets/mcp-BE9M-bkO.js +4 -0
- package/studio-dist/client/assets/mermaid-WFAXDIZX-BjSsakrn.js +1 -0
- package/studio-dist/client/assets/panel-CDQ6Lryw.js +1 -0
- package/studio-dist/client/assets/plugins._service._view-DRVPUAWN.js +1 -0
- package/studio-dist/client/assets/{prepaint-CKsXyJOR.js → prepaint-sD_LlrDN.js} +1 -1
- package/studio-dist/client/assets/{queries-Dfp5deWj.js → queries-COL925ML.js} +1 -1
- package/studio-dist/client/assets/react-dom-K3Hp2Cdj.js +1 -0
- package/studio-dist/client/assets/{react-BYUSgtBs.js → react-h2xQ_NSp.js} +1 -1
- package/studio-dist/client/assets/reports-BClsojkb.js +1 -0
- package/studio-dist/client/assets/routes-CJQ2MAej.js +1 -0
- package/studio-dist/client/assets/search-DhWdEiKT.js +1 -0
- package/studio-dist/client/assets/select-B2FsN9FY.js +1 -0
- package/studio-dist/client/assets/skills-SoUHk77W.js +1 -0
- package/studio-dist/client/assets/{specs-BrCOjOch.js → specs-C_tZnAvF.js} +1 -1
- package/studio-dist/client/assets/specs-view-C6t3Y5IT.js +1 -0
- package/studio-dist/client/assets/steps-CF3-Zpmh.js +1 -0
- package/studio-dist/client/assets/{store-C3vJq8Wj.js → store-pY9gU4uS.js} +1 -1
- package/studio-dist/client/assets/studio-X7bnFrRe.js +36 -0
- package/studio-dist/client/assets/studio-queries-CKtAnIKP.js +2 -0
- package/studio-dist/client/assets/usage-BaaqUpTG.js +55 -0
- package/studio-dist/client/assets/useAnchoredPopupScrollLock-BspHR7Wt.js +1 -0
- package/studio-dist/client/assets/useBlocker-BQOfcu_f.js +1 -0
- package/studio-dist/client/assets/useMutation-DKeEoP5S.js +1 -0
- package/studio-dist/client/assets/useOpenInteractionType-CtaZCaFT.js +1 -0
- package/studio-dist/client/assets/usePopupHandleStore-Bc7Q4bnF.js +1 -0
- package/studio-dist/client/assets/vault-sAPFUnPN.js +1 -0
- package/studio-dist/client/assets/{warnings-CqOOGlPD.js → warnings-D7YY1HSG.js} +1 -1
- package/studio-dist/client/assets/work-BZek_LGB.js +5 -0
- package/studio-dist/client/assets/workflow-N5boHXFz.js +1 -0
- package/studio-dist/server/THIRD-PARTY-LICENSES.md +4371 -0
- package/studio-dist/server/assets/DialogTitle-DnKSl2V0.js +421 -0
- package/studio-dist/server/assets/{__23tanstack-start-server-fn-resolver-gVfW5vIV.js → __23tanstack-start-server-fn-resolver-Bli9bpSB.js} +38 -18
- package/studio-dist/server/assets/_tanstack-start-manifest_v.js +91 -59
- package/studio-dist/server/assets/{actions-D8erOphH.js → actions-CHEFA1i9.js} +33 -1
- package/studio-dist/server/assets/{cn-FXJAM0KO.js → bundle-mjs-Ot6dQ8Pq.js} +1 -2056
- package/studio-dist/server/assets/{button-D6bvrFmm.js → button-BqA1urbl.js} +14 -7
- package/studio-dist/server/assets/chat-zl332Tvu.js +49486 -0
- package/studio-dist/server/assets/cn-B0fl6NWK.js +2057 -0
- package/studio-dist/server/assets/{combobox-D2MbYV1O.js → combobox-iTjvPCtS.js} +7 -6
- package/studio-dist/server/assets/{companion-view-Mf1ANbMb.js → companion-view-DIQ6AFIY.js} +2 -2
- package/studio-dist/server/assets/{companions-Dr6IpNAb.js → companions-aVwjRL8j.js} +1 -1
- package/studio-dist/server/assets/{fields-B4mAPETz.js → fields-BMap2_Ju.js} +10 -3
- package/studio-dist/server/assets/{friction-CWOTjpCV.js → friction-BER50hoD.js} +2 -2
- package/studio-dist/server/assets/{friction-9a5S1m7U.js → friction-BPs9KWdq.js} +8 -8
- package/studio-dist/server/assets/{getting-started-RU6tYU2Q.js → getting-started-DGfRVmZ_.js} +2 -2
- package/studio-dist/server/assets/{getting-started._topic-C02HGrC6.js → getting-started._topic-BgrBA4Vj.js} +2 -2
- package/studio-dist/server/assets/{getting-started.index-EzLRosbb.js → getting-started.index-BaFfQ9Mn.js} +2 -2
- package/studio-dist/server/assets/{graph-CZ2H9Fzr.js → graph-Cgzlrv3P.js} +8 -8
- package/studio-dist/server/assets/{graph-B11ITte0.js → graph-DODpuOy_.js} +1 -1
- package/studio-dist/server/assets/{graph-canvas-rP5TT14Z.js → graph-canvas-DW_zU1nA.js} +2 -2
- package/studio-dist/server/assets/{guides-BGftp4wf.js → guides-CA_EMG7E.js} +1 -1
- package/studio-dist/server/assets/{guides-B8HdeK_C.js → guides-D0SpoD32.js} +1 -1
- package/studio-dist/server/assets/{guides.server-DqFQAStf.js → guides.server-DJjQuy03.js} +1 -1
- package/studio-dist/server/assets/highlighted-body-JLMTFACH-BeHllu-r.js +41 -0
- package/studio-dist/server/assets/{markdown-view-CArpV-CS.js → markdown-view-CvVBGMZV.js} +1 -1
- package/studio-dist/server/assets/mcp-BU0fLYyJ.js +1103 -0
- package/studio-dist/server/assets/mcp-manager-D9YctTQe.js +50 -0
- package/studio-dist/server/assets/mermaid-WFAXDIZX-B1yDN6vG.js +1 -0
- package/studio-dist/server/assets/{panel-DR0iq46J.js → panel-D1K6Bsux.js} +4 -32
- package/studio-dist/server/assets/{plugins._service._view-n7u2k5dF.js → plugins._service._view-DdO1nELF.js} +4 -4
- package/studio-dist/server/assets/{prepaint-B28ClcPN.js → prepaint-BB3dwSmz.js} +1 -1
- package/studio-dist/server/assets/{queries-D-yVP9i0.js → queries-BwiDxQy5.js} +1 -1
- package/studio-dist/server/assets/{react-CiBZPDs8.js → react-B2cLiz-i.js} +1 -1
- package/studio-dist/server/assets/{reports-C2SmTgqh.js → reports-9Pr7Bz6o.js} +7 -7
- package/studio-dist/server/assets/{reports-B9k98oE6.js → reports-Cc9M3phM.js} +1 -1
- package/studio-dist/server/assets/{router-CPt0TAk_.js → router-DcWe0J7Y.js} +827 -548
- package/studio-dist/server/assets/{routes-CwH8LEy2.js → routes-BEXxl0py.js} +8 -8
- package/studio-dist/server/assets/{search-b-yQesv3.js → search-bltT7gwy.js} +39 -7
- package/studio-dist/server/assets/{select-C3i6TTX-.js → select-CZvHgGCi.js} +7 -6
- package/studio-dist/server/assets/{shell-CagqZZMZ.js → shell-BQ0vMKXN.js} +13 -4
- package/studio-dist/server/assets/{skills-DGg0mWDM.js → skills-Be_52h0i.js} +1 -1
- package/studio-dist/server/assets/{skills-C21Mg_8-.js → skills-BpGGUl6L.js} +8 -8
- package/studio-dist/server/assets/{specs-DetoMiaB.js → specs-CCGgXE-V.js} +5 -5
- package/studio-dist/server/assets/{specs-view-CmbfLDwN.js → specs-view-DtL5JxYM.js} +12 -11
- package/studio-dist/server/assets/{steps-D1tYAyWZ.js → steps-BWFSO6dM.js} +1 -1
- package/studio-dist/server/assets/{store-aC-I6f6o.js → store-X7yLPp7v.js} +1 -1
- package/studio-dist/server/assets/{studio-queries-Dqf-3nzj.js → studio-queries-ur1ygXi3.js} +117 -13
- package/studio-dist/server/assets/{studio-qRvQjRpz.js → studio-qzH-UETC.js} +1555 -179
- package/studio-dist/server/assets/{usage-Cwle9-xY.js → usage-C1o0DLzS.js} +1 -1
- package/studio-dist/server/assets/{usage-CS4CBK9D.js → usage-DWbSPrPD.js} +10 -9
- package/studio-dist/server/assets/{useAnchoredPopupScrollLock-BjMNgXv9.js → useAnchoredPopupScrollLock-DLDmv6kM.js} +4 -135
- package/studio-dist/server/assets/useBlocker-CQtANHK8.js +111 -0
- package/studio-dist/server/assets/{useMutation-DpBIuWXt.js → useMutation-NjlA8oFY.js} +2 -2
- package/studio-dist/server/assets/useOpenInteractionType-CZYscfOb.js +136 -0
- package/studio-dist/server/assets/usePopupHandleStore-DEEXJYv0.js +26 -0
- package/studio-dist/server/assets/{vault-CEBBRLMb.js → vault-B_kfi1h-.js} +1 -1
- package/studio-dist/server/assets/{vault-DVQidlId.js → vault-dL79JlKH.js} +8 -115
- package/studio-dist/server/assets/{views-UgO0Qz_g.js → views-BSGH56lb.js} +3 -3
- package/studio-dist/server/assets/{warnings-C7hgXpdk.js → warnings-DtUVPV-k.js} +2 -2
- package/studio-dist/server/assets/work-D789VXGH.js +110 -0
- package/studio-dist/server/assets/work-DsCEfhmK.js +3817 -0
- package/studio-dist/server/assets/work-requests-BLhOmQFO.js +11 -0
- package/studio-dist/server/assets/{workflow-6dZZ1ofw.js → workflow-BOZ2sRYg.js} +9 -9
- package/studio-dist/server/server.js +3 -3
- package/wrappers/bin/openspec +87 -2
- package/studio-dist/client/assets/app-ggXJ_QVh.css +0 -2
- package/studio-dist/client/assets/button-amJ3g5oD.js +0 -1
- package/studio-dist/client/assets/cn-BQPKiwI4.js +0 -1
- package/studio-dist/client/assets/combobox-CJ7aGFid.js +0 -1
- package/studio-dist/client/assets/fields-BAiGkJ5N.js +0 -1
- package/studio-dist/client/assets/friction-DqOU59v7.js +0 -1
- package/studio-dist/client/assets/getting-started-yp42dj5S.js +0 -1
- package/studio-dist/client/assets/getting-started._topic-C9zVXz_m.js +0 -1
- package/studio-dist/client/assets/getting-started.index-DWbDKICP.js +0 -1
- package/studio-dist/client/assets/graph-BYaD_5Bq.js +0 -2
- package/studio-dist/client/assets/guides-D6T6W_jV.js +0 -1
- package/studio-dist/client/assets/index-Qx7reRPD.js +0 -40
- package/studio-dist/client/assets/panel-C4bf_h2W.js +0 -1
- package/studio-dist/client/assets/plugins._service._view-y6f2FDAB.js +0 -1
- package/studio-dist/client/assets/reports-JFSwSueq.js +0 -1
- package/studio-dist/client/assets/routes-BdOWSgzK.js +0 -1
- package/studio-dist/client/assets/search-CXosfvYh.js +0 -1
- package/studio-dist/client/assets/select-BHYYWPhK.js +0 -1
- package/studio-dist/client/assets/skills-Bo9FLsBd.js +0 -1
- package/studio-dist/client/assets/specs-view-CdE2rlli.js +0 -1
- package/studio-dist/client/assets/steps-CKUno4lh.js +0 -1
- package/studio-dist/client/assets/studio-0ueISxwP.js +0 -100
- package/studio-dist/client/assets/studio-queries-BflKt9va.js +0 -2
- package/studio-dist/client/assets/usage-BLsLy0nN.js +0 -55
- package/studio-dist/client/assets/useAnchoredPopupScrollLock-DC7f8GOp.js +0 -1
- package/studio-dist/client/assets/useMutation-uJUrejsi.js +0 -1
- package/studio-dist/client/assets/vault-BB1B_OhR.js +0 -1
- package/studio-dist/client/assets/workflow-BFzmI-06.js +0 -1
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
import { raisedEngineRange } from "../orchestrator/engine-floor";
|
|
2
|
+
import { ConfigError } from "../orchestrator/types";
|
|
3
|
+
import {
|
|
4
|
+
MCP_MANAGER_HEADER_PREFIXES,
|
|
5
|
+
MCP_MANAGER_TRANSPORTS,
|
|
6
|
+
type McpManagerConfig,
|
|
7
|
+
parseHeaderRef,
|
|
8
|
+
} from "./types";
|
|
9
|
+
|
|
10
|
+
/** First Mate release that reads `mcpManager`; the `engines.mate` floor a save sets. */
|
|
11
|
+
export const MCP_MANAGER_VERSION = "1.0.0-canary.9";
|
|
12
|
+
|
|
13
|
+
export const MCP_MANAGER_NAME_PATTERN = /^[a-z][a-z0-9-]{0,63}$/;
|
|
14
|
+
export const MCP_MANAGER_VARIABLE_PATTERN = /^[A-Z_][A-Z0-9_]*$/;
|
|
15
|
+
|
|
16
|
+
const HEADER_NAME_PATTERN = /^[A-Za-z0-9-]+$/;
|
|
17
|
+
|
|
18
|
+
const SECTION_KEYS = ["servers", "groups", "enabled"] as const;
|
|
19
|
+
const STDIO_KEYS = ["command", "args", "env"] as const;
|
|
20
|
+
const REMOTE_KEYS = ["url", "transport", "headers", "env"] as const;
|
|
21
|
+
const SELECTION_KEYS = ["servers", "groups"] as const;
|
|
22
|
+
const AUDIENCE_KEYS = ["enable", "disable"] as const;
|
|
23
|
+
|
|
24
|
+
export function isRecord(value: unknown): value is Record<string, unknown> {
|
|
25
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function fail(message: string): never {
|
|
29
|
+
throw new ConfigError(message);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function checkKeys(where: string, value: Record<string, unknown>, allowed: readonly string[]) {
|
|
33
|
+
for (const key of Object.keys(value)) {
|
|
34
|
+
if (!allowed.includes(key)) {
|
|
35
|
+
fail(`${where}: unknown key "${key}" (allowed: ${allowed.join(", ")}).`);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function validateEnv(where: string, env: unknown): void {
|
|
41
|
+
if (!Array.isArray(env)) {
|
|
42
|
+
fail(
|
|
43
|
+
`${where}: env lists variable names only, e.g. env: [ACME_TOKEN]; it is not a mapping of values.`,
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
env.forEach((entry, index) => {
|
|
47
|
+
if (typeof entry !== "string" || !MCP_MANAGER_VARIABLE_PATTERN.test(entry)) {
|
|
48
|
+
fail(
|
|
49
|
+
`${where}: env entry ${index + 1} is not a variable name (must match ${MCP_MANAGER_VARIABLE_PATTERN.source}); env lists names only, never values.`,
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function validateHeaders(where: string, headers: unknown): void {
|
|
56
|
+
if (!isRecord(headers)) fail(`${where}: headers must be a mapping of header name to reference.`);
|
|
57
|
+
for (const [header, value] of Object.entries(headers)) {
|
|
58
|
+
if (!HEADER_NAME_PATTERN.test(header))
|
|
59
|
+
fail(`${where}: header "${header}" is not a header name.`);
|
|
60
|
+
if (parseHeaderRef(value) === null) {
|
|
61
|
+
fail(
|
|
62
|
+
`${where}: header "${header}" must be an optional scheme prefix (${MCP_MANAGER_HEADER_PREFIXES.map((prefix) => prefix.trim()).join(", ")}) followed by exactly one \${NAME} reference; literal values are not allowed.`,
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** An absent list is empty. */
|
|
69
|
+
function validateStringList(where: string, value: unknown): string[] {
|
|
70
|
+
if (value === undefined) return [];
|
|
71
|
+
if (!Array.isArray(value) || !value.every((entry) => typeof entry === "string")) {
|
|
72
|
+
fail(`${where} must be a list of names.`);
|
|
73
|
+
}
|
|
74
|
+
return value;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function validateServer(name: string, server: unknown): void {
|
|
78
|
+
const where = `mcpManager.servers.${name}`;
|
|
79
|
+
if (!MCP_MANAGER_NAME_PATTERN.test(name)) {
|
|
80
|
+
fail(`Invalid MCP server name "${name}": must match ${MCP_MANAGER_NAME_PATTERN.source}.`);
|
|
81
|
+
}
|
|
82
|
+
if (!isRecord(server)) fail(`${where} must be a mapping.`);
|
|
83
|
+
const hasCommand = Object.hasOwn(server, "command");
|
|
84
|
+
const hasUrl = Object.hasOwn(server, "url");
|
|
85
|
+
if (hasCommand && hasUrl) {
|
|
86
|
+
fail(`${where} declares both "command" and "url"; a server has exactly one transport.`);
|
|
87
|
+
}
|
|
88
|
+
if (!hasCommand && !hasUrl) fail(`${where} needs either "command" or "url".`);
|
|
89
|
+
|
|
90
|
+
if (hasCommand) {
|
|
91
|
+
checkKeys(where, server, STDIO_KEYS);
|
|
92
|
+
if (typeof server.command !== "string" || server.command.trim() === "") {
|
|
93
|
+
fail(`${where}: command must be a non-empty string.`);
|
|
94
|
+
}
|
|
95
|
+
validateStringList(`${where}.args`, server.args);
|
|
96
|
+
} else {
|
|
97
|
+
checkKeys(where, server, REMOTE_KEYS);
|
|
98
|
+
if (typeof server.url !== "string" || !/^https?:\/\/\S+$/.test(server.url)) {
|
|
99
|
+
fail(`${where}: url must be an http or https URL.`);
|
|
100
|
+
}
|
|
101
|
+
if (
|
|
102
|
+
server.transport !== undefined &&
|
|
103
|
+
!MCP_MANAGER_TRANSPORTS.includes(server.transport as never)
|
|
104
|
+
) {
|
|
105
|
+
fail(`${where}: transport must be one of ${MCP_MANAGER_TRANSPORTS.join(", ")}.`);
|
|
106
|
+
}
|
|
107
|
+
if (server.headers !== undefined) validateHeaders(where, server.headers);
|
|
108
|
+
}
|
|
109
|
+
if (server.env !== undefined) validateEnv(where, server.env);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/** Server and group names a valid root section declares. */
|
|
113
|
+
interface Catalog {
|
|
114
|
+
servers: ReadonlySet<string>;
|
|
115
|
+
groups: ReadonlySet<string>;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/** An absent selection names nothing. */
|
|
119
|
+
function validateSelection(
|
|
120
|
+
where: string,
|
|
121
|
+
selection: unknown,
|
|
122
|
+
catalog: Catalog,
|
|
123
|
+
): { servers: string[]; groups: string[] } {
|
|
124
|
+
if (selection === undefined) return { servers: [], groups: [] };
|
|
125
|
+
if (!isRecord(selection)) fail(`${where} must be a mapping with servers and groups lists.`);
|
|
126
|
+
checkKeys(where, selection, SELECTION_KEYS);
|
|
127
|
+
const named = {
|
|
128
|
+
servers: validateStringList(`${where}.servers`, selection.servers),
|
|
129
|
+
groups: validateStringList(`${where}.groups`, selection.groups),
|
|
130
|
+
};
|
|
131
|
+
for (const server of named.servers) {
|
|
132
|
+
if (!catalog.servers.has(server)) fail(`${where}: unknown MCP server "${server}".`);
|
|
133
|
+
}
|
|
134
|
+
for (const group of named.groups) {
|
|
135
|
+
if (!catalog.groups.has(group)) fail(`${where}: unknown MCP server group "${group}".`);
|
|
136
|
+
}
|
|
137
|
+
return named;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
function catalogOf(section: unknown): Catalog {
|
|
141
|
+
return {
|
|
142
|
+
servers: new Set(
|
|
143
|
+
isRecord(section) && isRecord(section.servers) ? Object.keys(section.servers) : [],
|
|
144
|
+
),
|
|
145
|
+
groups: new Set(
|
|
146
|
+
isRecord(section) && isRecord(section.groups) ? Object.keys(section.groups) : [],
|
|
147
|
+
),
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/** Validates the root `mcpManager` section; error texts never repeat a configured value. */
|
|
152
|
+
export function validateMcpManagerSection(section: unknown): asserts section is McpManagerConfig {
|
|
153
|
+
if (!isRecord(section)) fail("mcpManager must be a mapping with servers, groups and enabled.");
|
|
154
|
+
checkKeys("mcpManager", section, SECTION_KEYS);
|
|
155
|
+
|
|
156
|
+
if (section.servers !== undefined) {
|
|
157
|
+
if (!isRecord(section.servers)) fail("mcpManager.servers must be a mapping of name to server.");
|
|
158
|
+
for (const [name, server] of Object.entries(section.servers)) validateServer(name, server);
|
|
159
|
+
}
|
|
160
|
+
const catalog = catalogOf(section);
|
|
161
|
+
|
|
162
|
+
if (section.groups !== undefined) {
|
|
163
|
+
if (!isRecord(section.groups)) fail("mcpManager.groups must be a mapping of name to servers.");
|
|
164
|
+
for (const [name, members] of Object.entries(section.groups)) {
|
|
165
|
+
if (!MCP_MANAGER_NAME_PATTERN.test(name)) {
|
|
166
|
+
fail(
|
|
167
|
+
`Invalid MCP server group name "${name}": must match ${MCP_MANAGER_NAME_PATTERN.source}.`,
|
|
168
|
+
);
|
|
169
|
+
}
|
|
170
|
+
if (catalog.servers.has(name)) {
|
|
171
|
+
fail(
|
|
172
|
+
`mcpManager: "${name}" names both a server and a group; servers and groups share one namespace.`,
|
|
173
|
+
);
|
|
174
|
+
}
|
|
175
|
+
for (const member of validateStringList(`mcpManager.groups.${name}`, members)) {
|
|
176
|
+
if (!catalog.servers.has(member)) {
|
|
177
|
+
fail(`mcpManager.groups.${name}: unknown MCP server "${member}".`);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
validateSelection("mcpManager.enabled", section.enabled, catalog);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* Validates `audiences.<audience>.mcpManager` against the root catalog
|
|
188
|
+
* (`undefined` when the companion declares none).
|
|
189
|
+
*/
|
|
190
|
+
export function validateAudienceMcpManager(
|
|
191
|
+
audience: string,
|
|
192
|
+
selection: unknown,
|
|
193
|
+
root: unknown,
|
|
194
|
+
): void {
|
|
195
|
+
const where = `audience "${audience}": mcpManager`;
|
|
196
|
+
if (!isRecord(selection)) fail(`${where} must be a mapping with enable and disable.`);
|
|
197
|
+
checkKeys(where, selection, AUDIENCE_KEYS);
|
|
198
|
+
const catalog = catalogOf(root);
|
|
199
|
+
const enable = validateSelection(`${where}.enable`, selection.enable, catalog);
|
|
200
|
+
const disable = validateSelection(`${where}.disable`, selection.disable, catalog);
|
|
201
|
+
for (const kind of ["servers", "groups"] as const) {
|
|
202
|
+
const disabled = new Set(disable[kind]);
|
|
203
|
+
const both = enable[kind].find((name) => disabled.has(name));
|
|
204
|
+
if (both !== undefined) {
|
|
205
|
+
fail(`${where}: "${both}" is both enabled and disabled under ${kind}; keep one.`);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/** True when `mcpManager` appears at the root or under any audience. */
|
|
211
|
+
export function declaresMcpManager(config: { mcpManager?: unknown; audiences?: unknown }): boolean {
|
|
212
|
+
if (config.mcpManager !== undefined) return true;
|
|
213
|
+
return (
|
|
214
|
+
isRecord(config.audiences) &&
|
|
215
|
+
Object.values(config.audiences).some(
|
|
216
|
+
(audience) => isRecord(audience) && audience.mcpManager !== undefined,
|
|
217
|
+
)
|
|
218
|
+
);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/** The `engines.mate` range a save must write when the config declares `mcpManager`, else null. */
|
|
222
|
+
export function mcpManagerEngineRange(config: {
|
|
223
|
+
mcpManager?: unknown;
|
|
224
|
+
audiences?: unknown;
|
|
225
|
+
engines?: unknown;
|
|
226
|
+
}): string | null {
|
|
227
|
+
return declaresMcpManager(config) ? raisedEngineRange(config.engines, MCP_MANAGER_VERSION) : null;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/** The root section and every audience selection of a parsed `framework.yaml`. */
|
|
231
|
+
export function validateMcpManagerConfig(config: {
|
|
232
|
+
mcpManager?: unknown;
|
|
233
|
+
audiences?: unknown;
|
|
234
|
+
}): void {
|
|
235
|
+
if (config.mcpManager !== undefined) validateMcpManagerSection(config.mcpManager);
|
|
236
|
+
if (!isRecord(config.audiences)) return;
|
|
237
|
+
for (const [name, audience] of Object.entries(config.audiences)) {
|
|
238
|
+
if (isRecord(audience) && audience.mcpManager !== undefined) {
|
|
239
|
+
validateAudienceMcpManager(name, audience.mcpManager, config.mcpManager);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
}
|
|
@@ -3,7 +3,6 @@ import { execFileSync, spawn } from "node:child_process";
|
|
|
3
3
|
import crypto from "node:crypto";
|
|
4
4
|
import fsSync from "node:fs";
|
|
5
5
|
import fs from "node:fs/promises";
|
|
6
|
-
import net from "node:net";
|
|
7
6
|
|
|
8
7
|
import {
|
|
9
8
|
activeSessions,
|
|
@@ -17,6 +16,7 @@ import {
|
|
|
17
16
|
readServerRecord,
|
|
18
17
|
serverFileBase,
|
|
19
18
|
} from "../runtime/opencode-server-record";
|
|
19
|
+
import { freeLoopbackPort } from "../runtime/host-process";
|
|
20
20
|
import { withLock } from "../runtime/session-registry";
|
|
21
21
|
import { writeAtomic } from "../runtime/write-atomic";
|
|
22
22
|
|
|
@@ -62,21 +62,6 @@ function startServe({ cwd, env, port, log }: Parameters<ServerDeps["start"]>[0])
|
|
|
62
62
|
}
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
-
function freePort(): Promise<number> {
|
|
66
|
-
return new Promise((resolve, reject) => {
|
|
67
|
-
const probe = net.createServer();
|
|
68
|
-
probe.once("error", reject);
|
|
69
|
-
probe.listen(0, "127.0.0.1", () => {
|
|
70
|
-
const address = probe.address();
|
|
71
|
-
probe.close(() =>
|
|
72
|
-
typeof address === "object" && address
|
|
73
|
-
? resolve(address.port)
|
|
74
|
-
: reject(new Error("no free port")),
|
|
75
|
-
);
|
|
76
|
-
});
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
|
|
80
65
|
function commandOf(pid: number): string | null {
|
|
81
66
|
try {
|
|
82
67
|
return execFileSync("ps", ["-p", String(pid), "-o", "command="], { encoding: "utf8" }).trim();
|
|
@@ -91,7 +76,7 @@ const isOpenCodeServe = (command: string | null) => /\bopencode\b.*\bserve\b/.te
|
|
|
91
76
|
export const defaultServerDeps: ServerDeps = {
|
|
92
77
|
dir: openCodeServersDir(),
|
|
93
78
|
start: startServe,
|
|
94
|
-
freePort,
|
|
79
|
+
freePort: freeLoopbackPort,
|
|
95
80
|
fetch,
|
|
96
81
|
alive: processAlive,
|
|
97
82
|
command: commandOf,
|
|
@@ -3,6 +3,7 @@ import path from "node:path";
|
|
|
3
3
|
import { normalizeBaseAudience } from "../../tools/setup/dynamic-plugins/audiences";
|
|
4
4
|
|
|
5
5
|
import { FRAMEWORK_NAME } from "../../framework";
|
|
6
|
+
import { mcpManagerEngineRange, validateMcpManagerConfig } from "../mcp-manager/validate";
|
|
6
7
|
import { declaredAllowedAgents } from "../../runtime/policy";
|
|
7
8
|
import {
|
|
8
9
|
getDefaultSetupSelections,
|
|
@@ -149,7 +150,7 @@ function validatePluginDeclarations(config: FrameworkConfig): void {
|
|
|
149
150
|
|
|
150
151
|
export const AUDIENCE_NAME_PATTERN = /^[a-z][a-z0-9-]{0,63}$/;
|
|
151
152
|
|
|
152
|
-
const AUDIENCE_KEYS = ["capabilities", "plugins", "studio"] as const;
|
|
153
|
+
const AUDIENCE_KEYS = ["capabilities", "plugins", "studio", "mcpManager"] as const;
|
|
153
154
|
|
|
154
155
|
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
155
156
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
@@ -225,6 +226,14 @@ function validateAudienceCapabilities(
|
|
|
225
226
|
}
|
|
226
227
|
}
|
|
227
228
|
|
|
229
|
+
/** Only companions declare MCP servers; audiences select from the root catalog. */
|
|
230
|
+
function validateMcpManager(config: FrameworkConfig): void {
|
|
231
|
+
if (config.type === "hub" && config.mcpManager !== undefined) {
|
|
232
|
+
throw new ConfigError('Only companions may declare mcpManager; a "hub" framework may not.');
|
|
233
|
+
}
|
|
234
|
+
validateMcpManagerConfig(config);
|
|
235
|
+
}
|
|
236
|
+
|
|
228
237
|
/**
|
|
229
238
|
* Validates the optional `audiences` mapping. Only companions may declare
|
|
230
239
|
* audiences; names are safe identifiers and keys form a closed set so typos
|
|
@@ -294,6 +303,18 @@ function validateAudiences(config: FrameworkConfig): void {
|
|
|
294
303
|
}
|
|
295
304
|
}
|
|
296
305
|
|
|
306
|
+
/** Parsed `framework.yaml` as loading sees it: normalized, migrated, defaulted and validated. */
|
|
307
|
+
export function parseFrameworkConfig(raw: unknown): FrameworkConfig {
|
|
308
|
+
const merged = mergeWithDefaults(
|
|
309
|
+
migrateProfilesToAllowedAgents(normalizeBaseAudience(raw as FrameworkConfig)),
|
|
310
|
+
);
|
|
311
|
+
validateHubConfig(merged);
|
|
312
|
+
validatePluginDeclarations(merged);
|
|
313
|
+
validateAudiences(merged);
|
|
314
|
+
validateMcpManager(merged);
|
|
315
|
+
return merged;
|
|
316
|
+
}
|
|
317
|
+
|
|
297
318
|
export class ConfigStore extends YamlFileStore<FrameworkConfig> {
|
|
298
319
|
constructor(configPath = process.env.MATE_CONFIG ?? defaultConfigPath()) {
|
|
299
320
|
super(path.resolve(configPath));
|
|
@@ -301,13 +322,15 @@ export class ConfigStore extends YamlFileStore<FrameworkConfig> {
|
|
|
301
322
|
|
|
302
323
|
/** Either file shape loads as the base set at the root; the next save writes the root shape. */
|
|
303
324
|
override async load(): Promise<FrameworkConfig> {
|
|
304
|
-
|
|
305
|
-
|
|
325
|
+
return parseFrameworkConfig(await super.load());
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
/** A save holding `mcpManager` raises `engines.mate`; canaries up to 1.0.0-canary.8 still pass it (pre-release fallback). */
|
|
329
|
+
override async save(data: FrameworkConfig): Promise<void> {
|
|
330
|
+
const raised = mcpManagerEngineRange(data);
|
|
331
|
+
await super.save(
|
|
332
|
+
raised === null ? data : { ...data, engines: { ...data.engines, [FRAMEWORK_NAME]: raised } },
|
|
306
333
|
);
|
|
307
|
-
validateHubConfig(merged);
|
|
308
|
-
validatePluginDeclarations(merged);
|
|
309
|
-
validateAudiences(merged);
|
|
310
|
-
return merged;
|
|
311
334
|
}
|
|
312
335
|
|
|
313
336
|
protected async onMissing(): Promise<FrameworkConfig> {
|
|
@@ -38,11 +38,23 @@ export async function writeEngineFloor(companionPath: string, range: string): Pr
|
|
|
38
38
|
*/
|
|
39
39
|
export async function raiseEngineFloor(companionPath: string, version: string): Promise<boolean> {
|
|
40
40
|
const raw = (await rawStore(companionPath).load()) ?? {};
|
|
41
|
-
const
|
|
41
|
+
const raised = raisedEngineRange(raw.engines, version);
|
|
42
|
+
return raised === null ? false : writeEngineFloor(companionPath, raised);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* The `engines.mate` range raised to `>=version`, or null when the current
|
|
47
|
+
* range already starts at or above it or does not parse.
|
|
48
|
+
*/
|
|
49
|
+
export function raisedEngineRange(engines: unknown, version: string): string | null {
|
|
50
|
+
const current =
|
|
51
|
+
typeof engines === "object" && engines !== null
|
|
52
|
+
? (engines as Record<string, unknown>)[FRAMEWORK_NAME]
|
|
53
|
+
: undefined;
|
|
42
54
|
if (typeof current === "string") {
|
|
43
|
-
if (semver.validRange(current) === null) return
|
|
55
|
+
if (semver.validRange(current) === null) return null;
|
|
44
56
|
const lowest = semver.minVersion(current);
|
|
45
|
-
if (lowest && semver.gte(lowest, version)) return
|
|
57
|
+
if (lowest && semver.gte(lowest, version)) return null;
|
|
46
58
|
}
|
|
47
|
-
return
|
|
59
|
+
return `>=${version}`;
|
|
48
60
|
}
|
|
@@ -28,8 +28,9 @@ export function checkEngineRequirement(
|
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
const current = semver.parse(currentVersion);
|
|
31
|
+
// A pre-release build counts as its release only against a release range; a pre-release floor must compare as-is.
|
|
31
32
|
const currentReleaseVersion =
|
|
32
|
-
current && current.prerelease.length > 0
|
|
33
|
+
current && current.prerelease.length > 0 && !namesPrerelease(range)
|
|
33
34
|
? `${current.major}.${current.minor}.${current.patch}`
|
|
34
35
|
: null;
|
|
35
36
|
const satisfied =
|
|
@@ -44,3 +45,8 @@ export function checkEngineRequirement(
|
|
|
44
45
|
}
|
|
45
46
|
return { ok: true };
|
|
46
47
|
}
|
|
48
|
+
|
|
49
|
+
// Reads the written text: parsed comparators carry generated tags (`^1.2.3` becomes `<2.0.0-0`).
|
|
50
|
+
function namesPrerelease(range: string): boolean {
|
|
51
|
+
return /\d+\.\d+\.\d+-[0-9A-Za-z]/.test(range);
|
|
52
|
+
}
|
|
@@ -94,3 +94,17 @@ export async function upsertRepoLocalCompanionPointer(
|
|
|
94
94
|
|
|
95
95
|
await saveRepoLocalRegistry(repoPath, registry);
|
|
96
96
|
}
|
|
97
|
+
|
|
98
|
+
/** Drops the pointer to `companionPath` from `repoPath`'s own registry; writes nothing when none matches. */
|
|
99
|
+
export async function removeRepoLocalCompanionPointer(
|
|
100
|
+
repoPath: string,
|
|
101
|
+
companionPath: string,
|
|
102
|
+
): Promise<void> {
|
|
103
|
+
const resolvedCompanionPath = path.resolve(companionPath);
|
|
104
|
+
const registry = await loadRepoLocalRegistry(repoPath);
|
|
105
|
+
const companions = registry.companions.filter(
|
|
106
|
+
(pointer) => path.resolve(pointer.path) !== resolvedCompanionPath,
|
|
107
|
+
);
|
|
108
|
+
if (companions.length === registry.companions.length) return;
|
|
109
|
+
await saveRepoLocalRegistry(repoPath, { ...registry, companions });
|
|
110
|
+
}
|
|
@@ -85,33 +85,19 @@ export class CompanionStore {
|
|
|
85
85
|
);
|
|
86
86
|
}
|
|
87
87
|
|
|
88
|
-
const
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
});
|
|
102
|
-
const reconciled = reconcileRegistry(working.repos, repository);
|
|
103
|
-
working.repos = reconciled.repos;
|
|
104
|
-
await this.companionRegistryStore.save(working);
|
|
105
|
-
return reconciled;
|
|
106
|
-
},
|
|
107
|
-
);
|
|
108
|
-
if (!locked.acquired) {
|
|
109
|
-
throw new ConfigError(
|
|
110
|
-
`another ${FRAMEWORK_NAME} process is still writing ${registryPath}; try again.`,
|
|
111
|
-
);
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
const { kept, merged } = locked.value;
|
|
88
|
+
const { kept, merged } = await this.withRegistryLock(async () => {
|
|
89
|
+
// A companion's registry.yaml may not exist yet (its first-ever link):
|
|
90
|
+
// that is not a real error here, unlike a working repo reading its own
|
|
91
|
+
// missing config, so fall back to an empty registry instead of throwing.
|
|
92
|
+
const working = await this.companionRegistryStore.load().catch((error) => {
|
|
93
|
+
if (error instanceof ConfigError) return CompanionRegistryStore.defaultConfig();
|
|
94
|
+
throw error;
|
|
95
|
+
});
|
|
96
|
+
const reconciled = reconcileRegistry(working.repos, repository);
|
|
97
|
+
working.repos = reconciled.repos;
|
|
98
|
+
await this.companionRegistryStore.save(working);
|
|
99
|
+
return reconciled;
|
|
100
|
+
});
|
|
115
101
|
const companionPath = path.resolve(this.companionPath);
|
|
116
102
|
const source = options.companionSource ?? "git";
|
|
117
103
|
// Repo-local registry write is a cache, not the source of truth: the
|
|
@@ -138,6 +124,41 @@ export class CompanionStore {
|
|
|
138
124
|
return kept;
|
|
139
125
|
}
|
|
140
126
|
|
|
127
|
+
/** Drops every entry whose path resolves to `repositoryPath`, under the registry's lock; a missing registry is left alone. */
|
|
128
|
+
async removeRepository(repositoryPath: string): Promise<void> {
|
|
129
|
+
const resolvedRepositoryPath = path.resolve(repositoryPath);
|
|
130
|
+
await this.withRegistryLock(async () => {
|
|
131
|
+
const working = await this.companionRegistryStore.load().catch((error) => {
|
|
132
|
+
if (error instanceof ConfigError) return null;
|
|
133
|
+
throw error;
|
|
134
|
+
});
|
|
135
|
+
if (!working) return;
|
|
136
|
+
const repos = working.repos.filter(
|
|
137
|
+
(repo) => path.resolve(repo.path) !== resolvedRepositoryPath,
|
|
138
|
+
);
|
|
139
|
+
if (repos.length === working.repos.length) return;
|
|
140
|
+
working.repos = repos;
|
|
141
|
+
await this.companionRegistryStore.save(working);
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
private async withRegistryLock<T>(update: () => Promise<T>): Promise<T> {
|
|
146
|
+
const registryPath = this.companionRegistryStore.configPath;
|
|
147
|
+
const locked = await withPathLock(
|
|
148
|
+
REGISTRY_LOCK_NAMESPACE,
|
|
149
|
+
/** Its real path, missing segments as written: a first link has no file yet. */
|
|
150
|
+
physicalPath(registryPath),
|
|
151
|
+
{},
|
|
152
|
+
update,
|
|
153
|
+
);
|
|
154
|
+
if (!locked.acquired) {
|
|
155
|
+
throw new ConfigError(
|
|
156
|
+
`another ${FRAMEWORK_NAME} process is still writing ${registryPath}; try again.`,
|
|
157
|
+
);
|
|
158
|
+
}
|
|
159
|
+
return locked.value;
|
|
160
|
+
}
|
|
161
|
+
|
|
141
162
|
async getRepository(repositoryId: string): Promise<LinkedRepository | undefined> {
|
|
142
163
|
const working = await this.companionRegistryStore.load();
|
|
143
164
|
return working.repos.find((r) => r.id === repositoryId);
|
|
@@ -287,6 +308,23 @@ interface ResolveOptions {
|
|
|
287
308
|
logFailures?: boolean;
|
|
288
309
|
/** `false` looks up without the self-heal or the stale-pointer prune, so a caller can refuse first. */
|
|
289
310
|
write?: boolean;
|
|
311
|
+
/** Only links recorded for `cwd` itself: none inherited from an ancestor folder or another Checkout of the clone. */
|
|
312
|
+
own?: boolean;
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
interface LinkRegistry {
|
|
316
|
+
companions: RepoLocalCompanionPointer[];
|
|
317
|
+
repository?: { path?: unknown };
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
/** A repo-local registry; null when unreadable or another shape, such as a companion's own `{ repos }`. */
|
|
321
|
+
async function readLinkRegistry(registryPath: string): Promise<LinkRegistry | null> {
|
|
322
|
+
try {
|
|
323
|
+
const parsed = parse(await fs.readFile(registryPath, "utf8")) as Partial<LinkRegistry> | null;
|
|
324
|
+
return parsed && Array.isArray(parsed.companions) ? (parsed as LinkRegistry) : null;
|
|
325
|
+
} catch {
|
|
326
|
+
return null;
|
|
327
|
+
}
|
|
290
328
|
}
|
|
291
329
|
|
|
292
330
|
/**
|
|
@@ -356,9 +394,10 @@ export class CompanionResolver {
|
|
|
356
394
|
* Another Checkout of the clone only: a subfolder of the entry's own
|
|
357
395
|
* folder matches nothing, as before, so `mate working cleanup` there sticks.
|
|
358
396
|
*/
|
|
359
|
-
const byClone =
|
|
360
|
-
|
|
361
|
-
|
|
397
|
+
const byClone =
|
|
398
|
+
clone && !options.own
|
|
399
|
+
? repos.find((r) => entryOfClone(r, clone) && physicalPath(r.path) !== checkoutRoot)
|
|
400
|
+
: undefined;
|
|
362
401
|
return byClone && checkoutRoot
|
|
363
402
|
? { companionPath, repositoryId: byClone.id, folder: checkoutRoot }
|
|
364
403
|
: null;
|
|
@@ -400,20 +439,14 @@ export class CompanionResolver {
|
|
|
400
439
|
options: ResolveOptions,
|
|
401
440
|
): Promise<CompanionResolutionResult | null> {
|
|
402
441
|
const found = await findRepoLocalRegistryFile(resolvedCwd);
|
|
403
|
-
if (!found) return null;
|
|
442
|
+
if (!found || (options.own && found.repoRoot !== resolvedCwd)) return null;
|
|
404
443
|
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
const named = parsed.repository?.path;
|
|
412
|
-
if (typeof named === "string" && namesOtherCheckout(found.repoRoot, named)) return null;
|
|
413
|
-
pointers = parsed.companions as RepoLocalCompanionPointer[];
|
|
414
|
-
} catch {
|
|
415
|
-
return null;
|
|
416
|
-
}
|
|
444
|
+
const registry = await readLinkRegistry(found.registryPath);
|
|
445
|
+
if (!registry) return null;
|
|
446
|
+
/** A cache copied from another Checkout of the clone is that Checkout's, not this one's. */
|
|
447
|
+
const named = registry.repository?.path;
|
|
448
|
+
if (typeof named === "string" && namesOtherCheckout(found.repoRoot, named)) return null;
|
|
449
|
+
const pointers = registry.companions;
|
|
417
450
|
|
|
418
451
|
if (pointers.length === 0) return null;
|
|
419
452
|
|
|
@@ -617,16 +650,11 @@ export async function findDescendantRepoLocalRegistries(rootPath: string): Promi
|
|
|
617
650
|
}
|
|
618
651
|
}
|
|
619
652
|
|
|
653
|
+
// A missing or unreadable registry, or a companion's own, is not a shadowed link.
|
|
620
654
|
const shadowedPaths = await Promise.all(
|
|
621
|
-
registryCandidates.map(async ({ registryPath, shadowedPath }) =>
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
return stats.isFile() ? shadowedPath : null;
|
|
625
|
-
} catch {
|
|
626
|
-
// A missing or unreadable registry is not a shadowed link.
|
|
627
|
-
return null;
|
|
628
|
-
}
|
|
629
|
-
}),
|
|
655
|
+
registryCandidates.map(async ({ registryPath, shadowedPath }) =>
|
|
656
|
+
(await readLinkRegistry(registryPath)) ? shadowedPath : null,
|
|
657
|
+
),
|
|
630
658
|
);
|
|
631
659
|
return shadowedPaths.filter((candidate): candidate is string => candidate !== null).toSorted();
|
|
632
660
|
}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import fs from "node:fs/promises";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
|
|
4
|
+
import { parse } from "yaml";
|
|
5
|
+
|
|
4
6
|
import { FRAMEWORK_NAME } from "../../framework";
|
|
5
7
|
import {
|
|
6
8
|
CompanionResolver,
|
|
@@ -42,10 +44,24 @@ const emptyResolution = (): CompanionResolutionResult => ({
|
|
|
42
44
|
failures: [],
|
|
43
45
|
});
|
|
44
46
|
|
|
45
|
-
function kindForConfig(config: FrameworkConfig): Exclude<RootKind, "core"> {
|
|
47
|
+
function kindForConfig(config: Pick<FrameworkConfig, "type">): Exclude<RootKind, "core"> {
|
|
46
48
|
return config.type === "hub" ? "hub" : config.type === "working" ? "working" : "companion";
|
|
47
49
|
}
|
|
48
50
|
|
|
51
|
+
/** The kind a folder's own `framework.yaml` names; null without one. A file that cannot be read or parsed counts as a companion's. */
|
|
52
|
+
export async function localRootKind(folder: string): Promise<Exclude<RootKind, "core"> | null> {
|
|
53
|
+
try {
|
|
54
|
+
const raw = await fs.readFile(
|
|
55
|
+
path.join(folder, `.${FRAMEWORK_NAME}`, "config", "framework.yaml"),
|
|
56
|
+
"utf8",
|
|
57
|
+
);
|
|
58
|
+
return kindForConfig((parse(raw) as Pick<FrameworkConfig, "type"> | null) ?? {});
|
|
59
|
+
} catch (error) {
|
|
60
|
+
const code = (error as NodeJS.ErrnoException).code;
|
|
61
|
+
return code === "ENOENT" || code === "ENOTDIR" ? null : "companion";
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
49
65
|
async function loadRootConfig(
|
|
50
66
|
rootPath: string,
|
|
51
67
|
write?: boolean,
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type { McpManagerAudienceSelection, McpManagerConfig } from "../mcp-manager/types";
|
|
2
|
+
|
|
1
3
|
class MateError extends Error {}
|
|
2
4
|
|
|
3
5
|
export class ConfigError extends MateError {}
|
|
@@ -147,6 +149,7 @@ export interface AudienceConfig {
|
|
|
147
149
|
capabilities?: CapabilityConfig[];
|
|
148
150
|
plugins?: PluginDeclaration[];
|
|
149
151
|
studio?: { terminal?: StudioTerminalConfig };
|
|
152
|
+
mcpManager?: McpManagerAudienceSelection;
|
|
150
153
|
}
|
|
151
154
|
|
|
152
155
|
export interface FrameworkConfig {
|
|
@@ -162,6 +165,7 @@ export interface FrameworkConfig {
|
|
|
162
165
|
engines?: EngineConstraints;
|
|
163
166
|
studio?: { terminal?: StudioTerminalConfig };
|
|
164
167
|
audiences?: Record<string, AudienceConfig>;
|
|
168
|
+
mcpManager?: McpManagerConfig;
|
|
165
169
|
}
|
|
166
170
|
|
|
167
171
|
export interface CompanionRegistryConfig {
|