DeepSeek Harness Tauri 桌面版 | Only 8mb installer, zero environment setup, preset plugins, Windows / macOS / Linux.
feat(rightclick): 会话右键菜单新增「置顶会话」
hairyf7c3d1fc746d5
diff --git a/packages/dsh-tauri-rightclick/src/client/locales/index.ts b/packages/dsh-tauri-rightclick/src/client/locales/index.tsindex bad77608..c9f9493b 100644--- a/packages/dsh-tauri-rightclick/src/client/locales/index.ts+++ b/packages/dsh-tauri-rightclick/src/client/locales/index.ts@@ -29,6 +29,10 @@ const zh = {copiedWorkspacePath: '已复制工作区路径',sessionRenamed: '会话已重命名',sessionArchived: '会话已归档',+ pinSession: '置顶会话',+ unpinSession: '取消置顶',+ sessionPinned: '会话已置顶',+ sessionUnpinned: '已取消置顶',copied: '已复制',cutDone: '已剪切',linkCopied: '已复制链接',@@ -60,6 +64,7 @@ const zh = {officialWorkspaceRenameUnavailable: '无法打开官方工作区重命名窗口',officialArchiveUnavailable: '无法调用官方归档会话',officialForkUnavailable: '无法调用官方分叉会话',+ pinSessionUnavailable: '无法调用官方置顶会话',sessionUnknown: '无法确定当前会话',sessionNameEmpty: '会话名称不能为空',sessionServiceUnavailable: '无法取得官方会话服务',@@ -95,6 +100,10 @@ const en: Record<keyof typeof zh, string> = {copiedWorkspacePath: 'Workspace path copied',sessionRenamed: 'Session renamed',sessionArchived: 'Session archived',+ pinSession: 'Pin session',+ unpinSession: 'Unpin session',+ sessionPinned: 'Session pinned',+ sessionUnpinned: 'Session unpinned',copied: 'Copied',cutDone: 'Cut',linkCopied: 'Link copied',@@ -126,6 +135,7 @@ const en: Record<keyof typeof zh, string> = {officialWorkspaceRenameUnavailable: 'Could not open the official workspace rename dialog',officialArchiveUnavailable: 'Could not invoke the official archive action',officialForkUnavailable: 'Could not invoke the official fork action',+ pinSessionUnavailable: 'Could not invoke the official pin action',sessionUnknown: 'Could not determine the current session',sessionNameEmpty: 'Session name cannot be empty',sessionServiceUnavailable: 'Official session service is unavailable',diff --git a/packages/dsh-tauri-rightclick/src/client/register/context-menu.menu.ts b/packages/dsh-tauri-rightclick/src/client/register/context-menu.menu.tsindex c7721532..d46ca525 100644--- a/packages/dsh-tauri-rightclick/src/client/register/context-menu.menu.ts+++ b/packages/dsh-tauri-rightclick/src/client/register/context-menu.menu.ts@@ -14,11 +14,14 @@ import {archiveSessions,deleteWorkspace as deleteWorkspaceAction,forkSession,+ isSessionPinned,loadUngroupedSessions,loadWorkspaceSessions,openExternalUrl,openInExplorer,renameSession,+ supportsSessionPin,+ togglePinSession,} from '../service/menu'import { readClipboard } from '../utils/clipboard'import { pasteInto, replaceSelection, selectAll, selectSurface } from '../utils/editable'@@ -39,6 +42,17 @@ export function buildSessionMenu(): void {const current = session+ // 置顶会话:官方 0.1.7 起提供置顶能力,旧核心不展示该入口。+ if (current && supportsSessionPin(composer.workspaces)) {+ const pinned = isSessionPinned({ workspaces: composer.workspaces, sessionId: current.id })+ composer.add(pinned ? locale.text('unpinSession') : locale.text('pinSession'), async () => {+ const outcome = await togglePinSession({ workspaces: composer.workspaces, sessionId: current.id, pinned })+ if (outcome.ok)+ composer.toast(locale.text(pinned ? 'sessionUnpinned' : 'sessionPinned'))+ return outcome+ })+ }+composer.add(locale.text('renameSession'), async () => {if (officialAction(row))return officialSelect(row, RENAME_LABELS, locale.text('officialRenameUnavailable'), composer.delegate(false))diff --git a/packages/dsh-tauri-rightclick/src/client/service/menu.test.ts b/packages/dsh-tauri-rightclick/src/client/service/menu.test.tsindex 72f674f8..1c142ea2 100644--- a/packages/dsh-tauri-rightclick/src/client/service/menu.test.ts+++ b/packages/dsh-tauri-rightclick/src/client/service/menu.test.ts@@ -6,11 +6,14 @@ import {archiveSessions,deleteWorkspace,forkSession,+ isSessionPinned,loadUngroupedSessions,loadWorkspaceSessions,openExternalUrl,openInExplorer,renameSession,+ supportsSessionPin,+ togglePinSession,} from './menu'vi.mock('../apis', () => ({ postOpenPath: vi.fn(), postOpenUrl: vi.fn() }))@@ -291,3 +294,86 @@ describe('deleteWorkspace', () => {.toEqual({ ok: false, error: 'busy' })})})++describe('session pin (official 0.1.7 capability)', () => {+ const workspacesWith = (+ overrides: Record<string, unknown>,+ pinnedSessionIds?: SessionId[],+ ): WorkspacesRuntimeLike =>+ ({+ ...overrides,+ list: { getSnapshot: () => ({ items: [], archivedSessionIds: [], pinnedSessionIds }) },+ }) as unknown as WorkspacesRuntimeLike++ it('reports the capability only when pin and unpin both exist', () => {+ expect(supportsSessionPin(workspacesWith({ pinSession: vi.fn(), unpinSession: vi.fn() }))).toBe(true)+ expect(supportsSessionPin(workspacesWith({ pinSession: vi.fn() }))).toBe(false)+ expect(supportsSessionPin(workspacesWith({ unpinSession: vi.fn() }))).toBe(false)+ expect(supportsSessionPin(workspacesWith({}))).toBe(false)+ })++ it('reads the pinned set from the workspace snapshot', () => {+ const workspaces = workspacesWith({}, [sid('s-1')])+ expect(isSessionPinned({ workspaces, sessionId: sid('s-1') })).toBe(true)+ expect(isSessionPinned({ workspaces, sessionId: sid('s-2') })).toBe(false)+ })++ it('treats a pre-0.1.7 snapshot without a pinned set as unpinned', () => {+ const workspaces = {+ list: { getSnapshot: () => ({ items: [], archivedSessionIds: [] }) },+ } as unknown as WorkspacesRuntimeLike++ expect(isSessionPinned({ workspaces, sessionId: sid('s-1') })).toBe(false)+ })++ it('pins an unpinned session and unpins a pinned one', async () => {+ const pinSession = vi.fn(async () => undefined)+ const unpinSession = vi.fn(async () => undefined)+ const workspaces = workspacesWith({ pinSession, unpinSession })++ await expect(togglePinSession({ workspaces, sessionId: sid('s-1'), pinned: false }))+ .resolves+ .toEqual({ ok: true })+ expect(pinSession).toHaveBeenCalledWith('s-1')+ expect(unpinSession).not.toHaveBeenCalled()++ await expect(togglePinSession({ workspaces, sessionId: sid('s-1'), pinned: true }))+ .resolves+ .toEqual({ ok: true })+ expect(unpinSession).toHaveBeenCalledWith('s-1')+ })++ it('invokes the official method with the service as receiver', async () => {+ const seen: unknown[] = []+ const workspaces = workspacesWith({+ pinSession(sessionId: SessionId) {+ seen.push(this)+ expect(sessionId).toBe('s-1')+ return Promise.resolve()+ },+ unpinSession: async () => undefined,+ })++ await togglePinSession({ workspaces, sessionId: sid('s-1'), pinned: false })+ expect(seen[0]).toBe(workspaces)+ })++ it('refuses to run when the capability is absent', async () => {+ await expect(togglePinSession({ workspaces: workspacesWith({}), sessionId: sid('s-1'), pinned: false }))+ .resolves+ .toEqual({ ok: false, error: 'pinSessionUnavailable' })+ })++ it('returns the thrown message when the official call rejects', async () => {+ const workspaces = workspacesWith({+ pinSession: async () => {+ throw new Error('archive-conflict')+ },+ unpinSession: async () => undefined,+ })++ await expect(togglePinSession({ workspaces, sessionId: sid('s-1'), pinned: false }))+ .resolves+ .toEqual({ ok: false, error: 'archive-conflict' })+ })+})diff --git a/packages/dsh-tauri-rightclick/src/client/service/menu.ts b/packages/dsh-tauri-rightclick/src/client/service/menu.tsindex 391828bd..09eac619 100644--- a/packages/dsh-tauri-rightclick/src/client/service/menu.ts+++ b/packages/dsh-tauri-rightclick/src/client/service/menu.ts@@ -74,6 +74,40 @@ export async function archiveSession(input: {}}+/** Query:官方是否提供置顶会话能力(0.1.7 起);旧核心缺席时右键菜单不展示该入口。 */+export function supportsSessionPin(workspaces: WorkspacesRuntimeLike): boolean {+ return typeof workspaces.pinSession === 'function' && typeof workspaces.unpinSession === 'function'+}++/** Query:会话是否已置顶(旧核心无置顶集合时按未置顶处理)。 */+export function isSessionPinned(input: {+ workspaces: WorkspacesRuntimeLike+ sessionId: SessionId+}): boolean {+ return input.workspaces.list.getSnapshot().pinnedSessionIds?.includes(input.sessionId) ?? false+}++/** Action:置顶/取消置顶会话(官方 0.1.7 能力;能力缺席时不执行)。 */+export async function togglePinSession(input: {+ workspaces: WorkspacesRuntimeLike+ sessionId: SessionId+ pinned: boolean+}): Promise<ActionOutcome> {+ const { workspaces, sessionId, pinned } = input+ const pin = workspaces.pinSession+ const unpin = workspaces.unpinSession+ if (!pin || !unpin)+ return { ok: false, error: locale.text('pinSessionUnavailable') }+ try {+ // 以服务实例为接收者调用:官方实现依赖 this。+ await (pinned ? unpin : pin).call(workspaces, sessionId)+ return { ok: true }+ }+ catch (error) {+ return fail(error)+ }+}+/** Action:分叉会话(官方分叉不可用时的回退路径)。 */export async function forkSession(input: {sessions: SessionsRuntimeLikediff --git a/packages/dsh-tauri-rightclick/src/client/types/index.ts b/packages/dsh-tauri-rightclick/src/client/types/index.tsindex 0e75756c..48785327 100644--- a/packages/dsh-tauri-rightclick/src/client/types/index.ts+++ b/packages/dsh-tauri-rightclick/src/client/types/index.ts@@ -25,11 +25,17 @@ export type SessionsRuntimeLike = Omit<Pick<ISessions, 'list' | 'binding' | 'for}export type WorkspaceViewLike = WorkspaceView-export type WorkspaceListSnapshotLike = Pick<WorkspaceSnapshot, 'items' | 'archivedSessionIds'>+export type WorkspaceListSnapshotLike = Pick<WorkspaceSnapshot, 'items' | 'archivedSessionIds'> & {+ /** 0.1.7 起官方快照提供置顶集合;旧核心缺席即「无置顶」。 */+ pinnedSessionIds?: readonly SessionId[]+}/** 官方 workspaces 服务加上 alpha/桌面导航兼容扩展。 */export type WorkspacesRuntimeLike = Pick<IWorkspaces, 'list' | 'archiveSession' | 'delete'> & {startSession?: (workspaceId: WorkspaceId) => void+ /** 置顶/取消置顶会话:0.1.7 起官方提供;旧核心缺席时右键菜单不展示该入口。 */+ pinSession?: (sessionId: SessionId) => Promise<void>+ unpinSession?: (sessionId: SessionId) => Promise<void>}export interface ActionOutcome {