Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(mcp): 拒绝将托管对话目录用作项目
Dashff6780fc7ca0
diff --git a/apps/desktop/src/main/mcp-integrations/__tests__/createProject.test.ts b/apps/desktop/src/main/mcp-integrations/__tests__/createProject.test.tsindex 50e01dae21..0609058e6b 100644--- a/apps/desktop/src/main/mcp-integrations/__tests__/createProject.test.ts+++ b/apps/desktop/src/main/mcp-integrations/__tests__/createProject.test.ts@@ -4,6 +4,7 @@ import path from 'node:path';import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';const h = vi.hoisted(() => ({+ dialogueRoot: '',owner: { dataOwnerId: 'owner-a', ownerGeneration: 1 },boundary: false,ready: true,@@ -19,6 +20,9 @@ const h = vi.hoisted(() => ({visibility: vi.fn(),hiddenKeys: [] as string[],}));+vi.mock('../../localDb/dialogueWorkspace.js', () => ({+ dialogueWorkspaceRootDir: () => h.dialogueRoot,+}));vi.mock('electron', () => ({BrowserWindow: {getAllWindows: () => [@@ -72,6 +76,7 @@ describe('createProject', () => {beforeEach(async () => {vi.clearAllMocks();directory = await mkdtemp(path.join(os.tmpdir(), 'cindy-create-project-'));+ h.dialogueRoot = path.join(directory, 'dialogues');h.owner = { dataOwnerId: 'owner-a', ownerGeneration: 1 };h.boundary = false;h.ready = true;@@ -92,6 +97,20 @@ describe('createProject', () => {});const run = (workingDir: string) => createProject({ callerSessionId: 'caller', workingDir });+ it('rejects managed dialogue roots, descendants and symlink aliases but permits adjacent projects', async () => {+ const managed = path.join(h.dialogueRoot, '2026-09-18', 'task');+ await mkdir(managed, { recursive: true });+ expect(await run(h.dialogueRoot)).toMatchObject({ ok: false });+ expect(await run(managed)).toMatchObject({ ok: false });+ const alias = path.join(directory, 'alias');+ await symlink(managed, alias, process.platform === 'win32' ? 'junction' : 'dir');+ expect(await run(alias)).toMatchObject({ ok: false });+ expect(h.upsert).not.toHaveBeenCalled();+ const adjacent = `${h.dialogueRoot}-project`;+ await mkdir(adjacent);+ expect(await run(adjacent)).toMatchObject({ ok: true });+ });+it('registers an existing directory, restores visibility and refreshes with the captured owner', async () => {await writeFile(path.join(directory, 'keep.txt'), 'unchanged');const workingDir = directory.replaceAll('\\', '/');diff --git a/apps/desktop/src/main/mcp-integrations/__tests__/moveSession.test.ts b/apps/desktop/src/main/mcp-integrations/__tests__/moveSession.test.tsindex 3350832c15..e30705c60d 100644--- a/apps/desktop/src/main/mcp-integrations/__tests__/moveSession.test.ts+++ b/apps/desktop/src/main/mcp-integrations/__tests__/moveSession.test.ts@@ -4,6 +4,7 @@ import path from 'node:path';import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';const h = vi.hoisted(() => ({+ dialogueRoot: '',owner: { dataOwnerId: 'owner-a', ownerGeneration: 1 },query: vi.fn(),botLinks: [] as Array<{ botId: string }>,@@ -14,6 +15,9 @@ const h = vi.hoisted(() => ({saved: vi.fn(),enterLock: vi.fn(),}));+vi.mock('../../localDb/dialogueWorkspace.js', () => ({+ dialogueWorkspaceRootDir: () => h.dialogueRoot,+}));vi.mock('electron', () => ({ BrowserWindow: { getAllWindows: () => [] } }));vi.mock('../../appSessionState.js', () => ({getActiveDataOwnerPushStamp: () => ({ ...h.owner }),@@ -54,6 +58,7 @@ describe('moveSession host', () => {beforeEach(async () => {vi.clearAllMocks();directory = await mkdtemp(path.join(os.tmpdir(), 'cindy-move-session-'));+ h.dialogueRoot = path.join(directory, 'dialogues');h.owner = { dataOwnerId: 'owner-a', ownerGeneration: 1 };h.running = new Set();h.workers = [];@@ -174,7 +179,7 @@ describe('moveSession host', () => {expect(await run('relative')).toMatchObject({ errorCode: 'INVALID_ARGS' });expect(h.saved).not.toHaveBeenCalled();});- it.for(['.cindy-worktrees', '.xdt-worktrees'])(+ it.for(['.cindy-worktrees', '.xdt-worktrees', 'dialogues'])('rejects a %s alias retargeted while waiting for the route lock',async (managedName, ctx) => {const ordinary = path.join(directory, 'ordinary');diff --git a/apps/desktop/src/main/mcp-integrations/createProject.ts b/apps/desktop/src/main/mcp-integrations/createProject.tsindex 8afc04fbd9..3ba56a7929 100644--- a/apps/desktop/src/main/mcp-integrations/createProject.ts+++ b/apps/desktop/src/main/mcp-integrations/createProject.ts@@ -4,6 +4,7 @@ import { BrowserWindow } from 'electron';import { eq } from 'drizzle-orm';import { getActiveDataOwnerPushStamp, isAppSessionBoundaryPending } from '../appSessionState.js';import { tryGetDbClient } from '../localDb/client/current.js';+import { dialogueWorkspaceRootDir } from '../localDb/dialogueWorkspace.js';import { sessions } from '../localDb/schema.js';import { normalizeRecentWorkdirPath, upsertRecentWorkdir } from '../localDb/ipc/recentWorkdirs.js';import { restoreLocalProjectVisibility } from '../sidebarSettingsStore.js';@@ -92,12 +93,32 @@ export function validateLocalProjectDirectory(: fail('INVALID_ARGS', 'Managed task worktrees cannot be registered as separate projects.');}+function isWithinDirectory(directory: string, root: string): boolean {+ const relative = path.relative(root, directory);+ return (+ relative === '' ||+ (relative !== '..' && !relative.startsWith(`..${path.sep}`) && !path.isAbsolute(relative))+ );+}+/** Check physical targets without changing the caller's normalized project identity. */export async function validateExistingLocalProjectDirectory(workingDir: string) {+ const root = dialogueWorkspaceRootDir();+ if (isWithinDirectory(workingDir, root)) {+ return fail('INVALID_ARGS', 'Managed dialogue workspaces cannot be registered as projects.');+ }if (!(await stat(workingDir)).isDirectory())return fail('NOT_A_DIRECTORY', 'working_dir is not a directory.');- // Both registration and task moves must reject disguised managed worktrees.- return validateLocalProjectDirectory(await realpath(workingDir));+ // Resolve both sides: userData itself may use a symlink (e.g. /var on macOS).+ const physicalDirectory = await realpath(workingDir);+ const physicalRoot = await realpath(root).catch((error: NodeJS.ErrnoException) => {+ if (error.code === 'ENOENT') return root;+ throw error;+ });+ if (isWithinDirectory(physicalDirectory, physicalRoot)) {+ return fail('INVALID_ARGS', 'Managed dialogue workspaces cannot be registered as projects.');+ }+ return validateLocalProjectDirectory(physicalDirectory);}/** Register only: filesystem creation and task execution remain separate agent actions. */