paultian on Discord: magpie web in gateway mode, on a machine with Claude
Code and Codex installed, listed that machine's own sessions beside the
ones other computers sent through it. Owner's call (via the lead): keep
Sessions in gateway mode, scope it.
- sessions.OwnOff (set by the gui to ownSessionsOff): while it holds,
currentReads answers "none", Found and Dirs are empty, the trash lists
and restores/purges only what the gateway kept, and moving Claude
Code's folder is refused. Every route built on Reads follows: the list,
one, transcript, markdown, export, stats, overview, search, manage,
delete, carry, Usage's agent-file calls. Gateway-recorded sessions
(ledger projection, recorded conversations) are not behind the gate.
- ownSessionsOff: magpie web's page, and Settings' gateway mode On, or
Automatic with --gateway or no agents found (looked at once per 30s,
and again on another HOME/PATH). A turn of the answer resets the
sessions' caches and stats; the gateway-mode route does it at once.
- /api/sessions/reads says gateway:true: the page asks nothing, its empty
state names the gateway's sessions (en/zh/zh-TW/ja/de), and Settings ›
Privacy leaves out Agents' session history.
- The gateway-mode subtitle (5 languages), docs/reference.md and
site docs/docker.html (en/zh/ja) say Sessions stays and what it lists
(they said there was no Sessions tab, which was already wrong);
docs/subsystems/gateway-sessions.md has the design.
- Tests: Handler marks the process as magpie web for good, and 13 tests
served magpie web's page, so a later test's sandbox could be in gateway
mode by itself. webPageHandler ends the mark with the test, and
TestWebPageHandlerEveryWhere fails on a direct Handler(webHost{...}).
Ran (mote, at this tree rebased on origin/main):
- TestGatewayModeListsNoOwnSessions: red on the old code, green now.
- gateway-mode-sessions.test.cjs: chromium + webkit, en 900/390, zh,
zh-TW, ja 420, de 390: 36/36; red on the old client.js (every case).
- GUI files the change reaches (gateway-mode*, sessions-*, session-*,
privacy-*, usage-sessions-*, i18n-keys), both engines: 657/657.
- TestCoreScriptBudget ok.
- go test -shuffle=on ./internal/gui ./internal/sessions: sessions ok;
gui ok but TestMainWindowCorners/macOS_26_SDK, red the same on
origin/main 2f726b1f9 on mote (#3949).
- go vet, GOOS=linux go vet -tags nogui, GOOS=windows go vet of both
packages; gofmt -l clean.
Broken by hand: OwnOff answering false (the Go test goes red on the list,
stats, manage, one, transcript); the Purge guard and the Restore guard
each (red on purge / restore); the old client.js and settings.js (the GUI
test red). An injected stale agents memo and leaked webPage did not
reproduce the one TestUsageRequestContent red seen in the first package
run; it did not come back in two more runs, one shuffled.
Not tried: a real magpie web on a server with real agents on other
computers; the Go test on Windows and Linux boxes; the 30s memo under
real use.
99 lines
4.7 KiB
JavaScript
99 lines
4.7 KiB
JavaScript
// The sessions plugin's part of Settings: General's Session terminal and
|
|
// Privacy's Agents' session history. Run after app.js, whose helpers it
|
|
// shares (el, segs, svg, api, writingPrefs, savePrefs, openProtoMenu,
|
|
// status), and before start.js draws Settings; drawn whether the plugin is
|
|
// on or off.
|
|
|
|
function renderSessionTerminal(s, keep) {
|
|
const row = $("#sessionTerminalRow");
|
|
row.hidden = !document.body.classList.contains("mac");
|
|
if (row.hidden) return;
|
|
const select = $("#sessionTerminalSelect");
|
|
const apps = [...(s.terminalApps || [])];
|
|
if (!apps.some((app) => app.id === "com.apple.Terminal")) apps.unshift({ id: "com.apple.Terminal", name: "Terminal" });
|
|
const chosen = s.sessionTerminal || "system";
|
|
// a default that is not a terminal opens Terminal, as the server does
|
|
const defaultApp = apps.find((app) => app.id === s.terminalDefault) || apps.find((app) => app.id === "com.apple.Terminal");
|
|
const options = [{ id: "system", name: t("System default ({name})", { name: defaultApp.name }) }];
|
|
for (const app of apps) {
|
|
if (app.id === defaultApp.id && app.id !== chosen) continue;
|
|
options.push({ id: app.id, name: app.id === defaultApp.id ? t("{name} (fixed)", { name: app.name }) : app.name });
|
|
}
|
|
if (!options.some((app) => app.id === chosen)) {
|
|
options.push({ id: chosen, name: t("Unavailable app ({id})", { id: chosen }) });
|
|
}
|
|
// the app's own menu, not a native select
|
|
select.dataset.value = chosen;
|
|
select.replaceChildren(el("span", "", options.find((app) => app.id === chosen).name), svg(CHEV, 11, 1.6));
|
|
select.onclick = (e) => {
|
|
e.stopPropagation();
|
|
if (select.classList.contains("open")) return closeProtoMenu();
|
|
openProtoMenu(select, options.map((app) => ({ v: app.id, name: app.name, note: "", literalName: true })), chosen, (v) => {
|
|
if (v === chosen) return;
|
|
// drawn at once; the save draws it again with what was kept
|
|
select.dataset.value = v;
|
|
select.firstChild.textContent = options.find((app) => app.id === v).name;
|
|
savePrefs({ ...keep, sessionTerminal: v === "system" ? "" : v });
|
|
}, "Session terminal", "sess-menu");
|
|
};
|
|
}
|
|
|
|
// renderSessionReads: which agents' own session history magpie reads
|
|
// (RustCats on X: a new install showed every agent's sessions before
|
|
// anyone agreed). The Sessions page asks once; here it changes later.
|
|
// "Agents found later" is whether an agent with no row of its own is
|
|
// read, and drawn from the settings at once; each agent found on this
|
|
// computer has a row of its own, read from /api/sessions/reads when the
|
|
// Privacy part is shown (loadSessionReads).
|
|
let sessionReads = null; // /api/sessions/reads, as last read
|
|
let sessionReadsSeq = 0;
|
|
function renderSessionReads(s) {
|
|
const box = $("#sessionReadsList");
|
|
const r = sessionReads || { asked: !!s?.sessionReads?.asked, all: !!s?.sessionReads?.all, found: [] };
|
|
// gateway mode reads no agent's session history here, whatever these
|
|
// say (ownSessionsOff), so they are left out
|
|
const gw = !!(s?.gatewayOn || r.gateway);
|
|
box.hidden = gw;
|
|
box.previousElementSibling.hidden = gw;
|
|
if (gw) return;
|
|
const save = (body) => {
|
|
const n = ++sessionReadsSeq;
|
|
writingPrefs(api("sessions/reads", body))
|
|
.then((got) => { if (n === sessionReadsSeq) { sessionReads = got; renderSessionReads(prefs); } })
|
|
.catch((e) => { status(t(e.message), "err"); renderSessionReads(prefs); });
|
|
};
|
|
const row = (name, sub, on, fn) => {
|
|
const rw = el("div", "row pref");
|
|
const who = el("div", "who");
|
|
who.append(el("div", "name", name));
|
|
if (sub) who.append(el("div", "sub", sub));
|
|
const val = el("div", "val");
|
|
val.append(segs([["off", t("Off")], ["on", t("On")]], on ? "on" : "off", (v) => {
|
|
if ((v === "on") !== on) fn(v === "on");
|
|
}));
|
|
rw.append(who, val);
|
|
return rw;
|
|
};
|
|
const rows = [row(t("Agents found later"), t("Read the session history of an agent with no row here, one installed later too. Off, magpie reads only the agents turned on below; what its gateway served is counted either way"),
|
|
r.asked && r.all, (on) => {
|
|
// the agents with a row keep what their rows show
|
|
const agents = {};
|
|
for (const a of r.found || []) agents[a.agent] = !!a.on;
|
|
save(Object.keys(agents).length ? { all: on, agents } : { all: on });
|
|
})];
|
|
for (const a of r.found || []) {
|
|
const rw = row(a.name, "", a.on, (on) => save({ agents: { [a.agent]: on } }));
|
|
rw.dataset.agent = a.agent;
|
|
rows.push(rw);
|
|
}
|
|
box.replaceChildren(...rows);
|
|
}
|
|
function loadSessionReads() {
|
|
const n = ++sessionReadsSeq;
|
|
api("sessions/reads").then((got) => {
|
|
if (n !== sessionReadsSeq) return;
|
|
sessionReads = got;
|
|
renderSessionReads(prefs);
|
|
}).catch(() => {}); // the row drawn from the settings stays
|
|
}
|