fix(workspaces): 1.2.2 入口行为确认与重复提交保护 #8

Merged
newbie merged 1 commits from fix/workspace-entry-lifecycle into main 2026-11-13 09:38:39 +08:00
14 changed files with 345 additions and 103 deletions

View File

@ -1,5 +1,11 @@
# 更新日志
## 1.2.2 — 2026-11-13
- 总目录操作明确为新增独立工作区:执行前展示确认,说明不会迁移会话或移除旧入口,避免被误解为原位合并。
- 解除成员文件夹关联前明确提示对应工作区将恢复独立显示;侧栏与文件夹管理使用同一确认流程,不自动删除零可见会话的工作区或归档记录。
- 防止总目录操作重复提交;区分总目录已生成但注册工作区失败的状态,并提示重试复用已有目录。
## 1.2.1 — 2026-11-12
- Farm 创建改为幂等:同一组文件夹再次执行时复用已有 farm,不再返回 HTTP 400;文件夹不同仍明确冲突,防止误合并。

View File

@ -20,7 +20,7 @@ Upstream's `createRemoteWorkspace` matched existing records by the raw `remotePa
- **Host (build-time patch, `scripts/patch-remote-ssh.mjs`)**: registration compares light-normalized spellings first; on a miss it resolves the path once over SSH (`pwd -P` + `$HOME`) and compares canonical forms, storing the canonical spelling. Resolution failures are fail-open (creation proceeds as upstream). Behavior is covered by `npm run test:patch`; the vendored tree stays pristine, so upstream updates still drop in.
- **Client (groups)**: adding a cloud folder also refuses when an existing member is backed by the same workspace, or names the same connection + remote directory, regardless of mirror paths.
Already-duplicated projects are not merged automatically (sessions belong to their workspace); remove the duplicate member from the folder dialog once its session is no longer needed — that deletes the duplicate record with it.
Already-duplicated projects are not merged automatically (sessions belong to their workspace). Detaching a member keeps its backing workspace. Deleting the duplicate remote record requires the separate explicit “Delete workspace too” choice; review the affected entry before using it.
### Security hardening (also in the patch set)
@ -93,6 +93,10 @@ For Web, replace `desktop` with `web`. Fully restart DSH or the corresponding We
2. Use the `⋯` menu on a project or group to manage grouping, appearance, and folders.
3. Open **Folders…** on a project to attach folders or choose its default root.
**Add a linked-folder workspace** creates a separate entry after confirmation. Existing workspaces and sessions stay in place; it does not migrate sessions or remove old entries. If registration fails after the directory is created, the error identifies that directory; retrying with the same name and folders reuses its verified links.
Detaching a member folder keeps its backing workspace and sessions, so that workspace can appear independently again, even when empty. Both the sidebar and folder dialog ask for this decision. No automatic cleanup is inferred from an empty sidebar count: existing records do not reliably distinguish plugin-created members from independently registered workspaces. Remote record deletion remains a separate explicit choice; it attempts to clean up an unshared local mirror and registration, while session files and the original server directory remain.
For automatic grouping by path or name, see [workspace-groups.example.yaml](./workspace-groups.example.yaml) and configure `~/.dsh/workspace-groups.yaml`. Manual grouping works without this file.
## Uninstall

View File

@ -20,7 +20,7 @@ DeepSeek Harness 工作区分组插件。基于 [z-col/dsh-workspace-groups](htt
- **宿主侧(构建时补丁,`scripts/patch-remote-ssh.mjs`)**:注册时先比轻度规范化后的写法;对不上时走一次 SSH 把路径解析成规范形式(`pwd -P` + `$HOME`)再比对,存入的也用规范写法。解析失败不拦创建(退回上游行为)。补丁行为由 `npm run test:patch` 覆盖;vendor 树保持原样,上游更新仍可直接替换。
- **客户端(分组侧)**:添加云端文件夹时,若已有成员由同一工作区支撑、或指向同一连接 + 同一远程目录,一律拒绝,不再只看镜像路径。
已经产生的重复不会自动合并(会话归属各自的工作区);等那条成员里的会话不再需要时,在文件夹管理里移除该成员即可,它背后的重复记录会一并删除。
已经产生的重复不会自动合并(会话归属各自的工作区)。解除成员关联会保留其工作区;删除重复远程记录需要单独明确选择「连工作区一起删」,操作前请核对目标入口。
### 安全加固(同一组补丁)
@ -93,6 +93,10 @@ Web 环境将 `desktop` 改为 `web`。安装完成后,完全重启 DSH 或对
2. 在项目或分组的 `⋯` 菜单中管理分组、外观和文件夹。
3. 在项目的「文件夹…」弹窗中添加文件夹或选择默认根目录。
「新增总目录工作区」经确认后添加独立入口。旧工作区和会话仍在原处,不会迁移会话或删除旧入口。如果总目录创建成功但注册失败,提示会列出已创建的路径;保持名称和文件夹不变重试会复用经校验的链接。
解除 member 文件夹关联会保留其工作区和会话,因此该工作区可能重新独立显示,即使它是空入口。侧栏和文件夹弹窗都先让用户确认此结果。不会根据侧栏会话数自动清理:既有记录无法可靠区分插件新建的 member 和用户独立注册的工作区。删除远程记录仍是单独的明确选择,会尝试清理未共用的本地镜像与注册;聊天文件及服务器上的原目录保留。
需要按路径或名称自动分组时,可参考 [workspace-groups.example.yaml](./workspace-groups.example.yaml) 配置 `~/.dsh/workspace-groups.yaml`。不配置也不影响手动分组。
## 卸载

View File

@ -4189,9 +4189,9 @@ window.__ModuleLoader__.load({
}
/**
* Delete one remote workspace record through the SSH plugin: it removes the
* record, unregisters the native workspace behind it (that workspace's
* sessions go with it) and cleans up the mirror — the counterpart of
* {@link createRemoteFolder}, for when a member folder is removed for good.
* record and attempts to unregister its native workspace and clean up its
* local mirror unless shared by another record. Session files and the original
* remote directory remain; unregistering may hide sessions from the sidebar.
* @param recordId - remote-ssh record id stored on the member.
* @param fetchImpl - fetch implementation (tests inject one).
*/
@ -4357,11 +4357,16 @@ window.__ModuleLoader__.load({
if (picked === base) return "";
return picked.startsWith(`${base}/`) ? picked.slice(base.length + 1) : null;
}
function FoldersDialog({ workspace, entry, t, busy, canOpen, remote, ownerRemotePath, profiles, profilesError, knownWorkspaceIds, onClose, onBuildFarm, onAddFolder, onAddRemote, onAddSubpath, onSetRoot, onRemove, onOpenFolder }) {
function FoldersDialog({ workspace, entry, t, busy, canOpen, remote, ownerRemotePath, profiles, profilesError, knownWorkspaceIds, initialRemovePath, onClose, onBuildFarm, onAddFolder, onAddRemote, onAddSubpath, onSetRoot, onRemove, onOpenFolder }) {
const folders = effectiveFolders(workspace.path, entry);
const root = rootOf(workspace.path, entry);
const [addMode, setAddMode] = (0, react.useState)("local");
const [confirmRemovePath, setConfirmRemovePath] = (0, react.useState)(null);
const [confirmRemovePath, setConfirmRemovePath] = (0, react.useState)(initialRemovePath ?? null);
const [confirmFarm, setConfirmFarm] = (0, react.useState)(false);
const farmConfirmation = (0, react.useRef)(false);
(0, react.useEffect)(() => {
setConfirmRemovePath(initialRemovePath ?? null);
}, [initialRemovePath]);
const [profileId, setProfileId] = (0, react.useState)("");
const [remotePath, setRemotePath] = (0, react.useState)("");
const [browsing, setBrowsing] = (0, react.useState)(false);
@ -4538,7 +4543,7 @@ window.__ModuleLoader__.load({
className: "wgIconButton",
"aria-label": `${t("folder.remove")} ${label}`,
onClick: () => {
if (canDeleteRecord) setConfirmRemovePath(path);
if (member !== void 0) setConfirmRemovePath(path);
else onRemove(path, false);
},
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.IconTrashOutlineRegular, {})
@ -4548,41 +4553,48 @@ window.__ModuleLoader__.load({
}), confirmRemovePath === path && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
className: "wgFolderConfirm",
role: "alert",
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
className: "wgFolderConfirmText",
children: t("folder.removeRemotePrompt")
}), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
className: "wgFolderConfirmActions",
children: [
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
type: "button",
className: "wgFolderConfirmButton",
"data-tone": "danger",
onClick: () => {
setConfirmRemovePath(null);
onRemove(path, true);
},
children: t("folder.removeRemoteDelete")
}),
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
type: "button",
className: "wgFolderConfirmButton",
onClick: () => {
setConfirmRemovePath(null);
onRemove(path, false);
},
children: t("folder.removeRemoteOnly")
}),
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
type: "button",
className: "wgFolderConfirmButton",
onClick: () => {
setConfirmRemovePath(null);
},
children: t("cancel")
})
]
})]
children: [
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
className: "wgFolderConfirmText",
children: t(memberGone ? "folder.removeMissingPrompt" : "folder.removeMemberPrompt")
}),
canDeleteRecord && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
className: "wgFolderConfirmText",
children: t("folder.removeRemotePrompt")
}),
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
className: "wgFolderConfirmActions",
children: [
canDeleteRecord && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
type: "button",
className: "wgFolderConfirmButton",
"data-tone": "danger",
onClick: () => {
setConfirmRemovePath(null);
onRemove(path, true);
},
children: t("folder.removeRemoteDelete")
}),
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
type: "button",
className: "wgFolderConfirmButton",
onClick: () => {
setConfirmRemovePath(null);
onRemove(path, false);
},
children: t("folder.removeRemoteOnly")
}),
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
type: "button",
className: "wgFolderConfirmButton",
onClick: () => {
setConfirmRemovePath(null);
},
children: t("cancel")
})
]
})
]
})] }, path);
})
}),
@ -4603,7 +4615,10 @@ window.__ModuleLoader__.load({
type: "button",
className: "wgFolderPick",
disabled: busy,
onClick: onBuildFarm,
onClick: () => {
farmConfirmation.current = true;
setConfirmFarm(true);
},
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
className: "wgFolderPickPlus",
"aria-hidden": true,
@ -4613,6 +4628,37 @@ window.__ModuleLoader__.load({
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
className: "wgFolderHint",
children: t("folder.mergeHint")
}),
confirmFarm && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
className: "wgFolderConfirm",
role: "alert",
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
className: "wgFolderConfirmText",
children: t("folder.mergeConfirm")
}), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
className: "wgFolderConfirmActions",
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
type: "button",
className: "wgFolderConfirmButton",
disabled: busy,
onClick: () => {
if (!farmConfirmation.current || busy) return;
farmConfirmation.current = false;
setConfirmFarm(false);
onBuildFarm();
},
children: t("folder.mergeAction")
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
type: "button",
className: "wgFolderConfirmButton",
disabled: busy,
onClick: () => {
farmConfirmation.current = false;
setConfirmFarm(false);
},
children: t("cancel")
})]
})]
})
]
}),
@ -6687,7 +6733,9 @@ window.__ModuleLoader__.load({
const [foldersOwnerRemote, setFoldersOwnerRemote] = (0, react.useState)(null);
const foldersOwnerRequest = (0, react.useRef)("");
/** Open the folder dialog and learn the owner's remote root (cloud owners only). */
const [folderRemovalPath, setFolderRemovalPath] = (0, react.useState)(null);
const openFoldersFor = (workspaceId) => {
setFolderRemovalPath(null);
foldersOwnerRequest.current = workspaceId;
setFoldersTarget(workspaceId);
setFoldersOwnerRemote(null);
@ -6883,8 +6931,9 @@ window.__ModuleLoader__.load({
* workspace, so one session reaches all of them. The folders themselves are
* never copied, moved or deleted; the farm holds links only.
*/
const farmCreating = (0, react.useRef)(false);
const buildFarmFor = async (workspaceId) => {
if (foldersBusy) return;
if (foldersBusy || farmCreating.current) return;
const workspace = workspaces.find((item) => item.workspaceId === workspaceId);
if (workspace === void 0) return;
const folders = effectiveFolders(workspace.path, entryFor(foldersDoc, workspaceId));
@ -6892,28 +6941,41 @@ window.__ModuleLoader__.load({
notifyFolder(t("folder.emptyHint"));
return;
}
farmCreating.current = true;
setFoldersBusy(true);
try {
const farm = await buildFarm(workspace.title, folders);
await createWorkspace({ path: farm.path });
try {
await createWorkspace({ path: farm.path });
} catch (reason) {
notifyFolder(`${t("folder.mergeRegistrationFailed")} ${farm.path}: ${reason instanceof Error ? reason.message : String(reason)}`);
return;
}
notifyFolder(`${t("folder.mergeDone")} ${farm.path}`);
} catch (reason) {
notifyFolder(`${t("folder.mergeFailed")}: ${reason instanceof Error ? reason.message : String(reason)}`);
} finally {
farmCreating.current = false;
setFoldersBusy(false);
}
};
/**
* Remove one folder from a project. With `deleteRecord` set — only the
* folder dialog offers it, behind an explicit confirm — a remote member's
* backing record is deleted through the SSH plugin as well (record, native
* workspace and mirror go away, sessions included); without it the removal
* backing record is deleted through the SSH plugin as well (unshared native
* registration and local mirror cleanup is attempted; session files remain).
* Without it the removal
* is overlay-only and the workspace survives as its own project. If the
* record deletion fails, the member stays so the user can retry.
*/
const removeFolderFrom = (workspaceId, path, deleteRecord = false) => {
const removeFolderFrom = (workspaceId, path, deleteRecord = false, confirmed = false) => {
const entry = entryFor(foldersDoc, workspaceId);
const member = memberOf(entry, path);
if (member !== void 0 && !confirmed) {
openFoldersFor(workspaceId);
setFolderRemovalPath(path);
return;
}
if (deleteRecord && member?.kind === "remote" && member.recordId !== void 0 && member.recordId !== "") {
const recordId = member.recordId;
(async () => {
@ -8039,6 +8101,7 @@ window.__ModuleLoader__.load({
profiles: remoteProfiles,
profilesError: remoteProfilesError,
knownWorkspaceIds: workspaces.map((w) => w.workspaceId),
initialRemovePath: folderRemovalPath,
onAddFolder: () => {
addFolderTo(foldersTarget);
},
@ -8048,7 +8111,7 @@ window.__ModuleLoader__.load({
setFolderRoot(foldersTarget, path);
},
onRemove: (path, deleteRecord) => {
removeFolderFrom(foldersTarget, path, deleteRecord);
removeFolderFrom(foldersTarget, path, deleteRecord, true);
},
onOpenFolder: (path) => {
openFolderPath?.(path);
@ -8653,10 +8716,14 @@ window.__ModuleLoader__.load({
"folder.sectionList": "项目文件夹",
"folder.sectionAdd": "添加文件夹",
"folder.emptyHint": "还没有额外文件夹。下面挂一个目录,它的会话会独立运行,模型也能直接读到里面的文件。",
"folder.mergeTitle": "合并成一个总文件夹",
"folder.mergeAction": "生成总文件夹并添加为工作区",
"folder.mergeHint": "在旁边建一个目录,用链接把这些文件夹放进去,再注册成工作区。不复制、不移动原文件夹;之后在这个工作区里的会话可以同时读写它们。",
"folder.mergeDone": "已生成总文件夹:",
"folder.mergeTitle": "新增总目录工作区",
"folder.mergeAction": "新增总目录入口",
"folder.mergeHint": "为上方文件夹创建链接总目录,并新增一个独立工作区入口。原文件夹、旧工作区和原会话均保留;不会迁移会话或删除旧入口。",
"folder.mergeConfirm": "确认将上方列出的文件夹链接到总目录,并注册为独立工作区?旧工作区及会话仍在原处,新入口不包含旧会话。",
"folder.mergeDone": "总目录工作区已就绪;旧工作区和会话保留在原处:",
"folder.mergeRegistrationFailed": "总目录已创建,但工作区注册失败。保持名称和文件夹不变重试将复用该目录,不会迁移或删除旧工作区:",
"folder.removeMemberPrompt": "解除关联后,此文件夹的工作区和会话会保留,并可重新作为独立入口显示(即使没有会话)。不会删除目录或迁移会话。",
"folder.removeMissingPrompt": "仅移除此处的失效关联,不会重建工作区,也不会删除目录或会话。",
"folder.mergeFailed": "生成总文件夹失败",
"folder.base": "基础文件夹",
"folder.setRoot": "设为根目录",
@ -8667,9 +8734,9 @@ window.__ModuleLoader__.load({
"folder.duplicate": "该文件夹已在此工作区中",
"folder.conflict": "文件夹已被另一个窗口修改,已同步为最新状态,本次修改未保存,请重试",
"folder.removeError": "远程工作区删除失败",
"folder.removeRemotePrompt": "这个云端文件夹背后有一个工作区,移除时要连它一起删掉吗?删掉后它里面的会话也会消失。",
"folder.removeRemotePrompt": "“连工作区一起删”会删除远程记录,并尝试清理未被其他记录共用的工作区注册和本地镜像。会话可能从侧栏隐藏,聊天文件保留;不删除服务器上的原目录。",
"folder.removeRemoteDelete": "连工作区一起删",
"folder.removeRemoteOnly": "只移除文件夹",
"folder.removeRemoteOnly": "解除关联,保留工作区",
"folder.addError": "添加文件夹失败",
"folder.sessionError": "新建会话失败",
"folder.saveError": "文件夹保存失败",
@ -8848,10 +8915,14 @@ window.__ModuleLoader__.load({
"folder.sectionList": "Project folders",
"folder.sectionAdd": "Add a folder",
"folder.emptyHint": "No extra folders yet. A folder added below runs its sessions on its own, so the agent can read the files inside it directly.",
"folder.mergeTitle": "Merge into one folder",
"folder.mergeAction": "Create the merged folder as a workspace",
"folder.mergeHint": "Builds one directory that links these folders side by side and registers it as a workspace. Nothing is copied or moved; sessions in that workspace can read and write all of them.",
"folder.mergeDone": "Merged folder created: ",
"folder.mergeTitle": "Add a linked-folder workspace",
"folder.mergeAction": "Add a separate workspace entry",
"folder.mergeHint": "Links the folders above into one directory and adds a separate workspace entry. Original folders, workspaces and sessions stay in place; sessions are not migrated and old entries are not deleted.",
"folder.mergeConfirm": "Link the folders listed above into one directory and register a separate workspace? Existing workspaces and sessions stay in place. The new entry does not contain the old sessions.",
"folder.mergeDone": "Linked-folder workspace ready; existing workspaces and sessions stay in place: ",
"folder.mergeRegistrationFailed": "The linked directory was created, but workspace registration failed. Retrying with the same name and folders reuses it without migrating or deleting existing workspaces: ",
"folder.removeMemberPrompt": "Detaching keeps this folder’s workspace and sessions. It can appear as a separate entry again, even with no sessions. No directory is deleted and no sessions are migrated.",
"folder.removeMissingPrompt": "Remove only this stale association. This does not recreate the workspace or delete directories or sessions.",
"folder.mergeFailed": "Could not build the merged folder",
"folder.base": "Base folder",
"folder.setRoot": "Set as root",
@ -8862,9 +8933,9 @@ window.__ModuleLoader__.load({
"folder.duplicate": "That folder is already in this workspace",
"folder.conflict": "Folders changed in another window; synced to the latest state, this edit was not saved — please retry",
"folder.removeError": "Could not delete the remote workspace",
"folder.removeRemotePrompt": "This cloud folder is backed by its own workspace. Remove the workspace along with it? Its sessions will be deleted too.",
"folder.removeRemotePrompt": "“Delete workspace too” deletes the remote record and attempts to clean up its workspace registration and local mirror unless shared by other records. Sessions may disappear from the sidebar, but chat files remain. The original directory on the server is not deleted.",
"folder.removeRemoteDelete": "Delete workspace too",
"folder.removeRemoteOnly": "Remove folder only",
"folder.removeRemoteOnly": "Detach and keep workspace",
"folder.addError": "Could not add the folder",
"folder.sessionError": "Could not start a session",
"folder.saveError": "Could not save folders",

File diff suppressed because one or more lines are too long

View File

@ -2,7 +2,7 @@ import type { WorkspaceView } from '@deepseek-ai/dsh-api-workspace-controller/cl
import { type WorkspaceFolderEntry } from '../core/folders.ts';
import type { GroupsBrowserProps } from './contract.ts';
import { type RemoteProfileSummary } from './folder-directory.ts';
export declare function FoldersDialog({ workspace, entry, t, busy, canOpen, remote, ownerRemotePath, profiles, profilesError, knownWorkspaceIds, onClose, onBuildFarm, onAddFolder, onAddRemote, onAddSubpath, onSetRoot, onRemove, onOpenFolder }: {
export declare function FoldersDialog({ workspace, entry, t, busy, canOpen, remote, ownerRemotePath, profiles, profilesError, knownWorkspaceIds, initialRemovePath, onClose, onBuildFarm, onAddFolder, onAddRemote, onAddSubpath, onSetRoot, onRemove, onOpenFolder }: {
workspace: WorkspaceView;
entry: WorkspaceFolderEntry | undefined;
t: GroupsBrowserProps['t'];
@ -17,6 +17,8 @@ export declare function FoldersDialog({ workspace, entry, t, busy, canOpen, remo
profilesError: string | null;
/** Live workspace ids, so a member whose workspace is gone can say so. */
knownWorkspaceIds: readonly string[];
/** Sidebar removal opens this same confirmation instead of bypassing it. */
initialRemovePath?: string | null;
onClose: () => void;
/**
* Gather this project's folders into one link directory and register it as a

View File

@ -76,9 +76,9 @@ export declare function listRemoteProfiles(fetchImpl?: typeof fetch): Promise<Re
export declare function createRemoteFolder(profileId: string, remotePath: string, title?: string, fetchImpl?: typeof fetch): Promise<CreatedRemoteFolder>;
/**
* Delete one remote workspace record through the SSH plugin: it removes the
* record, unregisters the native workspace behind it (that workspace's
* sessions go with it) and cleans up the mirror — the counterpart of
* {@link createRemoteFolder}, for when a member folder is removed for good.
* record and attempts to unregister its native workspace and clean up its
* local mirror unless shared by another record. Session files and the original
* remote directory remain; unregistering may hide sessions from the sidebar.
* @param recordId - remote-ssh record id stored on the member.
* @param fetchImpl - fetch implementation (tests inject one).
*/

View File

@ -4,7 +4,7 @@
*/
import type { LocaleDictOf } from '@deepseek-ai/dsh-client-ui-slots';
/** Dictionary keys of the workspaceGroups namespace (single source of truth). */
export type WorkspaceGroupsKey = 'section.workspaces' | 'section.sessions' | 'search' | 'search.placeholder' | 'search.clear' | 'search.noMatches' | 'search.unavailable' | 'search.pending' | 'search.hasMore' | 'search.results.aria' | 'workspace.add' | 'workspace.addBusy' | 'workspace.addError' | 'workspace.addErrorTitle' | 'workspace.rename' | 'workspace.delete' | 'workspace.deleteTitle' | 'workspace.deleteConfirm' | 'workspace.deleteCancel' | 'workspace.renaming' | 'workspace.deleting' | 'workspace.renameTitle' | 'workspace.renamePlaceholder' | 'workspace.renameConfirm' | 'workspace.renameCancel' | 'workspace.moveOutOfGroup' | 'workspace.openInFolder' | 'workspace.openInFolderError' | 'folder.title' | 'folder.manage' | 'folder.listAria' | 'folder.sectionList' | 'folder.sectionAdd' | 'folder.emptyHint' | 'folder.mergeTitle' | 'folder.mergeAction' | 'folder.mergeHint' | 'folder.mergeDone' | 'folder.mergeFailed' | 'folder.base' | 'folder.setRoot' | 'folder.rootBadge' | 'folder.remove' | 'folder.add' | 'folder.done' | 'folder.duplicate' | 'folder.conflict' | 'folder.removeError' | 'folder.removeRemotePrompt' | 'folder.removeRemoteDelete' | 'folder.removeRemoteOnly' | 'folder.addError' | 'folder.sessionError' | 'folder.saveError' | 'folder.notReady' | 'folder.remoteSessionUnsupported' | 'folder.remoteHint' | 'folder.remoteNeedsSubpath' | 'folder.subpathLabel' | 'folder.subpathPlaceholder' | 'folder.addSubpath' | 'folder.subpathInvalid' | 'folder.cloudSection' | 'folder.profileLabel' | 'folder.remotePathLabel' | 'folder.remotePathPlaceholder' | 'folder.remotePathOrName' | 'folder.createAndAdd' | 'folder.cloudNoteBoth' | 'folder.addRemote' | 'folder.noProfiles' | 'folder.profilesError' | 'folder.cloudTag' | 'folder.localTag' | 'folder.memberMissing' | 'folder.memberNested' | 'folder.alreadyRoot' | 'folder.addAria' | 'folder.tabLocal' | 'folder.tabCloud' | 'folder.pickLocal' | 'folder.localNote' | 'folder.localIntoRemote' | 'folder.cloudNote' | 'folder.browse' | 'folder.browseTitle' | 'folder.browseListAria' | 'folder.browseNote' | 'folder.browseFailed' | 'folder.chooseHere' | 'folder.up' | 'folder.home' | 'folder.refresh' | 'folder.loading' | 'folder.loadingState' | 'folder.loadError' | 'folder.refreshError' | 'folder.retry' | 'folder.retryDraft' | 'folder.discardDraft' | 'folder.conflictDetail' | 'folder.emptyDir' | 'group.create' | 'group.createTitle' | 'group.createPlaceholder' | 'group.createConfirm' | 'group.createCancel' | 'group.rename' | 'group.renameTitle' | 'group.renameConfirm' | 'group.delete' | 'group.deleteTitle' | 'group.deleteConfirm' | 'group.deleteCancel' | 'group.nameDuplicate' | 'group.nameReserved' | 'group.pin' | 'group.unpin' | 'group.pinned' | 'group.appearance' | 'group.appearanceTitle' | 'group.appearanceDone' | 'group.color' | 'group.colorDefault' | 'group.icon' | 'group.iconDefault' | 'group.iconCustom' | 'group.iconInvalid' | 'group.icon.section.common' | 'group.icon.section.lab' | 'group.icon.section.materials' | 'group.icon.section.characterization' | 'group.icon.section.devices' | 'group.icon.section.emoji' | 'color.red' | 'color.orange' | 'color.amber' | 'color.green' | 'color.teal' | 'color.blue' | 'color.indigo' | 'color.purple' | 'color.pink' | 'color.gray' | 'section.topLevel' | 'section.defaultWorkspace' | 'manual.saveError' | 'manual.conflict' | 'session.new' | 'session.rename' | 'session.archive' | 'session.fork' | 'session.renameTitle' | 'session.renamePlaceholder' | 'session.renameConfirm' | 'session.renameCancel' | 'session.renaming' | 'uncategorized' | 'empty.none' | 'empty.noWorkspaces' | 'close' | 'cancel' | 'confirm' | 'retry' | 'configUnavailable' | 'collapse' | 'expandMore' | 'newSession' | 'quick.title' | 'quick.tab.workspaces' | 'quick.tab.sessions' | 'quick.search.placeholder' | 'quick.search.sessions' | 'quick.empty.workspaces' | 'quick.action.newSession' | 'quick.action.running' | 'quick.action.noneRunning' | 'quick.empty.sessions' | 'quick.select.hint' | 'quick.hint' | 'tabs.aria' | 'tabs.close' | 'tabs.archive' | 'tabs.pin' | 'tabs.unpin' | 'tabs.pinned' | 'tabs.rename' | 'tabs.renameSession' | 'tabs.renamePlaceholder' | 'tabs.closeOthers' | 'tabs.closeRight' | 'tabs.dragHint';
export type WorkspaceGroupsKey = 'section.workspaces' | 'section.sessions' | 'search' | 'search.placeholder' | 'search.clear' | 'search.noMatches' | 'search.unavailable' | 'search.pending' | 'search.hasMore' | 'search.results.aria' | 'workspace.add' | 'workspace.addBusy' | 'workspace.addError' | 'workspace.addErrorTitle' | 'workspace.rename' | 'workspace.delete' | 'workspace.deleteTitle' | 'workspace.deleteConfirm' | 'workspace.deleteCancel' | 'workspace.renaming' | 'workspace.deleting' | 'workspace.renameTitle' | 'workspace.renamePlaceholder' | 'workspace.renameConfirm' | 'workspace.renameCancel' | 'workspace.moveOutOfGroup' | 'workspace.openInFolder' | 'workspace.openInFolderError' | 'folder.title' | 'folder.manage' | 'folder.listAria' | 'folder.sectionList' | 'folder.sectionAdd' | 'folder.emptyHint' | 'folder.mergeTitle' | 'folder.mergeAction' | 'folder.mergeHint' | 'folder.mergeDone' | 'folder.mergeConfirm' | 'folder.mergeRegistrationFailed' | 'folder.removeMemberPrompt' | 'folder.removeMissingPrompt' | 'folder.mergeFailed' | 'folder.base' | 'folder.setRoot' | 'folder.rootBadge' | 'folder.remove' | 'folder.add' | 'folder.done' | 'folder.duplicate' | 'folder.conflict' | 'folder.removeError' | 'folder.removeRemotePrompt' | 'folder.removeRemoteDelete' | 'folder.removeRemoteOnly' | 'folder.addError' | 'folder.sessionError' | 'folder.saveError' | 'folder.notReady' | 'folder.remoteSessionUnsupported' | 'folder.remoteHint' | 'folder.remoteNeedsSubpath' | 'folder.subpathLabel' | 'folder.subpathPlaceholder' | 'folder.addSubpath' | 'folder.subpathInvalid' | 'folder.cloudSection' | 'folder.profileLabel' | 'folder.remotePathLabel' | 'folder.remotePathPlaceholder' | 'folder.remotePathOrName' | 'folder.createAndAdd' | 'folder.cloudNoteBoth' | 'folder.addRemote' | 'folder.noProfiles' | 'folder.profilesError' | 'folder.cloudTag' | 'folder.localTag' | 'folder.memberMissing' | 'folder.memberNested' | 'folder.alreadyRoot' | 'folder.addAria' | 'folder.tabLocal' | 'folder.tabCloud' | 'folder.pickLocal' | 'folder.localNote' | 'folder.localIntoRemote' | 'folder.cloudNote' | 'folder.browse' | 'folder.browseTitle' | 'folder.browseListAria' | 'folder.browseNote' | 'folder.browseFailed' | 'folder.chooseHere' | 'folder.up' | 'folder.home' | 'folder.refresh' | 'folder.loading' | 'folder.loadingState' | 'folder.loadError' | 'folder.refreshError' | 'folder.retry' | 'folder.retryDraft' | 'folder.discardDraft' | 'folder.conflictDetail' | 'folder.emptyDir' | 'group.create' | 'group.createTitle' | 'group.createPlaceholder' | 'group.createConfirm' | 'group.createCancel' | 'group.rename' | 'group.renameTitle' | 'group.renameConfirm' | 'group.delete' | 'group.deleteTitle' | 'group.deleteConfirm' | 'group.deleteCancel' | 'group.nameDuplicate' | 'group.nameReserved' | 'group.pin' | 'group.unpin' | 'group.pinned' | 'group.appearance' | 'group.appearanceTitle' | 'group.appearanceDone' | 'group.color' | 'group.colorDefault' | 'group.icon' | 'group.iconDefault' | 'group.iconCustom' | 'group.iconInvalid' | 'group.icon.section.common' | 'group.icon.section.lab' | 'group.icon.section.materials' | 'group.icon.section.characterization' | 'group.icon.section.devices' | 'group.icon.section.emoji' | 'color.red' | 'color.orange' | 'color.amber' | 'color.green' | 'color.teal' | 'color.blue' | 'color.indigo' | 'color.purple' | 'color.pink' | 'color.gray' | 'section.topLevel' | 'section.defaultWorkspace' | 'manual.saveError' | 'manual.conflict' | 'session.new' | 'session.rename' | 'session.archive' | 'session.fork' | 'session.renameTitle' | 'session.renamePlaceholder' | 'session.renameConfirm' | 'session.renameCancel' | 'session.renaming' | 'uncategorized' | 'empty.none' | 'empty.noWorkspaces' | 'close' | 'cancel' | 'confirm' | 'retry' | 'configUnavailable' | 'collapse' | 'expandMore' | 'newSession' | 'quick.title' | 'quick.tab.workspaces' | 'quick.tab.sessions' | 'quick.search.placeholder' | 'quick.search.sessions' | 'quick.empty.workspaces' | 'quick.action.newSession' | 'quick.action.running' | 'quick.action.noneRunning' | 'quick.empty.sessions' | 'quick.select.hint' | 'quick.hint' | 'tabs.aria' | 'tabs.close' | 'tabs.archive' | 'tabs.pin' | 'tabs.unpin' | 'tabs.pinned' | 'tabs.rename' | 'tabs.renameSession' | 'tabs.renamePlaceholder' | 'tabs.closeOthers' | 'tabs.closeRight' | 'tabs.dragHint';
export type WorkspaceGroupsDict = LocaleDictOf<'workspaceGroups'>;
/** Simplified Chinese dictionary. */
export declare const zh: WorkspaceGroupsDict;

View File

@ -1,6 +1,6 @@
{
"name": "workspace-groups-remote",
"version": "1.2.1",
"version": "1.2.2",
"description": "Merged DSH bundle: the workspace-groups sidebar manager (category -> project -> session grouped tree, session tab strip) plus dsh-remote-ssh (VSCode Remote-SSH-like remote development: remote workspaces, file access, integrated terminal) in one installable package.",
"keywords": [
"dsh",

View File

@ -13,7 +13,7 @@
* swaps to the remote tree, so no stacked overlays are needed and the current
* location stays readable at the top.
*/
import { useEffect, useState } from 'react'
import { useEffect, useRef, useState } from 'react'
import {
Button,
IconFolderOpenOutlineRegular,
@ -44,7 +44,7 @@ function subfolderOf(root: string | null, picked: string): string | null {
return picked.startsWith(`${base}/`) ? picked.slice(base.length + 1) : null
}
export function FoldersDialog({ workspace, entry, t, busy, canOpen, remote, ownerRemotePath, profiles, profilesError, knownWorkspaceIds, onClose, onBuildFarm, onAddFolder, onAddRemote, onAddSubpath, onSetRoot, onRemove, onOpenFolder }: {
export function FoldersDialog({ workspace, entry, t, busy, canOpen, remote, ownerRemotePath, profiles, profilesError, knownWorkspaceIds, initialRemovePath, onClose, onBuildFarm, onAddFolder, onAddRemote, onAddSubpath, onSetRoot, onRemove, onOpenFolder }: {
workspace: WorkspaceView
entry: WorkspaceFolderEntry | undefined
t: GroupsBrowserProps['t']
@ -59,6 +59,8 @@ export function FoldersDialog({ workspace, entry, t, busy, canOpen, remote, owne
profilesError: string | null
/** Live workspace ids, so a member whose workspace is gone can say so. */
knownWorkspaceIds: readonly string[]
/** Sidebar removal opens this same confirmation instead of bypassing it. */
initialRemovePath?: string | null
onClose: () => void
/**
* Gather this project's folders into one link directory and register it as a
@ -77,8 +79,11 @@ export function FoldersDialog({ workspace, entry, t, busy, canOpen, remote, owne
const folders = effectiveFolders(workspace.path, entry)
const root = rootOf(workspace.path, entry)
const [addMode, setAddMode] = useState<AddMode>('local')
// Path of the remote member whose removal awaits the delete-record choice.
const [confirmRemovePath, setConfirmRemovePath] = useState<string | null>(null)
// All members keep their workspace when detached, including local members.
const [confirmRemovePath, setConfirmRemovePath] = useState<string | null>(initialRemovePath ?? null)
const [confirmFarm, setConfirmFarm] = useState(false)
const farmConfirmation = useRef(false)
useEffect(() => { setConfirmRemovePath(initialRemovePath ?? null) }, [initialRemovePath])
const [profileId, setProfileId] = useState('')
const [remotePath, setRemotePath] = useState('')
const [browsing, setBrowsing] = useState(false)
@ -232,9 +237,8 @@ export function FoldersDialog({ workspace, entry, t, busy, canOpen, remote, owne
className="wgIconButton"
aria-label={`${t('folder.remove')} ${label}`}
onClick={() => {
// A remote member can take its backing workspace
// with it; ask which removal the user means first.
if (canDeleteRecord) setConfirmRemovePath(path)
// Detaching exposes the backing workspace as its own row.
if (member !== undefined) setConfirmRemovePath(path)
else onRemove(path, false)
}}
>
@ -245,16 +249,17 @@ export function FoldersDialog({ workspace, entry, t, busy, canOpen, remote, owne
</div>
{confirmRemovePath === path && (
<div className="wgFolderConfirm" role="alert">
<span className="wgFolderConfirmText">{t('folder.removeRemotePrompt')}</span>
<span className="wgFolderConfirmText">{t(memberGone ? 'folder.removeMissingPrompt' : 'folder.removeMemberPrompt')}</span>
{canDeleteRecord && <span className="wgFolderConfirmText">{t('folder.removeRemotePrompt')}</span>}
<span className="wgFolderConfirmActions">
<button
{canDeleteRecord && <button
type="button"
className="wgFolderConfirmButton"
data-tone="danger"
onClick={() => { setConfirmRemovePath(null); onRemove(path, true) }}
>
{t('folder.removeRemoteDelete')}
</button>
</button>}
<button
type="button"
className="wgFolderConfirmButton"
@ -285,11 +290,29 @@ export function FoldersDialog({ workspace, entry, t, busy, canOpen, remote, owne
{/* A session's file scope is its workspace directory, so folders in
different places are unreachable from one session. A farm puts
them side by side as links; nothing is copied or moved. */}
<button type="button" className="wgFolderPick" disabled={busy} onClick={onBuildFarm}>
<button type="button" className="wgFolderPick" disabled={busy} onClick={() => { farmConfirmation.current = true; setConfirmFarm(true) }}>
<span className="wgFolderPickPlus" aria-hidden>⇄</span>
<span>{t('folder.mergeAction')}</span>
</button>
<p className="wgFolderHint">{t('folder.mergeHint')}</p>
{confirmFarm && (
<div className="wgFolderConfirm" role="alert">
<span className="wgFolderConfirmText">{t('folder.mergeConfirm')}</span>
<span className="wgFolderConfirmActions">
<button type="button" className="wgFolderConfirmButton" disabled={busy}
onClick={() => {
if (!farmConfirmation.current || busy) return
farmConfirmation.current = false
setConfirmFarm(false)
onBuildFarm()
}}>
{t('folder.mergeAction')}
</button>
<button type="button" className="wgFolderConfirmButton" disabled={busy}
onClick={() => { farmConfirmation.current = false; setConfirmFarm(false) }}>{t('cancel')}</button>
</span>
</div>
)}
</section>
)}

View File

@ -932,7 +932,9 @@ export function GroupsBrowser({
const foldersOwnerRequest = useRef('')
/** Open the folder dialog and learn the owner's remote root (cloud owners only). */
const [folderRemovalPath, setFolderRemovalPath] = useState<string | null>(null)
const openFoldersFor = (workspaceId: string): void => {
setFolderRemovalPath(null)
foldersOwnerRequest.current = workspaceId
setFoldersTarget(workspaceId as WorkspaceId)
setFoldersOwnerRemote(null)
@ -1153,8 +1155,9 @@ export function GroupsBrowser({
* workspace, so one session reaches all of them. The folders themselves are
* never copied, moved or deleted; the farm holds links only.
*/
const farmCreating = useRef(false)
const buildFarmFor = async (workspaceId: WorkspaceId): Promise<void> => {
if (foldersBusy) return
if (foldersBusy || farmCreating.current) return
const workspace = workspaces.find(item => item.workspaceId === workspaceId)
if (workspace === undefined) return
const folders = effectiveFolders(workspace.path, entryFor(foldersDoc, workspaceId as string))
@ -1162,16 +1165,22 @@ export function GroupsBrowser({
notifyFolder(t('folder.emptyHint'))
return
}
farmCreating.current = true
setFoldersBusy(true)
try {
const farm = await buildFarm(workspace.title, folders)
// Registering the farm is a separate step: a created directory without a
// workspace is harmless, and the error still names what already exists.
await createWorkspace({ path: farm.path })
try {
await createWorkspace({ path: farm.path })
} catch (reason) {
// Keep the verified links: the host reuses the same farm on retry.
notifyFolder(`${t('folder.mergeRegistrationFailed')} ${farm.path}: ${reason instanceof Error ? reason.message : String(reason)}`)
return
}
notifyFolder(`${t('folder.mergeDone')} ${farm.path}`)
} catch (reason) {
notifyFolder(`${t('folder.mergeFailed')}: ${reason instanceof Error ? reason.message : String(reason)}`)
} finally {
farmCreating.current = false
setFoldersBusy(false)
}
}
@ -1179,14 +1188,20 @@ export function GroupsBrowser({
/**
* Remove one folder from a project. With `deleteRecord` set — only the
* folder dialog offers it, behind an explicit confirm — a remote member's
* backing record is deleted through the SSH plugin as well (record, native
* workspace and mirror go away, sessions included); without it the removal
* backing record is deleted through the SSH plugin as well (unshared native
* registration and local mirror cleanup is attempted; session files remain).
* Without it the removal
* is overlay-only and the workspace survives as its own project. If the
* record deletion fails, the member stays so the user can retry.
*/
const removeFolderFrom = (workspaceId: WorkspaceId, path: string, deleteRecord = false): void => {
const removeFolderFrom = (workspaceId: WorkspaceId, path: string, deleteRecord = false, confirmed = false): void => {
const entry = entryFor(foldersDoc, workspaceId as string)
const member = memberOf(entry, path)
if (member !== undefined && !confirmed) {
openFoldersFor(workspaceId as string)
setFolderRemovalPath(path)
return
}
if (deleteRecord && member?.kind === 'remote' && member.recordId !== undefined && member.recordId !== '') {
const recordId = member.recordId
void (async () => {
@ -2290,11 +2305,12 @@ export function GroupsBrowser({
profiles={remoteProfiles}
profilesError={remoteProfilesError}
knownWorkspaceIds={workspaces.map(w => w.workspaceId as string)}
initialRemovePath={folderRemovalPath}
onAddFolder={() => { void addFolderTo(foldersTarget) }}
onAddRemote={(profileId, remotePath) => addRemoteFolderTo(foldersTarget, profileId, remotePath)}
onAddSubpath={(relative) => addSubpathTo(foldersTarget, relative)}
onSetRoot={(path) => { setFolderRoot(foldersTarget, path) }}
onRemove={(path, deleteRecord) => { removeFolderFrom(foldersTarget, path, deleteRecord) }}
onRemove={(path, deleteRecord) => { removeFolderFrom(foldersTarget, path, deleteRecord, true) }}
onOpenFolder={(path) => { openFolderPath?.(path) }}
onClose={() => { foldersOwnerRequest.current = ''; setFoldersTarget(null) }}
/>

View File

@ -241,9 +241,9 @@ export async function createRemoteFolder(
/**
* Delete one remote workspace record through the SSH plugin: it removes the
* record, unregisters the native workspace behind it (that workspace's
* sessions go with it) and cleans up the mirror — the counterpart of
* {@link createRemoteFolder}, for when a member folder is removed for good.
* record and attempts to unregister its native workspace and clean up its
* local mirror unless shared by another record. Session files and the original
* remote directory remain; unregistering may hide sessions from the sidebar.
* @param recordId - remote-ssh record id stored on the member.
* @param fetchImpl - fetch implementation (tests inject one).
*/

View File

@ -45,6 +45,10 @@ export type WorkspaceGroupsKey =
| 'folder.mergeAction'
| 'folder.mergeHint'
| 'folder.mergeDone'
| 'folder.mergeConfirm'
| 'folder.mergeRegistrationFailed'
| 'folder.removeMemberPrompt'
| 'folder.removeMissingPrompt'
| 'folder.mergeFailed'
| 'folder.base'
| 'folder.setRoot'
@ -238,10 +242,14 @@ export const zh: WorkspaceGroupsDict = {
'folder.sectionList': '项目文件夹',
'folder.sectionAdd': '添加文件夹',
'folder.emptyHint': '还没有额外文件夹。下面挂一个目录,它的会话会独立运行,模型也能直接读到里面的文件。',
'folder.mergeTitle': '合并成一个总文件夹',
'folder.mergeAction': '生成总文件夹并添加为工作区',
'folder.mergeHint': '在旁边建一个目录,用链接把这些文件夹放进去,再注册成工作区。不复制、不移动原文件夹;之后在这个工作区里的会话可以同时读写它们。',
'folder.mergeDone': '已生成总文件夹:',
'folder.mergeTitle': '新增总目录工作区',
'folder.mergeAction': '新增总目录入口',
'folder.mergeHint': '为上方文件夹创建链接总目录,并新增一个独立工作区入口。原文件夹、旧工作区和原会话均保留;不会迁移会话或删除旧入口。',
'folder.mergeConfirm': '确认将上方列出的文件夹链接到总目录,并注册为独立工作区?旧工作区及会话仍在原处,新入口不包含旧会话。',
'folder.mergeDone': '总目录工作区已就绪;旧工作区和会话保留在原处:',
'folder.mergeRegistrationFailed': '总目录已创建,但工作区注册失败。保持名称和文件夹不变重试将复用该目录,不会迁移或删除旧工作区:',
'folder.removeMemberPrompt': '解除关联后,此文件夹的工作区和会话会保留,并可重新作为独立入口显示(即使没有会话)。不会删除目录或迁移会话。',
'folder.removeMissingPrompt': '仅移除此处的失效关联,不会重建工作区,也不会删除目录或会话。',
'folder.mergeFailed': '生成总文件夹失败',
'folder.base': '基础文件夹',
'folder.setRoot': '设为根目录',
@ -252,9 +260,9 @@ export const zh: WorkspaceGroupsDict = {
'folder.duplicate': '该文件夹已在此工作区中',
'folder.conflict': '文件夹已被另一个窗口修改,已同步为最新状态,本次修改未保存,请重试',
'folder.removeError': '远程工作区删除失败',
'folder.removeRemotePrompt': '这个云端文件夹背后有一个工作区,移除时要连它一起删掉吗?删掉后它里面的会话也会消失。',
'folder.removeRemotePrompt': '“连工作区一起删”会删除远程记录,并尝试清理未被其他记录共用的工作区注册和本地镜像。会话可能从侧栏隐藏,聊天文件保留;不删除服务器上的原目录。',
'folder.removeRemoteDelete': '连工作区一起删',
'folder.removeRemoteOnly': '只移除文件夹',
'folder.removeRemoteOnly': '解除关联,保留工作区',
'folder.addError': '添加文件夹失败',
'folder.sessionError': '新建会话失败',
'folder.saveError': '文件夹保存失败',
@ -434,10 +442,14 @@ export const en: WorkspaceGroupsDict = {
'folder.sectionList': 'Project folders',
'folder.sectionAdd': 'Add a folder',
'folder.emptyHint': 'No extra folders yet. A folder added below runs its sessions on its own, so the agent can read the files inside it directly.',
'folder.mergeTitle': 'Merge into one folder',
'folder.mergeAction': 'Create the merged folder as a workspace',
'folder.mergeHint': 'Builds one directory that links these folders side by side and registers it as a workspace. Nothing is copied or moved; sessions in that workspace can read and write all of them.',
'folder.mergeDone': 'Merged folder created: ',
'folder.mergeTitle': 'Add a linked-folder workspace',
'folder.mergeAction': 'Add a separate workspace entry',
'folder.mergeHint': 'Links the folders above into one directory and adds a separate workspace entry. Original folders, workspaces and sessions stay in place; sessions are not migrated and old entries are not deleted.',
'folder.mergeConfirm': 'Link the folders listed above into one directory and register a separate workspace? Existing workspaces and sessions stay in place. The new entry does not contain the old sessions.',
'folder.mergeDone': 'Linked-folder workspace ready; existing workspaces and sessions stay in place: ',
'folder.mergeRegistrationFailed': 'The linked directory was created, but workspace registration failed. Retrying with the same name and folders reuses it without migrating or deleting existing workspaces: ',
'folder.removeMemberPrompt': 'Detaching keeps this folder’s workspace and sessions. It can appear as a separate entry again, even with no sessions. No directory is deleted and no sessions are migrated.',
'folder.removeMissingPrompt': 'Remove only this stale association. This does not recreate the workspace or delete directories or sessions.',
'folder.mergeFailed': 'Could not build the merged folder',
'folder.base': 'Base folder',
'folder.setRoot': 'Set as root',
@ -448,9 +460,9 @@ export const en: WorkspaceGroupsDict = {
'folder.duplicate': 'That folder is already in this workspace',
'folder.conflict': 'Folders changed in another window; synced to the latest state, this edit was not saved — please retry',
'folder.removeError': 'Could not delete the remote workspace',
'folder.removeRemotePrompt': 'This cloud folder is backed by its own workspace. Remove the workspace along with it? Its sessions will be deleted too.',
'folder.removeRemotePrompt': '“Delete workspace too” deletes the remote record and attempts to clean up its workspace registration and local mirror unless shared by other records. Sessions may disappear from the sidebar, but chat files remain. The original directory on the server is not deleted.',
'folder.removeRemoteDelete': 'Delete workspace too',
'folder.removeRemoteOnly': 'Remove folder only',
'folder.removeRemoteOnly': 'Detach and keep workspace',
'folder.addError': 'Could not add the folder',
'folder.sessionError': 'Could not start a session',
'folder.saveError': 'Could not save folders',

View File

@ -0,0 +1,104 @@
// @vitest-environment jsdom
import React, { act } from 'react'
import { createRoot, type Root } from 'react-dom/client'
import { afterEach, describe, expect, it, vi } from 'vitest'
import type { ComponentProps, ReactNode } from 'react'
import { FoldersDialog } from '../src/client/FoldersDialog.tsx'
import { zh } from '../src/client/locales.ts'
vi.mock('@deepseek-ai/dsh-client-ui-primitives', () => ({
Button: ({ children, variant: _variant, ...props }: any) => React.createElement('button', props, children),
Modal: ({ children, footer }: { children: ReactNode; footer: ReactNode }) => React.createElement('div', null, children, footer),
IconFolderOpenOutlineRegular: () => null,
IconTrashOutlineRegular: () => null,
}))
Object.assign(globalThis, { React, IS_REACT_ACT_ENVIRONMENT: true })
let root: Root | undefined
let container: HTMLDivElement
const memberPath = 'C:\\other'
function mount(overrides: Partial<ComponentProps<typeof FoldersDialog>> = {}) {
container = document.createElement('div')
document.body.append(container)
root = createRoot(container)
const props = {
workspace: { workspaceId: 'owner', title: 'Owner', path: 'C:\\owner' },
entry: { folders: [], members: [{ path: memberPath, workspaceId: 'member', kind: 'local' }] },
t: (key: keyof typeof zh) => zh[key], busy: false, canOpen: false, remote: false,
ownerRemotePath: null, profiles: null, profilesError: null, knownWorkspaceIds: ['owner', 'member'],
onClose: vi.fn(), onBuildFarm: vi.fn(), onAddFolder: vi.fn(), onAddRemote: vi.fn(),
onAddSubpath: vi.fn(), onSetRoot: vi.fn(), onRemove: vi.fn(), onOpenFolder: vi.fn(),
...overrides,
} as unknown as ComponentProps<typeof FoldersDialog>
act(() => { root!.render(React.createElement(FoldersDialog, props)) })
return props
}
function button(text: string, parent: ParentNode = container): HTMLButtonElement {
const found = [...parent.querySelectorAll('button')].find(b => b.textContent?.endsWith(text))
expect(found, text).toBeDefined()
return found!
}
function click(element: HTMLElement) { act(() => { element.click() }) }
function removeButton() { return container.querySelector<HTMLButtonElement>('button[aria-label^="从工作区移除"]')! }
afterEach(() => { act(() => { root?.unmount() }); container?.remove(); root = undefined })
describe('folder lifecycle decisions', () => {
it('farm preview and cancel perform no creation or removal', () => {
const props = mount()
click(button(zh['folder.mergeAction']))
expect(container.textContent).toContain(zh['folder.mergeConfirm'])
expect(container.textContent).toContain(memberPath)
expect(props.onBuildFarm).not.toHaveBeenCalled()
click(button(zh.cancel, container.querySelector('[role="alert"]')!))
expect(props.onBuildFarm).not.toHaveBeenCalled()
expect(props.onRemove).not.toHaveBeenCalled()
expect(container.querySelector('[role="alert"]')).toBeNull()
})
it('double confirmation in the same render creates only once', () => {
const props = mount()
click(button(zh['folder.mergeAction']))
const confirm = button(zh['folder.mergeAction'], container.querySelector('[role="alert"]')!)
act(() => { confirm.click(); confirm.click() })
expect(props.onBuildFarm).toHaveBeenCalledTimes(1)
expect(props.onRemove).not.toHaveBeenCalled()
})
it('local member cancellation keeps the association, confirmation only detaches', () => {
const props = mount()
click(removeButton())
expect(container.textContent).toContain(zh['folder.removeMemberPrompt'])
expect(container.textContent).not.toContain(zh['folder.removeRemoteDelete'])
click(button(zh.cancel))
expect(props.onRemove).not.toHaveBeenCalled()
click(removeButton())
click(button(zh['folder.removeRemoteOnly']))
expect(props.onRemove).toHaveBeenCalledExactlyOnceWith(memberPath, false)
})
it('sidebar initial removal uses the same confirmation and preserves remote workspace by default', () => {
const props = mount({ initialRemovePath: memberPath, entry: { folders: [], members: [{
path: memberPath, workspaceId: 'member', kind: 'remote', remotePath: '/srv/project',
profileId: 'ssh', recordId: 'record',
}] } })
expect(container.textContent).toContain(zh['folder.removeMemberPrompt'])
expect(container.textContent).toContain(zh['folder.removeRemotePrompt'])
expect(props.onRemove).not.toHaveBeenCalled()
click(button(zh['folder.removeRemoteOnly']))
expect(props.onRemove).toHaveBeenCalledExactlyOnceWith(memberPath, false)
})
it('missing member does not promise a recreated independent entry', () => {
const props = mount({ initialRemovePath: memberPath, knownWorkspaceIds: ['owner'] })
expect(container.textContent).toContain(zh['folder.removeMissingPrompt'])
expect(container.textContent).not.toContain(zh['folder.removeMemberPrompt'])
click(button(zh['folder.removeRemoteOnly']))
expect(props.onRemove).toHaveBeenCalledExactlyOnceWith(memberPath, false)
})
it('plain subfolder removal needs no workspace decision', () => {
const props = mount({ entry: { folders: ['C:\\owner\\child'] } })
click(removeButton())
expect(props.onRemove).toHaveBeenCalledExactlyOnceWith('C:\\owner\\child', false)
})
})