From 7e71400a7c8af3e32107dbcc3b10e566e2a4345b Mon Sep 17 00:00:00 2001 From: Oke Iyanuoluwa Enoch <70354778+Iyanuoluwa007@users.noreply.github.com> Date: Mon, 30 Nov 2026 02:07:55 +0000 Subject: [PATCH] fix(setup): read Devin project MCP configuration (#15101) * fix(setup): read Devin project MCP configuration Devin loads .devin/mcp_config.json and .devin/mcp_config.local.json from the working directory up to the nearest .git or .jj, above the user file. A local file outranks every shared file, and a nested directory outranks its ancestors. REA only read the user file, so doctor judged it while Devin ran a project entry, and project uninstall skipped Devin. Return Devin's project candidates in that order, evaluate them with whole-definition replacement, and include Devin in project uninstall. Setup still writes only the user file. Fixes #15041 * fix(setup): apply Devin precedence by directory --------- Co-authored-by: morluto <76467478+morluto@users.noreply.github.com> --- docs/getting-started/client-configuration.md | 8 + src/application/ClientConfigurationFiles.ts | 15 +- src/application/SupportedClientLocations.ts | 39 ++++ tests/boundary/cli/projectUninstall.test.ts | 42 ++++ .../devinProjectConfiguration.test.ts | 216 ++++++++++++++++++ 5 files changed, 316 insertions(+), 4 deletions(-) create mode 100644 tests/boundary/filesystem/devinProjectConfiguration.test.ts diff --git a/docs/getting-started/client-configuration.md b/docs/getting-started/client-configuration.md index aebfb25c1f..5112bae90e 100644 --- a/docs/getting-started/client-configuration.md +++ b/docs/getting-started/client-configuration.md @@ -714,6 +714,14 @@ These values are client-side deadlines, so increase them in `~/.codex/config.tom workload needs more time. Devin honors `XDG_CONFIG_HOME` for its `devin/mcp_config.json` on non-Windows systems. +REA setup configures only Devin's user file. Devin also reads +`.devin/mcp_config.json` and `.devin/mcp_config.local.json` from the working +directory up to the project root (the nearest `.git` or `.jj`). A nested +directory outranks its ancestors, and the local file wins within the same +directory. The highest `rea` entry replaces lower ones. Doctor reports the +file that supplies the entry. Use `rea uninstall --project DIR` to remove an +owned entry from a project's `.devin` files. + ### ChatGPT Work on macOS If Work shows tools outside the families you selected, check the REA entry in diff --git a/src/application/ClientConfigurationFiles.ts b/src/application/ClientConfigurationFiles.ts index df8951db1d..74d0953797 100644 --- a/src/application/ClientConfigurationFiles.ts +++ b/src/application/ClientConfigurationFiles.ts @@ -640,7 +640,8 @@ const supportsProjectConfigurationWalk = ( client.format === "pi" || client.format === "mastracode" || client.name === "antigravity" || - client.format === "amp"; + client.format === "amp" || + client.name === "devin"; /** Read actual user layers, with a project view only when a directory is expressly supplied. */ export const readEffectiveClientRegistrationConfiguration = async ( @@ -696,10 +697,11 @@ export const readEffectiveClientRegistrationConfiguration = async ( >(); const userOverrides = new Set(client.openCodeUserOverridePaths); const layers = paths.value.filter( - // Mastra Code also reuses a user file at its project precedence when - // the current directory is home or a project path resolves to that file. + // Mastra Code and Devin also load a user file at project precedence + // when a project path resolves to the same file. ({ userPath }) => userPath === undefined || + client.name === "devin" || client.format === "mastracode" || userOverrides.has(userPath), ); @@ -793,7 +795,12 @@ export const readEffectiveClientRegistrationConfiguration = async ( // Preserve this occurrence in native order while retaining the user // file's parsed snapshot and ownership. const source = userByPath.get(userPath); - if (source !== undefined) sources.push(source); + if (source?.sourcePath !== undefined) + sources.push( + client.name === "devin" + ? { ...source, sourcePath: path, scope: "project" } + : source, + ); continue; } let source = projectSources.get(path); diff --git a/src/application/SupportedClientLocations.ts b/src/application/SupportedClientLocations.ts index 79bb60651c..88dd20e59b 100644 --- a/src/application/SupportedClientLocations.ts +++ b/src/application/SupportedClientLocations.ts @@ -204,6 +204,43 @@ const ampWorkspaceSettingsPath = ( } }; +/** + * Devin loads shared and then local settings in each directory, from the + * nearest Git or Jujutsu root down to cwd. Outside a project it reads only cwd. + */ +const devinProjectConfigurationPaths = ( + projectDirectory: string, + paths: typeof posix, +): Result => { + const filesIn = (directory: string) => + ["mcp_config.json", "mcp_config.local.json"].map((name) => + paths.join(directory, ".devin", name), + ); + const directories = [projectDirectory]; + let current = projectDirectory; + for (;;) { + for (const marker of [".git", ".jj"]) { + const path = paths.join(current, marker); + try { + lstatSync(path); + return ok(directories.reverse().flatMap(filesIn)); + } catch (cause: unknown) { + if (!isAbsentClientConfigPath(cause)) + return err({ + kind: "unknown_project_root", + scope: "project", + path, + detail: `Devin's project boundary at ${path} could not be inspected: ${errorMessage(cause)}.`, + }); + } + } + const parent = paths.dirname(current); + if (parent === current) return ok(filesIn(projectDirectory)); + current = parent; + directories.push(current); + } +}; + /** Native cwd-relative candidates in load order. This provides no write authority. */ export const clientProjectConfigurationPaths = ( client: Pick, @@ -217,6 +254,8 @@ export const clientProjectConfigurationPaths = ( return ampWorkspaceSettingsPath(projectDirectory, paths); if (client.format === "pi") return ok([paths.join(projectDirectory, ".pi", "mcp.json")]); + if (client.name === "devin") + return devinProjectConfigurationPaths(projectDirectory, paths); if (client.name === "antigravity") { const directories = antigravityProjectDirectories(projectDirectory, paths); return directories.ok diff --git a/tests/boundary/cli/projectUninstall.test.ts b/tests/boundary/cli/projectUninstall.test.ts index 2e897c55d0..61e7abdbbc 100644 --- a/tests/boundary/cli/projectUninstall.test.ts +++ b/tests/boundary/cli/projectUninstall.test.ts @@ -697,3 +697,45 @@ cliTest( expect(await readFile(`${workspace}.rea.backup`, "utf8")).toBe(original); }, ); + +cliTest( + "project uninstall removes owned Devin entries from the selected project's .devin files (#15041)", + async ({ cli }) => { + const root = await createTestTempDirectory("rea-project-uninstall-devin-"); + const project = join(root, "project"); + await mkdir(join(project, ".git"), { recursive: true }); + const devinRegistration = { + command: "npx", + args: ["-y", "rea-agents", "mcp"], + }; + const peer = { command: "unrelated", args: ["mcp"] }; + const sharedPath = join(project, ".devin", "mcp_config.json"); + const localPath = join(project, ".devin", "mcp_config.local.json"); + const shared = await put(sharedPath, { + mcpServers: { rea: devinRegistration, peer }, + }); + const local = await put(localPath, { + mcpServers: { rea: devinRegistration }, + }); + const result = await cli.run({ + arguments: ["uninstall", "--project", project, "--json"], + environment: await registrationEnvironment(join(root, "home")), + cwd: root, + }); + expect(result.exitCode, result.stdout).toBe(0); + expect(result.json).toMatchObject({ + status: "complete", + items: expect.arrayContaining([ + expect.objectContaining({ name: "devin", status: "removed" }), + ]), + }); + expect(JSON.parse(await readFile(sharedPath, "utf8"))).toEqual({ + mcpServers: { peer }, + }); + expect(JSON.parse(await readFile(localPath, "utf8"))).toEqual({ + mcpServers: {}, + }); + expect(await readFile(`${sharedPath}.rea.backup`, "utf8")).toBe(shared); + expect(await readFile(`${localPath}.rea.backup`, "utf8")).toBe(local); + }, +); diff --git a/tests/boundary/filesystem/devinProjectConfiguration.test.ts b/tests/boundary/filesystem/devinProjectConfiguration.test.ts new file mode 100644 index 0000000000..4780304b69 --- /dev/null +++ b/tests/boundary/filesystem/devinProjectConfiguration.test.ts @@ -0,0 +1,216 @@ +import { chmod, mkdir, symlink, unlink, writeFile } from "node:fs/promises"; +import { dirname, join } from "node:path"; +import { expect, it, vi } from "vitest"; + +import { effectiveClientServer } from "../../../src/application/ClientConfigurationDocument.js"; +import { readEffectiveClientRegistrationConfiguration } from "../../../src/application/ClientConfigurationFiles.js"; +import { readClientRegistrationStatuses } from "../../../src/application/ClientRegistrationStatus.js"; +import { clientProjectConfigurationPaths } from "../../../src/application/SupportedClientLocations.js"; +import { supportedClients } from "../../../src/application/SupportedClients.js"; +import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js"; + +const writeConfiguration = async (path: string, configuration: unknown) => { + await mkdir(dirname(path), { recursive: true }); + await writeFile(path, JSON.stringify(configuration)); +}; + +const server = (command: string, env?: Record) => ({ + command, + args: ["mcp"], + ...(env === undefined ? {} : { env }), +}); + +const fixture = async (marker: ".git" | ".jj" | "none" = ".git") => { + const root = await createTestTempDirectory("rea-devin-project-"); + const home = join(root, "home"); + const repository = join(root, "repository"); + const projectDirectory = join(repository, "child"); + await mkdir(projectDirectory, { recursive: true }); + if (marker !== "none") + await mkdir(join(repository, marker), { recursive: true }); + const client = supportedClients(home, process.platform, {}).find( + ({ name }) => name === "devin", + ); + if (client === undefined) + throw new Error("Devin is missing from the client table"); + const devin = (directory: string, name: string) => + join(directory, ".devin", name); + return { + client, + home, + repository, + projectDirectory, + shared: devin(projectDirectory, "mcp_config.json"), + local: devin(projectDirectory, "mcp_config.local.json"), + rootShared: devin(repository, "mcp_config.json"), + rootLocal: devin(repository, "mcp_config.local.json"), + read: () => + readEffectiveClientRegistrationConfiguration( + client, + undefined, + process.platform, + { projectDirectory }, + ), + }; +}; + +it.each([".git", ".jj"] as const)( + "orders Devin project files from the %s root, shared before local and ancestors before the working directory", + async (marker) => { + const { client, projectDirectory, shared, local, rootShared, rootLocal } = + await fixture(marker); + expect( + clientProjectConfigurationPaths( + client, + projectDirectory, + process.platform, + ), + ).toEqual({ ok: true, value: [rootShared, rootLocal, shared, local] }); + }, +); + +it("reads only the working directory's Devin files outside a project", async () => { + const { client, projectDirectory, shared, local } = await fixture("none"); + expect( + clientProjectConfigurationPaths(client, projectDirectory, process.platform), + ).toEqual({ ok: true, value: [shared, local] }); +}); + +it("selects the highest Devin file and replaces the whole server definition (#15041)", async () => { + const { client, shared, local, rootLocal, read } = await fixture(); + await writeConfiguration(client.configPath, { + mcpServers: { rea: server("user", { FROM_USER: "1" }) }, + }); + + const userOnly = await read(); + if (!userOnly.ok) throw Error(userOnly.error.detail); + expect(userOnly.value.configPath).toBe(client.configPath); + + await writeConfiguration(shared, { mcpServers: { rea: server("shared") } }); + const sharedResult = await read(); + if (!sharedResult.ok) throw Error(sharedResult.error.detail); + expect(sharedResult.value).toMatchObject({ + scope: "project", + configPath: shared, + launcherConfigPath: shared, + }); + expect(effectiveClientServer(sharedResult.value.document!, "rea")).toEqual( + server("shared"), + ); + + // The nested shared file outranks the repository root’s local file. + await writeConfiguration(rootLocal, { + mcpServers: { rea: server("root-local") }, + }); + const rootLocalResult = await read(); + if (!rootLocalResult.ok) throw Error(rootLocalResult.error.detail); + expect(rootLocalResult.value.configPath).toBe(shared); + await unlink(shared); + const rootOnly = await read(); + if (!rootOnly.ok) throw Error(rootOnly.error.detail); + expect(rootOnly.value.configPath).toBe(rootLocal); + + await writeConfiguration(local, { mcpServers: { rea: server("local") } }); + const localResult = await read(); + if (!localResult.ok) throw Error(localResult.error.detail); + expect(localResult.value).toMatchObject({ + scope: "project", + configPath: local, + }); + expect(effectiveClientServer(localResult.value.document!, "rea")).toEqual( + server("local"), + ); + + await unlink(local); + await unlink(rootLocal); + const restored = await read(); + if (!restored.ok) throw Error(restored.error.detail); + expect(restored.value.configPath).toBe(client.configPath); +}); + +it("keeps the user Devin registration when project files define only other servers", async () => { + const { client, shared, read } = await fixture(); + await writeConfiguration(client.configPath, { + mcpServers: { rea: server("user") }, + }); + await writeConfiguration(shared, { mcpServers: { peer: server("peer") } }); + const result = await read(); + if (!result.ok) throw Error(result.error.detail); + expect(result.value).toMatchObject({ + scope: "user", + configPath: client.configPath, + }); + expect(effectiveClientServer(result.value.document!, "rea")).toEqual( + server("user"), + ); +}); + +it("reports Devin's project registration and Windsurf's shared user registration in doctor", async () => { + const { client, home, projectDirectory, local } = await fixture(); + await writeConfiguration(client.configPath, { + mcpServers: { rea: server("user") }, + }); + await writeConfiguration(local, { mcpServers: { rea: server("unrelated") } }); + const cwd = vi.spyOn(process, "cwd").mockReturnValue(projectDirectory); + try { + const statuses = await readClientRegistrationStatuses(home, undefined, { + platform: process.platform, + environment: {}, + selectedClientIds: ["devin", "windsurf"], + }); + expect(statuses.find(({ client: name }) => name === "devin")).toMatchObject( + { scope: "project", config_path: local }, + ); + expect( + statuses.find(({ client: name }) => name === "windsurf"), + ).toMatchObject({ + config_path: client.configPath, + command: ["user", "mcp"], + }); + } finally { + cwd.mockRestore(); + } +}); + +it.skipIf(process.platform === "win32")( + "replays a user file reached through a higher Devin project alias", + async () => { + const { client, shared, local, read } = await fixture(); + await writeConfiguration(client.configPath, { + mcpServers: { rea: server("user") }, + }); + await writeConfiguration(shared, { mcpServers: { rea: server("shared") } }); + await symlink(client.configPath, local); + const result = await read(); + if (!result.ok) throw Error(result.error.detail); + expect(result.value).toMatchObject({ + scope: "project", + launcherConfigPath: local, + }); + expect(effectiveClientServer(result.value.document!, "rea")).toEqual( + server("user"), + ); + }, +); + +it.skipIf(process.platform === "win32" || process.getuid?.() === 0)( + "preserves an unreadable Devin project boundary instead of treating it as absent", + async () => { + const { client, projectDirectory } = await fixture(); + await chmod(projectDirectory, 0o000); + try { + expect( + clientProjectConfigurationPaths( + client, + projectDirectory, + process.platform, + ), + ).toMatchObject({ + ok: false, + error: { path: join(projectDirectory, ".git") }, + }); + } finally { + await chmod(projectDirectory, 0o700); + } + }, +);