Skip to content

A local-first multi-agent app development platform, built on PenguinHarness

feat(web): 侧边栏的工作区分组人人可移除(只动列表,可恢复)

lmliheng575106bc32b1
diff --git a/changelog/unreleased/2026-10-06-sidebar-remove-workspace.md b/changelog/unreleased/2026-10-06-sidebar-remove-workspace.md
new file mode 100644
index 00000000..623e52b9
--- /dev/null
+++ b/changelog/unreleased/2026-10-06-sidebar-remove-workspace.md
@@ -0,0 +1,31 @@
+# Web: every Workspace group can be taken off the sidebar, and nothing is deleted
+
+- **Date:** 2026-10-06
+- **Type:** feature
+- **Scope:** `web`
+
+[中文版](2026-10-06-sidebar-remove-workspace.zh.md)
+
+A Workspace group's ⋯ menu offered 删除工作区 only for a Workspace the user had added by hand. For a
+group the server derives from Sessions — which is most of them — the click wrote the registry entry
+and the group stayed exactly where it was, because the merge only ever drops an empty registry
+entry: the Workspaces a user was done with kept piling up in the sidebar with no way to take them
+off it.
+
+The removal now works for every Workspace group. It hides the group — and the chat rows inside it,
+which were the reason the group was still there — from the sidebar alone: the directory on disk and
+every Session in it are untouched, the confirmation says so, and picking the same folder again under
+新建工作区 puts the group back. A chat created in that directory after the removal brings it back on
+its own, so a live conversation can never end up invisible.
+
+## Web
+
+- `lib/workspace-registry.ts`: a registry entry gained `hiddenAt` (the instant of the removal), and
+ `dropHiddenWorkspaces` reads it — the group goes while every chat in it predates that instant, and
+ comes back the moment one was created after it. `unregisterWorkspace` became `hideWorkspace`;
+ registering a hidden pair clears the stamp and keeps its alias.
+- `components/layout/sidebar.tsx`: 删除工作区 is offered by every Workspace group that is one
+ directory (the merged temporary group has no path to act on), not only the registry-backed ones;
+ the confirmation copy states the scope — the list only, nothing deleted, restorable.
+- `test/workspace-registry.test.ts` (31 tests) covers the stamp and its way back, per machine, the
+ hidden-but-revived rule, and the stamp that cannot be read.
diff --git a/changelog/unreleased/2026-10-06-sidebar-remove-workspace.zh.md b/changelog/unreleased/2026-10-06-sidebar-remove-workspace.zh.md
new file mode 100644
index 00000000..f5a413ea
--- /dev/null
+++ b/changelog/unreleased/2026-10-06-sidebar-remove-workspace.zh.md
@@ -0,0 +1,27 @@
+# Web:侧边栏里每个工作区分组都能移除,且不删任何东西
+
+- **Date:** 2026-10-06
+- **Type:** feature
+- **Scope:** `web`
+
+[English](2026-10-06-sidebar-remove-workspace.md)
+
+工作区分组的 ⋯ 菜单里,「删除工作区」原先只在**手动添加过**的工作区上出现。至于服务端按会话路径
+归出来的分组(也就是绝大多数),点下去只是写了一条登记、分组照样留在原地 —— 合并时只会丢掉空的那条
+登记:于是用不上的工作区一直堆在侧边栏里,没有办法把它们拿掉。
+
+现在每个工作区分组都能移除。它只把分组 —— 连同里面的会话行(正是分组还在的原因)—— 从侧边栏的列表里
+收起来:磁盘目录和其中的会话一个都不动,确认框里照实写清;用头部的「新建工作区」再选一次同一个目录,
+分组就回来了。移除之后在那个目录里新建的对话,也会自己把分组带回来,所以活着的对话不可能凭空隐形。
+
+## Web
+
+- `lib/workspace-registry.ts`:登记条目新增 `hiddenAt`(移除发生的时刻),由
+ `dropHiddenWorkspaces` 读它 —— 组内每一段对话都早于这个时刻,分组就不在列表里;只要有一段是之后
+ 建的,分组就回来。`unregisterWorkspace` 改成 `hideWorkspace`;再次登记被隐藏的目录会清掉这个标记,
+ 别名保留。
+- `components/layout/sidebar.tsx`:「删除工作区」对每个**单个目录**的工作区分组都提供(合并出来的
+ 临时工作区组没有可作用的路径),不再只限登记过的分组;确认文案写明范围 —— 只动列表、不删东西、
+ 可恢复。
+- `test/workspace-registry.test.ts`(31 个用例)覆盖标记与回来的路、按机器区分、被隐藏又被新对话唤醒
+ 的规则,以及读不出来的标记。
diff --git a/packages/web/src/components/layout/sidebar.tsx b/packages/web/src/components/layout/sidebar.tsx
index 868dc6c8..d7687629 100644
--- a/packages/web/src/components/layout/sidebar.tsx
+++ b/packages/web/src/components/layout/sidebar.tsx
@@ -151,12 +151,13 @@ import {
togglePinnedSession,
} from "../../lib/pinned-sessions";
import {
+ dropHiddenWorkspaces,
+ hideWorkspace,
loadWorkspaceRegistry,
mergeRegisteredWorkspaces,
registerWorkspace,
saveWorkspaceRegistry,
setWorkspaceAlias,
- unregisterWorkspace,
} from "../../lib/workspace-registry";
import type { WorkspaceEntry } from "../../lib/workspace-registry";
import {
@@ -734,19 +735,25 @@ export function Sidebar({
* Workspace the server's counts know (empty until their rows page in — the initial load
* is each Agent's ten newest conversations, which touch only a few of dozens of
* Workspaces), by recency with the temp group last, plus the manually-added Workspaces
- * as empty groups behind them (newest registration first).
+ * as empty groups behind them (newest registration first) — and minus the ones the user
+ * removed from the sidebar (删除工作区), which takes a group with Sessions with it and
+ * gives it back the moment a chat is created there again (dropHiddenWorkspaces).
*/
const workspaceGroups = useMemo(
() =>
- mergeRegisteredWorkspaces(
- completeWorkspaceGroups(
- // A Workspace is a directory on a machine: rows from two machines that share a path
- // string are two groups, and the "+" of each opens a chat on its own machine.
- groupSessionsByWorkspace(sessions, (s) => machineForSession(s.sessionId)),
- workspaceGroupCounts,
- workspaceGroupLatest,
+ dropHiddenWorkspaces(
+ mergeRegisteredWorkspaces(
+ completeWorkspaceGroups(
+ // A Workspace is a directory on a machine: rows from two machines that share a path
+ // string are two groups, and the "+" of each opens a chat on its own machine.
+ groupSessionsByWorkspace(sessions, (s) => machineForSession(s.sessionId)),
+ workspaceGroupCounts,
+ workspaceGroupLatest,
+ ),
+ registeredWorkspaces,
),
registeredWorkspaces,
+ (s) => s.createdAt,
),
[sessions, workspaceGroupCounts, workspaceGroupLatest, registeredWorkspaces],
);
@@ -1439,17 +1446,20 @@ export function Sidebar({
/**
* 删除工作区 (confirmed via the shared ConfirmModal, like every destructive-looking
- * action): drops the sidebar registry entry only — disk and Sessions are never
- * touched, the confirm copy says exactly that, and re-adding restores it. A group
- * that still has Sessions simply persists as session-derived.
+ * action): stamps the sidebar registry entry so the group leaves the list — disk and
+ * Sessions are never touched, the confirm copy says exactly that, and picking the
+ * directory again in 新建工作区 brings it back. The stamp works on a group the server
+ * derives from Sessions too (dropHiddenWorkspaces), which is the case that used to
+ * survive the removal; a chat created in the directory after the removal re-reveals it.
*/
const confirmDeleteWorkspace = () => {
if (!deletingWorkspace) return;
applyRegistryChange(
- unregisterWorkspace(
+ hideWorkspace(
registeredWorkspaces,
deletingWorkspace.path,
deletingWorkspace.machineId,
+ new Date().toISOString(),
),
);
setDeletingWorkspace(null);
@@ -2697,24 +2707,25 @@ export function Sidebar({
<Icon d={ICONS.plus} size={ICON_SIZE.groupHeaderAction} />
</button>
{/* A group that is one directory (not the merged temporary group):
- the overflow right of the "+" — browse its files, and, for a
- manually-added (registry-backed) Workspace, rename the alias or
- remove it from the sidebar (session-derived groups have no
- registry entry for those two to act on). */}
+ the overflow right of the "+" — browse its files, remove the
+ group from the sidebar (every Workspace has that, session-derived
+ ones included: the removal hides the group, it does not delete
+ anything), and, for a manually-added (registry-backed) Workspace,
+ rename the alias — an alias lives in the registry entry, which a
+ session-derived group has none of. */}
{fullPath !== null && (
<GroupOverflowMenu
onBrowse={() => browseFiles(fullPath, group.machineId)}
{...(registeredKeys.has(group.key)
- ? {
- onRename: () => openRenameWorkspace(fullPath, group.machineId),
- onDelete: () =>
- setDeletingWorkspace({
- path: fullPath,
- machineId: group.machineId,
- label: group.label,
- }),
- }
+ ? { onRename: () => openRenameWorkspace(fullPath, group.machineId) }
: {})}
+ onDelete={() =>
+ setDeletingWorkspace({
+ path: fullPath,
+ machineId: group.machineId,
+ label: group.label,
+ })
+ }
/>
)}
</>
diff --git a/packages/web/src/lib/strings-en.ts b/packages/web/src/lib/strings-en.ts
index 05a111be..52af8c72 100644
--- a/packages/web/src/lib/strings-en.ts
+++ b/packages/web/src/lib/strings-en.ts
@@ -2634,7 +2634,7 @@ export const en: Strings = {
sortManual: "Manual order",
sortRecent: "Most recent",
newWorkspaceEntity: "New workspace",
- /** A Workspace group's overflow (… right of the header "+"): browse its files; a registry-backed group adds alias rename + sidebar-only removal. */
+ /** A Workspace group's overflow (… right of the header "+"): browse its files and remove the group from the sidebar (every Workspace); a registry-backed group also renames its alias. */
workspaceMenu: "Workspace options",
renameWorkspace: "Rename workspace",
renameWorkspaceLabel: "Name",
@@ -2643,7 +2643,7 @@ export const en: Strings = {
/** A Workspace group's "more" menu: the dock's Files panel on that directory. */
browseWorkspaceFiles: "Browse files",
deleteWorkspaceConfirm: (name: string) =>
- `Remove "${name}"? This only removes the workspace group from the sidebar — the directory on disk and existing chats are untouched, and it can be re-added anytime.`,
+ `Remove "${name}"? Nothing is deleted — the directory on disk and its chats stay as they are; the workspace group, chat rows and all, simply drops off the sidebar. Pick the folder again under "New workspace" to bring it back.`,
tempWorkspaces: "Temporary workspaces",
onMachine: (name: string, machine: string) => `${name} [SSH: ${machine}]`,
machineTag: (machine: string) => `[SSH: ${machine}]`,
diff --git a/packages/web/src/lib/strings.ts b/packages/web/src/lib/strings.ts
index 6a3e6aeb..4c5232b0 100644
--- a/packages/web/src/lib/strings.ts
+++ b/packages/web/src/lib/strings.ts
@@ -2679,7 +2679,7 @@ export const zh = {
sortManual: "手动排序",
sortRecent: "最近更新",
newWorkspaceEntity: "新建工作区",
- /** A Workspace group's overflow (… right of the header "+"): browse its files; a registry-backed group adds alias rename + sidebar-only removal. */
+ /** A Workspace group's overflow (… right of the header "+"): browse its files and remove the group from the sidebar (every Workspace); a registry-backed group also renames its alias. */
workspaceMenu: "工作区选项",
renameWorkspace: "重命名工作区",
renameWorkspaceLabel: "名称",
@@ -2688,7 +2688,7 @@ export const zh = {
/** A Workspace group's "more" menu: the dock's Files panel on that directory. */
browseWorkspaceFiles: "打开文件浏览",
deleteWorkspaceConfirm: (name: string) =>
- `确定移除「${name}」?仅从侧边栏移除该工作区分组,不影响磁盘目录与已有会话,可随时重新添加。`,
+ `确定移除「${name}」?不删任何东西:磁盘目录和已有会话都原样留着,只是这个工作区分组连同它的会话行先不在侧边栏显示;重新用「新建工作区」选到这个目录即可恢复。`,
tempWorkspaces: "临时工作区",
/** A name that only means something on another machine, written with the ssh alias that reaches it. */
onMachine: (name: string, machine: string) => `${name} [SSH: ${machine}]`,
diff --git a/packages/web/src/lib/workspace-registry.ts b/packages/web/src/lib/workspace-registry.ts
index 26176ca8..40417ba8 100644
--- a/packages/web/src/lib/workspace-registry.ts
+++ b/packages/web/src/lib/workspace-registry.ts
@@ -7,16 +7,17 @@
* storage — the model-group-expansion.ts convention) and merge into the grouping as
* empty groups.
*
- * An entry is `{ path, machineId?, alias? }`, and the first two together are its identity:
- * one directory on one machine. The alias is a display name set via the group's rename
- * action (it replaces the basename as the group label — for session-backed groups too —
- * while the full path stays in the tooltip; an empty alias reverts to the basename). Loads
- * stay tolerant of the branch's earlier string-only stored shape.
+ * An entry is `{ path, machineId?, alias?, hiddenAt? }`, and the first two together are its
+ * identity: one directory on one machine. The alias is a display name set via the group's
+ * rename action (it replaces the basename as the group label — for session-backed groups
+ * too — while the full path stays in the tooltip; an empty alias reverts to the basename).
+ * Loads stay tolerant of the branch's earlier string-only stored shape.
*
- * Lifecycle: an entry stays until the group's remove action unregisters it (sidebar-only —
- * disk and Sessions are never touched; with Sessions present the group simply persists as
- * session-derived). Once Sessions exist the entry mostly dedups away at merge, but it
- * still carries the alias and keeps the group visible after those Sessions are gone.
+ * Lifecycle: an entry stays until the group's 删除工作区 hides it (`hiddenAt`, and that works
+ * for a group the server derives from Sessions too — sidebar-only: disk and Sessions are never
+ * touched, and picking the directory again in 新建工作区 takes it back onto the list). Once
+ * Sessions exist the entry mostly dedups away at merge, but it still carries the alias and the
+ * hidden stamp and keeps the group visible after those Sessions are gone.
*/
import {
isTempWorkspace,
@@ -26,7 +27,7 @@ import {
} from "./session-grouping";
import type { WorkspaceGroup } from "./session-grouping";
-/** One registered Workspace: the normalized path, plus an optional display alias. */
+/** One registered Workspace: the normalized path, plus an optional display alias and hidden stamp. */
export interface WorkspaceEntry {
path: string;
/** Display name overriding the path basename (set via the group's rename action; absent = basename). */
@@ -40,6 +41,14 @@ export interface WorkspaceEntry {
* different directories, so the pair is the identity and `path` alone is not.
*/
machineId?: string;
+ /**
+ * When the user took this Workspace off the sidebar (ISO 8601; absent = on the list). The
+ * group is left out of it — session-backed or not — while every Session in it is older than
+ * this instant, so a chat CREATED in the directory afterwards brings the group back and a
+ * live conversation never ends up invisible (dropHiddenWorkspaces). Re-registering the pick
+ * clears the stamp: that is the way back onto the list.
+ */
+ hiddenAt?: string;
}
/**
@@ -97,10 +106,17 @@ function parseEntry(x: unknown): WorkspaceEntry | null {
const alias = typeof rawAlias === "string" ? rawAlias.trim() : "";
const rawMachine = (x as { machineId?: unknown }).machineId;
const machineId = typeof rawMachine === "string" && rawMachine !== "" ? rawMachine : undefined;
+ // Junk stamps are dropped rather than carried: the one thing this field can do is HIDE a
+ // group, and an unparseable instant would hide it for good (dropHiddenWorkspaces skips
+ // entries it cannot read, so the group stays on the list).
+ const rawHidden = (x as { hiddenAt?: unknown }).hiddenAt;
+ const hiddenAt =
+ typeof rawHidden === "string" && rawHidden.trim() !== "" ? rawHidden.trim() : undefined;
return {
path: p,
...(alias === "" ? {} : { alias }),
...(machineId === undefined ? {} : { machineId }),
+ ...(hiddenAt === undefined ? {} : { hiddenAt }),
};
}
return null;
@@ -149,7 +165,8 @@ export function saveWorkspaceRegistry(
* Registers a picked path: normalized and prepended (newest registration first).
* Returns the INPUT array unchanged (same reference) for anything unregisterable —
* callers skip the state update and storage write. Besides the empty path and an
- * already-registered one, a TEMPORARY-workspace path is rejected: the merge below can
+ * already-registered one that is NOT hidden (re-picking a hidden directory is how its group
+ * comes back), a TEMPORARY-workspace path is rejected: the merge below can
* never give it a group (the merged temp group owns that space), so accepting it would
* store an entry whose group never appears — no rename/remove overflow to undo it, and
* re-picking would hit the already-registered exit, leaving a ghost only a
@@ -164,8 +181,19 @@ export function registerWorkspace(
if (p === "" || isTempWorkspace(p)) return entries;
// Deduped on the PAIR: the same path on two machines is two different directories, and
// collapsing them would hide one behind the other with no way to tell which.
- if (entries.some((e) => sameWorkspace(e, { path: p, machineId }))) return entries;
- return [{ path: p, ...(machineId === undefined ? {} : { machineId }) }, ...entries];
+ const existing = entries.find((e) => sameWorkspace(e, { path: p, machineId }));
+ if (existing !== undefined && existing.hiddenAt === undefined) return entries;
+ // A HIDDEN entry is the one case where the same pick is not a no-op: picking the directory
+ // again is how the group the user removed comes back, so the stamp goes and the alias stays.
+ const kept = entries.filter((e) => e !== existing);
+ return [
+ {
+ path: p,
+ ...(existing?.alias === undefined ? {} : { alias: existing.alias }),
+ ...(machineId === undefined ? {} : { machineId }),
+ },
+ ...kept,
+ ];
}
/**
@@ -190,21 +218,85 @@ export function setWorkspaceAlias(
path: e.path,
...(a === "" ? {} : { alias: a }),
...(e.machineId === undefined ? {} : { machineId: e.machineId }),
+ // Renaming a group the user had removed must not put it back on the list — and the
+ // stamp has to survive the rewrite, or its group would reappear out of nowhere.
+ ...(e.hiddenAt === undefined ? {} : { hiddenAt: e.hiddenAt }),
}
: e,
);
}
-/** Drops the registry entry (sidebar-only — disk and Sessions are untouched). Same-reference fast exit when the pair isn't registered. */
-export function unregisterWorkspace(
+/**
+ * Takes a Workspace off the sidebar (the group's ⋯ menu → 删除工作区): stamps the pair with the
+ * instant of the removal, which `dropHiddenWorkspaces` reads to leave the group — and the chats
+ * inside it — off the list. Sidebar-only: the directory on disk and every Session in it stay
+ * exactly as they were, and re-picking the directory in 新建工作区 clears the stamp.
+ *
+ * An alias already set on the pair survives the rewrite. Same-reference fast exit for an
+ * unrepresentable path or a pair that is already hidden under the very same instant.
+ */
+export function hideWorkspace(
entries: readonly WorkspaceEntry[],
path: string,
- machineId: string | null = null,
+ machineId: string | null,
+ hiddenAt: string,
): readonly WorkspaceEntry[] {
- const target = { path, ...(machineId === null ? {} : { machineId }) };
- return entries.some((e) => sameWorkspace(e, target))
- ? entries.filter((e) => !sameWorkspace(e, target))
- : entries;
+ const p = normalizeWorkspacePath(path);
+ const at = hiddenAt.trim();
+ if (p === "" || at === "" || isTempWorkspace(p)) return entries;
+ const target = { path: p, ...(machineId === null ? {} : { machineId }) };
+ const entry = entries.find((e) => sameWorkspace(e, target));
+ if (entry?.hiddenAt === at) return entries;
+ return [
+ {
+ path: p,
+ ...(entry?.alias === undefined ? {} : { alias: entry.alias }),
+ ...(machineId === null ? {} : { machineId }),
+ hiddenAt: at,
+ },
+ ...entries.filter((e) => !sameWorkspace(e, target)),
+ ];
+}
+
+/**
+ * Drops the groups the user removed from the sidebar, keyed by `workspaceGroupKey` — the
+ * session-derived ones INCLUDED, which is the whole point: a group with Sessions used to
+ * survive 删除工作区 (the merge only ever drops an empty registry group), so the list kept the
+ * Workspaces the user was done with.
+ *
+ * A hidden entry hides its group only while the group holds no chat CREATED after the removal
+ * instant. A conversation started in that directory since then puts the group back: a live chat
+ * can never be invisible, and the stale stamp simply stops hiding anything (removing it again
+ * writes a fresh one). The empty group the merge adds for a hidden entry is dropped as well, so
+ * the Workspace leaves the list whether it had Sessions or not.
+ *
+ * `createdAt` is injected to keep the rule pure and testable; a Session whose stamp is missing
+ * or unparseable counts as older — it cannot prove the group is in use. Same-reference fast exit
+ * when no entry hides anything.
+ */
+export function dropHiddenWorkspaces<T>(
+ groups: WorkspaceGroup<T>[],
+ entries: readonly WorkspaceEntry[],
+ createdAt: (session: T) => string | null | undefined,
+): WorkspaceGroup<T>[] {
+ const hiddenAt = new Map<string, number>();
+ for (const e of entries) {
+ if (e.hiddenAt === undefined) continue;
+ const at = Date.parse(e.hiddenAt);
+ // An entry we cannot read hides nothing (see parseEntry): the group stays on the list.
+ if (!Number.isNaN(at)) hiddenAt.set(workspaceGroupKey(e.path, e.machineId ?? null), at);
+ }
+ if (hiddenAt.size === 0) return groups;
+ const kept = groups.filter((g) => {
+ const at = hiddenAt.get(g.key);
+ if (at === undefined) return true;
+ return g.sessions.some((s) => {
+ const raw = createdAt(s);
+ const created = raw === null || raw === undefined ? Number.NaN : Date.parse(raw);
+ return Number.isFinite(created) && created > at;
+ });
+ });
+ return kept.length === groups.length ? groups : kept;
}
/**
@@ -220,6 +312,10 @@ export function unregisterWorkspace(
* cap: fronting them would push every group with real chats behind 更多分组 as soon as
* a handful of Workspaces were registered. The sidebar widens the cap when it registers
* one, so a just-added Workspace is still revealed immediately.
+ *
+ * A HIDDEN entry is nothing special here — it still applies its alias, and the empty group it
+ * adds is dropped right afterwards by dropHiddenWorkspaces, which owns the hiding rule (a group
+ * off the list is a decision about the list, not about the merge).
*/
export function mergeRegisteredWorkspaces<T>(
groups: readonly WorkspaceGroup<T>[],
diff --git a/packages/web/test/workspace-registry.test.ts b/packages/web/test/workspace-registry.test.ts
index e2095008..fa56eaf9 100644
--- a/packages/web/test/workspace-registry.test.ts
+++ b/packages/web/test/workspace-registry.test.ts
@@ -6,8 +6,12 @@
* drive root kept whole), so it dedups against the paths Sessions report.
* - Registering prepends the pick; an already registered path, a blank one or a temporary
* Workspace changes nothing (the same array comes back). The machine a directory was picked
- * on is recorded, and the same path on two machines is two Workspaces.
- * - Unregistering drops one machine's entry, alias and all, and nothing when absent.
+ * on is recorded, and the same path on two machines is two Workspaces. A HIDDEN entry is the
+ * one exception: picking that directory again clears the stamp (that is the way back on the
+ * list) and keeps the alias.
+ * - Hiding stamps one machine's pair — alias and all — and stamps an unregistered path too (a
+ * group the server derives from Sessions has no entry of its own until then); a blank path,
+ * a blank instant or a temporary Workspace is refused.
* - An alias is trimmed, a blank one reverts to the basename, the input is never mutated, and
* an unchanged alias changes nothing; renaming one machine's entry leaves the other's alone.
* - Entries round-trip per Project (alias and machine included); nothing stored or no Project
@@ -17,16 +21,20 @@
* - Merged into the groups, empty registered groups follow the session-backed ones, an alias
* relabels a session-backed group too, a temporary path never forms a group, and each
* machine gets its own group.
+ * - Dropping the hidden ones takes a session-backed group off the list as long as every chat
+ * in it predates the removal — and gives it back the moment one was CREATED after it, so a
+ * live conversation can never be invisible. Per machine, like everything else here.
*/
import { describe, expect, it } from "vitest";
import {
+ dropHiddenWorkspaces,
+ hideWorkspace,
loadWorkspaceRegistry,
mergeRegisteredWorkspaces,
normalizeWorkspacePath,
registerWorkspace,
saveWorkspaceRegistry,
setWorkspaceAlias,
- unregisterWorkspace,
workspaceRegistryKey,
} from "../src/lib/workspace-registry";
import type { WorkspaceEntry, WorkspaceRegistryStorage } from "../src/lib/workspace-registry";
@@ -35,18 +43,22 @@ import type { WorkspaceGroup } from "../src/lib/session-grouping";
import { blockedStorage, memoryStorage } from "./helpers/storage";
/** Minimal session-derived group (only the fields the merge reads matter). */
-function group(key: string, over: Partial<WorkspaceGroup<{ id: string }>> = {}) {
+function group<T = { id: string }>(key: string, over: Partial<WorkspaceGroup<T>> = {}) {
return {
key,
label: key.split("/").filter(Boolean).pop() ?? "/",
fullPath: key,
machineId: null as string | null,
temp: false,
- sessions: [] as { id: string }[],
+ sessions: [] as T[],
...over,
};
}
+/** A chat row as dropHiddenWorkspaces reads one: an id plus the instant it was created. */
+type Chat = { id: string; createdAt: string };
+const chat = (id: string, createdAt: string): Chat => ({ id, createdAt });
+
describe("normalizeWorkspacePath", () => {
it("trims and drops trailing separators; the filesystem root survives; empty stays empty", () => {
expect(normalizeWorkspacePath(" /srv/app/ ")).toBe("/srv/app");
@@ -67,7 +79,7 @@ describe("normalizeWorkspacePath", () => {
});
});
-describe("registerWorkspace / unregisterWorkspace", () => {
+describe("registerWorkspace / hideWorkspace", () => {
it("register prepends the normalized pick (newest first) and dedups by normalized form with a same-reference fast exit", () => {
const empty: readonly WorkspaceEntry[] = [];
const one = registerWorkspace(empty, "/srv/app/");
@@ -86,10 +98,53 @@ describe("registerWorkspace / unregisterWorkspace", () => {
expect(registerWorkspace(entries, `${temp}/`)).toBe(entries);
});
- it("unregister drops the entry — alias and all — and returns the SAME array when the path isn't registered", () => {
+ it("picking a HIDDEN directory again takes it back onto the list: the stamp goes, the alias stays", () => {
+ const entries: readonly WorkspaceEntry[] = [
+ { path: "/a", alias: "Alpha", hiddenAt: "2026-10-06T10:00:00.000Z" },
+ { path: "/b" },
+ ];
+ expect(registerWorkspace(entries, "/a")).toEqual([
+ { path: "/a", alias: "Alpha" },
+ { path: "/b" },
+ ]);
+ // The machine travels with the pair: unhiding this machine's entry leaves the remote one hidden.
+ const both: readonly WorkspaceEntry[] = [
+ { path: "/a", hiddenAt: "2026-10-06T10:00:00.000Z" },
+ { path: "/a", machineId: "noeSE0FFHhNXl2J5", hiddenAt: "2026-10-06T10:00:00.000Z" },
+ ];
+ expect(registerWorkspace(both, "/a").map((e) => e.machineId)).toEqual([
+ undefined,
+ "noeSE0FFHhNXl2J5",
+ ]);
+ });
+});
+
+describe("hideWorkspace", () => {
+ const at = "2026-10-06T10:00:00.000Z";
+
+ it("stamps the pair — alias kept — and stamps an unregistered path too (a session-derived group has no entry yet)", () => {
const entries: readonly WorkspaceEntry[] = [{ path: "/a", alias: "Alpha" }, { path: "/b" }];
- expect(unregisterWorkspace(entries, "/a")).toEqual([{ path: "/b" }]);
- expect(unregisterWorkspace(entries, "/zzz")).toBe(entries);
+ expect(hideWorkspace(entries, "/a", null, at)).toEqual([
+ { path: "/a", alias: "Alpha", hiddenAt: at },
+ { path: "/b" },
+ ]);
+ expect(hideWorkspace(entries, "/zzz", null, at)).toEqual([
+ { path: "/zzz", hiddenAt: at },
+ { path: "/a", alias: "Alpha" },
+ { path: "/b" },
+ ]);
+ // Re-hiding under a new instant rewrites the stamp; the very same instant is a no-op.
+ const hidden = hideWorkspace(entries, "/a", null, at);
+ expect(hideWorkspace(hidden, "/a", null, "2026-10-06T11:00:00.000Z")).not.toBe(hidden);
+ expect(hideWorkspace(hidden, "/a", null, at)).toBe(hidden);
+ });
+
+ it("refuses a blank path, a blank instant and a temporary Workspace (same array back)", () => {
+ const entries: readonly WorkspaceEntry[] = [{ path: "/a" }];
+ expect(hideWorkspace(entries, " ", null, at)).toBe(entries);
+ expect(hideWorkspace(entries, "/a", null, " ")).toBe(entries);
+ const temp = "/home/u/.penguin/agents/a/workspaces/tmp-0123abcd";
+ expect(hideWorkspace(entries, temp, null, at)).toBe(entries);
});
});
@@ -109,6 +164,15 @@ describe("setWorkspaceAlias", () => {
const named = setWorkspaceAlias(entries, "/a", null, "X");
expect(setWorkspaceAlias(named, "/a", null, " X ")).toBe(named);
});
+
+ it("renaming a group the user had removed keeps it removed (the hidden stamp survives the rewrite)", () => {
+ const hidden: readonly WorkspaceEntry[] = [
+ { path: "/a", alias: "Alpha", hiddenAt: "2026-10-06T10:00:00.000Z" },
+ ];
+ expect(setWorkspaceAlias(hidden, "/a", null, "Beta")).toEqual([
+ { path: "/a", alias: "Beta", hiddenAt: "2026-10-06T10:00:00.000Z" },
+ ]);
+ });
});
describe("persisted registry (per-Project localStorage)", () => {
@@ -124,6 +188,7 @@ describe("persisted registry (per-Project localStorage)", () => {
[
{ path: "/srv/beta", alias: "Beta" },
{ path: "/srv/app", machineId: "noeSE0FFHhNXl2J5" },
+ { path: "/srv/gone", hiddenAt: "2026-10-06T10:00:00.000Z" },
],
s,
);
@@ -131,6 +196,7 @@ describe("persisted registry (per-Project localStorage)", () => {
expect(loadWorkspaceRegistry("p1", s)).toEqual([
{ path: "/srv/beta", alias: "Beta" },
{ path: "/srv/app", machineId: "noeSE0FFHhNXl2J5" },
+ { path: "/srv/gone", hiddenAt: "2026-10-06T10:00:00.000Z" },
]);
expect(loadWorkspaceRegistry("p2", s)).toEqual([{ path: "/other" }]);
});
@@ -158,6 +224,17 @@ describe("persisted registry (per-Project localStorage)", () => {
'[7, null, " ", {"alias": "orphan"}, {"path": "/a", "alias": 5}, {"path": "/b", "alias": " "}]',
);
expect(loadWorkspaceRegistry("p1", s)).toEqual([{ path: "/a" }, { path: "/b" }]);
+ // A junk hidden stamp is dropped rather than carried: it can only HIDE, and an instant we
+ // cannot read must not take a group off the list for good.
+ s.map.set(
+ workspaceRegistryKey("p1"),
+ '[{"path": "/a", "hiddenAt": 7}, {"path": "/b", "hiddenAt": " "}, {"path": "/c", "hiddenAt": " 2026-10-06T10:00:00.000Z "}]',
+ );
+ expect(loadWorkspaceRegistry("p1", s)).toEqual([
+ { path: "/a" },
+ { path: "/b" },
+ { path: "/c", hiddenAt: "2026-10-06T10:00:00.000Z" },
+ ]);
});
it("storage throwing (quota/private mode): save does not throw, load yields empty", () => {
@@ -280,18 +357,21 @@ describe("a workspace's machine", () => {
]);
});
- it("removes one machine's workspace, not every entry sharing the path", () => {
+ it("hides one machine's workspace, not the other entry sharing the path", () => {
const entries: readonly WorkspaceEntry[] = [
{ path: "/srv/app", machineId: "noeSE0FFHhNXl2J5" },
{ path: "/srv/app" },
];
- expect(unregisterWorkspace(entries, "/srv/app", "noeSE0FFHhNXl2J5")).toEqual([
+ expect(
+ hideWorkspace(entries, "/srv/app", "noeSE0FFHhNXl2J5", "2026-10-06T10:00:00.000Z"),
+ ).toEqual([
+ { path: "/srv/app", machineId: "noeSE0FFHhNXl2J5", hiddenAt: "2026-10-06T10:00:00.000Z" },
{ path: "/srv/app" },
]);
- expect(unregisterWorkspace(entries, "/srv/app")).toEqual([
+ expect(hideWorkspace(entries, "/srv/app", null, "2026-10-06T10:00:00.000Z")).toEqual([
+ { path: "/srv/app", hiddenAt: "2026-10-06T10:00:00.000Z" },
{ path: "/srv/app", machineId: "noeSE0FFHhNXl2J5" },
]);
- expect(unregisterWorkspace(entries, "/srv/app", "UNREGISTEREDaaaa")).toBe(entries);
});
it("merges one group per machine, and an alias relabels only its own", () => {
@@ -317,3 +397,66 @@ describe("a workspace's machine", () => {
expect(merged[1]!.sessions).toEqual([]);
});
});
+
+describe("dropHiddenWorkspaces", () => {
+ const at = "2026-10-06T10:00:00.000Z";
+ const created = (s: Chat) => s.createdAt;
+
+ it("takes a SESSION-BACKED group off the list — the case that used to survive 删除工作区", () => {
+ const groups = [
+ group<Chat>("/srv/app", { sessions: [chat("s1", "2026-10-06T09:00:00.000Z")] }),
+ group<Chat>("/srv/beta", { sessions: [chat("s2", "2026-10-06T09:30:00.000Z")] }),
+ ];
+ const kept = dropHiddenWorkspaces(groups, [{ path: "/srv/app", hiddenAt: at }], created);
+ expect(kept.map((g) => g.key)).toEqual(["/srv/beta"]);
+ // The group itself is untouched: only the list drops it (disk and chats are never edited).
+ expect(groups[0]!.sessions).toEqual([chat("s1", "2026-10-06T09:00:00.000Z")]);
+ });
+
+ it("a chat CREATED after the removal brings the group back — a live conversation is never invisible", () => {
+ const groups = [
+ group<Chat>("/srv/app", {
+ sessions: [chat("s1", "2026-10-06T09:00:00.000Z"), chat("s2", "2026-10-06T10:00:01.000Z")],
+ }),
+ ];
+ expect(dropHiddenWorkspaces(groups, [{ path: "/srv/app", hiddenAt: at }], created)).toBe(
+ groups,
+ );
+ });
+
+ it("drops the empty group the merge adds for a hidden entry (a Workspace with no Sessions)", () => {
+ const groups = [group<Chat>("/srv/app"), group<Chat>("/srv/beta")];
+ expect(dropHiddenWorkspaces(groups, [{ path: "/srv/app", hiddenAt: at }], created)).toEqual([
+ groups[1],
+ ]);
+ });
+
+ it("hides per pair: the same path on another machine is another Workspace and stays", () => {
+ const remote = "noeSE0FFHhNXl2J5";
+ const groups = [
+ group<Chat>("/srv/app", { sessions: [chat("s1", "2026-10-06T09:00:00.000Z")] }),
+ group<Chat>(`${remote}\u0000/srv/app`, {
+ machineId: remote,
+ sessions: [chat("s2", "2026-10-06T09:00:00.000Z")],
+ }),
+ ];
+ const kept = dropHiddenWorkspaces(groups, [{ path: "/srv/app", hiddenAt: at }], created);
+ expect(kept.map((g) => g.key)).toEqual([`${remote}\u0000/srv/app`]);
+ });
+
+ it("an unreadable or unparseable stamp hides nothing; with no hidden entry the INPUT array comes back", () => {
+ const groups = [
+ group<Chat>("/srv/app", { sessions: [chat("s1", "2026-10-06T09:00:00.000Z")] }),
+ ];
+ expect(dropHiddenWorkspaces(groups, [], created)).toBe(groups);
+ expect(dropHiddenWorkspaces(groups, [{ path: "/srv/app" }], created)).toBe(groups);
+ expect(
+ dropHiddenWorkspaces(groups, [{ path: "/srv/app", hiddenAt: "not a date" }], created),
+ ).toBe(groups);
+ // A Session whose stamp the rule cannot read counts as older, never as "in use".
+ const undated = [group<Chat>("/srv/app", { sessions: [{ id: "s1" } as unknown as Chat] })];
+ expect(dropHiddenWorkspaces(undated, [{ path: "/srv/app", hiddenAt: at }], created)).toEqual(
+ [],
+ );
+ });
+});