DSH / Atlas
2026-11-19implementedbug-fix

Conversation file references after directory moves

目录移动后的对话文件引用

A Session's directory moves during its life: `enter_worktree`, `exit_worktree`, and Host operations each record a `workspace-root/change` ([Session working directory](../architecture/2026-09-13-session-working-directory.md)). Tool rows, produced-file mentions, presented files, and changed-file cards store the absolute path of the operation that produced them, so they keep naming their file. References that stored onl

Source compatibility: Chinese title uses a compatible non-canonical header

English

Problem

A Session's directory moves during its life: enter_worktree, exit_worktree, and Host operations each record a workspace-root/change (Session working directory). Tool rows, produced-file mentions, presented files, and changed-file cards store the absolute path of the operation that produced them, so they keep naming their file. References that stored only relative text did not:

  • A relative Markdown link in an earlier reply, and a picked @file in an earlier message, were resolved against the directory at the click. After a move they opened the same path in another checkout or reported a missing file.
  • A relative inline image was resolved against the header directory, so an image written in a worktree did not load even before a later move.
  • An opened Sidebar tab stored a relative address for a file inside the Session's directory. After a move and a page reload it showed another file or none.

Decision

Each reference carries an absolute path from the moment it is written. No reader reconstructs the directory a reference was written in.

  • The ui:deliverable-file-references guidance asks the model for absolute Markdown link and image targets.
  • fileAddressFor puts the absolute path in the dsh-resource://file/session/… address: an absolute path is kept, and a relative path is joined to the directory the caller knows. An opened tab names one file for its lifetime.
  • A file or folder picked from the @ list is written as an absolute mention. A file dropped or pasted in Desktop keeps the absolute path the shell reports.
  • A relative path that still reaches the Client resolves against the Session's current directory: one the model wrote despite the guidance, one typed by hand after @, or one written before this decision. Links, images, and context-menu actions share that base.

Alternatives considered

Resolve each relative reference against the directory its message was written in. A Host projection would list each workspace-root/change with its sequence number, and the Client would select the directory by message sequence. It repairs existing conversations and leaves model-visible text unchanged. It adds a projection and a lookup in every reference consumer, and it cannot repair a target the model wrote against the wrong base: in recorded runs with the earlier guidance, a model working in a worktree wrote 7 of 66 link targets relative to the original project. Folding only the loaded events instead of adding a projection misses moves that precede the loaded page of a long conversation. An implementation of this route, a workingDirectoryHistory projection with a Markdown path resolver, was merged in #8268 and reverted in #8438.

Rewrite relative targets to absolute when the reply is stored. The stored reply would differ from the text the model produced, and later requests would replay the altered text. None of the eight surveyed agent products rewrites assistant prose; three of them ask for absolute targets in their prompts instead.

Keep relative tab addresses and convert them when the directory moves. Every Client that holds the Session would rewrite its stored tabs on each move, including a Client that is closed when the move happens.

Leave picked @file mentions relative. The model reads the mention under the directory of that request, so the request itself is correct. The sent message names another file after a move, and its chip becomes plain text after a reload when the file exists only in the earlier directory.

Consequences

Recorded runs with the absolute-target guidance produced 128 link and image targets in eight Sessions on two DeepSeek models, including project paths with spaces and non-ASCII characters; all were absolute and 127 named an existing file. Link targets averaged 76 characters instead of 19 in a project whose path has 51 characters; output tokens per Session showed no measurable rise.

A picked or dropped reference carries its absolute path wherever its serialized text appears: the fallback Session title and the turn-navigation preview show the path when a message starts with a reference. The chip label still shows the file name.

References written before this decision keep their relative text and follow the Session's current directory, and so does a hand-typed @relative/path. The @ list omits out, dist, build, and similar directories, so a file there is reachable only by typing. A tab stored with a relative address keeps following the Session's directory, and opening the same file again adds a second tab under the absolute address.

Compliance with the guidance was measured on DeepSeek models only. A model that still writes a relative target gets the current-directory rule above.

中文

问题

Session 的目录在其生命周期内会移动:enter_worktree、exit_worktree 与 Host 操作各自记录一条 workspace-root/change(Session 工作目录)。工具行、产出文件提及、交付文件与变更文件卡片保存了产生它们的操作的绝对路径,因此始终指向原来的文件。只保存相对文本的引用则不然:

  • 较早回复里的相对 Markdown 链接,以及较早消息里选中的 @文件,按点击时的目录解析。目录移动后,它们打开另一个检出里的同名路径,或报告文件不存在。
  • 相对路径的内联图片按头部目录解析,因此在工作树里写下的图片即使没有之后的移动也无法加载。
  • 已打开的侧边栏 tab 为 Session 目录内的文件保存相对地址。目录移动并刷新页面后,它显示另一个文件,或什么都不显示。

决策

**每个引用从写下时起就携带绝对路径。**读取方不再推断引用写下时所在的目录。

  • ui:deliverable-file-references 指引要求模型为 Markdown 链接与图片的目标使用绝对路径。
  • fileAddressFor 把绝对路径写进 dsh-resource://file/session/… 地址:绝对路径原样保留,相对路径与调用方已知的目录拼接。已打开的 tab 在其存续期间只指向一个文件。
  • 从 @ 列表选中的文件或文件夹写成绝对路径的 mention。Desktop 中拖入或粘贴的文件保留 shell 报告的绝对路径。
  • 仍然到达 Client 的相对路径按 Session 的当前目录解析:模型未遵循指引写下的、在 @ 之后手打的,或在本决策之前写下的。链接、图片与右键菜单动作共用这一基准目录。

考虑过的替代方案

**按消息写下时的目录解析每个相对引用。**由 Host 投影列出每条 workspace-root/change 及其序号,Client 按消息序号选择目录。它能修复已有对话,也不改变模型可见文本。但它新增一个投影,并要求每个引用使用方都做一次查找,而且无法修复模型按错误基准写下的目标:在使用旧指引的实测中,一个在工作树里工作的模型把 66 个链接目标中的 7 个写成了相对原项目的路径。若不加投影而只折叠已加载的事件,长对话中早于已加载页的移动会被漏掉。这条路线的一个实现(workingDirectoryHistory 投影加 Markdown 路径解析函数)曾在 #8268 合入,并在 #8438 回滚。

**在保存回复时把相对目标改写为绝对路径。**保存的回复将不同于模型产生的文本,之后的请求会重放改写后的文本。调研的八个 agent 产品都不改写助手正文;其中三个改为在提示词里要求绝对目标。

**保留相对的 tab 地址,在目录移动时转换。**每个持有该 Session 的 Client 都要在每次移动时改写自己保存的 tab,包括移动发生时已关闭的 Client。

**让选中的 @文件 mention 保持相对。**模型按该次请求的目录读取 mention,所以请求本身是正确的。但目录移动后,已发送的消息指向另一个文件;文件只存在于先前目录时,刷新后它的 chip 会变成纯文本。

影响

使用绝对目标指引的实测在两个 DeepSeek 模型的八个 Session 中产生了 128 个链接与图片目标,其中包含带空格与非 ASCII 字符的项目路径;全部为绝对路径,127 个指向存在的文件。在路径长 51 个字符的项目里,链接目标平均为 76 个字符,此前为 19 个;每个 Session 的输出 token 没有可测量的上升。

选中或拖入的引用在其序列化文本出现的地方都携带绝对路径:消息以引用开头时,兜底的 Session 标题与轮次导航预览会显示该路径。chip 的标签仍显示文件名。

本决策之前写下的引用保留相对文本并跟随 Session 的当前目录,手打的 @相对/路径 也是如此。@ 列表不列出 out、dist、build 等目录,因此其中的文件只能手打引用。以相对地址保存的 tab 继续跟随 Session 的目录,再次打开同一个文件会在绝对地址下新增一个 tab。

对指引的遵循程度只在 DeepSeek 模型上测量过。仍然写出相对目标的模型适用上面的当前目录规则。