Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(desktop): reject linked ghost content roots
Yuewei-LL309d1dd5e8a8
diff --git a/apps/desktop/src/main/cindy-brain/__tests__/ghostContentTree.test.ts b/apps/desktop/src/main/cindy-brain/__tests__/ghostContentTree.test.tsindex 053741a3d4..cae2bf2139 100644--- a/apps/desktop/src/main/cindy-brain/__tests__/ghostContentTree.test.ts+++ b/apps/desktop/src/main/cindy-brain/__tests__/ghostContentTree.test.ts@@ -163,6 +163,22 @@ describe('resolveGhostContentPath', () => {});describe('collectGhostContentFiles', () => {+ it('rejects a linked content root before following it', async () => {+ const root = path.join(workDir, 'plugin');+ const outside = path.join(workDir, 'outside');+ await fs.promises.mkdir(outside, { recursive: true });+ await fs.promises.writeFile(path.join(outside, 'main.js'), '// outside');+ if (!(await tryLinkDir(outside, root))) return;++ await expect(+ collectGhostContentFiles(root, {+ dotEntries: 'include',+ nonRegular: 'throw',+ label: 'test',+ }),+ ).rejects.toThrow(/ghost content root is not a real directory/);+ });+it('includes dot entries for skill content and rejects links there', async () => {const dir = path.join(workDir, 'skill');await fs.promises.mkdir(path.join(dir, 'refs'), { recursive: true });diff --git a/apps/desktop/src/main/cindy-brain/ghostContentTree.ts b/apps/desktop/src/main/cindy-brain/ghostContentTree.tsindex c0db71bd7e..a90acb84ba 100644--- a/apps/desktop/src/main/cindy-brain/ghostContentTree.ts+++ b/apps/desktop/src/main/cindy-brain/ghostContentTree.ts@@ -202,12 +202,22 @@ function sameStableDirectoryState(before: fs.BigIntStats, after: fs.BigIntStats)}async function captureGhostContentRootIdentity(rootDir: string): Promise<GhostContentRootIdentity> {+ const lexicalBefore = await fs.promises.lstat(rootDir, { bigint: true });+ if (lexicalBefore.isSymbolicLink() || !lexicalBefore.isDirectory()) {+ throw new Error(`ghost content root is not a real directory: ${rootDir}`);+ }const realPath = await fs.promises.realpath(rootDir);- const [pathStat, realStat] = await Promise.all([+ const [pathStat, realStat, lexicalAfter] = await Promise.all([fs.promises.stat(rootDir, { bigint: true }),fs.promises.stat(realPath, { bigint: true }),+ fs.promises.lstat(rootDir, { bigint: true }),]);- if (!pathStat.isDirectory() || !sameStableDirectoryState(pathStat, realStat)) {+ if (+ !sameStableDirectoryState(lexicalBefore, pathStat) ||+ !sameStableDirectoryState(pathStat, realStat) ||+ !sameStableDirectoryState(pathStat, lexicalAfter) ||+ lexicalAfter.isSymbolicLink()+ ) {throw new Error(`ghost content root is not a stable directory: ${rootDir}`);}return {@@ -223,7 +233,12 @@ async function assertGhostContentRootIdentity(rootDir: string,expected: GhostContentRootIdentity,): Promise<void> {- const current = await captureGhostContentRootIdentity(rootDir);+ let current: GhostContentRootIdentity;+ try {+ current = await captureGhostContentRootIdentity(rootDir);+ } catch (error) {+ throw new Error(`ghost content root changed while reading: ${rootDir}`, { cause: error });+ }if (current.realPath !== expected.realPath ||current.dev !== expected.dev ||