Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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: 18dba0ae335888409022eab367d53ecb8dd60d79
2026-11-23-chat-files-live-in-the-aeven-folder.zh.md: 06d7263ea1e871a81a1ffe8282c3e8347bd810a8
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
Original file line number Diff line number Diff line change
Expand Up @@ -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/<workspace id>/`, 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 shows a produced image whole, from its stored copy where one was recorded, the way generated images show: a lone image at its own proportions, several as tiles. The `produced-images` Turn data index names those images, so a closed Turn's reply that embeds one, by its path or by the copy `reply-images/stored` recorded, leaves it to the tail.
- **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.
- **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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Status: implemented
- **托管。** 设置 `AVN_HOSTED_SANDBOX=1` 时,`aeven-folder-sync` 以 `perAccount` 使用 `sandbox/accounts`,因此每个账户的托管文件夹(其受限命令唯一能看到、也由其磁盘配额覆盖的文件夹)就是它的 Aeven 文件夹。云端会话制作的文件会到达账户的桌面设备和文件云。`advertise` 仍为 false:受限命令只能看到其会话的子文件夹,看不到该文件夹的根目录。归入文件夹工作区的云端会话在 `.aeven-projects/<workspace id>/` 中工作,文件同步忽略它:该工作区的文件已经经由其工作区文件夹或 Git 传输,再同步云端副本会把同一个项目发送两次,而且不带 `.git`。
- **桌面。** 对于未记录目录、或位于没有文件夹的工作区中的会话,`working-directory` 通过新的 `working-directory/account-folder` bail 事件询问,当本设备的文件夹属于该账户时,`aeven-folder-sync` 回答账户的 Aeven 文件夹。会话随即在 `~/Documents/Aeven/chats` 中工作,另一台设备运行的对话也在文件同步带到本机的副本中解析其相对路径。没有回答时(例如设备的文件夹已被另一个账户认领时的第二个账户),会话不记录目录,继续使用沙箱策略的 `~/.aeven/chats`。认领无主文件夹是同步的,因此目录解析仍保持同步。
- **忽略规则。** 默认的文件同步忽略规则新增 `.npm` 与 `.local`(受限命令的主目录会在其工作区内缓存它们),以及 `.aeven-projects`。
- **查看产出图片。** 轮次尾部以完整图片显示产出的图片,有记录的存储副本时来自该副本,方式与生成图片相同:单张保持自身比例,多张平铺。`produced-images` 轮次数据索引列出这些图片,因此已关闭轮次的回复若按路径或按 `reply-images/stored` 记录的副本嵌入其中某张,会把它留给尾部。
- **查看产出图片。** 轮次尾部通过对话的图片渲染器、在生成图片所用的框中绘制产出图片,来源是该轮次某个工具结果共享的副本的完整引用。`GET /api/attachment-file` 提供日志以图片引用或仅在产出文件中命名的副本,而不只是以文件引用的副本:最初的实现从该路由加载每张产出图片,而该路由以 `ATTACHMENT_NOT_REFERENCED` 拒绝图片副本,因此每个图块都退回为一行;它在发布前没有在 chat.aeven.io 上实际检查。已关闭轮次的回复通过 `reply-images/stored` 记录的副本嵌入产出图片时,只有在尾部能绘制该副本时才把它留给尾部。收尾消息提到的文件像其行一样打开,先在 Files 侧栏中打开其存储副本。
- **打开缺失的文件。** `session/openWorkspacePath` 把在不存在任何东西的路径上发生的打开器失败归类为 `session/path-missing`,其他失败则报告打开器的 stderr,而不是 `Command failed:` 那一行。聊天视图的文件打开器不再给 Host 消息加前缀。有存储副本的产出文件在路径缺失时下载该副本;否则对话框写出文件和文件夹,并提供打开该文件夹,而不是一个不可能成功的重试([文件打开失败对话框](../bug-fix/2026-08-18-tool-row-file-open-failure.zh.md))。只写出恰好一个产出路径末尾的正文链接会打开该路径。

## 考虑过的替代方案
Expand Down
4 changes: 2 additions & 2 deletions packages/api/session-controller/README.i18n.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 packages/api/session-controller/README.md
README.md: 157ff3e4b28278b2bbd5b8e7baab803995d74314
README.zh.md: 395644e15e05c840b43f6665fad8ecc1a824d644
README.md: 8294b6fff4e9ec1f5fa94ea4af2e21c01f457351
README.zh.md: c8c2d14d4d4e02316d0580c0e58af8edd9537ce6
2 changes: 1 addition & 1 deletion packages/api/session-controller/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Content search on a Host that limits sessions to their owner asks the search pro

The authenticated `/api/file` route serves absolute paths through the composed filesystem provider. Each file response carries the file's version as its `ETag` with `Cache-Control: private, no-cache`, so a browser re-displaying an unchanged image gets an empty 304 after one `stat`, and every load still passes authentication. For extensionless raster files, including durable attachment objects, it identifies PNG, JPEG, WebP, and GIF bytes so a Markdown image can reference the stored path directly. `pathReads: false` leaves the route unregistered, for a Host serving several accounts whose readers must reach files only through a Session of their own. `/api/attachment-file` serves a stored original only when the Session log cites it: as a file content block, or as a non-image file reference a tool result records in its metadata, such as the film `show_motion` stores.

`openWorkspacePath` refuses with `session/open-unavailable` while `canOpenWorkspacePath()` reports false, so a Host without a desktop never runs a native opener for a caller. When the native opener fails and nothing exists at the path, it refuses with `session/path-missing` and the path, such as a file another device of the account wrote; any other failure is `gateway/internal` with the opener's stderr, not the `Command failed:` line that names its argv.
`GET /api/attachment-file` serves a stored copy the Session log cites as a file, as an image (a produced image's copy, which a tool result shares as an image), or only by id in a tool result's produced files, whose name and media type then come from the produced path. `openWorkspacePath` refuses with `session/open-unavailable` while `canOpenWorkspacePath()` reports false, so a Host without a desktop never runs a native opener for a caller. When the native opener fails and nothing exists at the path, it refuses with `session/path-missing` and the path, such as a file another device of the account wrote; any other failure is `gateway/internal` with the opener's stderr, not the `Command failed:` line that names its argv.

The Client adapter exposes `SessionEventStream`, a Gateway `RemoteJournalStream` bound to one ordinary or direct-subagent address. It opens follow before the initial page, publishes only contiguous `replace`, `prepend`, and `append` changes, and repairs reconnect or sequence gaps through a tail page. Backwards paging has two verbs: `loadOlder()` pulls one 50-message page, and `loadThrough(seq)` — the turn-jump loader — installs one 200-message window anchored on the target seq in a single round trip however far back that is, lowering a shared target when a repeated call joins the pass in flight, stopping once the installed window already covers that target, and reporting busy through the same `loadingOlder` snapshot bit. Ordinary records cover `[event.seq, event.seq]`; packed rows cover `[event.seq, event.seq + memberCount - 1]`. A business, persistence, or unresolved continuity failure terminates the stream, while only physical carrier loss selects automatic resumption. `SessionControlStream` is a Gateway `RemoteSnapshotStream`; every generation opens with a complete process-local baseline, so reconnect replaces queue, jobs, and projection state instead of treating transient values as durable events.

Expand Down
2 changes: 1 addition & 1 deletion packages/api/session-controller/README.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ kind: "package-reference"

经过身份验证的 `/api/file` 路由通过已组合的文件系统提供者提供绝对路径文件。每个文件响应都以文件版本作为 `ETag`,并带 `Cache-Control: private, no-cache`,因此浏览器重新显示未变化的图片时,经一次 `stat` 后得到空的 304,而每次加载仍需通过身份验证。对于无扩展名的栅格文件,包括持久化的附件对象,它会识别 PNG、JPEG、WebP 和 GIF 字节,使 Markdown 图片能够直接引用已存储的路径。`pathReads: false` 不注册该路由,适用于服务多个账号、其读者只能通过自己的 Session 访问文件的 Host。`/api/attachment-file` 只在 Session 日志引用某个已存储原件时才提供它:作为文件内容块,或作为工具结果在其元数据中记录的非图片文件引用,例如 `show_motion` 存储的影片。

当 `canOpenWorkspacePath()` 报告 false 时,`openWorkspacePath` 以 `session/open-unavailable` 拒绝,因此没有桌面的 Host 绝不会为调用者运行原生打开器。原生打开器失败且该路径上什么都不存在时,它以 `session/path-missing` 及该路径拒绝,例如账户另一台设备写出的文件;其他失败为 `gateway/internal`,附带打开器的 stderr,而不是写出其 argv 的 `Command failed:` 那一行。
`GET /api/attachment-file` 提供会话日志以文件、以图片(产出图片的副本,工具结果将其作为图片共享)或仅在工具结果的产出文件中以 id 引用的存储副本;后者的名称和媒体类型取自产出路径。当 `canOpenWorkspacePath()` 报告 false 时,`openWorkspacePath` 以 `session/open-unavailable` 拒绝,因此没有桌面的 Host 绝不会为调用者运行原生打开器。原生打开器失败且该路径上什么都不存在时,它以 `session/path-missing` 及该路径拒绝,例如账户另一台设备写出的文件;其他失败为 `gateway/internal`,附带打开器的 stderr,而不是写出其 argv 的 `Command failed:` 那一行。

Client adapter 提供 `SessionEventStream`,即绑定到一个普通 Session 或 direct subagent address 的 Gateway `RemoteJournalStream`。它在读取首个 page 前打开 follow,只发布连续的 `replace`、`prepend` 和 `append` 变更,并通过 tail page 修复重连或 seq 缺口。向后分页有两个动词:`loadOlder()` 拉一页 50 条 message,而 `loadThrough(seq)`——轮次跳转加载器——无论目标在多远之前,都只用一个往返安装一个锚定在目标 seq 上的 200 条 message 窗口;重复调用会加入进行中的那一趟并下调共享目标,已安装的窗口覆盖该目标时该趟即结束;忙碌状态复用同一个 `loadingOlder` 快照位。普通 record 覆盖 `[event.seq, event.seq]`,packed row 覆盖 `[event.seq, event.seq + memberCount - 1]`。业务、persistence 或无法恢复的连续性错误会终止 stream,只有物理载体断开才触发自动恢复。`SessionControlStream` 是 Gateway `RemoteSnapshotStream`;每代都以完整的进程本地 baseline 开始,因此重连会替换 queue、jobs 和 projection 状态,而不会把瞬态值当作 durable event。

Expand Down
23 changes: 21 additions & 2 deletions packages/api/session-controller/src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

import { randomUUID } from 'node:crypto'
import type { Context } from '@deepseek-ai/cordis'
import { stat } from 'node:fs/promises'
import { producedCopyName, producedMediaType } from './produced-copies.ts'
import { brandString } from '@aeven/brand'
import type { Agent, ModelSelection as AgentModelSelection } from '@aeven/agent'
import { AttachmentError, admitPromptContent } from '@aeven/attachment'
import { readFetchedAttachment } from './file-uploads.ts'
import type { FileAttachmentRef, ImageAttachmentRef, StoredFileAttachment, StoredImageAttachment } from '@aeven/attachment'
import type { AttachmentId, FileAttachmentRef, ImageAttachmentRef, StoredFileAttachment, StoredImageAttachment } from '@aeven/attachment'
import {
ReasoningEffortId, createUserMessage, freezeMessage,
} from '@aeven/llm'
Expand Down Expand Up @@ -758,10 +760,27 @@ export class SessionCommandController {
*/
async referencedFile(sessionId: SessionId, attachmentId: string): Promise<StoredFileAttachment | undefined> {
const source = await this.readSessionState(sessionId)
const ref = referencedAttachment(source.events, 'file', attachmentId)
const ref = referencedAttachment(source.events, 'file', attachmentId) ?? await this.producedCopyRef(source.events, attachmentId)
return ref === undefined ? undefined : readFetchedAttachment(this.ctx, attachmentId, () => this.ctx.attachments.readFile(ref))
}

/**
* The reference of a stored copy a tool result names only in its produced files, which records the copy's id and the
* file's path but no file block: the name and media type come from the path, the length from the stored object.
* @param events - the Session log.
* @param attachmentId - the copy's id.
* @returns the reference, or undefined when no produced file names the copy or this Host does not hold it.
*/
private async producedCopyRef(events: readonly SessionEvent[], attachmentId: string): Promise<FileAttachmentRef | undefined> {
const name = producedCopyName(events, attachmentId)
if (name === undefined) return undefined
const id = brandString<AttachmentId>(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 (bytes === undefined) return undefined
return { attachmentId: id, mediaType: producedMediaType(name), bytes, name, extraction: { textId: id } } as unknown as FileAttachmentRef
}

/**
* Read one image the addressed Session log cites.
* @param sessionId - the Session whose log is searched.
Expand Down
Loading