diff --git a/CHANGELOG.md b/CHANGELOG.md index ed2163f..7f78caf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -34,9 +34,16 @@ - `parseFolderEntry` 允许缺 `folders` 字段(不再连带丢掉 members),`remoteSubpath` 与 `joinSubpath` 对绝对/盘符/UNC 输入的判定统一;`joinSubpath` 额外拒绝 `C:foo`。 +### 侧栏文件夹行 +- 工作区自己的目录不再渲染成一条文件夹行。以前只要工作区挂了额外文件夹,它就会多出 + 一条以目录末段命名的行;云端工作区的路径是镜像目录,于是侧栏出现 `wmvl31c7ilkuc` + 这样的内部 id,并且工作区自身的会话被藏进这条行里,看起来像「一个项目套在它自己里面」。 +- 现在只有真正额外挂进来的文件夹才有行,工作区自己的会话直接列在标题下方;没有额外 + 文件夹时节点形状与引入文件夹功能之前完全一致。 + ### 测试与工程 - 新增 `tests/folders-cas.test.ts`、`tests/folders-persist.test.ts`、`tests/remote-paths.test.ts` - 覆盖上述回归点;`tsc -p tsconfig.json` / `tsconfig.client.json` 与 288 个 vitest 用例全部通过。 + 覆盖上述回归点;`tsc -p tsconfig.json` / `tsconfig.client.json` 与 290 个 vitest 用例全部通过。 - `tsdown.config.ts` 关闭客户端 sourcemap,`lib/client.js.map`(内嵌完整源码)已从构建产物移除; `.gitignore` 补 `*.map` / `*.tsbuildinfo` / `dist/` / `coverage/` / `tools/_tmp/`,并取消对 `docs/` 的忽略,把 `remote-ssh-integration-plan.md` 纳入版本控制。 diff --git a/lib/client.js b/lib/client.js index e044e20..4078e73 100644 --- a/lib/client.js +++ b/lib/client.js @@ -1557,18 +1557,17 @@ window.__ModuleLoader__.load({ if (bucket === void 0) byFolder.set(owner, [node]); else bucket.push(node); } - const folderNode = (path, isBase) => { - const owned = isBase ? base : byFolder.get(path) ?? []; + const folderNode = (path) => { return { path, label: labels.get(path) ?? folderLabel(path), isRoot: samePath(path, root), expanded: collapsedFolders === void 0 || !collapsedFolders.has(folderKey(workspaceId, path)), - isBase, - sessions: owned + isBase: false, + sessions: byFolder.get(path) ?? [] }; }; - const folders = [folderNode(workspacePath, true), ...extras.map((path) => folderNode(path, false))]; + const folders = extras.map((path) => folderNode(path)); const rootIndex = folders.findIndex((folder) => folder.isRoot); if (rootIndex > 0) { const [rootFolder] = folders.splice(rootIndex, 1); @@ -8068,11 +8067,20 @@ window.__ModuleLoader__.load({ onArchive: onSessionArchive }, session.id)) }); - return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(RowGroup, { + return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(RowGroup, { expanded: workspace.expanded, className: "wgTreeChildren", animate: animate && folders.length + workspace.sessions.length <= ANIMATION_ROW_CAP, - children: folders.map((folder) => { + children: [workspace.sessions.map((session) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(SessionRow, { + node: session, + currentId: current, + now, + t, + onOpen, + onRename: onSessionRename, + onFork, + onArchive: onSessionArchive + }, session.id)), folders.map((folder) => { const key = folderKey(workspace.workspaceId, folder.path); return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { role: "group", @@ -8112,7 +8120,7 @@ window.__ModuleLoader__.load({ }, session.id)) })] }, key); - }) + })] }); } /** One category section: header row + expanded workspace folders. */ @@ -8307,9 +8315,18 @@ window.__ModuleLoader__.load({ onArchive: () => {} }, session.id)) }); - return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", { + return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { role: "group", - children: folders.map((folder) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { + children: [workspace.sessions.map((session) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(SessionRow, { + node: session, + currentId: current, + now, + t, + onOpen: open, + onRename: () => {}, + onFork: () => {}, + onArchive: () => {} + }, session.id)), folders.map((folder) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { role: "group", children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(FolderRow, { node: folder, @@ -8332,7 +8349,7 @@ window.__ModuleLoader__.load({ onArchive: () => {} }, session.id)) })] - }, folderKey(workspace.workspaceId, folder.path))) + }, folderKey(workspace.workspaceId, folder.path)))] }); } /** diff --git a/lib/types/client/tree.d.ts b/lib/types/client/tree.d.ts index 91073a9..8811c00 100644 --- a/lib/types/client/tree.d.ts +++ b/lib/types/client/tree.d.ts @@ -75,8 +75,10 @@ export interface WorkspaceGroupNode { sessions: readonly SessionNode[]; /** * Folder rows, present only when the workspace carries at least one extra - * folder: root first, then stored order, base included. Absent means "this - * workspace has exactly one directory", the plain pre-folders node shape. + * folder: root first, then stored order. The base directory is never a row — + * it is the workspace row itself, and its sessions live in {@link sessions}. + * Absent means "this workspace has exactly one directory", the plain + * pre-folders node shape. */ folders?: readonly FolderNode[]; } diff --git a/src/client/GroupsBrowser.tsx b/src/client/GroupsBrowser.tsx index 290f007..b2bc7b5 100644 --- a/src/client/GroupsBrowser.tsx +++ b/src/client/GroupsBrowser.tsx @@ -2366,6 +2366,19 @@ function WorkspaceSubtree({ workspace, current, now, t, animate, onOpen, onSessi className="wgTreeChildren" animate={animate && folders.length + workspace.sessions.length <= ANIMATION_ROW_CAP} > + {workspace.sessions.map((session) => ( + + ))} {folders.map((folder) => { const key = folderKey(workspace.workspaceId, folder.path) return ( @@ -2673,6 +2686,19 @@ function SearchSubtree({ workspace, current, now, open, t }: { } return (
+ {workspace.sessions.map((session) => ( + {}} + onFork={() => {}} + onArchive={() => {}} + /> + ))} {folders.map((folder) => (
{ - const owned = isBase ? base : (byFolder.get(path) ?? []) + const folderNode = (path: string): FolderNode => { return { path, label: labels.get(path) ?? folderLabel(path), isRoot: samePath(path, root), expanded: collapsedFolders === undefined || !collapsedFolders.has(folderKey(workspaceId, path)), - isBase, + // The base directory is the workspace row itself, so every row here is an + // extra folder: a mirror id must never be dressed up as one, and none of + // them can be removed from the workspace. + isBase: false, // Every owned session is kept on the node so the row's count stays honest // while the folder is collapsed; the RowGroup does the hiding. - sessions: owned, + sessions: byFolder.get(path) ?? [], } } - const folders: FolderNode[] = [ - folderNode(workspacePath, true), - ...extras.map(path => folderNode(path, false)), - ] + const folders: FolderNode[] = extras.map(path => folderNode(path)) // Root first, then stored order: moving the root row to the front keeps the - // remaining rows (base included) in their stored order. + // remaining rows in their stored order. const rootIndex = folders.findIndex(folder => folder.isRoot) if (rootIndex > 0) { const [rootFolder] = folders.splice(rootIndex, 1) diff --git a/tests/tree.test.ts b/tests/tree.test.ts index d4ec447..50df4b2 100644 --- a/tests/tree.test.ts +++ b/tests/tree.test.ts @@ -13,6 +13,7 @@ import { describe, expect, it } from 'vitest' import type { SessionListState, SessionSummary } from '@deepseek-ai/dsh-api-session-controller/client' import type { WorkspaceView } from '@deepseek-ai/dsh-api-workspace-controller/client' import { deriveGroups, deriveSearchGroups, deriveTopLevel } from '../src/client/tree.ts' +import type { FoldersDocument } from '../src/core/folders.ts' import type { GroupsConfig, ManualGroups } from '../src/core/types.ts' const CONFIG: GroupsConfig = { @@ -215,3 +216,72 @@ describe('deriveTopLevel', () => { expect(top.map(w => w.workspaceId)).toEqual(['ws-c', 'ws-a', 'ws-b']) }) }) + +/** + * Regression: a workspace whose base directory is a remote mirror used to grow + * a folder row labelled with the mirror's leaf segment (`wmvl31c7ilkuc`) and + * then hide all of the workspace's own sessions behind it, so one cloud + * project looked like a project nested inside itself. + */ +describe('folder rows never include the base directory', () => { + const MIRROR = 'C:/Users/zcol/.dsh/remote-workspaces/wmvl31c7ilkuc' + const LOCAL = 'C:/Users/zcol/云端记忆系统' + + function sessionIn(id: string, cwd: string): SessionSummary { + return { ...session(id, `会话-${id}`), cwd } as unknown as SessionSummary + } + + function state(byId: Record): SessionListState { + return { + ids: Object.keys(byId), + byId, + current: undefined, + phase: 'ready', + subagentsByParent: {}, + } as unknown as SessionListState + } + + const workspaces = [ + workspace('ws-o', MIRROR, '插件项目', ['s-cloud']), + workspace('ws-m', LOCAL, '云端记忆系统', ['s-local']), + ] + const folders: FoldersDocument = { + version: 1, + workspaces: { + 'ws-o': { + folders: [], + members: [{ path: LOCAL, workspaceId: 'ws-m', kind: 'local' }], + }, + }, + } + const list = state({ + 's-cloud': sessionIn('s-cloud', `${MIRROR}/src`), + 's-local': sessionIn('s-local', `${LOCAL}/docs`), + }) + const noManual: ManualGroups = { categories: [], assignments: {} } + // Sessions only materialize on an expanded row, so the owner starts open. + const view = { expandedCategories: [], expandedWorkspaces: ['ws-o'] } + + it('renders only the extra folder and keeps base sessions on the workspace row', () => { + const groups = deriveGroups(list, workspaces, [], CONFIG, view, noManual, new Map(), folders) + const node = groups.flatMap(group => group.workspaces).find(w => w.workspaceId === 'ws-o') + expect(node).toBeDefined() + expect(node!.folders?.map(f => f.path)).toEqual([LOCAL]) + expect(node!.folders?.every(f => f.isBase === false)).toBe(true) + // The mirror id must never leak into a folder label. + expect(node!.folders?.map(f => f.label) ?? []).not.toContain('wmvl31c7ilkuc') + // Base-owned sessions stay on the workspace itself. + expect(node!.sessions.map(s => s.id)).toEqual(['s-cloud']) + expect(node!.folders?.[0]?.sessions.map(s => s.id)).toEqual(['s-local']) + }) + + it('keeps the pre-folders node shape when the workspace has no extras', () => { + const groups = deriveGroups(list, workspaces, [], CONFIG, view, noManual, new Map(), { + version: 1, + workspaces: {}, + }) + const node = groups.flatMap(group => group.workspaces).find(w => w.workspaceId === 'ws-o') + expect(node?.folders).toBeUndefined() + expect(node?.sessions.map(s => s.id)).toEqual(['s-cloud']) + }) +})