A cross-platform desktop All-in-One assistant for Claude Code, Codex, OpenCode,DeepSeek Harness and more. Only official website: ccswitch.io
Rust ai-toolsclaude-codecodexdeepseek-harnessdesktop-appgrokgrokbuildhermeskimi-codemcpopen-sourceopencodepiprovider-managementrustskillsskills-managementtauriwsl-support
feat(sessions): filter Codex history by archive status (#10190)
Jiarui Fan1de9b4ad49f1
diff --git a/src/components/sessions/SessionDialogs.tsx b/src/components/sessions/SessionDialogs.tsxindex 626bc720b..6e04161b7 100644--- a/src/components/sessions/SessionDialogs.tsx+++ b/src/components/sessions/SessionDialogs.tsx@@ -21,6 +21,7 @@ const dialogClass =interface SessionDeleteDialogProps {targets: SessionMeta[] | null;+ archiveSelection?: { status: string; query: string; hiddenCount: number };pending: boolean;onConfirm: () => void;onCancel: () => void;@@ -29,6 +30,7 @@ interface SessionDeleteDialogProps {/** 删除确认:按应用写清删了什么、没删什么。会话删除不经过废纸篓,不给撤销。 */export function SessionDeleteDialog({targets,+ archiveSelection,pending,onConfirm,onCancel,@@ -101,6 +103,27 @@ export function SessionDeleteDialog({defaultValue: "会从磁盘上永久删除,不经过废纸篓,无法撤销。",})}</DialogDescription>+ {archiveSelection && (+ <p className="m-0 break-words text-caption text-fg-2">+ {archiveSelection.status}+ {archiveSelection.query && (+ <>+ {" · "}+ <q>{archiveSelection.query}</q>+ </>+ )}+ {" · "}+ {t("sessionManager.selectedSessions", {+ defaultValue: "已选 {{count}} 个会话",+ count: list.length,+ })}+ {archiveSelection.hiddenCount > 0 &&+ t("sessionManager.hiddenSelected", {+ defaultValue: " · 其中 {{count}} 个不在当前结果里",+ count: archiveSelection.hiddenCount,+ })}+ </p>+ )}</div><ul className="m-0 flex list-none flex-col gap-2.5 rounded-panel bg-subtle px-3.5 py-3">{apps.map((app) => {diff --git a/src/components/sessions/SessionManagerPage.tsx b/src/components/sessions/SessionManagerPage.tsxindex 798c821d7..054de4782 100644--- a/src/components/sessions/SessionManagerPage.tsx+++ b/src/components/sessions/SessionManagerPage.tsx@@ -52,6 +52,13 @@ import { AppGlyph, APP_DISPLAY_NAME } from "@/components/shell/AppGlyph";import { extractErrorMessage } from "@/utils/errorUtils";import { isMac } from "@/lib/platform";import { SearchField } from "@/components/ui/search-field";+import {+ Select,+ SelectContent,+ SelectItem,+ SelectTrigger,+ SelectValue,+} from "@/components/ui/select";import { cn } from "@/lib/utils";import {getSessionRowHeight,@@ -67,6 +74,7 @@ import {getSessionKey,groupSessionsByProject,groupSessionsByTime,+ isArchivedSession,isSessionAppId,SESSION_APP_IDS,SESSION_SOURCE_PATHS,@@ -84,6 +92,7 @@ const GROUP_MODE_STORAGE_KEY = "cc-switch.sessionManager.groupMode";const EXPANDED_STORAGE_KEY = "cc-switch.sessionManager.expandedProjects";type AppFilter = SessionAppId | "all";+type ArchiveFilter = "all" | "archived" | "unarchived";type GroupMode = "time" | "project";type DeleteSource = "row" | "reader" | "bar";@@ -170,6 +179,20 @@ export function SessionManagerPage({isSessionAppId(appId) ? appId : "claude",);const [query, setQuery] = useState("");+ const [archiveFilter, setArchiveFilter] = useState<ArchiveFilter>("all");+ const activeArchiveFilter = appFilter === "codex" ? archiveFilter : "all";+ const archiveScopedSessions = useMemo(+ () =>+ activeArchiveFilter === "all"+ ? sessions+ : sessions.filter(+ (session) =>+ session.providerId === "codex" &&+ isArchivedSession(session) ===+ (activeArchiveFilter === "archived"),+ ),+ [sessions, activeArchiveFilter],+ );const [groupMode, setGroupMode] = useState<GroupMode>(readGroupMode);const [expanded, setExpanded] = useState<Set<string>>(readExpanded);const [readerKey, setReaderKey] = useState<string | null>(null);@@ -258,7 +281,7 @@ export function SessionManagerPage({);const { search: searchSessions } = useSessionSearch({- sessions,+ sessions: archiveScopedSessions,providerFilter: appFilter,providerIds: availableApps,});@@ -295,9 +318,9 @@ export function SessionManagerPage({const metaMatches = searchSessions(query);if (contentHits.size === 0) return sortSessionsByTime(metaMatches);const seen = new Set(metaMatches.map(getSessionKey));- const contentOnly = scopedSessions.filter(+ const contentOnly = archiveScopedSessions.filter((session) =>- (appFilter === "all" || session.providerId === appFilter) &&+ contentProviderIds.includes(session.providerId) &&!seen.has(getSessionKey(session)) &&contentHitOf(session) !== undefined,);@@ -306,8 +329,8 @@ export function SessionManagerPage({searchSessions,query,contentHits,- scopedSessions,- appFilter,+ archiveScopedSessions,+ contentProviderIds,contentHitOf,]);@@ -406,14 +429,14 @@ export function SessionManagerPage({const deleteSessionMutation = useDeleteSessionMutation();const isDeleting = deleteSessionMutation.isPending || isBatchDeleting;- // 选择里去掉已经不存在的会话+ // 清掉消失或不再符合归档条件的选择,避免批量删除包含筛选范围外的会话。useEffect(() => {- const valid = new Set(sessions.map(getSessionKey));+ const valid = new Set(archiveScopedSessions.map(getSessionKey));setSelectedKeys((current) => {const next = new Set([...current].filter((key) => valid.has(key)));return next.size === current.size ? current : next;});- }, [sessions]);+ }, [archiveScopedSessions]);const terminalName = useMemo(() => {if (!isMac()) return null;@@ -545,11 +568,11 @@ export function SessionManagerPage({const selectedSessions = useMemo(() =>- sessions.filter(+ archiveScopedSessions.filter((session) =>selectedKeys.has(getSessionKey(session)) && canDeleteSession(session),),- [sessions, selectedKeys],+ [archiveScopedSessions, selectedKeys],);const matchKeys = useMemo(() => new Set(matches.map(getSessionKey)),@@ -733,6 +756,11 @@ export function SessionManagerPage({const appName = (app: string) =>isSessionAppId(app) ? APP_DISPLAY_NAME[app] : app;const showAppIcon = appFilter === "all";+ const archiveLabels = {+ all: t("sessionManager.allArchiveStates", { defaultValue: "全部状态" }),+ archived: t("sessionManager.archived", { defaultValue: "已归档" }),+ unarchived: t("sessionManager.unarchived", { defaultValue: "未归档" }),+ };const totalCount = scopedSessions.length;const currentCount =appFilter === "all" ? totalCount : (counts.get(appFilter) ?? 0);@@ -1071,6 +1099,17 @@ export function SessionManagerPage({/>);}+ if (activeArchiveFilter !== "all") {+ return (+ <EmptyState+ title={t("sessionManager.noArchiveMatches", {+ defaultValue: "没有符合此归档状态的会话",+ })}+ action={archiveLabels.all}+ onAction={() => setArchiveFilter("all")}+ />+ );+ }return (<EmptyStatetitle={@@ -1247,7 +1286,7 @@ export function SessionManagerPage({readerSession && "hidden",)}>- <div className="flex shrink-0 items-center gap-2 px-6 pt-3.5">+ <div className="flex shrink-0 flex-wrap items-center gap-2 px-6 pt-3.5"><DropdownMenu><DropdownMenuTrigger asChild><Button@@ -1336,7 +1375,7 @@ export function SessionManagerPage({</DropdownMenuContent></DropdownMenu>- <div className="relative min-w-0 flex-1">+ <div className="relative min-w-32 flex-1"><SearchFieldid="session-search"ref={searchRef}@@ -1370,6 +1409,33 @@ export function SessionManagerPage({</span></div>+ {appFilter === "codex" && (+ <Select+ value={archiveFilter}+ onValueChange={(value: ArchiveFilter) =>+ setArchiveFilter(value)+ }+ >+ <SelectTrigger+ aria-label={t("sessionManager.archiveStatus", {+ defaultValue: "归档状态",+ })}+ className="h-8 w-auto max-w-48 gap-2"+ >+ <SelectValue />+ </SelectTrigger>+ <SelectContent>+ {(["all", "archived", "unarchived"] as const).map(+ (status) => (+ <SelectItem key={status} value={status}>+ {archiveLabels[status]}+ </SelectItem>+ ),+ )}+ </SelectContent>+ </Select>+ )}+<SegmentedControl<GroupMode>aria-label={t("sessionManager.groupBy", {defaultValue: "分组方式",@@ -1506,7 +1572,10 @@ export function SessionManagerPage({className={linkButton}onClick={() =>setSelectedKeys((current) => {- const next = new Set(current);+ const next =+ activeArchiveFilter === "all"+ ? new Set(current)+ : new Set<string>();matches.filter(canDeleteSession).forEach((session) => next.add(getSessionKey(session)));@@ -1628,6 +1697,15 @@ export function SessionManagerPage({<SessionDeleteDialogtargets={deleteTargets}+ archiveSelection={+ appFilter === "codex" && deleteSourceRef.current === "bar"+ ? {+ status: archiveLabels[activeArchiveFilter],+ query: trimmedQuery,+ hiddenCount: hiddenSelected,+ }+ : undefined+ }pending={isDeleting}onConfirm={() => void handleDeleteConfirm()}onCancel={cancelDelete}diff --git a/src/i18n/locales/de.json b/src/i18n/locales/de.jsonindex 216ff4965..7d57cedf9 100644--- a/src/i18n/locales/de.json+++ b/src/i18n/locales/de.json@@ -1649,6 +1649,10 @@"bucketEarlier": "Früher","lastPrefix": "Zuletzt: {{text}}","archived": "Archiviert",+ "archiveStatus": "Archivstatus",+ "allArchiveStates": "Alle Status",+ "unarchived": "Nicht archiviert",+ "noArchiveMatches": "Keine Sitzungen mit diesem Archivstatus.","rowTimes": "Zuletzt aktiv {{last}} · Erstellt {{created}}","resumeIn": "In {{terminal}} fortsetzen","resumeInFor": "{{title}} in {{terminal}} fortsetzen",diff --git a/src/i18n/locales/en.json b/src/i18n/locales/en.jsonindex c8ff17d4e..facc24a15 100644--- a/src/i18n/locales/en.json+++ b/src/i18n/locales/en.json@@ -1649,6 +1649,10 @@"bucketEarlier": "Earlier","lastPrefix": "Last: {{text}}","archived": "Archived",+ "archiveStatus": "Archive status",+ "allArchiveStates": "All statuses",+ "unarchived": "Unarchived",+ "noArchiveMatches": "No sessions match this archive status.","rowTimes": "Last active {{last}} · Created {{created}}","resumeIn": "Resume in {{terminal}}","resumeInFor": "Resume {{title}} in {{terminal}}",diff --git a/src/i18n/locales/ja.json b/src/i18n/locales/ja.jsonindex 5aaf37287..2ce7ebc70 100644--- a/src/i18n/locales/ja.json+++ b/src/i18n/locales/ja.json@@ -1649,6 +1649,10 @@"bucketEarlier": "それ以前","lastPrefix": "最後:{{text}}","archived": "アーカイブ済み",+ "archiveStatus": "アーカイブ状態",+ "allArchiveStates": "すべての状態",+ "unarchived": "未アーカイブ",+ "noArchiveMatches": "このアーカイブ状態に一致するセッションはありません。","rowTimes": "最終アクティブ {{last}} ・作成 {{created}}","resumeIn": "{{terminal}} で再開","resumeInFor": "{{title}} を {{terminal}} で再開",diff --git a/src/i18n/locales/ko.json b/src/i18n/locales/ko.jsonindex 4855cd6f4..45edd73c4 100644--- a/src/i18n/locales/ko.json+++ b/src/i18n/locales/ko.json@@ -1648,6 +1648,10 @@"bucketEarlier": "이전","lastPrefix": "마지막: {{text}}","archived": "보관됨",+ "archiveStatus": "보관 상태",+ "allArchiveStates": "모든 상태",+ "unarchived": "보관되지 않음",+ "noArchiveMatches": "이 보관 상태에 해당하는 세션이 없습니다.","rowTimes": "최근 활동 {{last}} · 생성 {{created}}","resumeIn": "{{terminal}}에서 이어가기","resumeInFor": "{{terminal}}에서 {{title}} 이어가기",diff --git a/src/i18n/locales/ru.json b/src/i18n/locales/ru.jsonindex efc2d7ab8..7af0c9268 100644--- a/src/i18n/locales/ru.json+++ b/src/i18n/locales/ru.json@@ -1650,6 +1650,10 @@"bucketEarlier": "Ранее","lastPrefix": "Последнее: {{text}}","archived": "В архиве",+ "archiveStatus": "Статус архивации",+ "allArchiveStates": "Все статусы",+ "unarchived": "Не в архиве",+ "noArchiveMatches": "Нет сеансов с таким статусом архивации.","rowTimes": "Активность: {{last}} · Создано: {{created}}","resumeIn": "Возобновить в {{terminal}}","resumeInFor": "Возобновить {{title}} в {{terminal}}",diff --git a/src/i18n/locales/tr.json b/src/i18n/locales/tr.jsonindex 05a235b46..c75416b19 100644--- a/src/i18n/locales/tr.json+++ b/src/i18n/locales/tr.json@@ -1578,6 +1578,10 @@"bucketEarlier": "Daha önce","lastPrefix": "Son: {{text}}","archived": "Arşivlendi",+ "archiveStatus": "Arşiv durumu",+ "allArchiveStates": "Tüm durumlar",+ "unarchived": "Arşivlenmemiş",+ "noArchiveMatches": "Bu arşiv durumuyla eşleşen oturum yok.","rowTimes": "Son aktif {{last}} · {{created}} oluşturuldu","resumeIn": "{{terminal}}'de devam ettir","resumeInFor": "{{terminal}}'de {{title}}'yi devam ettirin",diff --git a/src/i18n/locales/zh-TW.json b/src/i18n/locales/zh-TW.jsonindex ff242271c..b94e270b9 100644--- a/src/i18n/locales/zh-TW.json+++ b/src/i18n/locales/zh-TW.json@@ -1649,6 +1649,10 @@"bucketEarlier": "更早","lastPrefix": "最後:{{text}}","archived": "已封存",+ "archiveStatus": "封存狀態",+ "allArchiveStates": "全部狀態",+ "unarchived": "未封存",+ "noArchiveMatches": "沒有符合此封存狀態的工作階段","rowTimes": "最近活躍 {{last}} · 建立 {{created}}","resumeIn": "在 {{terminal}} 中繼續","resumeInFor": "在 {{terminal}} 中繼續 {{title}}",diff --git a/src/i18n/locales/zh.json b/src/i18n/locales/zh.jsonindex 2bee92adb..6129635aa 100644--- a/src/i18n/locales/zh.json+++ b/src/i18n/locales/zh.json@@ -1649,6 +1649,10 @@"bucketEarlier": "更早","lastPrefix": "最后:{{text}}","archived": "已归档",+ "archiveStatus": "归档状态",+ "allArchiveStates": "全部状态",+ "unarchived": "未归档",+ "noArchiveMatches": "没有符合此归档状态的会话","rowTimes": "最近活跃 {{last}} · 创建 {{created}}","resumeIn": "在 {{terminal}} 中恢复","resumeInFor": "在 {{terminal}} 中恢复 {{title}}",diff --git a/tests/components/SessionManagerPage.test.tsx b/tests/components/SessionManagerPage.test.tsxindex b80243df4..b4ac64334 100644--- a/tests/components/SessionManagerPage.test.tsx+++ b/tests/components/SessionManagerPage.test.tsx@@ -910,6 +910,65 @@ describe("SessionManagerPage", () => {deleteMany.mockRestore();});+ it("scopes search, selection and delete confirmation to the Codex archive status", async () => {+ const scrollIntoView = Element.prototype.scrollIntoView;+ Element.prototype.scrollIntoView ??= vi.fn();+ const bodyHit = vi.spyOn(sessionsApi, "searchContent").mockResolvedValue({+ hits: [+ {+ providerId: "codex",+ sourcePath: "/mock/codex/session-1.jsonl",+ matchCount: 1,+ snippets: [+ { messageIndex: 0, text: "archived_sessions", highlights: [] },+ ],+ },+ ],+ status: { running: false, processed: 3, total: 3 },+ });+ try {+ renderPage("codex");+ await screen.findByText("Alpha Session");+ fireEvent.click(+ screen.getAllByRole("checkbox", { name: "选择 Alpha Session" })[0],+ );+ const filter = screen.getByRole("combobox", { name: "归档状态" });+ await userEvent.click(filter);+ await userEvent.click(+ await screen.findByRole("option", { name: "未归档" }),+ );+ expect(screen.queryByText("Gamma Session")).not.toBeInTheDocument();+ expect(screen.getByText("已选 1 个会话")).toBeInTheDocument();+ await userEvent.click(filter);+ await userEvent.click(+ await screen.findByRole("option", { name: "已归档" }),+ );+ expect(screen.getByText("还没有选择会话")).toBeInTheDocument();+ fireEvent.change(screen.getByRole("textbox", { name: "搜索会话" }), {+ target: { value: "archived_sessions" },+ });+ await waitFor(() => expect(bodyHit).toHaveBeenCalled());+ await screen.findByText("匹配 1 个会话");+ expect(+ within(sessionList()).queryByText("Alpha Session"),+ ).not.toBeInTheDocument();+ expect(+ within(sessionList()).getByText("Gamma Session"),+ ).toBeInTheDocument();+ fireEvent.click(screen.getByRole("button", { name: "全选匹配结果" }));+ fireEvent.click(screen.getByRole("button", { name: "删除 1 个会话…" }));+ const dialog = within(await screen.findByRole("alertdialog"));+ expect(+ dialog.getByText("archived_sessions").parentElement,+ ).toHaveTextContent("已归档 · archived_sessions · 已选 1 个会话");+ expect(dialog.getByRole("heading")).toHaveTextContent("Gamma Session");+ } finally {+ bodyHit.mockRestore();+ if (!scrollIntoView)+ Reflect.deleteProperty(Element.prototype, "scrollIntoView");+ }+ });+it("drops hidden selections from the count and keeps search usable while selecting", async () => {renderPage("codex");await screen.findByText("Alpha Session");