From c1bf062d21e87e40171ebe662948d34eb614f016 Mon Sep 17 00:00:00 2001 From: Jason Date: Wed, 11 Nov 2026 15:17:27 +0800 Subject: [PATCH] feat(sessions): fold Codex desktop project-less chats into one group Codex desktop creates a fresh working directory for every chat that is not attached to a project, at /Codex//, and lists them together under "Recent" in its sidebar. The session manager's "By project" view grouped sessions strictly by projectDir, so each of those chats became its own one-session group and buried the real projects. groupSessionsByProject now recognises that directory shape (Windows or POSIX separators, case-insensitive) and puts the matches into a single "Codex chats" group whose path is the /Codex root. Deeper subdirectories and everything else keep grouping by their own directory. Adds the sessionManager.codexChats label in all eight locales. Refs #9415 --- .../sessions/SessionManagerPage.tsx | 7 ++- src/components/sessions/utils.ts | 33 +++++++++--- src/i18n/locales/de.json | 1 + src/i18n/locales/en.json | 1 + src/i18n/locales/ja.json | 1 + src/i18n/locales/ko.json | 1 + src/i18n/locales/ru.json | 1 + src/i18n/locales/tr.json | 1 + src/i18n/locales/zh-TW.json | 1 + src/i18n/locales/zh.json | 1 + tests/components/sessionUtils.test.ts | 54 ++++++++++++++++++- 11 files changed, 90 insertions(+), 12 deletions(-) diff --git a/src/components/sessions/SessionManagerPage.tsx b/src/components/sessions/SessionManagerPage.tsx index a6e54fa7d..c89af2f56 100644 --- a/src/components/sessions/SessionManagerPage.tsx +++ b/src/components/sessions/SessionManagerPage.tsx @@ -337,12 +337,15 @@ export function SessionManagerPage({ const unknownLabel = t("sessionManager.unknownDirectory", { defaultValue: "未知目录", }); + const codexChatsLabel = t("sessionManager.codexChats", { + defaultValue: "Codex 聊天", + }); const projectGroups = useMemo( () => groupMode === "project" - ? groupSessionsByProject(matches, unknownLabel) + ? groupSessionsByProject(matches, unknownLabel, codexChatsLabel) : [], - [groupMode, matches, unknownLabel], + [groupMode, matches, unknownLabel, codexChatsLabel], ); const timeGroups = useMemo( () => (groupMode === "time" ? groupSessionsByTime(matches) : []), diff --git a/src/components/sessions/utils.ts b/src/components/sessions/utils.ts index 0f473c05b..f77161971 100644 --- a/src/components/sessions/utils.ts +++ b/src/components/sessions/utils.ts @@ -196,29 +196,46 @@ const getProjectDirKey = (projectDir: string) => { .toLowerCase(); }; +/** + * Codex 桌面版不带项目的聊天,工作目录建在 `/Codex//`, + * 一次一个目录;桌面端侧栏把它们统一放在「最近」里。捕获组是 `/Codex`。 + */ +const CODEX_CHAT_DIR_RE = + /^(.*[\\/]Documents[\\/]Codex)[\\/]\d{4}-\d{2}-\d{2}[\\/][^\\/]+[\\/]*$/i; + +const CODEX_CHATS_KEY_PREFIX = "__codex_chats__:"; + /** * 按项目目录分组(选了「全部应用」时跨应用合并)。组按组内最近一条排序,未知目录排最后; - * 组内保持传入顺序。 + * 组内保持传入顺序。Codex 桌面版不带项目的聊天合成一组(和桌面端一致),组目录显示 + * `/Codex`。 */ export const groupSessionsByProject = ( sessions: SessionMeta[], unknownDirectoryLabel: string, + codexChatsLabel: string, ): SessionProjectGroup[] => { const groups = new Map(); sessions.forEach((session) => { - const projectDir = session.projectDir?.trim() || null; - const key = projectDir - ? getProjectDirKey(projectDir) - : UNKNOWN_PROJECT_DIR_KEY; + const rawDir = session.projectDir?.trim() || null; + const codexChatsRoot = rawDir?.match(CODEX_CHAT_DIR_RE)?.[1] ?? null; + const projectDir = codexChatsRoot ?? rawDir; + const key = codexChatsRoot + ? CODEX_CHATS_KEY_PREFIX + getProjectDirKey(codexChatsRoot) + : projectDir + ? getProjectDirKey(projectDir) + : UNKNOWN_PROJECT_DIR_KEY; let group = groups.get(key); if (!group) { group = { key, projectDir, - label: projectDir - ? getBaseName(projectDir) || projectDir - : unknownDirectoryLabel, + label: codexChatsRoot + ? codexChatsLabel + : projectDir + ? getBaseName(projectDir) || projectDir + : unknownDirectoryLabel, sessions: [], latest: 0, }; diff --git a/src/i18n/locales/de.json b/src/i18n/locales/de.json index 3fb79b5f7..f11c82c49 100644 --- a/src/i18n/locales/de.json +++ b/src/i18n/locales/de.json @@ -1443,6 +1443,7 @@ "searchSessions": "Sitzungen durchsuchen", "sessionList": "Sitzungen", "unknownDirectory": "Unbekanntes Verzeichnis", + "codexChats": "Codex-Chats", "batchDeleting": "Wird gelöscht …", "loadingSessions": "Sitzungen werden geladen …", "piRelativeSessionDir": "Das sessionDir von Pi ist relativ zu dem Verzeichnis, in dem Pi gestartet wird, daher kann ein globaler Browser es nicht sicher auflisten. Legen Sie ein absolutes sessionDir fest, um alle Pi-Sitzungen hier zu durchsuchen:", diff --git a/src/i18n/locales/en.json b/src/i18n/locales/en.json index 91ed99a68..3cd93739f 100644 --- a/src/i18n/locales/en.json +++ b/src/i18n/locales/en.json @@ -1443,6 +1443,7 @@ "searchSessions": "Search sessions", "sessionList": "Sessions", "unknownDirectory": "Unknown directory", + "codexChats": "Codex chats", "batchDeleting": "Deleting...", "loadingSessions": "Loading sessions...", "piRelativeSessionDir": "Pi sessionDir is relative to the directory where Pi is launched, so a global browser cannot enumerate it safely. Set an absolute sessionDir to browse all Pi sessions here:", diff --git a/src/i18n/locales/ja.json b/src/i18n/locales/ja.json index 409c27363..67ff23716 100644 --- a/src/i18n/locales/ja.json +++ b/src/i18n/locales/ja.json @@ -1443,6 +1443,7 @@ "searchSessions": "セッションを検索", "sessionList": "セッション一覧", "unknownDirectory": "不明なディレクトリ", + "codexChats": "Codex チャット", "batchDeleting": "削除中...", "loadingSessions": "セッションを読み込み中...", "piRelativeSessionDir": "Pi の sessionDir は Pi を起動したディレクトリからの相対パスであるため、グローバルブラウザーから安全に列挙できません。すべての Pi セッションをここで表示するには、sessionDir に絶対パスを設定してください:", diff --git a/src/i18n/locales/ko.json b/src/i18n/locales/ko.json index 1de732a43..4415a15b0 100644 --- a/src/i18n/locales/ko.json +++ b/src/i18n/locales/ko.json @@ -1443,6 +1443,7 @@ "searchSessions": "세션 검색", "sessionList": "세션 목록", "unknownDirectory": "알 수 없는 디렉터리", + "codexChats": "Codex 채팅", "batchDeleting": "삭제 중...", "loadingSessions": "세션 로드 중...", "piRelativeSessionDir": "Pi의 sessionDir이 상대 경로이면 Pi를 실행한 디렉터리에 따라 저장 위치가 달라져 CC Switch에서 세션 목록을 안전하게 확인할 수 없습니다. 모든 Pi 세션을 찾으려면 sessionDir을 절대 경로로 설정하세요.", diff --git a/src/i18n/locales/ru.json b/src/i18n/locales/ru.json index 2620af005..896db3720 100644 --- a/src/i18n/locales/ru.json +++ b/src/i18n/locales/ru.json @@ -1443,6 +1443,7 @@ "searchSessions": "Поиск сессий", "sessionList": "Сессии", "unknownDirectory": "Неизвестный каталог", + "codexChats": "Чаты Codex", "batchDeleting": "Удаление...", "loadingSessions": "Загрузка сессий...", "piRelativeSessionDir": "Pi sessionDir задан относительно каталога запуска Pi, поэтому глобальный браузер не может безопасно перечислить сессии. Укажите абсолютный sessionDir, чтобы просматривать все сессии Pi здесь:", diff --git a/src/i18n/locales/tr.json b/src/i18n/locales/tr.json index 032d159ff..55d9fad1b 100644 --- a/src/i18n/locales/tr.json +++ b/src/i18n/locales/tr.json @@ -1377,6 +1377,7 @@ "searchSessions": "Oturumları ara", "sessionList": "Oturumlar", "unknownDirectory": "Bilinmeyen dizin", + "codexChats": "Codex sohbetleri", "batchDeleting": "Siliniyor...", "loadingSessions": "Oturumlar yükleniyor...", "piRelativeSessionDir": "Pi sessionDir, Pi'nin başlatıldığı dizine göredir, dolayısıyla genel bir tarayıcı onu güvenli bir şekilde numaralandıramaz. Burada tüm Pi oturumlarına göz atmak için mutlak bir sessionDir ayarlayın:", diff --git a/src/i18n/locales/zh-TW.json b/src/i18n/locales/zh-TW.json index 6fcedfca9..5784eddc3 100644 --- a/src/i18n/locales/zh-TW.json +++ b/src/i18n/locales/zh-TW.json @@ -1443,6 +1443,7 @@ "searchSessions": "搜尋工作階段", "sessionList": "工作階段清單", "unknownDirectory": "未知目錄", + "codexChats": "Codex 聊天", "batchDeleting": "批次刪除中...", "loadingSessions": "載入工作階段中...", "piRelativeSessionDir": "Pi 的 sessionDir 是相對於啟動 Pi 時所在的目錄,因此全域瀏覽器無法安全列舉。請將 sessionDir 設為絕對路徑,之後即可在此瀏覽所有 Pi 工作階段:", diff --git a/src/i18n/locales/zh.json b/src/i18n/locales/zh.json index ac101bec8..3a35f7980 100644 --- a/src/i18n/locales/zh.json +++ b/src/i18n/locales/zh.json @@ -1443,6 +1443,7 @@ "searchSessions": "搜索会话", "sessionList": "会话列表", "unknownDirectory": "未知目录", + "codexChats": "Codex 聊天", "batchDeleting": "删除中...", "loadingSessions": "加载会话中...", "piRelativeSessionDir": "Pi 的 sessionDir 相对于启动 Pi 时的目录,全局浏览器无法安全枚举。请改用绝对 sessionDir,之后即可在此浏览全部 Pi 会话:", diff --git a/tests/components/sessionUtils.test.ts b/tests/components/sessionUtils.test.ts index 55c5675da..fd96a8283 100644 --- a/tests/components/sessionUtils.test.ts +++ b/tests/components/sessionUtils.test.ts @@ -39,7 +39,7 @@ describe("session utils", () => { }, ]; - const groups = groupSessionsByProject(sessions, "未知目录"); + const groups = groupSessionsByProject(sessions, "未知目录", "Codex 聊天"); expect(groups.map((group) => group.label)).toEqual([ "docs", @@ -93,7 +93,7 @@ describe("session utils", () => { }, ]; - const groups = groupSessionsByProject(sessions, "未知目录"); + const groups = groupSessionsByProject(sessions, "未知目录", "Codex 聊天"); expect( groups.map((group) => [ @@ -107,6 +107,56 @@ describe("session utils", () => { ]); }); + it("folds Codex desktop project-less chats into one group", () => { + const sessions: SessionMeta[] = [ + { + providerId: "codex", + sessionId: "win-a", + projectDir: "C:\\Users\\me\\Documents\\Codex\\2026-11-10\\x20", + lastActiveAt: 40, + }, + { + providerId: "codex", + sessionId: "project", + projectDir: "C:\\work\\app", + lastActiveAt: 30, + }, + { + providerId: "codex", + sessionId: "win-b", + projectDir: "c:/users/me/documents/Codex/2026-10-30/wo-d/", + lastActiveAt: 20, + }, + { + providerId: "codex", + sessionId: "mac", + projectDir: "/Users/me/Documents/Codex/2026-09-20/s", + lastActiveAt: 10, + }, + { + providerId: "codex", + sessionId: "nested", + projectDir: "/Users/me/Documents/Codex/2026-09-20/s/work", + lastActiveAt: 5, + }, + ]; + + const groups = groupSessionsByProject(sessions, "未知目录", "Codex 聊天"); + + expect( + groups.map((group) => [ + group.label, + group.projectDir, + group.sessions.map((session) => session.sessionId), + ]), + ).toEqual([ + ["Codex 聊天", "C:\\Users\\me\\Documents\\Codex", ["win-a", "win-b"]], + ["app", "C:\\work\\app", ["project"]], + ["Codex 聊天", "/Users/me/Documents/Codex", ["mac"]], + ["work", "/Users/me/Documents/Codex/2026-09-20/s/work", ["nested"]], + ]); + }); + it("buckets sessions into today / yesterday / this week / earlier", () => { // 2026-10-01 is a Thursday; the week starts on Monday 2026-09-28 const now = new Date(2026, 9, 1, 8, 15).getTime();