Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(device-link): 按全局缓存预算回收并补齐断连测试依赖
Dashcc03bfab896e
diff --git a/apps/desktop/src/main/cindy-media/__tests__/recycler.test.ts b/apps/desktop/src/main/cindy-media/__tests__/recycler.test.tsindex c919740a1f..eeaf2f9e6e 100644--- a/apps/desktop/src/main/cindy-media/__tests__/recycler.test.ts+++ b/apps/desktop/src/main/cindy-media/__tests__/recycler.test.ts@@ -186,6 +186,35 @@ describe('deleteZeroRefBlobs(安全删除顺序)', () => {});describe('scanCache / evictCacheBlobs(cache 瘦身)', () => {+ it('counts the global cache budget while only evicting remote-file exclusive copies', async () => {+ const other = await seedBlob('foreign-cache', { isCache: true });+ const shared = await seedBlob('shared-cache', { isCache: true });+ const own = await seedBlob('own-cache', { isCache: true });+ const live = await seedBlob('live-cache', { isCache: true });+ const pinned = await seedBlob('pinned-file');+ for (const entry of [shared, own, live, pinned]) await ledger.addRef({+ hash: entry.hash, refKind: 'integration-cache', refId: `remote:${entry.hash}`,+ originId: 'remote-file',+ }, db);+ for (const entry of [other, shared]) await ledger.addRef({+ hash: entry.hash, refKind: 'integration-cache', refId: `other:${entry.hash}`,+ originId: 'other',+ }, db);+ const total = other.bytes + shared.bytes + own.bytes + live.bytes;+ const params = { live: new Set([live.hash]), integration: 'remote-file' };+ const under = await recycler.scanCache({ ...params, limitBytes: total }, db);+ expect(under).toMatchObject({ totalBytes: total, count: 4, excessBytes: 0, evictable: [] });+ const over = await recycler.scanCache({ ...params, limitBytes: total - own.bytes }, db);+ expect(over).toMatchObject({ totalBytes: total, count: 4, excessBytes: own.bytes });+ expect(over.evictable.map(entry => entry.hash)).toEqual([own.hash]);+ await recycler.evictCacheBlobs({ ...params, hashes: over.evictable.map(entry => entry.hash) }, db);+ expect((await recycler.scanCache({ ...params, limitBytes: total - own.bytes }, db)).excessBytes).toBe(0);+ // If protected/other caches alone exceed the budget, do not widen deletion authority.+ expect((await recycler.scanCache({ ...params, limitBytes: 0 }, db)).evictable).toEqual([]);+ for (const entry of [other, shared, live, pinned])+ expect(fs.existsSync(blobPath(entry.hash, entry.ext))).toBe(true);+ });+it('超限时按 LRU 头部凑够超限量;未超限不出候选', async () => {const a = await seedBlob('cache-a', { isCache: true });const b = await seedBlob('cache-b', { isCache: true });diff --git a/apps/desktop/src/main/cindy-media/recycler.ts b/apps/desktop/src/main/cindy-media/recycler.tsindex a94a15c87b..9162857898 100644--- a/apps/desktop/src/main/cindy-media/recycler.ts+++ b/apps/desktop/src/main/cindy-media/recycler.ts@@ -179,10 +179,13 @@ export async function scanCache(): Promise<CacheScan> {const limitBytes = params.limitBytes ?? CACHE_LIMIT_BYTES;const rows = await ledger.listCacheBlobsByLru(db, params.integration);- const totalBytes = rows.reduce((sum, r) => sum + r.bytes, 0);+ // Integration scoping restricts eviction, not the shared warehouse budget.+ const { cacheBytes: totalBytes, cacheCount: count } = params.integration+ ? await ledger.getStorageStats(db)+ : { cacheBytes: rows.reduce((sum, r) => sum + r.bytes, 0), cacheCount: rows.length };const scan: CacheScan = {totalBytes,- count: rows.length,+ count,limitBytes,excessBytes: totalBytes - limitBytes,evictable: [],diff --git a/apps/desktop/src/main/mcp-apps/__tests__/remoteViews.test.ts b/apps/desktop/src/main/mcp-apps/__tests__/remoteViews.test.tsindex 1fa3848b60..5f2a26cb41 100644--- a/apps/desktop/src/main/mcp-apps/__tests__/remoteViews.test.ts+++ b/apps/desktop/src/main/mcp-apps/__tests__/remoteViews.test.ts@@ -33,16 +33,17 @@ const closeCode = ts.transpileModule(linkSource.statements.filter((node): node i.map((node) => node.getText(linkSource).replace(/^export /, '')).join('\n'), {compilerOptions: { target: ts.ScriptTarget.ES2022 },}).outputText;-function linkFixture(): { closeEpoch: (device: string) => number; close: (device: string) => void; closeLink: ReturnType<typeof vi.fn> } {+function linkFixture(): { closeEpoch: (device: string) => number; close: (device: string) => void; closeLink: ReturnType<typeof vi.fn>; stopFilePeers: ReturnType<typeof vi.fn> } {const closeLink = vi.fn();+ const stopFilePeers = vi.fn();const deps = {openLinkCloseEpochs: new Map<string, number>(), openLinkInFlight: new Map(),invalidatePluginOauth: vi.fn(), transportTimeoutReopen: { cancel: vi.fn() },- cancelSubscriptionReplay: vi.fn(), client: { closeLink },+ cancelSubscriptionReplay: vi.fn(), client: { closeLink }, stopFilePeers,};const api = new Function(...Object.keys(deps), closeCode +'; return { closeEpoch: getRemoteLinkCloseEpoch, close: closeRemoteLink };')(...Object.values(deps));- return { ...api, closeLink };+ return { ...api, closeLink, stopFilePeers };}function fixture() {let owner: object | undefined = {};@@ -91,6 +92,7 @@ describe('Main-bound remote MCP App Views', () => {expect(state.mounts.has(local.viewId)).toBe(false);expect(await otherFrame({ op: 'poll' })).toEqual([]);expect(f.link.closeLink).toHaveBeenCalledExactlyOnceWith('device-a', 'user');+ expect(f.link.stopFilePeers).toHaveBeenCalledExactlyOnceWith('device-a');// A fresh explicit open can use the new generation; the old frame stays revoked.expect(await f.open()).toHaveProperty('transport', 'sandbox');await expect(frame({ op: 'poll' })).rejects.toThrow('MCP_APP_LINK_CLOSED');diff --git a/docs/dev-rules/media-storage-and-protocols.md b/docs/dev-rules/media-storage-and-protocols.mdindex ad6a2eb6ba..71fb6a6c25 100644--- a/docs/dev-rules/media-storage-and-protocols.md+++ b/docs/dev-rules/media-storage-and-protocols.md@@ -75,6 +75,7 @@不可再生用户内容,必须沿用现有 pin/引用流程转为不可按缓存回收。- 远程文件的长期复用(2026-10-16 用户要求)不以短 TTL 清空:媒体经 `ingestMedia` /`integration-cache` 持久入仓,`remote-file` 命名空间按现有缓存预算自动 LRU 回收。+ 预算用量统计整个媒体仓的 cache 字节,命名空间只限制逐出候选,不另分配一份额度。自动清理只接受该命名空间独占且仍为 `isCache` 的字节;扫描和条件删除都检查其他引用与 pin,不能清理聊天附件或其他集成的共享字节。其他媒体清理维持原手动流程。普通 HTML 等非媒体仍走 `remote-file-cache`。完整身份、复验与平台清理策略见