Local-first AI coding agent desktop: Electron + Rust host core + pi Agent Harness + user-installable plugins
TypeScript ai-agentcoding-agentdesktop-appelectronglobali18nlocal-firstmcppipi-agentpi-desktoppluginsreactrusttypescript
fix: 按 MCP 编辑器目标项目校验重复配置
geng yue922058705921
diff --git a/apps/desktop/src/components/settings/AgentMcpPage.tsx b/apps/desktop/src/components/settings/AgentMcpPage.tsxindex b32eb9ab0..2b9f69aab 100644--- a/apps/desktop/src/components/settings/AgentMcpPage.tsx+++ b/apps/desktop/src/components/settings/AgentMcpPage.tsx@@ -215,18 +215,20 @@ export function AgentMcpPage() {}const candidateId = editor.draft.id.trim();const candidateLabel = editor.draft.label.trim().toLocaleLowerCase();- const sameLevel = (editor.level === "global" ? globalServers : projectServers).some(- (server) =>- server.id !== editor.editing?.id &&- (server.id === candidateId ||- (!!candidateLabel && server.label.trim().toLocaleLowerCase() === candidateLabel)),- );- if (sameLevel) {- showToast(t("settings.mcpDuplicate"), { variant: "error" });- return;- }setSaving(true);try {+ // 保存校验跟随编辑器的归属,并读取最新列表,避免页面切换后的记录误拦截。+ const { servers } = await api.listMcpServers({ level: editor.level, projectPath });+ const sameLevel = servers.some(+ (server) =>+ server.id !== editor.editing?.id &&+ (server.id === candidateId ||+ (!!candidateLabel && server.label.trim().toLocaleLowerCase() === candidateLabel)),+ );+ if (sameLevel) {+ showToast(t("settings.mcpDuplicate"), { variant: "error" });+ return;+ }await api.upsertMcpServer(draftToInput(editor.draft, { level: editor.level, projectPath }));await load();showToast(diff --git a/apps/desktop/test/mcp-market-owner-user-path.test.mjs b/apps/desktop/test/mcp-market-owner-user-path.test.mjsindex 75d144c80..707337a75 100644--- a/apps/desktop/test/mcp-market-owner-user-path.test.mjs+++ b/apps/desktop/test/mcp-market-owner-user-path.test.mjs@@ -26,7 +26,7 @@ const projectPath = "/projects/market-owner-a";const otherProjectPath = "/projects/market-owner-b";const entry = BUILTIN_MCP_CATALOG.servers.find((item) => !item.requiredEnv?.length);const settings = { defaultMode: "agent", theme: "light", language: "en" };-let records = [], writes = [], imports = [], hasProject = true;+let records = [], writes = [], imports = [], hasProject = true, lastProjectRead = null;Object.defineProperty(window, "AudioContext", { configurable: true, value: undefined });window.piDesktop = {platform: "darwin",@@ -38,6 +38,7 @@ window.piDesktop = {data = { projects: hasProject ? [{ id: 1, path: projectPath, name: "Market Project" }, { id: 2, path: otherProjectPath, name: "Other Project" }] : [] };break;case IPC.invoke.mcpList:+ if (input.level === "project") lastProjectRead = input.projectPath;data = { servers: records.filter((record) => record.level === input.level &&(record.level === "global" || record.projectPath === input.projectPath)), statuses: [] };break;@@ -103,6 +104,8 @@ async function selectOtherProject() {await until(() => document.querySelector('[role="option"]'), "Project options missing");click([...document.querySelectorAll('[role="option"]')].find(node => node.textContent.trim() === "Other Project"));await until(() => document.querySelector('.agent-capability-project-select').textContent.includes("Other Project"), "Project did not change");+ await until(() => lastProjectRead === otherProjectPath, "Other project's list did not load");+ await new Promise(requestAnimationFrame);}window.mcpMarketOwnerProbe = async () => {const results = [];@@ -150,6 +153,43 @@ window.mcpMarketOwnerProbe = async () => {await until(() => marketAction()?.disabled, "Installed state must follow the destination owner");results.push({ filter, project, otherOwner, level: writes[0].level });}+ const ownershipCases = [];+ for (const action of ["create", "edit"]) {+ const conflicts = action === "edit" ? ["other-project", "target-label"] : ["other-project", "target-label", "target-id"];+ for (const conflict of conflicts) {+ flushSync(() => root.render(null));+ hasProject = true;+ writes = [];+ lastProjectRead = null;+ const existing = { id: "existing", label: "Existing fixture", command: "fixture-server", transport: "stdio", enabled: true, level: "project", projectPath };+ records = action === "edit" ? [existing] : [];+ records.push({ ...existing, id: "other-id", projectPath: otherProjectPath });+ if (conflict !== "other-project") records.push({ ...existing,+ id: conflict === "target-id" ? "existing-fixture" : "conflicting-id",+ label: conflict === "target-id" ? "Different name" : "Existing fixture" });+ useAppStore.setState({ settings, toasts: [], workspace: { path: projectPath, name: "Market Project" } });+ flushSync(() => root.render(<><AgentMcpPage /><ToastHost /></>));+ await until(() => lastProjectRead === projectPath, "Target project's list did not load");+ await new Promise(requestAnimationFrame);+ if (action === "edit") {+ click(document.querySelector('[aria-label="' + i18n.t("settings.editMcpOf", { name: "Existing fixture" }) + '"]'));+ } else {+ click(button(i18n.t("settings.addMcp")));+ type(document.querySelector('input[placeholder="' + i18n.t("extensions.mcp.labelPlaceholder") + '"]'), "Existing fixture");+ type(document.querySelector('input[placeholder="-y @upstash/context7-mcp"]'), "-y fixture-server");+ }+ await selectOtherProject();+ click(button(i18n.t("common.save")));+ if (conflict === "other-project") {+ await until(() => writes.length === 1, "Other project's duplicate blocked a valid " + action);+ assert(writes[0].projectPath === projectPath, "Save changed the pinned owner");+ } else {+ await until(() => [...document.querySelectorAll('.toast-message')].some(node => node.textContent === i18n.t("settings.mcpDuplicate")), "Target conflict was not rejected");+ assert(writes.length === 0, "Conflicting save reached upsert");+ }+ ownershipCases.push({ action, conflict });+ }+ }// An existing global or project record retains its owner after the page's// selected project changes while the editor is open.for (const level of ["global", "project"]) {@@ -157,7 +197,9 @@ window.mcpMarketOwnerProbe = async () => {hasProject = true;writes = [];records = [{ id: "existing", label: "Existing fixture", command: "fixture-server", transport: "stdio", enabled: true, level,- ...(level === "project" ? { projectPath } : {}) }];+ ...(level === "project" ? { projectPath } : {}) },+ { id: "other-id", label: "Existing fixture", command: "fixture-server", transport: "stdio", enabled: true, level: "project", projectPath: otherProjectPath }];+ lastProjectRead = null;useAppStore.setState({ settings, workspace: { path: projectPath, name: "Market Project" } });flushSync(() => root.render(<AgentMcpPage />));await until(() => document.querySelector('.agent-capability-row'), "Existing record missing");@@ -183,7 +225,7 @@ window.mcpMarketOwnerProbe = async () => {await until(() => [...document.querySelectorAll(".toast-message")].some((node) => node.textContent === i18n.t("settings.selectProjectFirst")), "Missing project must report an error");assert(writes.length === 0, "Missing project must never save globally");- return { results, missingProjectBlocked: true };+ return { results, ownershipCases, missingProjectBlocked: true };};`;@@ -230,7 +272,7 @@ app.whenReady().then(async () => {});let output = "";for (const stream of [child.stdout, child.stderr]) stream.on("data", (chunk) => { output += chunk; });- const timer = setTimeout(() => child.kill("SIGKILL"), 30_000);+ const timer = setTimeout(() => child.kill("SIGKILL"), 55_000);let code;try {code = await new Promise((resolve, reject) => {@@ -243,6 +285,7 @@ app.whenReady().then(async () => {assert(line, output);const result = JSON.parse(line.slice("MCP_MARKET_OWNER ".length));assert.equal(result.results.length, 6);+ assert.equal(result.ownershipCases.length, 5);assert.equal(result.missingProjectBlocked, true);} finally { await rm(temp, { recursive: true, force: true }); }});diff --git a/docs/spec/04-ux/06-settings-ia.md b/docs/spec/04-ux/06-settings-ia.mdindex 6d108f2f8..7c2a708f1 100644--- a/docs/spec/04-ux/06-settings-ia.md+++ b/docs/spec/04-ux/06-settings-ia.md@@ -785,6 +785,10 @@ system while preserving their different data ownership:project when present and otherwise Global. Explicit Global/Project retaintheir ownership. An opened editor pins its project owner; changing the page'sselected project cannot move an existing definition (#1953).+ Save refreshes the list at the editor's pinned destination before checking+ duplicate IDs/names. A same-name definition in another project cannot block+ a valid save; a conflict in the target project still blocks it. Host upsert+ retains its authoritative destination validation for concurrent writes.- Inside the panel, each level is a group header row — level name, resolved`.agents` path in mono, localized count — followed by its rows. Lists flowat natural page height like every other Settings surface; the page scrollsdiff --git a/docs/spec/06-delivery/04-e2e-test-plan.md b/docs/spec/06-delivery/04-e2e-test-plan.mdindex 30848d4c1..4b2df7c3e 100644--- a/docs/spec/06-delivery/04-e2e-test-plan.md+++ b/docs/spec/06-delivery/04-e2e-test-plan.md@@ -20371,6 +20371,11 @@ Scenario: E2E-REVIEW-ROUNDS (local desktop, implemented)MCP All uses the selected project for create/import/install, falling back to Global only without a project. Explicit filters retain ownership and an opened editor pins its project. Verify create and market installation across all/project/global and missing-project cases with `mcp-market-owner-user-path.test.mjs`.+Open an editor in project A, switch the page to B and wait for B's list. A/B+same-name definitions with different IDs do not prevent saving to A. A real+duplicate name or ID in A still blocks creation; a real duplicate name blocks+editing. Cover both creating and editing before changing the page selection.+#### E2E-ISSUE-1789Image-model marking explains chat/default-menu exclusion and distinguishes generation from image input. Collapsed model rows retain an image-model badge. Verify marking, help, collapsing, unmarking and restored chat eligibility through `image-model-disclosure-user-path.test.mjs`.diff --git a/docs/zh-CN/spec/04-ux/06-settings-ia.md b/docs/zh-CN/spec/04-ux/06-settings-ia.mdindex cd9b0e42a..e15a59f48 100644--- a/docs/zh-CN/spec/04-ux/06-settings-ia.md+++ b/docs/zh-CN/spec/04-ux/06-settings-ia.md@@ -549,3 +549,5 @@ Token 用量**不是设置目的地**(D335 / ADR 0173)。已完成回合历MCP 在 All 筛选下优先创建、导入、安装到所选项目;未选项目时使用全局。显式 Global 保持全局,Project 无选择时禁止写入。已打开编辑器固定其项目归属,切换页面项目不会移动现有定义。其他能力页继续遵循各自已有默认规则。+保存前读取编辑器固定目标的最新列表,检查重复 ID 和名称;其他项目同名定义+不阻止合法保存,目标项目真实冲突仍拒绝。Host upsert 继续执行权威归属校验。diff --git a/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.md b/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.mdindex ff068fa17..fce9e9c3a 100644--- a/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.md+++ b/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.md@@ -10409,6 +10409,9 @@ Electron 一侧——工具自动签发、指示器、"停止"中止轮次、绘MCP All 在创建、导入、安装时使用所选项目,无项目才回退全局;显式筛选保留归属,编辑器固定项目。验证不同筛选、创建、市场安装和缺少项目拒绝写入。+在 A 打开创建或编辑窗口,切换页面至 B 并等待列表加载。A/B 同名不同 ID+不阻止保存到 A;A 真实重复名称或 ID 仍阻止创建,真实重复名称仍阻止编辑。+#### E2E-ISSUE-1789生图标记说明聊天和默认菜单移除效果,并区分图片生成与输入;折叠行保留生图标记。通过真实组件验证标记、帮助、折叠、取消及恢复聊天资格。