Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(plugin): admit 8 GiB downloads and resume after page replacement
Dash9e294565fd9e
diff --git a/apps/desktop/src/main/cindy-brain/__tests__/downloadCache.test.ts b/apps/desktop/src/main/cindy-brain/__tests__/downloadCache.test.tsindex e5f783a409..e008dbf114 100644--- a/apps/desktop/src/main/cindy-brain/__tests__/downloadCache.test.ts+++ b/apps/desktop/src/main/cindy-brain/__tests__/downloadCache.test.ts@@ -4,6 +4,17 @@ import os from 'node:os';import path from 'node:path';import { PluginDownloadCache } from '../downloadCache';+it('reserves an 8 GiB question with metadata without allocating its contents', async () => {+ const root = await fs.realpath(await fs.mkdtemp(path.join(os.tmpdir(), 'download-large-quota-')));+ const cache = new PluginDownloadCache();+ try {+ await cache.reserve(root, path.join(root, 'p', 'a'.repeat(64)), 8 * 1024 ** 3);+ await expect(cache.reserve(root, path.join(root, 'p', 'b'.repeat(64)), 8 * 1024 ** 3)).rejects.toThrow('full');+ } finally {+ await fs.rm(root, { recursive: true, force: true });+ }+});+it('shares quota across plugins, protects reserved/pinned files, and revokes evicted receipts', async () => {const root = await fs.realpath(await fs.mkdtemp(path.join(os.tmpdir(), 'download-quota-test-')));const cache = new PluginDownloadCache(148000);diff --git a/apps/desktop/src/main/cindy-brain/__tests__/downloadSlot.test.ts b/apps/desktop/src/main/cindy-brain/__tests__/downloadSlot.test.tsindex f5ddc6dfe7..de52a6ce4b 100644--- a/apps/desktop/src/main/cindy-brain/__tests__/downloadSlot.test.ts+++ b/apps/desktop/src/main/cindy-brain/__tests__/downloadSlot.test.ts@@ -7,6 +7,49 @@ vi.mock('../../maker-host/outbound-fetch.js', () => ({ guardedOutboundFetch: guaimport { PluginDownloadSlot } from '../downloadSlot';import { PluginDownloadCache } from '../downloadCache';import type { InstalledGhost } from '../../../shared/ghost';+it('drains a destroyed page before a new page resumes the same download id', async () => {+ const root = await fs.realpath(await fs.mkdtemp(path.join(os.tmpdir(), 'download-page-')));+ let oldPage = true, calls = 0, started!: () => void, release!: () => void;+ const ready = new Promise<void>(resolve => { started = resolve; });+ const cleanup = new Promise<void>(resolve => { release = resolve; });+ const slot = new PluginDownloadSlot({root: id => path.join(root,id),scope:()=> 'owner',send(){},+ getGhost:()=>({enabled:true,approval:{},manifest:{node:{},network:{hosts:['github.com']}}}) as unknown as InstalledGhost,+ download:async o => {+ if (++calls === 1) {+ await new Promise<void>(resolve => { o.signal!.addEventListener('abort',()=>resolve(),{once:true}); started(); });+ await cleanup;+ throw Error('old page stopped');+ }+ await fs.writeFile(o.targetPath,'ok');+ return {path:o.targetPath,size:2,sha256:o.sha256,fromCache:false,durationMs:1,resumedFromBytes:0};+ }});+ try {+ const request={kind:'start',id:'same',url:'https://github.com/file',sha256:'a'.repeat(64),bytes:2};+ const old = slot.handle('p',request,()=>oldPage);+ await ready; oldPage=false;+ const fresh = slot.handle('p',request,()=>true);+ await Promise.resolve(); expect(calls).toBe(1);+ release();+ expect(await old).toMatchObject({ok:false});+ expect(await fresh).toMatchObject({ok:true});+ expect(calls).toBe(2);+ } finally { release(); await slot.stopAndWait(); await fs.rm(root,{recursive:true,force:true}); }+});+it('admits 8 GiB archives and rejects an extra byte before invoking the downloader', async () => {+ const root = await fs.realpath(await fs.mkdtemp(path.join(os.tmpdir(), 'download-size-')));+ const download = vi.fn(async () => { throw new Error('fixture stops before allocating bytes'); });+ const slot = new PluginDownloadSlot({ root: id => path.join(root,id), scope: () => 'owner', send() {}, download,+ getGhost: () => ({enabled:true,approval:{},manifest:{node:{},network:{hosts:['github.com']}}}) as unknown as InstalledGhost,+ });+ try {+ const request = {kind:'start',id:'large',url:'https://github.com/file',sha256:'a'.repeat(64),bytes:8*1024**3};+ await slot.handle('p',request);+ expect(download).toHaveBeenCalledOnce();+ expect(download.mock.calls[0]).toEqual([expect.objectContaining({expectedSize:8*1024**3,maxBytes:8*1024**3})]);+ await slot.handle('p',{...request,id:'too-large',bytes:request.bytes+1});+ expect(download).toHaveBeenCalledOnce();+ } finally { await fs.rm(root,{recursive:true,force:true}); }+});it('keeps display progress monotonic across restart retries and resets for a new request', async () => {const root = await fs.realpath(await fs.mkdtemp(path.join(os.tmpdir(), 'download-progress-')));const events: any[] = [];diff --git a/apps/desktop/src/main/cindy-brain/downloadCache.ts b/apps/desktop/src/main/cindy-brain/downloadCache.tsindex 54f5f89a12..4216b4d7ca 100644--- a/apps/desktop/src/main/cindy-brain/downloadCache.ts+++ b/apps/desktop/src/main/cindy-brain/downloadCache.ts@@ -18,7 +18,7 @@ export class PluginDownloadCache {private reserved = new Map<string, number>();private pins = new Map<string, number>();private receipts = new Map<string, Receipt>();- constructor(private limit = 4 * 1024 ** 3) {}+ constructor(private limit = 16 * 1024 ** 3) {}revokeAll() {this.receipts.clear();}diff --git a/apps/desktop/src/main/cindy-brain/downloadSlot.ts b/apps/desktop/src/main/cindy-brain/downloadSlot.tsindex 50f0f8bb9d..b9ec9c9699 100644--- a/apps/desktop/src/main/cindy-brain/downloadSlot.ts+++ b/apps/desktop/src/main/cindy-brain/downloadSlot.ts@@ -20,7 +20,7 @@ export class PluginDownloadSlot {private cache = new PluginDownloadCache();private active = new Map<string,- { controller: AbortController; promise: Promise<unknown>; fingerprint: string }+ { controller: AbortController; promise: Promise<unknown>; fingerprint: string; current: () => boolean }>();constructor(private deps: PluginDownloadDeps) {}abortAll() {@@ -143,9 +143,9 @@ export class PluginDownloadSlot {!/^[a-f0-9]{64}$/.test(p.sha256) ||!Number.isSafeInteger(p.bytes) ||(p.bytes as number) < 1 ||- (p.bytes as number) > 2 ** 31+ (p.bytes as number) > 8 * 1024 ** 3)- throw Error('URL, SHA-256 and exact size (up to 2 GiB) are required');+ throw Error('URL, SHA-256 and exact size (up to 8 GiB) are required');const ghost = this.deps.getGhost(id);if (!ghost?.enabled || !ghost.manifest.node || !ghost.manifest.network?.hosts.length)throw Error('Download requires node and network.hosts declarations');@@ -182,6 +182,11 @@ export class PluginDownloadSlot {const fingerprint = JSON.stringify([p.url, p.sha256, p.bytes]);const existing = this.active.get(key);if (existing) {+ if (!existing.current()) {+ existing.controller.abort();+ await existing.promise;+ return this.handle(id, value, callerActive);+ }if (existing.fingerprint !== fingerprint) throw Error('Download id already in use');return existing.promise;}@@ -301,7 +306,7 @@ export class PluginDownloadSlot {};}).finally(() => this.active.delete(key));- this.active.set(key, { controller, promise, fingerprint });+ this.active.set(key, { controller, promise, fingerprint, current });return promise;} catch (e) {return { ok: false, message: (e as Error).message };diff --git a/apps/desktop/src/main/cindy-brain/forge.ts b/apps/desktop/src/main/cindy-brain/forge.tsindex 5c7a3f3649..cd60444359 100644--- a/apps/desktop/src/main/cindy-brain/forge.ts+++ b/apps/desktop/src/main/cindy-brain/forge.ts@@ -3968,7 +3968,7 @@ Node 请求及其子进程一并结束,晚到的授权或子进程启动会被声明 node 和 network.hosts 后可用 cindy.downloads.start({id,url,sha256,bytes});只接受声明的 HTTPS 主机(每次重定向复核),不发送 Cookie、凭证或自定义请求头。-SHA-256 和精确字节数必填,单文件最多 2 GiB。下载从获得队列槽位起最多 2 小时(含重试,不计排队),不改变 Node 调用期限。返回 {ok:true,token,bytes,sha256,fromCache},+SHA-256 和精确字节数必填,单文件最多 8 GiB。下载从获得队列槽位起最多 2 小时(含重试,不计排队),不改变 Node 调用期限。返回 {ok:true,token,bytes,sha256,fromCache},没有宿主路径。取消用 cindy.downloads.cancel({id})。订阅 onHostMessage 的 download-progress 事件:data 含 id、phase、loaded、total、speedBps;phase 为 queued/downloading/verifying/retrying/completed/failed/cancelled,retrying 另含 attempt、delayMs。@@ -3980,7 +3980,7 @@ params.downloads.archive。Node 在本次 RPC 结束前读取或复制文件,旧请求不带 downloadTokens 时保持原有 params 语义。旧宿主无 downloads 时提示升级。下载队列与宿主更新隔离,传输逐块写盘并支持校验、重试与续传。每账号所有插件的缓存-合计最多 4 GiB(含在途预留及每项 64 KiB 管理空间);不淘汰正在下载或被 Node RPC 借用的文件,满额且无可回收项时失败。+合计最多 16 GiB(含在途预留及每项 64 KiB 管理空间);不淘汰正在下载或被 Node RPC 借用的文件,满额且无可回收项时失败。缓存可被回收,重启后 token 失效,重新 start 可复用经校验的文件。卸载插件回收其下载缓存;停用、账号切换或批准身份改变会拒绝旧凭据,不增加用户授权步骤。diff --git a/docs/dev-rules/plugin-download-api.md b/docs/dev-rules/plugin-download-api.mdindex 4903da9dc1..19878bb31c 100644--- a/docs/dev-rules/plugin-download-api.md+++ b/docs/dev-rules/plugin-download-api.md@@ -6,13 +6,13 @@插件必须声明 node 与 network.hosts;仅允许已声明 HTTPS 主机,重定向每跳重新检查。本接口用于匿名公开文件,不携带 Cookie、账号凭证或自定义请求头;带授权请求继续使用 fetch 槽。-SHA-256 与精确字节数必填,单文件最大 2 GiB。目标由宿主管理,不接受本机目标路径。+SHA-256 与精确字节数必填,单文件最大 8 GiB。目标由宿主管理,不接受本机目标路径。面板不获得宿主路径。通过 `node.request({downloadTokens:{archive:token},params:{...}})`交接给同插件 Node,Host 校验账号、插件、批准身份和文件身份后注入 `params.downloads.archive`。携带凭据时 params 必须为对象且不得自带 downloads;旧请求不受影响。路径仅在本次 RPC 生命周期内有效,Node 须在返回前完成读取或复制,不得回传或记录路径。缓存由账号、插件、请求身份隔离;id 相同且内容相同可复用经校验的文件。-每账号总预算 4 GiB(含在途预留及每项 64 KiB 管理空间),按最近使用回收;下载中和 Node 借用中的文件不淘汰。+每账号总预算 16 GiB(含在途预留及每项 64 KiB 管理空间),按最近使用回收;下载中和 Node 借用中的文件不淘汰。缓存满且没有可回收空间时失败。卸载回收该插件缓存;重启后凭据失效,可重新 start 取凭据。下载使用独立队列(`createDownloader()`),不占用宿主更新队列;传输复用统一下载器的逐块写盘(写完一块才拉下一块)、重试与续传。插件提供的 URL 通过下载器的 `request` 注入点走