@uniqbit/mate-core 1.0.0-canary.8 → 1.0.0-canary.9
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 +1 -1
- package/src/cli/commands/doctor.ts +17 -0
- package/src/cli/commands/vscode/release-vsix.json +2 -2
- package/src/create-mate.ts +4 -1
- package/src/lib/mcp-manager/resolve.ts +70 -0
- package/src/lib/mcp-manager/store.ts +109 -0
- package/src/lib/mcp-manager/types.ts +58 -0
- package/src/lib/mcp-manager/validate.ts +246 -0
- 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/types.ts +4 -0
- package/src/runtime/workflow/turn.ts +14 -12
- package/src/studio.ts +17 -0
- package/src/tools/setup/capabilities/mcp-manager.ts +74 -0
- package/src/tools/setup/context-services.ts +35 -6
- package/src/tools/setup/dynamic-plugins/audiences.ts +3 -2
- package/src/tools/setup/engine.ts +55 -3
- package/src/tools/setup/plugin.ts +14 -0
- package/src/tools/setup/providers/claude-format.ts +39 -2
- package/src/tools/setup/providers/claude.ts +10 -0
- package/src/tools/setup/providers/opencode-format.ts +13 -3
- package/studio-dist/client/assets/{button-amJ3g5oD.js → button-C9SQW3kI.js} +1 -1
- package/studio-dist/client/assets/{cn-BQPKiwI4.js → cn-DC80MJV0.js} +1 -1
- package/studio-dist/client/assets/{combobox-CJ7aGFid.js → combobox-D7mKYCBb.js} +1 -1
- package/studio-dist/client/assets/{companion-view-C_N237bf.js → companion-view-C1F0_jbt.js} +1 -1
- package/studio-dist/client/assets/{fields-BAiGkJ5N.js → fields-CEep8IFT.js} +1 -1
- package/studio-dist/client/assets/{friction-DqOU59v7.js → friction-D9dBU7WN.js} +1 -1
- package/studio-dist/client/assets/getting-started-BDyGvHhc.js +1 -0
- package/studio-dist/client/assets/{getting-started-djaQeWlu.js → getting-started-BN4aTpsz.js} +1 -1
- package/studio-dist/client/assets/getting-started._topic-B9ajbF4o.js +1 -0
- package/studio-dist/client/assets/getting-started.index-CYiBPtb7.js +1 -0
- package/studio-dist/client/assets/{graph-BYaD_5Bq.js → graph-ah7ZXfTa.js} +2 -2
- package/studio-dist/client/assets/{graph-canvas-ySGKMhmk.js → graph-canvas-Be5qgdDt.js} +1 -1
- package/studio-dist/client/assets/guides-CsL0660B.js +1 -0
- package/studio-dist/client/assets/{index-Qx7reRPD.js → index-zmRH87D4.js} +3 -3
- package/studio-dist/client/assets/{markdown-view-jMiaBTSO.js → markdown-view-dku7MGPn.js} +1 -1
- package/studio-dist/client/assets/{panel-C4bf_h2W.js → panel-COgk0vP5.js} +1 -1
- package/studio-dist/client/assets/{plugins._service._view-y6f2FDAB.js → plugins._service._view-Cn3WBHab.js} +1 -1
- package/studio-dist/client/assets/{prepaint-CKsXyJOR.js → prepaint-BkoDSw5X.js} +1 -1
- package/studio-dist/client/assets/{queries-Dfp5deWj.js → queries-CMvC2OkU.js} +1 -1
- package/studio-dist/client/assets/{reports-JFSwSueq.js → reports-C_AqLBYH.js} +1 -1
- package/studio-dist/client/assets/{routes-BdOWSgzK.js → routes-BokQmHtC.js} +1 -1
- package/studio-dist/client/assets/{search-CXosfvYh.js → search-DxidNK2M.js} +1 -1
- package/studio-dist/client/assets/{select-BHYYWPhK.js → select-CYFCbHUd.js} +1 -1
- package/studio-dist/client/assets/{skills-Bo9FLsBd.js → skills-R3vttWHM.js} +1 -1
- package/studio-dist/client/assets/{specs-BrCOjOch.js → specs-Bqd1ajyD.js} +1 -1
- package/studio-dist/client/assets/{specs-view-CdE2rlli.js → specs-view-znqFPx9p.js} +1 -1
- package/studio-dist/client/assets/{steps-CKUno4lh.js → steps-tVDWn7j6.js} +1 -1
- package/studio-dist/client/assets/{store-C3vJq8Wj.js → store-BYnEU33C.js} +1 -1
- package/studio-dist/client/assets/studio-ndtFcS2Y.js +100 -0
- package/studio-dist/client/assets/{studio-queries-BflKt9va.js → studio-queries-CkUSByy7.js} +1 -1
- package/studio-dist/client/assets/{usage-BLsLy0nN.js → usage-Kuhr8dSl.js} +1 -1
- package/studio-dist/client/assets/{useAnchoredPopupScrollLock-DC7f8GOp.js → useAnchoredPopupScrollLock-dc_kP4Go.js} +1 -1
- package/studio-dist/client/assets/{useMutation-uJUrejsi.js → useMutation-CqtM9COw.js} +1 -1
- package/studio-dist/client/assets/{vault-BB1B_OhR.js → vault-CSP8kwRg.js} +1 -1
- package/studio-dist/client/assets/{warnings-CqOOGlPD.js → warnings-Cnw99ugO.js} +1 -1
- package/studio-dist/client/assets/{workflow-BFzmI-06.js → workflow-BPJAmmZi.js} +1 -1
- package/studio-dist/server/assets/{__23tanstack-start-server-fn-resolver-gVfW5vIV.js → __23tanstack-start-server-fn-resolver-CS3QRY4Q.js} +18 -18
- package/studio-dist/server/assets/_tanstack-start-manifest_v.js +58 -58
- package/studio-dist/server/assets/{button-D6bvrFmm.js → button-Ct_WeYLc.js} +1 -1
- package/studio-dist/server/assets/{cn-FXJAM0KO.js → cn-DWFJaP_9.js} +1 -1
- package/studio-dist/server/assets/{combobox-D2MbYV1O.js → combobox-17vO5Uz8.js} +6 -6
- package/studio-dist/server/assets/{companion-view-Mf1ANbMb.js → companion-view-JkxnGLlp.js} +2 -2
- package/studio-dist/server/assets/{companions-Dr6IpNAb.js → companions-YNLsbnch.js} +1 -1
- package/studio-dist/server/assets/{fields-B4mAPETz.js → fields-VytPpqBq.js} +2 -2
- package/studio-dist/server/assets/{friction-9a5S1m7U.js → friction-B6osqFSm.js} +8 -8
- package/studio-dist/server/assets/{friction-CWOTjpCV.js → friction-BW86PCPM.js} +2 -2
- package/studio-dist/server/assets/{getting-started-RU6tYU2Q.js → getting-started-CFHSeX5h.js} +2 -2
- package/studio-dist/server/assets/{getting-started._topic-C02HGrC6.js → getting-started._topic-BK2eU6AS.js} +2 -2
- package/studio-dist/server/assets/{getting-started.index-EzLRosbb.js → getting-started.index-DZLuXnNO.js} +2 -2
- package/studio-dist/server/assets/{graph-CZ2H9Fzr.js → graph-BJVZBevL.js} +8 -8
- package/studio-dist/server/assets/{graph-B11ITte0.js → graph-DGZHV-Ek.js} +1 -1
- package/studio-dist/server/assets/{graph-canvas-rP5TT14Z.js → graph-canvas-lrNT6jbl.js} +2 -2
- package/studio-dist/server/assets/{guides-B8HdeK_C.js → guides-CEwLOZb9.js} +1 -1
- package/studio-dist/server/assets/{guides-BGftp4wf.js → guides-_G8Vucsk.js} +1 -1
- package/studio-dist/server/assets/{guides.server-DqFQAStf.js → guides.server-ZWFKX2XJ.js} +1 -1
- package/studio-dist/server/assets/{markdown-view-CArpV-CS.js → markdown-view-Bmjghg_Z.js} +1 -1
- package/studio-dist/server/assets/{panel-DR0iq46J.js → panel-DvRjyil3.js} +4 -4
- package/studio-dist/server/assets/{plugins._service._view-n7u2k5dF.js → plugins._service._view-B32LzraG.js} +4 -4
- package/studio-dist/server/assets/{prepaint-B28ClcPN.js → prepaint-BEHwKl51.js} +1 -1
- package/studio-dist/server/assets/{queries-D-yVP9i0.js → queries-D6Vq0AuZ.js} +1 -1
- package/studio-dist/server/assets/{reports-B9k98oE6.js → reports-DDaH5k0H.js} +1 -1
- package/studio-dist/server/assets/{reports-C2SmTgqh.js → reports-Dn92pLap.js} +7 -7
- package/studio-dist/server/assets/{router-CPt0TAk_.js → router-Bjf4S9tO.js} +25 -25
- package/studio-dist/server/assets/{routes-CwH8LEy2.js → routes-B4sNiE0X.js} +8 -8
- package/studio-dist/server/assets/{search-b-yQesv3.js → search-DKeJRvg8.js} +1 -1
- package/studio-dist/server/assets/{select-C3i6TTX-.js → select-CVHYL7oR.js} +5 -5
- package/studio-dist/server/assets/{shell-CagqZZMZ.js → shell-BxbYYaAk.js} +2 -2
- package/studio-dist/server/assets/{skills-C21Mg_8-.js → skills-B4-0qpqN.js} +8 -8
- package/studio-dist/server/assets/{skills-DGg0mWDM.js → skills-Bj8eOgzR.js} +1 -1
- package/studio-dist/server/assets/{specs-DetoMiaB.js → specs-rfMug6qW.js} +4 -4
- package/studio-dist/server/assets/{specs-view-CmbfLDwN.js → specs-view-qi1SE1Sl.js} +10 -10
- package/studio-dist/server/assets/{steps-D1tYAyWZ.js → steps-rger6HJc.js} +1 -1
- package/studio-dist/server/assets/{store-aC-I6f6o.js → store-Dg9T7oWs.js} +1 -1
- package/studio-dist/server/assets/{studio-qRvQjRpz.js → studio-D79JzDLc.js} +1347 -0
- package/studio-dist/server/assets/{studio-queries-Dqf-3nzj.js → studio-queries-CeFfmIuM.js} +3 -3
- package/studio-dist/server/assets/{usage-CS4CBK9D.js → usage-BJgYWRCX.js} +9 -9
- package/studio-dist/server/assets/{usage-Cwle9-xY.js → usage-Dw_UQFX-.js} +1 -1
- package/studio-dist/server/assets/{useAnchoredPopupScrollLock-BjMNgXv9.js → useAnchoredPopupScrollLock-ciS_sEq3.js} +2 -2
- package/studio-dist/server/assets/{useMutation-DpBIuWXt.js → useMutation-DnWK0PhO.js} +2 -2
- package/studio-dist/server/assets/{vault-CEBBRLMb.js → vault-BzarssiL.js} +1 -1
- package/studio-dist/server/assets/{vault-DVQidlId.js → vault-CvlrLd2H.js} +6 -6
- package/studio-dist/server/assets/{views-UgO0Qz_g.js → views-CAxwKHMK.js} +2 -2
- package/studio-dist/server/assets/{warnings-C7hgXpdk.js → warnings-BpVCugHm.js} +2 -2
- package/studio-dist/server/assets/{workflow-6dZZ1ofw.js → workflow-BdrzcCt8.js} +9 -9
- package/studio-dist/server/server.js +2 -2
- 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/guides-D6T6W_jV.js +0 -1
- package/studio-dist/client/assets/studio-0ueISxwP.js +0 -100
|
@@ -38,11 +38,23 @@ export async function writeEngineFloor(companionPath: string, range: string): Pr
|
|
|
38
38
|
*/
|
|
39
39
|
export async function raiseEngineFloor(companionPath: string, version: string): Promise<boolean> {
|
|
40
40
|
const raw = (await rawStore(companionPath).load()) ?? {};
|
|
41
|
-
const
|
|
41
|
+
const raised = raisedEngineRange(raw.engines, version);
|
|
42
|
+
return raised === null ? false : writeEngineFloor(companionPath, raised);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* The `engines.mate` range raised to `>=version`, or null when the current
|
|
47
|
+
* range already starts at or above it or does not parse.
|
|
48
|
+
*/
|
|
49
|
+
export function raisedEngineRange(engines: unknown, version: string): string | null {
|
|
50
|
+
const current =
|
|
51
|
+
typeof engines === "object" && engines !== null
|
|
52
|
+
? (engines as Record<string, unknown>)[FRAMEWORK_NAME]
|
|
53
|
+
: undefined;
|
|
42
54
|
if (typeof current === "string") {
|
|
43
|
-
if (semver.validRange(current) === null) return
|
|
55
|
+
if (semver.validRange(current) === null) return null;
|
|
44
56
|
const lowest = semver.minVersion(current);
|
|
45
|
-
if (lowest && semver.gte(lowest, version)) return
|
|
57
|
+
if (lowest && semver.gte(lowest, version)) return null;
|
|
46
58
|
}
|
|
47
|
-
return
|
|
59
|
+
return `>=${version}`;
|
|
48
60
|
}
|
|
@@ -28,8 +28,9 @@ export function checkEngineRequirement(
|
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
const current = semver.parse(currentVersion);
|
|
31
|
+
// A pre-release build counts as its release only against a release range; a pre-release floor must compare as-is.
|
|
31
32
|
const currentReleaseVersion =
|
|
32
|
-
current && current.prerelease.length > 0
|
|
33
|
+
current && current.prerelease.length > 0 && !namesPrerelease(range)
|
|
33
34
|
? `${current.major}.${current.minor}.${current.patch}`
|
|
34
35
|
: null;
|
|
35
36
|
const satisfied =
|
|
@@ -44,3 +45,8 @@ export function checkEngineRequirement(
|
|
|
44
45
|
}
|
|
45
46
|
return { ok: true };
|
|
46
47
|
}
|
|
48
|
+
|
|
49
|
+
// Reads the written text: parsed comparators carry generated tags (`^1.2.3` becomes `<2.0.0-0`).
|
|
50
|
+
function namesPrerelease(range: string): boolean {
|
|
51
|
+
return /\d+\.\d+\.\d+-[0-9A-Za-z]/.test(range);
|
|
52
|
+
}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type { McpManagerAudienceSelection, McpManagerConfig } from "../mcp-manager/types";
|
|
2
|
+
|
|
1
3
|
class MateError extends Error {}
|
|
2
4
|
|
|
3
5
|
export class ConfigError extends MateError {}
|
|
@@ -147,6 +149,7 @@ export interface AudienceConfig {
|
|
|
147
149
|
capabilities?: CapabilityConfig[];
|
|
148
150
|
plugins?: PluginDeclaration[];
|
|
149
151
|
studio?: { terminal?: StudioTerminalConfig };
|
|
152
|
+
mcpManager?: McpManagerAudienceSelection;
|
|
150
153
|
}
|
|
151
154
|
|
|
152
155
|
export interface FrameworkConfig {
|
|
@@ -162,6 +165,7 @@ export interface FrameworkConfig {
|
|
|
162
165
|
engines?: EngineConstraints;
|
|
163
166
|
studio?: { terminal?: StudioTerminalConfig };
|
|
164
167
|
audiences?: Record<string, AudienceConfig>;
|
|
168
|
+
mcpManager?: McpManagerConfig;
|
|
165
169
|
}
|
|
166
170
|
|
|
167
171
|
export interface CompanionRegistryConfig {
|
|
@@ -182,20 +182,27 @@ function pathSkill(workflow: Workflow, skill: string): boolean {
|
|
|
182
182
|
);
|
|
183
183
|
}
|
|
184
184
|
|
|
185
|
-
/**
|
|
186
|
-
* The hand-offs the verdict of a finished turn reads, one per change: after each reported
|
|
187
|
-
* change's last report, or, for a turn that only started a companion's step, the change's.
|
|
188
|
-
*/
|
|
189
185
|
function handoffQueries(turn: Turn, workflow: Workflow, again: boolean): HandoffQuery[] {
|
|
190
186
|
if (turn.reports.length > 0) {
|
|
191
187
|
const last = new Map<string, string>();
|
|
192
188
|
for (const report of turn.reports) if (report.change) last.set(report.change, report.skill);
|
|
193
|
-
|
|
189
|
+
const queries: HandoffQuery[] = [...last].map(([change, after]) => ({ change, after }));
|
|
190
|
+
const unnamed = unnamedStep(turn);
|
|
191
|
+
if (unnamed && !last.has(unnamed.change)) queries.push({ change: unnamed.change });
|
|
192
|
+
return queries;
|
|
194
193
|
}
|
|
195
194
|
const step = turn.step;
|
|
196
195
|
return !again && step && companionStep(workflow, step.skill) ? [{ change: step.change }] : [];
|
|
197
196
|
}
|
|
198
197
|
|
|
198
|
+
function unnamedStep(turn: Turn): Step | undefined {
|
|
199
|
+
const step = turn.step;
|
|
200
|
+
if (!step?.change) return undefined;
|
|
201
|
+
const reported = (change: string) =>
|
|
202
|
+
turn.reports.some((report) => report.skill === step.skill && report.change === change);
|
|
203
|
+
return reported("") && !reported(step.change) ? step : undefined;
|
|
204
|
+
}
|
|
205
|
+
|
|
199
206
|
/** Every query's hand-off at once, by change. */
|
|
200
207
|
async function fetchHandoffs(
|
|
201
208
|
queries: readonly HandoffQuery[],
|
|
@@ -251,13 +258,8 @@ async function turnVerdict(
|
|
|
251
258
|
{ again, runtime, response }: FinishOptions,
|
|
252
259
|
): Promise<TurnVerdict> {
|
|
253
260
|
if (turn.reports.length > 0) {
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
const unnamed =
|
|
257
|
-
step?.change &&
|
|
258
|
-
turn.reports.some((report) => report.skill === step.skill && !report.change) &&
|
|
259
|
-
!turn.reports.some((report) => report.skill === step.skill && report.change === step.change);
|
|
260
|
-
if (unnamed && step) {
|
|
261
|
+
const step = unnamedStep(turn);
|
|
262
|
+
if (step && next(step.change) !== null) {
|
|
261
263
|
if (again) return PASS;
|
|
262
264
|
return {
|
|
263
265
|
kind: "sendBack",
|
package/src/studio.ts
CHANGED
|
@@ -222,3 +222,20 @@ export {
|
|
|
222
222
|
LIGHT_PALETTE,
|
|
223
223
|
type ReportPalette,
|
|
224
224
|
} from "./cli/commands/report/palette";
|
|
225
|
+
|
|
226
|
+
export {
|
|
227
|
+
McpManagerConflictError,
|
|
228
|
+
readMcpManager,
|
|
229
|
+
writeMcpManager,
|
|
230
|
+
type McpManagerPatch,
|
|
231
|
+
type McpManagerSnapshot,
|
|
232
|
+
} from "./lib/mcp-manager/store";
|
|
233
|
+
export type {
|
|
234
|
+
McpManagerAudienceSelection,
|
|
235
|
+
McpManagerConfig,
|
|
236
|
+
McpManagerRemoteServer,
|
|
237
|
+
McpManagerSelection,
|
|
238
|
+
McpManagerServer,
|
|
239
|
+
McpManagerStdioServer,
|
|
240
|
+
McpManagerTransport,
|
|
241
|
+
} from "./lib/mcp-manager/types";
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
// oxlint-disable no-await-in-loop
|
|
2
|
+
import { resolveMcpServers } from "../../../lib/mcp-manager/resolve";
|
|
3
|
+
import type { ResolvedMcpServer } from "../../../lib/mcp-manager/types";
|
|
4
|
+
import { parseHeaderRef } from "../../../lib/mcp-manager/validate";
|
|
5
|
+
import { readAudienceSelection } from "../dynamic-plugins/audiences";
|
|
6
|
+
import type { CapabilityPlugin, McpServerDescriptor } from "../plugin";
|
|
7
|
+
|
|
8
|
+
export const MCP_MANAGER_PLUGIN_ID = "mcp-manager";
|
|
9
|
+
|
|
10
|
+
/** A validated declared server as a descriptor holding references only. */
|
|
11
|
+
export function toMcpServerDescriptor({ name, server }: ResolvedMcpServer): McpServerDescriptor {
|
|
12
|
+
const envRefs = server.env?.length ? { envRefs: server.env } : {};
|
|
13
|
+
if ("command" in server) {
|
|
14
|
+
return {
|
|
15
|
+
name,
|
|
16
|
+
command: server.command,
|
|
17
|
+
...(server.args ? { args: server.args } : {}),
|
|
18
|
+
...envRefs,
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
const headerRefs = Object.entries(server.headers ?? {}).flatMap(([header, value]) => {
|
|
22
|
+
const ref = parseHeaderRef(value);
|
|
23
|
+
return ref ? [[header, ref] as const] : [];
|
|
24
|
+
});
|
|
25
|
+
return {
|
|
26
|
+
name,
|
|
27
|
+
url: server.url,
|
|
28
|
+
transport: server.transport ?? "http",
|
|
29
|
+
...envRefs,
|
|
30
|
+
...(headerRefs.length > 0 ? { headerRefs: Object.fromEntries(headerRefs) } : {}),
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Renders the companion's `mcpManager` servers for the audience in
|
|
36
|
+
* `MATE_AUDIENCE` into every active Agent Runtime. Enabled by the section
|
|
37
|
+
* alone, so it never appears in a setup selector.
|
|
38
|
+
*/
|
|
39
|
+
export function createMcpManagerPlugin(
|
|
40
|
+
env: Record<string, string | undefined> = process.env,
|
|
41
|
+
): CapabilityPlugin {
|
|
42
|
+
return {
|
|
43
|
+
id: MCP_MANAGER_PLUGIN_ID,
|
|
44
|
+
kind: "capability",
|
|
45
|
+
label: "MCP Manager",
|
|
46
|
+
description: "MCP servers the companion declares in framework.yaml.",
|
|
47
|
+
defaultSelected: false,
|
|
48
|
+
selectable: false,
|
|
49
|
+
isEnabled: (config) => config.mcpManager !== undefined,
|
|
50
|
+
getInstallRequirements: () => [],
|
|
51
|
+
async apply(ctx) {
|
|
52
|
+
const servers = resolveMcpServers(ctx.config, readAudienceSelection(env));
|
|
53
|
+
if (servers.length === 0) return;
|
|
54
|
+
const owners = (await ctx.mcp?.owners?.()) ?? new Map<string, string>();
|
|
55
|
+
const declared = Object.keys(ctx.config.mcpManager?.servers ?? {});
|
|
56
|
+
const clashes = declared.flatMap((name) => {
|
|
57
|
+
const owner = owners.get(name);
|
|
58
|
+
return owner ? [`"${name}" (also registered by the "${owner}" Capability)`] : [];
|
|
59
|
+
});
|
|
60
|
+
if (clashes.length > 0) {
|
|
61
|
+
const reason = `${MCP_MANAGER_PLUGIN_ID}: error: mcpManager declares MCP server ${clashes.join(", ")}; rename it in mcpManager.servers. No mcpManager server was rendered.`;
|
|
62
|
+
if (ctx.mcp?.withhold) {
|
|
63
|
+
ctx.mcp.withhold(reason);
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
throw new Error(reason);
|
|
67
|
+
}
|
|
68
|
+
for (const server of servers) {
|
|
69
|
+
await ctx.mcp?.register(toMcpServerDescriptor(server));
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
async teardown() {},
|
|
73
|
+
};
|
|
74
|
+
}
|
|
@@ -199,6 +199,8 @@ export interface PluginContextServices {
|
|
|
199
199
|
services: { mcp: McpService; instructions: InstructionsService; templates: TemplatesService };
|
|
200
200
|
/** MCP server names and instruction block keys registered during this run. */
|
|
201
201
|
registered: { mcpServers: Set<string>; instructionBlocks: Set<string> };
|
|
202
|
+
/** Set by `mcp.withhold`: finalize keeps this plugin's previous MCP servers and their record. */
|
|
203
|
+
mcpWithheld?: boolean;
|
|
202
204
|
}
|
|
203
205
|
|
|
204
206
|
export interface ContextServiceMediatorOptions {
|
|
@@ -207,6 +209,8 @@ export interface ContextServiceMediatorOptions {
|
|
|
207
209
|
hostingProviders: HostingProvider[];
|
|
208
210
|
assetOverrideRoots?: string[];
|
|
209
211
|
warn(message: string): void;
|
|
212
|
+
/** MCP server names enabled Capabilities declare as contributions, by name to plugin id. */
|
|
213
|
+
declaredMcpOwners?(): Promise<ReadonlyMap<string, string>>;
|
|
210
214
|
}
|
|
211
215
|
|
|
212
216
|
/**
|
|
@@ -244,11 +248,25 @@ export class ContextServiceMediator {
|
|
|
244
248
|
);
|
|
245
249
|
return;
|
|
246
250
|
}
|
|
251
|
+
if (entry?.mcpWithheld) return;
|
|
247
252
|
for (const provider of hosts) {
|
|
248
253
|
await provider.hosting.mcp?.register(ctx, descriptor);
|
|
249
254
|
}
|
|
250
255
|
registered.mcpServers.add(descriptor.name);
|
|
251
256
|
},
|
|
257
|
+
owners: async () => {
|
|
258
|
+
const owners = new Map(await this.options.declaredMcpOwners?.());
|
|
259
|
+
for (const [otherId, other] of this.byPlugin) {
|
|
260
|
+
if (otherId === pluginId) continue;
|
|
261
|
+
for (const name of other.registered.mcpServers) owners.set(name, otherId);
|
|
262
|
+
}
|
|
263
|
+
owners.forEach((owner, name) => owner === pluginId && owners.delete(name));
|
|
264
|
+
return owners;
|
|
265
|
+
},
|
|
266
|
+
withhold: (reason: string) => {
|
|
267
|
+
if (entry) entry.mcpWithheld = true;
|
|
268
|
+
warn(reason);
|
|
269
|
+
},
|
|
252
270
|
};
|
|
253
271
|
|
|
254
272
|
const instructions: InstructionsService = {
|
|
@@ -297,6 +315,13 @@ export class ContextServiceMediator {
|
|
|
297
315
|
return entry;
|
|
298
316
|
}
|
|
299
317
|
|
|
318
|
+
/** MCP server names any plugin registered in this pass. */
|
|
319
|
+
registeredMcpServers(): Set<string> {
|
|
320
|
+
return new Set(
|
|
321
|
+
[...this.byPlugin.values()].flatMap((entry) => [...entry.registered.mcpServers]),
|
|
322
|
+
);
|
|
323
|
+
}
|
|
324
|
+
|
|
300
325
|
/**
|
|
301
326
|
* Reconcile the bookkeeping manifest: remove provider entries that were
|
|
302
327
|
* previously registered but not re-registered in this run, then persist the
|
|
@@ -307,11 +332,17 @@ export class ContextServiceMediator {
|
|
|
307
332
|
const manifestPath = getContextServicesManifestPath(ctx.companionPath, frameworkName);
|
|
308
333
|
const manifest = await loadManifest(manifestPath);
|
|
309
334
|
|
|
335
|
+
/** A name that moved to another plugin this pass is that plugin's now, never removed. */
|
|
336
|
+
const registeredThisPass = this.registeredMcpServers();
|
|
337
|
+
|
|
310
338
|
for (const [pluginId, entry] of this.byPlugin) {
|
|
311
339
|
const previous = manifest.plugins[pluginId] ?? {};
|
|
312
|
-
const
|
|
313
|
-
(
|
|
314
|
-
|
|
340
|
+
const mcpServers = entry.mcpWithheld
|
|
341
|
+
? (previous.mcpServers ?? [])
|
|
342
|
+
: [...entry.registered.mcpServers];
|
|
343
|
+
const staleMcpServers = entry.mcpWithheld
|
|
344
|
+
? []
|
|
345
|
+
: (previous.mcpServers ?? []).filter((name) => !registeredThisPass.has(name));
|
|
315
346
|
const staleBlocks = (previous.instructionBlocks ?? []).filter(
|
|
316
347
|
(blockKey) => !entry.registered.instructionBlocks.has(blockKey),
|
|
317
348
|
);
|
|
@@ -329,9 +360,7 @@ export class ContextServiceMediator {
|
|
|
329
360
|
}
|
|
330
361
|
|
|
331
362
|
const record: PluginServiceRecord = {};
|
|
332
|
-
if (
|
|
333
|
-
record.mcpServers = [...entry.registered.mcpServers];
|
|
334
|
-
}
|
|
363
|
+
if (mcpServers.length > 0) record.mcpServers = mcpServers;
|
|
335
364
|
if (entry.registered.instructionBlocks.size > 0) {
|
|
336
365
|
record.instructionBlocks = [...entry.registered.instructionBlocks];
|
|
337
366
|
}
|
|
@@ -16,7 +16,7 @@ export const AUDIENCE_ENV = "MATE_AUDIENCE";
|
|
|
16
16
|
export const BASE_AUDIENCE = "base";
|
|
17
17
|
|
|
18
18
|
/** The keys 0.18.4 moved under `audiences.base`; companion-wide keys stayed at the root. */
|
|
19
|
-
export const BASE_AUDIENCE_KEYS = ["capabilities", "plugins", "studio"] as const;
|
|
19
|
+
export const BASE_AUDIENCE_KEYS = ["capabilities", "plugins", "studio", "mcpManager"] as const;
|
|
20
20
|
|
|
21
21
|
export type AudienceResolution =
|
|
22
22
|
| { ok: true; active: string | null }
|
|
@@ -30,7 +30,8 @@ function pluginList(value: unknown): unknown[] {
|
|
|
30
30
|
return isRecord(value) && Array.isArray(value.plugins) ? value.plugins : [];
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
|
|
33
|
+
/** The raw entry of a declared audience; undefined for none, `base` or an undeclared one. */
|
|
34
|
+
export function audienceEntry(raw: unknown, audience: string | null): unknown {
|
|
34
35
|
if (audience === null || audience === BASE_AUDIENCE) return undefined;
|
|
35
36
|
if (!isRecord(raw) || !isRecord(raw.audiences)) return undefined;
|
|
36
37
|
return Object.hasOwn(raw.audiences, audience) ? raw.audiences[audience] : undefined;
|
|
@@ -4,6 +4,7 @@ import { FRAMEWORK_NAME } from "../../framework";
|
|
|
4
4
|
import type { FrameworkConfig } from "../../lib/orchestrator/types";
|
|
5
5
|
import { getClaudePluginRoot } from "../../lib/package-paths";
|
|
6
6
|
import type { RenderedRuntimeDocuments } from "../../runtime/runtime-document-manifest";
|
|
7
|
+
import { MCP_MANAGER_PLUGIN_ID } from "./capabilities/mcp-manager";
|
|
7
8
|
import { collectHostingProviders, ContextServiceMediator } from "./context-services";
|
|
8
9
|
import type {
|
|
9
10
|
CapabilityContributionInput,
|
|
@@ -55,6 +56,19 @@ export interface SetupInstallationOutcome {
|
|
|
55
56
|
claudePluginFolders: ClaudePluginFolders;
|
|
56
57
|
}
|
|
57
58
|
|
|
59
|
+
/**
|
|
60
|
+
* A phase's entries in registration order, except that `mcp-manager` applies
|
|
61
|
+
* after every other Capability, including hydrated ones, so its clash check
|
|
62
|
+
* sees the servers they register.
|
|
63
|
+
*/
|
|
64
|
+
function phaseEntries(entries: NormalizedRegistration[], phase: Plugin["kind"]) {
|
|
65
|
+
const inPhase = entries.filter((candidate) => candidate.plugin.kind === phase);
|
|
66
|
+
return [
|
|
67
|
+
...inPhase.filter((entry) => entry.plugin.id !== MCP_MANAGER_PLUGIN_ID),
|
|
68
|
+
...inPhase.filter((entry) => entry.plugin.id === MCP_MANAGER_PLUGIN_ID),
|
|
69
|
+
];
|
|
70
|
+
}
|
|
71
|
+
|
|
58
72
|
export function buildSetupInstallationPlan(
|
|
59
73
|
config: FrameworkConfig,
|
|
60
74
|
registrations: PluginRegistration[],
|
|
@@ -78,7 +92,7 @@ export function buildSetupInstallationPlan(
|
|
|
78
92
|
"integration",
|
|
79
93
|
"root",
|
|
80
94
|
] as const) {
|
|
81
|
-
for (const entry of entries
|
|
95
|
+
for (const entry of phaseEntries(entries, phase)) {
|
|
82
96
|
const plugin = entry.plugin;
|
|
83
97
|
if (phase === "root") {
|
|
84
98
|
actions.push({ phase, pluginId: plugin.id, action: "apply" });
|
|
@@ -145,6 +159,18 @@ export async function executeSetupInstallationPlan(
|
|
|
145
159
|
warnings.push(message);
|
|
146
160
|
emitWarning(message);
|
|
147
161
|
},
|
|
162
|
+
declaredMcpOwners: async () => {
|
|
163
|
+
const owners = new Map<string, string>();
|
|
164
|
+
/** A rejecting Capability fails the reconcile below, which reports it. */
|
|
165
|
+
const inputs = await collectContributionInputs(ctx, plugins, plan, () => {});
|
|
166
|
+
for (const input of [...inputs.values()].flat()) {
|
|
167
|
+
if (!input.capabilityEnabled) continue;
|
|
168
|
+
for (const server of input.contributions.mcpServers ?? []) {
|
|
169
|
+
owners.set(server.name, input.pluginId);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
return owners;
|
|
173
|
+
},
|
|
148
174
|
});
|
|
149
175
|
|
|
150
176
|
for (const action of plan.actions) {
|
|
@@ -196,7 +222,12 @@ export async function executeSetupInstallationPlan(
|
|
|
196
222
|
|
|
197
223
|
await mediator.finalize();
|
|
198
224
|
|
|
199
|
-
const inputsByRuntime = await reconcileCapabilityContributions(
|
|
225
|
+
const inputsByRuntime = await reconcileCapabilityContributions(
|
|
226
|
+
ctx,
|
|
227
|
+
plugins,
|
|
228
|
+
plan,
|
|
229
|
+
mediator.registeredMcpServers(),
|
|
230
|
+
);
|
|
200
231
|
const claudeInputs = inputsByRuntime.get("claude") ?? [];
|
|
201
232
|
const folderOptions = { bundledPluginRoot: getClaudePluginRoot() };
|
|
202
233
|
const claudePluginFolders =
|
|
@@ -305,16 +336,37 @@ async function reconcileCapabilityContributions(
|
|
|
305
336
|
ctx: SetupContext,
|
|
306
337
|
plugins: Plugin[],
|
|
307
338
|
plan: SetupInstallationPlan,
|
|
339
|
+
registeredMcpServers: ReadonlySet<string>,
|
|
308
340
|
): Promise<Map<string, CapabilityContributionInput[]>> {
|
|
309
341
|
const inputsByRuntime = await collectContributionInputs(ctx, plugins, plan);
|
|
310
342
|
for (const [runtimeId, inputs] of inputsByRuntime) {
|
|
311
343
|
const reconcile = RUNTIME_SURFACE_RECONCILERS[runtimeId];
|
|
312
344
|
if (!reconcile || inputs.length === 0) continue;
|
|
313
|
-
|
|
345
|
+
/** The mediator registers through active runtimes only. */
|
|
346
|
+
const spared = plan.activeProviders.includes(runtimeId)
|
|
347
|
+
? registeredMcpServers
|
|
348
|
+
: new Set<string>();
|
|
349
|
+
await reconcile(
|
|
350
|
+
ctx,
|
|
351
|
+
inputs.map((input) => sparingRegistered(input, spared)),
|
|
352
|
+
);
|
|
314
353
|
}
|
|
315
354
|
return inputsByRuntime;
|
|
316
355
|
}
|
|
317
356
|
|
|
357
|
+
/** A disabled Capability's teardown never removes a name another plugin registered this pass. */
|
|
358
|
+
function sparingRegistered(
|
|
359
|
+
input: CapabilityContributionInput,
|
|
360
|
+
registered: ReadonlySet<string>,
|
|
361
|
+
): CapabilityContributionInput {
|
|
362
|
+
const servers = input.contributions.mcpServers;
|
|
363
|
+
if (input.capabilityEnabled || !servers?.some((server) => registered.has(server.name))) {
|
|
364
|
+
return input;
|
|
365
|
+
}
|
|
366
|
+
const mcpServers = servers.filter((server) => !registered.has(server.name));
|
|
367
|
+
return { ...input, contributions: { ...input.contributions, mcpServers } };
|
|
368
|
+
}
|
|
369
|
+
|
|
318
370
|
/** Receives one Capability's rejected contributions; that Capability then contributes nothing. */
|
|
319
371
|
export type ContributionErrorHandler = (capabilityId: string, error: unknown) => void;
|
|
320
372
|
|
|
@@ -78,11 +78,25 @@ export interface McpServerDescriptor {
|
|
|
78
78
|
command?: string;
|
|
79
79
|
args?: string[];
|
|
80
80
|
url?: string;
|
|
81
|
+
/** Remote transport; absent leaves the runtime's default. */
|
|
82
|
+
transport?: "http" | "sse";
|
|
83
|
+
/** Literal values, written as given. */
|
|
81
84
|
env?: Record<string, string>;
|
|
85
|
+
/** Variable names the runtime expands at start; a value is never written. */
|
|
86
|
+
envRefs?: string[];
|
|
87
|
+
/** Header name to a literal prefix and one variable the runtime expands at start. */
|
|
88
|
+
headerRefs?: Record<string, { prefix: string; variable: string }>;
|
|
82
89
|
}
|
|
83
90
|
|
|
84
91
|
export interface McpService {
|
|
85
92
|
register(descriptor: McpServerDescriptor): Promise<void>;
|
|
93
|
+
/**
|
|
94
|
+
* MCP server names other plugins own in this pass, by name to plugin id:
|
|
95
|
+
* those registered so far and those enabled Capabilities declare.
|
|
96
|
+
*/
|
|
97
|
+
owners?(): Promise<ReadonlyMap<string, string>>;
|
|
98
|
+
/** Registers nothing more this pass and keeps the plugin's previous servers in place, reporting `reason`. */
|
|
99
|
+
withhold?(reason: string): void;
|
|
86
100
|
}
|
|
87
101
|
|
|
88
102
|
export interface InstructionsService {
|
|
@@ -11,9 +11,38 @@ export interface McpEntryDescriptor {
|
|
|
11
11
|
command?: string;
|
|
12
12
|
args?: string[];
|
|
13
13
|
url?: string;
|
|
14
|
+
transport?: "http" | "sse";
|
|
14
15
|
env?: Record<string, string>;
|
|
16
|
+
envRefs?: string[];
|
|
17
|
+
headerRefs?: Record<string, { prefix: string; variable: string }>;
|
|
15
18
|
}
|
|
16
19
|
|
|
20
|
+
/** Literal `env` plus each reference rendered by `ref`; undefined when there is neither. */
|
|
21
|
+
export function mcpEntryEnvironment(
|
|
22
|
+
descriptor: McpEntryDescriptor,
|
|
23
|
+
ref: (variable: string) => string,
|
|
24
|
+
): Record<string, string> | undefined {
|
|
25
|
+
if (!descriptor.env && !descriptor.envRefs?.length) return undefined;
|
|
26
|
+
return {
|
|
27
|
+
...descriptor.env,
|
|
28
|
+
...Object.fromEntries((descriptor.envRefs ?? []).map((name) => [name, ref(name)])),
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** Header references rendered by `ref`; undefined when there are none. */
|
|
33
|
+
export function mcpEntryHeaders(
|
|
34
|
+
descriptor: McpEntryDescriptor,
|
|
35
|
+
ref: (variable: string) => string,
|
|
36
|
+
): Record<string, string> | undefined {
|
|
37
|
+
const entries = Object.entries(descriptor.headerRefs ?? {});
|
|
38
|
+
if (entries.length === 0) return undefined;
|
|
39
|
+
return Object.fromEntries(
|
|
40
|
+
entries.map(([header, { prefix, variable }]) => [header, `${prefix}${ref(variable)}`]),
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const claudeRef = (variable: string) => `\${${variable}}`;
|
|
45
|
+
|
|
17
46
|
// Claude runtime config format primitives: parse/merge/serialize for
|
|
18
47
|
// `settings.local.json` (hook maps, permissions) and `.mcp.json`. Which hook
|
|
19
48
|
// groups are Mate-managed lives here too, because the companion-side reconcile
|
|
@@ -165,11 +194,19 @@ export async function writeClaudeMcpConfig(
|
|
|
165
194
|
|
|
166
195
|
/** Map a provider-agnostic MCP descriptor to Claude's `.mcp.json` entry shape. */
|
|
167
196
|
export function toClaudeMcpEntry(descriptor: McpEntryDescriptor): Record<string, unknown> {
|
|
168
|
-
if (descriptor.url)
|
|
197
|
+
if (descriptor.url) {
|
|
198
|
+
const headers = mcpEntryHeaders(descriptor, claudeRef);
|
|
199
|
+
return {
|
|
200
|
+
...(descriptor.transport ? { type: descriptor.transport } : {}),
|
|
201
|
+
url: descriptor.url,
|
|
202
|
+
...(headers ? { headers } : {}),
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
const env = mcpEntryEnvironment(descriptor, claudeRef);
|
|
169
206
|
return {
|
|
170
207
|
command: descriptor.command,
|
|
171
208
|
...(descriptor.args ? { args: descriptor.args } : {}),
|
|
172
|
-
...(
|
|
209
|
+
...(env ? { env } : {}),
|
|
173
210
|
};
|
|
174
211
|
}
|
|
175
212
|
|
|
@@ -800,6 +800,12 @@ async function teardownClaude(companionPath: string, allowedAgents: string[]): P
|
|
|
800
800
|
}
|
|
801
801
|
}
|
|
802
802
|
|
|
803
|
+
async function removeHubAppliedClaudeFiles(ctx: SetupContext): Promise<void> {
|
|
804
|
+
await fs.rm(getCompanionClaudeSettingsPath(ctx.companionPath), { force: true });
|
|
805
|
+
await fs.rm(getCompanionClaudeMcpConfigPath(ctx.companionPath), { force: true });
|
|
806
|
+
await pruneEmptyAncestors(path.join(ctx.companionPath, ".claude"), ctx.companionPath);
|
|
807
|
+
}
|
|
808
|
+
|
|
803
809
|
async function teardownLegacyClaudeBin(companionPath: string): Promise<void> {
|
|
804
810
|
try {
|
|
805
811
|
await fs.rm(path.join(companionPath, ".claude", "bin"), { recursive: true, force: true });
|
|
@@ -946,6 +952,10 @@ export function createClaudePlugin(): ProviderPlugin {
|
|
|
946
952
|
await syncCompanionClaudeSettings(ctx.companionPath, ctx.config);
|
|
947
953
|
},
|
|
948
954
|
async teardown(ctx) {
|
|
955
|
+
if (ctx.scope === "hub") {
|
|
956
|
+
await removeHubAppliedClaudeFiles(ctx);
|
|
957
|
+
return;
|
|
958
|
+
}
|
|
949
959
|
await teardownClaude(ctx.companionPath, ctx.config.allowedAgents ?? []);
|
|
950
960
|
},
|
|
951
961
|
};
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import fs from "node:fs/promises";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
|
|
4
|
-
import type
|
|
4
|
+
import { mcpEntryEnvironment, mcpEntryHeaders, type McpEntryDescriptor } from "./claude-format";
|
|
5
|
+
|
|
6
|
+
const openCodeRef = (variable: string) => `{env:${variable}}`;
|
|
5
7
|
|
|
6
8
|
// OpenCode V2 config format primitives, plus the one-time V1-to-V2 normalization
|
|
7
9
|
// used while reconciling an existing companion config. This module owns file
|
|
@@ -299,12 +301,20 @@ export function mergeOpenCodeConfigContent(
|
|
|
299
301
|
/** Map a provider-agnostic MCP descriptor to OpenCode V2's server entry shape. */
|
|
300
302
|
export function toOpenCodeMcpEntry(descriptor: McpEntryDescriptor): Record<string, unknown> {
|
|
301
303
|
if (descriptor.url) {
|
|
302
|
-
|
|
304
|
+
// OpenCode picks the remote transport itself, so `transport` is not rendered.
|
|
305
|
+
const headers = mcpEntryHeaders(descriptor, openCodeRef);
|
|
306
|
+
return {
|
|
307
|
+
type: "remote",
|
|
308
|
+
url: descriptor.url,
|
|
309
|
+
...(headers ? { headers } : {}),
|
|
310
|
+
disabled: false,
|
|
311
|
+
};
|
|
303
312
|
}
|
|
313
|
+
const environment = mcpEntryEnvironment(descriptor, openCodeRef);
|
|
304
314
|
return {
|
|
305
315
|
type: "local",
|
|
306
316
|
command: [descriptor.command ?? "", ...(descriptor.args ?? [])].filter(Boolean),
|
|
307
|
-
...(
|
|
317
|
+
...(environment ? { environment } : {}),
|
|
308
318
|
disabled: false,
|
|
309
319
|
};
|
|
310
320
|
}
|