diff --git a/docs/config/mcp-servers.mdx b/docs/config/mcp-servers.mdx index 9b0f2fc1a9f..ea8c8290177 100644 --- a/docs/config/mcp-servers.mdx +++ b/docs/config/mcp-servers.mdx @@ -68,7 +68,7 @@ A remote plugin server can declare OAuth sign-in settings (a client, scopes, an Stdio plugin servers launch with the spec's `PLUGIN_ROOT` and `PLUGIN_DATA` environment variables; per-plugin data directories live under `~/.xum/plugin-data/`. -**Settings → Plugins** installs plugins from git into `~/.xum/plugins` (paste a git URL or `owner/repo[/path/to/plugin][@ref]`); the exact location derives from the active Xum home (a legacy `~/.mux` home keeps working) and is shown in the section. Before anything is written, a consent preview lists the plugin's manifest, every skill, and every MCP server command line. Installs are pinned to the resolved commit; update checks compare the tracked branch or tag against the pinned commit and never auto-apply. With a monorepo subpath (for example `cursor/plugins/pstack`; for a full git URL, enter the folder in the **Plugin folder** field), Xum downloads only that folder's files (a sparse, partial clone) and installs it as the plugin, and the consent preview and update reviews cover only that folder: an upstream commit that changes only files outside it still shows as an update, but applies without a new review. Applying an update replaces the plugin directory wholesale — local edits to a managed plugin directory are discarded — and restarts that plugin's running MCP servers. Uninstalling removes the directory, the registry entry, and the plugin's global enablement and per-workspace server overrides, but keeps `~/.xum/plugin-data/` unless you opt in to deleting it. +**Settings → Plugins** installs plugins from git into `~/.xum/plugins` (paste a git URL or `owner/repo[/path/to/plugin][@ref]`); the exact location derives from the active Xum home (a legacy `~/.mux` home keeps working) and is shown in the section. Before anything is written, a consent preview lists the plugin's manifest, every skill, and every MCP server command line. Installs are pinned to the resolved commit; update checks compare the tracked branch or tag against the pinned commit and never auto-apply. With a monorepo subpath (for example `cursor/plugins/pstack`; for a full git URL, enter the folder in the **Plugin folder** field), Xum downloads only that folder's files (a sparse, partial clone) and installs it as the plugin, and the consent preview and update reviews cover only that folder: an upstream commit that changes only files outside it still shows as an update, but applies without a new review. Applying an update replaces the plugin directory wholesale — local edits to a managed plugin directory are discarded — and restarts that plugin's running MCP servers. An update also signs out of a remote server whose sign-in settings change or that the update removes. Uninstalling removes the directory, the registry entry, the plugin's global enablement and per-workspace server overrides, and the stored sign-in of each remote MCP server it declares, but keeps `~/.xum/plugin-data/` unless you opt in to deleting it. Stored sign-ins are keyed by server URL, so another server at the same URL is signed out too. ### Plugin server environment diff --git a/src/node/services/agentPlugins/installService.test.ts b/src/node/services/agentPlugins/installService.test.ts index bfbb8a4208d..0facbeb452d 100644 --- a/src/node/services/agentPlugins/installService.test.ts +++ b/src/node/services/agentPlugins/installService.test.ts @@ -32,6 +32,7 @@ import { import { AgentPluginInstallService, describeSignInChanges, + signInResetUrls, withDiskQuotaWatchdog, } from "./installService"; import { @@ -4568,6 +4569,279 @@ describe("AgentPluginInstallService", () => { await oauth.dispose(); }); + describe("stored sign-ins of plugin MCP servers that an update removes or an uninstall deletes", () => { + const docsUrl = "https://docs.example.com/mcp"; + const keepUrl = "https://keep.example.com/mcp"; + const oauthEntry = (url: string, clientId: string) => ({ + type: "streamable-http", + url, + extensions: { + "com.openai": { auth: { type: "oauth", client: { mode: "provided", clientId } } }, + }, + }); + const writeServers = async (servers: Record | undefined) => { + const file = path.join(remoteDir, "mcp.json"); + if (servers === undefined) await fsPromises.rm(file); + else + await fsPromises.writeFile( + file, + JSON.stringify({ $schema: AGENT_PLUGIN_MCP_SCHEMA_ID_1_0_0, mcpServers: servers }) + ); + await commitAll(remoteDir, Object.keys(servers ?? {}).join(" ") || "no MCP file"); + }; + const signedInStore = (urls: string[]) => + JSON.stringify({ + version: 2, + entries: Object.fromEntries( + urls.map((serverUrl) => [ + serverUrl, + { + serverUrl, + updatedAtMs: Date.now(), + clientInformation: { client_id: "client-a" }, + tokens: { access_token: "at", token_type: "Bearer" }, + }, + ]) + ), + }); + const pendingRecord = (): Promise => + fsPromises.readFile(path.join(muxRoot, "plugin-sign-outs-pending.json"), "utf8").then( + (text) => JSON.parse(text) as unknown, + () => null + ); + const installSignedIn = async ( + servers: Record, + signedInUrls: string[], + hooks: { onStop?: () => Promise; mcpConfigService?: MCPConfigService } = {} + ) => { + const updater = new AgentPluginInstallService(config, { + mcpServerManager: { + stopServersWithKeyPrefix: () => hooks.onStop?.() ?? Promise.resolve(), + } as unknown as MCPServerManager, + ...(hooks.mcpConfigService !== undefined + ? { mcpConfigService: hooks.mcpConfigService } + : {}), + }); + await writeServers(servers); + const preview = await updater.preview({ input: remoteDir }); + await updater.install({ source: preview.source, expectedSha: preview.lockedSha }); + await fsPromises.writeFile(path.join(muxRoot, "mcp-oauth.json"), signedInStore(signedInUrls)); + const oauth = new McpOauthService(config, new MCPConfigService(config)); + updater.setMcpOauthService(oauth); + const update = async (servers: Record | undefined) => { + await writeServers(servers); + const review = await updater.previewUpdate({ name: "demo-plugin" }); + await updater.update({ + name: "demo-plugin", + consent: { fromSha: review.fromSha, toSha: review.toSha }, + }); + }; + return { updater, oauth, update }; + }; + + // The 20 s limits: each test installs and updates a plugin over git, which takes more than the + // default 5 s on a loaded runner. + test("signs out the removed server, so a later server at its URL does not inherit the credentials", async () => { + const { oauth, update } = await installSignedIn( + { docs: oauthEntry(docsUrl, "client-a"), keep: oauthEntry(keepUrl, "client-k") }, + [docsUrl, keepUrl] + ); + await update({ keep: oauthEntry(keepUrl, "client-k") }); + expect(await oauth.hasAuthTokens({ serverUrl: docsUrl })).toBe(false); + expect(await oauth.hasAuthTokens({ serverUrl: keepUrl })).toBe(true); + await update({ + keep: oauthEntry(keepUrl, "client-k"), + docs: oauthEntry(docsUrl, "client-b"), + }); + expect(await oauth.hasAuthTokens({ serverUrl: docsUrl })).toBe(false); + await oauth.dispose(); + }, 20_000); + + test("signs out every server when the update drops the plugin's MCP file", async () => { + const { oauth, update } = await installSignedIn({ docs: oauthEntry(docsUrl, "client-a") }, [ + docsUrl, + ]); + await update(undefined); + expect(await oauth.hasAuthTokens({ serverUrl: docsUrl })).toBe(false); + await oauth.dispose(); + }, 20_000); + + test("an uninstall signs out the plugin's servers, so a reinstall under another client does not inherit them", async () => { + const { updater, oauth } = await installSignedIn({ docs: oauthEntry(docsUrl, "client-a") }, [ + docsUrl, + ]); + await updater.uninstall({ name: "demo-plugin", deletePluginData: false }); + expect(await oauth.hasAuthTokens({ serverUrl: docsUrl })).toBe(false); + await writeServers({ docs: oauthEntry(docsUrl, "client-b") }); + const preview = await updater.preview({ input: remoteDir }); + await updater.install({ source: preview.source, expectedSha: preview.lockedSha }); + expect(await oauth.hasAuthTokens({ serverUrl: docsUrl })).toBe(false); + await oauth.dispose(); + }, 20_000); + + test("an uninstall whose sign-out fails leaves the URL pending for the next pass", async () => { + const { updater, oauth } = await installSignedIn({ docs: oauthEntry(docsUrl, "client-a") }, [ + docsUrl, + ]); + spyOn(oauth, "logout").mockResolvedValue({ success: false, error: "disk full" }); + await updater.uninstall({ name: "demo-plugin", deletePluginData: false }); + expect(await registry()).toEqual([]); + const record = await fsPromises.readFile( + path.join(muxRoot, "plugin-sign-outs-pending.json"), + "utf8" + ); + expect(JSON.parse(record)).toEqual({ version: 1, urls: [docsUrl] }); + await oauth.dispose(); + }, 20_000); + + test("an uninstall that fails keeps the sign-in and records no sign-out", async () => { + const { updater, oauth } = await installSignedIn({ docs: oauthEntry(docsUrl, "client-a") }, [ + docsUrl, + ]); + const internals = updater as unknown as { + writeRegistry: (envelope: Record, entries: unknown[]) => Promise; + }; + const writeSpy = spyOn(internals, "writeRegistry").mockImplementationOnce(() => + Promise.reject(new Error("ENOSPC: no space left on device")) + ); + try { + await expect( + updater.uninstall({ name: "demo-plugin", deletePluginData: false }) + ).rejects.toThrow(/persist the plugin registry/); + } finally { + writeSpy.mockRestore(); + } + expect(await registry()).toHaveLength(1); + expect(await oauth.hasAuthTokens({ serverUrl: docsUrl })).toBe(true); + expect(await pathExists(path.join(muxRoot, "plugin-sign-outs-pending.json"))).toBe(false); + await oauth.dispose(); + }, 20_000); + + test("a plugin whose MCP file cannot be read can still be uninstalled", async () => { + const { updater, oauth } = await installSignedIn({ docs: oauthEntry(docsUrl, "client-a") }, [ + docsUrl, + ]); + await fsPromises.writeFile(path.join(pluginsDir(), "demo-plugin", "mcp.json"), "{ not json"); + await updater.uninstall({ name: "demo-plugin", deletePluginData: false }); + expect(await registry()).toEqual([]); + await oauth.dispose(); + }, 20_000); + test("an update records its sign-outs before the old tree stops and moves", async () => { + let armed = false; + let atFirstStop: unknown = "not read"; + const { update, oauth } = await installSignedIn( + { docs: oauthEntry(docsUrl, "client-a") }, + [docsUrl], + { + onStop: async () => { + if (armed && atFirstStop === "not read") atFirstStop = await pendingRecord(); + }, + } + ); + armed = true; + await update({ docs: oauthEntry(docsUrl, "client-b") }); + expect(atFirstStop).toEqual({ version: 1, urls: [docsUrl] }); + await oauth.dispose(); + }, 20_000); + + test("an uninstall records its sign-outs before the registry commit", async () => { + const { updater, oauth } = await installSignedIn({ docs: oauthEntry(docsUrl, "client-a") }, [ + docsUrl, + ]); + const internals = updater as unknown as { + writeRegistry: (envelope: Record, entries: unknown[]) => Promise; + }; + const realWrite = internals.writeRegistry.bind(internals); + let atCommit: unknown = "not read"; + const writeSpy = spyOn(internals, "writeRegistry").mockImplementation( + async (envelope, entries) => { + if (atCommit === "not read") atCommit = await pendingRecord(); + return realWrite(envelope, entries); + } + ); + try { + await updater.uninstall({ name: "demo-plugin", deletePluginData: false }); + } finally { + writeSpy.mockRestore(); + } + expect(atCommit).toEqual({ version: 1, urls: [docsUrl] }); + await oauth.dispose(); + }, 20_000); + + test("an uninstall refuses at once while the pending sign-out record is corrupt, and changes nothing", async () => { + const mcpConfigService = new MCPConfigService(config, { + agentPluginsMcpProvider: createAgentPluginsMcpProvider({ xumHome: muxRoot }), + }); + let armed = false; + let stops = 0; + const { updater, oauth } = await installSignedIn( + { docs: oauthEntry(docsUrl, "client-a") }, + [docsUrl], + { + mcpConfigService, + onStop: () => { + if (armed) stops++; + return Promise.resolve(); + }, + } + ); + const key = buildPluginServerKey( + computePluginInstanceId(path.join(pluginsDir(), "demo-plugin")), + "docs" + ); + expect(await mcpConfigService.setServerEnabled(key, true)).toEqual({ + success: true, + data: undefined, + }); + await fsPromises.writeFile(path.join(muxRoot, "plugin-sign-outs-pending.json"), "{ not json"); + armed = true; + const failure = await updater + .uninstall({ name: "demo-plugin", deletePluginData: false }) + .then( + () => undefined, + (error: unknown) => error as Error + ); + // The record's own error, naming the Settings recovery step, before anything moves. + expect(failure?.message).toMatch( + /^The pending plugin sign-out record .*Sign out of plugin MCP servers/ + ); + expect(stops).toBe(0); + // The record fences plugin discovery, so read the global enablement from its file. + const globalConfig = jsonc.parse( + await fsPromises.readFile(path.join(muxRoot, "mcp.jsonc"), "utf8") + ) as { enabledPluginServers?: string[] }; + expect(globalConfig.enabledPluginServers).toEqual([key]); + expect(await registry()).toHaveLength(1); + expect(await oauth.hasAuthTokens({ serverUrl: docsUrl })).toBe(true); + await oauth.dispose(); + }, 20_000); + + test("an uninstall of a plugin with no remote servers ignores a corrupt pending record", async () => { + const preview = await service.preview({ input: remoteDir }); + await service.install({ source: preview.source, expectedSha: preview.lockedSha }); + await fsPromises.writeFile(path.join(muxRoot, "plugin-sign-outs-pending.json"), "{ not json"); + await service.uninstall({ name: "demo-plugin", deletePluginData: false }); + expect(await registry()).toEqual([]); + }, 20_000); + + test("a plugin whose servers cannot be listed can still be uninstalled", async () => { + const { updater, oauth } = await installSignedIn({ docs: oauthEntry(docsUrl, "client-a") }, [ + docsUrl, + ]); + const discover = spyOn(discoveryModule, "discoverAgentPluginAt").mockRejectedValueOnce( + new Error("EACCES: permission denied") + ); + try { + await updater.uninstall({ name: "demo-plugin", deletePluginData: false }); + expect(discover).toHaveBeenCalled(); + } finally { + discover.mockRestore(); + } + expect(await registry()).toEqual([]); + await oauth.dispose(); + }, 20_000); + }); + test("an update review reads a Codex .mcp.json once per tree, not once per server", async () => { await fsPromises.rm(path.join(remoteDir, "mcp.json")); const servers = (secret: string) => @@ -8879,6 +9153,63 @@ describe("describeSignInChanges", () => { }); }); +describe("signInResetUrls", () => { + // The credential key drops a trailing slash, as McpOauthService.credentialKey does. + const key = (url: string): string | null => url.replace(/\/$/, ""); + const tree = (servers: Record) => + new Map( + Object.entries(servers).map(([name, signIn]) => [name, signIn === null ? {} : { signIn }]) + ); + const at = (url: string, identity: string) => ({ url, identity }); + const mcp = "https://mcp.example.com/mcp"; + + test("resets a server whose identity changes, and no server whose identity stays", () => { + expect(signInResetUrls(tree({ a: at(mcp, "x") }), tree({ a: at(mcp, "y") }), key)).toEqual([ + mcp, + ]); + expect(signInResetUrls(tree({ a: at(mcp, "x") }), tree({ a: at(mcp, "x") }), key)).toEqual([]); + }); + + test("matches by credential key: a respelled URL with the same identity is not a removal", () => { + expect( + signInResetUrls(tree({ a: at(mcp, "x") }), tree({ b: at(`${mcp}/`, "x") }), key) + ).toEqual([]); + expect( + signInResetUrls(tree({ a: at(mcp, "x") }), tree({ b: at(`${mcp}/`, "y") }), key) + ).toEqual([`${mcp}/`]); + }); + + test("a sibling that already has the new identity does not mask a change", () => { + const current = tree({ a: at(mcp, "x"), b: at(mcp, "y") }); + expect(signInResetUrls(current, tree({ a: at(mcp, "y"), b: at(mcp, "y") }), key)).toEqual([ + mcp, + ]); + }); + + test("a renamed entry has no previous self: any other identity at the key resets it", () => { + const current = tree({ a: at(mcp, "x"), b: at(mcp, "y") }); + expect(signInResetUrls(current, tree({ c: at(mcp, "y"), b: at(mcp, "y") }), key)).toEqual([ + mcp, + ]); + expect( + signInResetUrls(tree({ a: at(mcp, "y"), b: at(mcp, "y") }), tree({ c: at(mcp, "y") }), key) + ).toEqual([]); + }); + + test("resets the URL of each server the update removes, and no other", () => { + const other = "https://other.example.com/mcp"; + const current = tree({ a: at(mcp, "x"), b: at(other, "x"), local: null }); + expect(signInResetUrls(current, tree({ b: at(other, "x") }), key)).toEqual([mcp]); + expect(signInResetUrls(current, tree({}), key)).toEqual([mcp, other]); + }); + + test("a server added at a new key, a tree with no current servers and an unkeyed URL reset nothing", () => { + expect(signInResetUrls(tree({}), tree({ a: at(mcp, "x") }), key)).toEqual([]); + expect(signInResetUrls(undefined, tree({ a: at(mcp, "x") }), key)).toEqual([]); + expect(signInResetUrls(tree({ a: at(mcp, "x") }), tree({}), () => null)).toEqual([]); + }); +}); + describe("file review of a Cursor plugin with a runnable command hook (D1, D30)", () => { let muxRoot: string; let remoteDir: string; diff --git a/src/node/services/agentPlugins/installService.ts b/src/node/services/agentPlugins/installService.ts index 81728e50738..af2feea721c 100644 --- a/src/node/services/agentPlugins/installService.ts +++ b/src/node/services/agentPlugins/installService.ts @@ -1748,6 +1748,77 @@ export function describeSignInChanges(before?: SurfaceSignIn, after?: SurfaceSig return lines; } +interface SignInKeyEntry { + url: string; + identityByServerName: Map; +} + +function indexSignIns( + servers: ReadonlyMap | undefined, + credentialKey: (url: string) => string | null +): Map { + const index = new Map(); + // mutation-equivalent: a Map is never falsy, so ?? and || agree + for (const [serverName, { signIn }] of servers ?? []) { + const key = signIn && credentialKey(signIn.url); + if (!key || !signIn) continue; + // mutation-equivalent: an entry object is never falsy, so ?? and || agree + const entry = index.get(key) ?? { + url: signIn.url, + identityByServerName: new Map(), + }; + entry.identityByServerName.set(serverName, signIn.identity); + index.set(key, entry); + } + return index; +} + +/** + * Compare an entry with its own previous identity (same name, same key): when two servers share + * a URL, another entry already using the new identity must not mask the change. A renamed (or + * added) entry has no previous self, and the stored credentials cannot be traced to one entry: + * it changed whenever any identity at the key differs. + */ +function signInIdentityChanged( + before: ReadonlyMap, + serverName: string, + identity: string +): boolean { + const previous = before.get(serverName); + return previous !== undefined + ? previous !== identity + : [...before.values()].some((other) => other !== identity); +} + +/** + * The server URLs whose stored credentials an update must sign out: a key whose sign-in identity + * changes, and a key the update removes. A removed server keeps its credentials under its URL, + * and a later update can add a server at that URL under another identity with no current server + * left to show the change, so the removal is the only moment to sign out. A needless sign-out is + * acceptable; stale credentials offered under a new identity are not. + */ +export function signInResetUrls( + current: ReadonlyMap | undefined, + staged: ReadonlyMap, + credentialKey: (url: string) => string | null +): string[] { + const before = indexSignIns(current, credentialKey); + const after = indexSignIns(staged, credentialKey); + const resets: string[] = []; + for (const [key, now] of after) { + const was = before.get(key); + if ( + was !== undefined && + [...now.identityByServerName].some(([serverName, identity]) => + signInIdentityChanged(was.identityByServerName, serverName, identity) + ) + ) + resets.push(now.url); + } + for (const [key, was] of before) if (!after.has(key)) resets.push(was.url); + return resets; +} + const LOGO_MAX_BYTES = 512 * 1024; // No SVG: a data-URL cannot run script, but raster-only keeps the // renderer away from markup altogether. No GIF: OpenAI does not list it, and it @@ -3257,32 +3328,7 @@ export class AgentPluginInstallService { // respelled URL (`/mcp` vs `/mcp/`) with a new identity still resets. const credentialKey = (url: string): string | null => this.mcpOauthService?.credentialKey(url) ?? null; - // Compare each entry with its own previous identity (same name, same key): when two - // servers share a URL, another entry already using the new identity must not mask the - // change. A renamed (or added) entry has no previous self, and the stored credentials - // cannot be traced to one entry: reset whenever any identity at the key differs. A - // needless sign-out is acceptable; stale credentials offered under a new identity are not. - const currentIdentities = new Map>(); - const currentEntryIdentity = new Map(); - for (const [serverName, server] of current?.servers ?? []) { - const key = server.signIn && credentialKey(server.signIn.url); - if (!key || !server.signIn) continue; - const identities = currentIdentities.get(key) ?? new Set(); - identities.add(server.signIn.identity); - currentIdentities.set(key, identities); - currentEntryIdentity.set(`${serverName}\0${key}`, server.signIn.identity); - } - for (const [serverName, server] of staged.servers) { - const key = server.signIn && credentialKey(server.signIn.url); - if (!key || !server.signIn) continue; - const previous = currentEntryIdentity.get(`${serverName}\0${key}`); - const identity = server.signIn.identity; - const changed = - previous !== undefined - ? previous !== identity - : [...(currentIdentities.get(key) ?? [])].some((other) => other !== identity); - if (changed) signInResets?.push(server.signIn.url); - } + signInResets?.push(...signInResetUrls(current?.servers, staged.servers, credentialKey)); // Skill advertisements interpolate into the model-visible skill index on // every request, so a new skill — or a reworded description — can inject // instructions without the user ever invoking it. Gate both. @@ -5219,8 +5265,8 @@ export class AgentPluginInstallService { } /** - * Removes `urls` from the pending sign-outs: they finished, or the update rolled back before - * the new tree was live. Best effort: a leftover URL only signs the server out once more. + * Removes `urls` from the pending sign-outs: they finished, or the update or uninstall rolled + * back before it took effect. Best effort: a leftover URL only signs the server out once more. */ private async forgetPendingSignOuts(urls: readonly string[]): Promise { if (urls.length === 0) return; @@ -5232,7 +5278,7 @@ export class AgentPluginInstallService { } } - /** Signs out `urls` after an update; the ones that failed stay pending. */ + /** Signs out `urls` after an update or an uninstall; the ones that failed stay pending. */ private async signOutAndSettle(name: string, urls: string[]): Promise { const done: string[] = []; // One deadline for every wait of this update: N hung logouts must not hold the lock N times. @@ -5543,6 +5589,43 @@ export class AgentPluginInstallService { return urls; } + /** + * Throws the pending record's own error when an uninstall that will record sign-outs cannot + * read it. It runs before anything stops or moves: a failure at the commit would roll the tree + * back but not the global MCP enablement. + */ + private async assertPendingSignOutsReadable(urls: readonly string[]): Promise { + if (urls.length > 0) await this.readPendingSignOuts(); + } + + /** + * A server that fails to load is not listed. A tree Xum cannot read lists none: it must stay + * removable. + */ + private async installedServerUrls(name: string): Promise { + try { + const { plugin } = await discoverAgentPluginAt({ + pluginDir: this.targetPathFor(name), + scope: "global", + }); + // mutation-equivalent: a null plugin throws a TypeError, and the catch also returns [] + if (plugin?.mcpConfigPath === undefined) return []; + const { servers } = await loadPluginMcpServers(plugin, { + xumHome: this.config.rootDir, + instanceId: this.instanceIdFor(name), + }); + return Object.values(servers).flatMap((info) => + info.transport === "stdio" ? [] : [info.url] + ); + } catch (error) { + log.warn("Could not list the MCP servers of a plugin that is being uninstalled", { + plugin: name, + error: getErrorMessage(error), + }); + return []; + } + } + /** One plugin tree's remote MCP server URLs; throws when the tree's servers cannot be read. */ private async pluginTreeServerUrls(dirName: string, installed: boolean): Promise { // Plugin trees are directories (or links to one), dot-prefixed names included, as discovery @@ -5762,6 +5845,9 @@ export class AgentPluginInstallService { const targetPath = this.targetPathFor(entry.name); const instanceId = this.instanceIdFor(entry.name); const serverKeyPrefix = buildPluginServerKey(instanceId, ""); + // Read before the tree moves: its servers' stored sign-ins are keyed by URL and outlive it. + const signOutUrls = await this.installedServerUrls(entry.name); + await this.assertPendingSignOutsReadable(signOutUrls); // Enumerate pruning targets BEFORE committing anything: if this fails, // the uninstall aborts with the install fully intact (retryable from @@ -5898,7 +5984,11 @@ export class AgentPluginInstallService { } else { delete commitEnvelope.pendingOverridePrunes; } + let recordedSignOuts: string[] = []; try { + // Recorded before the commit, like an update's: a crash after it leaves the sign-outs for + // the next start (#6122). + recordedSignOuts = await this.recordPendingSignOuts(signOutUrls); // Before the commit, so a failure leaves trust and approved copies cleared (fail closed) // rather than kept for a later install under this name. await removePluginHookTrust(this.config.rootDir, this.instanceIdFor(entry.name)); @@ -5908,6 +5998,8 @@ export class AgentPluginInstallService { rawRegistry.filter((rawEntry) => this.rawEntryName(rawEntry) !== entry.name) ); } catch (error) { + // The plugin stays installed: its servers keep their sign-ins. + await this.forgetPendingSignOuts(recordedSignOuts); const treeRestored = await restoreTree("failed registry write"); let dataRestored = true; if (stagedData) { @@ -5988,6 +6080,10 @@ export class AgentPluginInstallService { await consumeJournal(); } + // Signed out before the final stop, like an update: a startup that raced the sign-out is + // invalidated too. + await this.signOutAndSettle(entry.name, signOutUrls); + // Re-invalidate AFTER the tree is gone: a getToolsForWorkspace call // that started right after the pre-rename stop snapshots the new epoch, // and can still have discovered the plugin before the rename — its diff --git a/src/node/services/agentSkills/builtInSkillContent.generated.ts b/src/node/services/agentSkills/builtInSkillContent.generated.ts index a2e210c6d31..566d88304cc 100644 --- a/src/node/services/agentSkills/builtInSkillContent.generated.ts +++ b/src/node/services/agentSkills/builtInSkillContent.generated.ts @@ -4974,7 +4974,7 @@ export const BUILTIN_SKILL_FILES: Record> = { "", "Stdio plugin servers launch with the spec's `PLUGIN_ROOT` and `PLUGIN_DATA` environment variables; per-plugin data directories live under `~/.xum/plugin-data/`.", "", - "**Settings → Plugins** installs plugins from git into `~/.xum/plugins` (paste a git URL or `owner/repo[/path/to/plugin][@ref]`); the exact location derives from the active Xum home (a legacy `~/.mux` home keeps working) and is shown in the section. Before anything is written, a consent preview lists the plugin's manifest, every skill, and every MCP server command line. Installs are pinned to the resolved commit; update checks compare the tracked branch or tag against the pinned commit and never auto-apply. With a monorepo subpath (for example `cursor/plugins/pstack`; for a full git URL, enter the folder in the **Plugin folder** field), Xum downloads only that folder's files (a sparse, partial clone) and installs it as the plugin, and the consent preview and update reviews cover only that folder: an upstream commit that changes only files outside it still shows as an update, but applies without a new review. Applying an update replaces the plugin directory wholesale — local edits to a managed plugin directory are discarded — and restarts that plugin's running MCP servers. Uninstalling removes the directory, the registry entry, and the plugin's global enablement and per-workspace server overrides, but keeps `~/.xum/plugin-data/` unless you opt in to deleting it.", + "**Settings → Plugins** installs plugins from git into `~/.xum/plugins` (paste a git URL or `owner/repo[/path/to/plugin][@ref]`); the exact location derives from the active Xum home (a legacy `~/.mux` home keeps working) and is shown in the section. Before anything is written, a consent preview lists the plugin's manifest, every skill, and every MCP server command line. Installs are pinned to the resolved commit; update checks compare the tracked branch or tag against the pinned commit and never auto-apply. With a monorepo subpath (for example `cursor/plugins/pstack`; for a full git URL, enter the folder in the **Plugin folder** field), Xum downloads only that folder's files (a sparse, partial clone) and installs it as the plugin, and the consent preview and update reviews cover only that folder: an upstream commit that changes only files outside it still shows as an update, but applies without a new review. Applying an update replaces the plugin directory wholesale — local edits to a managed plugin directory are discarded — and restarts that plugin's running MCP servers. An update also signs out of a remote server whose sign-in settings change or that the update removes. Uninstalling removes the directory, the registry entry, the plugin's global enablement and per-workspace server overrides, and the stored sign-in of each remote MCP server it declares, but keeps `~/.xum/plugin-data/` unless you opt in to deleting it. Stored sign-ins are keyed by server URL, so another server at the same URL is signed out too.", "", "### Plugin server environment", "",