diff --git a/internal/gui/assets/plugins/sessions/client.js b/internal/gui/assets/plugins/sessions/client.js index 5de58794f..aebbbf204 100644 --- a/internal/gui/assets/plugins/sessions/client.js +++ b/internal/gui/assets/plugins/sessions/client.js @@ -284,22 +284,31 @@ magpie.plugin("sessions", (ctx) => { const wrap = page.querySelector(".sm-switch"); const tabs = wrap.querySelector(".sm-agents"); const pick = wrap.querySelector(".sm-agent-pick"); + const filter = page.querySelector(".sm-filter"); const fit = () => { + filter.style.flexBasis = ""; const room = parseFloat(getComputedStyle(wrap).width); if (!room) return; const focused = document.activeElement; // Measure the actual labels, including language, font and text zoom, // rather than guessing a breakpoint or a number of agents. tabs.hidden = false; - const compact = tabs.scrollWidth > Math.floor(room); + // the search gives way to the tabs, down to its least, before the menu + // takes them (Settings › came into the head beside them) + // (a narrow window's head is a grid, where it can't) + const over = tabs.scrollWidth - Math.floor(room); + const fw = getComputedStyle(filter.parentElement).display === "flex" ? filter.offsetWidth : 0; + const compact = over > 0 && (!fw || fw - over < 110); + if (over > 0 && !compact) filter.style.flexBasis = Math.ceil(fw - over) + "px"; tabs.hidden = compact || !data?.agents.length; pick.hidden = !compact || !current(); if (!compact && pick.classList.contains("open")) closeProtoMenu(); if (compact && tabs.contains(focused)) pick.focus({ preventScroll: true }); else if (!compact && focused === pick) tabs.querySelector(".on")?.focus({ preventScroll: true }); }; + // the head, not the tabs' box, which the search's width changes fitObserver = new ResizeObserver(fit); - fitObserver.observe(wrap); + fitObserver.observe(page.querySelector(".sm-head")); fit(); if (keepFocus) (pick.hidden ? tabs.querySelector(".on") : pick)?.focus({ preventScroll: true }); } @@ -513,7 +522,14 @@ magpie.plugin("sessions", (ctx) => { 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; selecting = false; picked.clear(); draw(); }; - h.append(q, sel, tr); + // which agents' history is read is Settings › Privacy's (the scattered + // settings audit after netube99 on X); gateway mode reads none there + const go = el("button", "text sm-toset"); + go.type = "button"; + go.append(el("span", "", t("Settings")), " ›"); + go.hidden = !!data?.reads?.gateway; + go.onclick = (e) => openSettingsAt(e, "privacy", "#sessionReadsList .row"); + h.append(q, sel, tr, go); return h; } diff --git a/internal/gui/assets/plugins/sessions/sessions.css b/internal/gui/assets/plugins/sessions/sessions.css index abfb8df4b..bc9d0d0dd 100644 --- a/internal/gui/assets/plugins/sessions/sessions.css +++ b/internal/gui/assets/plugins/sessions/sessions.css @@ -19,6 +19,7 @@ .sm-filter { width: 200px; flex: 0 1 200px; min-width: 110px; } .sm-trash-btn { display: inline-flex; align-items: center; gap: 5px; flex: none; } .sm-trash-btn.on { background: var(--pill); color: var(--fg); } +.sm-toset { flex: none; white-space: nowrap; } .sm-body { display: flex; flex-direction: column; gap: 8px; flex: none; } .sm-note { margin: 0 2px; } /* where a session said what was searched for, the words themselves marked */ @@ -114,12 +115,13 @@ body.window .sm-group .row.sm-sess { padding-left: 32px; } .row.sm-sess .cost { min-width: 58px; } } @media (max-width: 420px) { - .sm-head { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; row-gap: 6px; } + .sm-head { display: grid; grid-template-columns: minmax(0, 1fr) auto auto auto; row-gap: 6px; } .sm-switch { grid-column: 1 / -1; } .sm-agent-pick { max-width: 100%; } .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; } + .sm-toset { grid-column: 4; grid-row: 2; } } /* 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/assets/plugins/sessions/settings.js b/internal/gui/assets/plugins/sessions/settings.js index a6830d6f8..62bea7dea 100644 --- a/internal/gui/assets/plugins/sessions/settings.js +++ b/internal/gui/assets/plugins/sessions/settings.js @@ -88,7 +88,10 @@ function renderSessionReads(s) { rw.dataset.agent = a.agent; rows.push(rw); } + // a row lit by a link (openSettingsAt) keeps its light through the read + const lit = [...box.children].findIndex((e) => e.classList.contains("flash")); box.replaceChildren(...rows); + if (lit >= 0) rows[lit]?.classList.add("flash"); } function loadSessionReads() { const n = ++sessionReadsSeq; diff --git a/internal/gui/tests/sessions-to-settings.test.cjs b/internal/gui/tests/sessions-to-settings.test.cjs new file mode 100644 index 000000000..67f0189c7 --- /dev/null +++ b/internal/gui/tests/sessions-to-settings.test.cjs @@ -0,0 +1,91 @@ +// Run with Node's test runner and Playwright on the module path; see README.md. +// Which agents' session history magpie reads is set in Settings › Privacy, +// and the Sessions page it is about didn't lead there once its first ask was +// answered (the scattered settings audit after netube99 on X). Its head now +// has a Settings › that opens Privacy at those rows, lit, with Back to +// Sessions; gateway mode, which reads no agent's history, has none. Every +// language, Chromium and WebKit, at 1100 and 420 wide, nothing past the +// window's edge or over the head's other buttons. +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(); + +function serve(lang, gateway) { + const settings = { lang, theme: "light", gatewayOn: gateway, sessionReads: { asked: true, all: true }, lanURLs: [], fx: { rate: 7.2, at: new Date().toISOString() } }; + const reads = { asked: true, all: true, found: gateway ? [] : [{ agent: "claude", name: "Claude Code", icon: "claude", on: true }], gateway }; + 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:false,textSize:100};` }); + 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 }); + if (url.pathname === "/api/settings") return json(settings); + if (url.pathname === "/api/plugins") return json({ plugins: [] }); + if (url.pathname === "/api/groups") return json({ groups: [], models: [] }); + if (url.pathname === "/api/providers") return json({ providers: [], presets: [], excluded: [] }); + if (url.pathname === "/api/sessions/reads") return json(reads); + if (url.pathname === "/api/sessions/manage") { + const rows = [{ agent: "claude", id: "s1", cwd: "/srv/app", title: "rename foo to bar", start: at(10), last: at(5), models: [], resume: "", size: 10, messages: 2, files: 0, deletable: true, gateway }]; + return json({ agents: [{ agent: "claude", count: 1, deletable: true, name: "Claude Code", icon: "claude" }], agent: "claude", sessions: rows, terminal: false, trash: [], trashDir: "", recording: true, reads }); + } + if (url.pathname === "/api/window/fit") return route.fulfill({ status: 204 }); + 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 fits = (page) => page.evaluate(() => document.documentElement.scrollWidth <= document.documentElement.clientWidth + 1); + +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 [1100, 420]) { + test(`${engine} ${lang} ${width}: Sessions leads to Settings › Privacy's session history`, async (t) => { + const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" })); + t.after(() => browser.close()); + const open = async (gateway) => { + const page = await (await browser.newContext({ viewport: { width, height: 760 }, reducedMotion: "reduce" })).newPage(); + page.setDefaultTimeout(6000); + page.setDefaultNavigationTimeout(60000); + page.errors = []; + page.on("pageerror", (e) => { if (engine === "webkit" && /due to access control checks/.test(e.message)) return; page.errors.push(e.message); }); + await page.route("**/*", serve(lang, gateway)); + await page.goto("http://magpie.test/?view=sessions"); + await page.locator(".sm-head .sm-trash-btn").waitFor(); + return page; + }; + const tr = (page, s) => page.evaluate((s) => t(s), s); + + let page = await open(false); + const go = page.locator(".sm-head .sm-toset"); + await go.waitFor(); + assert.equal((await go.textContent()).trim(), (await tr(page, "Settings")) + " ›"); + assert(await fits(page), "the Sessions page fits"); + const gb = await go.boundingBox(), hb = await page.locator(".sm-head").boundingBox(); + assert(gb.x >= hb.x - 1 && gb.x + gb.width <= hb.x + hb.width + 1, "inside the head"); + for (const sel of [".sm-filter", ".sm-trash-btn"]) { + const b = await page.locator(".sm-head " + sel).boundingBox(); + assert(!b || b.x + b.width <= gb.x + 0.5 || b.x >= gb.x + gb.width - 0.5 || b.y + b.height <= gb.y + 0.5 || b.y >= gb.y + gb.height - 0.5, sel + " lies over Settings ›"); + } + await go.click(); + await page.locator("#view-settings #sessionReadsList .row.flash").first().waitFor(); + const back = page.locator("#navBack"); + await back.waitFor(); + await back.click(); + await page.locator("#view-sessions .sm-head").waitFor(); + assert.deepEqual(page.errors, []); + + // gateway mode reads no agent's history: no link + page = await open(true); + assert.equal(await page.locator(".sm-head .sm-toset").isVisible(), false, "no Settings › in gateway mode"); + assert.deepEqual(page.errors, []); + }); + } + } +} diff --git a/internal/gui/tests/sessions-toolbar.test.cjs b/internal/gui/tests/sessions-toolbar.test.cjs index 395cd30ea..4b272691f 100644 --- a/internal/gui/tests/sessions-toolbar.test.cjs +++ b/internal/gui/tests/sessions-toolbar.test.cjs @@ -96,7 +96,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", assert(await tabs.isHidden(), "overflowing tabs give way to the menu"); assert(await picker.isVisible()); } - const boxes = await view.locator(".sm-switch, .sm-filter, .sm-trash-btn").evaluateAll((els) => els.map((e) => { + const boxes = await view.locator(".sm-switch, .sm-filter, .sm-trash-btn, .sm-toset").evaluateAll((els) => els.map((e) => { const b = e.getBoundingClientRect(); return { name: e.className, left: b.left, right: b.right, top: b.top, bottom: b.bottom, width: b.width }; }));