From 076b0e5881bf8713eef525dd40c4e7b8a9735c33 Mon Sep 17 00:00:00 2001 From: zhc Date: Fri, 23 Oct 2026 18:32:36 +0800 Subject: [PATCH] fix(client): clarify context menu ownership and render icon groups --- apps/desktop/README.i18n.yaml | 4 +- apps/desktop/README.md | 2 +- apps/desktop/README.zh.md | 2 +- apps/desktop/src/file-actions.ts | 11 +- apps/desktop/src/ipc.ts | 5 +- apps/desktop/src/preload-app.ts | 1 - apps/desktop/tests/file-actions.spec.ts | 7 +- apps/desktop/tests/preload-app.spec.ts | 4 +- apps/web/tests/context-menus.e2e.ts | 6 +- docs/event-producer-consumer.md | 3 + docs/event-producer-consumer.zh.md | 3 + packages/client/ui-chat/README.i18n.yaml | 8 +- packages/client/ui-chat/README.md | 4 +- packages/client/ui-chat/README.zh.md | 4 +- packages/client/ui-chat/src/client/apply.ts | 3 +- .../ui-chat/src/client/chat/ChatView.tsx | 9 +- .../ui-chat/src/client/chat/context-menu.ts | 44 ------ .../ui-chat/tests/chat-view.client.spec.tsx | 18 +++ .../tests/context-menu.client.spec.tsx | 67 +++++---- .../client/ui-context-menu/README.i18n.yaml | 8 +- packages/client/ui-context-menu/README.md | 4 +- packages/client/ui-context-menu/README.zh.md | 4 +- .../ui-context-menu/src/client/index.ts | 10 +- .../ui-context-menu/src/client/locales.ts | 11 ++ .../client/ui-file-actions/README.i18n.yaml | 8 +- packages/client/ui-file-actions/README.md | 6 +- packages/client/ui-file-actions/README.zh.md | 6 +- packages/client/ui-file-actions/package.json | 14 +- .../src/client/context-menus.ts | 92 ++++++++++++ .../ui-file-actions/src/client/files.ts | 7 +- .../ui-file-actions/src/client/index.ts | 13 ++ .../ui-file-actions/src/client/locales.ts | 132 ++++++++++++++++++ packages/client/ui-file-actions/src/types.ts | 5 - .../tests/files.client.spec.ts | 23 ++- .../tests/plugin-menus.client.spec.ts | 63 +++++++++ packages/client/ui-file-actions/tsconfig.json | 15 ++ .../client/ui-open-in-app/README.i18n.yaml | 4 +- packages/client/ui-open-in-app/README.md | 4 +- packages/client/ui-open-in-app/README.zh.md | 4 +- packages/client/ui-open-in-app/package.json | 1 - .../src/client/context-menus.ts | 66 ++------- .../ui-open-in-app/src/client/locales.ts | 56 -------- .../tests/context-menu-actions.client.spec.ts | 38 +++-- .../tests/context-menus.client.spec.ts | 10 +- .../client/ui-primitives/README.i18n.yaml | 4 +- packages/client/ui-primitives/README.md | 2 +- packages/client/ui-primitives/README.zh.md | 2 +- .../client/ui-primitives/src/Menu.module.css | 7 - packages/client/ui-primitives/src/Menu.tsx | 60 ++++---- packages/client/ui-primitives/src/index.ts | 4 +- .../ui-primitives/src/markdown/render.tsx | 20 ++- .../client/ui-primitives/src/menu-point.ts | 26 ++++ .../client/ui-primitives/src/user-text.tsx | 24 +++- .../tests/context-menu.client.spec.tsx | 80 ++++++++++- packages/client/ui-reference/README.i18n.yaml | 4 +- packages/client/ui-reference/README.md | 2 +- packages/client/ui-reference/README.zh.md | 2 +- .../ui-reference/src/client/FileReference.tsx | 15 +- .../tests/file-reference.client.spec.tsx | 22 +++ .../ui-sidebar-right/src/client/locales.ts | 32 +++-- packages/client/ui-tool/README.i18n.yaml | 4 +- packages/client/ui-tool/README.md | 2 +- packages/client/ui-tool/README.zh.md | 2 +- .../src/client/tool/components/ToolRow.tsx | 23 ++- .../ui-tool/tests/tool-row.client.spec.tsx | 22 +++ .../src/client/rows/WorkspaceBrowser.tsx | 13 +- .../src/client/slot-catalog.ts | 2 +- pnpm-lock.yaml | 21 ++- 68 files changed, 821 insertions(+), 383 deletions(-) delete mode 100644 packages/client/ui-chat/src/client/chat/context-menu.ts create mode 100644 packages/client/ui-context-menu/src/client/locales.ts create mode 100644 packages/client/ui-file-actions/src/client/context-menus.ts create mode 100644 packages/client/ui-file-actions/src/client/locales.ts create mode 100644 packages/client/ui-file-actions/tests/plugin-menus.client.spec.ts diff --git a/apps/desktop/README.i18n.yaml b/apps/desktop/README.i18n.yaml index 53fddbee47..e357caa8f7 100644 --- a/apps/desktop/README.i18n.yaml +++ b/apps/desktop/README.i18n.yaml @@ -66,8 +66,8 @@ en: 182a9c6705213e13 zh: 681762f83490f4c6 /deepseek-harness-desktop/updates/local-updater-qualification: - en: 939fd8795e9609cd - zh: a54564960c638321 + en: 4127e6a9824d6b85 + zh: a52b3cc634528bb6 /deepseek-harness-desktop/low-level-development-overrides: en: 8264b135871e8978 zh: 0939aafb1b2961fc diff --git a/apps/desktop/README.md b/apps/desktop/README.md index 32e1255cc1..acd1b34274 100644 --- a/apps/desktop/README.md +++ b/apps/desktop/README.md @@ -356,7 +356,7 @@ The command builds the Desktop shell and runs its coordinator with real Electron The downloaded bytes are inert, and the installation call is recorded rather than executed. The test substitutes browser opening and clipboard writing to avoid external navigation and clipboard changes. It does not boot the full product workspace, qualify a real installer or restart, verify publisher signatures, or exercise differential updates or macOS. Stalled policy requests, feed requests, and payload transfers exercise real deadlines and recovery. The actual ordinary dialog verifies isolated preload loading, card geometry, an unfiltered parent page, cancellation, task-warning choices, and explicit installation approval; account-row component tests provide separate evidence. The [local qualification decision](../../.agents/notes/implemented/testing/2026-09-10-desktop-local-updater-qualification.md) and [verification record](tests/README.md) preserve these limits; production release requirements remain unchanged. -Native original-file operations accept only the trusted application frame. Saved paths stay in the main process and references expire on window reload or close. Remote image reads omit credentials, validate every redirect, reject the application Host and its loopback aliases, stop on main-frame navigation, and use `DSH_DESKTOP_IMAGE_READ_TIMEOUT_MS` (30000 ms) and `DSH_DESKTOP_IMAGE_READ_MAX_BYTES` (67108864 bytes). Image clipboard input uses the same byte limit. Other reachable HTTP(S) destinations follow deployment network isolation. [File actions](../../packages/client/ui-file-actions/README.md) defines saving and clipboard behavior. +Native original-file operations accept only the trusted application frame. Saved paths stay in the main process and references expire on window reload or close. Remote image reads omit credentials, validate every redirect, reject the application Host and its loopback aliases, stop on main-frame navigation, and use `DSH_DESKTOP_IMAGE_READ_TIMEOUT_MS` (30000 ms) and `DSH_DESKTOP_IMAGE_READ_MAX_BYTES` (67108864 bytes). Image copying uses the renderer Clipboard API after PNG conversion. Other reachable HTTP(S) destinations follow deployment network isolation. [File actions](../../packages/client/ui-file-actions/README.md) defines saving and clipboard behavior. diff --git a/apps/desktop/README.zh.md b/apps/desktop/README.zh.md index 4271619833..afa50cd90f 100644 --- a/apps/desktop/README.zh.md +++ b/apps/desktop/README.zh.md @@ -356,7 +356,7 @@ node apps/desktop/node_modules/pnpm/bin/pnpm.mjs --dir apps/desktop run test:upd 下载内容是不可执行的测试字节,安装调用仅记录而不执行。测试替换浏览器打开与剪贴板写入,避免外部导航和剪贴板修改。它不启动完整产品工作区,不验证真实安装器或重启,不验证发布者签名,也不覆盖差分更新或 macOS。停滞的策略请求、清单请求和负载传输会执行真实截止时间及恢复。真实常规弹窗验证隔离预加载、卡片尺寸、未施加模糊的父页面、取消、任务警告选项与显式安装批准;账户行组件测试另行提供证据。[本地验证决策](../../.agents/notes/implemented/testing/2026-09-10-desktop-local-updater-qualification.zh.md)和[验证记录](tests/README.zh.md)保留这些限制;生产发布要求保持不变。 -原生原始文件操作仅接受可信应用页面。保存路径保留在主进程,窗口刷新或关闭后引用失效。远程图片读取不携带凭据,逐次校验重定向,拒绝应用 Host 及其回环别名,在主框架导航时终止,并使用 `DSH_DESKTOP_IMAGE_READ_TIMEOUT_MS`(30000 毫秒)与 `DSH_DESKTOP_IMAGE_READ_MAX_BYTES`(67108864 字节)。图片剪贴板输入使用相同的字节上限。其他可达的 HTTP(S) 目标遵循部署侧网络隔离。[文件操作](../../packages/client/ui-file-actions/README.zh.md) 定义保存和剪贴板行为。 +原生原始文件操作仅接受可信应用页面。保存路径保留在主进程,窗口刷新或关闭后引用失效。远程图片读取不携带凭据,逐次校验重定向,拒绝应用 Host 及其回环别名,在主框架导航时终止,并使用 `DSH_DESKTOP_IMAGE_READ_TIMEOUT_MS`(30000 毫秒)与 `DSH_DESKTOP_IMAGE_READ_MAX_BYTES`(67108864 字节)。图片复制在转换为 PNG 后使用渲染进程的 Clipboard API。其他可达的 HTTP(S) 目标遵循部署侧网络隔离。[文件操作](../../packages/client/ui-file-actions/README.zh.md) 定义保存和剪贴板行为。 diff --git a/apps/desktop/src/file-actions.ts b/apps/desktop/src/file-actions.ts index 6f9606fd19..1354a20c76 100644 --- a/apps/desktop/src/file-actions.ts +++ b/apps/desktop/src/file-actions.ts @@ -1,5 +1,5 @@ -/** Trusted-window original-file saves and clipboard transfers. Saved paths stay in the main process. */ -import { app, clipboard, ClipboardItem, dialog, ipcMain, nativeImage, shell } from 'electron' +/** Trusted-window original-file saves and image reads. Saved paths stay in the main process. */ +import { app, dialog, ipcMain, shell } from 'electron' import type { BrowserWindow, IpcMainInvokeEvent } from 'electron' import { open, rename, rm, stat, writeFile } from 'node:fs/promises' import { basename, dirname, extname, join } from 'node:path' @@ -103,13 +103,6 @@ export function installFileActions( assertOwner(event) shell.showItemInFolder(entry.path) }) - ipcMain.handle(DESKTOP_IPC.imageCopy, async (event, bytes: unknown) => { - assertOwner(event) - if (!(bytes instanceof Uint8Array) || bytes.byteLength > maxBytes) throw new Error('Invalid clipboard image') - const image = nativeImage.createFromBuffer(Buffer.from(bytes)) - if (image.isEmpty()) throw new Error('Image cannot be decoded') - await clipboard.write([new ClipboardItem({ 'image/png': new Blob([new Uint8Array(image.toPNG())]) })]) - }) ipcMain.handle(DESKTOP_IPC.imageRead, async (event, value: unknown) => { const owner = assertOwner(event) if (typeof value !== 'string') throw new Error('Invalid image URL') diff --git a/apps/desktop/src/ipc.ts b/apps/desktop/src/ipc.ts index c343572e85..71907f4563 100644 --- a/apps/desktop/src/ipc.ts +++ b/apps/desktop/src/ipc.ts @@ -8,8 +8,9 @@ import type { DesktopFileDrag } from '@deepseek-ai/dsh-util-file-drag' /** IPC channel names kept private to the desktop application bundle. */ export const DESKTOP_IPC = { - fileSave: 'dsh-desktop:file-save', fileReveal: 'dsh-desktop:file-reveal', - imageCopy: 'dsh-desktop:image-copy', imageRead: 'dsh-desktop:image-read', + fileSave: 'dsh-desktop:file-save', + fileReveal: 'dsh-desktop:file-reveal', + imageRead: 'dsh-desktop:image-read', shortcutsInput: 'dsh-desktop:shortcuts-input', shortcutsCloseWindow: 'dsh-desktop:shortcuts-close-window', shortcutsGet: 'dsh-desktop:shortcuts-get', diff --git a/apps/desktop/src/preload-app.ts b/apps/desktop/src/preload-app.ts index fd79878235..bc33ab66e5 100644 --- a/apps/desktop/src/preload-app.ts +++ b/apps/desktop/src/preload-app.ts @@ -18,7 +18,6 @@ function createProductApi(): DshDesktopProductApi { fileActions: { save: request => ipcRenderer.invoke(DESKTOP_IPC.fileSave, request) as Promise, reveal: id => ipcRenderer.invoke(DESKTOP_IPC.fileReveal, id) as Promise, - copyImage: bytes => ipcRenderer.invoke(DESKTOP_IPC.imageCopy, bytes) as Promise, readImage: url => ipcRenderer.invoke(DESKTOP_IPC.imageRead, url) as Promise<{ bytes: Uint8Array; mediaType: string }>, }, browser: createDesktopBrowserBridge(), diff --git a/apps/desktop/tests/file-actions.spec.ts b/apps/desktop/tests/file-actions.spec.ts index 0ac42f1bc1..b65af18873 100644 --- a/apps/desktop/tests/file-actions.spec.ts +++ b/apps/desktop/tests/file-actions.spec.ts @@ -10,8 +10,7 @@ import { DESKTOP_IPC } from '../src/ipc.ts' const electron = vi.hoisted(() => ({ app: { getPath: vi.fn() }, ipcMain: { handle: vi.fn() }, dialog: { showSaveDialog: vi.fn() }, - shell: { showItemInFolder: vi.fn() }, nativeImage: { createFromBuffer: vi.fn() }, clipboard: { write: vi.fn() }, - ClipboardItem: class { constructor(readonly content: object) {} }, + shell: { showItemInFolder: vi.fn() }, })) vi.mock('electron', () => electron) const roots: string[] = [] @@ -96,7 +95,7 @@ it('preserves saved references across iframe and same-document navigation', asyn f.owner.emit('closed') }) -it('rejects redirects to the application Host and bounds clipboard decoding', async () => { +it('rejects redirects to the application Host', async () => { const root = await directory() const owner = Object.assign(new EventEmitter(), { webContents: new EventEmitter(), isDestroyed: () => false }) installFileActions(() => owner as BrowserWindow, () => 'http://127.0.0.1:19321') @@ -107,7 +106,5 @@ it('rejects redirects to the application Host and bounds clipboard decoding', as const event = {} as IpcMainInvokeEvent await expect(handler(DESKTOP_IPC.imageRead)(event, 'https://images.example/photo')).rejects.toThrow('Invalid image URL') expect(fetchImage).toHaveBeenCalledOnce() - await expect(handler(DESKTOP_IPC.imageCopy)(event, new Uint8Array(64 * 1024 * 1024 + 1))).rejects.toThrow('Invalid clipboard image') - expect(electron.nativeImage.createFromBuffer).not.toHaveBeenCalled() expect(await readdir(root)).toEqual([]) }) diff --git a/apps/desktop/tests/preload-app.spec.ts b/apps/desktop/tests/preload-app.spec.ts index c81fe20f9d..b054063884 100644 --- a/apps/desktop/tests/preload-app.spec.ts +++ b/apps/desktop/tests/preload-app.spec.ts @@ -38,18 +38,16 @@ it('exposes onboarding size activation to the application document', async () => expect(electron.ipcRenderer.send.mock.calls).toEqual([[DESKTOP_IPC.onboardingActive, true], [DESKTOP_IPC.onboardingActive, false]]) }) -it('routes original-file and clipboard requests through the trusted application bridge', async () => { +it('routes original-file requests through the trusted application bridge', async () => { vi.stubGlobal('location', new URL('dsh-app://app/')) await import('../src/preload-app.ts') const api = electron.contextBridge.exposeInMainWorld.mock.calls.find(([name]) => name === 'dshDesktop')?.[1] as DshDesktopProductApi const request = { bytes: new Uint8Array([1, 2]), name: 'image.gif', mode: 'download' as const } await api.fileActions.save(request) await api.fileActions.readImage('https://images.example/original.gif') - await api.fileActions.copyImage(request.bytes) expect(electron.ipcRenderer.invoke.mock.calls).toEqual([ [DESKTOP_IPC.fileSave, request], [DESKTOP_IPC.imageRead, 'https://images.example/original.gif'], - [DESKTOP_IPC.imageCopy, request.bytes], ]) }) diff --git a/apps/web/tests/context-menus.e2e.ts b/apps/web/tests/context-menus.e2e.ts index 0d3a2299d0..594aab6d56 100644 --- a/apps/web/tests/context-menus.e2e.ts +++ b/apps/web/tests/context-menus.e2e.ts @@ -144,9 +144,11 @@ describe('web context menus', () => { await page.keyboard.press('Shift+F10') await page.getByRole('menuitem', { name: 'Copy file path', exact: true }).waitFor() await page.keyboard.press('End') - await page.keyboard.press('ArrowUp') + const saveAs = page.getByRole('menuitem', { name: 'Save as…', exact: true }) + if (!await saveAs.isDisabled()) await page.keyboard.press('ArrowUp') + expect(await page.getByRole('menuitem', { name: 'Copy file path', exact: true }).evaluate(element => element === document.activeElement)).toBe(true) await page.keyboard.press('Enter') - expect(await page.evaluate(() => navigator.clipboard.readText())).toBe(join(scaffold.workspaceCwd, 'first.txt')) + await expect.poll(() => page.evaluate(() => navigator.clipboard.readText())).toBe(join(scaffold.workspaceCwd, 'first.txt')) expect(await file.evaluate(element => element === document.activeElement)).toBe(true) await page.evaluate(() => { document.documentElement.style.setProperty('--dsh-frame-overlay-top', '100px') diff --git a/docs/event-producer-consumer.md b/docs/event-producer-consumer.md index 47056513f2..248458814f 100644 --- a/docs/event-producer-consumer.md +++ b/docs/event-producer-consumer.md @@ -99,6 +99,7 @@ This matrix shows which packages dispatch each harness-owned event and which pac | Event string | Dispatchers | Listeners | | --- | --- | --- | | `agent/request` | [`agent-loop`](../packages/core/agent-loop) (`waterfall`) | [`compaction-basic`](../packages/compaction/compaction-basic) | +| `connection/reset` | `gateway` (`emit`) | `terminal-controller`, `ui-settings` | | `internal/config` | - | [`llm-pi-ai`](../packages/llm/llm-pi-ai) | | `internal/dispatch` | - | [`terminal-bash`](../packages/terminal/terminal-bash) | | `internal/plugin` | - | `computer-use-cua-driver-native`, `inspector`, `loader`, [`lsp-stdio`](../packages/lsp/lsp-stdio), [`mcp-client`](../packages/mcp/mcp-client), `modules` | @@ -106,7 +107,9 @@ This matrix shows which packages dispatch each harness-owned event and which pac | `internal/status` | - | [`agent`](../packages/core/agent), `inspector`, `translator`, [`web`](../packages/web/web) | | `internal/update` | - | [`app-boot`](../packages/boot/app-boot) | | `loader/volatile-update` | - | [`cua`](../packages/experimental/cua), [`llm-deepseek`](../packages/llm/llm-deepseek), [`llm-deepseek-api-key`](../packages/llm/llm-deepseek-api-key), [`llm-pi-ai`](../packages/llm/llm-pi-ai), [`plugin-market`](../packages/boot/plugin-market), `product-analytics`, `speech-to-text` | +| `locale/change` | `locale` (`emit`) | `locale` | | `slots/changed` | `ui-renderer` (`emit`) | - | +| `theme/change` | `ui-theme` (`emit`) | `ui-layout`, `ui-theme` | Maintenance mode: generated: Cordis event declarations and producer/listener edges are resolved from the repository TypeScript Program. diff --git a/docs/event-producer-consumer.zh.md b/docs/event-producer-consumer.zh.md index dc555041ff..a194adca91 100644 --- a/docs/event-producer-consumer.zh.md +++ b/docs/event-producer-consumer.zh.md @@ -101,6 +101,7 @@ | Event string | Dispatchers | Listeners | | --- | --- | --- | | `agent/request` | [`agent-loop`](../packages/core/agent-loop) (`waterfall`) | [`compaction-basic`](../packages/compaction/compaction-basic) | +| `connection/reset` | `gateway` (`emit`) | `terminal-controller`, `ui-settings` | | `internal/config` | - | [`llm-pi-ai`](../packages/llm/llm-pi-ai) | | `internal/dispatch` | - | [`terminal-bash`](../packages/terminal/terminal-bash) | | `internal/plugin` | - | `computer-use-cua-driver-native`, `inspector`, `loader`, [`lsp-stdio`](../packages/lsp/lsp-stdio), [`mcp-client`](../packages/mcp/mcp-client), `modules` | @@ -108,7 +109,9 @@ | `internal/status` | - | [`agent`](../packages/core/agent), `inspector`, `translator`, [`web`](../packages/web/web) | | `internal/update` | - | [`app-boot`](../packages/boot/app-boot) | | `loader/volatile-update` | - | [`cua`](../packages/experimental/cua), [`llm-deepseek`](../packages/llm/llm-deepseek), [`llm-deepseek-api-key`](../packages/llm/llm-deepseek-api-key), [`llm-pi-ai`](../packages/llm/llm-pi-ai), [`plugin-market`](../packages/boot/plugin-market), `product-analytics`, `speech-to-text` | +| `locale/change` | `locale` (`emit`) | `locale` | | `slots/changed` | `ui-renderer` (`emit`) | - | +| `theme/change` | `ui-theme` (`emit`) | `ui-layout`, `ui-theme` | Maintenance mode: generated: Cordis event declarations and producer/listener edges are resolved from the repository TypeScript Program. diff --git a/packages/client/ui-chat/README.i18n.yaml b/packages/client/ui-chat/README.i18n.yaml index 9270da564e..d5480fc21a 100644 --- a/packages/client/ui-chat/README.i18n.yaml +++ b/packages/client/ui-chat/README.i18n.yaml @@ -21,8 +21,8 @@ en: cbf1f0a2205046a5 zh: 2e59d0815351349f /deepseek-ai-dsh-client-ui-chat/command-and-failure-rows: - en: 5ada67393e11644f - zh: 30f6538942dd742b + en: 38e9af25761d8860 + zh: aab4c04d43520460 /deepseek-ai-dsh-client-ui-chat/turn-token-usage: en: cfdfe3d99d3f4e09 zh: 9330bad3d3f7a689 @@ -36,8 +36,8 @@ en: a14c74ed7de0ef9c zh: d5e618b2ef809150 /deepseek-ai-dsh-client-ui-chat/scroll-ownership: - en: 3c437cbcc09621d8 - zh: 17830fa01842143a + en: 461cd577ac6d5e5b + zh: a17a833e069cbfe4 /deepseek-ai-dsh-client-ui-chat/model-experience: en: c17b4dd43a61c569 zh: f7414309810c3a08 diff --git a/packages/client/ui-chat/README.md b/packages/client/ui-chat/README.md index aef6c54a6c..2161fa2cd4 100644 --- a/packages/client/ui-chat/README.md +++ b/packages/client/ui-chat/README.md @@ -61,7 +61,7 @@ When an Assistant attempt retires without a visible message, Chat hides its alre Generic command rows retain the ordinary command glyph in every lifecycle state; failure remains explicit through the row state and summary. Every terminal Turn failure renders its inline red-dot row; a quota failure's row states the neutral `message.failure.quota` copy instead of the provider message. The transient notice for a newly appended `QUOTA` or `ACCOUNT_QUOTA` comes from this package's frame-wide entry in `shell.overlay`, which outlives the Chat panel: it offers the one live notice to the `shell.quota-notice` chain and falls back to its own warning Toast, while an entry that claims the code replaces that fallback. Only Sessions this Client has bound and materialized publish; quota failures in Sessions it never opened do not. A newer notice replaces the current one unless a claiming entry retains it with `keepOpen()`: that call returns a release the caller owns and must run on unmount, any live hold keeps the claiming entry mounted and drops later notices, and releasing resumes later notices without replaying the dropped ones. The fallback Toast has no deferral of its own: while the Desktop account's opaque native Platform page covers the document, it still runs underneath and its display timer may elapse unseen, dismissing the notice itself, so only the persistent failure row remains. A release drops only its own hold, so one that runs after a dismissal or a newer hold leaves that newer hold intact. Dismissal and sign-out clear every hold, and dropped notices are not queued while their persistent failure rows still render. History replacement and pagination never publish a notice. Intermediate retries do not create a terminal row; output-token limits use the amber warning dot. A Turn that restart recovery closed as `interrupted` renders a localized stopped row stating that the DSH process exited mid-Turn, without a code chip, and its process summary reads Stopped. -Reference and tool-file context gestures use the recorded target path rather than its display label. Shift+F10 and the context key open the focused reference menu; images and editable controls keep their own handlers. +Reference and tool-file components declare their context-menu targets through the scoped delegate, using the recorded path rather than a display label. Chat supplies Session and path context without interpreting plugin DOM attributes or undeclared links. Shift+F10 and the context key open the focused reference menu; images and editable controls keep their own handlers. ----- @@ -182,7 +182,7 @@ The Chat view detects selection and context-menu gestures on business nodes mark `ctx.uiConversation.interactions` dispatches eligible gestures to plugin registrations and supplies their component to the Chat view. The action surface is absolutely positioned inside the existing Chat column, above the composer seat and its dock. Its wrapper preserves the component's outer stroke and shadow; components own internal scrolling. Scrolling the selection outside that visible region temporarily hides the surface; returning restores it. Chat owns viewport visibility, placement, outside pointer presses, Escape, new selections, source invalidation, and disposal; explicit dismissal preserves browser selection and layout changes do not reopen the surface. [Message quotes](../../session/message-quotes/README.md) owns quotation eligibility and insertion. -Markdown files, links, and images forward explicit right-click targets to [ui-context-menu](../ui-context-menu/README.md). File targets retain their working directory and line; ordinary link clicks retain the configured opening preference. +Markdown files, links, images, reference chips, and tool-file controls forward explicit right-click targets to [ui-context-menu](../ui-context-menu/README.md). File targets retain their working directory and line; ordinary link clicks retain the configured opening preference. ## Model Experience diff --git a/packages/client/ui-chat/README.zh.md b/packages/client/ui-chat/README.zh.md index ea62dbfdf7..cfa30599c9 100644 --- a/packages/client/ui-chat/README.zh.md +++ b/packages/client/ui-chat/README.zh.md @@ -61,7 +61,7 @@ Assistant 尝试结束且没有可见消息时,Chat 隐藏已发布的 Node, 通用指令行在所有生命周期状态中都保留普通指令图标;失败仍通过行状态与摘要表达。每个终止轮次都渲染自己的红点行;欠费失败的行使用中立的 `message.failure.quota` 文案,而不是提供方消息。新追加的 `QUOTA` 或 `ACCOUNT_QUOTA` 产生的瞬时提示来自本包注册在 `shell.overlay` 的全局条目,它不随 Chat 面板消失:该条目把唯一一条实时提示交给 `shell.quota-notice` 链,并在无人接管时回退到自己的警告 Toast,接管该错误码的条目会替换该回退。只有本 Client 已绑定并已物化的 Session 会发布提示;它从未打开的 Session 中的欠费不会发布。更新的提示会替换当前提示,除非认领条目用 `keepOpen()` 保持住当前提示:该调用返回一个由调用方持有、必须在卸载时调用的释放函数,只要存在保持,认领条目就继续挂载,后续提示被丢弃,释放后恢复后续提示但不重放已丢弃的提示。回退 Toast 自身没有延后策略:当 Desktop 账号的不透明原生 Platform 页盖住本页时,它仍会在下方运行,其显示计时器可能在不可见时走完并自行撤下提示,因此只留下持久化失败行。释放只移除自己的保持,因此它在关闭或更新的保持之后执行时不会影响更新的保持。关闭与退出登录会清空所有保持;被丢弃的提示不排队,其对应的持久化失败行仍会渲染。历史替换和分页不会发布提示。中间重试不会创建终止行;输出 token 上限使用琥珀色警告点。重启恢复以 `interrupted` 结束的轮次会渲染本地化的停止行,说明 DSH 进程在轮次中途退出,不显示代码标签,其过程摘要显示“已停止”。 -引用与工具文件的右键操作使用记录的目标路径,而非显示标签。Shift+F10 和菜单键打开已聚焦引用的菜单;图片与可编辑控件保留自己的处理器。 +引用与工具文件组件通过作用域内的委托声明右键菜单目标,使用记录的路径而非显示标签。Chat 提供 Session 与路径上下文,不解释插件 DOM 属性或未声明的链接。Shift+F10 和菜单键打开已聚焦引用的菜单;图片与可编辑控件保留自己的处理器。 ----- @@ -182,7 +182,7 @@ Chat view 在标记了 `data-text-interaction-source` 的业务节点上检测 `ctx.uiConversation.interactions` 将有效手势分发给插件注册项,并把对应组件交给 Chat view。操作展示位置在已有 Chat 列内绝对定位,限制在 composer seat 及其 dock 上方。外层容器保留组件的外描边与阴影,内部滚动由组件负责。选区滚出该可见范围时暂时隐藏操作,滚回后恢复。Chat 负责视口可见性、定位、外部指针按下、Escape、新选区、来源失效与卸载清理;主动关闭保留浏览器选区,布局变化不会重新打开操作。[Message quotes](../../session/message-quotes/README.zh.md) 负责引用的接管条件和插入。 -Markdown 文件、链接和图片将明确的右键目标转发给 [ui-context-menu](../ui-context-menu/README.zh.md)。文件目标保留工作目录和行号;普通链接点击仍遵循配置的打开偏好。 +Markdown 文件、链接、图片、引用 chip 和工具文件控件将明确的右键目标转发给 [ui-context-menu](../ui-context-menu/README.zh.md)。文件目标保留工作目录和行号;普通链接点击仍遵循配置的打开偏好。 ## 模型体验 diff --git a/packages/client/ui-chat/src/client/apply.ts b/packages/client/ui-chat/src/client/apply.ts index 40847f6389..47a2a9990b 100644 --- a/packages/client/ui-chat/src/client/apply.ts +++ b/packages/client/ui-chat/src/client/apply.ts @@ -76,9 +76,8 @@ export const CHAT_NODE_INJECT: ChatNodeInjected = { /** Services required by the Chat target and its presentation registrations. */ export const inject = [ - 'menus', 'slots', 'sessions', 'uiWorkspace', 'uiSession', 'uiConversation', 'locale', - 'configForms', 'connection', 'remote', 'remote.session', 'sidebarRight', 'fileDrag', + 'configForms', 'connection', 'remote', 'remote.session', 'sidebarRight', 'fileDrag', 'menus', ] /** diff --git a/packages/client/ui-chat/src/client/chat/ChatView.tsx b/packages/client/ui-chat/src/client/chat/ChatView.tsx index e543bcce19..9ef9432f38 100644 --- a/packages/client/ui-chat/src/client/chat/ChatView.tsx +++ b/packages/client/ui-chat/src/client/chat/ChatView.tsx @@ -1,7 +1,6 @@ // An enclosing `[data-conversation-scroll]` owns scrolling when present; // otherwise this view owns it. Each row subscribes to one stable node key. -import { openChatContextMenu, chatContextKey } from './context-menu.ts' import { useCallback, useEffect, useMemo, useRef, useState } from 'react' import type { NodeKey, RenderEntry, @@ -215,8 +214,6 @@ export function ChatView({
{ openChatContextMenu(event, openContextMenu) }} - onKeyDown={(event) => { chatContextKey(event, openContextMenu) }} data-chat-motion={deferCompletedTurns && scroll.initialized && (running || motionTail || pendingInputs.length > 0) ? '' : undefined}> {openState === 'loading' &&
{t('chat.loadingHistory')}
} @@ -233,7 +230,11 @@ export function ChatView({
)} + openContextMenu={openContextMenu} + openFile={requestOpenFile} + openExternalLink={openExternalLink} + fileImages={fileImages} + > {renderSlot('conversation.chat.flow', { entries, pendingInputs, lastInputTurn, deferCollapse, cwd, openFile: requestOpenFile, inspectCall, forkAt, loadImage, fileMentions, diff --git a/packages/client/ui-chat/src/client/chat/context-menu.ts b/packages/client/ui-chat/src/client/chat/context-menu.ts deleted file mode 100644 index dc18377076..0000000000 --- a/packages/client/ui-chat/src/client/chat/context-menu.ts +++ /dev/null @@ -1,44 +0,0 @@ -/** Delegate reference and tool-file gestures to the shared context-menu capability. */ -import type { KeyboardEvent, MouseEvent, SyntheticEvent } from 'react' -import type { ChatViewInjected } from '../contract/slots.ts' - -function show(event: SyntheticEvent, open: ChatViewInjected['openContextMenu'], point?: { x: number; y: number }): void { - if (event.defaultPrevented || !(event.target instanceof Element)) return - if (event.target.closest('img, input, textarea, [contenteditable="true"], [role="menu"]')) return - const source = event.target.closest('[data-file-path], a[href]') - if (source === null || !event.currentTarget.contains(source)) return - const path = source.getAttribute('data-file-path') - const url = source.getAttribute('href') - if (!path && (!url || !/^https?:\/\//iu.test(url))) return - event.preventDefault(); event.stopPropagation() - const rect = source.getBoundingClientRect() - const position = point ?? { x: rect.left, y: rect.bottom } - source.focus({ preventScroll: true }) - if (path) { - const line = Number(source.getAttribute('data-file-line')) - open({ kind: 'file', path, - ...(Number.isSafeInteger(line) && line > 0 ? { line } : {}), - ...(source.getAttribute('data-file-base') === 'workspace' ? { base: 'workspace' as const } : {}), - }, position) - } - else if (url) open({ kind: 'url', url }, position) -} - -/** - * Open the menu of a rendered file reference or URL. - * @param event - bubbled pointer gesture. - * @param open - captured Session menu callback. - */ -export function openChatContextMenu(event: MouseEvent, open: ChatViewInjected['openContextMenu']): void { - show(event, open, event.clientX === 0 && event.clientY === 0 ? undefined : { x: event.clientX, y: event.clientY }) -} - -/** - * Open a focused reference with the context key or Shift+F10. - * @param event - keyboard menu request. - * @param open - captured Session menu callback. - */ -export function chatContextKey(event: KeyboardEvent, open: ChatViewInjected['openContextMenu']): void { - if (event.repeat || event.nativeEvent.isComposing || event.ctrlKey || event.altKey || event.metaKey) return - if (event.key === 'ContextMenu' || (event.key === 'F10' && event.shiftKey)) show(event, open) -} 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 b0ecc417cf..b024619636 100644 --- a/packages/client/ui-chat/tests/chat-view.client.spec.tsx +++ b/packages/client/ui-chat/tests/chat-view.client.spec.tsx @@ -4617,3 +4617,21 @@ const fileDrag = { prepare: vi.fn(async () => ({ start: () => true, release: () it('formats Portuguese elapsed minutes with numeric units', () => { expect(formatRunDuration(90_000, key => pt[key])).toBe('1m 30s') }) + +it('does not infer menu targets from links or data attributes inside a plugin flow slot', () => { + const h = makeHarness() + const custom = vi.fn() + const view = render( <> + Plugin link + + + } />) + expect(fireEvent.contextMenu(view.getByRole('link', { name: 'Plugin link' }))).toBe(true) + expect(fireEvent.contextMenu(view.getByRole('button', { name: 'Undeclared file' }))).toBe(true) + fireEvent.contextMenu(view.getByRole('button', { name: 'Custom target' })) + expect(custom).toHaveBeenCalledOnce() + expect(h.props.openContextMenu).not.toHaveBeenCalled() +}) diff --git a/packages/client/ui-chat/tests/context-menu.client.spec.tsx b/packages/client/ui-chat/tests/context-menu.client.spec.tsx index 36d1f67c99..e3ac0269bd 100644 --- a/packages/client/ui-chat/tests/context-menu.client.spec.tsx +++ b/packages/client/ui-chat/tests/context-menu.client.spec.tsx @@ -1,41 +1,48 @@ // @vitest-environment jsdom import { cleanup, fireEvent, render } from '@testing-library/react' +import { createPortal } from 'react-dom' import { afterEach, expect, it, vi } from 'vitest' -import { chatContextKey, openChatContextMenu } from '../src/client/chat/context-menu.ts' +import { contextMenuTrigger, MarkdownDelegateProvider, MarkdownText } from '@deepseek-ai/dsh-client-ui-primitives' afterEach(cleanup) -it('copies the recorded path target rather than a tool or reference display label, and preserves URL query and fragment', () => { +it('leaves undeclared plugin links alone and binds only explicitly rendered Markdown targets', () => { const open = vi.fn() - const view = render(
{ openChatContextMenu(event, open) }}> - - Website -
) - fireEvent.contextMenu(view.getByRole('button'), { clientX: 50, clientY: 70 }) - expect(open).toHaveBeenLastCalledWith({ kind: 'file', path: '/workspace/output.txt', line: 42 }, { x: 50, y: 70 }) - fireEvent.contextMenu(view.getByRole('link'), { clientX: 80, clientY: 90 }) - expect(open).toHaveBeenLastCalledWith({ kind: 'url', url: 'https://example.com/path?q=1#fragment' }, { x: 80, y: 90 }) + const custom = vi.fn() + const view = render( {}}> + Plugin link + + + ) + expect(fireEvent.contextMenu(view.getByRole('link', { name: 'Plugin link' }))).toBe(true) + expect(open).not.toHaveBeenCalled() + const file = view.getByRole('button', { name: 'File' }) + fireEvent.contextMenu(file, { clientX: 40, clientY: 50 }) + expect(open).toHaveBeenLastCalledWith({ kind: 'file', path: 'docs/file.ts', line: 42 }, { x: 40, y: 50 }) + file.getBoundingClientRect = () => new DOMRect(30, 40, 100, 20) + fireEvent.keyDown(file, { key: 'F10', shiftKey: true }) + expect(open).toHaveBeenLastCalledWith({ kind: 'file', path: 'docs/file.ts', line: 42 }, { x: 30, y: 60 }) + expect(document.activeElement).toBe(file) + fireEvent.contextMenu(view.getByRole('button', { name: 'Plugin target' }), { clientX: 70, clientY: 80 }) + expect(custom).toHaveBeenCalledExactlyOnceWith({ kind: 'pluginDocument', id: 'one' }, { x: 70, y: 80 }) + expect(open).toHaveBeenCalledTimes(2) }) -it('opens keyboard menus from their focused reference and leaves images, editors, and unrelated gestures alone', () => { - const open = vi.fn() - const view = render(
{ chatContextKey(event, open) }} - onContextMenu={(event) => { openChatContextMenu(event, open) }}> - - Image -