DeepSeek Harness Tauri 桌面版 | Only 8mb installer, zero environment setup, preset plugins, Windows / macOS / Linux.
refactor(ssh-ui): 「同步到远端」升到与「管理机器」同级
Menghuan1918dad7891b51d8
diff --git a/packages/dsh-tauri-ssh-ui/src/client/components/sync-panel.tsx b/packages/dsh-tauri-ssh-ui/src/client/components/sync-panel.tsxindex c4f01203..fc7272bc 100644--- a/packages/dsh-tauri-ssh-ui/src/client/components/sync-panel.tsx+++ b/packages/dsh-tauri-ssh-ui/src/client/components/sync-panel.tsx@@ -24,12 +24,10 @@ import { cls } from '../styles'export interface SyncPanelProps {store: MachinesStoret: (key: SshKey) => string- /** 侧边栏面板内嵌形态:隐藏大标题/说明(面板标签已表意)。 */- embedded?: boolean}/** Render the sync panel over the store snapshot. */-export function SyncPanel({ store, t, embedded = false }: SyncPanelProps): ReactNode {+export function SyncPanel({ store, t }: SyncPanelProps): ReactNode {const state = useSyncExternalStore(store.subscribe, store.getSnapshot)const [selected, setSelected] = useState<ReadonlySet<string>>(() => new Set())const [targetId, setTargetId] = useState<string | null>(null)@@ -53,9 +51,13 @@ export function SyncPanel({ store, t, embedded = false }: SyncPanelProps): React}return (- <section className={cls.syncPanel} data-testid="sync-panel">- {embedded ? null : <h3 className={cls.groupTitle}>{t('sync.title')}</h3>}- {embedded ? null : <p className={cls.groupHint}>{t('sync.desc')}</p>}+ <section className={cls.section} data-testid="sync-panel">+ <div className={cls.sectionHead}>+ <div>+ <h2 className={cls.title}>{t('sync.title')}</h2>+ <p className={cls.intro}>{t('sync.desc')}</p>+ </div>+ </div>{connected.length === 0? <p className={cls.hint}>{t('sync.notConnectedHint')}</p>: (diff --git a/packages/dsh-tauri-ssh-ui/src/client/constants/index.ts b/packages/dsh-tauri-ssh-ui/src/client/constants/index.tsindex aa01647d..ca0deb68 100644--- a/packages/dsh-tauri-ssh-ui/src/client/constants/index.ts+++ b/packages/dsh-tauri-ssh-ui/src/client/constants/index.ts@@ -17,6 +17,16 @@ export const SETTINGS_SECTION_ID = 'dsh-tauri-ssh'/** Order of this plugin's settings section among the other sections. */export const SETTINGS_SECTION_ORDER = 50+/**+ * Registration id of the plugin/skill sync settings section — a sibling of+ * {@link SETTINGS_SECTION_ID}, so the desktop switcher can deep-link both+ * remote-machine surfaces at the same level (`dsh://settings:open` section).+ */+export const SYNC_SECTION_ID = 'dsh-tauri-ssh-sync'++/** Order of the sync section, right behind the machines section. */+export const SYNC_SECTION_ORDER = 51+/** The /api-ssh route the host plugin mounts (same-origin POST envelope). */export const SSH_API_PATH = '/api-ssh'diff --git a/packages/dsh-tauri-ssh-ui/src/client/index.test.ts b/packages/dsh-tauri-ssh-ui/src/client/index.test.tsindex 7815b522..3f8cc3f8 100644--- a/packages/dsh-tauri-ssh-ui/src/client/index.test.ts+++ b/packages/dsh-tauri-ssh-ui/src/client/index.test.ts@@ -2,6 +2,7 @@ import type { UiContext } from './types/index'import { afterEach, describe, expect, it, vi } from 'vitest'import { apply as hostApply } from '../index'import { MachinesSection } from './components/machines-section.tsx'+import { SyncPanel } from './components/sync-panel.tsx'import { apply, inject } from './index'import { en, zh } from './locales/index'import { desktopBridge } from './service/bridge'@@ -13,7 +14,6 @@ import { MachinesStore } from './store/index'vi.mock('dsh-tauri/client', () => ({invoke: vi.fn(async () => undefined),defineRegister: (feature: (controller: unknown) => void) => feature,- definePanel: (_ctx: unknown, entry: { id: string }) => ({ id: entry.id, dispose: () => {} }),}))// dsh-tauri-ui/client 的 dist bundle 以 ModuleLoader 工厂包裹,脱离宿主加载器@@ -54,13 +54,13 @@ describe('ui-ssh client plugin', () => {})it('declares its inject topology', () => {- expect(inject).toEqual(['slots', 'locale', 'layout'])+ expect(inject).toEqual(['slots', 'locale'])})it('registers the ssh dictionaries on activation', () => {const { ctx, locale, effects } = scriptedCtx()apply(ctx)- expect(effects).toHaveLength(3)+ expect(effects).toHaveLength(2)effects[0]?.()expect(locale.register).toHaveBeenCalledWith('ssh', { zh, en })expect(locale.bind).toHaveBeenCalledWith('ssh')@@ -97,6 +97,27 @@ describe('ui-ssh client plugin', () => {await store.load()expect(fetchMock).toHaveBeenCalledWith('/api-ssh', expect.objectContaining({ method: 'POST' }))})++ it('registers the sync section as a sibling of the machines section', () => {+ const { ctx, slots } = scriptedCtx()+ apply(ctx)+ expect(slots.inject).toHaveBeenCalledTimes(2)+ const contribution = slots.inject.mock.calls[1]?.[1] as () => unknown+ contribution()+ const options = slots.register.mock.calls[0]?.[0] as {+ id: string+ order: number+ label: () => string+ locale: string+ inject: () => Record<string, unknown>+ }+ expect(options.id).toBe('dsh-tauri-ssh-sync')+ expect(options.order).toBe(51)+ expect(options.label()).toBe('t:sync.nav')+ expect(options.locale).toBe('ssh')+ expect(options.inject().store).toBeInstanceOf(MachinesStore)+ expect(slots.register.mock.calls[0]?.[1]).toBe(SyncPanel)+ })})afterEach(() => {diff --git a/packages/dsh-tauri-ssh-ui/src/client/index.ts b/packages/dsh-tauri-ssh-ui/src/client/index.tsindex 04535c61..195f4450 100644--- a/packages/dsh-tauri-ssh-ui/src/client/index.ts+++ b/packages/dsh-tauri-ssh-ui/src/client/index.ts@@ -1,9 +1,11 @@/*** SSH-machines settings page, browser half. Registers the `ssh` dictionary- * and one `settings.section` entry; the page state lives in the injected- * MachinesStore (machine CRUD and the connection plane, all through the host- * plugin's /api-ssh route). The css-render style tree mounts once here via- * ctx.effect (unmounts with the plugin). Export discipline: thin apply,+ * and two sibling `settings.section` entries — the machines page and the+ * plugin/skill sync page — so the desktop switcher can deep-link either of+ * them at the same level. The page state lives in the injected MachinesStore+ * (machine CRUD, the connection plane and the sync surface, all through the+ * host plugin's /api-ssh route). The css-render style tree mounts once here+ * via ctx.effect (unmounts with the plugin). Export discipline: thin apply,* everything else in feature modules.* @module dsh-tauri-ssh-ui/client*/@@ -11,18 +13,25 @@import type { UiContext } from './types'import { mountStyle } from 'dsh-tauri-ui/client'import { MachinesSection } from './components/machines-section'-import { SETTINGS_SECTION_ID, SETTINGS_SECTION_ORDER, SETTINGS_SECTION_SLOT, SSH_LOCALE_NS } from './constants'+import { SyncPanel } from './components/sync-panel'+import {+ SETTINGS_SECTION_ID,+ SETTINGS_SECTION_ORDER,+ SETTINGS_SECTION_SLOT,+ SSH_LOCALE_NS,+ SYNC_SECTION_ID,+ SYNC_SECTION_ORDER,+} from './constants'import { en, zh } from './locales'-import { syncPanelFeature } from './register/sync-panel'import { desktopBridge } from './service/bridge'import { MachinesStore } from './store'import { SSH_STYLE_ID, sshStyle } from './styles'/** Required services: the settings slot seam and the locale seat. */-export const inject = ['slots', 'locale', 'layout']+export const inject = ['slots', 'locale']/**- * Register the `ssh` dictionaries and the settings section, each once its+ * Register the `ssh` dictionaries and both settings sections, each once its* slot declaration is on the ledger.* @param ctx - client root context.*/@@ -31,7 +40,6 @@ export function apply(ctx: UiContext): void {ctx.effect(() => mountStyle(sshStyle, SSH_STYLE_ID), 'dsh-tauri-ssh-ui: styles')const t = ctx.locale.bind(SSH_LOCALE_NS)const store = new MachinesStore((url, init) => fetch(url, init))- ctx.effect(syncPanelFeature(store, t), 'dsh-tauri-ssh-ui: sync panel')ctx.slots.inject(SETTINGS_SECTION_SLOT, () => ctx.slots.register({name: SETTINGS_SECTION_SLOT,id: SETTINGS_SECTION_ID,@@ -40,6 +48,14 @@ export function apply(ctx: UiContext): void {locale: SSH_LOCALE_NS,inject: () => ({ store, bridge: desktopBridge }),}, MachinesSection))+ ctx.slots.inject(SETTINGS_SECTION_SLOT, () => ctx.slots.register({+ name: SETTINGS_SECTION_SLOT,+ id: SYNC_SECTION_ID,+ order: SYNC_SECTION_ORDER,+ label: () => t('sync.nav'),+ locale: SSH_LOCALE_NS,+ inject: () => ({ store }),+ }, SyncPanel))}/** The dictionary key union, re-exported for the section props. */diff --git a/packages/dsh-tauri-ssh-ui/src/client/locales/index.ts b/packages/dsh-tauri-ssh-ui/src/client/locales/index.tsindex 0f1a84ee..35774c32 100644--- a/packages/dsh-tauri-ssh-ui/src/client/locales/index.ts+++ b/packages/dsh-tauri-ssh-ui/src/client/locales/index.ts@@ -32,7 +32,7 @@ export const zh = {'field.port': '端口','field.user': '用户(可选)','session.remoteTitle': '目前正在 SSH 中',- 'sync.panelLabel': '同步到远端',+ 'sync.nav': '同步到远端','sync.notConnectedHint': '还没有已连接的机器——先在「SSH 远程机器」里连接一台,即可把插件和 Skill 同步过去。','session.remoteHintNamed': '此实例正通过 SSH 来自 {name} 的连接使用——机器管理请在发起 SSH 连接的机器上配置。','session.remoteHint': '此实例正通过 SSH 远程连接使用——机器管理请在发起 SSH 连接的机器上配置。',@@ -136,7 +136,7 @@ export const en = {'field.port': 'Port','field.user': 'User (optional)','session.remoteTitle': 'Currently in an SSH session',- 'sync.panelLabel': 'Sync to remote',+ 'sync.nav': 'Sync to remote','sync.notConnectedHint': 'No connected machines yet — connect one under “SSH machines” first, then sync plugins and skills to it.','session.remoteHintNamed': 'This instance is in use over SSH from {name} — manage machines on the machine that initiated the SSH connection.','session.remoteHint': 'This instance is in use over SSH — manage machines on the machine that initiated the SSH connection.',diff --git a/packages/dsh-tauri-ssh-ui/src/client/register/sync-panel.test.tsx b/packages/dsh-tauri-ssh-ui/src/client/register/sync-panel.test.tsxdeleted file mode 100644index 7e6ef59c..00000000--- a/packages/dsh-tauri-ssh-ui/src/client/register/sync-panel.test.tsx+++ /dev/null@@ -1,26 +0,0 @@-import type { MachinesStore } from '../store/index'-import { describe, expect, it, vi } from 'vitest'-import { SYNC_PANEL_ID, syncPanelFeature } from './sync-panel'--const mocks = vi.hoisted(() => ({- definePanel: vi.fn((_ctx: unknown, _entry: unknown) => ({ dispose: () => {} })),-}))--vi.mock('dsh-tauri/client', () => ({- defineRegister: (feature: (...args: never[]) => void) => feature,- definePanel: mocks.definePanel,-}))--describe('syncPanelFeature', () => {- it('registers the sidebar panel with an embedded SyncPanel render', () => {- const store = { subscribe: () => () => {}, getSnapshot: () => ({}) } as unknown as MachinesStore- const feature = syncPanelFeature(store, key => key)- const controller = { add: vi.fn() }- ;(feature as (controller: unknown, ctx: unknown) => void)(controller, {})- expect(controller.add).toHaveBeenCalledOnce()- const entry = mocks.definePanel.mock.calls[0]?.[1] as unknown as { id: string, render: () => unknown }- expect(entry.id).toBe(SYNC_PANEL_ID)- expect(typeof entry.render).toBe('function')- mocks.definePanel.mockClear()- })-})diff --git a/packages/dsh-tauri-ssh-ui/src/client/register/sync-panel.tsx b/packages/dsh-tauri-ssh-ui/src/client/register/sync-panel.tsxdeleted file mode 100644index 3ad7d4f1..00000000--- a/packages/dsh-tauri-ssh-ui/src/client/register/sync-panel.tsx+++ /dev/null@@ -1,44 +0,0 @@-import type { ClientContext } from 'dsh-tauri/client'-import type { SshKey } from '../locales/index'-import type { MachinesStore } from '../store/index'-import { definePanel, defineRegister } from 'dsh-tauri/client'-import { SyncPanel } from '../components/sync-panel'--export const SYNC_PANEL_ID = 'dsh-tauri-ssh-sync'-export const SYNC_PANEL_ORDER = 45--/**- * dsh 主侧边栏的「同步到远端」面板:definePanel 注册 sidebar.panellist 图标与- * main 槽内容,一处点击直达插件/Skill 同步(原先埋在设置页机器列表尾部)。- */-export function syncPanelFeature(store: MachinesStore, t: (key: SshKey) => string) {- return defineRegister<ClientContext>((controller, ctx) => {- if (typeof window === 'undefined' || window.parent === window)- return- controller.add(- definePanel(ctx, {- id: SYNC_PANEL_ID,- order: SYNC_PANEL_ORDER,- label: () => t('sync.panelLabel'),- icon: ({ size, active }) => (- <svg- aria-hidden="true"- fill="none"- height={size}- stroke={active ? 'currentColor' : 'currentColor'}- strokeLinecap="round"- strokeLinejoin="round"- strokeWidth="1.6"- viewBox="0 0 16 16"- width={size}- >- <path d="M8 13V3" />- <path d="m3.5 7.5 4.5-4.5 4.5 4.5" />- <path d="M2.5 13.5h11" />- </svg>- ),- render: () => <SyncPanel embedded store={store} t={t} />,- }).dispose,- )- })-}diff --git a/src/i18n/locales/en-US.json b/src/i18n/locales/en-US.jsonindex 6ed5e7cd..b98b3714 100644--- a/src/i18n/locales/en-US.json+++ b/src/i18n/locales/en-US.json@@ -354,6 +354,7 @@"remote.switcher": "Remote machines","remote.local": "Local","remote.manage": "Manage machines",+ "remote.sync": "Sync to remote","remote.manage_hint": "Add or manage machines in the web app: open Settings → SSH Remote Machines.","remote.disconnect_active": "Disconnect current remote","remote.retry_in": " (retry in {{seconds}}s)",diff --git a/src/i18n/locales/zh-CN.json b/src/i18n/locales/zh-CN.jsonindex 75088184..aa98334f 100644--- a/src/i18n/locales/zh-CN.json+++ b/src/i18n/locales/zh-CN.json@@ -354,6 +354,7 @@"remote.switcher": "远端机器","remote.local": "本地","remote.manage": "管理机器",+ "remote.sync": "同步到远端","remote.manage_hint": "在网页端「设置 → SSH 远端机器」面板中添加或管理机器。","remote.disconnect_active": "断开当前远端连接","remote.retry_in": "({{seconds}}s 后重试)",diff --git a/src/layout/components/nav-bridge.test.ts b/src/layout/components/nav-bridge.test.tsindex 743ec677..f3d088e5 100644--- a/src/layout/components/nav-bridge.test.ts+++ b/src/layout/components/nav-bridge.test.ts@@ -1,5 +1,5 @@import { describe, expect, it } from 'vitest'-import { navBridgeOf, SSH_MACHINES_SECTION } from './nav-bridge'+import { navBridgeOf, SSH_MACHINES_SECTION, SSH_SYNC_SECTION } from './nav-bridge'describe('navBridgeOf', () => {it('sends no callbacks while the iframe is absent', () => {@@ -15,12 +15,14 @@ describe('navBridgeOf', () => {bridge.onNewChat?.()bridge.onOpenFolder?.()bridge.onOpenMachineManager?.()+ bridge.onOpenSyncToRemote?.()expect(sent).toEqual([{ type: 'dsh://sidebar:toggle' },{ type: 'dsh://session:new' },{ type: 'dsh://workspace:add' },{ type: 'dsh://settings:open', section: SSH_MACHINES_SECTION },+ { type: 'dsh://settings:open', section: SSH_SYNC_SECTION },])})})diff --git a/src/layout/components/nav-bridge.ts b/src/layout/components/nav-bridge.tsindex aafef184..8210fe45 100644--- a/src/layout/components/nav-bridge.ts+++ b/src/layout/components/nav-bridge.ts@@ -4,6 +4,9 @@ import type { IframeOutboundMessage } from '@/hooks/use-iframe-post'/** 设置浮层分区 id:SSH 机器管理(dsh-tauri-ssh 插件注册)。 */export const SSH_MACHINES_SECTION = 'dsh-tauri-ssh'+/** 设置浮层分区 id:同步到远端(同一插件注册的第二个分区,与上者同级)。 */+export const SSH_SYNC_SECTION = 'dsh-tauri-ssh-sync'+/*** 导航栏回调桥:把每个导航栏动作翻译成一条宿主 → iframe 协议消息。*@@ -23,5 +26,6 @@ export function navBridgeOf(post: (message: IframeOutboundMessage) => void, liveonNewChat: () => post({ type: 'dsh://session:new' }),onOpenFolder: () => post({ type: 'dsh://workspace:add' }),onOpenMachineManager: () => post({ type: 'dsh://settings:open', section: SSH_MACHINES_SECTION }),+ onOpenSyncToRemote: () => post({ type: 'dsh://settings:open', section: SSH_SYNC_SECTION }),}}diff --git a/src/layout/components/navbar.tsx b/src/layout/components/navbar.tsxindex f50bd85c..4a686385 100644--- a/src/layout/components/navbar.tsx+++ b/src/layout/components/navbar.tsx@@ -153,11 +153,13 @@ export interface NavbarProps {onNewChat?: () => void/** 管理机器:向 iframe 发 `dsh://settings:open` 定位 SSH 分区(统一到设置页) */onOpenMachineManager?: () => void+ /** 同步到远端:向 iframe 发 `dsh://settings:open` 定位同步分区(与机器管理同级) */+ onOpenSyncToRemote?: () => void/** 打开文件夹:向 iframe 发 `dsh://workspace:add`(dsh 官方「添加工作区」);传入时该项可用 */onOpenFolder?: () => void}-export function Navbar({ sidebarCollapsed = false, onToggleSidebar, onNewChat, onOpenFolder, onOpenMachineManager }: NavbarProps) {+export function Navbar({ sidebarCollapsed = false, onToggleSidebar, onNewChat, onOpenFolder, onOpenMachineManager, onOpenSyncToRemote }: NavbarProps) {const { t } = useTranslation()const isFullscreen = useMacOSFullscreen()// 只读取「dsh-tauri 插件是否已安装」;查询键与「插件」面板共用(同一份缓存),@@ -370,7 +372,7 @@ export function Navbar({ sidebarCollapsed = false, onToggleSidebar, onNewChat, o</Button></If><If cond={onToggleSidebar != null}>- <RemoteSwitcher onManage={onOpenMachineManager} />+ <RemoteSwitcher onManage={onOpenMachineManager} onSync={onOpenSyncToRemote} /><ConnectDialog /></If><If cond={!IS_MACOS}>diff --git a/src/layout/components/remote-switcher.test.tsx b/src/layout/components/remote-switcher.test.tsxindex 0f225c03..9aac2e24 100644--- a/src/layout/components/remote-switcher.test.tsx+++ b/src/layout/components/remote-switcher.test.tsx@@ -97,6 +97,23 @@ describe('remoteSwitcher 渲染', () => {})})+ it('操作区:管理机器与同步到远端同级且各自回调;缺回调时双双置灰', async () => {+ const syncSpy = vi.fn()+ const { unmount } = render(<RemoteSwitcher onManage={manageSpy} onSync={syncSpy} />)+ const menu = await openMenu()+ fireEvent.click(within(menu).getByText('remote.sync'))+ await waitFor(() => {+ expect(syncSpy).toHaveBeenCalled()+ })+ expect(within(menu).getByText('remote.manage')).toBeTruthy()+ unmount()++ render(<RemoteSwitcher />)+ const bare = await openMenu()+ expect(within(bare).getByText('remote.manage').closest('[role="menuitem"]')?.getAttribute('aria-disabled')).toBe('true')+ expect(within(bare).getByText('remote.sync').closest('[role="menuitem"]')?.getAttribute('aria-disabled')).toBe('true')+ })+it('机器项:状态点语义(标识色优先内联 / 已连接绿 / 重连琥珀 / 放弃红)与状态文案', async () => {seedMachines([machineOf({ id: 'colored', name: 'colored', color: '#ff00ff', state: 'reconnecting' }),diff --git a/src/layout/components/remote-switcher.tsx b/src/layout/components/remote-switcher.tsxindex 32c1ca62..96923dbf 100644--- a/src/layout/components/remote-switcher.tsx+++ b/src/layout/components/remote-switcher.tsx@@ -1,5 +1,5 @@import type { SshMachineRow } from '@/store/modules/remote'-import { ArrowUpRightFromSquare, Gear, Globe, House, Power } from '@gravity-ui/icons'+import { ArrowUpRightFromSquare, ArrowUpToLine, Gear, Globe, House, Power } from '@gravity-ui/icons'import { Button, Description, Dropdown, Label } from '@heroui/react'import { invoke } from '@tauri-apps/api/core'import { useTranslation } from 'react-i18next'@@ -51,14 +51,14 @@ function openInNewWindow(machine: SshMachineRow, onError: (err: unknown) => void** 数据面全部来自本地实例 `/api-ssh`(`useRemoteMachines` 启动秒级轮询 +* 聚焦刷新);点击机器行=当前窗口切换(未连接则发起连接,进度弹窗实时- * 呈现),行尾图标=新窗口打开(已连接机器可用)。管理入口在底部- * 「管理机器…」(进 iframe 设置浮层的 SSH 机器分区)。+ * 呈现),行尾图标=新窗口打开(已连接机器可用)。操作区两项同级:底部+ * 「管理机器…」与「同步到远端…」,各自直达 iframe 设置浮层的对应分区。** 色点语义(S3 词汇表):机器标识色优先 → 已连接绿 → 重连/进行中琥珀 →* 放弃红 → 其余中性灰;未连接行整体降不透明度。本地实例不可达时进入降级* 态:远端项禁用 + 顶部提示,恢复后自动复原(轮询静默重试,不弹错误)。*/-export function RemoteSwitcher({ onManage }: { onManage?: () => void }) {+export function RemoteSwitcher({ onManage, onSync }: { onManage?: () => void, onSync?: () => void }) {const { t } = useTranslation()useRemoteMachines()const { machines, activeId, available, pendingId } = useStore(store.remote)@@ -209,6 +209,18 @@ export function RemoteSwitcher({ onManage }: { onManage?: () => void }) {<Label>{t('remote.manage')}</Label></span></Dropdown.Item>+ <Dropdown.Item+ className="rounded-md"+ id="remote-sync"+ isDisabled={onSync == null}+ textValue={t('remote.sync')}+ onAction={onSync}+ >+ <span className="flex w-full items-center gap-2">+ <ArrowUpToLine className="size-3.5 text-muted" />+ <Label>{t('remote.sync')}</Label>+ </span>+ </Dropdown.Item></Dropdown.Section></Dropdown.Menu></Dropdown.Popover>