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
feat(bridge): real sessionMemory namespace for the Server Edition
enes2c3ada642aba
diff --git a/src/preload/index.test.ts b/src/preload/index.test.tsindex 7b6738a9b..5deb6fa58 100644--- a/src/preload/index.test.ts+++ b/src/preload/index.test.ts@@ -66,6 +66,23 @@ describe('preload sshProject passphrase wiring', () => {expect(h.removeListener).toHaveBeenCalledWith(IPC.sshPassphraseRequest, handler)})+ // The desktop half of the session-memory surface. `remote` is the renderer's own "this scope is+ // an SSH host" claim and one of the TWO independent sources the core service ORs to decide which+ // machine answers; `projectId` is the only thing naming that machine. A preload that normalized+ // either (dropped a `false`, defaulted the object, reordered the args) would route a remote query+ // into a LOCAL sweep and publish this machine's sessions under the host's name — invisible to+ // every other test, since core is handed a perfectly well-formed query.+ it('sessionMemory forwards the query verbatim on both channels', async () => {+ const q = { projectId: 'p1', remote: true }+ await api.sessionMemory.read(q)+ await api.sessionMemory.host(q)+ expect(h.invoke).toHaveBeenCalledWith(IPC.sessionMemory, { projectId: 'p1', remote: true })+ expect(h.invoke).toHaveBeenCalledWith(IPC.sessionMemoryHost, { projectId: 'p1', remote: true })+ // An explicit `remote: false` is a claim too, and must not be normalized away.+ await api.sessionMemory.read({ projectId: 'p2', remote: false })+ expect(h.invoke).toHaveBeenCalledWith(IPC.sessionMemory, { projectId: 'p2', remote: false })+ })+it('onPassphraseDismiss subscribes the dismiss channel and forwards the requestId', () => {const got: { requestId: string }[] = []const off = api.sshProject.onPassphraseDismiss((e) => got.push(e))diff --git a/src/preload/index.ts b/src/preload/index.tsindex df0756473..42d4fe3a1 100644--- a/src/preload/index.ts+++ b/src/preload/index.ts@@ -9,6 +9,7 @@ import type {RecycledInfo,RelayPeerPending,RemoteUsageQuery,+ SessionMemoryQuery,UpdateInfo,UpdateProgress,Workspace,@@ -378,6 +379,14 @@ const api: NodeTerminalApi = {return () => ipcRenderer.removeListener(IPC.usageUpdate, handler)}},+ // The query is forwarded VERBATIM: `remote` is the renderer's own "this scope is an SSH host"+ // claim, which the core service ORs with its own `isRemoteProject`. Normalizing it here (say,+ // dropping a `false`, or defaulting the object) would silently re-open the misattribution this+ // surface exists to prevent — one machine's sessions published under another's name.+ sessionMemory: {+ read: (q?: SessionMemoryQuery) => ipcRenderer.invoke(IPC.sessionMemory, q),+ host: (q?: SessionMemoryQuery) => ipcRenderer.invoke(IPC.sessionMemoryHost, q)+ },context: {onUpdate: (listener) => {const handler = (_e: unknown, payload: Parameters<typeof listener>[0]) => listener(payload)diff --git a/src/renderer/bridge/stubs.test.ts b/src/renderer/bridge/stubs.test.tsindex ec6cb06a1..e8097800a 100644--- a/src/renderer/bridge/stubs.test.ts+++ b/src/renderer/bridge/stubs.test.ts@@ -66,6 +66,11 @@ describe('bridge stubs', () => {// UpdatePolicy — a `null` here was a TypeError on every Server Edition page load.await expect(s.updates.getPolicy()).resolves.toEqual({ minSupported: null, mandatory: false })await expect(s.usage.fetch()).resolves.toBeNull()+ // `ok:false` is load-bearing: the stub means "we could not measure", and an `ok:true` with no+ // rows would render as "nothing on this machine is using memory" — a confident wrong answer on+ // exactly the surface (the relay tab) where the sessions live on somebody else's machine.+ await expect(s.sessionMemory.read()).resolves.toEqual({ ok: false, rows: [], mem: null })+ await expect(s.sessionMemory.host()).resolves.toBeNull()await expect(s.license.getStatus()).rejects.toMatchObject({ code: E_UNSUPPORTED })})diff --git a/src/renderer/bridge/stubs.ts b/src/renderer/bridge/stubs.tsindex 0e3baee2b..917c9af77 100644--- a/src/renderer/bridge/stubs.ts+++ b/src/renderer/bridge/stubs.ts@@ -243,6 +243,18 @@ export function buildStubApi(): Omit<cookieProviders: () => Promise.resolve({}),onUpdate: noopUnsub},+ sessionMemory: {+ // Superseded by the real WS-backed namespace in ws-bridge (the core session-memory service+ // runs in the server shell too), so nothing reaches these in a live browser session. Kept+ // only to satisfy `satisfies NodeTerminalApi`.+ //+ // Where it DOES stay in force is the relay tab, which shares this stub surface: there the+ // renderer runs on the guest while the sessions live on the host, so answering at all would+ // describe the wrong machine. `ok:false` / `null` are the service's own words for "could not+ // measure" — the one honest answer, and never mistakable for "nothing is using memory".+ read: () => Promise.resolve({ ok: false, rows: [], mem: null }),+ host: () => Promise.resolve(null)+ },claude: {// Overridden by the real WS-backed namespace in ws-bridge; the stub still answers with the// fail-open caps (never rejects) because the permission-mode gate reads it on the boot path.diff --git a/src/renderer/bridge/ws-bridge.namespaces.test.ts b/src/renderer/bridge/ws-bridge.namespaces.test.tsindex f79955f29..7fc195d00 100644--- a/src/renderer/bridge/ws-bridge.namespaces.test.ts+++ b/src/renderer/bridge/ws-bridge.namespaces.test.ts@@ -1,5 +1,7 @@import { describe, it, expect } from 'vitest'-import { buildFilesApi, buildRealApi } from './ws-bridge'+import { readFileSync } from 'node:fs'+import { join } from 'node:path'+import { buildFilesApi, buildRealApi, buildSessionMemoryApi } from './ws-bridge'import { IPC } from '../../shared/ipc'function fakeClient() {@@ -69,3 +71,56 @@ describe('buildRealApi: workspace', () => {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 --git a/src/renderer/bridge/ws-bridge.ts b/src/renderer/bridge/ws-bridge.tsindex 3658e91b5..a882b4f84 100644--- a/src/renderer/bridge/ws-bridge.ts+++ b/src/renderer/bridge/ws-bridge.ts@@ -27,6 +27,7 @@ import {type FilesApi,type FsApi,type GitApi,+ type MemInfo,type NodeTerminalApi,type PresenceApi,type PtyApi,@@ -36,6 +37,8 @@ import {type ProviderUsage,type RemoteAccountUsage,type RemoteUsageQuery,+ type SessionMemoryQuery,+ type SessionMemoryReport,type Settings,type SpeechApi,type SpeechModelInfo,@@ -608,6 +611,31 @@ function buildUsageApi(client: RpcClient): Pick<NodeTerminalApi, 'usage'> {}}+/**+ * Real, not a stub: the same core service (`startSessionMemoryService`) registers these channels in+ * the server shell, so the browser gets a genuine per-session breakdown of the machine it is served+ * from — the one it is actually looking at.+ *+ * The query is forwarded VERBATIM. `remote` is the renderer's own "this scope is an SSH host"+ * claim and is one of TWO independent sources the service ORs to decide which machine answers;+ * `projectId` is the only thing naming that machine. A layer that drops or rewrites either turns a+ * remote query into a local sweep, and this machine's sessions get published under the host's name.+ *+ * Neither member catches: a transport failure must not be laundered into `{ok:false}` / `null`,+ * which are the service's own words for "the sweep could not run" and "RAM unreadable". The panel+ * shows a failed request as a failed request.+ */+export function buildSessionMemoryApi(client: RpcClient): Pick<NodeTerminalApi, 'sessionMemory'> {+ return {+ sessionMemory: {+ read: (q?: SessionMemoryQuery) =>+ client.request(IPC.sessionMemory, q) as Promise<SessionMemoryReport>,+ host: (q?: SessionMemoryQuery) =>+ client.request(IPC.sessionMemoryHost, q) as Promise<MemInfo | null>+ }+ }+}+/*** Build the `claude` namespace over an RpcClient. `cliCaps` is a REAL handler on the server* (`registerClaudeCliIpc` runs in the server shell too), so the browser resolves the very same@@ -779,6 +807,7 @@ export async function installWsBridge(): Promise<boolean> {...buildPresenceApi(client),...buildSpeechApi(client),...buildUsageApi(client),+ ...buildSessionMemoryApi(client),...buildGitHubApi(client),// `claude` is assembled from two builders: `cliCaps` from the relay-shared one, and the// transcript reader from the Server-Edition-only one (which also supplies `chat`).diff --git a/src/shared/types.ts b/src/shared/types.tsindex bb06f1661..3f2687202 100644--- a/src/shared/types.ts+++ b/src/shared/types.ts@@ -1500,6 +1500,23 @@ export interface SessionMemoryQuery {remote?: boolean}+/**+ * Per-session memory for the machine the ACTIVE PROJECT runs on — the same scoping rule the usage+ * indicator follows (`usageScope`), for the same reason: a number is meaningless without the+ * machine it describes.+ *+ * Both members are on-demand only, never polled: a remote answer costs an ssh exec plus a `ps` of+ * somebody else's whole process table. Pass the query through verbatim — `remote` is one of the two+ * independent sources the service uses to decide which host answers.+ */+export interface SessionMemoryApi {+ /** Per-session breakdown for the scoped machine. `ok:false` = the sweep could not run, which is+ * NOT an empty `rows` with `ok:true` ("we looked, there are none"). */+ read(q?: SessionMemoryQuery): Promise<SessionMemoryReport>+ /** The scoped machine's RAM. `null` = could not read (never "zero"). */+ host(q?: SessionMemoryQuery): Promise<MemInfo | null>+}+/** Claude Code subscription usage snapshot for the bottom-left indicator. */export interface ClaudeUsage {/**@@ -1989,6 +2006,7 @@ export interface NodeTerminalApi {githubIssues: import('./github-issues').GitHubIssuesApigithubControl: import('./github-issues').GitHubControlApiusage: UsageApi+ sessionMemory: SessionMemoryApicontext: ContextApicanvas: CanvasApiclaude: ClaudeApi