Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(desktop): preserve package links and scaffold identity
Yuewei-LL6a1f6f29e92f
diff --git a/apps/desktop/src/main/cindy-brain/GhostManager.ts b/apps/desktop/src/main/cindy-brain/GhostManager.tsindex 9e4aaa48e2..c8944abb88 100644--- a/apps/desktop/src/main/cindy-brain/GhostManager.ts+++ b/apps/desktop/src/main/cindy-brain/GhostManager.ts@@ -58,8 +58,9 @@ async function readRegularFileStableWithLimit(filePath: string,maxBytes: number,): Promise<Buffer> {- const noFollow = fs.constants.O_NOFOLLOW ?? 0;- const handle = await fs.promises.open(filePath, fs.constants.O_RDONLY | noFollow);+ // 顶层 .cindy 路径允许是用户选择的 symlink;确认前后由整包 sha256 对账,+ // 单次读取则始终绑定同一个已打开句柄,避免 stat/read 的二次解析窗口。+ const handle = await fs.promises.open(filePath, fs.constants.O_RDONLY);try {const opened = await handle.stat();if (!opened.isFile() || opened.isSymbolicLink()) {diff --git a/apps/desktop/src/main/cindy-brain/__tests__/GhostManager.test.ts b/apps/desktop/src/main/cindy-brain/__tests__/GhostManager.test.tsindex c3b250c773..947c491322 100644--- a/apps/desktop/src/main/cindy-brain/__tests__/GhostManager.test.ts+++ b/apps/desktop/src/main/cindy-brain/__tests__/GhostManager.test.ts@@ -3671,6 +3671,24 @@ describe('GhostManager · setEnabled(启用/停用)', () => {});describe('GhostManager · inspect(只验不装)', () => {+ it('allows a top-level .cindy symlink and installs the inspected target bytes', async () => {+ const target = await makeCindy('symlink-target.cindy', goodManifest());+ const linked = path.join(workDir, 'symlink-source.cindy');+ try {+ await fs.promises.symlink(target, linked, 'file');+ } catch {+ return; // Windows without file-symlink capability cannot exercise this POSIX regression.+ }++ const inspected = await manager.inspect(linked);+ expect('packageSha256' in inspected).toBe(true);+ if (!('packageSha256' in inspected)) return;+ const installed = await manager.install(linked, {+ expectedPackageSha256: inspected.packageSha256,+ });+ expect('ghost' in installed).toBe(true);+ });+it('合法 .cindy → 返回清单,且零副作用(仓库目录不被创建)', async () => {const cindy = await makeCindy('a.cindy', goodManifest());const result = await manager.inspect(cindy);diff --git a/apps/desktop/src/main/cindy-brain/__tests__/forge.test.ts b/apps/desktop/src/main/cindy-brain/__tests__/forge.test.tsindex 0e083db2d7..9a1dc91146 100644--- a/apps/desktop/src/main/cindy-brain/__tests__/forge.test.ts+++ b/apps/desktop/src/main/cindy-brain/__tests__/forge.test.ts@@ -47,12 +47,12 @@ const directoryLinkType = process.platform === 'win32' ? 'junction' : 'dir';let workDir: string;async function testScaffoldWriter(request: ForgeScaffoldWriteRequest) {- const parentStats = await fs.promises.lstat(request.parentDir);+ const parentStats = await fs.promises.lstat(request.parentDir, { bigint: true });if (!parentStats.isDirectory() || parentStats.isSymbolicLink()) {return { ok: false as const, errorCode: 'INTERNAL' as const, message: 'unsafe parent' };}if (- !(request.expectedParent.dev === 0 && request.expectedParent.ino === 0) &&+ !(request.expectedParent.dev === 0n && request.expectedParent.ino === 0n) &&(parentStats.dev !== request.expectedParent.dev || parentStats.ino !== request.expectedParent.ino)) {return { ok: false as const, errorCode: 'INTERNAL' as const, message: 'parent changed' };@@ -967,6 +967,35 @@ describe('packGhostDir', () => {});describe('scaffoldGhostDir', () => {+ it('passes the stable parent identity as lossless bigint values', async () => {+ const parentStat = await fs.promises.lstat(workDir, { bigint: true });+ let captured: ForgeScaffoldWriteRequest | undefined;+ const result = await scaffoldGhostDirRaw(+ {+ dir: path.join(workDir, 'bigint-parent'),+ template: 'plain',+ id: 'bigint-parent',+ name: 'BigInt parent',+ },+ {+ sessionWorkdir: workDir,+ writeScaffold: async (request) => {+ captured = request;+ return { ok: true };+ },+ },+ );++ expect(result.ok).toBe(true);+ expect(captured?.expectedParent).toEqual({+ realPath: await fs.promises.realpath(workDir),+ dev: parentStat.dev,+ ino: parentStat.ino,+ });+ expect(typeof captured?.expectedParent.dev).toBe('bigint');+ expect(typeof captured?.expectedParent.ino).toBe('bigint');+ });+it.each<ForgeScaffoldTemplate>(['plain', 'agent-action', 'node-json-rpc', 'node-mcp'])('生成 %s 模板,随后可以直接打包并通过装入检查',async (template) => {diff --git a/apps/desktop/src/main/cindy-brain/forge.ts b/apps/desktop/src/main/cindy-brain/forge.tsindex 1fb46a08a0..a046162172 100644--- a/apps/desktop/src/main/cindy-brain/forge.ts+++ b/apps/desktop/src/main/cindy-brain/forge.ts@@ -151,8 +151,8 @@ export interface ForgeScaffoldWriteRequest {targetName: string;expectedParent: {realPath: string;- dev: number;- ino: number;+ dev: bigint;+ ino: bigint;};files: Array<{ path: string; base64: string }>;}@@ -568,10 +568,10 @@ export async function scaffoldGhostDir(}const parentDir = path.dirname(targetDir);- let parentStat: fs.Stats;+ let parentStat: fs.BigIntStats;let parentRealPath: string;try {- parentStat = await fs.promises.lstat(parentDir);+ parentStat = await fs.promises.lstat(parentDir, { bigint: true });if (!parentStat.isDirectory() || parentStat.isSymbolicLink()) {return { ok: false, errorCode: 'INVALID_INPUT', message: 'dir 的父目录必须是工作目录内已存在的普通目录' };}diff --git a/apps/desktop/src/main/cindy-brain/forgeScaffoldWorkerProcess.ts b/apps/desktop/src/main/cindy-brain/forgeScaffoldWorkerProcess.tsindex 75d41d5d7d..a8765c4f70 100644--- a/apps/desktop/src/main/cindy-brain/forgeScaffoldWorkerProcess.ts+++ b/apps/desktop/src/main/cindy-brain/forgeScaffoldWorkerProcess.ts@@ -2,7 +2,7 @@ import fs from 'node:fs';import path from 'node:path';interface Request {- expectedParent: { realPath: string; dev: number; ino: number };+ expectedParent: { realPath: string; dev: bigint; ino: bigint };targetName: string;files: Array<{ path: string; base64: string }>;}@@ -31,14 +31,14 @@ function hasCode(error: unknown, code: string): boolean {return Boolean(error && typeof error === 'object' && 'code' in error && error.code === code);}-function sameParentIdentity(stats: fs.Stats, expected: Request['expectedParent']): boolean {+function sameParentIdentity(stats: fs.BigIntStats, expected: Request['expectedParent']): boolean {if (!stats.isDirectory() || stats.isSymbolicLink()) return false;- return (expected.dev === 0 && expected.ino === 0) ||+ return (expected.dev === 0n && expected.ino === 0n) ||(stats.dev === expected.dev && stats.ino === expected.ino);}async function verifyParent(expected: Request['expectedParent']): Promise<void> {- const stats = await fs.promises.lstat('.');+ const stats = await fs.promises.lstat('.', { bigint: true });if (!sameParentIdentity(stats, expected)) throw new Error('Forge scaffold parent identity changed');const real = await fs.promises.realpath('.');if (!samePath(real, expected.realPath)) throw new Error('Forge scaffold parent path changed');