diff --git a/docs/config-catalog.md b/docs/config-catalog.md index 594e84e390..f959573e49 100644 --- a/docs/config-catalog.md +++ b/docs/config-catalog.md @@ -5008,7 +5008,7 @@ export interface Config { ## `@deepseek-ai/dsh-working-directory` - `inject`: `fs` · `sessionProjections` · `systemPrompt` -- `source`: [`packages/session/working-directory/src/index.ts:64`](../packages/session/working-directory/src/index.ts) +- `source`: [`packages/session/working-directory/src/index.ts:65`](../packages/session/working-directory/src/index.ts) ```ts config-catalog /** Deployment default for Sessions without an original project directory. */ diff --git a/docs/config-catalog.zh.md b/docs/config-catalog.zh.md index de864293e7..ddb52636e9 100644 --- a/docs/config-catalog.zh.md +++ b/docs/config-catalog.zh.md @@ -5010,7 +5010,7 @@ export interface Config { ## `@deepseek-ai/dsh-working-directory` - `inject`: `fs` · `sessionProjections` · `systemPrompt` -- `source`: [`packages/session/working-directory/src/index.ts:64`](../packages/session/working-directory/src/index.ts) +- `source`: [`packages/session/working-directory/src/index.ts:65`](../packages/session/working-directory/src/index.ts) ```ts config-catalog /** Deployment default for Sessions without an original project directory. */ diff --git a/docs/event-producer-consumer.md b/docs/event-producer-consumer.md index 45becd2454..82804c724d 100644 --- a/docs/event-producer-consumer.md +++ b/docs/event-producer-consumer.md @@ -98,7 +98,7 @@ Application listeners are outside this package matrix. Desktop Host subscribes t | `workflow/log` | `emit` | [`packages/workflow/workflow/src/index.ts:58`](../packages/workflow/workflow/src/index.ts) | [`workflow`](../packages/workflow/workflow) (`events.dispatch`) | [`tool-workflow`](../packages/workflow/tool-workflow) | | `workflow/phase` | `emit` | [`packages/workflow/workflow/src/index.ts:51`](../packages/workflow/workflow/src/index.ts) | [`workflow`](../packages/workflow/workflow) (`events.dispatch`) | [`tool-workflow`](../packages/workflow/tool-workflow) | | `workflow/start` | `emit` | [`packages/workflow/workflow/src/index.ts:43`](../packages/workflow/workflow/src/index.ts) | [`workflow`](../packages/workflow/workflow) (`events.dispatch`) | - | -| `working-directory/access` | `waterfall` | [`packages/session/working-directory/src/index.ts:33`](../packages/session/working-directory/src/index.ts) | [`working-directory`](../packages/session/working-directory) (`waterfall`) | `worktree` | +| `working-directory/access` | `waterfall` | [`packages/session/working-directory/src/index.ts:34`](../packages/session/working-directory/src/index.ts) | [`working-directory`](../packages/session/working-directory) (`waterfall`) | `worktree` | | `workspace/session-activity` | `waterfall` | [`packages/workspace/workspace/src/index.ts:129`](../packages/workspace/workspace/src/index.ts) | [`workspace`](../packages/workspace/workspace) (`waterfall`) | [`agent`](../packages/core/agent), [`jobs`](../packages/jobs/jobs), [`schedule`](../packages/schedule/schedule), [`subagent`](../packages/subagent/subagent) | | `workspace/session-archived` | `parallel` | [`packages/workspace/workspace/src/index.ts:156`](../packages/workspace/workspace/src/index.ts) | [`workspace`](../packages/workspace/workspace) (`parallel`) | `worktree` | | `workspace/session-stop` | `parallel` | [`packages/workspace/workspace/src/index.ts:147`](../packages/workspace/workspace/src/index.ts) | [`workspace`](../packages/workspace/workspace) (`parallel`) | [`agent`](../packages/core/agent), [`jobs`](../packages/jobs/jobs), [`schedule`](../packages/schedule/schedule), [`subagent`](../packages/subagent/subagent) | diff --git a/docs/event-producer-consumer.zh.md b/docs/event-producer-consumer.zh.md index b54ab96fb4..cbf071daab 100644 --- a/docs/event-producer-consumer.zh.md +++ b/docs/event-producer-consumer.zh.md @@ -100,7 +100,7 @@ | `workflow/log` | `emit` | [`packages/workflow/workflow/src/index.ts:58`](../packages/workflow/workflow/src/index.ts) | [`workflow`](../packages/workflow/workflow) (`events.dispatch`) | [`tool-workflow`](../packages/workflow/tool-workflow) | | `workflow/phase` | `emit` | [`packages/workflow/workflow/src/index.ts:51`](../packages/workflow/workflow/src/index.ts) | [`workflow`](../packages/workflow/workflow) (`events.dispatch`) | [`tool-workflow`](../packages/workflow/tool-workflow) | | `workflow/start` | `emit` | [`packages/workflow/workflow/src/index.ts:43`](../packages/workflow/workflow/src/index.ts) | [`workflow`](../packages/workflow/workflow) (`events.dispatch`) | - | -| `working-directory/access` | `waterfall` | [`packages/session/working-directory/src/index.ts:33`](../packages/session/working-directory/src/index.ts) | [`working-directory`](../packages/session/working-directory) (`waterfall`) | `worktree` | +| `working-directory/access` | `waterfall` | [`packages/session/working-directory/src/index.ts:34`](../packages/session/working-directory/src/index.ts) | [`working-directory`](../packages/session/working-directory) (`waterfall`) | `worktree` | | `workspace/session-activity` | `waterfall` | [`packages/workspace/workspace/src/index.ts:129`](../packages/workspace/workspace/src/index.ts) | [`workspace`](../packages/workspace/workspace) (`waterfall`) | [`agent`](../packages/core/agent), [`jobs`](../packages/jobs/jobs), [`schedule`](../packages/schedule/schedule), [`subagent`](../packages/subagent/subagent) | | `workspace/session-archived` | `parallel` | [`packages/workspace/workspace/src/index.ts:156`](../packages/workspace/workspace/src/index.ts) | [`workspace`](../packages/workspace/workspace) (`parallel`) | `worktree` | | `workspace/session-stop` | `parallel` | [`packages/workspace/workspace/src/index.ts:147`](../packages/workspace/workspace/src/index.ts) | [`workspace`](../packages/workspace/workspace) (`parallel`) | [`agent`](../packages/core/agent), [`jobs`](../packages/jobs/jobs), [`schedule`](../packages/schedule/schedule), [`subagent`](../packages/subagent/subagent) | diff --git a/docs/persistence-catalog.i18n.yaml b/docs/persistence-catalog.i18n.yaml index e645630d53..46e75fa19c 100644 --- a/docs/persistence-catalog.i18n.yaml +++ b/docs/persistence-catalog.i18n.yaml @@ -300,8 +300,8 @@ en: e8dd0cebbb930eb7 zh: e8dd0cebbb930eb7 /session-persistence-event-catalog/events/working-directory/working-directory-change-log-only: - en: bf12683fa0fe3dfa - zh: 79a678a53cee33b9 + en: fbdf3777f155f458 + zh: 98dc9a9351c07415 /session-persistence-event-catalog/events/workspace: en: 63ee1a85e4b59ae3 zh: 63ee1a85e4b59ae3 @@ -1494,8 +1494,8 @@ en: bef51e0442ebb903 zh: 240ebeb160533d8c /session-persistence-event-catalog/resolved-persistence-types/cwd: - en: 166c1be5f6237f1b - zh: 5002d35a2ec5fb1e + en: 6a6f06c1421739c3 + zh: 0e28ae71c2e84a1d /session-persistence-event-catalog/resolved-persistence-types/decision-durationms-exitcode-handlerid: en: a99ac57bbec0370f zh: 9073329e324a66e0 @@ -1929,8 +1929,8 @@ en: 0b74295f7c5c8f11 zh: 5f1213cec87f6be0 /session-persistence-event-catalog/resolved-persistence-types/kind-working-directory: - en: a36b909ecbd38156 - zh: b02edb123e72fbb1 + en: f688f9a75f549c23 + zh: 03ccb103398fc27b /session-persistence-event-catalog/resolved-persistence-types/max-tokens-messages-model-thinking: en: 3216b23c131d0070 zh: 73ca171c6014f16e diff --git a/docs/persistence-catalog.md b/docs/persistence-catalog.md index e50b0e571e..51530b9db9 100644 --- a/docs/persistence-catalog.md +++ b/docs/persistence-catalog.md @@ -1329,7 +1329,7 @@ Source: [`packages/web/web-search-deepseek/src/provider.ts:89`](../packages/web/ } ``` -Source: [`packages/session/working-directory/src/index.ts:56`](../packages/session/working-directory/src/index.ts) +Source: [`packages/session/working-directory/src/index.ts:57`](../packages/session/working-directory/src/index.ts) ### `workspace/*` @@ -6209,7 +6209,7 @@ Sources: [`packages/compaction/compaction/src/types.ts:24`](../packages/compacti SHA-256: `da60ed58a8fa23d7aa4920ab5c1f4e3d28109cb0797ef9e5c8b125721b847582` -Sources: [`packages/session/working-directory/src/index.ts:56`](../packages/session/working-directory/src/index.ts) +Sources: [`packages/session/working-directory/src/index.ts:57`](../packages/session/working-directory/src/index.ts) | Property | Presence | Type | |---|---|---| @@ -7949,7 +7949,7 @@ Sources: [`packages/experimental/webhook/src/types.ts:74`](../packages/experimen SHA-256: `2235d957bf4b7c6cf959231d480f0ba1f3a6d72d82981493fb6c7c963021d3d5` -Sources: [`packages/session/working-directory/src/index.ts:49`](../packages/session/working-directory/src/index.ts) +Sources: [`packages/session/working-directory/src/index.ts:50`](../packages/session/working-directory/src/index.ts) | Property | Presence | Type | |---|---|---| diff --git a/docs/persistence-catalog.zh.md b/docs/persistence-catalog.zh.md index 44821431d7..1f9ec58b35 100644 --- a/docs/persistence-catalog.zh.md +++ b/docs/persistence-catalog.zh.md @@ -1331,7 +1331,7 @@ export type SessionEvent = { } ``` -来源:[`packages/session/working-directory/src/index.ts:56`](../packages/session/working-directory/src/index.ts) +来源:[`packages/session/working-directory/src/index.ts:57`](../packages/session/working-directory/src/index.ts) ### `workspace/*` @@ -6211,7 +6211,7 @@ SHA-256: `3e4e7683b0192c9f0e6a75c59076108f017892cdb302a98032c2632fd79c356f` SHA-256: `da60ed58a8fa23d7aa4920ab5c1f4e3d28109cb0797ef9e5c8b125721b847582` -来源:[`packages/session/working-directory/src/index.ts:56`](../packages/session/working-directory/src/index.ts) +来源:[`packages/session/working-directory/src/index.ts:57`](../packages/session/working-directory/src/index.ts) | 属性 | 存在性 | 类型 | |---|---|---| @@ -7951,7 +7951,7 @@ SHA-256: `9edc162949abf93bd5ff049191b345454ba104f583937ce5580fb50f067d2b94` SHA-256: `2235d957bf4b7c6cf959231d480f0ba1f3a6d72d82981493fb6c7c963021d3d5` -来源:[`packages/session/working-directory/src/index.ts:49`](../packages/session/working-directory/src/index.ts) +来源:[`packages/session/working-directory/src/index.ts:50`](../packages/session/working-directory/src/index.ts) | 属性 | 存在性 | 类型 | |---|---|---| diff --git a/docs/persistence-schema.json b/docs/persistence-schema.json index 7f6e0f2741..1f507fafaa 100644 --- a/docs/persistence-schema.json +++ b/docs/persistence-schema.json @@ -159,7 +159,7 @@ {"digest":"2142e391b9ccb60d487afcf373ce74db98d952f69e8289eddb352a7e16e996c5","names":[],"sources":[]}, {"digest":"2152caf1a71e588e4df2358a806dea24936c1c47131134f01a12939d12cdc0c0","names":["packages/team/agent-team/src/types.ts#TeamMessageSource"],"sources":["packages/team/agent-team/src/types.ts:121"]}, {"digest":"21fb6a90d5068f6a0003b7ab316ed2f56342477146a65c00db0f13c4d8df667d","names":[],"sources":[]}, - {"digest":"2235d957bf4b7c6cf959231d480f0ba1f3a6d72d82981493fb6c7c963021d3d5","names":[],"sources":["packages/session/working-directory/src/index.ts:49"]}, + {"digest":"2235d957bf4b7c6cf959231d480f0ba1f3a6d72d82981493fb6c7c963021d3d5","names":[],"sources":["packages/session/working-directory/src/index.ts:50"]}, {"digest":"224aa11d4d5f88c450822d01b99e6ca5e3a9c7f26a5ede10bae33384a09ef4dc","names":[],"sources":[]}, {"digest":"234142ee4f996f38cc9fa3b8b3e3de29b03c9aefe5ebf6c224eddd564505aa85","names":[],"sources":[]}, {"digest":"237c004c73b6b288246816e0d7fde16e09c63a47aa3b1227383d7afe58666163","names":[],"sources":[]}, @@ -607,7 +607,7 @@ {"digest":"d9196086e41e4dd5c2ce87f5c25529c8112a1731d258cf0728747d41a9ee3241","names":[],"sources":[]}, {"digest":"d9c462b9f62fdd3efc76a44b9524dc8781f6b91cd9c7e584b17d971defafebab","names":["packages/llm/llm/src/message.ts#ToolMessageSource"],"sources":["packages/llm/llm/src/message.ts:29"]}, {"digest":"d9edf1862e4471d6ad8a106a3f4160e0643874368707d50ecd8e27e5ee7a2567","names":[],"sources":[]}, - {"digest":"da60ed58a8fa23d7aa4920ab5c1f4e3d28109cb0797ef9e5c8b125721b847582","names":[],"sources":["packages/session/working-directory/src/index.ts:56"]}, + {"digest":"da60ed58a8fa23d7aa4920ab5c1f4e3d28109cb0797ef9e5c8b125721b847582","names":[],"sources":["packages/session/working-directory/src/index.ts:57"]}, {"digest":"dacf3d5f3e4ff619c1320e64a48dec5e7ecd7870bece65fbd449a0e63adfa521","names":[],"sources":[]}, {"digest":"db06ef35b27a38425046b2228fa6bce9582abe140d781d363137eb2f4d233a1c","names":[],"sources":[]}, {"digest":"db6c5246911d47a7969f6b4cb47c7d0dbbde75c402710b22ace3672fa97bebe0","names":[],"sources":[]}, diff --git a/packages/client/ui-chat/README.i18n.yaml b/packages/client/ui-chat/README.i18n.yaml index 082b54c10d..bc95795cc8 100644 --- a/packages/client/ui-chat/README.i18n.yaml +++ b/packages/client/ui-chat/README.i18n.yaml @@ -15,8 +15,8 @@ en: 41cd21266011d571 zh: 3172d1a2acbb27b7 /deepseek-ai-dsh-client-ui-chat/reference-previews: - en: 5d88ffc61638ee14 - zh: 32265e3d953c9389 + en: 90e75f3a18a86854 + zh: bb7b0a10050de9aa /deepseek-ai-dsh-client-ui-chat/hidden-chat-rows: en: 8ca277dc7fed699f zh: 167478dba50f3904 diff --git a/packages/client/ui-chat/README.md b/packages/client/ui-chat/README.md index c62b0913da..166ef9976b 100644 --- a/packages/client/ui-chat/README.md +++ b/packages/client/ui-chat/README.md @@ -37,7 +37,7 @@ Image drag actions arrive through the image entry’s inject face from [ui-file- Sent generic-file attachments retain the draft's [file-card radius](../../../docs/ui-radius.md#radius-scale). -`ChatView` supplies file and HTTP(S) navigation through the existing `MarkdownDelegateProvider` around its node list, passing `requestOpenFile`, `openExternalLink`, and `fileImages` directly. Its file opener retains Chat's failure feedback and retry handling. Assistant Markdown file links open in the right Sidebar after the message settles, including references to unmodified files. Relative link and image paths resolve from the viewed Session's current working directory, or its workspace root when none is recorded; absolute paths retain the same Session's filesystem access. [Supported Markdown line references](../ui-primitives/README.md#rendering-agent-output) navigate to the first specified line and reuse an existing file tab. Missing files show the preview's error state. +`ChatView` supplies file and HTTP(S) navigation through the existing `MarkdownDelegateProvider` around its node list, passing `requestOpenFile`, `openExternalLink`, and `fileImages` directly. Its file opener retains Chat's failure feedback and retry handling. Assistant Markdown file links open in the right Sidebar after the message settles, including references to unmodified files. Relative link and image paths in an Assistant message resolve from the directory that was current when the message was written, using the `workingDirectoryHistory` projection; without that history they resolve from the Session's current working directory, or its workspace root when none is recorded; absolute paths retain the same Session's filesystem access. [Supported Markdown line references](../ui-primitives/README.md#rendering-agent-output) navigate to the first specified line and reuse an existing file tab. Missing files show the preview's error state. `ChatView` also passes `renderCode`, so each Markdown fence in the Chat flow that has a language and content renders through the session-scoped `conversation.chat.markdown.fence` hoc slot. Its `entryKey` is the lowercased fence language, and its owner props carry that `lang`, the fence `code`, the `streaming` state, and `meta`, the rest of the info string when present. The slot content is a plain code block without unified-diff rows, so a language without a layer renders as code. Chat registers layers for `math`, which shows the source while the message streams and display TeX after it settles, and for `diff` and `patch`, which render unified-diff rows in place of the content. Other plugins add a language by registering a layer whose `key` is the lowercased language: a layer that omits `children` replaces the code block, a layer that renders `children` decorates it, and either may parse its own parameters from `meta`. diff --git a/packages/client/ui-chat/README.zh.md b/packages/client/ui-chat/README.zh.md index 653315cd51..f7af022c09 100644 --- a/packages/client/ui-chat/README.zh.md +++ b/packages/client/ui-chat/README.zh.md @@ -37,7 +37,7 @@ kind: "package-reference" 已发送的普通文件附件保留草稿中的[文件卡片圆角](../../../docs/ui-radius.zh.md#radius-scale)。 -`ChatView` 通过节点列表外围既有的 `MarkdownDelegateProvider` 提供文件及 HTTP(S) 导航,直接传入 `requestOpenFile`、`openExternalLink` 和 `fileImages`。文件打开动作保留 Chat 的失败反馈与重试处理。Assistant Markdown 文件链接在消息落定后可于右侧栏打开,包括未修改文件的引用。相对链接与图片路径基于当前查看的 Session 的当前工作目录解析,未记录时回落到其工作区根目录;绝对路径仍使用同一 Session 的文件系统访问。[支持的 Markdown 行号引用](../ui-primitives/README.zh.md#rendering-agent-output)定位到指定起始行,并复用现有文件标签。文件缺失时显示预览错误状态。 +`ChatView` 通过节点列表外围既有的 `MarkdownDelegateProvider` 提供文件及 HTTP(S) 导航,直接传入 `requestOpenFile`、`openExternalLink` 和 `fileImages`。文件打开动作保留 Chat 的失败反馈与重试处理。Assistant Markdown 文件链接在消息落定后可于右侧栏打开,包括未修改文件的引用。Assistant 消息中的相对链接与图片路径按该消息写下时的当前目录解析(取自 `workingDirectoryHistory` 投影);没有该历史时按 Session 的当前工作目录解析,未记录时回落到其工作区根目录;绝对路径仍使用同一 Session 的文件系统访问。[支持的 Markdown 行号引用](../ui-primitives/README.zh.md#rendering-agent-output)定位到指定起始行,并复用现有文件标签。文件缺失时显示预览错误状态。 `ChatView` 还传入 `renderCode`,因此 Chat 消息流中带语言且有内容的每个 Markdown 围栏都经由 session 作用域的 `conversation.chat.markdown.fence` hoc slot 渲染。其 `entryKey` 为小写的围栏语言,owner props 携带该 `lang`、围栏 `code`、`streaming` 状态,以及存在时为 info string 其余部分的 `meta`。slot 内容是不带统一 diff 行的普通代码块,因此没有对应层的语言按代码渲染。Chat 自带 `math` 层,消息流式输出时显示源码,落定后显示行间 TeX;还自带 `diff` 与 `patch` 层,以统一 diff 行代替内容渲染。其他插件注册 `key` 为小写语言的层即可接入该语言:不渲染 `children` 的层替换代码块,渲染 `children` 的层装饰代码块,两者都可以自行从 `meta` 解析参数。 diff --git a/packages/client/ui-chat/src/client/chat/AssistantNodeView.tsx b/packages/client/ui-chat/src/client/chat/AssistantNodeView.tsx index ad5963c093..d2767703a2 100644 --- a/packages/client/ui-chat/src/client/chat/AssistantNodeView.tsx +++ b/packages/client/ui-chat/src/client/chat/AssistantNodeView.tsx @@ -1,7 +1,11 @@ import { memo, useCallback, useMemo } from 'react' +import { MarkdownPathScope } from '@deepseek-ai/dsh-client-ui-primitives' import type { InjectFace, PropsRenderSlots } from '@deepseek-ai/dsh-client-ui-slots' +import { resolveWorkspacePath } from '@deepseek-ai/dsh-util-workspace-path' +import type {} from '@deepseek-ai/dsh-working-directory/client' import type { ChatFileMentions, ChatNodeViewProps, PresentationInjected, TurnTailOwnerProps } from '../contract/slots.ts' import { AssistantMarkdown } from './AssistantMarkdown.tsx' +import { directoryAt } from './directory-at.ts' /** Business readers owned by the assistant renderer's existing Slot registration. */ export interface AssistantNodeInjected extends PresentationInjected { @@ -17,7 +21,7 @@ type AssistantNodeViewProps = ChatNodeViewProps<'assistant-step'> & InjectFace getTriggerProps(() => ({ @@ -46,22 +50,30 @@ export const AssistantNodeView = memo(function AssistantNodeView({ : turnProcess.spec.answerStep === data.step && turnProcess.spec.inlineReasoning) && !turnProcess.open const revealProcess = useCallback(() => { turnProcess?.setOpen(true) }, [turnProcess]) + // Relative destinations name files in the directory that was current when this message was written. + const directory = useProjection('workingDirectoryHistory', history => directoryAt(history, node.anchorSeq)) + const resolvePath = useCallback( + (path: string) => directory === undefined ? path : resolveWorkspacePath(directory, path), + [directory], + ) return ( - + + + ) }) diff --git a/packages/client/ui-chat/src/client/chat/ChatView.tsx b/packages/client/ui-chat/src/client/chat/ChatView.tsx index 9e415da38c..7ee99e6d00 100644 --- a/packages/client/ui-chat/src/client/chat/ChatView.tsx +++ b/packages/client/ui-chat/src/client/chat/ChatView.tsx @@ -100,7 +100,7 @@ export function ChatView({ const inbox = useProjection('inbox') as InboxState | undefined // Workspace root off the session list row: path summaries display relative to it. const rootCwd = useSessions(s => s.byId[sessionId]?.cwd) - // Relative images resolve like file links: from the current directory, else that root. + // Images outside a message's path scope resolve like file links: from the current directory, else that root. const imageCwd = useProjection('workingDirectory') ?? rootCwd const fileImages = useMemo(() => ({ fileDrag, diff --git a/packages/client/ui-chat/src/client/chat/directory-at.ts b/packages/client/ui-chat/src/client/chat/directory-at.ts new file mode 100644 index 0000000000..d0c2d4a8e7 --- /dev/null +++ b/packages/client/ui-chat/src/client/chat/directory-at.ts @@ -0,0 +1,18 @@ +/** Select the working directory that applied at one Session log position. */ +import type { WorkingDirectoryHistoryEntry } from '@deepseek-ai/dsh-working-directory/client' + +/** + * Find the directory in effect for an event: the last history entry whose seq + * precedes the event's seq. + * @param history - Ascending directory history, or undefined while it is unavailable. + * @param seq - Seq of the event whose recorded paths are being resolved. + * @returns the absolute directory, or undefined when no entry precedes `seq`. + */ +export function directoryAt(history: readonly WorkingDirectoryHistoryEntry[] | undefined, seq: number): string | undefined { + let found: string | undefined + for (const entry of history ?? []) { + if (entry.seq >= seq) break + found = entry.cwd + } + return found +} diff --git a/packages/client/ui-chat/tests/chat-view.client.spec.tsx b/packages/client/ui-chat/tests/chat-view.client.spec.tsx index 2b4b698d7f..0ac9333503 100644 --- a/packages/client/ui-chat/tests/chat-view.client.spec.tsx +++ b/packages/client/ui-chat/tests/chat-view.client.spec.tsx @@ -789,29 +789,42 @@ describe('Chat node rendering', () => { expect(h.openFile).toHaveBeenCalledWith('src/index.ts', { line: 24 }) }) - it('resolves relative Markdown images from the Session\'s current working directory', () => { + it('resolves each message\'s relative images and links from the directory current when it was written', () => { const h = makeHarness({ - nodes: [user(1, 'draw'), assistant(2, '![chart](tmp/a.png)', 1)], - turnEnds: new Map([[1, 2]]), + nodes: [ + user(1, 'draw'), assistant(2, '![before](tmp/a.png) [notes](notes.md)', 1), + user(6, 'again'), assistant(7, '![after](tmp/a.png) [notes again](notes.md)', 2), + ], + turnEnds: new Map([[1, 2], [2, 7]]), }) const sessions = createSnapshotStore({ ids: [SID], phase: 'ready', projectionsBySession: {}, byId: { [SID]: { id: SID, displayTitle: 'proj', cwd: '/proj', running: false, blank: false, updatedAt: 1, retainedBy: {} } }, }) h.props.useSessions = bindSnapshotSelector(sessions) - const directory = createSnapshotStore('/proj/.agents/worktrees/w') - const useDirectory = bindSnapshotSelector(directory) + const projections = createSnapshotStore>({ + workingDirectory: '/proj/w', + workingDirectoryHistory: [{ seq: 0, cwd: '/proj' }, { seq: 4, cwd: '/proj/w' }], + }) + const useProjections = bindSnapshotSelector(projections) const useOther = h.props.useProjection - h.props.useProjection = (key: 'inbox' | 'workingDirectory') => { - const current = useDirectory(value => value) + h.props.useProjection = (key: 'inbox', selector?: (value: never) => unknown) => { + const value: unknown = useProjections(values => values[key]) const other: unknown = useOther(key) - return key === 'workingDirectory' ? current : other + const picked = key in projections.getSnapshot() ? value : other + return selector === undefined ? picked : selector(picked as never) } const view = render() - const source = () => new URL(view.getByRole('img', { name: 'chart' }).getAttribute('src')!, document.baseURI).searchParams.get('path') - expect(source()).toBe('/proj/.agents/worktrees/w/tmp/a.png') - act(() => { directory.set(null) }) - expect(source()).toBe('/proj/tmp/a.png') + const source = (name: string) => new URL(view.getByRole('img', { name }).getAttribute('src')!, document.baseURI).searchParams.get('path') + expect(source('before')).toBe('/proj/tmp/a.png') + expect(source('after')).toBe('/proj/w/tmp/a.png') + fireEvent.click(view.getByRole('button', { name: 'notes' })) + expect(h.openFile).toHaveBeenLastCalledWith('/proj/notes.md') + fireEvent.click(view.getByRole('button', { name: 'notes again' })) + expect(h.openFile).toHaveBeenLastCalledWith('/proj/w/notes.md') + // Without a history, relative destinations fall back to the current directory. + act(() => { projections.set({ workingDirectory: '/proj/w', workingDirectoryHistory: undefined }) }) + expect(source('before')).toBe('/proj/w/tmp/a.png') }) it('threads the injected file-mention vocabulary into the closing prose only', () => { diff --git a/packages/client/ui-primitives/README.i18n.yaml b/packages/client/ui-primitives/README.i18n.yaml index 662fc787a4..bb706eea0d 100644 --- a/packages/client/ui-primitives/README.i18n.yaml +++ b/packages/client/ui-primitives/README.i18n.yaml @@ -24,8 +24,8 @@ en: 8265fa792c6fd9ec zh: 600d2af4d5a3d183 /deepseek-ai-dsh-client-ui-primitives/use-this-package/rendering-agent-output: - en: e2649937f077d4e0 - zh: 6ad604cb5adfc16b + en: 67e5b615e786f933 + zh: ae8ef437861393b7 /deepseek-ai-dsh-client-ui-primitives/use-this-package/localizing-copy: en: 3fd7072b662eed0a zh: 88c6c299c0a6f8cd diff --git a/packages/client/ui-primitives/README.md b/packages/client/ui-primitives/README.md index 5c817b94b2..9f2e282311 100644 --- a/packages/client/ui-primitives/README.md +++ b/packages/client/ui-primitives/README.md @@ -125,7 +125,7 @@ Explicit `./`, `../`, slash/backslash-rooted paths (including UNC), and Windows `JsonTree` clamps collapsed strings to `collapsedStringLines` (three by default). Expanded strings show raw text, retain sibling commas, and fit within the window and outer scrolling containers. Resize and ancestor-scroll events update that limit. Row copy feedback updates independently of JSON value rendering; pending clipboard writes cannot update a different row or an unmounted tree. -`ImageLightbox` is the shared original-image modal with focus restoration and Escape dismissal. Like `Modal`, its mask leaves the Windows caption unpainted, and its close control sits 20px below the caption. The internal thumbnail renderer receives loading/failure labels from its owner. `HoverCard.inline` keeps a file link in the text flow and uses the shared menu material, keyboard-visible focus, and placement above or below the anchor without covering it. Its transparent hover region connects the anchor to the panel across the visual gap, so crossing the gap does not activate content beneath it. Escape closes an open thumbnail even when focus is elsewhere; subsequent Escape presses reach the owner. `MarkdownDelegateProvider.fileImages` supplies a decoded-path resolver and complete image labels: settled image links gain hover previews, and standalone images gain lightbox activation. Image-only anchors retain their single navigation target. The parser recovers only complete, unescaped, standalone local image references with bare spaces and an unambiguous supported image suffix; code and ambiguous destinations remain literal. +`ImageLightbox` is the shared original-image modal with focus restoration and Escape dismissal. Like `Modal`, its mask leaves the Windows caption unpainted, and its close control sits 20px below the caption. The internal thumbnail renderer receives loading/failure labels from its owner. `HoverCard.inline` keeps a file link in the text flow and uses the shared menu material, keyboard-visible focus, and placement above or below the anchor without covering it. Its transparent hover region connects the anchor to the panel across the visual gap, so crossing the gap does not activate content beneath it. Escape closes an open thumbnail even when focus is elsewhere; subsequent Escape presses reach the owner. `MarkdownDelegateProvider.fileImages` supplies a decoded-path resolver and complete image labels: settled image links gain hover previews, and standalone images gain lightbox activation. `MarkdownPathScope` maps each decoded local destination of the enclosed Markdown before it reaches the delegate's file opener, image resolver, drag address, and object menus; rendered labels and alt text keep the authored path, the nearest scope wins, and destinations outside a scope pass unchanged. Image-only anchors retain their single navigation target. The parser recovers only complete, unescaped, standalone local image references with bare spaces and an unambiguous supported image suffix; code and ambiguous destinations remain literal. `DraggableImage` receives explicit `fileDrag: FileDragActions`, also supplied through `MarkdownDelegateProvider.fileImages.fileDrag`. The [file-drag plugin](../ui-file-drag/README.md) owns preparation, transfer, and localized failure feedback; the image primitive manages gestures and cancellation. Resource-backed images prepare on primary pointer down; other sources also prepare on hover. Releasing inside the image preserves preparation for the next gesture; pointer leave releases unused preparation. Markdown export names use the decoded path basename. Panning images skip preparation. Starting before preparation finishes cancels that gesture quietly; an actual preparation failure reports a retry message. Managed Web transfers carry an application-local token and a `DownloadURL` pointing to a plugin-owned Blob URL, with no `text/plain` payload. diff --git a/packages/client/ui-primitives/README.zh.md b/packages/client/ui-primitives/README.zh.md index f3e1c1719a..b457ac97a5 100644 --- a/packages/client/ui-primitives/README.zh.md +++ b/packages/client/ui-primitives/README.zh.md @@ -125,7 +125,7 @@ kind: "package-library" `JsonTree` 把折叠字符串限制为 `collapsedStringLines` 行(默认三行)。展开后显示原始文本、保留同级逗号,并限制在窗口与外层滚动容器内;尺寸变化和祖先滚动事件会更新此限制。行复制反馈独立于 JSON 值渲染更新;尚未完成的剪贴板写入不会更新另一行或已卸载的树。 -`ImageLightbox` 是共享原图浮层,支持焦点恢复与 Esc 关闭。与 `Modal` 相同,其遮罩不覆盖 Windows 顶栏,关闭按钮位于顶栏下方 20px。包内缩略图渲染器由调用方提供加载及失败文案。`HoverCard.inline` 使文件链接保持在文本流内,并使用共享菜单材质、键盘可见焦点,并在锚点上方或下方定位而不遮挡锚点。即使焦点位于其他位置,Esc 也会关闭已打开的缩略图;后续 Esc 按键继续传给 owner。`MarkdownDelegateProvider.fileImages` 提供已解码路径解析器与完整图片文案:消息落定后的图片链接支持悬停预览,独立图片支持点击放大。仅包含图片的链接保留单一导航目标。解析器仅恢复完整、未转义、独立成段且带明确图片扩展名的含裸空格本地图片引用;代码与有歧义的目标保持原文。 透明悬停区域连接锚点与弹层之间的视觉空隙,鼠标经过时不会激活下方内容。 +`ImageLightbox` 是共享原图浮层,支持焦点恢复与 Esc 关闭。与 `Modal` 相同,其遮罩不覆盖 Windows 顶栏,关闭按钮位于顶栏下方 20px。包内缩略图渲染器由调用方提供加载及失败文案。`HoverCard.inline` 使文件链接保持在文本流内,并使用共享菜单材质、键盘可见焦点,并在锚点上方或下方定位而不遮挡锚点。即使焦点位于其他位置,Esc 也会关闭已打开的缩略图;后续 Esc 按键继续传给 owner。`MarkdownDelegateProvider.fileImages` 提供已解码路径解析器与完整图片文案:消息落定后的图片链接支持悬停预览,独立图片支持点击放大。`MarkdownPathScope` 会在所包含 Markdown 的每个已解码本地目标到达委托的文件打开、图片解析、拖放地址与对象菜单之前先做映射;显示的文字与 alt 仍保留原文路径,最近的作用域生效,作用域之外的目标原样传递。仅包含图片的链接保留单一导航目标。解析器仅恢复完整、未转义、独立成段且带明确图片扩展名的含裸空格本地图片引用;代码与有歧义的目标保持原文。 透明悬停区域连接锚点与弹层之间的视觉空隙,鼠标经过时不会激活下方内容。 `DraggableImage` 接收显式的 `fileDrag: FileDragActions`,受管理的 Markdown 图片通过 `MarkdownDelegateProvider.fileImages.fileDrag` 接收同一组回调。[文件拖放插件](../ui-file-drag/README.zh.md) 负责准备、传递与本地化失败提示;图片原语负责手势和取消。带资源引用的图片仅在主指针按下时准备,其他来源也可在悬停时准备。在图片内松开保留准备供下一次手势使用;指针移开释放未使用的准备,平移模式跳过准备。Markdown 导出名取已解码路径的文件名。在准备完成前起拖会静默取消本次手势;实际准备失败才显示重试提示。受管理的 Web 拖放携带应用内令牌和指向插件所持 Blob URL 的 `DownloadURL`,不设置 `text/plain`。 diff --git a/packages/client/ui-primitives/src/index.ts b/packages/client/ui-primitives/src/index.ts index 44dbcd8871..ea6925973c 100644 --- a/packages/client/ui-primitives/src/index.ts +++ b/packages/client/ui-primitives/src/index.ts @@ -119,8 +119,8 @@ export type { CodeBlockProps } from './markdown/CodeBlock.tsx' export { FenceCodeBlock, FenceMathBlock } from './markdown/FenceBlocks.tsx' export type { FenceCodeBlockProps } from './markdown/FenceBlocks.tsx' export { JsonBlock } from './markdown/JsonBlock.tsx' -export { MarkdownDelegateProvider, useMarkdownDelegate } from './markdown/MarkdownDelegate.tsx' -export type { MarkdownDelegate, MarkdownDelegateProviderProps, MarkdownExternalLinkHandler, MarkdownDelegateFenceInfo } from './markdown/MarkdownDelegate.tsx' +export { MarkdownDelegateProvider, MarkdownPathScope, useMarkdownDelegate } from './markdown/MarkdownDelegate.tsx' +export type { MarkdownDelegate, MarkdownDelegateProviderProps, MarkdownExternalLinkHandler, MarkdownDelegateFenceInfo, MarkdownPathResolver, MarkdownPathScopeProps } from './markdown/MarkdownDelegate.tsx' export { DetailDocument, detailDocumentState, useDetailDocumentLabels } from './DetailDocument.tsx' export type { DetailDocumentCopy, DetailDocumentLabels, DetailDocumentRead, DetailDocumentState } from './DetailDocument.tsx' export { MarkdownText } from './markdown/MarkdownText.tsx' diff --git a/packages/client/ui-primitives/src/markdown/MarkdownDelegate.tsx b/packages/client/ui-primitives/src/markdown/MarkdownDelegate.tsx index df0491c34e..93e218d6ea 100644 --- a/packages/client/ui-primitives/src/markdown/MarkdownDelegate.tsx +++ b/packages/client/ui-primitives/src/markdown/MarkdownDelegate.tsx @@ -93,6 +93,43 @@ export function MarkdownDelegateProvider({ ) } +/** + * Map one decoded local Markdown destination to the path the delegate receives. + * @param path - Destination as the document authored it. + * @returns Path passed to file links, image previews, and object menus. + */ +export type MarkdownPathResolver = (path: string) => string + +const identityPath: MarkdownPathResolver = path => path +const MarkdownPathContext = createContext(identityPath) + +/** Props for one local-destination resolution scope. */ +export interface MarkdownPathScopeProps { + /** Resolver for destinations rendered inside this scope; the nearest scope wins. */ + readonly resolvePath: MarkdownPathResolver + readonly children: ReactNode +} + +/** + * Resolve local destinations of the enclosed Markdown before they reach the + * enclosing {@link MarkdownDelegate}, for example against the directory that + * was current when one message was written. Rendered labels, titles, and alt + * text keep the authored path. Outside a scope, destinations pass unchanged. + * @param props - Resolver and child tree. + * @returns the scoped child tree. + */ +export function MarkdownPathScope({ resolvePath, children }: MarkdownPathScopeProps): ReactNode { + return {children} +} + +/** + * Read the nearest local-destination resolver. + * @returns the scope's resolver, or identity outside a scope. + */ +export function useMarkdownPathResolver(): MarkdownPathResolver { + return useContext(MarkdownPathContext) +} + /** * Read the nearest Markdown navigation capabilities. * @returns Owner callbacks, or an empty delegate outside a provider. diff --git a/packages/client/ui-primitives/src/markdown/render.tsx b/packages/client/ui-primitives/src/markdown/render.tsx index 8d24014135..0c8f6e3622 100644 --- a/packages/client/ui-primitives/src/markdown/render.tsx +++ b/packages/client/ui-primitives/src/markdown/render.tsx @@ -28,7 +28,7 @@ import { FenceCodeBlock, FenceMathBlock } from './FenceBlocks.tsx' import { isExplicitFilePath, parseFileLink } from './file-link.ts' import { renderTexToReact } from './katex.tsx' import { LinkIconMedium, classifyLinkPath } from '../LinkIcon.tsx' -import { useMarkdownDelegate } from './MarkdownDelegate.tsx' +import { useMarkdownDelegate, useMarkdownPathResolver } from './MarkdownDelegate.tsx' import { HoverCard } from '../HoverCard.tsx' import { DraggableImage } from '../DraggableImage.tsx' import { ImageLightbox } from '../ImageLightbox.tsx' @@ -640,19 +640,21 @@ function MarkdownFileLink({ file, glyph, children }: { readonly children: ReactNode[] }): ReactNode { const { openFile, fileImages, getTriggerProps } = useMarkdownDelegate() + const resolvePath = useMarkdownPathResolver() const [load] = useState(nextImageLoad) if (openFile === undefined) return <>{children} + const target = { ...file, path: resolvePath(file.path) } // Pure-image anchors already contain their preview and keep one navigation target. const preview = glyph && classifyLinkPath(file.path) === 'image' ? fileImages : undefined - const resolved = preview?.resolve(file.path) + const resolved = preview?.resolve(target.path) const src = resolved === undefined ? undefined : freshImageUrl(resolved, load) const anchor = (