Node-based terminal manager for AI coding agents — tmux-backed terminals and parallel agent sessions as draggable nodes on an infinite pan/zoom canvas. macOS, Linux, and a browser Server Edition.
TypeScript adhdagent-orchestrationai-agentscanvasclaude-codecodexcoding-agentsdeveloper-toolselectrongeminilinuxmacosmultiplexeropencodeparallel-agentsterminalterminal-emulatorterminal-multiplexertmuxworkspace-manager
Merge origin/main into feat/session-memory-panel
enes4738cd6831ba
diff --cc src/main/index.tsindex 7686d17ed,e479e36a1..fd0ac9941--- a/src/main/index.ts+++ b/src/main/index.ts@@@ -69,7 -69,9 +69,10 @@@ import { createGrantsAccessor, type Pusimport { createRemoteGrantsCache } from '../core/remote-push-grants'import { createAckSweeper } from '../core/ack-sweep'import { createSessionReaper } from '../core/session-budget'+import { startSessionMemoryService, sshScopePredicate } from '../core/session-memory-service'+ import { createMemoryPressureMonitor } from '../core/memory-pressure'+ import { createPtyPressureMonitor } from '../core/pty-pressure'+ import { registerPtmxLimitHandler } from './ptmx-limit'import { getDeviceId } from '../core/device-id'import { initRemoteStatusPush } from './remote-ssh/remote-status-push'import { initCanvasSync } from '../core/canvas-sync'@@@ -1501,45 -1528,50 +1529,88 @@@ app.whenReady().then(async () =>// budget). Attached sessions are never touched; a reaped node cold-restores on next open.// Local sockets only — a remote SSH host's sessions are reaped by that host's own// nodeterm-server, never across the wire. Timer is unref'd; no explicit stop needed.- createSessionReaper({ tmuxBin: () => ptyManager.getTmuxBin() }).start()+ // `shadowed` subtracts our own control-mode shadows from tmux's attached flag: a shadow is a real+ // tmux client but NOT a watcher, so a shadowed session must stay exactly as cullable as an idle+ // detached one (see PtyManager.shadowedTmuxSessions).+ const sessionReaper = createSessionReaper({+ tmuxBin: () => ptyManager.getTmuxBin(),+ shadowed: (socket) => ptyManager.shadowedTmuxSessions(socket)+ })+ sessionReaper.start()+ // Memory pressure (core/memory-pressure.ts): the reaper's own 10-minute timer is the steady+ // state; this is the fast path. On a watermark crossing the renderer runs its reclaim levers+ // (hidden WebGL contexts, parked terminals) and a CRITICAL reading also sweeps the reaper NOW+ // rather than waiting out its timer. Both levers are idempotent and the monitor re-fires at most+ // once a minute. The send goes through `sendToMain`, which resolves the window AT SEND TIME and+ // no-ops while it is closed (macOS keeps the app alive without one) — the monitor's own+ // try/catch is the backstop, not the primary.+ createMemoryPressureMonitor({+ onPressure: (severity) => {+ sendToMain(IPC.appMemoryPressure, severity)+ if (severity === 'critical') void sessionReaper.sweep()+ }+ }).start()+ // Pty-device pressure (core/pty-pressure.ts): the OTHER way this machine runs out, and the one+ // that actually happened. The memory monitor above could not see it — during the 2026-08-11+ // incident RAM was plentiful while `/dev/ttys*` was full, so the reaper never woke and the user+ // got no warning at all, just terminals that stopped opening. Same shape as the memory leg: tell+ // the renderer (which raises a banner) on every band change, and sweep the reaper NOW on+ // critical — a reaped detached session returns its pty device, which is exactly the resource in+ // short supply. Transitions only, re-announced at most every five minutes.+ //+ // The sweep is passed `pressure: 'pty'` because a bare `sweep()` here would plan NOTHING: the+ // budget's own triggers are memory and a detached-count cap, and the incident profile clears+ // both (healthy RAM, under the cap). The reason grants the same batch allowance low memory+ // would and widens no exemption — attached and in-grace sessions stay untouchable.+ const ptyPressure = createPtyPressureMonitor({+ onLevel: (reading) => {+ sendToMain(IPC.ptyPressure, reading)+ if (reading.level === 'critical') void sessionReaper.sweep({ pressure: 'pty' })+ }+ })+ ptyPressure.start()+ // The banner's "Fix automatically…" button. Registered, never called on our own initiative: it+ // raises `kern.tty.ptmx_max` behind macOS's own admin-password dialog. Its success re-announces+ // through the monitor's funnel, so the banner clears without waiting out the next tick.+ registerPtmxLimitHandler(corePlatform, { announce: (reading) => ptyPressure.announce(reading) })+ // Session memory (docs/superpowers/specs/2026-08-10-session-memory-panel-design.md): the pill's+ // cheap RAM read plus the on-demand per-session breakdown. An SSH project's sessions live on ITS+ // host, so they are read THERE over the project's ControlMaster — the same injection Context Link+ // and remote usage use (core owns the command + the parsing, main owns the master).+ // `sshProjectManager` is assigned far below, so both closures resolve it lazily; they only ever+ // run after a project has connected.+ startSessionMemoryService({+ tmuxBin: () => ptyManager.getTmuxBin(),+ remote: {+ // Identity, not liveness: a DISCONNECTED SSH project is still someone else's machine, and+ // `connectedHosts()` alone would answer "local" for it — exactly the window the service's+ // refusal exists for. The workspace index is the connection-independent source; the live+ // masters are OR-ed in for a project the index has not (yet) listed. See sshScopePredicate.+ isRemoteProject: sshScopePredicate({+ sshProjectIds: () => workspaceStore.sshProjectIds(),+ connectedProjectIds: () =>+ (sshProjectManager?.connectedHosts() ?? []).map((h) => h.projectId)+ }),+ run: async (projectId, command) => {+ const mgr = sshProjectManager+ const ref = mgr?.refForProject(projectId)+ if (!mgr || !ref) return null+ try {+ const { code, stdout } = await mgr.sshRun(childArgs(ref.conn, ref.controlPath, command))+ // Gated on the exit code, unlike the usage runner: every command in the generated script+ // ends `|| true`, so a completed read exits 0 unconditionally. A non-zero code therefore+ // means ssh itself could not run it — a dead ControlMaster reports exactly that, with an+ // EMPTY stdout ("Control socket connect(…): No such file or directory" goes to stderr).+ // Passing that empty string on would leave "the host answered nothing" to be inferred+ // from a missing marker; `null` says "we could not look" outright.+ if (code !== 0) return null+ return stdout+ } catch {+ return null+ }+ }+ }+ })const ackSweeper = createAckSweeper({handlers: { ackDone, onUnreadClear: (id) => sendToMain(IPC.agentUnreadClear, id) }})diff --cc src/renderer/bridge/ws-bridge.namespaces.test.tsindex 7fc195d00,2a566793e..e8e80cfb0--- a/src/renderer/bridge/ws-bridge.namespaces.test.ts+++ b/src/renderer/bridge/ws-bridge.namespaces.test.ts@@@ -70,57 -68,12 +70,65 @@@ describe('buildRealApi: workspace', ()expect(c.calls[0]).toEqual({ kind: 'subscribe', method: IPC.workspaceMigrated, args: [] })expect(typeof un).toBe('function')})++ it('onCorruptRecovered subscribes to the channel core actually broadcasts', () => {+ const c = fakeClient()+ const api = buildRealApi(c as never)+ const un = api.workspace.onCorruptRecovered(() => {})+ expect(c.calls[0]).toEqual({ kind: 'subscribe', method: IPC.workspaceCorruptRecovered, args: [] })+ expect(typeof un).toBe('function')+ })})++describe('buildRealApi: sessionMemory', () => {+ // A real WS namespace, not a stub: the same core service (`startSessionMemoryService`) registers+ // both channels in the server shell, so the browser gets a genuine per-session breakdown of the+ // machine it is served from.+ it('read/host hit the real channels', async () => {+ const c = fakeClient()+ const api = buildSessionMemoryApi(c as never)+ await api.sessionMemory.read()+ await api.sessionMemory.host()+ expect(c.calls.map((x) => ({ kind: x.kind, method: x.method }))).toEqual([+ { kind: 'request', method: IPC.sessionMemory },+ { kind: 'request', method: IPC.sessionMemoryHost }+ ])+ })++ // The query is the ONLY thing that decides which machine answers: `projectId` names the scope and+ // `remote` is the renderer's own "this scope is an SSH host" claim, which the service ORs with its+ // own `isRemoteProject`. A layer that drops or rewrites either one turns a remote query into a+ // LOCAL sweep, and the panel publishes this machine's sessions under the host's name. So the+ // query must arrive at the RPC call byte-identical, on BOTH channels.+ it('passes projectId and the remote flag through unmodified', async () => {+ const c = fakeClient()+ const api = buildSessionMemoryApi(c as never)+ const q = { projectId: 'p1', remote: true }+ await api.sessionMemory.read(q)+ await api.sessionMemory.host(q)+ expect(c.calls).toEqual([+ { kind: 'request', method: IPC.sessionMemory, args: [{ projectId: 'p1', remote: true }] },+ { kind: 'request', method: IPC.sessionMemoryHost, args: [{ projectId: 'p1', remote: true }] }+ ])+ })++ // `remote: false` is a claim too ("the renderer says this is NOT an SSH scope"), and it must not+ // be normalized away into `undefined` — the shell's own predicate still gets to say otherwise,+ // but the renderer's answer has to reach it as written.+ it('keeps an explicit remote:false', async () => {+ const c = fakeClient()+ const api = buildSessionMemoryApi(c as never)+ await api.sessionMemory.read({ projectId: 'p2', remote: false })+ expect(c.calls[0].args).toEqual([{ projectId: 'p2', remote: false }])+ })++ // The builder above is dead code unless it is actually spread into the assembled api. It cannot+ // be caught by the compiler: `buildStubApi()` already supplies a `sessionMemory`, so dropping the+ // spread leaves `NodeTerminalApi` satisfied and the STUB silently wins in every live browser+ // session. installWsBridge needs a socket + DOM to run, so the wiring is pinned by source text.+ it('is spread into the assembled window.nodeTerminal', () => {+ const src = readFileSync(join(__dirname, 'ws-bridge.ts'), 'utf8')+ const install = src.slice(src.indexOf('export async function installWsBridge'))+ expect(install).toContain('...buildSessionMemoryApi(client)')+ })+})diff --cc src/server/index.tsindex 6b57b59c0,ad27af254..2157b00fc--- a/src/server/index.ts+++ b/src/server/index.ts@@@ -50,7 -50,8 +50,9 @@@ import { createPushNotify, createLiveUpimport { createGrantsAccessor } from '../core/push-grants'import { createAckSweeper } from '../core/ack-sweep'import { createSessionReaper } from '../core/session-budget'+import { startSessionMemoryService, sshScopePredicate } from '../core/session-memory-service'+ import { createMemoryPressureMonitor } from '../core/memory-pressure'+ import { createPtyPressureMonitor } from '../core/pty-pressure'import { claudeCliCaps, type ClaudeCliCaps } from '../core/claude-cli'import { claudeConfigDirFor } from '../core/claude-config-dir'import { presenceHub } from '../core/presence/hub'@@@ -441,40 -442,51 +443,82 @@@ export async function startServer// and this standing process is the natural owner of reaping them (field report: 95 sessions /// 34 GB idle claude). Attached sessions are never touched; a reaped node cold-restores on next// open. Kill switch + tuning via NODETERM_SESSION_* env (core/session-budget.ts).- const sessionReaper = createSessionReaper({ tmuxBin: () => ptyManager.getTmuxBin() })+ // `shadowed` subtracts our own control-mode shadows from tmux's attached flag: a shadow is a real+ // tmux client but NOT a watcher, so a shadowed session must stay exactly as cullable as an idle+ // detached one (see PtyManager.shadowedTmuxSessions).+ const sessionReaper = createSessionReaper({+ tmuxBin: () => ptyManager.getTmuxBin(),+ shadowed: (socket) => ptyManager.shadowedTmuxSessions(socket)+ })sessionReaper.start()+ // Memory pressure (core/memory-pressure.ts): only the reaper leg on this shell. A CRITICAL+ // reading sweeps NOW instead of waiting out the reaper's 10-minute timer — that is the whole+ // responder chain here. The renderer levers the desktop also runs (hidden WebGL contexts,+ // parked terminals) are deliberately NOT pushed to attached browsers: a tab's own memory is the+ // browser's to manage, and it already discards on its own terms (see the documented no-op in+ // renderer/bridge/stubs.ts). Stopped on close beside the reaper — the timer is unref'd, but a+ // test that starts and closes several servers must not leave sweepers behind.+ const pressure = createMemoryPressureMonitor({+ onPressure: (severity) => {+ if (severity === 'critical') void sessionReaper.sweep()+ }+ })+ pressure.start()+ // Pty-device pressure (core/pty-pressure.ts): the reaper leg ONLY, and deliberately so.+ //+ // A standing host is exactly where the ceiling is reached first — it accumulates the sessions+ // (field report: 95) whose panes and ssh children hold the devices — so the sweep matters more+ // here than on the desktop. What is missing is the OTHER half: the desktop also raises a banner+ // whose one useful affordance is "Fix automatically…", and that button ends in macOS's own+ // admin-password dialog on the HOST's physical display. A browser tab (possibly on another+ // machine, possibly on a Linux host with no such limit at all) cannot answer that prompt, so a+ // banner there would name a problem it gives the reader no way to act on. The channel exists —+ // platform.broadcast reaches attached tabs — this is a choice, not a gap, and the same one+ // already documented for the memory-pressure levers in renderer/bridge/stubs.ts. Server hosts+ // hitting the wall are told by the spawn error (core/pty-devices.ts), which is the surface a+ // headless host actually has. Stopped on close beside the memory monitor.+ //+ // `pressure: 'pty'` for the same reason as the desktop: without an explicit reason the budget's+ // own triggers (memory watermark, detached cap) are both clear on a pty-starved host and the+ // sweep plans nothing. It buys an allowance, not an exemption — see planReap.+ const ptyPressure = createPtyPressureMonitor({+ onLevel: (reading) => {+ if (reading.level === 'critical') void sessionReaper.sweep({ pressure: 'pty' })+ }+ })+ ptyPressure.start()+ // Session memory: the pill's RAM read plus the on-demand per-session breakdown. The Server+ // Edition runs ON the host whose sessions it reports and has no SSH-project manager, so it passes+ // no `run` — an SSH scope is REFUSED (ok:false), never swept locally.+ //+ // It does supply `isRemoteProject`, because knowing which projects are somebody else's machine+ // and being able to READ them are different capabilities: the workspace index answers the first+ // right here (the same source as the SSH check in the agentAnswerPermission handler above).+ // Without it, an SSH query arriving WITHOUT the renderer's `remote` flag would fall through to+ // the local sweep and publish this server's own sessions under the remote host's name — the exact+ // misattribution the refusal exists to prevent. Registered here (not in handlers/index.ts)+ // because this is where `ptyManager` lives — the same call site as the reaper above, mirroring+ // src/main/index.ts.+ //+ // DEPENDENCY, and one that breaks silently: `sshProjectIds()` reads the IN-MEMORY index, which is+ // populated only by the `await workspaceStore.load(...)` above — a line documented there as being+ // for context-link. Drop it, or stop awaiting it before `server.listen()` below, and every SSH+ // project reads as local here: the refusal quietly degrades to renderer-flag-only routing, which+ // is the misattribution bug itself. `test/server/session-memory-e2e.test.ts` exists to fail if+ // that happens.+ //+ // What is NOT load-bearing is this boot's position relative to that load. `isRemoteProject` is a+ // closure evaluated per QUERY, and no query can arrive before `startServer` reaches `listen()`,+ // so reordering the two would change nothing. The requirement is that the load happens and is+ // complete before the server serves — not that it precedes this line.+ startSessionMemoryService({+ tmuxBin: () => ptyManager.getTmuxBin(),+ remote: {+ isRemoteProject: sshScopePredicate({ sshProjectIds: () => workspaceStore.sshProjectIds() })+ }+ })+// Headless notification host: every core service above (incl. the loopback hook server, which// is its own listener and MUST run) is booted, but we bind NO public HTTP/WS listener — no// renderer serving, no auth surface, no open port. The granted push senders reach the phone over