From be0e31233c9507b75e96749f832d9da26f884857 Mon Sep 17 00:00:00 2001 From: yudshj Date: Mon, 28 Sep 2026 11:41:44 +0800 Subject: [PATCH 1/3] feat(web): open the workspace from the sidebar file tree --- .../files-open.expected.md | 6 ++ apps/web/tests/shortcuts-workspace.e2e.ts | 24 ++++++++ .../client/ui-open-in-app/README.i18n.yaml | 12 ++-- packages/client/ui-open-in-app/README.md | 6 +- packages/client/ui-open-in-app/README.zh.md | 6 +- packages/client/ui-open-in-app/package.json | 1 + .../src/client/OpenInAppAction.tsx | 6 +- .../client/ui-open-in-app/src/client/index.ts | 35 ++++++------ .../tests/browser-plugin.client.spec.ts | 7 ++- packages/client/ui-open-in-app/tsconfig.json | 3 + .../client/ui-sidebar-files/README.i18n.yaml | 4 +- packages/client/ui-sidebar-files/README.md | 2 +- packages/client/ui-sidebar-files/README.zh.md | 2 +- .../ui-sidebar-files/src/client/FilesBody.tsx | 8 ++- .../ui-sidebar-files/src/client/index.ts | 12 +++- .../ui-sidebar-files/tests/mount.client.tsx | 1 + .../src/client/slot-catalog.ts | 56 +++++++++++++++++++ pnpm-lock.yaml | 3 + 18 files changed, 154 insertions(+), 40 deletions(-) create mode 100644 apps/web/tests/expected/shortcuts-workspace/files-open.expected.md diff --git a/apps/web/tests/expected/shortcuts-workspace/files-open.expected.md b/apps/web/tests/expected/shortcuts-workspace/files-open.expected.md new file mode 100644 index 0000000000..9c7cf15731 --- /dev/null +++ b/apps/web/tests/expected/shortcuts-workspace/files-open.expected.md @@ -0,0 +1,6 @@ +- text: {{cwd}}/keyboard-project +- button "Reload" +- button "Open in Finder" +- button "More ways to open" +- list: + - listitem: Empty directory diff --git a/apps/web/tests/shortcuts-workspace.e2e.ts b/apps/web/tests/shortcuts-workspace.e2e.ts index 139a0ad6a5..bbeb011c9c 100644 --- a/apps/web/tests/shortcuts-workspace.e2e.ts +++ b/apps/web/tests/shortcuts-workspace.e2e.ts @@ -160,6 +160,30 @@ describe.skipIf(mode === 'record')('web e2e: workspace shortcuts', () => { await bind('Open locally') await page.keyboard.press('Meta+Shift+Comma') await expect.poll(() => launched).toEqual([{ app: 'vscode', path: workspace.path }]) + + await page.keyboard.press('Meta+Alt+P') + const files = page.locator('[data-files-state="tree"]') + await files.locator('[data-files-row="empty"]').waitFor() + const opener = files.locator('[data-open-target="directory"]') + await opener.getByRole('button', { name: 'Open in VS Code', exact: true }).click() + await expect.poll(() => launched).toEqual([ + { app: 'vscode', path: workspace.path }, { app: 'vscode', path: workspace.path }, + ]) + await opener.getByRole('button', { name: 'More ways to open', exact: true }).click() + await page.getByRole('menuitem', { name: 'Finder', exact: true }).click() + await expect.poll(() => launched.at(-1)).toEqual({ app: 'finder', path: workspace.path }) + await opener.getByRole('button', { name: 'Open in Finder', exact: true }).waitFor() + await page.keyboard.press('Meta+Shift+Comma') + await expect.poll(() => launched).toEqual([ + { app: 'vscode', path: workspace.path }, { app: 'vscode', path: workspace.path }, + { app: 'finder', path: workspace.path }, { app: 'finder', path: workspace.path }, + ]) + await compareOrRefreshGolden(join(root, 'files-open.expected.md'), + await captureStableAria(page, '[data-files-state="tree"]', scaffold.workspaceCwd), mode) + await opener.getByRole('button', { name: 'More ways to open', exact: true }).click() + await page.getByRole('menuitem', { name: 'Finder (default)', exact: true }).waitFor() + await page.keyboard.press('Escape') + await page.getByRole('menu').waitFor({ state: 'hidden' }) expect(console.pageErrors).toEqual([]) }) }) diff --git a/packages/client/ui-open-in-app/README.i18n.yaml b/packages/client/ui-open-in-app/README.i18n.yaml index 84beb9dff8..3494bebb8b 100644 --- a/packages/client/ui-open-in-app/README.i18n.yaml +++ b/packages/client/ui-open-in-app/README.i18n.yaml @@ -18,11 +18,11 @@ en: 056e2bd9e3c78dd8 zh: be35d2ba53be0442 /deepseek-ai-dsh-client-ui-open-in-app/use-this-package/what-to-expect: - en: c93c175a3583820a - zh: fa812b70176d3d60 + en: 856b3127245f4d21 + zh: 6a1910efa522134f /deepseek-ai-dsh-client-ui-open-in-app/understand-the-implementation: - en: c8ac8873c45eb568 - zh: fd623c411f79d90f + en: 2c5976da969fede9 + zh: 5eb1702233a55048 /deepseek-ai-dsh-client-ui-open-in-app/further-exploration: en: 9deb509f65b6edfd zh: d6cd63b2abc3731b @@ -36,5 +36,5 @@ en: 3d77fca62d3c8e86 zh: 3125d32a158e690a /deepseek-ai-dsh-client-ui-open-in-app/known-limitations-and-deferred-work/dev-note: - en: 739fd95270d14d0a - zh: d5a6b59133ac6b3f + en: c79e15f681adeacd + zh: 6a30399297bde201 diff --git a/packages/client/ui-open-in-app/README.md b/packages/client/ui-open-in-app/README.md index ae8b195921..14cb1f037a 100644 --- a/packages/client/ui-open-in-app/README.md +++ b/packages/client/ui-open-in-app/README.md @@ -29,7 +29,7 @@ Mount this plugin in the Web composition beside [`dsh-host-open-in-app`](../../h ### What to expect -The Session header and document header use the same 24px-high split button with 9px corners. Both headers show only the icon; their tooltip names the default application or the reveal action. Both show the default action’s icon, mark its application with “(default)” in the menu, disable while their own gesture runs, and report failures through a transient toast. The directory adapter uses the existing cross-platform application catalog and remembers the last successful choice in `dsh.open-in-app.choice`; a missing choice falls back to the first available application. +The Session header, file-tree header, and document header use the same 24px-high split button with 9px corners. These headers show only the icon; their tooltip names the default application or the reveal action. They show the default action’s icon, mark its application with “(default)” in the menu, disable while their own gesture runs, and report failures through a transient toast. The file-tree opener targets its Session’s workspace and shares the application choice and launch state with the Session header. The directory adapter uses the existing cross-platform application catalog and remembers the last successful choice in `dsh.open-in-app.choice`; a missing choice falls back to the first available application. The **Open locally** shortcut captures the main Session's directory and the same remembered application as the header button. The effective binding appears in the button tooltip and `aria-keyshortcuts`; Web follows the [shortcut service’s platform defaults](../shortcuts/README.md). The command runs only while the Conversation is selected and the header button has a directory and installed application to open. An in-flight launch also blocks the command. Pointer and keyboard gestures share the controller's launch state, so repeated gestures cannot launch twice or change the remembered choice mid-launch. @@ -45,7 +45,7 @@ Mounted controls with the same association reader and file share one query and i
Implementation internals — click to expand -The plugin registers the split button on `conversation.session.header.utilities` through the standard slot/inject currency and registers the `open-in-app` dictionaries as one effect. A page-lifetime controller ([`src/client/controller.ts`](src/client/controller.ts)) owns the once-per-page availability read, the persisted choice snapshot store, and the launch POST; the component receives the shared sources through the inject `hooks` compartment, so every Session header shares one truth. Document-relative route forms and wire payload types come from the host package's browser-safe `@deepseek-ai/dsh-host-open-in-app/shared` subpath. The controller guards in-flight launches and publishes their captured directory and status; header controls derive delayed busy and transient error visuals from that source. +The plugin registers the split button on `conversation.session.header.utilities` and `sidebar.right.tab.files.actions` through the standard slot/inject currency and registers the `open-in-app` dictionaries as one effect. A page-lifetime controller ([`src/client/controller.ts`](src/client/controller.ts)) owns the once-per-page availability read, the persisted choice snapshot store, and the launch POST; the component receives the shared sources through the inject `hooks` compartment, so every Session header shares one truth. Document-relative route forms and wire payload types come from the host package's browser-safe `@deepseek-ai/dsh-host-open-in-app/shared` subpath. The controller guards in-flight launches and publishes their captured directory and status; header controls derive delayed busy and transient error visuals from that source. The directory and file adapters supply application metadata and operations to [`OpenTargetButton`](src/client/OpenTargetButton.tsx), which owns menu ordering, default markers, icons, sizing, and gesture feedback. The file header and empty state share `FileOpenTarget`, while `OpenPathInjected.applications` queries `session.workspacePathApplications` through [`open-path.ts`](src/client/open-path.ts). Opening uses `session.openWorkspacePath`; the Host revalidates an explicitly selected handler before launch. The directory adapter keeps the existing catalog routes. `FileRouteAction` supplies the same control to delivery cards and change review through `deliverables.file.actions` and `deliverables.review.file.actions`; their authenticated routes retain Session file authorization. A failed or unavailable file query therefore needs no platform-specific UI implementation. @@ -94,4 +94,4 @@ The feature-level decisions, including the split into the host package and this
-**Runtime invariant:** No companion is published. The plugin registers one dictionary effect and five slot entries whose disposal the HMR-safety spec proves; application availability, the choice, and the desktop answer live in the controllers' snapshot stores with no second copy to diverge. +**Runtime invariant:** No companion is published. The plugin registers one dictionary effect and six slot entries whose disposal the HMR-safety spec proves; application availability, the choice, and the desktop answer live in the controllers' snapshot stores with no second copy to diverge. diff --git a/packages/client/ui-open-in-app/README.zh.md b/packages/client/ui-open-in-app/README.zh.md index 1477640a04..aba36b0a35 100644 --- a/packages/client/ui-open-in-app/README.zh.md +++ b/packages/client/ui-open-in-app/README.zh.md @@ -29,7 +29,7 @@ kind: "package-reference" ### 预期行为 -会话标题栏和文档标题栏共用同一个高 24px、圆角 9px 的分体按钮。两个标题栏都只显示图标,悬停提示显示默认应用名称或文件定位动作。两者都显示默认动作的图标,在菜单的默认应用后标注“(默认)”,仅在自己的操作执行期间禁用,并通过短暂提示报告失败。目录适配器使用已有的跨平台应用列表,将最后一次成功选择保存在 `dsh.open-in-app.choice` 中;原选择不可用时回退到第一个可用应用。 +会话标题栏、文件树标题栏和文档标题栏共用同一个高 24px、圆角 9px 的分体按钮。这些标题栏都只显示图标,悬停提示显示默认应用名称或文件定位动作。它们都显示默认动作的图标,在菜单的默认应用后标注“(默认)”,仅在自己的操作执行期间禁用,并通过短暂提示报告失败。文件树打开按钮以所属 Session 的工作区为目标,并与会话头部共享应用选择和启动状态。目录适配器使用已有的跨平台应用列表,将最后一次成功选择保存在 `dsh.open-in-app.choice` 中;原选择不可用时回退到第一个可用应用。 **在本地打开**快捷键捕获主会话的目录,并使用与头部按钮相同的已记住应用。按钮 tooltip 和 `aria-keyshortcuts` 显示当前有效绑定;Web 遵循[快捷键服务的平台默认值](../shortcuts/README.zh.md)。只有选中会话界面、且头部按钮有可打开的目录和已安装应用时,命令才执行。启动尚未结束时也会阻止命令。鼠标与键盘操作共享 controller 的启动状态,重复操作不会启动两次,也不会在启动期间更改已记住的选择。 @@ -45,7 +45,7 @@ kind: "package-reference"
实现内幕——点击展开 -插件通过标准 slot/inject 机制把分体按钮注册到 `conversation.session.header.utilities`,并以一个 effect 注册 `open-in-app` 词典。一个页面生命周期的 controller([`src/client/controller.ts`](src/client/controller.ts))拥有每页一次的可用性读取、持久化选择的 snapshot store 与启动 POST;组件经 inject 的 `hooks` 隔间接收共享源,因此所有会话头部共享同一份事实。文档相对的路由形式与 wire 载荷类型来自主机包的浏览器安全子路径 `@deepseek-ai/dsh-host-open-in-app/shared`。controller 守卫执行中的启动,并发布所捕获的目录与状态;头部控件从该源派生延迟出现的等待态和短暂错误态。 +插件通过标准 slot/inject 机制把分体按钮注册到 `conversation.session.header.utilities` 和 `sidebar.right.tab.files.actions`,并以一个 effect 注册 `open-in-app` 词典。一个页面生命周期的 controller([`src/client/controller.ts`](src/client/controller.ts))拥有每页一次的可用性读取、持久化选择的 snapshot store 与启动 POST;组件经 inject 的 `hooks` 隔间接收共享源,因此所有会话头部共享同一份事实。文档相对的路由形式与 wire 载荷类型来自主机包的浏览器安全子路径 `@deepseek-ai/dsh-host-open-in-app/shared`。controller 守卫执行中的启动,并发布所捕获的目录与状态;头部控件从该源派生延迟出现的等待态和短暂错误态。 目录和文件适配器把应用信息与操作交给 [`OpenTargetButton`](src/client/OpenTargetButton.tsx),由它统一管理菜单顺序、默认标记、图标、尺寸和操作反馈。文件标题栏和空态共用 `FileOpenTarget`,`OpenPathInjected.applications` 通过 [`open-path.ts`](src/client/open-path.ts) 查询 `session.workspacePathApplications`。打开操作使用 `session.openWorkspacePath`,Host 在启动前重新验证指定的关联应用。`FileRouteAction` 通过 `deliverables.file.actions` 和 `deliverables.review.file.actions` 为交付卡片和变更对比页提供同一控件,其认证路由保留会话文件校验。目录适配器继续使用已有的应用列表路由,文件查询失败或不可用时无需增加平台专用的界面实现。 @@ -94,4 +94,4 @@ Host 在打开或定位前通过当前文件系统验证路径。没有对应 Ho
-**运行时不变式:** 不发布伴生入口。插件注册一个词典 effect 和五个 slot 条目,HMR 安全性 spec 证明它们都会在资源释放时撤销;应用可用性、选择与桌面回答存储在控制器的快照存储中,不存在可能与之分歧的第二份副本。 +**运行时不变式:** 不发布伴生入口。插件注册一个词典 effect 和六个 slot 条目,HMR 安全性 spec 证明它们都会在资源释放时撤销;应用可用性、选择与桌面回答存储在控制器的快照存储中,不存在可能与之分歧的第二份副本。 diff --git a/packages/client/ui-open-in-app/package.json b/packages/client/ui-open-in-app/package.json index f722f7b47a..912ffb6897 100644 --- a/packages/client/ui-open-in-app/package.json +++ b/packages/client/ui-open-in-app/package.json @@ -69,6 +69,7 @@ "@deepseek-ai/dsh-client-ui-renderer": "workspace:*", "@deepseek-ai/dsh-client-ui-session": "workspace:*", "@deepseek-ai/dsh-client-ui-sidebar-documentpreview": "workspace:*", + "@deepseek-ai/dsh-client-ui-sidebar-files": "workspace:*", "@deepseek-ai/dsh-client-ui-slots": "workspace:*", "@deepseek-ai/dsh-host-open-in-app": "workspace:*", "@deepseek-ai/dsh-session": "workspace:*", diff --git a/packages/client/ui-open-in-app/src/client/OpenInAppAction.tsx b/packages/client/ui-open-in-app/src/client/OpenInAppAction.tsx index 532508c557..1572416483 100644 --- a/packages/client/ui-open-in-app/src/client/OpenInAppAction.tsx +++ b/packages/client/ui-open-in-app/src/client/OpenInAppAction.tsx @@ -7,7 +7,7 @@ import type { ShortcutCatalogEntry } from '@deepseek-ai/dsh-client-shortcuts/cli import { NS } from './locales.ts' import { OpenTargetButton } from './OpenTargetButton.tsx' -/** Browser operations and state injected into the Session Header contribution. */ +/** Browser operations and state shared by the Session header and file tree contributions. */ export interface OpenInAppActionInjected { hooks: { openInAppApps: ObservableSnapshot @@ -20,9 +20,9 @@ export interface OpenInAppActionInjected { iconUrl: (appId: string) => string } -/** Full props for the Session-header open-in-app split button. */ +/** Full props for the workspace directory split button. */ export type OpenInAppActionProps = - PropsRuntime<'conversation.session.header.utilities'> + PropsRuntime<'conversation.session.header.utilities' | 'sidebar.right.tab.files.actions'> & PropsLocale & InjectFace diff --git a/packages/client/ui-open-in-app/src/client/index.ts b/packages/client/ui-open-in-app/src/client/index.ts index 271c459365..aad013fbfc 100644 --- a/packages/client/ui-open-in-app/src/client/index.ts +++ b/packages/client/ui-open-in-app/src/client/index.ts @@ -11,6 +11,7 @@ import type {} from '@deepseek-ai/dsh-client-ui-renderer/client' import type {} from '@deepseek-ai/dsh-client-ui-layout/client' import type {} from '@deepseek-ai/dsh-client-ui-session/client' import type {} from '@deepseek-ai/dsh-client-ui-sidebar-documentpreview/client' +import type {} from '@deepseek-ai/dsh-client-ui-sidebar-files/client' import type {} from '@deepseek-ai/dsh-api-gateway/client' import type {} from '@deepseek-ai/dsh-api-remotes/client' import type {} from '@deepseek-ai/dsh-api-session-controller/remote' @@ -39,8 +40,8 @@ export type { OpenPathEmptyActionProps } from './OpenPathEmptyAction.tsx' export const inject = ['sessions', 'slots', 'locale', 'remote', 'remote.session', 'shortcuts', 'layout'] /** - * Client plugin body: register the dictionaries, the header split button, and - * the document preview's path controls. + * Client plugin body: register dictionaries, workspace directory controls, and + * document preview path controls. * @param ctx - client root context. */ export function apply(ctx: ClientContext): void { @@ -77,22 +78,24 @@ export function apply(ctx: ClientContext): void { } } }, }), 'open-in-app: workspace command') + const directoryInjected = (): OpenInAppActionInjected => ({ + hooks: { + openInAppApps: controller.apps, + openInAppChoice: controller.choice, + openInAppLaunch: controller.operation, + shortcuts: ctx.shortcuts.catalog, + }, + launch: (appId, path) => controller.launch(appId, path), + choose: (appId) => { controller.choose(appId) }, + iconUrl: appId => `${OPEN_IN_APP_ICON_PREFIX_ROUTE}/${appId}`, + }) ctx.slots.inject('conversation.session.header.utilities', () => ctx.slots.register({ name: 'conversation.session.header.utilities', - id: 'open-in-app', - order: -10, - locale: NS, - inject: (): OpenInAppActionInjected => ({ - hooks: { - openInAppApps: controller.apps, - openInAppChoice: controller.choice, - openInAppLaunch: controller.operation, - shortcuts: ctx.shortcuts.catalog, - }, - launch: (appId, path) => controller.launch(appId, path), - choose: (appId) => { controller.choose(appId) }, - iconUrl: appId => `${OPEN_IN_APP_ICON_PREFIX_ROUTE}/${appId}`, - }), + id: 'open-in-app', order: -10, locale: NS, inject: directoryInjected, + }, OpenInAppAction)) + ctx.slots.inject('sidebar.right.tab.files.actions', () => ctx.slots.register({ + name: 'sidebar.right.tab.files.actions', + id: 'open-in-app', locale: NS, inject: directoryInjected, }, OpenInAppAction)) const applications: OpenPathInjected['applications'] = (path, signal) => paths.applications(path, signal) const pathInjected = (): OpenPathInjected => ({ diff --git a/packages/client/ui-open-in-app/tests/browser-plugin.client.spec.ts b/packages/client/ui-open-in-app/tests/browser-plugin.client.spec.ts index 2fce5eb64e..dde57184ce 100644 --- a/packages/client/ui-open-in-app/tests/browser-plugin.client.spec.ts +++ b/packages/client/ui-open-in-app/tests/browser-plugin.client.spec.ts @@ -45,6 +45,7 @@ async function bench() { name: 'root', children: { 'conversation.session.header.utilities': { kind: 'list', scope: 'session' }, + 'sidebar.right.tab.files.actions': { kind: 'list', scope: 'session' }, 'sidebar.right.tab.document.actions': { kind: 'list', scope: 'session' }, 'sidebar.right.tab.document.unpreviewable': { kind: 'list', scope: 'session' }, 'deliverables.file.actions': { kind: 'list', scope: 'session' }, @@ -193,14 +194,18 @@ describe('open-in-app browser half', () => { expect(ctx.slots.entries('deliverables.file.actions')).toHaveLength(0) }) - it('registers the header split button, and fiber teardown removes it (HMR safety)', async () => { + it('shares the directory control and controller across headers and removes both on teardown', async () => { vi.stubGlobal('fetch', vi.fn(async () => new Response(JSON.stringify({ apps: [] }), { status: 200 }))) const { ctx, fiber } = await bench() const entry = ctx.slots.entries('conversation.session.header.utilities')[0] + const files = ctx.slots.entries('sidebar.right.tab.files.actions')[0] + expect(files?.component).toBe(OpenInAppAction) + expect(files?.inject).toBe(entry?.inject) expect(entry?.component).toBe(OpenInAppAction) expect(entry?.options).toMatchObject({ id: 'open-in-app' }) await fiber.dispose() expect(headerEntryIds(ctx)).not.toContain('open-in-app') + expect(ctx.slots.entries('sidebar.right.tab.files.actions')).toHaveLength(0) }) it('injects the controller face: availability sources, launch carrier, choice, and icon URLs', async () => { diff --git a/packages/client/ui-open-in-app/tsconfig.json b/packages/client/ui-open-in-app/tsconfig.json index 3dc30c5d14..f4b9263e3d 100644 --- a/packages/client/ui-open-in-app/tsconfig.json +++ b/packages/client/ui-open-in-app/tsconfig.json @@ -47,6 +47,9 @@ { "path": "../ui-sidebar-documentpreview/tsconfig.client.json" }, + { + "path": "../ui-sidebar-files" + }, { "path": "../ui-slots" }, diff --git a/packages/client/ui-sidebar-files/README.i18n.yaml b/packages/client/ui-sidebar-files/README.i18n.yaml index 0a282bb61a..d2d60fbdf9 100644 --- a/packages/client/ui-sidebar-files/README.i18n.yaml +++ b/packages/client/ui-sidebar-files/README.i18n.yaml @@ -15,8 +15,8 @@ en: 9411fb4809692e09 zh: dd13990d39c5be7f /deepseek-ai-dsh-client-ui-sidebar-files/what-it-registers: - en: a13aadd9b0294870 - zh: d30dc67f177f6c2d + en: 3ce68ed86f6fa80f + zh: e55ba82f50226106 /deepseek-ai-dsh-client-ui-sidebar-files/the-tree: en: a0ae0b1f223b3df1 zh: 8ddc325519bd75b2 diff --git a/packages/client/ui-sidebar-files/README.md b/packages/client/ui-sidebar-files/README.md index 49ae5abb81..7f8173742b 100644 --- a/packages/client/ui-sidebar-files/README.md +++ b/packages/client/ui-sidebar-files/README.md @@ -27,7 +27,7 @@ Browse a Session's workspace tree and open files in Sidebar previews. The root a The `workspace.files` command opens or focuses the file page in the focused pane; from the conversation it uses the current Session's active dock pane. A guide gives way to the file page, and repeated opens retain one file page per pane. Desktop defaults to Mod+P. The guide entry displays the effective shortcut; Windows and macOS Web use the [shortcut service’s platform defaults](../shortcuts/README.md); Linux Web leaves this command unbound by default. - **The type** — `ctx.sidebarRightTabs.register(...)` with kind `files`, id `@deepseek-ai/dsh-client-ui-sidebar-files`, band `builtin`, no patterns, and one guide entry (order 10, its title and description from the `sidebarFiles` namespace, its glyph a yellow folder) that opens the type. -- **The body** — the keyed `sidebar.right.pane.tab` seat under that id: a header row under the strip, then the tree. The shared [`PathLabel`](../ui-primitives/README.md#component-catalog) displays the root path with subdued directories and a primary final segment. A clipped path retains its trailing characters with a left-edge fade; hovering reveals the full path. The reload control stays at its right. +- **The body** — the keyed `sidebar.right.pane.tab` seat under that id: a header row under the strip, then the tree. The shared [`PathLabel`](../ui-primitives/README.md#component-catalog) displays the root path with subdued directories and a primary final segment. A clipped path retains its trailing characters with a left-edge fade; hovering reveals the full path. The reload control and the Session-scoped `sidebar.right.tab.files.actions` list stay at its right; [`ui-open-in-app`](../ui-open-in-app/README.md) contributes the workspace directory opener. - **The chip title** — the keyed `sidebar.right.pane.tab.title` seat under that id: a shared `FileTypeIcon` folder glyph at 16px before the type's label. The tree's own rows never draw this sheet. Source files under `src/client/`: `definition.tsx` (the type), `store.ts` (what it keeps), `face.ts` (Remote reads and watches), `directory-node.ts` (open directories and their lifetimes), `FilesBody.tsx` (what it draws, with its ordering and failure-line helpers), `FilesTitle.tsx` (the chip title), `locales.ts` (what it says), and `index.ts` (the wiring). diff --git a/packages/client/ui-sidebar-files/README.zh.md b/packages/client/ui-sidebar-files/README.zh.md index 73c6a3eb94..913bca8286 100644 --- a/packages/client/ui-sidebar-files/README.zh.md +++ b/packages/client/ui-sidebar-files/README.zh.md @@ -27,7 +27,7 @@ kind: "package-reference" 命令 `workspace.files` 在焦点分栏内打开或聚焦文件页;从聊天区触发时使用当前会话的活动停靠分栏。文件页替换开始页,同一分栏内重复打开仍保留一个文件页。桌面默认键为 Mod+P。开始页入口显示有效快捷键;Windows 和 macOS Web 使用[快捷键服务的平台默认值](../shortcuts/README.zh.md);Linux Web 默认不绑定此命令。 - **类型**:`ctx.sidebarRightTabs.register(...)`,kind 为 `files`,id 为 `@deepseek-ai/dsh-client-ui-sidebar-files`,档位 `builtin`,没有 patterns,另有一个打开该类型的引导页入口(order 10,标题与描述取自 `sidebarFiles` 命名空间,图标为黄色文件夹)。 -- **正文**:以该 id 为键的 `sidebar.right.pane.tab` slot:strip 下的一行标题行,然后是树。共享的 [`PathLabel`](../ui-primitives/README.zh.md#component-catalog) 显示根路径,目录使用弱化颜色,最后一段使用主色。路径过长时保留尾部字符并在左侧渐隐;悬停显示完整路径。重新读取控件位于右端。 +- **正文**:以该 id 为键的 `sidebar.right.pane.tab` slot:strip 下的一行标题行,然后是树。共享的 [`PathLabel`](../ui-primitives/README.zh.md#component-catalog) 显示根路径,目录使用弱化颜色,最后一段使用主色。路径过长时保留尾部字符并在左侧渐隐;悬停显示完整路径。重新读取控件和 Session 作用域的 `sidebar.right.tab.files.actions` 列表位于右端;[`ui-open-in-app`](../ui-open-in-app/README.zh.md) 在此提供工作区目录打开按钮。 - **标签页标题**:以该 id 为键的 `sidebar.right.pane.tab.title` slot:类型标签前的一枚 16px 共享 `FileTypeIcon` 文件夹图标。树本身的行不画这枚图标。 `src/client/` 下的源文件:`definition.tsx`(类型是什么)、`store.ts`(它保存什么)、`face.ts`(Remote 读取与监听)、`directory-node.ts`(打开的目录及其生命周期)、`FilesBody.tsx`(它画什么,含排序与失败行两个辅助函数)、`FilesTitle.tsx`(标签页标题)、`locales.ts`(它说什么)、`index.ts`(接线)。 diff --git a/packages/client/ui-sidebar-files/src/client/FilesBody.tsx b/packages/client/ui-sidebar-files/src/client/FilesBody.tsx index 29fb98d31c..6db0d10b83 100644 --- a/packages/client/ui-sidebar-files/src/client/FilesBody.tsx +++ b/packages/client/ui-sidebar-files/src/client/FilesBody.tsx @@ -6,13 +6,13 @@ * draw for each absolute path and what a click means: a directory toggles, a * file opens through the owner's `tabActions` for a `file:` viewer to claim, and * anything else is shown but refuses to open. The header uses the shared - * PathLabel for the root, followed by reload for the expanded directories. + * PathLabel for the root, followed by reload and workspace directory actions. */ import { useEffect, useLayoutEffect, useRef } from 'react' import type { ReactNode } from 'react' import clsx from 'clsx' import type { RemoteFailure } from '@deepseek-ai/dsh-api-remotes/client' -import type { PropsLocale, PropsRuntime, PropsStore, TranslateNS } from '@deepseek-ai/dsh-client-ui-slots' +import type { PropsLocale, PropsRenderSlots, PropsRuntime, PropsStore, TranslateNS } from '@deepseek-ai/dsh-client-ui-slots' import { FileTypeIcon, IconFolderCloseRegular, IconFolderOpenRegular, IconRefreshOutlineRegular, Tooltip, classifyFileType, IconPauseOutlineRegular, IconPlayOutlineRegular, PathLabel, @@ -28,6 +28,7 @@ import css from './FilesBody.module.css' /** The body's composed props: the tab it draws, its store, its face, and its copy. */ export type FilesBodyProps = & PropsRuntime<'sidebar.right.pane.tab'> + & PropsRenderSlots<'sidebar.right.tab.files.actions'> & PropsStore> & FilesInjected & PropsLocale<'sidebarFiles'> @@ -135,7 +136,7 @@ function Level({ path, tree }: { path: string; tree: TreeContext }): ReactNode { /** The file tree's body: the workspace root and whatever the reader has opened under it. */ export function FilesBody({ - useTabInfo, sessionId, useSessions, useStore, actions, start, refresh, setAutoRefresh, toggle, t, + useTabInfo, sessionId, useSessions, useStore, actions, start, refresh, setAutoRefresh, toggle, t, renderSlot, }: FilesBodyProps): ReactNode { const { tab } = useTabInfo() useEffect(() => tab.actions.bindCommands({ refresh: () => { refresh(tab.id) } }), [tab.actions, tab.id, refresh]) @@ -210,6 +211,7 @@ export function FilesBody({ + {renderSlot('sidebar.right.tab.files.actions', {})}
ctx.slots.inject('sidebar.right.pane.tab', () => ctx.slots.register( - { name: 'sidebar.right.pane.tab', key: FILES_ID, locale: NS, store, inject }, + { + name: 'sidebar.right.pane.tab', key: FILES_ID, locale: NS, store, inject, + children: { 'sidebar.right.tab.files.actions': { kind: 'list', scope: 'session' } }, + }, FilesBody, )), 'ui-sidebar-files: files tab body') ctx.effect(() => ctx.slots.inject('sidebar.right.pane.tab.title', () => ctx.slots.register( diff --git a/packages/client/ui-sidebar-files/tests/mount.client.tsx b/packages/client/ui-sidebar-files/tests/mount.client.tsx index 78597ba17b..5646e773fb 100644 --- a/packages/client/ui-sidebar-files/tests/mount.client.tsx +++ b/packages/client/ui-sidebar-files/tests/mount.client.tsx @@ -87,6 +87,7 @@ function harness(cwd: string | null, refreshShortcut?: ReturnType null, sessionId: SESSION, useSessions: (sel: (s: SessionListState) => S) => sel(sessions), useStore: hookOf(instance), diff --git a/packages/extensions/cordis-client-runner/src/client/slot-catalog.ts b/packages/extensions/cordis-client-runner/src/client/slot-catalog.ts index 9b84cb4413..606b206f3f 100644 --- a/packages/extensions/cordis-client-runner/src/client/slot-catalog.ts +++ b/packages/extensions/cordis-client-runner/src/client/slot-catalog.ts @@ -3453,6 +3453,62 @@ export const CLIENT_SLOT_API: readonly ClientSlotEntry[] = [ example: 'return {\n inject: [\'slots\'],\n apply(ctx) {\n ctx.slots.inject(\'sidebar.right.tab.document.unpreviewable\', () => ctx.slots.register(\n { name: \'sidebar.right.tab.document.unpreviewable\', id: \'my-entry\', order: 100, label: \'My entry\' },\n () => React.createElement(\'div\', null, \'hello\'),\n ))\n },\n}', source: 'packages/client/ui-sidebar-documentpreview/src/client/document/contract.ts:78', }, + { + key: 'sidebar.right.tab.files.actions', + kind: 'list', + scope: 'session', + summary: 'Workspace directory actions after the file tree\'s reload control.', + doc: 'Workspace directory actions after the file tree\'s reload control.', + registerOptions: [ + { + name: 'id', + requirement: 'required', + type: 'string', + doc: 'Your cell key. Use an id of your own: a fresh id is added beside the shipped entries, while reusing a shipped id puts you in THAT cell and replaces it. Owners that filter by id address you by it.', + }, + { + name: 'order', + requirement: 'optional', + type: 'number', + doc: 'Position among the entries, ascending (default 0).', + }, + { + name: 'label', + requirement: 'optional', + type: 'string | (() => string)', + doc: 'Display text where the owner projects one (nav rows, tabs). A thunk is re-read on every projection, so localized text follows the active locale without re-registering.', + }, + ], + ownerProps: [], + ownerPropsReferences: [], + standardProps: [ + 'useResource: UseResource', + 'useWorkspaces: SnapshotSelectorHook', + 'usePanelInfo: UsePanelInfo', + 'useSessions: UseSessions', + 'useSessionStatus: UseSessionStatus', + 'useSessionRetainInfo: UseSessionRetainInfo', + 'useWorkspaces: SnapshotSelectorHook', + 'useChat: UseChat', + 'useConversation: UseConversation', + 'useInput: SnapshotSelectorHook', + 'inputActions: InputActions', + 'useSession: SessionSnapshotSelector', + 'sessionId: SessionId', + 'useProjection: UseProjection', + 'useTrajectory: UseTrajectory', + ], + keyDomain: '', + hookContext: '', + slotInject: '', + declaredBy: 'an entry in \'sidebar.right.pane.tab\' (client-ui-sidebar-files), so it exists while that entry is mounted', + occupants: [ + 'client-ui-open-in-app OpenInAppAction id \'open-in-app\'', + ], + replaceRisk: 'none', + example: 'return {\n inject: [\'slots\'],\n apply(ctx) {\n ctx.slots.inject(\'sidebar.right.tab.files.actions\', () => ctx.slots.register(\n { name: \'sidebar.right.tab.files.actions\', id: \'my-entry\', order: 100, label: \'My entry\' },\n () => React.createElement(\'div\', null, \'hello\'),\n ))\n },\n}', + source: 'packages/client/ui-sidebar-files/src/client/index.ts:34', + }, { key: 'sidebar.right.tab.guide', kind: 'chain', diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index f4d3188cbc..cf730271b8 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -4142,6 +4142,9 @@ importers: '@deepseek-ai/dsh-client-ui-sidebar-documentpreview': specifier: workspace:* version: link:../ui-sidebar-documentpreview + '@deepseek-ai/dsh-client-ui-sidebar-files': + specifier: workspace:* + version: link:../ui-sidebar-files '@deepseek-ai/dsh-client-ui-slots': specifier: workspace:* version: link:../ui-slots From 35002626a19082a76553d19bcde510383d8f2921 Mon Sep 17 00:00:00 2001 From: yudshj Date: Mon, 28 Sep 2026 14:23:10 +0800 Subject: [PATCH 2/3] refactor(web): pass the displayed directory to sidebar actions --- apps/web/tests/shortcuts-workspace.e2e.ts | 1 + .../client/ui-open-in-app/README.i18n.yaml | 4 +-- packages/client/ui-open-in-app/README.md | 2 +- packages/client/ui-open-in-app/README.zh.md | 2 +- .../src/client/OpenInAppAction.tsx | 34 +++++++++++++------ .../client/ui-open-in-app/src/client/index.ts | 4 +-- .../tests/browser-plugin.client.spec.ts | 4 +-- .../tests/open-in-app-action.client.spec.tsx | 15 +++++++- .../client/ui-sidebar-files/README.i18n.yaml | 4 +-- packages/client/ui-sidebar-files/README.md | 2 +- packages/client/ui-sidebar-files/README.zh.md | 2 +- .../ui-sidebar-files/src/client/FilesBody.tsx | 11 ++++-- .../ui-sidebar-files/src/client/index.ts | 9 ++++- .../src/client/slot-catalog.ts | 2 +- 14 files changed, 68 insertions(+), 28 deletions(-) diff --git a/apps/web/tests/shortcuts-workspace.e2e.ts b/apps/web/tests/shortcuts-workspace.e2e.ts index bbeb011c9c..38743ec424 100644 --- a/apps/web/tests/shortcuts-workspace.e2e.ts +++ b/apps/web/tests/shortcuts-workspace.e2e.ts @@ -178,6 +178,7 @@ describe.skipIf(mode === 'record')('web e2e: workspace shortcuts', () => { { app: 'vscode', path: workspace.path }, { app: 'vscode', path: workspace.path }, { app: 'finder', path: workspace.path }, { app: 'finder', path: workspace.path }, ]) + await expect.poll(() => opener.getAttribute('data-state')).toBe('idle') await compareOrRefreshGolden(join(root, 'files-open.expected.md'), await captureStableAria(page, '[data-files-state="tree"]', scaffold.workspaceCwd), mode) await opener.getByRole('button', { name: 'More ways to open', exact: true }).click() diff --git a/packages/client/ui-open-in-app/README.i18n.yaml b/packages/client/ui-open-in-app/README.i18n.yaml index 3494bebb8b..680f7cce76 100644 --- a/packages/client/ui-open-in-app/README.i18n.yaml +++ b/packages/client/ui-open-in-app/README.i18n.yaml @@ -18,8 +18,8 @@ en: 056e2bd9e3c78dd8 zh: be35d2ba53be0442 /deepseek-ai-dsh-client-ui-open-in-app/use-this-package/what-to-expect: - en: 856b3127245f4d21 - zh: 6a1910efa522134f + en: 42f7977b585f9c3a + zh: a13772312d52b97f /deepseek-ai-dsh-client-ui-open-in-app/understand-the-implementation: en: 2c5976da969fede9 zh: 5eb1702233a55048 diff --git a/packages/client/ui-open-in-app/README.md b/packages/client/ui-open-in-app/README.md index 14cb1f037a..813b0c8bd4 100644 --- a/packages/client/ui-open-in-app/README.md +++ b/packages/client/ui-open-in-app/README.md @@ -29,7 +29,7 @@ Mount this plugin in the Web composition beside [`dsh-host-open-in-app`](../../h ### What to expect -The Session header, file-tree header, and document header use the same 24px-high split button with 9px corners. These headers show only the icon; their tooltip names the default application or the reveal action. They show the default action’s icon, mark its application with “(default)” in the menu, disable while their own gesture runs, and report failures through a transient toast. The file-tree opener targets its Session’s workspace and shares the application choice and launch state with the Session header. The directory adapter uses the existing cross-platform application catalog and remembers the last successful choice in `dsh.open-in-app.choice`; a missing choice falls back to the first available application. +The Session header, file-tree header, and document header use the same 24px-high split button with 9px corners. These headers show only the icon; their tooltip names the default application or the reveal action. They show the default action’s icon, mark its application with “(default)” in the menu, disable while their own gesture runs, and report failures through a transient toast. The file-tree opener targets the displayed directory supplied as `absolutePath` and shares the application choice and launch state with the Session header. The directory adapter uses the existing cross-platform application catalog and remembers the last successful choice in `dsh.open-in-app.choice`; a missing choice falls back to the first available application. The **Open locally** shortcut captures the main Session's directory and the same remembered application as the header button. The effective binding appears in the button tooltip and `aria-keyshortcuts`; Web follows the [shortcut service’s platform defaults](../shortcuts/README.md). The command runs only while the Conversation is selected and the header button has a directory and installed application to open. An in-flight launch also blocks the command. Pointer and keyboard gestures share the controller's launch state, so repeated gestures cannot launch twice or change the remembered choice mid-launch. diff --git a/packages/client/ui-open-in-app/README.zh.md b/packages/client/ui-open-in-app/README.zh.md index aba36b0a35..7131105eaf 100644 --- a/packages/client/ui-open-in-app/README.zh.md +++ b/packages/client/ui-open-in-app/README.zh.md @@ -29,7 +29,7 @@ kind: "package-reference" ### 预期行为 -会话标题栏、文件树标题栏和文档标题栏共用同一个高 24px、圆角 9px 的分体按钮。这些标题栏都只显示图标,悬停提示显示默认应用名称或文件定位动作。它们都显示默认动作的图标,在菜单的默认应用后标注“(默认)”,仅在自己的操作执行期间禁用,并通过短暂提示报告失败。文件树打开按钮以所属 Session 的工作区为目标,并与会话头部共享应用选择和启动状态。目录适配器使用已有的跨平台应用列表,将最后一次成功选择保存在 `dsh.open-in-app.choice` 中;原选择不可用时回退到第一个可用应用。 +会话标题栏、文件树标题栏和文档标题栏共用同一个高 24px、圆角 9px 的分体按钮。这些标题栏都只显示图标,悬停提示显示默认应用名称或文件定位动作。它们都显示默认动作的图标,在菜单的默认应用后标注“(默认)”,仅在自己的操作执行期间禁用,并通过短暂提示报告失败。文件树打开按钮以 `absolutePath` 传入的显示目录为目标,并与会话头部共享应用选择和启动状态。目录适配器使用已有的跨平台应用列表,将最后一次成功选择保存在 `dsh.open-in-app.choice` 中;原选择不可用时回退到第一个可用应用。 **在本地打开**快捷键捕获主会话的目录,并使用与头部按钮相同的已记住应用。按钮 tooltip 和 `aria-keyshortcuts` 显示当前有效绑定;Web 遵循[快捷键服务的平台默认值](../shortcuts/README.zh.md)。只有选中会话界面、且头部按钮有可打开的目录和已安装应用时,命令才执行。启动尚未结束时也会阻止命令。鼠标与键盘操作共享 controller 的启动状态,重复操作不会启动两次,也不会在启动期间更改已记住的选择。 diff --git a/packages/client/ui-open-in-app/src/client/OpenInAppAction.tsx b/packages/client/ui-open-in-app/src/client/OpenInAppAction.tsx index 1572416483..b5e52a4883 100644 --- a/packages/client/ui-open-in-app/src/client/OpenInAppAction.tsx +++ b/packages/client/ui-open-in-app/src/client/OpenInAppAction.tsx @@ -20,21 +20,35 @@ export interface OpenInAppActionInjected { iconUrl: (appId: string) => string } -/** Full props for the workspace directory split button. */ +/** Full props for the Session-header directory split button. */ export type OpenInAppActionProps = - PropsRuntime<'conversation.session.header.utilities' | 'sidebar.right.tab.files.actions'> + PropsRuntime<'conversation.session.header.utilities'> & PropsLocale & InjectFace +/** Full props for a directory split button targeting the file tree's displayed path. */ +export type DirectoryOpenInAppActionProps = + PropsRuntime<'sidebar.right.tab.files.actions'> + & PropsLocale + & InjectFace + +/** + * Open the Session header's workspace through the shared directory control. + * @param props - Session state, installed catalog, and launch operations. + * @returns the directory control, or null without a workspace. + */ +export function OpenInAppAction(props: OpenInAppActionProps): React.JSX.Element | null { + const cwd = props.useSessions(state => state.byId[props.sessionId]?.cwd) + return cwd === undefined || cwd === '' ? null : +} /** * Adapt the installed directory catalog to the shared opening control. - * @param props - workspace state, installed catalog, and launch operations. - * @returns the shared control, or null without an eligible application and directory. + * @param props - displayed directory, installed catalog, and launch operations. + * @returns the shared control, or null without an eligible application. */ -export function OpenInAppAction(props: OpenInAppActionProps): React.JSX.Element | null { - const { sessionId, useSessions, useOpenInAppApps, useOpenInAppChoice, t } = props - const cwd = useSessions(state => state.byId[sessionId]?.cwd) +export function DirectoryOpenInAppAction(props: DirectoryOpenInAppActionProps): React.JSX.Element | null { + const { absolutePath, useOpenInAppApps, useOpenInAppChoice, t } = props const available = useOpenInAppApps(apps => apps) const choice = useOpenInAppChoice(id => id) const operation = props.useOpenInAppLaunch(value => value) @@ -44,15 +58,15 @@ export function OpenInAppAction(props: OpenInAppActionProps): React.JSX.Element return key === undefined ? [] : [{ id, name: t(key), icon: props.iconUrl(id) }] }) const preferred = apps.find(app => app.id === choice) ?? apps[0] - if (preferred === undefined || cwd === undefined || cwd === '') return null + if (preferred === undefined) return null return ( { const id = operation.kind === 'application' ? operation.id : preferred.id try { - await props.launch(id, cwd) + await props.launch(id, absolutePath) } catch (_error) { // Native launch failure is announced by the shared control. return 'openError' diff --git a/packages/client/ui-open-in-app/src/client/index.ts b/packages/client/ui-open-in-app/src/client/index.ts index aad013fbfc..fcb35ad252 100644 --- a/packages/client/ui-open-in-app/src/client/index.ts +++ b/packages/client/ui-open-in-app/src/client/index.ts @@ -17,7 +17,7 @@ import type {} from '@deepseek-ai/dsh-api-remotes/client' import type {} from '@deepseek-ai/dsh-api-session-controller/remote' import { OPEN_IN_APP_ICON_PREFIX_ROUTE } from '@deepseek-ai/dsh-host-open-in-app/shared' import { OpenInAppController } from './controller.ts' -import { OpenInAppAction, type OpenInAppActionInjected } from './OpenInAppAction.tsx' +import { DirectoryOpenInAppAction, OpenInAppAction, type OpenInAppActionInjected } from './OpenInAppAction.tsx' import { OpenInAppPathController } from './open-path.ts' import { OpenPathAction, type OpenPathInjected } from './OpenPathAction.tsx' import { FileRouteAction } from './FileRouteAction.tsx' @@ -96,7 +96,7 @@ export function apply(ctx: ClientContext): void { ctx.slots.inject('sidebar.right.tab.files.actions', () => ctx.slots.register({ name: 'sidebar.right.tab.files.actions', id: 'open-in-app', locale: NS, inject: directoryInjected, - }, OpenInAppAction)) + }, DirectoryOpenInAppAction)) const applications: OpenPathInjected['applications'] = (path, signal) => paths.applications(path, signal) const pathInjected = (): OpenPathInjected => ({ hooks: { openInAppDesktop: paths.desktop }, diff --git a/packages/client/ui-open-in-app/tests/browser-plugin.client.spec.ts b/packages/client/ui-open-in-app/tests/browser-plugin.client.spec.ts index dde57184ce..2be2b883ea 100644 --- a/packages/client/ui-open-in-app/tests/browser-plugin.client.spec.ts +++ b/packages/client/ui-open-in-app/tests/browser-plugin.client.spec.ts @@ -18,7 +18,7 @@ import { createLayoutStore } from '@deepseek-ai/dsh-client-ui-layout/src/client/ import type {} from '@deepseek-ai/dsh-client-ui-conversation/client' import { apply, inject, type OpenInAppActionInjected, type OpenPathInjected } from '../src/client/index.ts' import { apply as nodeApply } from '../src/index.ts' -import { OpenInAppAction } from '../src/client/OpenInAppAction.tsx' +import { DirectoryOpenInAppAction, OpenInAppAction } from '../src/client/OpenInAppAction.tsx' import { OpenPathAction } from '../src/client/OpenPathAction.tsx' import { OpenPathEmptyAction } from '../src/client/OpenPathEmptyAction.tsx' import { en, NS, zh } from '../src/client/locales.ts' @@ -199,7 +199,7 @@ describe('open-in-app browser half', () => { const { ctx, fiber } = await bench() const entry = ctx.slots.entries('conversation.session.header.utilities')[0] const files = ctx.slots.entries('sidebar.right.tab.files.actions')[0] - expect(files?.component).toBe(OpenInAppAction) + expect(files?.component).toBe(DirectoryOpenInAppAction) expect(files?.inject).toBe(entry?.inject) expect(entry?.component).toBe(OpenInAppAction) expect(entry?.options).toMatchObject({ id: 'open-in-app' }) diff --git a/packages/client/ui-open-in-app/tests/open-in-app-action.client.spec.tsx b/packages/client/ui-open-in-app/tests/open-in-app-action.client.spec.tsx index 1332ee067d..7a454d43b1 100644 --- a/packages/client/ui-open-in-app/tests/open-in-app-action.client.spec.tsx +++ b/packages/client/ui-open-in-app/tests/open-in-app-action.client.spec.tsx @@ -7,7 +7,7 @@ import { createSnapshotStore } from '@deepseek-ai/dsh-client-store' import type { SessionListState } from '@deepseek-ai/dsh-api-session-controller/client' import type { SessionId } from '@deepseek-ai/dsh-session/types' import type { ShortcutCatalogEntry, ShortcutCommandId } from '@deepseek-ai/dsh-client-shortcuts/client' -import { OpenInAppAction, type OpenInAppActionProps } from '../src/client/OpenInAppAction.tsx' +import { DirectoryOpenInAppAction, OpenInAppAction, type OpenInAppActionProps } from '../src/client/OpenInAppAction.tsx' import { OpenInAppController } from '../src/client/controller.ts' import { zh } from '../src/client/locales.ts' @@ -164,3 +164,16 @@ it('omits the dropdown when only one directory application is available', () => expect(screen.getAllByRole('button')).toHaveLength(1) expect(screen.queryByRole('button', { name: zh['path.more'] })).toBeNull() }) + +it('opens the displayed directory and follows its changes without reading the Session cwd', async () => { + const b = bench({ apps: ['finder'], cwd: '/session-workspace' }) + const useSessions = vi.fn(() => { throw new Error('Directory controls must use the displayed path') }) + const view = render() + await act(async () => { fireEvent.click(screen.getByRole('button')) }) + expect(b.launch).toHaveBeenLastCalledWith('finder', '/displayed-directory') + + view.rerender() + await act(async () => { fireEvent.click(screen.getByRole('button')) }) + expect(b.launch).toHaveBeenLastCalledWith('finder', '/another-directory') + expect(useSessions).not.toHaveBeenCalled() +}) diff --git a/packages/client/ui-sidebar-files/README.i18n.yaml b/packages/client/ui-sidebar-files/README.i18n.yaml index d2d60fbdf9..4e7e344973 100644 --- a/packages/client/ui-sidebar-files/README.i18n.yaml +++ b/packages/client/ui-sidebar-files/README.i18n.yaml @@ -15,8 +15,8 @@ en: 9411fb4809692e09 zh: dd13990d39c5be7f /deepseek-ai-dsh-client-ui-sidebar-files/what-it-registers: - en: 3ce68ed86f6fa80f - zh: e55ba82f50226106 + en: ed52405be7c3fa24 + zh: d06dbd49c786c5f0 /deepseek-ai-dsh-client-ui-sidebar-files/the-tree: en: a0ae0b1f223b3df1 zh: 8ddc325519bd75b2 diff --git a/packages/client/ui-sidebar-files/README.md b/packages/client/ui-sidebar-files/README.md index 7f8173742b..22431cfc52 100644 --- a/packages/client/ui-sidebar-files/README.md +++ b/packages/client/ui-sidebar-files/README.md @@ -27,7 +27,7 @@ Browse a Session's workspace tree and open files in Sidebar previews. The root a The `workspace.files` command opens or focuses the file page in the focused pane; from the conversation it uses the current Session's active dock pane. A guide gives way to the file page, and repeated opens retain one file page per pane. Desktop defaults to Mod+P. The guide entry displays the effective shortcut; Windows and macOS Web use the [shortcut service’s platform defaults](../shortcuts/README.md); Linux Web leaves this command unbound by default. - **The type** — `ctx.sidebarRightTabs.register(...)` with kind `files`, id `@deepseek-ai/dsh-client-ui-sidebar-files`, band `builtin`, no patterns, and one guide entry (order 10, its title and description from the `sidebarFiles` namespace, its glyph a yellow folder) that opens the type. -- **The body** — the keyed `sidebar.right.pane.tab` seat under that id: a header row under the strip, then the tree. The shared [`PathLabel`](../ui-primitives/README.md#component-catalog) displays the root path with subdued directories and a primary final segment. A clipped path retains its trailing characters with a left-edge fade; hovering reveals the full path. The reload control and the Session-scoped `sidebar.right.tab.files.actions` list stay at its right; [`ui-open-in-app`](../ui-open-in-app/README.md) contributes the workspace directory opener. +- **The body** — the keyed `sidebar.right.pane.tab` seat under that id: a header row under the strip, then the tree. The shared [`PathLabel`](../ui-primitives/README.md#component-catalog) displays the root path with subdued directories and a primary final segment. A clipped path retains its trailing characters with a left-edge fade; hovering reveals the full path. The reload control and the Session-scoped `sidebar.right.tab.files.actions` list stay at its right, with the displayed root passed as `absolutePath`; [`ui-open-in-app`](../ui-open-in-app/README.md) contributes the workspace directory opener. - **The chip title** — the keyed `sidebar.right.pane.tab.title` seat under that id: a shared `FileTypeIcon` folder glyph at 16px before the type's label. The tree's own rows never draw this sheet. Source files under `src/client/`: `definition.tsx` (the type), `store.ts` (what it keeps), `face.ts` (Remote reads and watches), `directory-node.ts` (open directories and their lifetimes), `FilesBody.tsx` (what it draws, with its ordering and failure-line helpers), `FilesTitle.tsx` (the chip title), `locales.ts` (what it says), and `index.ts` (the wiring). diff --git a/packages/client/ui-sidebar-files/README.zh.md b/packages/client/ui-sidebar-files/README.zh.md index 913bca8286..72e6a9bd80 100644 --- a/packages/client/ui-sidebar-files/README.zh.md +++ b/packages/client/ui-sidebar-files/README.zh.md @@ -27,7 +27,7 @@ kind: "package-reference" 命令 `workspace.files` 在焦点分栏内打开或聚焦文件页;从聊天区触发时使用当前会话的活动停靠分栏。文件页替换开始页,同一分栏内重复打开仍保留一个文件页。桌面默认键为 Mod+P。开始页入口显示有效快捷键;Windows 和 macOS Web 使用[快捷键服务的平台默认值](../shortcuts/README.zh.md);Linux Web 默认不绑定此命令。 - **类型**:`ctx.sidebarRightTabs.register(...)`,kind 为 `files`,id 为 `@deepseek-ai/dsh-client-ui-sidebar-files`,档位 `builtin`,没有 patterns,另有一个打开该类型的引导页入口(order 10,标题与描述取自 `sidebarFiles` 命名空间,图标为黄色文件夹)。 -- **正文**:以该 id 为键的 `sidebar.right.pane.tab` slot:strip 下的一行标题行,然后是树。共享的 [`PathLabel`](../ui-primitives/README.zh.md#component-catalog) 显示根路径,目录使用弱化颜色,最后一段使用主色。路径过长时保留尾部字符并在左侧渐隐;悬停显示完整路径。重新读取控件和 Session 作用域的 `sidebar.right.tab.files.actions` 列表位于右端;[`ui-open-in-app`](../ui-open-in-app/README.zh.md) 在此提供工作区目录打开按钮。 +- **正文**:以该 id 为键的 `sidebar.right.pane.tab` slot:strip 下的一行标题行,然后是树。共享的 [`PathLabel`](../ui-primitives/README.zh.md#component-catalog) 显示根路径,目录使用弱化颜色,最后一段使用主色。路径过长时保留尾部字符并在左侧渐隐;悬停显示完整路径。重新读取控件和 Session 作用域的 `sidebar.right.tab.files.actions` 列表位于右端,并通过 `absolutePath` 传入当前显示的根目录;[`ui-open-in-app`](../ui-open-in-app/README.zh.md) 在此提供工作区目录打开按钮。 - **标签页标题**:以该 id 为键的 `sidebar.right.pane.tab.title` slot:类型标签前的一枚 16px 共享 `FileTypeIcon` 文件夹图标。树本身的行不画这枚图标。 `src/client/` 下的源文件:`definition.tsx`(类型是什么)、`store.ts`(它保存什么)、`face.ts`(Remote 读取与监听)、`directory-node.ts`(打开的目录及其生命周期)、`FilesBody.tsx`(它画什么,含排序与失败行两个辅助函数)、`FilesTitle.tsx`(标签页标题)、`locales.ts`(它说什么)、`index.ts`(接线)。 diff --git a/packages/client/ui-sidebar-files/src/client/FilesBody.tsx b/packages/client/ui-sidebar-files/src/client/FilesBody.tsx index 6db0d10b83..2aa024b649 100644 --- a/packages/client/ui-sidebar-files/src/client/FilesBody.tsx +++ b/packages/client/ui-sidebar-files/src/client/FilesBody.tsx @@ -12,7 +12,9 @@ import { useEffect, useLayoutEffect, useRef } from 'react' import type { ReactNode } from 'react' import clsx from 'clsx' import type { RemoteFailure } from '@deepseek-ai/dsh-api-remotes/client' -import type { PropsLocale, PropsRenderSlots, PropsRuntime, PropsStore, TranslateNS } from '@deepseek-ai/dsh-client-ui-slots' +import type { + PropsLocale, PropsRenderSlots, PropsRuntime, PropsStore, TranslateNS, +} from '@deepseek-ai/dsh-client-ui-slots' import { FileTypeIcon, IconFolderCloseRegular, IconFolderOpenRegular, IconRefreshOutlineRegular, Tooltip, classifyFileType, IconPauseOutlineRegular, IconPlayOutlineRegular, PathLabel, @@ -136,7 +138,8 @@ function Level({ path, tree }: { path: string; tree: TreeContext }): ReactNode { /** The file tree's body: the workspace root and whatever the reader has opened under it. */ export function FilesBody({ - useTabInfo, sessionId, useSessions, useStore, actions, start, refresh, setAutoRefresh, toggle, t, renderSlot, + useTabInfo, sessionId, useSessions, useStore, actions, + start, refresh, setAutoRefresh, toggle, t, renderSlot, }: FilesBodyProps): ReactNode { const { tab } = useTabInfo() useEffect(() => tab.actions.bindCommands({ refresh: () => { refresh(tab.id) } }), [tab.actions, tab.id, refresh]) @@ -211,7 +214,9 @@ export function FilesBody({ - {renderSlot('sidebar.right.tab.files.actions', {})} + {renderSlot('sidebar.right.tab.files.actions', { + absolutePath: state.root, + })}
ctx.slots.register(\n { name: \'sidebar.right.tab.files.actions\', id: \'my-entry\', order: 100, label: \'My entry\' },\n () => React.createElement(\'div\', null, \'hello\'),\n ))\n },\n}', From 171c9e922593a4ac822f099f38794c1675dca31a Mon Sep 17 00:00:00 2001 From: yudshj Date: Mon, 28 Sep 2026 17:39:48 +0800 Subject: [PATCH 3/3] refactor(web): reuse the path-based open-in-app action --- .../client/ui-open-in-app/README.i18n.yaml | 4 +- packages/client/ui-open-in-app/README.md | 2 +- packages/client/ui-open-in-app/README.zh.md | 2 +- .../src/client/OpenInAppAction.tsx | 27 ++----- .../client/ui-open-in-app/src/client/index.ts | 16 +++- .../tests/browser-plugin.client.spec.ts | 34 +++++--- .../tests/open-in-app-action.client.spec.tsx | 77 +++++++------------ .../src/client/slot-catalog.ts | 4 +- 8 files changed, 76 insertions(+), 90 deletions(-) diff --git a/packages/client/ui-open-in-app/README.i18n.yaml b/packages/client/ui-open-in-app/README.i18n.yaml index 680f7cce76..1489618994 100644 --- a/packages/client/ui-open-in-app/README.i18n.yaml +++ b/packages/client/ui-open-in-app/README.i18n.yaml @@ -21,8 +21,8 @@ en: 42f7977b585f9c3a zh: a13772312d52b97f /deepseek-ai-dsh-client-ui-open-in-app/understand-the-implementation: - en: 2c5976da969fede9 - zh: 5eb1702233a55048 + en: a0304e1bd9b44370 + zh: af0fdfd01c296dce /deepseek-ai-dsh-client-ui-open-in-app/further-exploration: en: 9deb509f65b6edfd zh: d6cd63b2abc3731b diff --git a/packages/client/ui-open-in-app/README.md b/packages/client/ui-open-in-app/README.md index 813b0c8bd4..9b2e7e3d6b 100644 --- a/packages/client/ui-open-in-app/README.md +++ b/packages/client/ui-open-in-app/README.md @@ -45,7 +45,7 @@ Mounted controls with the same association reader and file share one query and i
Implementation internals — click to expand -The plugin registers the split button on `conversation.session.header.utilities` and `sidebar.right.tab.files.actions` through the standard slot/inject currency and registers the `open-in-app` dictionaries as one effect. A page-lifetime controller ([`src/client/controller.ts`](src/client/controller.ts)) owns the once-per-page availability read, the persisted choice snapshot store, and the launch POST; the component receives the shared sources through the inject `hooks` compartment, so every Session header shares one truth. Document-relative route forms and wire payload types come from the host package's browser-safe `@deepseek-ai/dsh-host-open-in-app/shared` subpath. The controller guards in-flight launches and publishes their captured directory and status; header controls derive delayed busy and transient error visuals from that source. +Both directory slots use `OpenInAppAction` with an explicit `absolutePath`. The `conversation.session.header.utilities` registration reads the Session cwd, while `sidebar.right.tab.files.actions` receives the displayed directory from its owner. The plugin registers the `open-in-app` dictionaries as one effect. A page-lifetime controller ([`src/client/controller.ts`](src/client/controller.ts)) owns the once-per-page availability read, the persisted choice snapshot store, and the launch POST; the component receives the shared sources through the inject `hooks` compartment, so every Session header shares one truth. Document-relative route forms and wire payload types come from the host package's browser-safe `@deepseek-ai/dsh-host-open-in-app/shared` subpath. The controller guards in-flight launches and publishes their captured directory and status; header controls derive delayed busy and transient error visuals from that source. The directory and file adapters supply application metadata and operations to [`OpenTargetButton`](src/client/OpenTargetButton.tsx), which owns menu ordering, default markers, icons, sizing, and gesture feedback. The file header and empty state share `FileOpenTarget`, while `OpenPathInjected.applications` queries `session.workspacePathApplications` through [`open-path.ts`](src/client/open-path.ts). Opening uses `session.openWorkspacePath`; the Host revalidates an explicitly selected handler before launch. The directory adapter keeps the existing catalog routes. `FileRouteAction` supplies the same control to delivery cards and change review through `deliverables.file.actions` and `deliverables.review.file.actions`; their authenticated routes retain Session file authorization. A failed or unavailable file query therefore needs no platform-specific UI implementation. diff --git a/packages/client/ui-open-in-app/README.zh.md b/packages/client/ui-open-in-app/README.zh.md index 7131105eaf..8259f0695f 100644 --- a/packages/client/ui-open-in-app/README.zh.md +++ b/packages/client/ui-open-in-app/README.zh.md @@ -45,7 +45,7 @@ kind: "package-reference"
实现内幕——点击展开 -插件通过标准 slot/inject 机制把分体按钮注册到 `conversation.session.header.utilities` 和 `sidebar.right.tab.files.actions`,并以一个 effect 注册 `open-in-app` 词典。一个页面生命周期的 controller([`src/client/controller.ts`](src/client/controller.ts))拥有每页一次的可用性读取、持久化选择的 snapshot store 与启动 POST;组件经 inject 的 `hooks` 隔间接收共享源,因此所有会话头部共享同一份事实。文档相对的路由形式与 wire 载荷类型来自主机包的浏览器安全子路径 `@deepseek-ai/dsh-host-open-in-app/shared`。controller 守卫执行中的启动,并发布所捕获的目录与状态;头部控件从该源派生延迟出现的等待态和短暂错误态。 +两个目录插槽均通过显式的 `absolutePath` 使用 `OpenInAppAction`。`conversation.session.header.utilities` 的注册函数读取会话 cwd,`sidebar.right.tab.files.actions` 则接收所属组件传入的显示目录。插件以一个 effect 注册 `open-in-app` 词典。一个页面生命周期的 controller([`src/client/controller.ts`](src/client/controller.ts))拥有每页一次的可用性读取、持久化选择的 snapshot store 与启动 POST;组件经 inject 的 `hooks` 隔间接收共享源,因此所有会话头部共享同一份事实。文档相对的路由形式与 wire 载荷类型来自主机包的浏览器安全子路径 `@deepseek-ai/dsh-host-open-in-app/shared`。controller 守卫执行中的启动,并发布所捕获的目录与状态;头部控件从该源派生延迟出现的等待态和短暂错误态。 目录和文件适配器把应用信息与操作交给 [`OpenTargetButton`](src/client/OpenTargetButton.tsx),由它统一管理菜单顺序、默认标记、图标、尺寸和操作反馈。文件标题栏和空态共用 `FileOpenTarget`,`OpenPathInjected.applications` 通过 [`open-path.ts`](src/client/open-path.ts) 查询 `session.workspacePathApplications`。打开操作使用 `session.openWorkspacePath`,Host 在启动前重新验证指定的关联应用。`FileRouteAction` 通过 `deliverables.file.actions` 和 `deliverables.review.file.actions` 为交付卡片和变更对比页提供同一控件,其认证路由保留会话文件校验。目录适配器继续使用已有的应用列表路由,文件查询失败或不可用时无需增加平台专用的界面实现。 diff --git a/packages/client/ui-open-in-app/src/client/OpenInAppAction.tsx b/packages/client/ui-open-in-app/src/client/OpenInAppAction.tsx index b5e52a4883..9610a9c11c 100644 --- a/packages/client/ui-open-in-app/src/client/OpenInAppAction.tsx +++ b/packages/client/ui-open-in-app/src/client/OpenInAppAction.tsx @@ -1,6 +1,5 @@ import type { ObservableSnapshot } from '@deepseek-ai/dsh-client-store' -import type { InjectFace, PropsLocale, PropsRuntime } from '@deepseek-ai/dsh-client-ui-slots' -import type {} from '@deepseek-ai/dsh-client-ui-conversation/client' +import type { InjectFace, PropsLocale } from '@deepseek-ai/dsh-client-ui-slots' import { APP_LABEL_KEY } from './applications.ts' import type { OpenInAppLaunchState } from './controller.ts' import type { ShortcutCatalogEntry } from '@deepseek-ai/dsh-client-shortcuts/client' @@ -20,34 +19,18 @@ export interface OpenInAppActionInjected { iconUrl: (appId: string) => string } -/** Full props for the Session-header directory split button. */ +/** Directory path, installed applications, and launch operations for the split button. */ export type OpenInAppActionProps = - PropsRuntime<'conversation.session.header.utilities'> - & PropsLocale + PropsLocale & InjectFace - -/** Full props for a directory split button targeting the file tree's displayed path. */ -export type DirectoryOpenInAppActionProps = - PropsRuntime<'sidebar.right.tab.files.actions'> - & PropsLocale - & InjectFace - -/** - * Open the Session header's workspace through the shared directory control. - * @param props - Session state, installed catalog, and launch operations. - * @returns the directory control, or null without a workspace. - */ -export function OpenInAppAction(props: OpenInAppActionProps): React.JSX.Element | null { - const cwd = props.useSessions(state => state.byId[props.sessionId]?.cwd) - return cwd === undefined || cwd === '' ? null : -} + & { absolutePath: string } /** * Adapt the installed directory catalog to the shared opening control. * @param props - displayed directory, installed catalog, and launch operations. * @returns the shared control, or null without an eligible application. */ -export function DirectoryOpenInAppAction(props: DirectoryOpenInAppActionProps): React.JSX.Element | null { +export function OpenInAppAction(props: OpenInAppActionProps): React.JSX.Element | null { const { absolutePath, useOpenInAppApps, useOpenInAppChoice, t } = props const available = useOpenInAppApps(apps => apps) const choice = useOpenInAppChoice(id => id) diff --git a/packages/client/ui-open-in-app/src/client/index.ts b/packages/client/ui-open-in-app/src/client/index.ts index fcb35ad252..146cfed2f7 100644 --- a/packages/client/ui-open-in-app/src/client/index.ts +++ b/packages/client/ui-open-in-app/src/client/index.ts @@ -4,12 +4,15 @@ * file defaults and application lists come from the serving Host desktop. */ +import { createElement } from 'react' +import type { PropsRuntime } from '@deepseek-ai/dsh-client-ui-slots' import type { ShortcutCommandId } from '@deepseek-ai/dsh-client-shortcuts/client' import type { Context as ClientContext } from '@deepseek-ai/cordis' import type {} from '@deepseek-ai/dsh-client-locale/client' import type {} from '@deepseek-ai/dsh-client-ui-renderer/client' import type {} from '@deepseek-ai/dsh-client-ui-layout/client' import type {} from '@deepseek-ai/dsh-client-ui-session/client' +import type {} from '@deepseek-ai/dsh-client-ui-conversation/client' import type {} from '@deepseek-ai/dsh-client-ui-sidebar-documentpreview/client' import type {} from '@deepseek-ai/dsh-client-ui-sidebar-files/client' import type {} from '@deepseek-ai/dsh-api-gateway/client' @@ -17,7 +20,7 @@ import type {} from '@deepseek-ai/dsh-api-remotes/client' import type {} from '@deepseek-ai/dsh-api-session-controller/remote' import { OPEN_IN_APP_ICON_PREFIX_ROUTE } from '@deepseek-ai/dsh-host-open-in-app/shared' import { OpenInAppController } from './controller.ts' -import { DirectoryOpenInAppAction, OpenInAppAction, type OpenInAppActionInjected } from './OpenInAppAction.tsx' +import { OpenInAppAction, type OpenInAppActionInjected, type OpenInAppActionProps } from './OpenInAppAction.tsx' import { OpenInAppPathController } from './open-path.ts' import { OpenPathAction, type OpenPathInjected } from './OpenPathAction.tsx' import { FileRouteAction } from './FileRouteAction.tsx' @@ -89,14 +92,21 @@ export function apply(ctx: ClientContext): void { choose: (appId) => { controller.choose(appId) }, iconUrl: appId => `${OPEN_IN_APP_ICON_PREFIX_ROUTE}/${appId}`, }) + function SessionOpenInAppAction( + props: PropsRuntime<'conversation.session.header.utilities'> & Omit, + ) { + const { sessionId, useSessions } = props + const cwd = useSessions(state => state.byId[sessionId]?.cwd) + return cwd ? createElement(OpenInAppAction, { ...props, absolutePath: cwd }) : null + } ctx.slots.inject('conversation.session.header.utilities', () => ctx.slots.register({ name: 'conversation.session.header.utilities', id: 'open-in-app', order: -10, locale: NS, inject: directoryInjected, - }, OpenInAppAction)) + }, SessionOpenInAppAction)) ctx.slots.inject('sidebar.right.tab.files.actions', () => ctx.slots.register({ name: 'sidebar.right.tab.files.actions', id: 'open-in-app', locale: NS, inject: directoryInjected, - }, DirectoryOpenInAppAction)) + }, OpenInAppAction)) const applications: OpenPathInjected['applications'] = (path, signal) => paths.applications(path, signal) const pathInjected = (): OpenPathInjected => ({ hooks: { openInAppDesktop: paths.desktop }, diff --git a/packages/client/ui-open-in-app/tests/browser-plugin.client.spec.ts b/packages/client/ui-open-in-app/tests/browser-plugin.client.spec.ts index 2be2b883ea..43b988f2c9 100644 --- a/packages/client/ui-open-in-app/tests/browser-plugin.client.spec.ts +++ b/packages/client/ui-open-in-app/tests/browser-plugin.client.spec.ts @@ -6,6 +6,7 @@ import { createSnapshotStore } from '@deepseek-ai/dsh-client-store' * proving removal (HMR safety) and the injected controller faces. */ +import type { PropsRuntime, SlotComponent } from '@deepseek-ai/dsh-client-ui-slots' import type { ShortcutCommand } from '@deepseek-ai/dsh-client-shortcuts/client' import type { SessionListState } from '@deepseek-ai/dsh-api-session-controller/client' import type { SessionId } from '@deepseek-ai/dsh-session/types' @@ -18,7 +19,7 @@ import { createLayoutStore } from '@deepseek-ai/dsh-client-ui-layout/src/client/ import type {} from '@deepseek-ai/dsh-client-ui-conversation/client' import { apply, inject, type OpenInAppActionInjected, type OpenPathInjected } from '../src/client/index.ts' import { apply as nodeApply } from '../src/index.ts' -import { DirectoryOpenInAppAction, OpenInAppAction } from '../src/client/OpenInAppAction.tsx' +import { OpenInAppAction } from '../src/client/OpenInAppAction.tsx' import { OpenPathAction } from '../src/client/OpenPathAction.tsx' import { OpenPathEmptyAction } from '../src/client/OpenPathEmptyAction.tsx' import { en, NS, zh } from '../src/client/locales.ts' @@ -194,16 +195,29 @@ describe('open-in-app browser half', () => { expect(ctx.slots.entries('deliverables.file.actions')).toHaveLength(0) }) - it('shares the directory control and controller across headers and removes both on teardown', async () => { + it('adapts the Session directory, shares the controller with the file tree, and removes both on teardown', async () => { vi.stubGlobal('fetch', vi.fn(async () => new Response(JSON.stringify({ apps: [] }), { status: 200 }))) - const { ctx, fiber } = await bench() - const entry = ctx.slots.entries('conversation.session.header.utilities')[0] - const files = ctx.slots.entries('sidebar.right.tab.files.actions')[0] - expect(files?.component).toBe(DirectoryOpenInAppAction) - expect(files?.inject).toBe(entry?.inject) - expect(entry?.component).toBe(OpenInAppAction) - expect(entry?.options).toMatchObject({ id: 'open-in-app' }) - await fiber.dispose() + const { ctx, fiber, list } = await bench() + try { + const entry = ctx.slots.entries('conversation.session.header.utilities')[0] + const files = ctx.slots.entries('sidebar.right.tab.files.actions')[0] + expect(files?.component).toBe(OpenInAppAction) + expect(files?.inject).toBe(entry?.inject) + expect(entry?.options).toMatchObject({ id: 'open-in-app' }) + const header = entry?.component as SlotComponent, 'sessionId' | 'useSessions' + >> + const id = 'main' as SessionId + const props = { sessionId: id, useSessions: (select: (state: SessionListState) => T) => select(list.getSnapshot()) } + expect(header(props)).toBeNull() + for (const cwd of ['', '/first', '/second']) { + list.set({ ...list.getSnapshot(), ids: [id], byId: { + [id]: { id, displayTitle: 'Main', cwd, running: false, blank: false, updatedAt: 0, retainedBy: {} }, + } }) + if (cwd === '') expect(header(props)).toBeNull() + else expect(header(props)).toMatchObject({ type: OpenInAppAction, props: { absolutePath: cwd } }) + } + } finally { await fiber.dispose() } expect(headerEntryIds(ctx)).not.toContain('open-in-app') expect(ctx.slots.entries('sidebar.right.tab.files.actions')).toHaveLength(0) }) diff --git a/packages/client/ui-open-in-app/tests/open-in-app-action.client.spec.tsx b/packages/client/ui-open-in-app/tests/open-in-app-action.client.spec.tsx index 7a454d43b1..b3515eafda 100644 --- a/packages/client/ui-open-in-app/tests/open-in-app-action.client.spec.tsx +++ b/packages/client/ui-open-in-app/tests/open-in-app-action.client.spec.tsx @@ -1,13 +1,10 @@ // @vitest-environment jsdom -import { useSyncExternalStore } from 'react' import { afterEach, describe, expect, it, vi } from 'vitest' import { cleanup, fireEvent, render, screen, act } from '@testing-library/react' -import { makeTranslate } from '@deepseek-ai/dsh-client-test-runtime' +import { bindSnapshotSelector, makeTranslate } from '@deepseek-ai/dsh-client-test-runtime' import { createSnapshotStore } from '@deepseek-ai/dsh-client-store' -import type { SessionListState } from '@deepseek-ai/dsh-api-session-controller/client' -import type { SessionId } from '@deepseek-ai/dsh-session/types' import type { ShortcutCatalogEntry, ShortcutCommandId } from '@deepseek-ai/dsh-client-shortcuts/client' -import { DirectoryOpenInAppAction, OpenInAppAction, type OpenInAppActionProps } from '../src/client/OpenInAppAction.tsx' +import { OpenInAppAction, type OpenInAppActionProps } from '../src/client/OpenInAppAction.tsx' import { OpenInAppController } from '../src/client/controller.ts' import { zh } from '../src/client/locales.ts' @@ -17,7 +14,6 @@ afterEach(() => { vi.useRealTimers() }) -const SESSION = 'session' as SessionId const t: OpenInAppActionProps['t'] = makeTranslate(zh) interface Bench { @@ -29,16 +25,10 @@ interface Bench { function bench(over: { apps?: readonly string[] | null choice?: string - cwd?: string + absolutePath?: string shortcuts?: readonly ShortcutCatalogEntry[] launch?: (appId: string, path: string) => Promise } = {}): Bench { - const state: SessionListState = { - ids: [SESSION], - byId: over.cwd === undefined ? {} : { [SESSION]: { id: SESSION, displayTitle: 'Workspace', cwd: over.cwd, running: false, retainedBy: {}, blank: false, updatedAt: 0 } }, - phase: 'ready', - projectionsBySession: {}, - } const apps = createSnapshotStore(over.apps ?? null) const choice = createSnapshotStore(over.choice ?? '') const controller = new OpenInAppController(async (_input, init) => { @@ -48,43 +38,34 @@ function bench(over: { }) const launch = vi.fn((appId: string, path: string) => controller.launch(appId, path)) const choose = vi.fn() - function useSessions(select: (snapshot: SessionListState) => T): T { - return select(state) - } - function useSelector(source: { getSnapshot(): T; subscribe(listener: () => void): () => void }): (select: (value: T) => R) => R { - return select => select(useSyncExternalStore(listener => source.subscribe(listener), () => source.getSnapshot())) - } - const props = { - sessionId: SESSION, - useSessions, - useOpenInAppApps: useSelector(apps), - useOpenInAppChoice: useSelector(choice), - useOpenInAppLaunch: useSelector(controller.operation), - useShortcuts: useSelector(createSnapshotStore(over.shortcuts ?? [])), + const props: OpenInAppActionProps = { + absolutePath: over.absolutePath ?? '/w', + useOpenInAppApps: bindSnapshotSelector(apps), + useOpenInAppChoice: bindSnapshotSelector(choice), + useOpenInAppLaunch: bindSnapshotSelector(controller.operation), + useShortcuts: bindSnapshotSelector(createSnapshotStore(over.shortcuts ?? [])), launch, choose, iconUrl: (appId: string) => `open-in-app/icon/${appId}`, t, - } as OpenInAppActionProps + } return { props, launch, choose } } describe('OpenInAppAction visibility', () => { it('advertises the configured workspace accelerator', () => { - render() expect(screen.getByRole('button', { name: t('open.title', { app: zh['app.finder'] }) }).getAttribute('aria-keyshortcuts')).toBe('Control+O') }) - it('renders nothing before availability arrives, with no apps, without a cwd, and for unnameable ids', () => { + it('renders nothing before availability arrives, with no apps, and for unnameable ids', () => { for (const over of [ - { apps: null, cwd: '/w' }, - { apps: [], cwd: '/w' }, - { apps: [], choice: 'vscode', cwd: '/w' }, - { apps: ['finder'] }, - { apps: ['finder'], cwd: '' }, - { apps: ['someday-an-app'], cwd: '/w' }, + { apps: null, absolutePath: '/w' }, + { apps: [], absolutePath: '/w' }, + { apps: [], choice: 'vscode', absolutePath: '/w' }, + { apps: ['someday-an-app'], absolutePath: '/w' }, ] as const) { const { container } = render() expect(container.innerHTML).toBe('') @@ -93,11 +74,11 @@ describe('OpenInAppAction visibility', () => { }) it('shows the remembered choice, falling back to the first available app when it is gone', () => { - render() + render() expect(screen.getByRole('button', { name: t('open.title', { app: 'Cursor' }) }).querySelector('img')?.getAttribute('src')).toBe('open-in-app/icon/cursor') cleanup() - render() + render() expect(screen.getByRole('button', { name: t('open.title', { app: zh['app.finder'] }) }).querySelector('img')?.getAttribute('src')).toBe('open-in-app/icon/finder') }) }) @@ -105,7 +86,7 @@ describe('OpenInAppAction visibility', () => { describe('OpenInAppAction launching', () => { it('disables both buttons and ignores duplicate gestures until the launch settles', async () => { const pending = Promise.withResolvers() - const b = bench({ apps: ['finder', 'cursor'], cwd: '/w/dir', launch: () => pending.promise }) + const b = bench({ apps: ['finder', 'cursor'], absolutePath: '/w/dir', launch: () => pending.promise }) const view = render() const main = screen.getByRole('button', { name: t('open.title', { app: zh['app.finder'] }) }) fireEvent.click(main) @@ -119,7 +100,7 @@ describe('OpenInAppAction launching', () => { }) it('announces launch failure without changing the remembered application', async () => { - const b = bench({ apps: ['finder', 'cursor'], cwd: '/w', launch: async () => { throw new Error('gone') } }) + const b = bench({ apps: ['finder', 'cursor'], absolutePath: '/w', launch: async () => { throw new Error('gone') } }) render() fireEvent.click(screen.getByRole('button', { name: zh['path.more'] })) await act(async () => { fireEvent.click(screen.getByRole('menuitem', { name: 'Cursor' })) }) @@ -128,7 +109,7 @@ describe('OpenInAppAction launching', () => { }) it('lists only applications, marks the remembered default, and remembers a successful choice', async () => { - const b = bench({ apps: ['finder', 'cursor', 'terminal'], cwd: '/w/dir' }) + const b = bench({ apps: ['finder', 'cursor', 'terminal'], absolutePath: '/w/dir' }) render() fireEvent.click(screen.getByRole('button', { name: zh['path.more'] })) expect(screen.getAllByRole('menuitem').map(item => item.textContent)).toEqual(['访达(默认)', 'Cursor', '终端']) @@ -139,7 +120,7 @@ describe('OpenInAppAction launching', () => { }) it('closes on Escape without launching and falls back after an icon fails', async () => { - const b = bench({ apps: ['finder', 'terminal'], cwd: '/w' }) + const b = bench({ apps: ['finder', 'terminal'], absolutePath: '/w' }) const view = render() fireEvent.click(screen.getByRole('button', { name: zh['path.more'] })) fireEvent.keyDown(screen.getByRole('menu'), { key: 'Escape' }) @@ -152,7 +133,7 @@ describe('OpenInAppAction launching', () => { }) it('names the selected application in the tooltip', async () => { - render() + render() fireEvent.mouseEnter(screen.getByRole('button', { name: t('open.title', { app: zh['app.finder'] }) })) expect(await screen.findByText(t('open.title', { app: zh['app.finder'] }))).toBeTruthy() }) @@ -160,20 +141,18 @@ describe('OpenInAppAction launching', () => { it('omits the dropdown when only one directory application is available', () => { - render() + render() expect(screen.getAllByRole('button')).toHaveLength(1) expect(screen.queryByRole('button', { name: zh['path.more'] })).toBeNull() }) -it('opens the displayed directory and follows its changes without reading the Session cwd', async () => { - const b = bench({ apps: ['finder'], cwd: '/session-workspace' }) - const useSessions = vi.fn(() => { throw new Error('Directory controls must use the displayed path') }) - const view = render() +it('opens the displayed directory and follows its changes', async () => { + const b = bench({ apps: ['finder'], absolutePath: '/displayed-directory' }) + const view = render() await act(async () => { fireEvent.click(screen.getByRole('button')) }) expect(b.launch).toHaveBeenLastCalledWith('finder', '/displayed-directory') - view.rerender() + view.rerender() await act(async () => { fireEvent.click(screen.getByRole('button')) }) expect(b.launch).toHaveBeenLastCalledWith('finder', '/another-directory') - expect(useSessions).not.toHaveBeenCalled() }) diff --git a/packages/extensions/cordis-client-runner/src/client/slot-catalog.ts b/packages/extensions/cordis-client-runner/src/client/slot-catalog.ts index 6ee4f7ad7b..7a15a2f5ef 100644 --- a/packages/extensions/cordis-client-runner/src/client/slot-catalog.ts +++ b/packages/extensions/cordis-client-runner/src/client/slot-catalog.ts @@ -1497,7 +1497,7 @@ export const CLIENT_SLOT_API: readonly ClientSlotEntry[] = [ slotInject: '', declaredBy: 'an entry in \'conversation.session.header\' (client-ui-conversation), so it exists while that entry is mounted', occupants: [ - 'client-ui-open-in-app OpenInAppAction id \'open-in-app\'', + 'client-ui-open-in-app SessionOpenInAppAction id \'open-in-app\'', 'client-ui-schedule ScheduleCatalogAction id \'schedule-catalog\'', 'session-log-export SessionLogDownloadHeaderAction id \'session-log-download\'', ], @@ -3503,7 +3503,7 @@ export const CLIENT_SLOT_API: readonly ClientSlotEntry[] = [ slotInject: '', declaredBy: 'an entry in \'sidebar.right.pane.tab\' (client-ui-sidebar-files), so it exists while that entry is mounted', occupants: [ - 'client-ui-open-in-app DirectoryOpenInAppAction id \'open-in-app\'', + 'client-ui-open-in-app OpenInAppAction id \'open-in-app\'', ], replaceRisk: 'none', example: 'return {\n inject: [\'slots\'],\n apply(ctx) {\n ctx.slots.inject(\'sidebar.right.tab.files.actions\', () => ctx.slots.register(\n { name: \'sidebar.right.tab.files.actions\', id: \'my-entry\', order: 100, label: \'My entry\' },\n () => React.createElement(\'div\', null, \'hello\'),\n ))\n },\n}',