diff --git a/.agents/notes/implemented/architecture/2026-11-23-chat-files-live-in-the-aeven-folder.i18n.yaml b/.agents/notes/implemented/architecture/2026-11-23-chat-files-live-in-the-aeven-folder.i18n.yaml index b30bceb7f4..7ca198fce2 100644 --- a/.agents/notes/implemented/architecture/2026-11-23-chat-files-live-in-the-aeven-folder.i18n.yaml +++ b/.agents/notes/implemented/architecture/2026-11-23-chat-files-live-in-the-aeven-folder.i18n.yaml @@ -2,5 +2,5 @@ # side as of the last confirmed-consistent state. Both languages carry equal authority; # after editing either side, bring the other along and re-record with: # pnpm run verify-translation-pairing --write .agents/notes/implemented/architecture/2026-11-23-chat-files-live-in-the-aeven-folder.md -2026-11-23-chat-files-live-in-the-aeven-folder.md: c66c1b743eaae83fe7ab6fe5a1421303cf3e6759 -2026-11-23-chat-files-live-in-the-aeven-folder.zh.md: bceeca1f9b1b9e5cb5a3a8408e63c1c9fa8ad7a0 +2026-11-23-chat-files-live-in-the-aeven-folder.md: 7da1dcbf5637460e1de8355edb0991c830421c7e +2026-11-23-chat-files-live-in-the-aeven-folder.zh.md: 728f6aa16822a5c121b1ab385580cb58f4fd6a2f diff --git a/.agents/notes/implemented/architecture/2026-11-23-chat-files-live-in-the-aeven-folder.md b/.agents/notes/implemented/architecture/2026-11-23-chat-files-live-in-the-aeven-folder.md index c66c1b743e..7da1dcbf56 100644 --- a/.agents/notes/implemented/architecture/2026-11-23-chat-files-live-in-the-aeven-folder.md +++ b/.agents/notes/implemented/architecture/2026-11-23-chat-files-live-in-the-aeven-folder.md @@ -15,7 +15,7 @@ A chat without a folder of its own works inside the account's Aeven folder on ev - **Hosted.** With `AVN_HOSTED_SANDBOX=1`, `aeven-folder-sync` uses `sandbox/accounts` with `perAccount`, so each account's managed folder, the only folder its jailed commands see and the one its disk quota covers, is its Aeven folder. The files cloud sessions make reach the account's desktops and the file cloud. `advertise` stays false: a jailed command sees only its session's subfolder, not the folder's root. A cloud session filed in a folder workspace works in `.aeven-projects//`, which file sync ignores: that workspace's files already travel through its workspace folder or Git, and syncing the cloud's copy as well sent the same project twice, without its `.git`. - **Desktop.** `working-directory` asks the new `working-directory/account-folder` bail event for a session that records no directory, or sits in a workspace without a folder, and `aeven-folder-sync` answers with the account's Aeven folder when this device's folder belongs to that account. The session then works in `~/Documents/Aeven/chats`, and a conversation another device ran resolves its relative paths in the copy file sync brought here. Without an answer, such as a second account of a device whose folder another account claimed, the session records no directory and keeps the sandbox policy's `~/.aeven/chats`. The claim of an unowned folder is synchronous so that resolution stays synchronous. - **Ignores.** The default file sync ignores add `.npm` and `.local`, which a jailed command's home caches inside its workspace, and `.aeven-projects`. -- **Reading produced images.** The turn tail draws a produced image through the conversation's image renderer, in the frames generated images take, from the full reference of the copy a tool result of the Turn shared. `GET /api/attachment-file` serves a copy the log cites as an image or names only in produced files, not just one cited as a file: the first realization loaded every produced image from that route, which refused image copies with `ATTACHMENT_NOT_REFERENCED`, so each tile fell back to a row; it shipped without a live check on chat.aeven.io. A closed Turn's reply that embeds a produced image through the copy `reply-images/stored` recorded leaves it to the tail only when the tail can draw that copy. A file the closing message mentions opens like its row, the Files sidebar with its stored copy first. +- **Reading produced images.** The turn tail draws a produced image through the conversation's image renderer, in the frames generated images take, from the full reference of the copy a tool result of the Turn shared. `GET /api/attachment-file` serves a copy the log cites as an image or names only in produced files, not just one cited as a file: the first realization loaded every produced image from that route, which refused image copies with `ATTACHMENT_NOT_REFERENCED`, so each tile fell back to a row; it shipped without a live check on chat.aeven.io. A closed Turn's reply that embeds a produced image through the copy `reply-images/stored` recorded leaves it to the tail only when the tail can draw that copy. A file the closing message mentions opens like its row, the Files sidebar with its stored copy first. A reply's image resolves to its stored copy through the image cache's `peek`, which names the durable URL from the reference before any read or Session binding: on the desktop app a synced conversation's replies rendered before the binding existed fell back to the authored path, failed, and showed "Image not shown" until a remount. A copy named only in produced files is fetched from the account before it is served, as any cited attachment is. - **Opening a missing file.** `session/openWorkspacePath` classifies an opener failure at a path where nothing exists as `session/path-missing`, and reports any other failure with the opener's stderr instead of the `Command failed:` line. The chat view's file opener no longer prefixes the Host message. A produced file with a stored copy downloads the copy where the path is missing; otherwise the dialog names the file and the folder and offers that folder instead of a Retry that cannot succeed ([file-open failure dialog](../bug-fix/2026-08-18-tool-row-file-open-failure.md)). A prose link naming only the tail of exactly one produced path opens that path. ## Alternatives considered diff --git a/.agents/notes/implemented/architecture/2026-11-23-chat-files-live-in-the-aeven-folder.zh.md b/.agents/notes/implemented/architecture/2026-11-23-chat-files-live-in-the-aeven-folder.zh.md index bceeca1f9b..728f6aa168 100644 --- a/.agents/notes/implemented/architecture/2026-11-23-chat-files-live-in-the-aeven-folder.zh.md +++ b/.agents/notes/implemented/architecture/2026-11-23-chat-files-live-in-the-aeven-folder.zh.md @@ -15,7 +15,7 @@ Status: implemented - **托管。** 设置 `AVN_HOSTED_SANDBOX=1` 时,`aeven-folder-sync` 以 `perAccount` 使用 `sandbox/accounts`,因此每个账户的托管文件夹(其受限命令唯一能看到、也由其磁盘配额覆盖的文件夹)就是它的 Aeven 文件夹。云端会话制作的文件会到达账户的桌面设备和文件云。`advertise` 仍为 false:受限命令只能看到其会话的子文件夹,看不到该文件夹的根目录。归入文件夹工作区的云端会话在 `.aeven-projects//` 中工作,文件同步忽略它:该工作区的文件已经经由其工作区文件夹或 Git 传输,再同步云端副本会把同一个项目发送两次,而且不带 `.git`。 - **桌面。** 对于未记录目录、或位于没有文件夹的工作区中的会话,`working-directory` 通过新的 `working-directory/account-folder` bail 事件询问,当本设备的文件夹属于该账户时,`aeven-folder-sync` 回答账户的 Aeven 文件夹。会话随即在 `~/Documents/Aeven/chats` 中工作,另一台设备运行的对话也在文件同步带到本机的副本中解析其相对路径。没有回答时(例如设备的文件夹已被另一个账户认领时的第二个账户),会话不记录目录,继续使用沙箱策略的 `~/.aeven/chats`。认领无主文件夹是同步的,因此目录解析仍保持同步。 - **忽略规则。** 默认的文件同步忽略规则新增 `.npm` 与 `.local`(受限命令的主目录会在其工作区内缓存它们),以及 `.aeven-projects`。 -- **查看产出图片。** 轮次尾部通过对话的图片渲染器、在生成图片所用的框中绘制产出图片,来源是该轮次某个工具结果共享的副本的完整引用。`GET /api/attachment-file` 提供日志以图片引用或仅在产出文件中命名的副本,而不只是以文件引用的副本:最初的实现从该路由加载每张产出图片,而该路由以 `ATTACHMENT_NOT_REFERENCED` 拒绝图片副本,因此每个图块都退回为一行;它在发布前没有在 chat.aeven.io 上实际检查。已关闭轮次的回复通过 `reply-images/stored` 记录的副本嵌入产出图片时,只有在尾部能绘制该副本时才把它留给尾部。收尾消息提到的文件像其行一样打开,先在 Files 侧栏中打开其存储副本。 +- **查看产出图片。** 轮次尾部通过对话的图片渲染器、在生成图片所用的框中绘制产出图片,来源是该轮次某个工具结果共享的副本的完整引用。`GET /api/attachment-file` 提供日志以图片引用或仅在产出文件中命名的副本,而不只是以文件引用的副本:最初的实现从该路由加载每张产出图片,而该路由以 `ATTACHMENT_NOT_REFERENCED` 拒绝图片副本,因此每个图块都退回为一行;它在发布前没有在 chat.aeven.io 上实际检查。已关闭轮次的回复通过 `reply-images/stored` 记录的副本嵌入产出图片时,只有在尾部能绘制该副本时才把它留给尾部。收尾消息提到的文件像其行一样打开,先在 Files 侧栏中打开其存储副本。回复中的图片通过图片缓存的 `peek` 解析为其存储副本,`peek` 在任何读取或会话绑定之前就根据引用给出持久 URL:在桌面应用中,同步对话的回复若在绑定存在之前渲染,会退回到作者写的路径、加载失败并显示 "Image not shown",直到重新挂载。仅在产出文件中命名的副本在提供之前会先从账户获取,与任何被引用的附件相同。 - **打开缺失的文件。** `session/openWorkspacePath` 把在不存在任何东西的路径上发生的打开器失败归类为 `session/path-missing`,其他失败则报告打开器的 stderr,而不是 `Command failed:` 那一行。聊天视图的文件打开器不再给 Host 消息加前缀。有存储副本的产出文件在路径缺失时下载该副本;否则对话框写出文件和文件夹,并提供打开该文件夹,而不是一个不可能成功的重试([文件打开失败对话框](../bug-fix/2026-08-18-tool-row-file-open-failure.zh.md))。只写出恰好一个产出路径末尾的正文链接会打开该路径。 ## 考虑过的替代方案 diff --git a/packages/api/session-controller/src/commands.ts b/packages/api/session-controller/src/commands.ts index 1a21654e87..33e1ae028b 100644 --- a/packages/api/session-controller/src/commands.ts +++ b/packages/api/session-controller/src/commands.ts @@ -776,7 +776,11 @@ export class SessionCommandController { if (name === undefined) return undefined const id = brandString(attachmentId) const host = this.ctx.attachments.fileHostPath({ attachmentId: id } as FileAttachmentRef) - const bytes = host === undefined ? undefined : await stat(host).then(info => info.size, () => undefined) + if (host === undefined) return undefined + const size = (): Promise => stat(host).then(info => info.size, () => undefined) + // A copy another device of the account stored arrives from the account first, as any cited attachment does. + let bytes = await size() + if (bytes === undefined && await this.ctx.get('sessionHandoff')?.fetchAttachment(attachmentId) === true) bytes = await size() if (bytes === undefined) return undefined return { attachmentId: id, mediaType: producedMediaType(name), bytes, name, extraction: { textId: id } } as unknown as FileAttachmentRef } diff --git a/packages/client/ui-conversation/src/client/conversation/historical-images.ts b/packages/client/ui-conversation/src/client/conversation/historical-images.ts index 40fd2bc627..d7610af8d5 100644 --- a/packages/client/ui-conversation/src/client/conversation/historical-images.ts +++ b/packages/client/ui-conversation/src/client/conversation/historical-images.ts @@ -26,6 +26,11 @@ export function durableImageUrl(attachment: ImageAttachmentRef, sessionId?: Sess return url.href } +/** Whether this page is the desktop app's, whose Host permits stored-image reads without a Session. */ +function desktopReads(): boolean { + return typeof window !== 'undefined' && (window as { avnDesktop?: unknown }).avnDesktop !== undefined +} + interface ImageUrlEntry { readonly sessionId: SessionId readonly generation: number @@ -76,13 +81,18 @@ export class HistoricalImageCache { } /** - * Return an already-displayable URL without starting a read. + * Return an already-displayable URL without starting a read. A browser reads a stored image from its own URL, which + * the reference alone names, so that URL answers before any read or Session binding exists: a reply rendered while a + * synced conversation is still loading shows its stored image instead of a source this device cannot serve, and + * nothing would re-resolve it once the binding arrived. * @param sessionId - Session authorization and lifetime scope. * @param attachment - Durable image reference. - * @returns current preview or canonical URL when cached. + * @returns the current preview or canonical URL; in a browser, the durable URL when nothing is cached yet. */ peek(sessionId: SessionId, attachment: ImageAttachmentRef): string | undefined { - return this.entries.get(this.key(sessionId, attachment))?.current + const current = this.entries.get(this.key(sessionId, attachment))?.current + if (current !== undefined || typeof document === 'undefined') return current + return durableImageUrl(attachment, desktopReads() ? undefined : sessionId) } /** @@ -136,8 +146,7 @@ export class HistoricalImageCache { // without one (a test runtime) falls back to reading the bytes through the // session binding and minting an object URL. if (typeof document !== 'undefined') { - const desktop = typeof window !== 'undefined' && (window as { avnDesktop?: unknown }).avnDesktop !== undefined - const url = durableImageUrl(attachment, desktop ? undefined : entry.sessionId) + const url = durableImageUrl(attachment, desktopReads() ? undefined : entry.sessionId) // Known at once, so `peek` answers right after `resolve`; a seeded // preview keeps its place as the current URL. entry.current ??= url diff --git a/packages/client/ui-conversation/tests/historical-images.client.spec.ts b/packages/client/ui-conversation/tests/historical-images.client.spec.ts index 7937c2cb7b..218c2e21d7 100644 --- a/packages/client/ui-conversation/tests/historical-images.client.spec.ts +++ b/packages/client/ui-conversation/tests/historical-images.client.spec.ts @@ -55,7 +55,9 @@ describe('HistoricalImageCache', () => { try { await runtime.sessions.remove(sessionId) await Promise.resolve() - expect(cache.peek(sessionId, ATTACHMENT)).toBeUndefined() + // Nothing is cached any more; a browser still names the durable URL, never the revoked preview. + expect(cache.peek(sessionId, preview)).not.toBe('blob:seeded') + expect(cache.peek(sessionId, preview)).toContain('/api/attachment-image') expect(revoked).toHaveBeenCalledWith('blob:seeded') } finally { revoked.mockRestore() @@ -63,6 +65,26 @@ describe('HistoricalImageCache', () => { await runtime.dispose() }) + // A reply rendered while a synced conversation loads shows its stored image, not a path this device lacks (#761). + it('names the durable URL before any read or Session binding', async () => { + const runtime = await SlotTestRuntime.create() + const cache = new HistoricalImageCache(runtime.ctx, runtime.ctx.sessions) + // No binding exists for this session yet, and nothing was resolved: the reference alone names the URL. + const early = cache.peek('s-loading' as never, ATTACHMENT) + expect(early).toContain('/api/attachment-image') + expect(early).toContain('sessionId=s-loading') + expect(early).toContain(`id=${String(ATTACHMENT.attachmentId)}`) + + // The desktop app's Host reads stored images without a Session. + vi.stubGlobal('avnDesktop', {}) + try { + expect(cache.peek('s-loading' as never, ATTACHMENT)).not.toContain('sessionId=') + } finally { + vi.unstubAllGlobals() + } + await runtime.dispose() + }) + it('invalidates a pending image load when its Session binding is released', async () => { await withoutDocument(async () => { const read = Promise.withResolvers>>()