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(remote): projects.list host RPC for relay-based project browsing
enes7eca6ed21a51
diff --git a/src/core/pty-manager.ts b/src/core/pty-manager.tsindex d6ddfac1e..08c15bc9f 100644--- a/src/core/pty-manager.ts+++ b/src/core/pty-manager.ts@@ -914,6 +914,32 @@ export class PtyManager {}}+ /**+ * List the names of all live nodeterm tmux sessions (on our dedicated socket). Used by the+ * relay host's `projects.list` RPC so a paired phone can enumerate the host's sessions the same+ * way the SSH browse path does (`tmux -L node-terminal list-sessions`). Returns the trimmed,+ * non-empty session names; `[]` on any error (tmux unavailable / no server / no sessions) so it+ * never throws.+ */+ async listNodetermSessions(): Promise<string[]> {+ if (!this.tmuxPath) return []+ try {+ const { stdout } = await runAsync(this.tmuxPath, [+ '-L',+ TMUX_SOCKET,+ 'list-sessions',+ '-F',+ '#{session_name}'+ ])+ return stdout+ .split('\n')+ .map((line) => line.trim())+ .filter((line) => line.length > 0)+ } catch {+ return []+ }+ }+/** Permanently end a node's persistent tmux session (called when the user closes it). */async destroySession(persistKey: string): Promise<void> {// destroy() is called (close button) while the session is still live, so its sshRemote isdiff --git a/src/main/index.ts b/src/main/index.tsindex 7c2ef7b4b..353028b09 100644--- a/src/main/index.ts+++ b/src/main/index.ts@@ -1,4 +1,5 @@import { join, resolve, posix } from 'path'+import { readFile } from 'fs/promises'import { homedir } from 'os'import { randomUUID } from 'crypto'import { app, BrowserWindow, dialog, ipcMain, Notification, shell } from 'electron'@@ -104,6 +105,26 @@ const chatDriver = new ChatDriver(getMainWindow, sendToMain)// Set once the app window is ready; used by the quit hooks to tear down SSH-project masters.let sshProjectManager: ReturnType<typeof initSshProject> | undefined+// Markers delimiting the `projects.list` relay blob. The iOS client splits on these exact+// strings to recover [workspace.json | newline-joined tmux session names | agent-status.json],+// matching the SSH browse pipeline it already uses — keep them in sync with NodetermProjects.swift.+const NT_PROJECTS_MARK = '--NT-PROJECTS-SPLIT--'+const NT_STATUS_MARK = '--NT-STATUS-SPLIT--'++/**+ * Build the marker-delimited projects blob served over the relay's `projects.list` RPC. Reads the+ * same files the SSH browse path reads locally on the host (no SSH): `workspace.json` ++ * `agent-status.json` under userData, plus the live nodeterm tmux session names. Every read is+ * best-effort (missing files degrade to an empty section) so this never throws.+ */+async function listProjectsOutput(): Promise<string> {+ const dir = app.getPath('userData')+ const workspace = await readFile(join(dir, 'workspace.json'), 'utf8').catch(() => '')+ const status = await readFile(join(dir, 'agent-status.json'), 'utf8').catch(() => '')+ const sessions = (await ptyManager.listNodetermSessions().catch(() => [])).join('\n')+ return `${workspace}\n${NT_PROJECTS_MARK}\n${sessions}\n${NT_STATUS_MARK}\n${status}`+}+// Remote git routing is scoped to the ACTIVE project only (set via `git:set-active-remote`).// A global cwd-keyed match would misroute when two SSH projects share a remote path, or when a// LOCAL project's cwd equals a connected SSH project's remoteCwd. The renderer drives this on every@@ -840,10 +861,10 @@ app.whenReady().then(async () => {// Lazy getter: sshProjectManager is created just below, so a remote account op (which only runs// after the user has connected an SSH project) always sees the live manager.initClaudeAccounts(() => sshProjectManager)- initRemoteHost(win, ptyManager)+ initRemoteHost(win, ptyManager, listProjectsOutput)// Standing (phone) relay host: keep a host connection registered so a paired phone can reach// this Mac from anywhere. Honors settings.phoneAccessEnabled + the Pro gate internally.- const standingHost = initStandingHost(win, ptyManager, () => settingsStore.get())+ const standingHost = initStandingHost(win, ptyManager, () => settingsStore.get(), listProjectsOutput)ipcMain.on(IPC.remoteStandingHostSet, (_e, enabled: boolean) => standingHost.setEnabled(!!enabled))// Reconcile from persisted settings on launch (starts hosting if enabled + Pro).standingHost.syncFromSettings()diff --git a/src/main/remote/host-service.ts b/src/main/remote/host-service.tsindex 5fdfa4064..b5c7e10d6 100644--- a/src/main/remote/host-service.ts+++ b/src/main/remote/host-service.ts@@ -135,7 +135,11 @@ export function createHostHandlers(fs: HostFsOps = fsOps,// Directories the remote client may read/write within. Empty ⇒ no filesystem access is served// (deny-by-default). Production passes the cwds of the host's shared canvas nodes.- getRoots: () => string[] = () => []+ getRoots: () => string[] = () => [],+ // Produce the marker-delimited "projects" blob for the `projects.list` RPC (workspace.json ++ // live tmux session names + agent-status.json — the same bytes the iOS SSH browse path reads).+ // Read-only, takes no client params. Default = empty so the 4-arg security tests still compile.+ listProjects: () => Promise<string> = async () => ''): HostHandlers {// streamId -> Stream. PTY callbacks close over their own `streamId` directly, so no// reverse (sessionId -> streamId) index is needed.@@ -315,6 +319,14 @@ export function createHostHandlers(case 'fs.write':handleFs(req)break+ case 'projects.list':+ // Read-only enumeration of the host's projects/sessions/agent-status (no client params —+ // nothing to jail). Gated by the same pre-handler approval check in connectHostSession, so+ // an unapproved device never reaches here. Always respond ok; degrade to an empty blob.+ void listProjects()+ .then((output) => socket.respond(req.id, true, { output }))+ .catch(() => socket.respond(req.id, true, { output: '' }))+ breakdefault:socket.respond(req.id, false, { message: `Unknown method: ${req.method}` })}@@ -556,6 +568,11 @@ export interface HostSessionOptions {subscribeCanvas(cb: (state: CanvasState) => void): () => void/** Forward a (sanitized) client canvas mutation to the host renderer (the single writer). */applyMutation(mutation: CanvasMutation): void+ /**+ * Produce the marker-delimited projects blob for the `projects.list` RPC (see createHostHandlers).+ * Optional: omit for host sessions that don't serve project browse (defaults to an empty blob).+ */+ listProjects?: () => Promise<string>/*** A peer completed the E2EE handshake and awaits an approval decision. The caller inspects the* session (sas / peerPublicKeyB64) and either approves immediately (pin-once) or prompts the@@ -658,8 +675,12 @@ export function connectHostSession(opts: HostSessionOptions): HostSession {}})// Confine the client's fs.* access to the cwds of the host's currently-shared canvas nodes.- handlers = createHostHandlers(opts.pty, socket, fsOps, () =>- rootsFromCanvas(opts.getLatestCanvas())+ handlers = createHostHandlers(+ opts.pty,+ socket,+ fsOps,+ () => rootsFromCanvas(opts.getLatestCanvas()),+ opts.listProjects ?? (async () => ''))canvasSync = createHostCanvasSync(socket, opts.applyMutation)unsubCanvas = opts.subscribeCanvas(() => scheduleBroadcast())@@ -674,7 +695,11 @@ export function connectHostSession(opts: HostSessionOptions): HostSession {* the relay as host, and returns the offer string. `remote:host:stop` closes the relay socket* (which kills the served PTYs and drops the client's access).*/-export function initRemoteHost(win: BrowserWindow, ptyManager: PtyManager): void {+export function initRemoteHost(+ win: BrowserWindow,+ ptyManager: PtyManager,+ listProjects: () => Promise<string> = async () => ''+): void {initHostCanvasHub()let session: HostSession | null = null@@ -709,6 +734,7 @@ export function initRemoteHost(win: BrowserWindow, ptyManager: PtyManager): voidgetLatestCanvas: currentCanvas,subscribeCanvas,applyMutation: (mutation) => send(IPC.remoteHostApplyMutation, mutation),+ listProjects,// Interactive host: surface the SAS so the human can verify + approve.onPeerReady: (s) => send(IPC.remoteHostPeerPending, { sas: s.sas() }),onClose: () => {}diff --git a/src/main/remote/remote-security.test.ts b/src/main/remote/remote-security.test.tsindex 1e10b11d2..2630f6b72 100644--- a/src/main/remote/remote-security.test.ts+++ b/src/main/remote/remote-security.test.ts@@ -92,6 +92,30 @@ describe('R1: fs.* is confined to the shared roots', () => {})})+// --- projects.list: read-only browse RPC ------------------------------------++describe('projects.list serves the host projects blob', () => {+ it('responds ok with the listProjects output', async () => {+ const { socket, responses, fs, pty } = makeHostFakes()+ const listProjects = vi.fn(async () => 'FIXTURE')+ const handlers = createHostHandlers(pty, socket, fs, () => [], listProjects)+ handlers.onRpc({ id: '1', method: 'projects.list', params: undefined })+ await Promise.resolve()+ await Promise.resolve()+ expect(listProjects).toHaveBeenCalledTimes(1)+ expect(responses).toEqual([{ id: '1', ok: true, body: { output: 'FIXTURE' } }])+ })++ it('defaults to an empty blob when no provider is injected (4-arg call)', async () => {+ const { socket, responses, fs, pty } = makeHostFakes()+ const handlers = createHostHandlers(pty, socket, fs, () => [])+ handlers.onRpc({ id: '2', method: 'projects.list', params: undefined })+ await Promise.resolve()+ await Promise.resolve()+ expect(responses).toEqual([{ id: '2', ok: true, body: { output: '' } }])+ })+})+// --- R2: SAS determinism -----------------------------------------------------describe('R2: channel SAS', () => {diff --git a/src/main/remote/standing-host.ts b/src/main/remote/standing-host.tsindex 948db615b..028dbdd3c 100644--- a/src/main/remote/standing-host.ts+++ b/src/main/remote/standing-host.ts@@ -90,7 +90,8 @@ export interface StandingHost {export function initStandingHost(win: BrowserWindow,ptyManager: PtyManager,- getSettings: () => Settings+ getSettings: () => Settings,+ listProjects: () => Promise<string> = async () => ''): StandingHost {initHostCanvasHub()@@ -207,6 +208,7 @@ export function initStandingHost(getLatestCanvas: currentCanvas,subscribeCanvas,applyMutation: (mutation: CanvasMutation) => send(IPC.remoteHostApplyMutation, mutation),+ listProjects,onPeerReady: (s) => void onPeerReady(s),onClose: () => {// Peer/relay dropped. Fully reset this session and re-register (fresh token).