@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
|
@@ -21,7 +21,9 @@ export type AnswerReason =
|
|
|
21
21
|
/** The repository has no checkout linked on this machine. */
|
|
22
22
|
| "no-checkout"
|
|
23
23
|
/** The branch is gone from the remote and its content is on no default-branch commit. */
|
|
24
|
-
| "branch-deleted"
|
|
24
|
+
| "branch-deleted"
|
|
25
|
+
/** The unpushed branch never moved from the default-branch commit it was created at. */
|
|
26
|
+
| "empty-branch";
|
|
25
27
|
|
|
26
28
|
export interface BranchOutcome {
|
|
27
29
|
repository: string;
|
|
@@ -172,6 +174,23 @@ async function unpushedHead(
|
|
|
172
174
|
return (await git.localTip(branch)) === head ? true : undefined;
|
|
173
175
|
}
|
|
174
176
|
|
|
177
|
+
async function hasNoCommitsOfItsOwn(
|
|
178
|
+
git: MergeGit,
|
|
179
|
+
branch: string,
|
|
180
|
+
head: string,
|
|
181
|
+
local: { tip: string | null; unpushed: boolean },
|
|
182
|
+
): Promise<boolean> {
|
|
183
|
+
if (local.tip !== head) return false;
|
|
184
|
+
if ((await git.neverAdvanced(branch, head)) !== true) return false;
|
|
185
|
+
return local.unpushed || (await unpushedHead(git, branch, head)) === true;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
function answerReasonOf(evidence: LocalMergeEvidence, deleted: boolean): AnswerReason {
|
|
189
|
+
if (evidence.empty) return "empty-branch";
|
|
190
|
+
if (evidence.suggestion) return "likely-merged";
|
|
191
|
+
return deleted ? "branch-deleted" : "not-on-default";
|
|
192
|
+
}
|
|
193
|
+
|
|
175
194
|
async function lookup(
|
|
176
195
|
repository: string,
|
|
177
196
|
branch: string,
|
|
@@ -226,16 +245,18 @@ async function lookup(
|
|
|
226
245
|
: {};
|
|
227
246
|
return { ...base, ...withFetch, ...found, result: "merged", needsAnswer: false, provenance };
|
|
228
247
|
}
|
|
229
|
-
const suggestion = evidence
|
|
248
|
+
const { suggestion } = evidence;
|
|
249
|
+
const neverPushed = fetch?.branchDeleted === true && (recorded.unpushed || unpushed === true);
|
|
250
|
+
const reportedFetch = neverPushed ? { fetch: { ok: true, branchUnpushed: true } } : withFetch;
|
|
230
251
|
// Without a fetch a missing `origin/<branch>` is no evidence of deletion.
|
|
231
|
-
const deleted = fetch?.branchDeleted === true && evidence.uncontained;
|
|
252
|
+
const deleted = fetch?.branchDeleted === true && !neverPushed && evidence.uncontained;
|
|
232
253
|
return {
|
|
233
254
|
...base,
|
|
234
|
-
...
|
|
255
|
+
...reportedFetch,
|
|
235
256
|
...found,
|
|
236
257
|
result: "unknown",
|
|
237
258
|
needsAnswer: true,
|
|
238
|
-
answerReason:
|
|
259
|
+
answerReason: answerReasonOf(evidence, deleted),
|
|
239
260
|
...(suggestion ? { suggestion } : {}),
|
|
240
261
|
fetchedAt,
|
|
241
262
|
};
|
|
@@ -297,6 +318,8 @@ export interface LocalMergeEvidence {
|
|
|
297
318
|
suggestion: PatchMatch | null;
|
|
298
319
|
/** Containment ran and found no default-branch commit holding the head. */
|
|
299
320
|
uncontained: boolean;
|
|
321
|
+
/** The unpushed head is on the default branch and its branch never moved from it. */
|
|
322
|
+
empty?: boolean;
|
|
300
323
|
}
|
|
301
324
|
|
|
302
325
|
/**
|
|
@@ -320,9 +343,10 @@ export async function localMergeEvidence(
|
|
|
320
343
|
? recordedHead
|
|
321
344
|
: null;
|
|
322
345
|
let head = live ?? recorded ?? known.fallback ?? null;
|
|
346
|
+
const localTip = head ? await git.localTip(branch) : null;
|
|
323
347
|
if (live) {
|
|
324
348
|
// Unpushed work: the remote tip alone would settle a merge of the branch's earlier commits.
|
|
325
|
-
for (const candidate of [
|
|
349
|
+
for (const candidate of [localTip, recorded]) {
|
|
326
350
|
// oxlint-disable-next-line no-await-in-loop -- the second candidate is compared to the first
|
|
327
351
|
if (candidate && (await git.aheadOf(head!, candidate))) head = candidate;
|
|
328
352
|
}
|
|
@@ -330,6 +354,10 @@ export async function localMergeEvidence(
|
|
|
330
354
|
const unsettled = { live, head, merged: false, uncontained: false };
|
|
331
355
|
if (!head) return { ...unsettled, suggestion: null };
|
|
332
356
|
if (await git.isAncestor(head, defaultBranch)) {
|
|
357
|
+
const local = { tip: localTip, unpushed: known.unpushed === true };
|
|
358
|
+
if (await hasNoCommitsOfItsOwn(git, branch, head, local)) {
|
|
359
|
+
return { ...unsettled, empty: true, suggestion: null };
|
|
360
|
+
}
|
|
333
361
|
// A fast-forward and a branch without commits of its own look the same: only a merge
|
|
334
362
|
// commit settles by itself, and a check Git could not run settles nothing.
|
|
335
363
|
if ((await git.onFirstParent(head, defaultBranch)) === false) {
|
|
@@ -126,12 +126,17 @@ export function pushPending(git: CompanionGit, remote: StagingRemote): Promise<N
|
|
|
126
126
|
}
|
|
127
127
|
|
|
128
128
|
/**
|
|
129
|
-
* A
|
|
130
|
-
*
|
|
129
|
+
* A lock failure counts only as the remote's rejection: locally it hits the tracking ref after
|
|
130
|
+
* an accepted push.
|
|
131
131
|
*/
|
|
132
132
|
export function isRejectedPush(result: NetworkGitResult): boolean {
|
|
133
|
-
return
|
|
134
|
-
|
|
133
|
+
return (
|
|
134
|
+
/\[rejected\]|non-fast-forward|fetch first|stale info|reference already exists/i.test(
|
|
135
|
+
result.stderr,
|
|
136
|
+
) ||
|
|
137
|
+
/\[remote rejected\][^\n]*\((cannot lock ref|failed to update ref|incorrect old value)/i.test(
|
|
138
|
+
result.stderr,
|
|
139
|
+
)
|
|
135
140
|
);
|
|
136
141
|
}
|
|
137
142
|
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { randomBytes } from "node:crypto";
|
|
1
2
|
import fs from "node:fs/promises";
|
|
2
3
|
import path from "node:path";
|
|
3
4
|
|
|
@@ -19,7 +20,14 @@ import {
|
|
|
19
20
|
import { errorMessage } from "../../../runtime/error-message";
|
|
20
21
|
import { isSubmittedName } from "../../../runtime/pending-records";
|
|
21
22
|
import { isWithin } from "../../../runtime/physical-path";
|
|
22
|
-
import {
|
|
23
|
+
import {
|
|
24
|
+
contentDigest,
|
|
25
|
+
emptyFolderKeepingClaim,
|
|
26
|
+
folderDigest,
|
|
27
|
+
OWNER_FILE,
|
|
28
|
+
ownFiles,
|
|
29
|
+
sharedDigestAt,
|
|
30
|
+
} from "../../../runtime/submitted-arrivals";
|
|
23
31
|
import type { PublicationSecretScan } from "../../../runtime/publication-secret-scan";
|
|
24
32
|
import type { SecretFinding } from "../../../runtime/secret-scan";
|
|
25
33
|
import {
|
|
@@ -28,6 +36,7 @@ import {
|
|
|
28
36
|
isCommitId,
|
|
29
37
|
readDeliveryRecord,
|
|
30
38
|
readOrUnlinkedRecord,
|
|
39
|
+
submissionStateOf,
|
|
31
40
|
upsertDelivery,
|
|
32
41
|
withoutStage,
|
|
33
42
|
writeDeliveryRecord,
|
|
@@ -497,12 +506,13 @@ async function pushGroup(
|
|
|
497
506
|
for (const [index, name] of names.entries()) {
|
|
498
507
|
const folder = sourcePathOf(type, name);
|
|
499
508
|
const files: [string, Buffer][] = [];
|
|
509
|
+
let claim: Buffer | null = null;
|
|
500
510
|
for (const file of listed[index]!) {
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
]);
|
|
511
|
+
const relative = path.posix.relative(folder, file);
|
|
512
|
+
// oxlint-disable-next-line no-await-in-loop -- one file at a time
|
|
513
|
+
const content = await readSubmittable(companionPath, folder, file);
|
|
514
|
+
if (relative === OWNER_FILE) claim = content;
|
|
515
|
+
else files.push([relative, content]);
|
|
506
516
|
}
|
|
507
517
|
// oxlint-disable-next-line no-await-in-loop -- one folder at a time
|
|
508
518
|
const theirs = await pendingContent(work, dir, folder);
|
|
@@ -517,7 +527,7 @@ async function pushGroup(
|
|
|
517
527
|
// A blocked change submitted again by name may accept its conflict, even unchanged.
|
|
518
528
|
if (unchanged && !blocked) continue;
|
|
519
529
|
const mine = submitted[folder]?.content;
|
|
520
|
-
const here = contentOnly(files);
|
|
530
|
+
const here = contentOnly(claim ? [...files, [OWNER_FILE, claim]] : files);
|
|
521
531
|
// Never submitted or taken here: only the same content may be pushed over it.
|
|
522
532
|
if (mine === undefined && theirs !== here) {
|
|
523
533
|
throw new Error(
|
|
@@ -555,7 +565,7 @@ async function pushGroup(
|
|
|
555
565
|
}
|
|
556
566
|
records.set(name, record);
|
|
557
567
|
// oxlint-disable-next-line no-await-in-loop -- one folder at a time
|
|
558
|
-
await
|
|
568
|
+
await emptyFolderKeepingClaim(within(dir, folder));
|
|
559
569
|
const copied: [string, Buffer][] = [];
|
|
560
570
|
for (const [relative, read] of files) {
|
|
561
571
|
const target = within(dir, `${folder}/${relative}`);
|
|
@@ -598,7 +608,11 @@ async function pushGroup(
|
|
|
598
608
|
[DELIVERY_FILE, written],
|
|
599
609
|
);
|
|
600
610
|
}
|
|
601
|
-
digests.set(name, {
|
|
611
|
+
digests.set(name, {
|
|
612
|
+
digest: contentDigest(claim ? [...copied, [OWNER_FILE, claim]] : copied),
|
|
613
|
+
// oxlint-disable-next-line no-await-in-loop -- one folder at a time
|
|
614
|
+
content: (await pendingContent(work, dir, folder)) ?? contentOnly(copied),
|
|
615
|
+
});
|
|
602
616
|
staged.push(folder);
|
|
603
617
|
}
|
|
604
618
|
return staged;
|
|
@@ -959,12 +973,6 @@ export interface TakeResult {
|
|
|
959
973
|
message: string;
|
|
960
974
|
}
|
|
961
975
|
|
|
962
|
-
/**
|
|
963
|
-
* Takes submitted change `name` into the checkout: writes its folder as the fetched pending
|
|
964
|
-
* branch has it, untracked, and records it as submitted from this checkout, so an edit is
|
|
965
|
-
* submitted again like one of the checkout's own and the folder gives way once its archive
|
|
966
|
-
* arrives. Refused while the checkout holds a folder of that name; nothing is pushed.
|
|
967
|
-
*/
|
|
968
976
|
export async function takeSubmitted(
|
|
969
977
|
companionPath: string,
|
|
970
978
|
name: string,
|
|
@@ -981,10 +989,15 @@ export async function takeSubmitted(
|
|
|
981
989
|
if (!isChangeName(name)) return refused("missing", `mate: "${name}" is no change name.`);
|
|
982
990
|
const relative = sourcePathOf(type, name);
|
|
983
991
|
const dir = sourceDir(companionPath, type, name);
|
|
984
|
-
if (await pathIsDirectory(dir)) {
|
|
985
|
-
return refused("exists", `mate: ${relative} is in this checkout already; nothing was taken.`);
|
|
986
|
-
}
|
|
987
992
|
const git = (deps.git ?? defaultGit)(companionPath);
|
|
993
|
+
const exists = await pathIsDirectory(dir);
|
|
994
|
+
const kept = exists ? await replaceRefusal(git, companionPath, relative, deps) : null;
|
|
995
|
+
if (kept) {
|
|
996
|
+
return refused(
|
|
997
|
+
"exists",
|
|
998
|
+
`mate: ${relative} is in this checkout already and ${kept}; nothing was taken.`,
|
|
999
|
+
);
|
|
1000
|
+
}
|
|
988
1001
|
const remote = await stagingRemote(git);
|
|
989
1002
|
if (!remote) return refused("no-remote", "mate: the companion has no upstream.");
|
|
990
1003
|
const fetched = await fetchPendingBranches(git, remote);
|
|
@@ -993,11 +1006,15 @@ export async function takeSubmitted(
|
|
|
993
1006
|
const tip = (
|
|
994
1007
|
await git.run(["rev-parse", "--verify", "-q", `${pendingRef(remote)}^{commit}`])
|
|
995
1008
|
).stdout.trim();
|
|
996
|
-
const
|
|
1009
|
+
const held =
|
|
1010
|
+
isCommitId(tip) &&
|
|
1011
|
+
(await git.run(["cat-file", "-e", "--end-of-options", `${tip}:${relative}`])).status === 0;
|
|
1012
|
+
const record = held
|
|
997
1013
|
? await git.run(["show", "--end-of-options", `${tip}:${relative}/${DELIVERY_FILE}`])
|
|
998
1014
|
: null;
|
|
999
|
-
|
|
1000
|
-
|
|
1015
|
+
const state = submissionStateOf(record?.status === 0 ? record.stdout : null);
|
|
1016
|
+
if (!held || state === "dropped") {
|
|
1017
|
+
return refused("missing", `mate: ${name} is not on ${pendingPlace(remote)}.`);
|
|
1001
1018
|
}
|
|
1002
1019
|
// Anyone may push the inbox: a link there must not reach the checkout, where it is followed.
|
|
1003
1020
|
const linked = await linkedContentPaths(git, tip, [relative]);
|
|
@@ -1009,6 +1026,14 @@ export async function takeSubmitted(
|
|
|
1009
1026
|
: `mate: ${pendingPlace(remote)} holds a symbolic link or submodule at ${linked.join(", ")}; Mate does not take it.`,
|
|
1010
1027
|
);
|
|
1011
1028
|
}
|
|
1029
|
+
let backup: string | null = null;
|
|
1030
|
+
if (exists) {
|
|
1031
|
+
if (await replaceRefusal(git, companionPath, relative, deps)) {
|
|
1032
|
+
return refused("exists", `mate: ${relative} changed while taking it; nothing was taken.`);
|
|
1033
|
+
}
|
|
1034
|
+
backup = path.join(path.dirname(dir), `.${name}.take-${randomBytes(4).toString("hex")}`);
|
|
1035
|
+
await fs.rename(dir, backup);
|
|
1036
|
+
}
|
|
1012
1037
|
// The work tree only: the index stays as it is, so the folder is untracked like a submitted one.
|
|
1013
1038
|
const written = await git.run([
|
|
1014
1039
|
...LITERAL_PATHSPECS,
|
|
@@ -1021,11 +1046,13 @@ export async function takeSubmitted(
|
|
|
1021
1046
|
const files = written.status === 0 ? await ownFiles(git, companionPath, relative) : null;
|
|
1022
1047
|
if (!files || files.length === 0) {
|
|
1023
1048
|
await fs.rm(dir, { recursive: true, force: true });
|
|
1049
|
+
if (backup) await fs.rename(backup, dir);
|
|
1024
1050
|
return refused(
|
|
1025
1051
|
"failed",
|
|
1026
1052
|
`mate: writing ${relative} failed; nothing was taken. ${describeGitFailure(written)}`,
|
|
1027
1053
|
);
|
|
1028
1054
|
}
|
|
1055
|
+
if (backup) await fs.rm(backup, { recursive: true, force: true });
|
|
1029
1056
|
updateSubmittedFolders(
|
|
1030
1057
|
companionPath,
|
|
1031
1058
|
{
|
|
@@ -1035,16 +1062,48 @@ export async function takeSubmitted(
|
|
|
1035
1062
|
dir,
|
|
1036
1063
|
files.filter((file) => file !== DELIVERY_FILE),
|
|
1037
1064
|
),
|
|
1065
|
+
shared: await sharedDigestAt(git, tip, relative),
|
|
1038
1066
|
submittedAt: (deps.now?.() ?? new Date()).toISOString(),
|
|
1039
1067
|
},
|
|
1040
1068
|
},
|
|
1041
1069
|
[],
|
|
1042
1070
|
deps.stateHome,
|
|
1043
1071
|
);
|
|
1072
|
+
const next =
|
|
1073
|
+
state === "submitted"
|
|
1074
|
+
? `Edit it, then submit it again with \`mate artifact submit ${name}\`.`
|
|
1075
|
+
: `Continue it, then submit it with \`mate artifact submit ${name}\` once it is done.`;
|
|
1044
1076
|
return {
|
|
1045
1077
|
change: name,
|
|
1046
1078
|
status: "taken",
|
|
1047
1079
|
path: relative,
|
|
1048
|
-
message: `Took ${name} into ${relative} as ${pendingPlace(remote)} has it.
|
|
1080
|
+
message: `Took ${name} into ${relative} as ${pendingPlace(remote)} has it. ${next}`,
|
|
1049
1081
|
};
|
|
1050
1082
|
}
|
|
1083
|
+
|
|
1084
|
+
/** Why a take must not replace the folder `relative`; null when a take loses nothing. */
|
|
1085
|
+
async function replaceRefusal(
|
|
1086
|
+
git: CompanionGit,
|
|
1087
|
+
companionPath: string,
|
|
1088
|
+
relative: string,
|
|
1089
|
+
deps: Pick<SubmitDeps, "stateHome">,
|
|
1090
|
+
): Promise<string | null> {
|
|
1091
|
+
const recorded = readSubmittedFolders(companionPath, deps.stateHome)[relative];
|
|
1092
|
+
const files = recorded ? await ownFiles(git, companionPath, relative) : null;
|
|
1093
|
+
const dir = path.join(companionPath, ...relative.split("/"));
|
|
1094
|
+
if (!recorded || !files || (await folderDigest(dir, files)) !== recorded.digest) {
|
|
1095
|
+
return "changed since this checkout last pushed or took it";
|
|
1096
|
+
}
|
|
1097
|
+
const known = new Set(
|
|
1098
|
+
files.flatMap((file) => {
|
|
1099
|
+
const parts = file.split("/");
|
|
1100
|
+
return parts.map((_, index) => parts.slice(0, index + 1).join("/"));
|
|
1101
|
+
}),
|
|
1102
|
+
);
|
|
1103
|
+
const stray = (await fs.readdir(dir, { recursive: true }))
|
|
1104
|
+
.map((entry) => entry.split(path.sep).join("/"))
|
|
1105
|
+
.find((entry) => !known.has(entry));
|
|
1106
|
+
return stray === undefined
|
|
1107
|
+
? null
|
|
1108
|
+
: `holds ${stray}, which Git ignores or Mate does not take, and a take would delete it`;
|
|
1109
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { audienceEntry, normalizeBaseAudience } from "../../tools/setup/dynamic-plugins/audiences";
|
|
2
|
+
import {
|
|
3
|
+
type McpManagerAudienceSelection,
|
|
4
|
+
type McpManagerConfig,
|
|
5
|
+
type McpManagerSelection,
|
|
6
|
+
parseHeaderRef,
|
|
7
|
+
type ResolvedMcpServer,
|
|
8
|
+
} from "./types";
|
|
9
|
+
import { isRecord } from "./validate";
|
|
10
|
+
|
|
11
|
+
function members(section: McpManagerConfig, groups: string[] | undefined): string[] {
|
|
12
|
+
return (groups ?? []).flatMap((group) => section.groups?.[group] ?? []);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function audienceSelection(raw: unknown, audience: string | null): McpManagerAudienceSelection {
|
|
16
|
+
const entry = audienceEntry(raw, audience);
|
|
17
|
+
return isRecord(entry) && isRecord(entry.mcpManager)
|
|
18
|
+
? (entry.mcpManager as McpManagerAudienceSelection)
|
|
19
|
+
: {};
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** A variable an effective server needs that the environment leaves unset or empty. */
|
|
23
|
+
export interface MissingMcpVariable {
|
|
24
|
+
server: string;
|
|
25
|
+
variable: string;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** Variables a server reads: its `env` names and the one each header references. */
|
|
29
|
+
export function serverVariables(server: ResolvedMcpServer["server"]): string[] {
|
|
30
|
+
const headers = "headers" in server ? Object.values(server.headers ?? {}) : [];
|
|
31
|
+
const fromHeaders = headers.flatMap((value) => parseHeaderRef(value)?.variable ?? []);
|
|
32
|
+
return [...new Set([...(server.env ?? []), ...fromHeaders])];
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** Unset and empty both count as missing. Checks presence only; a value never leaves `env`. */
|
|
36
|
+
export function isVariableSet(env: Record<string, string | undefined>, variable: string): boolean {
|
|
37
|
+
return Boolean(env[variable]);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function missingMcpVariables(
|
|
41
|
+
raw: unknown,
|
|
42
|
+
audience: string | null,
|
|
43
|
+
env: Record<string, string | undefined>,
|
|
44
|
+
): MissingMcpVariable[] {
|
|
45
|
+
return resolveMcpServers(raw, audience).flatMap(({ name, server }) =>
|
|
46
|
+
serverVariables(server)
|
|
47
|
+
.filter((variable) => !isVariableSet(env, variable))
|
|
48
|
+
.map((variable) => ({ server: name, variable })),
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* The effective servers of an already validated `framework.yaml` for
|
|
54
|
+
* `audience`, ordered by name. Group decisions apply before server decisions,
|
|
55
|
+
* so a named server beats a group; `null`, `base` or an undeclared audience
|
|
56
|
+
* gives the base set.
|
|
57
|
+
*/
|
|
58
|
+
export function resolveMcpServers(raw: unknown, audience: string | null): ResolvedMcpServer[] {
|
|
59
|
+
const normalized = normalizeBaseAudience(raw);
|
|
60
|
+
if (!isRecord(normalized) || !isRecord(normalized.mcpManager)) return [];
|
|
61
|
+
const section = normalized.mcpManager as McpManagerConfig;
|
|
62
|
+
const base: McpManagerSelection = section.enabled ?? {};
|
|
63
|
+
const { enable = {}, disable = {} } = audienceSelection(normalized, audience);
|
|
64
|
+
|
|
65
|
+
const names = new Set([...(base.servers ?? []), ...members(section, base.groups)]);
|
|
66
|
+
for (const name of members(section, enable.groups)) names.add(name);
|
|
67
|
+
for (const name of members(section, disable.groups)) names.delete(name);
|
|
68
|
+
for (const name of enable.servers ?? []) names.add(name);
|
|
69
|
+
for (const name of disable.servers ?? []) names.delete(name);
|
|
70
|
+
|
|
71
|
+
return [...names]
|
|
72
|
+
.filter((name) => section.servers?.[name] !== undefined)
|
|
73
|
+
.toSorted()
|
|
74
|
+
.map((name) => ({ name, server: section.servers![name] }));
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** Effective server names for the base set and for each of `audiences`. */
|
|
78
|
+
export function effectiveSets(
|
|
79
|
+
raw: unknown,
|
|
80
|
+
audiences: readonly string[],
|
|
81
|
+
): { base: string[]; audiences: Record<string, string[]> } {
|
|
82
|
+
const names = (audience: string | null) =>
|
|
83
|
+
resolveMcpServers(raw, audience).map((server) => server.name);
|
|
84
|
+
return {
|
|
85
|
+
base: names(null),
|
|
86
|
+
audiences: Object.fromEntries(audiences.map((audience) => [audience, names(audience)])),
|
|
87
|
+
};
|
|
88
|
+
}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import crypto from "node:crypto";
|
|
2
|
+
import fs from "node:fs/promises";
|
|
3
|
+
import { isDeepStrictEqual } from "node:util";
|
|
4
|
+
|
|
5
|
+
import { type Document, isCollection, isMap, isNode, isScalar, parseDocument } from "yaml";
|
|
6
|
+
|
|
7
|
+
import { FRAMEWORK_NAME } from "../../framework";
|
|
8
|
+
import { companionFrameworkConfigPath } from "../../runtime/policy";
|
|
9
|
+
import { writeAtomic } from "../../runtime/write-atomic";
|
|
10
|
+
import { BASE_AUDIENCE, declaredAudiences } from "../../tools/setup/dynamic-plugins/audiences";
|
|
11
|
+
import { parseFrameworkConfig } from "../orchestrator/config-store";
|
|
12
|
+
import { ConfigError, type FrameworkConfig } from "../orchestrator/types";
|
|
13
|
+
import { effectiveSets } from "./resolve";
|
|
14
|
+
import type { McpManagerAudienceSelection, McpManagerConfig } from "./types";
|
|
15
|
+
import { mcpManagerEngineRange } from "./validate";
|
|
16
|
+
|
|
17
|
+
/** `framework.yaml` changed after the read whose token a write carries. */
|
|
18
|
+
export class McpManagerConflictError extends Error {
|
|
19
|
+
constructor() {
|
|
20
|
+
super("framework.yaml changed since it was read; read it again and reapply the change.");
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface McpManagerSnapshot {
|
|
25
|
+
/** The root section; null when the companion declares none. */
|
|
26
|
+
catalog: McpManagerConfig | null;
|
|
27
|
+
/** Each declared audience's selection; `{}` when it selects nothing. */
|
|
28
|
+
audiences: Record<string, McpManagerAudienceSelection>;
|
|
29
|
+
/** Effective server names for the base set and per declared audience. */
|
|
30
|
+
effective: { base: string[]; audiences: Record<string, string[]> };
|
|
31
|
+
/** Content hash of `framework.yaml`, the concurrency token a write carries. */
|
|
32
|
+
token: string;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* A change to the section. `catalog: null` removes the root section; an
|
|
37
|
+
* audience mapped to null loses its selection. Absent keys stay unchanged.
|
|
38
|
+
*/
|
|
39
|
+
export interface McpManagerPatch {
|
|
40
|
+
catalog?: McpManagerConfig | null;
|
|
41
|
+
audiences?: Record<string, McpManagerAudienceSelection | null>;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function tokenOf(text: string): string {
|
|
45
|
+
return crypto.createHash("sha256").update(text).digest("hex");
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function snapshotOf(config: FrameworkConfig, token: string): McpManagerSnapshot {
|
|
49
|
+
const names = declaredAudiences(config);
|
|
50
|
+
return {
|
|
51
|
+
catalog: config.mcpManager ?? null,
|
|
52
|
+
audiences: Object.fromEntries(
|
|
53
|
+
names.map((name) => [name, config.audiences?.[name]?.mcpManager ?? {}]),
|
|
54
|
+
),
|
|
55
|
+
effective: effectiveSets(config, names),
|
|
56
|
+
token,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const isPlainObject = (value: unknown): value is Record<string, unknown> =>
|
|
61
|
+
typeof value === "object" && value !== null && !Array.isArray(value);
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Sets `value` at `path`, rewriting only the entries that differ, so untouched
|
|
65
|
+
* entries keep their comments and flow or block style.
|
|
66
|
+
*/
|
|
67
|
+
function mergeIn(document: Document, path: readonly string[], value: unknown): void {
|
|
68
|
+
const held: unknown = document.getIn(path, true);
|
|
69
|
+
if (isNode(held) && isDeepStrictEqual(held.toJS(document), value)) return;
|
|
70
|
+
if (isMap(held) && isPlainObject(value)) {
|
|
71
|
+
const removed = held.items.filter(
|
|
72
|
+
({ key }) => !Object.hasOwn(value, String(isScalar(key) ? key.value : key)),
|
|
73
|
+
);
|
|
74
|
+
for (const { key } of removed) held.delete(key);
|
|
75
|
+
for (const [key, child] of Object.entries(value)) mergeIn(document, [...path, key], child);
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
const node = document.createNode(value);
|
|
79
|
+
if (isCollection(held) && isCollection(node)) node.flow = held.flow;
|
|
80
|
+
if (isNode(held)) {
|
|
81
|
+
node.commentBefore = held.commentBefore;
|
|
82
|
+
node.comment = held.comment;
|
|
83
|
+
}
|
|
84
|
+
document.setIn(path, node);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
async function readText(companionPath: string): Promise<string> {
|
|
88
|
+
return fs.readFile(companionFrameworkConfigPath(companionPath), "utf8");
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** The catalog, audience selections and effective sets, validated as loading validates them. */
|
|
92
|
+
export async function readMcpManager(companionPath: string): Promise<McpManagerSnapshot> {
|
|
93
|
+
const text = await readText(companionPath);
|
|
94
|
+
return snapshotOf(parseFrameworkConfig(parseDocument(text).toJS()), tokenOf(text));
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Applies `patch` to `framework.yaml`, keeping comments, key order and every
|
|
99
|
+
* other key. Fails with {@link McpManagerConflictError} when the file changed
|
|
100
|
+
* since `token`'s read, and with the loader's error when the result is
|
|
101
|
+
* invalid; either way the file is left unchanged.
|
|
102
|
+
*/
|
|
103
|
+
export async function writeMcpManager(
|
|
104
|
+
companionPath: string,
|
|
105
|
+
patch: McpManagerPatch,
|
|
106
|
+
token: string,
|
|
107
|
+
): Promise<McpManagerSnapshot> {
|
|
108
|
+
const text = await readText(companionPath);
|
|
109
|
+
if (tokenOf(text) !== token) throw new McpManagerConflictError();
|
|
110
|
+
|
|
111
|
+
const document = parseDocument(text);
|
|
112
|
+
if (patch.catalog === null) document.delete("mcpManager");
|
|
113
|
+
else if (patch.catalog !== undefined) mergeIn(document, ["mcpManager"], patch.catalog);
|
|
114
|
+
for (const [audience, selection] of Object.entries(patch.audiences ?? {})) {
|
|
115
|
+
if (audience === BASE_AUDIENCE) {
|
|
116
|
+
throw new ConfigError(
|
|
117
|
+
`"${BASE_AUDIENCE}" is the base set; write its servers to the catalog.`,
|
|
118
|
+
);
|
|
119
|
+
}
|
|
120
|
+
if (selection === null) document.deleteIn(["audiences", audience, "mcpManager"]);
|
|
121
|
+
else mergeIn(document, ["audiences", audience, "mcpManager"], selection);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
const raw = document.toJS() as Record<string, unknown>;
|
|
125
|
+
const config = parseFrameworkConfig(raw);
|
|
126
|
+
const raised = mcpManagerEngineRange(raw);
|
|
127
|
+
if (raised !== null) document.setIn(["engines", FRAMEWORK_NAME], raised);
|
|
128
|
+
|
|
129
|
+
// No folding, so a long flow entry the save left alone stays on its line.
|
|
130
|
+
const next = document.toString({ lineWidth: 0 });
|
|
131
|
+
await writeAtomic(companionFrameworkConfigPath(companionPath), next);
|
|
132
|
+
return snapshotOf(config, tokenOf(next));
|
|
133
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/** Remote transports a declared server may name; absent means `http`. */
|
|
2
|
+
export const MCP_MANAGER_TRANSPORTS = ["http", "sse"] as const;
|
|
3
|
+
export type McpManagerTransport = (typeof MCP_MANAGER_TRANSPORTS)[number];
|
|
4
|
+
|
|
5
|
+
/** Scheme prefixes a header may put before its `${NAME}` reference. */
|
|
6
|
+
export const MCP_MANAGER_HEADER_PREFIXES = ["Bearer ", "Basic ", "Token "] as const;
|
|
7
|
+
|
|
8
|
+
/** Fields every declared server shares. Holds variable names, never values. */
|
|
9
|
+
interface McpManagerServerBase {
|
|
10
|
+
/** Environment variable names the server reads, rendered as runtime references. */
|
|
11
|
+
env?: string[];
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/** A server Mate starts as a local process. */
|
|
15
|
+
export interface McpManagerStdioServer extends McpManagerServerBase {
|
|
16
|
+
command: string;
|
|
17
|
+
args?: string[];
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** A server Mate reaches over the network. */
|
|
21
|
+
export interface McpManagerRemoteServer extends McpManagerServerBase {
|
|
22
|
+
url: string;
|
|
23
|
+
transport?: McpManagerTransport;
|
|
24
|
+
/** Header name to `<scheme prefix>${NAME}`, e.g. `Bearer ${ACME_KEY}`. */
|
|
25
|
+
headers?: Record<string, string>;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export type McpManagerServer = McpManagerStdioServer | McpManagerRemoteServer;
|
|
29
|
+
|
|
30
|
+
/** Server and group names, as a selection lists them. */
|
|
31
|
+
export interface McpManagerSelection {
|
|
32
|
+
servers?: string[];
|
|
33
|
+
groups?: string[];
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** The `mcpManager` section at the root of `framework.yaml`. */
|
|
37
|
+
export interface McpManagerConfig {
|
|
38
|
+
servers?: Record<string, McpManagerServer>;
|
|
39
|
+
/** Group name to member server names. */
|
|
40
|
+
groups?: Record<string, string[]>;
|
|
41
|
+
/** The base selection. */
|
|
42
|
+
enabled?: McpManagerSelection;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** `audiences.<name>.mcpManager`: selects from the root catalog only. */
|
|
46
|
+
export interface McpManagerAudienceSelection {
|
|
47
|
+
enable?: McpManagerSelection;
|
|
48
|
+
disable?: McpManagerSelection;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** A header value split into its literal prefix and the one variable it references. */
|
|
52
|
+
export interface McpManagerHeaderRef {
|
|
53
|
+
prefix: string;
|
|
54
|
+
variable: string;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const HEADER_VALUE_PATTERN = new RegExp(
|
|
58
|
+
`^(${MCP_MANAGER_HEADER_PREFIXES.join("|")})?\\$\\{([A-Z_][A-Z0-9_]*)\\}$`,
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
/** `${NAME}` with an optional known scheme prefix, or null for anything else. */
|
|
62
|
+
export function parseHeaderRef(value: unknown): McpManagerHeaderRef | null {
|
|
63
|
+
if (typeof value !== "string") return null;
|
|
64
|
+
const match = HEADER_VALUE_PATTERN.exec(value);
|
|
65
|
+
return match ? { prefix: match[1] ?? "", variable: match[2]! } : null;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** One server of an effective set, ready to become an MCP descriptor. */
|
|
69
|
+
export interface ResolvedMcpServer {
|
|
70
|
+
name: string;
|
|
71
|
+
server: McpManagerServer;
|
|
72
|
+
}
|