From f4640c0aee5cd3a7c18b7ac2ab5e57ef8b15e05a Mon Sep 17 00:00:00 2001 From: yetone Date: Wed, 21 Oct 2026 18:16:41 +0800 Subject: [PATCH] sessions: an agent's folders are one list, newest first, the temporary ones folded at the end MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The Sessions page drew each folder as a boxed group with its checkbox, path and buttons always showing. Now it is one list, the way Finder's recents read: a row says the folder's name, where it is (home as ~, from the manage reply's new `home`), its newest session's title, when, and how many. Temporary folders, the disk's root and apps' hidden folders under home wait folded under Other folders at the end; a search or a session opened from elsewhere unfolds them. Checkboxes and the Delete bar come only with Select, and Done lets the pick go. Relocate project and Delete all sessions move into a folder's ⋯ menu (hover, always on touch, and right-click); Delete all asks in magpie's own dialog. Asked for by the owner ("这个会话页面其实特别丑"), who approved the design. Tests: sessions-folder-list.test.cjs (new) checks the order, the ~ path, the fold and its count, Select/Done, the ⋯ menu's Delete all and its ask, and no horizontal scroll, in Chromium and WebKit, en/zh/zh-TW/ja/de, at 1000 and 420px. The other sessions tests follow the ⋯ menu and Select. Run at this head (rebased on 17a2b00ef): - node --test, 37 GUI files (every sessions*/session*, i18n*, checkbox-look, account-mask-sessions, routing-session*, usage-session*): 493 pass, 0 fail. - gofmt -l internal/gui: clean; go vet -tags nogui ./internal/gui: ok; go test -tags nogui ./internal/gui: ok (budgets included). Not run: the whole GUI suite at this head. The last full run (183fa169b, 10-23) had its reds filed (#3402 to #3416 and earlier issues); none is a sessions file. Not tried in the Wails window on a real machine's sessions. --- docs/session-relocation.md | 2 +- docs/subsystems/gui-shell.md | 13 ++ .../gui/assets/plugins/sessions/client.js | 156 +++++++++++++++--- internal/gui/assets/plugins/sessions/i18n.js | 12 ++ .../gui/assets/plugins/sessions/sessions.css | 40 +++-- internal/gui/sessions_manage.go | 18 +- internal/gui/tests/checkbox-look.test.cjs | 1 + .../gui/tests/sessions-folder-delete.test.cjs | 5 +- .../gui/tests/sessions-folder-list.test.cjs | 143 ++++++++++++++++ .../gui/tests/sessions-folder-paging.test.cjs | 1 + .../tests/sessions-gateway-delete.test.cjs | 2 +- .../gui/tests/sessions-manage-paging.test.cjs | 1 + internal/gui/tests/sessions-manage.test.cjs | 7 +- internal/gui/tests/sessions-relocate.test.cjs | 18 +- .../gui/tests/sessions-wsl-delete.test.cjs | 2 + 15 files changed, 367 insertions(+), 54 deletions(-) create mode 100644 internal/gui/tests/sessions-folder-list.test.cjs diff --git a/docs/session-relocation.md b/docs/session-relocation.md index 075fa1f55..1756dfd8d 100644 --- a/docs/session-relocation.md +++ b/docs/session-relocation.md @@ -2,7 +2,7 @@ When a project folder is renamed or moved, Claude Code's saved sessions remain under the old encoded path in its `projects` directory. In **Sessions**, choose -**Claude Code**, then **Relocate project** beside the old folder. +**Claude Code**, then **Relocate project** in the old folder's ⋯ menu. 1. Close Claude Code and its editor sessions. Wait at least one minute after their last write. diff --git a/docs/subsystems/gui-shell.md b/docs/subsystems/gui-shell.md index 16feb1b34..275280611 100644 --- a/docs/subsystems/gui-shell.md +++ b/docs/subsystems/gui-shell.md @@ -207,6 +207,19 @@ under its id (`render`, #1835). The row itself keeps one line: the fullest window while idle, what it is doing while it answers. See `routing-seat-windows.test.cjs`. +### The Sessions page's folders + +The Sessions page lists an agent's project folders as one list, newest +session first ([`client.js`](../../internal/gui/assets/plugins/sessions/client.js)). +A row says the folder's name, the folder it is in (home as `~`, from the +manage reply's `home`), its newest session's title, when, and how many. +Temporary folders, the disk's root and apps' hidden folders under home +(`scratch`) wait folded under Other folders at the end; a search, or a +session opened from elsewhere, unfolds them. Checkboxes and the Delete bar +come only with Select, and Done lets the pick go. Relocate project and +Delete all sessions are in a folder's ⋯ menu, shown on hover (always on a +touch screen) and on a right-click. See `sessions-folder-list.test.cjs`. + ### Stored agent sessions in WSL The Sessions page uses `sessions.ListAgent`; Usage → Sessions uses diff --git a/internal/gui/assets/plugins/sessions/client.js b/internal/gui/assets/plugins/sessions/client.js index cefa57394..eadc160e7 100644 --- a/internal/gui/assets/plugins/sessions/client.js +++ b/internal/gui/assets/plugins/sessions/client.js @@ -32,6 +32,11 @@ magpie.plugin("sessions", (ctx) => { const SEARCH_WAIT = 300; const needleOf = (q) => q.trim().split(/\s+/).filter(Boolean).join(" ").toLowerCase(); let trashOn = false; + // Picking sessions to delete is a mode of its own, as in Finder and Mail: + // off, no row carries a checkbox and there is no bar over the list + // (yetone: a box on every row, and a lone Delete under the Trash). + let selecting = false; + let othersOpen = false; // the folders an app or the system made, unfolded const picked = new Set(); // ids picked to delete, of the agent shown const opened = new Set(); // folders unfolded, by cwd const folderBoxes = new Map(); // each folder's box as drawn, by cwd @@ -70,6 +75,7 @@ magpie.plugin("sessions", (ctx) => { // elements, held every click on the page for over a second, and slowed // the Library page after it (yetone). const FOLDERS = "\x00folders"; + const OTHERS = "\x00others"; // A session seen only through magpie's gateway has no folder magpie knows // (its agent's files are on another computer, in a container or under @@ -79,9 +85,34 @@ magpie.plugin("sessions", (ctx) => { const groupOf = (s) => s.cwd || (s.gateway ? GW : ""); const groupName = (k) => k === GW ? t("Seen through the gateway") : k ? baseName(k) : t("No folder"); + // A folder an app or the system made, not a project of the reader's: the + // disk's root, a temp folder, or one under a hidden folder of a home + // (~/.some-agent/…). They go under a fold of their own after the + // projects (yetone: "/", "T" and folders named by UUIDs led the list). + const scratch = (k) => { + if (!k || k === GW) return false; + const p = k.replace(/\\/g, "/").replace(/\/+$/, ""); + return p === "" || /^[a-z]:$/i.test(p) + || /^\/(private\/)?(tmp|var\/tmp|var\/folders)(\/|$)/.test(p) + || /\/AppData\/Local\/Temp(\/|$)/i.test(p) + || /^([a-z]:)?\/(Users|home)\/[^/]+\/\.[^/]/i.test(p) || /^\/root\/\./.test(p); + }; + // where a folder is, as its row says it: the folder it is in, with the + // home folder as ~; the whole path is the row's title + const whereOf = (p) => { + const home = data?.home || ""; + const up = p.replace(/[\\/]+$/, ""); + const cut = Math.max(up.lastIndexOf("/"), up.lastIndexOf("\\")); + if (home && up === home) return "~"; + const parent = cut < 0 ? "" : cut === 0 ? "/" : up.slice(0, cut); + if (!home || !parent) return parent; + return parent === home ? "~" : parent.startsWith(home + "/") || parent.startsWith(home + "\\") ? "~" + parent.slice(home.length) : parent; + }; + const TRASH = "M3 4.5h10M6.5 4.5V3h3v1.5M4.5 4.5l.6 8.5h5.8l.6-8.5M7 7v4M9 7v4"; const TERM = "M3 4.5 6 7.5 3 10.5M7.5 11.5h5.5"; const UNDO = "M5.5 3.5 2.5 6.5l3 3M2.5 6.5H10a3.5 3.5 0 0 1 0 7H7"; + const MOVE = "M2.5 8h10M9.5 5l3 3-3 3"; async function load(name) { const n = ++loading; @@ -234,6 +265,7 @@ magpie.plugin("sessions", (ctx) => { function chooseAgent(name) { if (name === data.agent && !trashOn) return; trashOn = false; + selecting = false; agent = name; try { localStorage.setItem("magpie.sessionsAgent", name); } catch {} picked.clear(); @@ -345,13 +377,22 @@ magpie.plugin("sessions", (ctx) => { q.hidden = trashOn; q.oninput = () => { query = q.value; drawnIn.clear(); searchSoon(); redrawList(); }; q.onkeydown = (e) => { if (e.key === "Escape" && q.value) { e.stopPropagation(); q.value = ""; query = ""; drawnIn.clear(); searchSoon(); redrawList(); } }; + const sel = el("button", "text sm-select" + (selecting ? " on" : ""), t(selecting ? "Done" : "Select")); + sel.type = "button"; + sel.setAttribute("aria-pressed", String(selecting)); + sel.hidden = trashOn || !a?.deletable || !data?.sessions?.some((s) => s.deletable); + sel.onclick = () => { + selecting = !selecting; + if (!selecting) picked.clear(); + draw(); + }; const tr = el("button", "text sm-trash-btn" + (trashOn ? " on" : "")); tr.type = "button"; tr.setAttribute("aria-pressed", String(trashOn)); tr.append(svg(TRASH, 13, 1.4), el("span", "", t("Trash"))); if (data?.trash.length) tr.append(el("em", "", String(data.trash.length))); - tr.onclick = () => { trashOn = !trashOn; draw(); }; - h.append(q, tr); + tr.onclick = () => { trashOn = !trashOn; selecting = false; picked.clear(); draw(); }; + h.append(q, sel, tr); return h; } @@ -509,11 +550,12 @@ magpie.plugin("sessions", (ctx) => { cancel.focus({ preventScroll: true }); } - // the bar over the tree: pick every session shown, and delete those picked + // the bar over the tree while picking: pick every session shown, and + // delete those picked function selectBar() { const bar = el("div", "row-head sm-bar"); const a = current(); - if (!a?.deletable) { bar.hidden = true; return bar; } + if (!a?.deletable || !selecting) { bar.hidden = true; return bar; } const list = shown().filter((s) => s.deletable); const all = el("input", "sm-check"); all.type = "checkbox"; @@ -551,12 +593,14 @@ magpie.plugin("sessions", (ctx) => { const bar = page.querySelector(".sm-bar"); if (bar) bar.replaceWith(selectBar()); const list = shown(); - // the folder of the latest session is open the first time an agent is shown + // the project of the latest session is open the first time an agent is + // shown if (openedFor !== data.agent) { openedFor = data.agent; opened.clear(); drawnIn.clear(); - if (list[0]) opened.add(groupOf(list[0])); + const first = list.find((s) => !scratch(groupOf(s))) || list[0]; + if (first) opened.add(groupOf(first)); } nest(list); // a session shown under another stays in sight: its folder and every @@ -582,15 +626,45 @@ magpie.plugin("sessions", (ctx) => { return; } const q = query.trim(); - const all = [...groups]; - // a page of folders, or as many as were drawn before, and down to the - // folder of the session opened to its details + // the projects in one list, and the folders apps and the system made + // folded under them + const all = [...groups].filter(([k]) => !scratch(k)); + const rest = [...groups].filter(([k]) => scratch(k)); + if (all.length) tree.append(folderList(el("div", "list sm-folders"), all, FOLDERS, q)); + if (rest.length) tree.append(othersBox(rest, q)); + toFocus(); + } + + // folderList draws into box a page of folders, or as many as were drawn + // before, and down to the folder of the session opened to its details + function folderList(box, all, key, q) { const top = rootOf.get(detail) || detail; const at = detail ? all.findIndex(([, items]) => items.some((s) => s.id === top)) : -1; - const n = Math.min(all.length, Math.max(drawnIn.get(FOLDERS) || SM_PAGE, at + 1)); - for (const [cwd, items] of all.slice(0, n)) tree.append(folder(cwd, items, q)); - if (n < all.length) tree.append(moreFolders(all, n, q)); - toFocus(); + const n = Math.min(all.length, Math.max(drawnIn.get(key) || SM_PAGE, at + 1)); + for (const [cwd, items] of all.slice(0, n)) box.append(folder(cwd, items, q)); + if (n < all.length) box.append(moreFolders(all, n, q, key)); + return box; + } + + // othersBox is the fold of the folders apps and the system made: shut + // until the reader opens it, a search finds something in it, or the + // session opened to its details is in it + function othersBox(rest, q) { + const box = el("div", "list sm-others"); + const top = rootOf.get(detail) || detail; + const open = othersOpen || !!q || (!!detail && rest.some(([, items]) => items.some((s) => s.id === top))); + const r = el("div", "row sm-others-row"); + const fold = el("button", "fold sm-others-fold"); + fold.type = "button"; + fold.setAttribute("aria-expanded", String(open)); + const words = el("span", "sm-fwords"); + words.append(el("span", "name", t("Other folders")), el("span", "sm-latest", t("Temporary folders, the disk's root and apps' hidden folders"))); + fold.append(svg(CHEV_R, 10, 1.6), words); + fold.onclick = () => { othersOpen = !open; redrawList(); }; + r.append(fold, el("span", "note", t(rest.length === 1 ? "{n} folder" : "{n} folders", { n: rest.length }))); + box.append(r); + if (open) folderList(box, rest, OTHERS, q); + return box; } // nest finds the sessions shown that are under another one shown: a @@ -619,8 +693,8 @@ magpie.plugin("sessions", (ctx) => { // moreFolders adds the next page of folders above itself, as moreRow does // a folder's sessions - function moreFolders(all, n, q) { - drawnIn.set(FOLDERS, n); + function moreFolders(all, n, q, key) { + drawnIn.set(key, n); const b = el("button", "text sess-page-more sm-more-folders"); b.type = "button"; b.dataset.unrolls = ""; // it goes down with the folders it opens @@ -631,16 +705,19 @@ magpie.plugin("sessions", (ctx) => { const next = Math.min(all.length, n + SM_PAGE); b.before(...all.slice(n, next).map(([cwd, items]) => folder(cwd, items, q))); n = next; - drawnIn.set(FOLDERS, n); + drawnIn.set(key, n); if (n >= all.length) b.remove(); else b.textContent = label(); }; return b; } + // A folder's row: its name and where it is, the latest session's title + // under them, and when that was and how many there are on the right. + // What can be done to the whole folder is in its ⋯ menu, shown on hover. function folder(cwd, items, q) { const open = !!q || opened.has(cwd); - const g = el("div", "list sm-group"); + const g = el("div", "sm-group"); const r = el("div", "row sm-folder"); // the sessions under those on top are the folder's too const members = []; @@ -649,7 +726,7 @@ magpie.plugin("sessions", (ctx) => { const writable = members.filter((s) => s.deletable); // the folder's box picks every session of it shown, folded or not, // for the bar's Delete; the bar still counts sessions (#527) - if (current()?.deletable && writable.length) { + if (selecting && current()?.deletable && writable.length) { const c = el("input", "sm-check sm-folder-check"); c.type = "checkbox"; // a session's own box ticked or not shows here at once @@ -670,20 +747,47 @@ magpie.plugin("sessions", (ctx) => { const fold = el("button", "fold"); fold.type = "button"; fold.setAttribute("aria-expanded", String(open)); - fold.append(svg(CHEV_R, 10, 1.6), el("span", "name", groupName(cwd))); + const path = cwd === GW ? "" : cwd; + const line = el("span", "sm-fline"); + line.append(el("span", "name", groupName(cwd))); + const where = path ? whereOf(path) : ""; + if (where) line.append(el("span", "sub sm-path", where)); + const words = el("span", "sm-fwords"); + words.append(line); + const latest = members.reduce((x, s) => (s.last || "") > (x.last || "") ? s : x, members[0]); + if (latest) words.append(el("span", "sm-latest", latest.title || t("(no prompt)"))); + fold.append(svg(CHEV_R, 10, 1.6), words); fold.onclick = () => { if (opened.has(cwd)) opened.delete(cwd); else opened.add(cwd); redrawList(); }; - const path = cwd === GW ? "" : cwd; - r.append(fold, el("span", "sub sm-path", path), el("span", "grow"), el("span", "note", t(members.length === 1 ? "{n} session" : "{n} sessions", { n: members.length }))); + const when = el("span", "sm-when"); + if (latest?.last) when.append(el("span", "sm-ago", ago(latest.last))); + when.append(el("span", "note", t(members.length === 1 ? "{n} session" : "{n} sessions", { n: members.length }))); + r.append(fold, when); + const acts = []; const allInFolder = (data.sessions || []).filter((s) => s.cwd === cwd); if (data.agent === "claude" && path && allInFolder.every((s) => !s.read_only && !s.gateway) && new Set(allInFolder.map((s) => s.wsl || "")).size === 1) { - const move = el("button", "text", t("Relocate project")); - move.type = "button"; - move.onclick = (e) => { e.stopPropagation(); askRelocate(cwd, allInFolder[0].wsl || ""); }; - r.append(move); + acts.push({ name: "Relocate project", icon: MOVE, run: () => askRelocate(cwd, allInFolder[0].wsl || "") }); + } + if (current()?.deletable && writable.length) { + acts.push({ name: "Delete all sessions", icon: TRASH, sep: acts.length > 0, run: () => askDelete(writable.map((s) => s.id), wholeFolder(writable.map((s) => s.id))) }); + } + if (acts.length) { + const more = el("button", "copy sm-folder-more"); + more.type = "button"; + more.title = t("More"); + more.setAttribute("aria-label", t("More")); + more.setAttribute("aria-haspopup", "menu"); + more.append(svg(DOTS, 14, 2)); + more.onclick = (e) => { + e.stopPropagation(); + if (more.classList.contains("open")) return closeAgentMenu(); + openRowMenu(more, acts); + }; + r.append(more); + r.oncontextmenu = (e) => { e.preventDefault(); openRowMenu(more, acts); }; } r.title = path; @@ -727,7 +831,7 @@ magpie.plugin("sessions", (ctx) => { wrap.dataset.depth = String(depth); const r = el("div", "row sess sm-sess"); r.dataset.id = s.id; - if (a?.deletable && s.deletable) { + if (selecting && a?.deletable && s.deletable) { const c = el("input", "sm-check"); c.type = "checkbox"; c.checked = picked.has(s.id); diff --git a/internal/gui/assets/plugins/sessions/i18n.js b/internal/gui/assets/plugins/sessions/i18n.js index 0547169f3..5c0253d18 100644 --- a/internal/gui/assets/plugins/sessions/i18n.js +++ b/internal/gui/assets/plugins/sessions/i18n.js @@ -2,6 +2,9 @@ // kernel adds them to i18n.js's (magpie.strings). magpie.strings({ zh: { + "Other folders": "其他文件夹", + "Temporary folders, the disk's root and apps' hidden folders": "临时文件夹、磁盘根目录和应用的隐藏文件夹", + "Delete all sessions": "删除全部会话", "{n} subagent": "{n} 个子代理", "{n} subagents": "{n} 个子代理", "Relocate project": "迁移项目会话", @@ -71,6 +74,9 @@ magpie.strings({ "Searched what was said in the latest {n} of {total} sessions.": "已搜索最近 {n} 个会话的对话内容(共 {total} 个)。", }, "zh-TW": { + "Other folders": "其他資料夾", + "Temporary folders, the disk's root and apps' hidden folders": "暫存資料夾、磁碟根目錄和應用程式的隱藏資料夾", + "Delete all sessions": "刪除全部會話", "{n} subagent": "{n} 個子代理", "{n} subagents": "{n} 個子代理", "Relocate project": "遷移專案會話", @@ -140,6 +146,9 @@ magpie.strings({ "Searched what was said in the latest {n} of {total} sessions.": "已搜尋最近 {n} 個會話的對話內容(共 {total} 個)。", }, ja: { + "Other folders": "その他のフォルダ", + "Temporary folders, the disk's root and apps' hidden folders": "一時フォルダ、ディスクのルート、アプリの隠しフォルダ", + "Delete all sessions": "すべてのセッションを削除", "{n} subagent": "{n} 個のサブエージェント", "{n} subagents": "{n} 個のサブエージェント", "Relocate project": "プロジェクトを移動", @@ -209,6 +218,9 @@ magpie.strings({ "Searched what was said in the latest {n} of {total} sessions.": "最新 {n} 件の会話の内容を検索しました(全 {total} 件)。", }, de: { + "Other folders": "Weitere Ordner", + "Temporary folders, the disk's root and apps' hidden folders": "Temporäre Ordner, das Stammverzeichnis und versteckte Ordner von Apps", + "Delete all sessions": "Alle Sitzungen löschen", "{n} subagent": "{n} Subagent", "{n} subagents": "{n} Subagenten", "Relocate project": "Projekt verschieben", diff --git a/internal/gui/assets/plugins/sessions/sessions.css b/internal/gui/assets/plugins/sessions/sessions.css index b6562a6d5..86979dee3 100644 --- a/internal/gui/assets/plugins/sessions/sessions.css +++ b/internal/gui/assets/plugins/sessions/sessions.css @@ -31,13 +31,32 @@ .sm-check { flex: none; margin: 0; width: 14px; height: 14px; accent-color: var(--accent); } .sm-tree { display: flex; flex-direction: column; gap: 8px; } .sm-group .skeleton.sk-line { width: 60%; height: 12px; } -.row.sm-folder { min-height: 34px; gap: 8px; } -.row.sm-folder .fold { color: var(--fg-2); font-weight: 500; flex: none; max-width: 45%; } -.row.sm-folder .fold .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } -.row.sm-folder .sm-path { flex: 0 1 auto; min-width: 0; margin: 0; font-family: var(--code-font, var(--code)); font-size: 10.5px; color: var(--faint); } -:where(html[data-fonts]) .row.sm-folder .sm-path { font-style: var(--code-style, inherit); font-weight: var(--code-weight, inherit); font-stretch: var(--code-stretch, 100%); } -.row.sm-folder .grow { flex: 1; } -.row.sm-folder .note { flex: none; font-size: 11px; color: var(--faint); font-variant-numeric: tabular-nums; } +.sm-select.on { background: var(--pill); color: var(--fg); } +/* the folders are one list, parted by hairlines, never a card each; the + sessions of an open one go on in it, set in under its name */ +.sm-folders > .sm-group + .sm-group, .sm-folders > .sm-group + .sm-more-folders, +.sm-others > .sm-group, .sm-others > .sm-more-folders { border-top: 1px solid var(--line-2); } +.sm-group > .row.sm-folder + .sm-item { border-top: 1px solid var(--line-2); } +.sm-tree .sm-more-folders { margin: 6px 11px; } +.row.sm-folder, .row.sm-others-row { min-height: 44px; gap: 8px; } +.row.sm-folder .fold, .row.sm-others-row .fold { flex: 1; min-width: 0; margin: 0 0 0 -4px; padding: 4px 6px 4px 4px; gap: 8px; text-align: left; color: var(--faint); } +.row.sm-folder .fold:hover, .row.sm-others-row .fold:hover { background: none; } +.row.sm-folder:hover, .row.sm-others-row:hover { background: color-mix(in srgb, var(--pill) 40%, transparent); } +.sm-fwords { min-width: 0; flex: 1; display: flex; flex-direction: column; gap: 1px; } +.sm-fline { min-width: 0; display: flex; align-items: baseline; gap: 8px; } +.sm-fline .name, .sm-others-row .name { flex: none; max-width: 60%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; font-weight: 500; color: var(--fg); } +.row.sm-folder .sm-path { flex: 0 1 auto; min-width: 0; margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 11.5px; color: var(--faint); } +.sm-latest { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; color: var(--muted); } +.sm-when { flex: none; display: flex; flex-direction: column; align-items: flex-end; gap: 1px; } +.sm-when .sm-ago { font-size: 11.5px; color: var(--muted); white-space: nowrap; } +.row.sm-folder .note, .row.sm-others-row .note { flex: none; font-size: 11px; color: var(--faint); font-variant-numeric: tabular-nums; white-space: nowrap; } +/* what can be done to a whole folder waits under ⋯ until the row is pointed at */ +.sm-folder-more { flex: none; opacity: 0; transition: opacity .12s; } +.row.sm-folder:hover .sm-folder-more, .row.sm-folder:focus-within .sm-folder-more, .sm-folder-more.open { opacity: 1; } +@media (hover: none) { .sm-folder-more { opacity: 1; } } +.sm-group .row.sm-sess { padding-left: 29px; } +body.window .sm-group .row.sm-sess { padding-left: 32px; } +.sm-others { margin-top: 4px; } .row.sm-sess { min-height: 44px; } .sm-item .sess-detail { padding-left: 34px; } .row.sess .sm-del:hover { color: var(--red); background: var(--red-soft); } @@ -67,11 +86,12 @@ .row.sess.sm-sess { gap: 8px; } } @media (max-width: 420px) { - .sm-head { display: grid; grid-template-columns: minmax(0, 1fr) auto; row-gap: 6px; } + .sm-head { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; row-gap: 6px; } .sm-switch { grid-column: 1 / -1; } .sm-agent-pick { max-width: 100%; } - .sm-filter { width: 100%; min-width: 0; } - .sm-trash-btn { grid-column: 2; justify-self: end; } + .sm-filter { grid-column: 1; grid-row: 2; width: 100%; min-width: 0; } + .sm-select { grid-column: 2; grid-row: 2; } + .sm-trash-btn { grid-column: 3; grid-row: 2; justify-self: end; } } /* Codex sessions made with another provider, hidden from Codex's history (#887) */ .row.sm-provider { gap: 10px; min-height: 40px; padding: 8px 11px; height: auto; } diff --git a/internal/gui/sessions_manage.go b/internal/gui/sessions_manage.go index 7ec415175..410a18b5c 100644 --- a/internal/gui/sessions_manage.go +++ b/internal/gui/sessions_manage.go @@ -6,6 +6,7 @@ import ( "encoding/json" "errors" "net/http" + "os" "runtime" "sort" "sync" @@ -117,18 +118,21 @@ func sessionManageRoutes(mux *http.ServeMux, w Windows) { mux.HandleFunc("GET /api/sessions/manage", func(rw http.ResponseWriter, r *http.Request) { looks := agentLooks() out := struct { - Agents []manageAgentJSON `json:"agents"` - Agent string `json:"agent"` - Sessions []managedJSON `json:"sessions"` - Terminal bool `json:"terminal"` - Trash []trashedJSON `json:"trash"` - TrashDir string `json:"trashDir"` - Recording bool `json:"recording"` + Agents []manageAgentJSON `json:"agents"` + Agent string `json:"agent"` + Sessions []managedJSON `json:"sessions"` + Terminal bool `json:"terminal"` + Trash []trashedJSON `json:"trash"` + TrashDir string `json:"trashDir"` + // Home: the home folder, which a folder's row says as ~ + Home string `json:"home,omitempty"` + Recording bool `json:"recording"` // Recorded: some gateway conversation text is kept, to delete Recorded bool `json:"recorded"` }{Agents: []manageAgentJSON{}, Sessions: []managedJSON{}, Terminal: runtime.GOOS == "darwin" && !isWeb(w), Trash: trashJSON(looks), TrashDir: tilde(sessions.TrashDir()), Recording: settings.Load().GatewayConversations, Recorded: sessions.HasGatewayConversations()} + out.Home, _ = os.UserHomeDir() want := r.URL.Query().Get("agent") gateway := listedGateway(usage.GatewaySessions(time.Time{}, nil)) // a gateway session its agent keeps too is counted once; only the diff --git a/internal/gui/tests/checkbox-look.test.cjs b/internal/gui/tests/checkbox-look.test.cjs index 6189d3b5e..c898f4b48 100644 --- a/internal/gui/tests/checkbox-look.test.cjs +++ b/internal/gui/tests/checkbox-look.test.cjs @@ -97,6 +97,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", await page.locator("#nav").getByRole("button", { name: nav[lang], exact: true }).click(); const view = page.locator("#view-sessions"); await view.locator('.row.sm-sess[data-id="a-login"]').waitFor(); + await view.locator(".sm-select").click(); // read once the box's own transitions end: reduced motion makes every // transition .01ms, not none, and Chromium under load can still show // one at its start two frames after the click diff --git a/internal/gui/tests/sessions-folder-delete.test.cjs b/internal/gui/tests/sessions-folder-delete.test.cjs index 5a64af94f..94d8905c4 100644 --- a/internal/gui/tests/sessions-folder-delete.test.cjs +++ b/internal/gui/tests/sessions-folder-delete.test.cjs @@ -159,7 +159,10 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", await ask.waitFor(); }; - // every folder starts with its box, before its name, inside its row + // no box until Select; then every folder starts with its box, + // before its name, inside its row + assert.equal(await view.locator(".sm-check, .sm-folder-check").count(), 0, "no boxes before Select"); + await view.locator(".sm-select").click(); const boxes = view.locator(".row.sm-folder input.sm-folder-check"); assert.equal(await boxes.count(), 3); for (const b of await boxes.all()) { diff --git a/internal/gui/tests/sessions-folder-list.test.cjs b/internal/gui/tests/sessions-folder-list.test.cjs new file mode 100644 index 000000000..3668d0207 --- /dev/null +++ b/internal/gui/tests/sessions-folder-list.test.cjs @@ -0,0 +1,143 @@ +// Run with Node's test runner and Playwright on the module path; see README.md. +// The Sessions page lists project folders as one list, newest first: each +// row has the folder's name, where it is (home said as ~), its newest +// session's title, when and how many. Temporary folders, the disk's root and +// apps' hidden folders wait folded under Other folders at the end. Boxes and +// the Delete bar come with Select; a folder's Delete all is in its ⋯ menu and +// asks in magpie's own dialog. In every language, Chromium and WebKit, wide +// and narrow; no backend, the API is faked here. +const assert = require("node:assert/strict"); +const fs = require("node:fs/promises"); +const path = require("node:path"); +const { test } = require("node:test"); +const { chromium, webkit } = require("playwright"); + +const assets = path.resolve(__dirname, "../assets"); +const at = (min) => new Date(Date.now() - min * 60e3).toISOString(); +const sess = (id, cwd, title, min) => ({ + agent: "claude", id, cwd, title, start: at(min + 5), last: at(min), models: [], + resume: `cd ${cwd} && claude --resume ${id}`, path: `~/.claude/projects/x/${id}.jsonl`, size: 1024, messages: 4, files: 1, deletable: true, +}); + +function serve(lang, calls) { + let sessions = [ + sess("t-1", "/private/var/folders/15/p0yq/T", "make a commit message", 10), + sess("a-1", "/home/me/work/app", "fix the login", 20), + sess("r-1", "/", "summarize a file", 25), + sess("a-2", "/home/me/work/app", "add tests", 40), + sess("h-1", "/home/me/.yansu-agent/chats/1784", "hello", 50), + sess("b-1", "/home/me/blog", "write the post", 300), + ]; + return async (route) => { + const req = route.request(), url = new URL(req.url()); + const json = (data) => route.fulfill({ json: data }); + if (url.pathname === "/boot.js") return route.fulfill({ contentType: "text/javascript", body: `window.bootPrefs = {lang:"${lang}",theme:"light",web:true};` }); + if (url.pathname === "/wails/runtime.js") return route.fulfill({ contentType: "text/javascript", body: "export const Window = {};" }); + if (url.pathname === "/api/state") return json({ agents: [], profiles: [], settings: { lang, theme: "light" } }); + if (url.pathname === "/api/plugins") return json({ plugins: [] }); + if (url.pathname === "/api/groups") return json({ groups: [] }); + if (url.pathname === "/api/providers") return json({ providers: [], presets: [], excluded: [], gateway: { running: true, window: true } }); + if (url.pathname === "/api/sessions/manage") { + return json({ agents: [{ agent: "claude", count: sessions.length, deletable: true, name: "Claude Code", icon: "claude" }], + agent: "claude", home: "/home/me", sessions, terminal: false, trash: [], trashDir: "~/.local/share/magpie/trash/sessions" }); + } + if (url.pathname === "/api/sessions/delete") { + const body = req.postDataJSON(); + calls.push(body); + sessions = sessions.filter((s) => !body.ids.includes(s.id)); + return json({ deleted: body.ids, refused: [] }); + } + if (url.pathname.startsWith("/api/")) return json({}); + const file = path.join(assets, url.pathname === "/" ? "index.html" : url.pathname); + const contentType = { ".html": "text/html", ".js": "text/javascript", ".css": "text/css", ".svg": "image/svg+xml", ".png": "image/png" }[path.extname(file)]; + try { await route.fulfill({ body: await fs.readFile(file), contentType }); } catch { await route.fulfill({ status: 404, body: "" }); } + }; +} + +const keys = ["Other folders", "Temporary folders, the disk's root and apps' hidden folders", "Delete all sessions", "Select", "Done", "More", "{n} folders"]; + +for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) { + for (const lang of ["en", "zh", "zh-TW", "ja", "de"]) { + for (const width of [1000, 420]) { + test(`${engine} ${lang} ${width}px: folders are one list, the temporary ones folded at the end`, async (t) => { + const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" })); + const page = await (await browser.newContext({ viewport: { width, height: 700 }, reducedMotion: "reduce" })).newPage(); + t.after(async () => { + if (process.env.ARTIFACT_DIR) { + await fs.mkdir(process.env.ARTIFACT_DIR, { recursive: true }); + await page.screenshot({ path: path.join(process.env.ARTIFACT_DIR, `${engine}-${lang}-${width}-sessions-folder-list.png`) }); + } + await browser.close(); + }); + page.setDefaultTimeout(5000); + const errors = []; + page.on("pageerror", (e) => errors.push(e.message)); + page.on("dialog", (d) => { errors.push("a browser dialog: " + d.message()); d.dismiss(); }); + const calls = []; + await page.route("**/*", serve(lang, calls)); + await page.goto("http://magpie.test/?view=providers"); + await page.evaluate(() => show("sessions")); + const view = page.locator("#view-sessions"); + const tr = (k, vars) => page.evaluate(([k, vars]) => t(k, vars), [k, vars]); + const folders = view.locator(".sm-folders .row.sm-folder"); + await folders.first().waitFor(); + + if (lang !== "en") { + const missing = await page.evaluate(([lang, keys]) => keys.filter((k) => !I18N[lang][k]), [lang, keys]); + assert.deepEqual(missing, [], `${lang} has every string`); + } + + // the projects, newest first; the newest open + assert.deepEqual(await folders.locator(".fold .name").allTextContents(), ["app", "blog"]); + const app = folders.nth(0); + assert.equal(await app.locator(".fold").getAttribute("aria-expanded"), "true"); + assert.equal(await app.locator(".sm-latest").textContent(), "fix the login"); + assert.notEqual((await app.locator(".sm-ago").textContent()).trim(), ""); + assert.equal(await app.getAttribute("title"), "/home/me/work/app"); + if (width > 560) assert.equal(await app.locator(".sm-path").textContent(), "~/work"); + + // the rest folded at the end, saying how many + const others = view.locator(".sm-others"); + assert.equal(await others.locator(".sm-others-fold .name").textContent(), await tr("Other folders")); + assert.equal((await others.locator(".sm-others-row > .note").textContent()).trim(), await tr("{n} folders", { n: 3 })); + assert.equal(await others.locator(".sm-others-fold").getAttribute("aria-expanded"), "false"); + assert.equal(await others.locator(".row.sm-folder").count(), 0); + await others.locator(".sm-others-fold").click(); + assert.deepEqual(await others.locator(".row.sm-folder .fold .name").allTextContents(), ["T", "/", "1784"]); + + // no boxes, no bar until Select; Done puts them away and the pick + assert.equal(await view.locator(".sm-check, .sm-folder-check").count(), 0); + assert(!(await view.locator(".sm-bar").isVisible())); + const sel = view.locator(".sm-select"); + assert.equal((await sel.textContent()).trim(), await tr("Select")); + await sel.click(); + assert.equal((await sel.textContent()).trim(), await tr("Done")); + assert.equal(await sel.getAttribute("aria-pressed"), "true"); + assert(await view.locator(".sm-bar").isVisible()); + await app.locator(".sm-folder-check").check(); + await sel.click(); + assert.equal(await view.locator(".sm-check, .sm-folder-check").count(), 0); + await sel.click(); + assert.equal(await app.locator(".sm-folder-check").isChecked(), false, "Done let the pick go"); + await sel.click(); + + // ⋯ → Delete all sessions asks, then deletes the folder's sessions + await app.hover(); + await app.locator(".sm-folder-more").click(); + await page.locator(".row-menu").getByRole("menuitem", { name: await tr("Delete all sessions"), exact: true }).click(); + const ask = page.locator("#modal .sm-ask"); + await ask.waitFor(); + assert.equal((await ask.locator(".sm-ask-path").textContent()).trim(), "/home/me/work/app"); + assert.deepEqual(calls, []); + await ask.getByRole("button", { name: await tr("Delete"), exact: true }).click(); + await ask.waitFor({ state: "detached" }); + await page.waitForFunction(() => !document.querySelector('#view-sessions .row.sm-sess[data-id="a-1"]')); + assert.deepEqual(calls.map((c) => [...c.ids].sort()), [["a-1", "a-2"]]); + + const wide = await page.evaluate(() => document.documentElement.scrollWidth > innerWidth); + assert.equal(wide, false, "nothing runs past the window"); + assert.deepEqual(errors, []); + }); + } + } +} diff --git a/internal/gui/tests/sessions-folder-paging.test.cjs b/internal/gui/tests/sessions-folder-paging.test.cjs index 4ef85c666..77ead75ae 100644 --- a/internal/gui/tests/sessions-folder-paging.test.cjs +++ b/internal/gui/tests/sessions-folder-paging.test.cjs @@ -111,6 +111,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", await page.mouse.move(width / 2, 320); await page.mouse.wheel(0, -40000); await page.waitForFunction(() => document.querySelector("#view-sessions").scrollTop === 0); + await view.locator(".sm-select").click(); await view.locator(".sm-bar .sm-check").check(); assert.equal(await view.locator(".sm-bar .sm-count").textContent(), w.all); await view.locator(".sm-bar .sm-check").uncheck(); diff --git a/internal/gui/tests/sessions-gateway-delete.test.cjs b/internal/gui/tests/sessions-gateway-delete.test.cjs index ca90092aa..d8c2cf862 100644 --- a/internal/gui/tests/sessions-gateway-delete.test.cjs +++ b/internal/gui/tests/sessions-gateway-delete.test.cjs @@ -97,7 +97,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", // grouped as seen through the gateway, with no path const folder = view.locator(".sm-folder").first(); assert.equal((await folder.locator(".fold .name").textContent()).trim(), await tr(KEYS.seen)); - assert.equal((await folder.locator(".sm-path").textContent()).trim(), ""); + assert.equal(await folder.locator(".sm-path").count(), 0); // what magpie recorded is its size; nothing recorded says no size at all const subA = (await rowA.locator(".sub").first().textContent()); assert(subA.includes(await tr(KEYS.size, { size: "2 KB" })) || subA.includes(await tr(KEYS.size, { size: "2.0 KB" })), `recorded size in ${subA}`); diff --git a/internal/gui/tests/sessions-manage-paging.test.cjs b/internal/gui/tests/sessions-manage-paging.test.cjs index 170b2bc2a..6cb6272c8 100644 --- a/internal/gui/tests/sessions-manage-paging.test.cjs +++ b/internal/gui/tests/sessions-manage-paging.test.cjs @@ -122,6 +122,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", assert.equal(await rows.count(), 100); // the folder's box and the bar pick every session, drawn or not + await view.locator(".sm-select").click(); await view.locator(".sm-folder-check").first().check(); assert.equal(await view.locator(".sm-bar .sm-count").textContent(), w.picked); await view.locator(".sm-bar .sm-check").check(); diff --git a/internal/gui/tests/sessions-manage.test.cjs b/internal/gui/tests/sessions-manage.test.cjs index 02da50e44..613bf908e 100644 --- a/internal/gui/tests/sessions-manage.test.cjs +++ b/internal/gui/tests/sessions-manage.test.cjs @@ -173,7 +173,11 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", // the id's line is named for it (#465: it read 整个会话, the routing option's word) assert((await view.locator(".sess-detail .sess-line .k").allInnerTexts()).includes(w.idLine)); - // picking: two rows, the page held still + // picking: Select brings the boxes; two rows, the page held still + assert.equal(await view.locator(".sm-check").count(), 0, "no boxes before Select"); + assert(!(await view.locator(".sm-bar").isVisible()), "no bar before Select"); + await reach(view.locator(".sm-select")); + await view.locator(".sm-select").click(); await still(row("a-old"), "picking", () => row("a-old").locator(".sm-check").click()); await reach(row("b-1")); await row("b-1").locator(".sm-check").click(); @@ -241,6 +245,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", await view.locator('.row.sm-sess[data-id="o-1"]').waitFor(); assert.equal((await view.locator(".sm-note").textContent()).trim(), w.cant); assert.equal(await view.locator(".sm-del, .sm-check").count(), 0); + assert(!(await view.locator(".sm-select").isVisible()), "no Select where nothing can be deleted"); assert(!(await view.locator(".sm-bar").isVisible())); const mutationCount = calls.length; await view.locator(".sm-agents .opt", { hasText: "Hermes" }).click(); diff --git a/internal/gui/tests/sessions-relocate.test.cjs b/internal/gui/tests/sessions-relocate.test.cjs index b0f1e1d84..80307f66b 100644 --- a/internal/gui/tests/sessions-relocate.test.cjs +++ b/internal/gui/tests/sessions-relocate.test.cjs @@ -1,7 +1,7 @@ // Run with Node's test runner and Playwright on the module path; see README.md. // A Claude Code project folder renamed or moved (#1131): its row on the -// Sessions page has Relocate project, which opens magpie's own dialog (never -// prompt()) with the old path and a field for the new one. Preview posts +// Sessions page has Relocate project in its ⋯ menu, which opens magpie's +// own dialog (never prompt()) with the old path and a field for the new one. Preview posts // sessions/relocate-claude with no token and says what would move; the same // button then confirms with the preview's token, and editing the path first // asks for a new preview. A folder with a session magpie can't write, or a @@ -98,14 +98,18 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", assert.deepEqual(missing, [], `${lang} has every string`); } + // Relocate is in the folder's ⋯ menu; a read-only folder has none const relocate = await tr("Relocate project"); - assert.equal(await folder("desk").getByRole("button", { name: relocate }).count(), 0, "no Relocate where a session is read-only"); - const move = folder("old-app").getByRole("button", { name: relocate, exact: true }); - await move.scrollIntoViewIfNeeded(); - const box = await move.boundingBox(); - assert(box && box.x + box.width <= width, "Relocate fits in the row"); + assert.equal(await folder("desk").locator(".sm-folder-more").count(), 0, "no Relocate where a session is read-only"); + const more = folder("old-app").locator(".sm-folder-more"); + await more.scrollIntoViewIfNeeded(); + await folder("old-app").hover(); + const box = await more.boundingBox(); + assert(box && box.x + box.width <= width, "the ⋯ fits in the row"); const open0 = await folder("old-app").locator(".fold").getAttribute("aria-expanded"); const y0 = await page.evaluate(() => document.querySelector("#view-sessions").scrollTop); + await more.click(); + const move = page.locator(".row-menu").getByRole("menuitem", { name: relocate, exact: true }); await move.click(); const ask = page.locator("#modal .sm-ask"); await ask.waitFor(); diff --git a/internal/gui/tests/sessions-wsl-delete.test.cjs b/internal/gui/tests/sessions-wsl-delete.test.cjs index f9674455d..1e564b238 100644 --- a/internal/gui/tests/sessions-wsl-delete.test.cjs +++ b/internal/gui/tests/sessions-wsl-delete.test.cjs @@ -79,6 +79,8 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", assert.equal(await row.locator(".badge.wsl").textContent(), "WSL Ubuntu"); assert.equal(await view.locator(".sm-note", { hasText: w.note }).count(), 0, "no note that WSL's can't be deleted"); + assert.equal(await view.locator(".sm-bar").isHidden(), true, "no bar before Select"); + await view.locator(".sm-select").click(); assert.equal(await view.locator(".sm-bar").isHidden(), false); const folderBox = view.locator(".row.sm-folder input.sm-folder-check"); assert.equal(await folderBox.count(), 1);