Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

fix(chat): deduplicate validated symlink target identities

ylliuuu66b3cf3461a7af
diff --git a/apps/desktop/src/main/maker-ipc/__tests__/chatServerReplyFiles.test.ts b/apps/desktop/src/main/maker-ipc/__tests__/chatServerReplyFiles.test.ts
index 9d948c5e57..c28323ed27 100644
--- a/apps/desktop/src/main/maker-ipc/__tests__/chatServerReplyFiles.test.ts
+++ b/apps/desktop/src/main/maker-ipc/__tests__/chatServerReplyFiles.test.ts
@@ -145,6 +145,22 @@ describe('group reply file delivery', () => {
expect(await prepareChatReplyFiles(text, 'lane', () => {})).toEqual({ text, attachments: [] });
});
+ it('deduplicates accepted symlink targets before the file limit, retaining the first link', async () => {
+ const aliases: string[] = [];
+ for (let i = 0; i < 24; i++) {
+ const alias = path.join(work, `same-report-${i}.pdf`);
+ await fs.symlink(pdf, alias);
+ aliases.push(alias);
+ }
+ try {
+ const body = [...aliases, pdf].map(source => `[report](<${source}>)`).join(' ');
+ const result = await prepareChatReplyFiles(body, 'lane', () => {});
+ expect(result.attachments).toHaveLength(1);
+ expect(result.attachments[0]!.name).toBe(path.basename(aliases[0]!));
+ expect((await result.attachments[0]!.readBytes!()).toString()).toBe('%PDF-1.4\nreport');
+ } finally { for (const alias of aliases) await fs.unlink(alias); }
+ });
+
it('deduplicates real filesystem identities before applying the count limit', async () => {
const source = path.join(work, 'CaseReport.pdf');
await fs.writeFile(source, 'case report');
diff --git a/apps/desktop/src/main/maker-ipc/chatServerReplyFiles.ts b/apps/desktop/src/main/maker-ipc/chatServerReplyFiles.ts
index c5150dcc2b..1f09225ec3 100644
--- a/apps/desktop/src/main/maker-ipc/chatServerReplyFiles.ts
+++ b/apps/desktop/src/main/maker-ipc/chatServerReplyFiles.ts
@@ -258,7 +258,7 @@ export async function prepareChatReplyFiles(text: string, sessionId: string, ass
if ((error as NodeJS.ErrnoException).code !== 'ENOENT') throw error;
}
assertCurrent();
- if (seen.has(identity)) continue;
+ if (!symbolic && seen.has(identity)) continue;
// Metadata only: bytes still require the live authority and descriptor checks below.
const candidate = singleFile || symbolic ? await fs.realpath(canonicalSource).catch(() => undefined) : undefined;
assertCurrent();
@@ -268,7 +268,9 @@ export async function prepareChatReplyFiles(text: string, sessionId: string, ass
const target = await fs.lstat(candidate, { bigint: true }).catch(() => undefined);
assertCurrent();
singleFile = !!target?.isFile() && target.nlink === 1n && target.ino !== 0n;
+ if (singleFile) identity = `${target!.dev}:${target!.ino}`;
}
+ if (seen.has(identity)) continue;
const realSource = singleFile && candidate && isPathWithin(root, candidate) ? candidate : undefined;
// Only potential rendered-image aliases defer counting to the validated
// image merger. Independent files still fail at the existing limit here.