From 626d48fe0a07fd4f8614ce0f3650434959a37dee Mon Sep 17 00:00:00 2001 From: Willie Date: Tue, 22 Sep 2026 02:01:36 +0800 Subject: [PATCH] fix(ui): offer only replace for a changed off switch, and name its project A project's off switch that was edited by hand in the Agent's file shows up as a conflict with "Import from Agent" next to it. Import reads the Agent's global file, which holds the server and never the project's switch, so it brought in something unrelated and the conflict stayed. Only replacing the entry settles it, so that is the one button offered. The conflict row also says which project folder it is in: one server can conflict in several, and two such rows shared a React key. Refs #289 --- ui/src/components/mcp/MCPPreview.tsx | 6 +++--- ui/src/components/mcp/mcpView.test.ts | 10 +++++++++- ui/src/components/mcp/mcpView.ts | 3 +++ ui/src/pages/MCPPage.tsx | 8 +++++--- 4 files changed, 20 insertions(+), 7 deletions(-) diff --git a/ui/src/components/mcp/MCPPreview.tsx b/ui/src/components/mcp/MCPPreview.tsx index aa340ef71..9a462a710 100644 --- a/ui/src/components/mcp/MCPPreview.tsx +++ b/ui/src/components/mcp/MCPPreview.tsx @@ -6,7 +6,7 @@ import Badge from '../Badge'; import Button from '../Button'; import { Checkbox } from '../Checkbox'; import { useT } from '../../i18n'; -import { countActions, describeMessage, groupByFile, isResolvable, statusVariant } from './mcpView'; +import { canImportConflict, countActions, describeMessage, groupByFile, isResolvable, statusVariant } from './mcpView'; export type MCPResolve = (target: string, name: string, action: 'import' | 'replace') => void; @@ -49,9 +49,9 @@ export default function MCPPreview({ plan, onResolve, busy = false }: Props) { {change.message ? {describeMessage(t, change.message)} : null} {onResolve && isResolvable(change) ?
- + {canImportConflict(change) ? : null} - {t('mcp.resolveHint', { target: change.target })} + {canImportConflict(change) ? {t('mcp.resolveHint', { target: change.target })} : null}
: null} )} diff --git a/ui/src/components/mcp/mcpView.test.ts b/ui/src/components/mcp/mcpView.test.ts index 26e7d1ff6..fa0b15efd 100644 --- a/ui/src/components/mcp/mcpView.test.ts +++ b/ui/src/components/mcp/mcpView.test.ts @@ -1,6 +1,6 @@ import { describe, expect, it } from 'vitest'; import type { MCPPlan } from '../../api/mcp'; -import { buildMatrix, describeError, describeMessage, groupByFile, isResolvable, joinCommand, splitCommand, switchTargets, targetLabel } from './mcpView'; +import { buildMatrix, describeError, describeMessage, canImportConflict, groupByFile, isResolvable, joinCommand, splitCommand, switchTargets, targetLabel } from './mcpView'; import { mcpTargets } from '../../api/mcp'; const change = (name: string, target: string, action: string, message?: string) => ({ name, target, action, message, path: `/${target}.json` }); @@ -81,3 +81,11 @@ describe('groupByFile', () => { expect(groups.map((g) => g.offListFor)).toEqual([undefined, '/work/app', undefined]); }); }); + +describe('canImportConflict', () => { + // Import reads the Agent's global file, which holds the server and never the project's switch. + it('offers no import for a changed switch, which only a replace can settle', () => { + const changed = { target: 'opencode', path: '/work/app/opencode.json', name: 'docs', action: 'conflict', message: 'Agent configuration changed; import it or explicitly replace this entry' }; + expect([canImportConflict(changed), canImportConflict({ ...changed, root: '/work/app', switch: true })]).toEqual([true, false]); + }); +}); diff --git a/ui/src/components/mcp/mcpView.ts b/ui/src/components/mcp/mcpView.ts index 4c8c7a94b..eff07b28f 100644 --- a/ui/src/components/mcp/mcpView.ts +++ b/ui/src/components/mcp/mcpView.ts @@ -111,6 +111,9 @@ export const isResolvable = (change: MCPChange) => change.action === 'conflict' && ['mcp.conflictChanged', 'mcp.conflictUnmanaged', 'mcp.conflictOrphaned'].includes(conflictKeys[conflictPrefix(change.message ?? '')]); +/** Whether importing can settle a conflict. It reads the Agent's global file, which never holds a project's switch. */ +export const canImportConflict = (change: MCPChange) => isResolvable(change) && !change.switch; + /** Agents a project can turn a global server off for: those it uses, that the server reaches and that have a switch. */ export const switchTargets = (server: MCPServer, defaults: string[], projectTargets: readonly string[]) => (server.targets ?? defaults).filter((x) => mcpOffTargets.includes(x) && projectTargets.includes(x) && (x !== 'pi' || server.piExtension === 'pi-mcp-adapter')); diff --git a/ui/src/pages/MCPPage.tsx b/ui/src/pages/MCPPage.tsx index c821e59af..fe9a8c340 100644 --- a/ui/src/pages/MCPPage.tsx +++ b/ui/src/pages/MCPPage.tsx @@ -22,7 +22,7 @@ import { MCPConfigDialog } from '../components/mcp/MCPConfigView'; import MCPRemoveDialog from '../components/mcp/MCPRemoveDialog'; import MCPRestoreDialog from '../components/mcp/MCPRestoreDialog'; import MCPServerDialog from '../components/mcp/MCPServerDialog'; -import { buildMatrix, describeError, describeMessage, isShadowed, isResolvable, targetLabel, type MCPChange } from '../components/mcp/mcpView'; +import { buildMatrix, canImportConflict, describeError, describeMessage, isShadowed, isResolvable, projectOf, targetLabel, type MCPChange } from '../components/mcp/mcpView'; import { useT } from '../i18n'; import { shortenHome } from '../lib/paths'; import { queryKeys } from '../lib/queryKeys'; @@ -214,13 +214,15 @@ export default function MCPPage() {
{conflicts.map((c, i) => ( -
+
{i === 0 && {t(conflicts.length === 1 ? 'mcp.conflictLead.one' : 'mcp.conflictLead.other', { count: conflicts.length })} } {conflictText(c)} + {/* One server can conflict in several folders, so a project's row says which. */} + {projectOf(roots, c) && ยท {shortenHome(projectOf(roots, c)!)}} {isResolvable(c) && <> - + {canImportConflict(c) && } }