@uniqbit/mate-core 1.0.0-canary.9 → 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/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/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 +27 -9
- package/src/lib/mcp-manager/store.ts +35 -11
- package/src/lib/mcp-manager/types.ts +14 -0
- package/src/lib/mcp-manager/validate.ts +6 -10
- package/src/lib/opencode-server.ts +2 -17
- 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/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/write-atomic.ts +2 -2
- package/src/studio.ts +52 -8
- 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 +1 -2
- package/src/tools/setup/dynamic-plugins/declarations.ts +0 -26
- package/src/tools/setup/plugins/gitignore.ts +1 -0
- package/src/tools/setup/providers/claude-format.ts +1 -5
- package/src/tools/setup/providers/claude.ts +28 -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-C1F0_jbt.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-BN4aTpsz.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-Be5qgdDt.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-dku7MGPn.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-BkoDSw5X.js → prepaint-sD_LlrDN.js} +1 -1
- package/studio-dist/client/assets/{queries-CMvC2OkU.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-Bqd1ajyD.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-BYnEU33C.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-Cnw99ugO.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-CS3QRY4Q.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-DWFJaP_9.js → bundle-mjs-Ot6dQ8Pq.js} +1 -2056
- package/studio-dist/server/assets/{button-Ct_WeYLc.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-17vO5Uz8.js → combobox-iTjvPCtS.js} +7 -6
- package/studio-dist/server/assets/{companion-view-JkxnGLlp.js → companion-view-DIQ6AFIY.js} +2 -2
- package/studio-dist/server/assets/{companions-YNLsbnch.js → companions-aVwjRL8j.js} +1 -1
- package/studio-dist/server/assets/{fields-VytPpqBq.js → fields-BMap2_Ju.js} +10 -3
- package/studio-dist/server/assets/{friction-BW86PCPM.js → friction-BER50hoD.js} +2 -2
- package/studio-dist/server/assets/{friction-B6osqFSm.js → friction-BPs9KWdq.js} +8 -8
- package/studio-dist/server/assets/{getting-started-CFHSeX5h.js → getting-started-DGfRVmZ_.js} +2 -2
- package/studio-dist/server/assets/{getting-started._topic-BK2eU6AS.js → getting-started._topic-BgrBA4Vj.js} +2 -2
- package/studio-dist/server/assets/{getting-started.index-DZLuXnNO.js → getting-started.index-BaFfQ9Mn.js} +2 -2
- package/studio-dist/server/assets/{graph-BJVZBevL.js → graph-Cgzlrv3P.js} +8 -8
- package/studio-dist/server/assets/{graph-DGZHV-Ek.js → graph-DODpuOy_.js} +1 -1
- package/studio-dist/server/assets/{graph-canvas-lrNT6jbl.js → graph-canvas-DW_zU1nA.js} +2 -2
- package/studio-dist/server/assets/{guides-_G8Vucsk.js → guides-CA_EMG7E.js} +1 -1
- package/studio-dist/server/assets/{guides-CEwLOZb9.js → guides-D0SpoD32.js} +1 -1
- package/studio-dist/server/assets/{guides.server-ZWFKX2XJ.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-Bmjghg_Z.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-DvRjyil3.js → panel-D1K6Bsux.js} +4 -32
- package/studio-dist/server/assets/{plugins._service._view-B32LzraG.js → plugins._service._view-DdO1nELF.js} +4 -4
- package/studio-dist/server/assets/{prepaint-BEHwKl51.js → prepaint-BB3dwSmz.js} +1 -1
- package/studio-dist/server/assets/{queries-D6Vq0AuZ.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-Dn92pLap.js → reports-9Pr7Bz6o.js} +7 -7
- package/studio-dist/server/assets/{reports-DDaH5k0H.js → reports-Cc9M3phM.js} +1 -1
- package/studio-dist/server/assets/{router-Bjf4S9tO.js → router-DcWe0J7Y.js} +827 -548
- package/studio-dist/server/assets/{routes-B4sNiE0X.js → routes-BEXxl0py.js} +8 -8
- package/studio-dist/server/assets/{search-DKeJRvg8.js → search-bltT7gwy.js} +39 -7
- package/studio-dist/server/assets/{select-CVHYL7oR.js → select-CZvHgGCi.js} +7 -6
- package/studio-dist/server/assets/{shell-BxbYYaAk.js → shell-BQ0vMKXN.js} +13 -4
- package/studio-dist/server/assets/{skills-Bj8eOgzR.js → skills-Be_52h0i.js} +1 -1
- package/studio-dist/server/assets/{skills-B4-0qpqN.js → skills-BpGGUl6L.js} +8 -8
- package/studio-dist/server/assets/{specs-rfMug6qW.js → specs-CCGgXE-V.js} +5 -5
- package/studio-dist/server/assets/{specs-view-qi1SE1Sl.js → specs-view-DtL5JxYM.js} +12 -11
- package/studio-dist/server/assets/{steps-rger6HJc.js → steps-BWFSO6dM.js} +1 -1
- package/studio-dist/server/assets/{store-Dg9T7oWs.js → store-X7yLPp7v.js} +1 -1
- package/studio-dist/server/assets/{studio-queries-CeFfmIuM.js → studio-queries-ur1ygXi3.js} +117 -13
- package/studio-dist/server/assets/{studio-D79JzDLc.js → studio-qzH-UETC.js} +209 -180
- package/studio-dist/server/assets/{usage-Dw_UQFX-.js → usage-C1o0DLzS.js} +1 -1
- package/studio-dist/server/assets/{usage-BJgYWRCX.js → usage-DWbSPrPD.js} +10 -9
- package/studio-dist/server/assets/{useAnchoredPopupScrollLock-ciS_sEq3.js → useAnchoredPopupScrollLock-DLDmv6kM.js} +4 -135
- package/studio-dist/server/assets/useBlocker-CQtANHK8.js +111 -0
- package/studio-dist/server/assets/{useMutation-DnWK0PhO.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-BzarssiL.js → vault-B_kfi1h-.js} +1 -1
- package/studio-dist/server/assets/{vault-CvlrLd2H.js → vault-dL79JlKH.js} +8 -115
- package/studio-dist/server/assets/{views-CAxwKHMK.js → views-BSGH56lb.js} +3 -3
- package/studio-dist/server/assets/{warnings-BpVCugHm.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-BdrzcCt8.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-C9SQW3kI.js +0 -1
- package/studio-dist/client/assets/cn-DC80MJV0.js +0 -1
- package/studio-dist/client/assets/combobox-D7mKYCBb.js +0 -1
- package/studio-dist/client/assets/fields-CEep8IFT.js +0 -1
- package/studio-dist/client/assets/friction-D9dBU7WN.js +0 -1
- package/studio-dist/client/assets/getting-started-BDyGvHhc.js +0 -1
- package/studio-dist/client/assets/getting-started._topic-B9ajbF4o.js +0 -1
- package/studio-dist/client/assets/getting-started.index-CYiBPtb7.js +0 -1
- package/studio-dist/client/assets/graph-ah7ZXfTa.js +0 -2
- package/studio-dist/client/assets/guides-CsL0660B.js +0 -1
- package/studio-dist/client/assets/index-zmRH87D4.js +0 -40
- package/studio-dist/client/assets/panel-COgk0vP5.js +0 -1
- package/studio-dist/client/assets/plugins._service._view-Cn3WBHab.js +0 -1
- package/studio-dist/client/assets/reports-C_AqLBYH.js +0 -1
- package/studio-dist/client/assets/routes-BokQmHtC.js +0 -1
- package/studio-dist/client/assets/search-DxidNK2M.js +0 -1
- package/studio-dist/client/assets/select-CYFCbHUd.js +0 -1
- package/studio-dist/client/assets/skills-R3vttWHM.js +0 -1
- package/studio-dist/client/assets/specs-view-znqFPx9p.js +0 -1
- package/studio-dist/client/assets/steps-tVDWn7j6.js +0 -1
- package/studio-dist/client/assets/studio-ndtFcS2Y.js +0 -100
- package/studio-dist/client/assets/studio-queries-CkUSByy7.js +0 -2
- package/studio-dist/client/assets/usage-Kuhr8dSl.js +0 -55
- package/studio-dist/client/assets/useAnchoredPopupScrollLock-dc_kP4Go.js +0 -1
- package/studio-dist/client/assets/useMutation-CqtM9COw.js +0 -1
- package/studio-dist/client/assets/vault-CSP8kwRg.js +0 -1
- package/studio-dist/client/assets/workflow-BPJAmmZi.js +0 -1
|
@@ -7,18 +7,25 @@ import {
|
|
|
7
7
|
selectCompanionLinkInputs,
|
|
8
8
|
type CompanionLinkInputs,
|
|
9
9
|
type CompanionLinkWizardOptions,
|
|
10
|
+
type ExistingCompanion,
|
|
10
11
|
} from "../../companion-link-wizard";
|
|
11
12
|
import { extractRepoName } from "../artifact/extract-repo-name";
|
|
12
13
|
import { GlobalConfigStore } from "../../../lib/orchestrator/global-config-store";
|
|
13
14
|
import { linkIdFor } from "../../../lib/orchestrator/registry-checkouts";
|
|
14
|
-
import {
|
|
15
|
+
import {
|
|
16
|
+
RepoLocalRegistryStore,
|
|
17
|
+
removeRepoLocalCompanionPointer,
|
|
18
|
+
} from "../../../lib/orchestrator/repo-local-store";
|
|
15
19
|
import {
|
|
16
20
|
CompanionResolver,
|
|
17
21
|
companionRootedStore,
|
|
18
22
|
findDescendantRepoLocalRegistries,
|
|
19
23
|
} from "../../../lib/orchestrator/repository-link";
|
|
20
|
-
import {
|
|
24
|
+
import { errorMessage } from "../../../runtime/error-message";
|
|
25
|
+
import { remoteIdentity } from "../../../runtime/forge-remote";
|
|
26
|
+
import { namesOtherCheckout, originUrlOf, readGitLayout } from "../../../runtime/git-layout";
|
|
21
27
|
import { repoLocalRegistryPath } from "../../../runtime/repo-local";
|
|
28
|
+
import { localRootKind } from "../../../lib/orchestrator/root-context";
|
|
22
29
|
import { inspectSetupPreflight } from "../../../lib/orchestrator/setup-preflight";
|
|
23
30
|
import { runSetupFlowAtPath } from "../setup";
|
|
24
31
|
import { runInstallCommand } from "../install";
|
|
@@ -37,7 +44,12 @@ interface CompanionLinkCommandDeps {
|
|
|
37
44
|
stat?: typeof fs.stat;
|
|
38
45
|
listCompanions?: () => Promise<string[]>;
|
|
39
46
|
registerCompanion?: (companionPath: string) => Promise<void>;
|
|
40
|
-
|
|
47
|
+
/** The companions `cwd` resolves to now, read without writing. */
|
|
48
|
+
currentCompanions?: (cwd: string) => Promise<string[]>;
|
|
49
|
+
detectCompanionFolders?: (cwd: string) => Promise<string[]>;
|
|
50
|
+
readOrigin?: (folder: string) => string | null;
|
|
51
|
+
removeRepoLocalPointer?: (repoPath: string, companionPath: string) => Promise<void>;
|
|
52
|
+
removeCompanionRepository?: (companionPath: string, repositoryPath: string) => Promise<void>;
|
|
41
53
|
registerRepository?: (
|
|
42
54
|
repository: LinkedRepository,
|
|
43
55
|
options: { companionPath: string; companionSource: CompanionSource },
|
|
@@ -68,7 +80,7 @@ async function adoptedCheckout(
|
|
|
68
80
|
return (local?.companions ?? []).some((pointer) => linked.has(path.resolve(pointer.path)));
|
|
69
81
|
}
|
|
70
82
|
|
|
71
|
-
/**
|
|
83
|
+
/** Where the git source clones companions. */
|
|
72
84
|
function companionsHomeDir(): string {
|
|
73
85
|
return path.join(os.homedir(), `.${FRAMEWORK_NAME}`, "companions");
|
|
74
86
|
}
|
|
@@ -78,6 +90,71 @@ function isInsideDir(parentDir: string, candidatePath: string): boolean {
|
|
|
78
90
|
return relative === "" || (!relative.startsWith("..") && !path.isAbsolute(relative));
|
|
79
91
|
}
|
|
80
92
|
|
|
93
|
+
// Only `cwd`'s own links: Replace cannot remove one inherited from an ancestor folder or another Checkout.
|
|
94
|
+
async function currentCompanionsOf(cwd: string): Promise<string[]> {
|
|
95
|
+
const { match, ambiguousMatches } = await new CompanionResolver(
|
|
96
|
+
new GlobalConfigStore(),
|
|
97
|
+
).resolveWithDiagnostics(cwd, { write: false, own: true });
|
|
98
|
+
const matches = ambiguousMatches.length > 0 ? ambiguousMatches : match ? [match] : [];
|
|
99
|
+
return matches.map((current) => path.resolve(current.companionPath));
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
async function isCompanionFolder(folder: string): Promise<boolean> {
|
|
103
|
+
return (await localRootKind(folder)) === "companion";
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/** Companion folders among the direct children of `folder` and of its parent; no deeper scan. */
|
|
107
|
+
async function detectCompanionFoldersNear(folder: string): Promise<string[]> {
|
|
108
|
+
const found = await Promise.all(
|
|
109
|
+
[folder, path.dirname(folder)].map(async (parent) => {
|
|
110
|
+
const entries = await fs.readdir(parent, { withFileTypes: true }).catch(() => []);
|
|
111
|
+
return Promise.all(
|
|
112
|
+
entries
|
|
113
|
+
.filter((entry) => entry.isDirectory() || entry.isSymbolicLink())
|
|
114
|
+
.map(async (entry) => {
|
|
115
|
+
const child = path.join(parent, entry.name);
|
|
116
|
+
return (await isCompanionFolder(child)) ? child : null;
|
|
117
|
+
}),
|
|
118
|
+
);
|
|
119
|
+
}),
|
|
120
|
+
);
|
|
121
|
+
return found.flat().filter((child): child is string => child !== null);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/** Raw config, so an `insteadOf` rewrite does not change the identity. */
|
|
125
|
+
function readOriginUrl(folder: string): string | null {
|
|
126
|
+
const layout = readGitLayout(folder);
|
|
127
|
+
return layout ? originUrlOf(layout) : null;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/** Identities when both URLs parse; a URL `parseRemote` cannot read, such as a local path, compares as written. */
|
|
131
|
+
function sameRemote(origin: string | null, url: string): boolean {
|
|
132
|
+
if (!origin) return false;
|
|
133
|
+
const originIdentity = remoteIdentity(origin);
|
|
134
|
+
const urlIdentity = remoteIdentity(url);
|
|
135
|
+
// Forges match owner and repository case-insensitively.
|
|
136
|
+
return originIdentity !== null && urlIdentity !== null
|
|
137
|
+
? originIdentity.toLowerCase() === urlIdentity.toLowerCase()
|
|
138
|
+
: origin.trim() === url.trim();
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
function chosenCompanionPaths(
|
|
142
|
+
inputs: CompanionLinkInputs,
|
|
143
|
+
companionsDir: string,
|
|
144
|
+
extractName: (url: string) => string | null,
|
|
145
|
+
): string[] {
|
|
146
|
+
if (inputs.source === "git") {
|
|
147
|
+
if (inputs.clonePath) return [path.resolve(inputs.clonePath)];
|
|
148
|
+
const repoName = extractName(inputs.gitUrl ?? "");
|
|
149
|
+
return repoName ? [path.join(companionsDir, repoName)] : [];
|
|
150
|
+
}
|
|
151
|
+
if (inputs.source === "existing") {
|
|
152
|
+
return (inputs.companionPaths ?? []).map((companionPath) => path.resolve(companionPath));
|
|
153
|
+
}
|
|
154
|
+
const localPath = inputs.localPath?.trim();
|
|
155
|
+
return localPath ? [path.resolve(localPath)] : [];
|
|
156
|
+
}
|
|
157
|
+
|
|
81
158
|
export const companionLinkCommandDeps = {
|
|
82
159
|
runCompanionLinkCommandWithDeps: (argv: string[]) => runCompanionLinkCommandWithDeps(argv),
|
|
83
160
|
};
|
|
@@ -86,6 +163,12 @@ export async function runCompanionLinkCommand(argv: string[]): Promise<void> {
|
|
|
86
163
|
return companionLinkCommandDeps.runCompanionLinkCommandWithDeps(argv);
|
|
87
164
|
}
|
|
88
165
|
|
|
166
|
+
function warnOnFailure(removal: Promise<void>, failure: string): Promise<void> {
|
|
167
|
+
return removal.catch((error: unknown) => {
|
|
168
|
+
console.error(`mate: warning: could not remove ${failure}: ${errorMessage(error)}`);
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
|
|
89
172
|
function exitWithError(message: string): never {
|
|
90
173
|
process.stderr.write(`${message}\n`);
|
|
91
174
|
process.exit(1);
|
|
@@ -117,13 +200,14 @@ export async function runCompanionLinkCommandWithDeps(
|
|
|
117
200
|
const globalConfigStore = new GlobalConfigStore();
|
|
118
201
|
return globalConfigStore.list.bind(globalConfigStore);
|
|
119
202
|
})();
|
|
120
|
-
const
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
203
|
+
const currentCompanions = deps.currentCompanions ?? currentCompanionsOf;
|
|
204
|
+
const detectCompanionFolders = deps.detectCompanionFolders ?? detectCompanionFoldersNear;
|
|
205
|
+
const readOrigin = deps.readOrigin ?? readOriginUrl;
|
|
206
|
+
const removeRepoLocalPointer = deps.removeRepoLocalPointer ?? removeRepoLocalCompanionPointer;
|
|
207
|
+
const removeCompanionRepository =
|
|
208
|
+
deps.removeCompanionRepository ??
|
|
209
|
+
((companionPath, repositoryPath) =>
|
|
210
|
+
companionRootedStore(companionPath).removeRepository(repositoryPath));
|
|
127
211
|
const registerCompanion =
|
|
128
212
|
deps.registerCompanion ??
|
|
129
213
|
(() => {
|
|
@@ -138,43 +222,73 @@ export async function runCompanionLinkCommandWithDeps(
|
|
|
138
222
|
deps.findDescendantRepoLocalRegistries ?? findDescendantRepoLocalRegistries;
|
|
139
223
|
|
|
140
224
|
const cwd = path.resolve(process.cwd());
|
|
141
|
-
const existingMatch = await resolveCompanion(cwd);
|
|
142
225
|
const companionsDir = companionsHomeDir();
|
|
143
|
-
const
|
|
144
|
-
|
|
226
|
+
const [current, registeredPaths, detected] = await Promise.all([
|
|
227
|
+
currentCompanions(cwd),
|
|
228
|
+
listCompanions(),
|
|
229
|
+
detectCompanionFolders(cwd),
|
|
230
|
+
]);
|
|
231
|
+
const registered = new Set(registeredPaths.map((candidate) => path.resolve(candidate)));
|
|
232
|
+
const candidatePaths = [
|
|
233
|
+
...new Set(
|
|
234
|
+
[...registered, ...current, ...detected].map((candidate) => path.resolve(candidate)),
|
|
235
|
+
),
|
|
236
|
+
].filter((candidate) => candidate !== cwd);
|
|
145
237
|
const existingCompanions = (
|
|
146
238
|
await Promise.all(
|
|
147
|
-
|
|
148
|
-
const companionPath = path.resolve(candidate);
|
|
149
|
-
if (companionPath === cwd) return null;
|
|
150
|
-
if (!isInsideDir(companionsDir, companionPath)) return null;
|
|
239
|
+
candidatePaths.map(async (companionPath): Promise<ExistingCompanion | null> => {
|
|
151
240
|
const target = await stat(companionPath).catch(() => null);
|
|
152
|
-
|
|
241
|
+
if (!target?.isDirectory()) return null;
|
|
242
|
+
// A stale registration of a working repository or hub is no companion.
|
|
243
|
+
const kind = await localRootKind(companionPath);
|
|
244
|
+
if (kind === "working" || kind === "hub") return null;
|
|
245
|
+
return { path: companionPath, registered: registered.has(companionPath) };
|
|
153
246
|
}),
|
|
154
247
|
)
|
|
155
|
-
).filter((candidate): candidate is
|
|
248
|
+
).filter((candidate): candidate is ExistingCompanion => candidate !== null);
|
|
249
|
+
// Read on first use: most links never take the Git URL step.
|
|
250
|
+
const origins = new Map<string, string | null>();
|
|
251
|
+
const originOf = (companionPath: string) => {
|
|
252
|
+
if (!origins.has(companionPath)) origins.set(companionPath, readOrigin(companionPath));
|
|
253
|
+
return origins.get(companionPath) ?? null;
|
|
254
|
+
};
|
|
255
|
+
|
|
256
|
+
const replacedBy = (chosenInputs: CompanionLinkInputs): string[] => {
|
|
257
|
+
const chosen = new Set(chosenCompanionPaths(chosenInputs, companionsDir, extractName));
|
|
258
|
+
return chosen.size > 0 ? current.filter((companionPath) => !chosen.has(companionPath)) : [];
|
|
259
|
+
};
|
|
156
260
|
|
|
157
261
|
const inputs = await selectInputs({
|
|
158
262
|
existingCompanions,
|
|
263
|
+
clonesOf: (gitUrl) =>
|
|
264
|
+
existingCompanions
|
|
265
|
+
.filter((companion) => sameRemote(originOf(companion.path), gitUrl))
|
|
266
|
+
.map((companion) => companion.path),
|
|
267
|
+
replacedBy,
|
|
159
268
|
});
|
|
160
269
|
if (!inputs) {
|
|
161
270
|
exitWithError("Aborted.");
|
|
162
271
|
}
|
|
163
272
|
|
|
164
273
|
const companionSource = inputs.source;
|
|
165
|
-
|
|
274
|
+
const companionPaths = chosenCompanionPaths(inputs, companionsDir, extractName);
|
|
166
275
|
|
|
167
|
-
if (companionSource === "git") {
|
|
276
|
+
if (companionSource === "git" && !inputs.clonePath) {
|
|
168
277
|
const gitUrl = inputs.gitUrl ?? "";
|
|
169
|
-
const
|
|
170
|
-
if (!
|
|
278
|
+
const [companionPath] = companionPaths;
|
|
279
|
+
if (!companionPath) {
|
|
171
280
|
exitWithError(`mate: could not extract repository name from URL: ${gitUrl}`);
|
|
172
281
|
}
|
|
173
282
|
|
|
174
|
-
const companionPath = path.join(companionsDir, repoName);
|
|
175
|
-
|
|
176
283
|
const existingTarget = await stat(companionPath).catch(() => null);
|
|
177
|
-
if (
|
|
284
|
+
if (existingTarget?.isDirectory()) {
|
|
285
|
+
const origin = readOrigin(companionPath);
|
|
286
|
+
if (!sameRemote(origin, gitUrl)) {
|
|
287
|
+
exitWithError(
|
|
288
|
+
`mate: ${companionPath} already exists with origin ${origin ?? "(none)"}, not ${gitUrl}. Move that folder away, or link it with "Enter the path of another folder".`,
|
|
289
|
+
);
|
|
290
|
+
}
|
|
291
|
+
} else {
|
|
178
292
|
await mkdir(companionsDir, { recursive: true });
|
|
179
293
|
// Git may ask for credentials: a labelled hand-over, never a spinner.
|
|
180
294
|
const progress = createProgress("Linking companion");
|
|
@@ -196,14 +310,10 @@ export async function runCompanionLinkCommandWithDeps(
|
|
|
196
310
|
);
|
|
197
311
|
}
|
|
198
312
|
}
|
|
199
|
-
companionPaths = [companionPath];
|
|
200
313
|
} else if (companionSource === "existing") {
|
|
201
|
-
if (
|
|
314
|
+
if (companionPaths.length === 0) {
|
|
202
315
|
exitWithError("mate: no existing companion was selected.");
|
|
203
316
|
}
|
|
204
|
-
companionPaths = inputs.companionPaths.map((rawCompanionPath) =>
|
|
205
|
-
path.resolve(rawCompanionPath),
|
|
206
|
-
);
|
|
207
317
|
const targets = await Promise.all(
|
|
208
318
|
companionPaths.map((companionPath) => stat(companionPath).catch(() => null)),
|
|
209
319
|
);
|
|
@@ -211,18 +321,15 @@ export async function runCompanionLinkCommandWithDeps(
|
|
|
211
321
|
if (notADirectory) {
|
|
212
322
|
exitWithError(`mate: existing companion must be a directory: ${notADirectory}`);
|
|
213
323
|
}
|
|
214
|
-
} else {
|
|
215
|
-
const
|
|
216
|
-
if (!
|
|
324
|
+
} else if (companionSource === "local") {
|
|
325
|
+
const [companionPath] = companionPaths;
|
|
326
|
+
if (!companionPath) {
|
|
217
327
|
exitWithError("mate: no local companion path was provided.");
|
|
218
328
|
}
|
|
219
|
-
|
|
220
|
-
const resolvedCompanionPath = path.resolve(rawCompanionPath);
|
|
221
|
-
const existingTarget = await stat(resolvedCompanionPath).catch(() => null);
|
|
329
|
+
const existingTarget = await stat(companionPath).catch(() => null);
|
|
222
330
|
if (!existingTarget?.isDirectory()) {
|
|
223
|
-
exitWithError(`mate: local companion must be a directory: ${
|
|
331
|
+
exitWithError(`mate: local companion must be a directory: ${companionPath}`);
|
|
224
332
|
}
|
|
225
|
-
companionPaths = [resolvedCompanionPath];
|
|
226
333
|
}
|
|
227
334
|
|
|
228
335
|
/** The registry keeps the ID of an entry the clone already has, and the link names the kept one. */
|
|
@@ -241,22 +348,42 @@ export async function runCompanionLinkCommandWithDeps(
|
|
|
241
348
|
companionSource: options.companionSource,
|
|
242
349
|
}));
|
|
243
350
|
|
|
244
|
-
|
|
245
|
-
|
|
351
|
+
const sourceOf = (companionPath: string): CompanionSource =>
|
|
352
|
+
isInsideDir(companionsDir, companionPath) ? "git" : "local";
|
|
353
|
+
|
|
354
|
+
// After the first new link is written, so a failed setup or link leaves the old one in place.
|
|
355
|
+
const removeReplaced = async () => {
|
|
356
|
+
/* oxlint-disable no-await-in-loop -- one replaced companion after another */
|
|
357
|
+
for (const replacedPath of inputs.replace ? replacedBy(inputs) : []) {
|
|
358
|
+
await warnOnFailure(
|
|
359
|
+
removeRepoLocalPointer(cwd, replacedPath),
|
|
360
|
+
`the link to ${replacedPath} from ${cwd}`,
|
|
361
|
+
);
|
|
362
|
+
await warnOnFailure(
|
|
363
|
+
removeCompanionRepository(replacedPath, cwd),
|
|
364
|
+
`${cwd} from the registry of ${replacedPath}`,
|
|
365
|
+
);
|
|
366
|
+
}
|
|
367
|
+
/* oxlint-enable no-await-in-loop */
|
|
368
|
+
};
|
|
246
369
|
|
|
247
370
|
let keptId: string | undefined;
|
|
248
371
|
/* oxlint-disable no-await-in-loop -- each companion is set up, linked and installed in turn; a declined install stops the rest */
|
|
249
372
|
for (const companionPath of companionPaths) {
|
|
250
373
|
const preflight = await inspectPreflight(companionPath);
|
|
251
|
-
|
|
374
|
+
// A clone found on this machine already holds its framework.yaml.
|
|
375
|
+
if (companionSource === "git" && !inputs.clonePath && preflight.kind !== "existing-companion") {
|
|
252
376
|
await runSetup(companionPath);
|
|
253
377
|
}
|
|
254
378
|
|
|
255
379
|
const kept = await registerRepository(repository, {
|
|
256
380
|
companionPath,
|
|
257
|
-
companionSource:
|
|
381
|
+
companionSource: sourceOf(companionPath),
|
|
258
382
|
});
|
|
259
|
-
keptId
|
|
383
|
+
if (keptId === undefined) {
|
|
384
|
+
keptId = kept.id;
|
|
385
|
+
await removeReplaced();
|
|
386
|
+
}
|
|
260
387
|
await registerCompanion(companionPath);
|
|
261
388
|
await invalidateInstallState({ kind: "companion", companionPath });
|
|
262
389
|
if ((await installCompanion(companionPath)) === false) return;
|
|
@@ -286,7 +413,7 @@ export async function runCompanionLinkCommandWithDeps(
|
|
|
286
413
|
console.log(`Successfully linked companion for ${keptId ?? repository.id}`);
|
|
287
414
|
for (const companionPath of companionPaths) {
|
|
288
415
|
console.log(` Companion: ${companionPath}`);
|
|
416
|
+
console.log(` Source: ${sourceOf(companionPath)}`);
|
|
289
417
|
}
|
|
290
|
-
console.log(` Source: ${persistedSource}`);
|
|
291
418
|
console.log(" Workspace: run `mate companion open` to open the workspace in your editor");
|
|
292
419
|
}
|
|
@@ -2,13 +2,7 @@ import {
|
|
|
2
2
|
REPORT_DOCUMENT_VERSION,
|
|
3
3
|
REPORT_STATUS_TONES,
|
|
4
4
|
REPORT_TEXT_FORMATS,
|
|
5
|
-
type ReportDiagramSection,
|
|
6
|
-
type ReportDiffSection,
|
|
7
5
|
type ReportDocument,
|
|
8
|
-
type ReportKeyValue,
|
|
9
|
-
type ReportMetric,
|
|
10
|
-
type ReportSection,
|
|
11
|
-
type ReportStatus,
|
|
12
6
|
type ReportValue,
|
|
13
7
|
} from "./types";
|
|
14
8
|
|
|
@@ -304,14 +298,3 @@ export function parseReportDocument(json: string): ReportDocument {
|
|
|
304
298
|
}
|
|
305
299
|
return validateReportDocument(input);
|
|
306
300
|
}
|
|
307
|
-
|
|
308
|
-
export type {
|
|
309
|
-
ReportDiagramSection,
|
|
310
|
-
ReportDiffSection,
|
|
311
|
-
ReportDocument,
|
|
312
|
-
ReportKeyValue,
|
|
313
|
-
ReportMetric,
|
|
314
|
-
ReportSection,
|
|
315
|
-
ReportStatus,
|
|
316
|
-
ReportValue,
|
|
317
|
-
};
|
|
@@ -74,6 +74,10 @@ function bracketed(hostname: string): string {
|
|
|
74
74
|
return hostname.includes(":") && !hostname.startsWith("[") ? `[${hostname}]` : hostname;
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
+
export function isLoopbackHostname(hostname: string): boolean {
|
|
78
|
+
return LOOPBACK_HOSTNAMES.includes(bracketed(hostname.toLowerCase()));
|
|
79
|
+
}
|
|
80
|
+
|
|
77
81
|
function digest(value: string): Buffer {
|
|
78
82
|
return createHash("sha256").update(value).digest();
|
|
79
83
|
}
|
|
@@ -12,10 +12,43 @@ export interface StudioAction {
|
|
|
12
12
|
id: string;
|
|
13
13
|
skill: string;
|
|
14
14
|
label: string;
|
|
15
|
-
subject: "spec";
|
|
15
|
+
subject: "spec" | "workset" | "change";
|
|
16
16
|
prompts: Record<TerminalAgent, (subject: string) => string>;
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
+
export const WORK_ACTIONS: readonly StudioAction[] = [
|
|
20
|
+
{
|
|
21
|
+
id: "explore-workset",
|
|
22
|
+
skill: "mate-explore-change",
|
|
23
|
+
label: "Explore",
|
|
24
|
+
subject: "workset",
|
|
25
|
+
prompts: {
|
|
26
|
+
claude: (subject) => `/mate-explore-change ${subject}`,
|
|
27
|
+
opencode: (subject) => `Use the mate-explore-change skill on Workset ${subject}.`,
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
id: "propose-workset",
|
|
32
|
+
skill: "mate-propose-change",
|
|
33
|
+
label: "Propose",
|
|
34
|
+
subject: "workset",
|
|
35
|
+
prompts: {
|
|
36
|
+
claude: (subject) => `/mate-propose-change ${subject}`,
|
|
37
|
+
opencode: (subject) => `Use the mate-propose-change skill for ${subject}.`,
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
id: "apply-change",
|
|
42
|
+
skill: "mate-apply-change",
|
|
43
|
+
label: "Apply",
|
|
44
|
+
subject: "change",
|
|
45
|
+
prompts: {
|
|
46
|
+
claude: (subject) => `/mate-apply-change ${subject}`,
|
|
47
|
+
opencode: (subject) => `Use the mate-apply-change skill on change ${subject}.`,
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
];
|
|
51
|
+
|
|
19
52
|
export const STUDIO_ACTIONS: readonly StudioAction[] = [
|
|
20
53
|
{
|
|
21
54
|
id: "show-me",
|
|
@@ -30,7 +63,7 @@ export const STUDIO_ACTIONS: readonly StudioAction[] = [
|
|
|
30
63
|
];
|
|
31
64
|
|
|
32
65
|
export function findAction(id: unknown): StudioAction | null {
|
|
33
|
-
return STUDIO_ACTIONS.find((action) => action.id === id) ?? null;
|
|
66
|
+
return [...STUDIO_ACTIONS, ...WORK_ACTIONS].find((action) => action.id === id) ?? null;
|
|
34
67
|
}
|
|
35
68
|
|
|
36
69
|
/** Skill trees each agent loads; Claude does not read the shared Agents tree. */
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import { isDeepStrictEqual } from "node:util";
|
|
2
|
+
|
|
3
|
+
import { effectiveSets, isVariableSet, serverVariables } from "../../../lib/mcp-manager/resolve";
|
|
4
|
+
import {
|
|
5
|
+
McpManagerConflictError,
|
|
6
|
+
readMcpManager,
|
|
7
|
+
writeMcpManager,
|
|
8
|
+
type McpManagerPatch,
|
|
9
|
+
type McpManagerSnapshot,
|
|
10
|
+
} from "../../../lib/mcp-manager/store";
|
|
11
|
+
import type {
|
|
12
|
+
McpManagerAudienceSelection,
|
|
13
|
+
McpManagerConfig,
|
|
14
|
+
McpManagerSelection,
|
|
15
|
+
} from "../../../lib/mcp-manager/types";
|
|
16
|
+
import { validateMcpManagerConfig } from "../../../lib/mcp-manager/validate";
|
|
17
|
+
import { ConfigError } from "../../../lib/orchestrator/types";
|
|
18
|
+
|
|
19
|
+
type Env = Record<string, string | undefined>;
|
|
20
|
+
|
|
21
|
+
/** What the MCP view edits: the root section and each declared audience's selection. */
|
|
22
|
+
export interface McpManagerState {
|
|
23
|
+
/** Null when the companion declares no `mcpManager`. */
|
|
24
|
+
catalog: McpManagerConfig | null;
|
|
25
|
+
audiences: Record<string, McpManagerAudienceSelection>;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** A variable a server reads and whether Studio's environment sets it; never its value. */
|
|
29
|
+
export interface McpVariableStatus {
|
|
30
|
+
name: string;
|
|
31
|
+
set: boolean;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** What core derives from a state, so the browser reimplements no precedence. */
|
|
35
|
+
export interface McpManagerDerived {
|
|
36
|
+
/** Effective server names for the base set and per audience. */
|
|
37
|
+
effective: McpManagerSnapshot["effective"];
|
|
38
|
+
/** Per catalog server, the variables it reads. */
|
|
39
|
+
variables: Record<string, McpVariableStatus[]>;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export interface McpManagerView extends McpManagerState, McpManagerDerived {
|
|
43
|
+
/** The concurrency token a save carries. */
|
|
44
|
+
token: string;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** A state's derived data, or core's validation error for it. */
|
|
48
|
+
export type McpManagerPreview = ({ ok: true } & McpManagerDerived) | { ok: false; reason: string };
|
|
49
|
+
|
|
50
|
+
export type McpManagerSaveResult =
|
|
51
|
+
| { kind: "saved"; view: McpManagerView }
|
|
52
|
+
/** `framework.yaml` changed after the read; nothing was written. */
|
|
53
|
+
| { kind: "conflict"; current: McpManagerView };
|
|
54
|
+
|
|
55
|
+
/** The state as `framework.yaml` would hold it, for core's validation and resolution. */
|
|
56
|
+
function rawOf(state: McpManagerState) {
|
|
57
|
+
return {
|
|
58
|
+
...(state.catalog ? { mcpManager: state.catalog } : {}),
|
|
59
|
+
audiences: Object.fromEntries(
|
|
60
|
+
Object.entries(state.audiences).map(([name, selection]) => [name, { mcpManager: selection }]),
|
|
61
|
+
),
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function variablesOf(catalog: McpManagerConfig | null, env: Env): McpManagerDerived["variables"] {
|
|
66
|
+
return Object.fromEntries(
|
|
67
|
+
Object.entries(catalog?.servers ?? {}).map(([server, declared]) => [
|
|
68
|
+
server,
|
|
69
|
+
serverVariables(declared).map((name) => ({ name, set: isVariableSet(env, name) })),
|
|
70
|
+
]),
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function viewOf(snapshot: McpManagerSnapshot, env: Env): McpManagerView {
|
|
75
|
+
return { ...snapshot, variables: variablesOf(snapshot.catalog, env) };
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export async function readMcpManagerView(companionPath: string, env: Env): Promise<McpManagerView> {
|
|
79
|
+
return viewOf(await readMcpManager(companionPath), env);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export function previewMcpManager(state: McpManagerState, env: Env): McpManagerPreview {
|
|
83
|
+
try {
|
|
84
|
+
const raw = rawOf(state);
|
|
85
|
+
validateMcpManagerConfig(raw);
|
|
86
|
+
return {
|
|
87
|
+
ok: true,
|
|
88
|
+
effective: effectiveSets(raw, Object.keys(state.audiences)),
|
|
89
|
+
variables: variablesOf(state.catalog, env),
|
|
90
|
+
};
|
|
91
|
+
} catch (error) {
|
|
92
|
+
if (!(error instanceof ConfigError)) throw error;
|
|
93
|
+
return { ok: false, reason: error.message };
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** Without empty lists; undefined when it names nothing. */
|
|
98
|
+
function selectionOf(selection: McpManagerSelection | undefined): McpManagerSelection | undefined {
|
|
99
|
+
const { servers = [], groups = [] } = selection ?? {};
|
|
100
|
+
if (servers.length === 0 && groups.length === 0) return undefined;
|
|
101
|
+
return { ...(servers.length > 0 ? { servers } : {}), ...(groups.length > 0 ? { groups } : {}) };
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function catalogOf(catalog: McpManagerConfig | null): McpManagerConfig | null {
|
|
105
|
+
const { servers = {}, groups = {}, enabled } = catalog ?? {};
|
|
106
|
+
const hasServers = Object.keys(servers).length > 0;
|
|
107
|
+
const hasGroups = Object.keys(groups).length > 0;
|
|
108
|
+
if (!hasServers && !hasGroups) return null;
|
|
109
|
+
const base = selectionOf(enabled);
|
|
110
|
+
return {
|
|
111
|
+
...(hasServers ? { servers } : {}),
|
|
112
|
+
...(hasGroups ? { groups } : {}),
|
|
113
|
+
...(base ? { enabled: base } : {}),
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function audienceOf(
|
|
118
|
+
selection: McpManagerAudienceSelection | undefined,
|
|
119
|
+
): McpManagerAudienceSelection | null {
|
|
120
|
+
const enable = selectionOf(selection?.enable);
|
|
121
|
+
const disable = selectionOf(selection?.disable);
|
|
122
|
+
if (!enable && !disable) return null;
|
|
123
|
+
return { ...(enable ? { enable } : {}), ...(disable ? { disable } : {}) };
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Only what differs from `current`, so a save rewrites no untouched part and its comments
|
|
128
|
+
* stay. Covers the declared audiences `next` names: a save never creates one.
|
|
129
|
+
*/
|
|
130
|
+
function patchOf(next: McpManagerState, current: McpManagerSnapshot): McpManagerPatch {
|
|
131
|
+
const patch: McpManagerPatch = {};
|
|
132
|
+
const catalog = catalogOf(next.catalog);
|
|
133
|
+
if (!isDeepStrictEqual(catalog, catalogOf(current.catalog))) patch.catalog = catalog;
|
|
134
|
+
for (const [name, held] of Object.entries(current.audiences)) {
|
|
135
|
+
// Declared after the client's read, so it never saw it: an overwrite leaves it alone.
|
|
136
|
+
if (!Object.hasOwn(next.audiences, name)) continue;
|
|
137
|
+
const selection = audienceOf(next.audiences[name]);
|
|
138
|
+
if (isDeepStrictEqual(selection, audienceOf(held))) continue;
|
|
139
|
+
patch.audiences = { ...patch.audiences, [name]: selection };
|
|
140
|
+
}
|
|
141
|
+
return patch;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/** Writes the whole next state; throws the loader's error when it is invalid. */
|
|
145
|
+
export async function saveMcpManagerView(
|
|
146
|
+
companionPath: string,
|
|
147
|
+
next: McpManagerState,
|
|
148
|
+
token: string,
|
|
149
|
+
env: Env,
|
|
150
|
+
): Promise<McpManagerSaveResult> {
|
|
151
|
+
validateMcpManagerConfig(rawOf(next));
|
|
152
|
+
try {
|
|
153
|
+
const patch = patchOf(next, await readMcpManager(companionPath));
|
|
154
|
+
return {
|
|
155
|
+
kind: "saved",
|
|
156
|
+
view: viewOf(await writeMcpManager(companionPath, patch, token), env),
|
|
157
|
+
};
|
|
158
|
+
} catch (error) {
|
|
159
|
+
if (!(error instanceof McpManagerConflictError)) throw error;
|
|
160
|
+
return { kind: "conflict", current: await readMcpManagerView(companionPath, env) };
|
|
161
|
+
}
|
|
162
|
+
}
|
|
@@ -18,6 +18,18 @@ export const SERVICE_ASSET_PREFIX = "/studio/plugins/";
|
|
|
18
18
|
/** Answers 204 to any reader; the page probes its connection here. */
|
|
19
19
|
export const STUDIO_PING_ROUTE = "/api/ping";
|
|
20
20
|
|
|
21
|
+
/**
|
|
22
|
+
* The Analysis chat: `POST {companion, messages}` streams one read-only agent turn as an
|
|
23
|
+
* AI SDK UI message stream. Only on a localhost-only Studio, or in the appliance.
|
|
24
|
+
*/
|
|
25
|
+
export const CHAT_ROUTE = "/api/chat";
|
|
26
|
+
|
|
27
|
+
/** `GET` with the selected companion: what a chat turn for it can use; starts no agent. */
|
|
28
|
+
export const CHAT_SESSION_ROUTE = "/api/chat/session";
|
|
29
|
+
|
|
30
|
+
/** `GET` which credential answers chat turns (never its value); `PUT {kind, value}` sets one in Studio; `DELETE` clears it. */
|
|
31
|
+
export const CHAT_CREDENTIAL_ROUTE = "/api/chat/credential";
|
|
32
|
+
|
|
21
33
|
/** One event stream per page: board, reports and markdown tree changes for a companion. */
|
|
22
34
|
export const STUDIO_EVENTS_ROUTE = "/api/events";
|
|
23
35
|
|