DeepSeek Harness Tauri 桌面版 | Only 8mb installer, zero environment setup, preset plugins, Windows / macOS / Linux.
feat(session): open archived session data directory from group title
hairyf27306744cdd0
diff --git a/packages/dsh-tauri-session/README.md b/packages/dsh-tauri-session/README.mdindex 6a603464..ca325452 100644--- a/packages/dsh-tauri-session/README.md+++ b/packages/dsh-tauri-session/README.md@@ -19,6 +19,9 @@ DeepSeek Harness 桌面端插件:管理「已归档的聊天」的设置页(`bg-module-platform` 底)。- **分组规则**:排序方式同时影响「组」与「组内聊天」(两级都排序);组按成员聚合值排序,组内按排序方式排序;无项目组统一命名为「未分组」。+- **打开目录**:分组标题带下划线并可点击,宿主按组内会话 id 解析+ `$DSH_HOME/sessions/...` 下对应的会话数据目录(同一工作区的会话共享项目目录,+ 直接打开;跨项目回退 sessions 根目录)并在系统文件管理器中打开,失败弹 toast。- **取消归档**:从宿主归档集合移除该会话后,回到其原来的工作区组(宿主归档从不修改工作区 sessionIds 记账,会话在组内保留的位置自动恢复显示);成功后弹「对话已取消归档 [查看]」toast,查看可跳转到恢复的会话。@@ -48,6 +51,7 @@ v2 起插件不再自持 `archive.json`,而是直接使用**宿主 `WorkspaceR| 方法 | 路径 | 说明 || --- | --- | --- || GET | `/archived` | 宿主归档集合 id + 每个会话的创建元数据(读 host session header) |+| POST | `/open-path` | 按组内 `sessionIds` 解析会话数据目录(`$DSH_HOME/sessions/...`)并在系统文件管理器中打开 || POST | `/archive` | 归档单个会话 || POST | `/archive-workspace` | 归档一组会话(一次调用) || POST | `/unarchive` | 取消归档(改写宿主归档集合) |diff --git a/packages/dsh-tauri-session/src/client/apis/client.test.ts b/packages/dsh-tauri-session/src/client/apis/client.test.tsnew file mode 100644index 00000000..b967df66--- /dev/null+++ b/packages/dsh-tauri-session/src/client/apis/client.test.ts@@ -0,0 +1,24 @@+import { describe, expect, it, vi } from 'vitest'+import { postOpenSessionDir } from './client'++const { postMock } = vi.hoisted(() => ({ postMock: vi.fn() }))++vi.mock('dsh-tauri/client', () => ({+ createJsonClient: vi.fn(() => ({ request: vi.fn(), post: postMock })),+ createExternalStore: vi.fn(() => ({ subscribe: vi.fn(), getSnapshot: vi.fn(), set: vi.fn() })),+}))++describe('postOpenSessionDir', () => {+ it('posts the group session ids to the session open-path route', async () => {+ postMock.mockResolvedValue({ ok: true })++ await expect(postOpenSessionDir(['s1', 's2'])).resolves.toEqual({ ok: true })+ expect(postMock).toHaveBeenCalledWith('/open-path', { sessionIds: ['s1', 's2'] })+ })++ it('propagates a route failure so the panel can toast it', async () => {+ postMock.mockRejectedValue(new Error('session-directory-not-found'))++ await expect(postOpenSessionDir(['missing'])).rejects.toThrow('session-directory-not-found')+ })+})diff --git a/packages/dsh-tauri-session/src/client/apis/client.ts b/packages/dsh-tauri-session/src/client/apis/client.tsindex a59aab16..6f8af72a 100644--- a/packages/dsh-tauri-session/src/client/apis/client.ts+++ b/packages/dsh-tauri-session/src/client/apis/client.ts@@ -28,6 +28,11 @@ export function fetchArchived(): Promise<ArchivedListPayload> {return sessionApi.request('/archived')}+/** 在系统文件管理器中打开归档分组对应的会话数据目录(宿主按 sessionIds 解析)。 */+export function postOpenSessionDir(sessionIds: readonly string[]): Promise<{ ok: boolean }> {+ return sessionApi.post('/open-path', { sessionIds })+}+/** 归档单个会话。 */export function postArchive(sessionId: string, workspaceId?: string, beforeSessionId?: string): Promise<ArchivedListPayload> {return sessionApi.post('/archive', { sessionId, ...(workspaceId ? { workspaceId } : {}), ...(beforeSessionId ? { beforeSessionId } : {}) })diff --git a/packages/dsh-tauri-session/src/client/components/archive-panel.tsx b/packages/dsh-tauri-session/src/client/components/archive-panel.tsxindex c2459add..ab949d56 100644--- a/packages/dsh-tauri-session/src/client/components/archive-panel.tsx+++ b/packages/dsh-tauri-session/src/client/components/archive-panel.tsx@@ -20,8 +20,10 @@ import type { MenuEntry } from '@deepseek-ai/dsh-client-ui-primitives'*/import type { ReactElement } from 'react'import type { ArchivePanelProps, ArchiveSort } from '../types'-import { Button, Input, Menu, Modal } from '@deepseek-ai/dsh-client-ui-primitives'+import type { ArchiveGroupRow } from '../utils/sort'+import { Button, Input, Menu, Modal, Toast } from '@deepseek-ai/dsh-client-ui-primitives'import { useCallback, useEffect, useState, useSyncExternalStore } from 'react'+import { postOpenSessionDir } from '../apis'import { SESSION_CLASSES as K } from '../constants'import { text, useLocale } from '../locales'import {@@ -50,6 +52,7 @@ export function ArchivePanel(props: ArchivePanelProps): ReactElement | null {useLocale()const [confirm, setConfirm] = useState<DeleteConfirm>(null)const [openGroupMenu, setOpenGroupMenu] = useState<string | null>(null)+ const [openPathError, setOpenPathError] = useState<string | null>(null)const sessions = useSyncExternalStore(props.sessionsRuntime.list.subscribe, props.sessionsRuntime.list.getSnapshot)const workspaces = useSyncExternalStore(props.workspacesRuntime.list.subscribe, props.workspacesRuntime.list.getSnapshot)@@ -129,6 +132,20 @@ export function ArchivePanel(props: ArchivePanelProps): ReactElement | null {}}+ /** 在系统文件管理器中打开分组对应的会话数据目录($DSH_HOME/sessions/...,宿主解析)。 */+ async function handleOpenGroupDirectory(group: ArchiveGroupRow): Promise<void> {+ const sessionIds = group.rows.map(row => row.sessionId)+ if (sessionIds.length === 0)+ return+ try {+ await postOpenSessionDir(sessionIds)+ setOpenPathError(null)+ }+ catch (error) {+ setOpenPathError(error instanceof Error ? error.message : String(error))+ }+ }+const footer = (<><Button variant="ghost" onClick={() => setConfirm(null)}>{text('cancel')}</Button>@@ -202,7 +219,15 @@ export function ArchivePanel(props: ArchivePanelProps): ReactElement | null {<section key={group.id} className={K.group}><div className={K.groupHeader}><IconFolderOpen />- <span className={K.groupTitle}>{group.title || text('ungrouped')}</span>+ <button+ type="button"+ className={K.groupTitle}+ title={text('openDirectory')}+ aria-label={`${text('openDirectory')}: ${group.title || text('ungrouped')}`}+ onClick={() => void handleOpenGroupDirectory(group)}+ >+ {group.title || text('ungrouped')}+ </button><span className={K.groupCount}>{group.rows.length}{' '}@@ -302,6 +327,16 @@ export function ArchivePanel(props: ArchivePanelProps): ReactElement | null {footer={footer}closeLabel={text('close')}/>++ {openPathError+ ? (+ <Toast+ key={openPathError}+ text={text('openFailed', { reason: openPathError })}+ onDone={() => setOpenPathError(null)}+ />+ )+ : null}</div>)}diff --git a/packages/dsh-tauri-session/src/client/locales/index.ts b/packages/dsh-tauri-session/src/client/locales/index.tsindex 8394e30f..7ab8346c 100644--- a/packages/dsh-tauri-session/src/client/locales/index.ts+++ b/packages/dsh-tauri-session/src/client/locales/index.ts@@ -50,6 +50,8 @@ const DICT_ZH = {untitled: '未命名会话',requestFailed: '请求失败 ({status})',requestTimeout: '请求超时,请检查会话插件是否已加载最新版本',+ openDirectory: '打开目录',+ openFailed: '打开目录失败: {reason}',} as const satisfies Record<LocaleKey, string>/** en 字典,与 zh 键集完全一致(locale 运行时强制双语平衡)。 */@@ -92,6 +94,8 @@ const DICT_EN: Record<LocaleKey, string> = {untitled: 'Untitled session',requestFailed: 'Request failed ({status})',requestTimeout: 'Request timed out. Check that the session plugin is up to date.',+ openDirectory: 'Open directory',+ openFailed: 'Failed to open directory: {reason}',}/** 活跃语言 id(module 级缓存,apply 时初始化并由订阅推进)。 */diff --git a/packages/dsh-tauri-session/src/client/styles/index.ts b/packages/dsh-tauri-session/src/client/styles/index.tsindex c33aa32f..9c27f858 100644--- a/packages/dsh-tauri-session/src/client/styles/index.ts+++ b/packages/dsh-tauri-session/src/client/styles/index.ts@@ -117,7 +117,18 @@ const archiveStyle = c([overflow: 'hidden',textOverflow: 'ellipsis',whiteSpace: 'nowrap',- }),+ padding: 0,+ border: 'none',+ background: 'none',+ fontFamily: 'inherit',+ textAlign: 'left',+ cursor: 'pointer',+ textDecoration: 'underline',+ textUnderlineOffset: '2px',+ textDecorationColor: 'var(--dsw-alias-label-secondary, currentColor)',+ }, [+ c('&:hover', { color: 'var(--dsw-alias-brand-primary)' }),+ ]),c(`.${K.groupCount}`, {fontSize: '13px',lineHeight: '20px',diff --git a/packages/dsh-tauri-session/src/client/types/locale.ts b/packages/dsh-tauri-session/src/client/types/locale.tsindex 4534f713..2ac47a72 100644--- a/packages/dsh-tauri-session/src/client/types/locale.ts+++ b/packages/dsh-tauri-session/src/client/types/locale.ts@@ -38,4 +38,6 @@ export type LocaleKey| 'untitled'| 'requestFailed'| 'requestTimeout'+ | 'openDirectory'+ | 'openFailed'| 'close'diff --git a/packages/dsh-tauri-session/src/host/routes/index.ts b/packages/dsh-tauri-session/src/host/routes/index.tsindex cfd2054f..040fb1c6 100644--- a/packages/dsh-tauri-session/src/host/routes/index.ts+++ b/packages/dsh-tauri-session/src/host/routes/index.ts@@ -1,13 +1,15 @@/**- * route.ts — 归档管理 HTTP 路由(/api/dsh-session/*):archived / archive /- * archive-workspace / unarchive / delete / delete-workspace / clear。+ * route.ts — 归档管理 HTTP 路由(/api/dsh-session/*):archived / open-path /+ * archive / archive-workspace / unarchive / delete / delete-workspace / clear。** 变更类路由标注 mutate: true,统一由 withConnectionAuth 做连接鉴权;- * 每个 handler 只是把 body 参数化后转交 archive.ts 的业务函数,不内联业务逻辑。+ * 每个 handler 只是把 body 参数化后转交 archive.ts / session-files.ts 的业务函数,+ * 不内联业务逻辑。open-path 不接受客户端路径,按 sessionIds 在+ * `$DSH_HOME/sessions/...` 内有界解析会话数据目录后交给系统文件管理器。*/import type { HostContext } from '../types/index.js'-import { routeHandler, withConnectionAuth } from 'dsh-tauri'+import { openDirectory, routeHandler, withConnectionAuth } from 'dsh-tauri'import { SESSION_API_PREFIX, SESSION_PLUGIN_NAME } from '../../shared/constants.js'import {archiveSession,@@ -18,6 +20,9 @@ import {permanentlyDeleteSession,unarchiveSession,} from '../service/archive.js'+import { resolveSessionGroupDirectory } from '../service/session-files.js'++const MAX_OPEN_SESSION_IDS = 500/** 构建路由列表。 */export function buildRoutes(ctx: HostContext, dshHome: string): any[] {@@ -27,6 +32,22 @@ export function buildRoutes(ctx: HostContext, dshHome: string): any[] {path: `${SESSION_API_PREFIX}/archived`,handler: routeHandler(async () => [200, buildArchivedPayload(ctx)]),},+ {+ kind: 'exact',+ path: `${SESSION_API_PREFIX}/open-path`,+ handler: routeHandler(async (body) => {+ const rawIds = Array.isArray(body?.sessionIds) ? body.sessionIds : []+ const sessionIds = rawIds.filter((id): id is string => typeof id === 'string' && id.length > 0)+ if (sessionIds.length === 0 || sessionIds.length > MAX_OPEN_SESSION_IDS)+ return [400, { ok: false, error: 'invalid-session-ids' }]+ const directory = resolveSessionGroupDirectory(dshHome, sessionIds)+ if (!directory)+ return [400, { ok: false, error: 'session-directory-not-found' }]+ if (!openDirectory(directory))+ return [400, { ok: false, error: 'not-a-directory' }]+ return [200, { ok: true }]+ }, { mutate: true }),+ },{kind: 'exact',path: `${SESSION_API_PREFIX}/archive`,diff --git a/packages/dsh-tauri-session/src/host/service/session-files.test.ts b/packages/dsh-tauri-session/src/host/service/session-files.test.tsnew file mode 100644index 00000000..e92f4f69--- /dev/null+++ b/packages/dsh-tauri-session/src/host/service/session-files.test.ts@@ -0,0 +1,67 @@+import { mkdirSync, mkdtempSync, rmSync } from 'node:fs'+import { tmpdir } from 'node:os'+import { join } from 'pathe'+import { afterEach, beforeEach, describe, expect, it } from 'vitest'+import { locateSessionDataDir, removeSessionDataDir, resolveSessionGroupDirectory } from './session-files'++let dshHome = ''++beforeEach(() => {+ dshHome = mkdtempSync(join(tmpdir(), 'dsh-session-files-'))+})++afterEach(() => {+ rmSync(dshHome, { recursive: true, force: true })+})++function makeSessionDir(group: string | undefined, marker: string): string {+ const dir = group ? join(dshHome, 'sessions', group, marker) : join(dshHome, 'sessions', marker)+ mkdirSync(dir, { recursive: true })+ return dir+}++describe('locateSessionDataDir', () => {+ it('finds a depth-2 session data directory (sessions/<group>/session-<id>)', () => {+ const dir = makeSessionDir('--project-a--', 'session-abc')+ expect(locateSessionDataDir(dshHome, 'abc')).toBe(dir)+ })++ it('finds a depth-1 session data directory (sessions/session-<id>)', () => {+ const dir = makeSessionDir(undefined, 'session-xyz')+ expect(locateSessionDataDir(dshHome, 'xyz')).toBe(dir)+ })++ it('returns undefined when no session data directory exists', () => {+ expect(locateSessionDataDir(dshHome, 'missing')).toBeUndefined()+ })+})++describe('resolveSessionGroupDirectory', () => {+ it('opens the shared project directory when all sessions live in one group', () => {+ makeSessionDir('--project-a--', 'session-abc')+ makeSessionDir('--project-a--', 'session-def')+ expect(resolveSessionGroupDirectory(dshHome, ['abc', 'def'])).toBe(join(dshHome, 'sessions', '--project-a--'))+ })++ it('falls back to the sessions root when sessions span multiple project directories', () => {+ makeSessionDir('--project-a--', 'session-abc')+ makeSessionDir('--project-b--', 'session-def')+ expect(resolveSessionGroupDirectory(dshHome, ['abc', 'def'])).toBe(join(dshHome, 'sessions'))+ })++ it('returns undefined when no session in the group has data on disk', () => {+ expect(resolveSessionGroupDirectory(dshHome, ['ghost'])).toBeUndefined()+ })+})++describe('removeSessionDataDir (regression: shared scan)', () => {+ it('removes the located depth-2 directory', () => {+ makeSessionDir('--project-a--', 'session-abc')+ expect(removeSessionDataDir(dshHome, 'abc')).toBe(true)+ expect(locateSessionDataDir(dshHome, 'abc')).toBeUndefined()+ })++ it('reports false when the session has no data directory', () => {+ expect(removeSessionDataDir(dshHome, 'ghost')).toBe(false)+ })+})diff --git a/packages/dsh-tauri-session/src/host/service/session-files.ts b/packages/dsh-tauri-session/src/host/service/session-files.tsindex 012b3618..bc03f73d 100644--- a/packages/dsh-tauri-session/src/host/service/session-files.ts+++ b/packages/dsh-tauri-session/src/host/service/session-files.ts@@ -10,7 +10,7 @@import type { HostContext, SessionLike } from '../types/index.js'import { readdirSync, rmSync } from 'node:fs'-import { join, resolve, sep } from 'pathe'+import { dirname, join, resolve, sep } from 'pathe'/** 查找会话对象(host ctx.sessions)。 */export function findSession(ctx: HostContext, sessionId: string): SessionLike | undefined {@@ -68,17 +68,55 @@ export function encodeSessionId(id: string): string {* @returns 是否实际删除了目录。*/export function removeSessionDataDir(dshHome: string, sessionId: string): boolean {+ const dir = findSessionDataDir(join(dshHome, 'sessions'), sessionId)+ if (!dir)+ return false+ rmSync(dir, { recursive: true, force: true })+ return true+}++/**+ * 只读定位一个会话的持久化数据目录(不删除)。+ * 扫描规则与 removeSessionDataDir 完全一致(有界深度 2,防 `..`/绝对路径逃逸),+ * 供「打开会话目录」解析目标路径使用。+ * @returns 会话数据目录绝对路径;未找到返回 undefined。+ */+export function locateSessionDataDir(dshHome: string, sessionId: string): string | undefined {+ return findSessionDataDir(join(dshHome, 'sessions'), sessionId)+}++/**+ * 解析「打开分组会话目录」的目标:组内各会话数据目录的公共父目录。+ * 同一工作区的会话共享 cwd → 同属一个项目目录(`$DSH_HOME/sessions/--<key>--`),+ * 直接打开它即可看到该组全部会话的数据目录;跨项目(未分组混合 cwd)时回退到+ * sessions 根目录,让用户看到全部相关项目目录。+ * @returns 待打开的目录绝对路径;组内没有任何会话目录时返回 undefined。+ */+export function resolveSessionGroupDirectory(dshHome: string, sessionIds: readonly string[]): string | undefined {const sessionsRoot = join(dshHome, 'sessions')+ const parents = new Set<string>()+ for (const sessionId of sessionIds) {+ const dir = findSessionDataDir(sessionsRoot, sessionId)+ if (dir)+ parents.add(dirname(dir))+ }+ if (parents.size === 0)+ return undefined+ if (parents.size === 1)+ return [...parents][0]+ return isDir(sessionsRoot) ? sessionsRoot : undefined+}++/** 有界扫描(深度 2)查找会话数据目录,返回首个命中(含一级/二级布局)。 */+function findSessionDataDir(sessionsRoot: string, sessionId: string): string | undefined {// DSH versions use either the raw id or the legacy `session-<id>` directory name.const encodedId = encodeSessionId(sessionId)const markers = [encodedId, `session-${sessionId}`, sessionId]// 一级:sessions/<id> or sessions/session-<id>for (const marker of markers) {const direct = join(sessionsRoot, marker)- if (isWithinSessionsRoot(sessionsRoot, direct) && isDir(direct)) {- rmSync(direct, { recursive: true, force: true })- return true- }+ if (isWithinSessionsRoot(sessionsRoot, direct) && isDir(direct))+ return direct}// 二级:sessions/<group>/session-<id>let groups: string[] = []@@ -88,16 +126,14 @@ export function removeSessionDataDir(dshHome: string, sessionId: string): boolea.map(entry => entry.name)}catch {- return false+ return undefined}for (const group of groups) {for (const marker of markers) {const nested = join(sessionsRoot, group, marker)- if (isWithinSessionsRoot(sessionsRoot, nested) && isDir(nested)) {- rmSync(nested, { recursive: true, force: true })- return true- }+ if (isWithinSessionsRoot(sessionsRoot, nested) && isDir(nested))+ return nested}}- return false+ return undefined}