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(relay): multi-peer host pool + invite/revoke with a seat cap (team-access Task 2)
enes2d134992cea4
diff --git a/src/main/remote/relay-host-service.test.ts b/src/main/remote/relay-host-service.test.tsindex cbe70f0ff..63410e411 100644--- a/src/main/remote/relay-host-service.test.ts+++ b/src/main/remote/relay-host-service.test.ts@@ -41,8 +41,17 @@ vi.mock('./approved-devices', () => ({}}))-import { initRelayHost } from './relay-host-service'-import type { RelayHostSession } from './relay-host'+// Keep `connectRelayHost` (the reviewed handshake) REAL — the crypto tests below exercise it for+// real — but spy `killRelayHostsByPeerKey` so the revoke test can assert the identity-based cut is+// fired with the right peer key (the module-level `live` set it reads is only populated by real+// sessions, so a pass-through spy is the clean way to observe it with a fake `connect`).+vi.mock('./relay-host', async (importOriginal) => {+ const mod = await importOriginal<typeof import('./relay-host')>()+ return { ...mod, killRelayHostsByPeerKey: vi.fn(mod.killRelayHostsByPeerKey) }+})++import { initRelayHost, E_SEATS_FULL } from './relay-host-service'+import { killRelayHostsByPeerKey, type RelayHostSession } from './relay-host'import { connectRelay, type RelayTransport } from './relay-socket'import { createTrustGate, type TrustGate } from './relay-trust'import { genKeyPair, publicKeyToB64 } from './e2ee'@@ -120,7 +129,8 @@ function wireHost(): {mintToken: async () => ({ pairingToken: 'tok-123' }),isPremium: () => true,relayAllowed: () => true,- getEntitlement: () => 'ent-abc'+ getEntitlement: () => 'ent-abc',+ licensedSeats: () => 3})let peerGate: TrustGate | null = null@@ -225,6 +235,7 @@ describe('initRelayHost — start()', () => {isPremium: () => true,relayAllowed: () => true,getEntitlement: () => 'ent',+ licensedSeats: () => 3,loadKeys: async () => {throw Object.assign(new Error('locked'), { code: 'E_PEER_KEY_LOCKED' })},@@ -298,6 +309,7 @@ describe('initRelayHost — sharedProjectId threads start → connect', () => {isPremium: () => true,relayAllowed: () => true,getEntitlement: () => 'ent-abc',+ licensedSeats: () => 3,connect: (o) => {captured = o// A no-op session; start() only needs the offer, which it builds itself.@@ -360,3 +372,186 @@ describe('initRelayHost — teardown', () => {expect(closed?.args[0]).toEqual({ id })})})++// Team Access — the POOL. A fake `connect` gives full, synchronous control over each seat's+// pending/open/close callbacks (the reviewed handshake is exercised for real in the crypto tests+// above and in relay-host.test.ts — it is UNCHANGED). Each fake session has a distinct peer key so+// the identity-based revoke can be asserted per seat.+interface FakeSession extends RelayHostSession {+ close: ReturnType<typeof vi.fn>+ confirm: ReturnType<typeof vi.fn>+}++function makeFakeSession(n: number): FakeSession {+ return {+ clientId: () => null,+ sas: () => '123 456',+ peerKeyB64: () => `peer-${n}`,+ sharedProjectId: () => undefined,+ confirm: vi.fn(),+ close: vi.fn()+ }+}++/** Wire an `initRelayHost` whose `connect` returns controllable fake sessions, capped at `seats`. */+function wirePool(seats: number): {+ invite: (opts?: { projectId?: string; email?: string }) => Promise<{ offer: string }>+ captured: Array<{ opts: any; session: FakeSession }>+} {+ const win = fakeWin()+ const captured: Array<{ opts: any; session: FakeSession }> = []+ initRelayHost(win as never, platform, {+ loadKeys: async () => genKeyPair(),+ mintToken: async () => ({ pairingToken: 'tok' }),+ isPremium: () => true,+ relayAllowed: () => true,+ getEntitlement: () => 'ent',+ licensedSeats: () => seats,+ connect: (o) => {+ const session = makeFakeSession(captured.length)+ captured.push({ opts: o, session })+ return session as unknown as RelayHostSession+ }+ })+ return {+ invite: (opts = {}) => h.handlers[IPC.relayHostInvite]({}, opts) as Promise<{ offer: string }>,+ captured+ }+}++function openedIds(channel: string): Array<{ id: string; email?: string }> {+ return h.sent.filter((x) => x.channel === channel).map((x) => x.args[0])+}++describe('initRelayHost — Team Access pool (invite/cap)', () => {+ it('invite adds a session (no supersede) and returns a decodable offer', async () => {+ const host = wirePool(3)+ const { offer } = await host.invite({ email: '[email protected]' })+ expect(decodeOffer(offer)?.pairingToken).toBe('tok')+ expect(host.captured.length).toBe(1)+ })++ it('three invites succeed at cap 3; a 4th is refused with E_SEATS_FULL (no close of others)', async () => {+ const host = wirePool(3)+ await host.invite()+ await host.invite()+ await host.invite()+ expect(host.captured.length).toBe(3)+ await expect(host.invite()).rejects.toThrow(E_SEATS_FULL)+ // The cap does NOT supersede — every existing seat stays live.+ for (const c of host.captured) expect(c.session.close).not.toHaveBeenCalled()+ expect(host.captured.length).toBe(3)+ })++ it('cap 1 refuses a 2nd invite (backward-compat single-peer)', async () => {+ const host = wirePool(1)+ await host.invite()+ await expect(host.invite()).rejects.toThrow(E_SEATS_FULL)+ })++ it('the seat cap counts from mint (pending), before the peer opens', async () => {+ const host = wirePool(1)+ await host.invite()+ // Not even pending yet — no onPeerPending fired — and the seat is already taken.+ await expect(host.invite()).rejects.toThrow(E_SEATS_FULL)+ })+})++describe('initRelayHost — Team Access email label rides the events', () => {+ it('email is carried on peer-pending and open', async () => {+ const host = wirePool(3)+ await host.invite({ email: '[email protected]' })+ host.captured[0].opts.onPeerPending(host.captured[0].session)+ host.captured[0].opts.onOpen()++ const pending = openedIds(IPC.relayHostPeerPending).at(-1)+ expect(pending?.email).toBe('[email protected]')+ const open = openedIds(IPC.relayHostOpen).at(-1)+ expect(open?.email).toBe('[email protected]')+ expect(open?.id).toBe(pending?.id)+ })+})++describe('initRelayHost — Team Access revoke + seat freeing', () => {+ it('revoke(id) cuts only that peer by identity and frees exactly one seat', async () => {+ vi.mocked(killRelayHostsByPeerKey).mockClear()+ const host = wirePool(3)+ await host.invite()+ await host.invite()+ await host.invite()+ // Make seat 0 pending so it has a renderer id to address.+ host.captured[0].opts.onPeerPending(host.captured[0].session)+ const id0 = openedIds(IPC.relayHostPeerPending).at(-1)!.id++ // At cap: a fresh invite is refused...+ await expect(host.invite()).rejects.toThrow(E_SEATS_FULL)++ h.handlers[IPC.relayHostRevoke]({}, { id: id0 })++ // Cut by the revoked peer's identity only.+ expect(killRelayHostsByPeerKey).toHaveBeenCalledTimes(1)+ expect(killRelayHostsByPeerKey).toHaveBeenCalledWith('peer-0')+ // The renderer is told this seat closed.+ expect(openedIds(IPC.relayHostClosed).at(-1)).toEqual({ id: id0 })++ // Exactly one seat freed: one fresh invite succeeds, the next is refused again.+ await expect(host.invite()).resolves.toHaveProperty('offer')+ await expect(host.invite()).rejects.toThrow(E_SEATS_FULL)+ })++ it('revoke with an unknown id is a no-op (no throw, no cut)', async () => {+ vi.mocked(killRelayHostsByPeerKey).mockClear()+ const host = wirePool(3)+ await host.invite()+ expect(() => h.handlers[IPC.relayHostRevoke]({}, { id: 'nope' })).not.toThrow()+ expect(killRelayHostsByPeerKey).not.toHaveBeenCalled()+ })++ it('a peer dropping (onClose) frees its seat', async () => {+ const host = wirePool(1)+ await host.invite()+ await expect(host.invite()).rejects.toThrow(E_SEATS_FULL)+ // The relay socket drops under seat 0.+ host.captured[0].opts.onClose()+ await expect(host.invite()).resolves.toHaveProperty('offer')+ })+})++describe('initRelayHost — Team Access stop() closes the whole pool', () => {+ it('stop() closes every session and clears the pool', async () => {+ const host = wirePool(3)+ await host.invite()+ await host.invite()+ await host.invite()++ await h.handlers[IPC.relayHostStop]()++ for (const c of host.captured) expect(c.session.close).toHaveBeenCalledTimes(1)+ // The pool is empty again — fresh invites succeed up to the cap.+ await expect(host.invite()).resolves.toHaveProperty('offer')+ })+})++describe('initRelayHost — Team Access start() aliases invite (additive)', () => {+ it('start() adds a seat (no supersede) and is cap-checked', async () => {+ const win = fakeWin()+ const captured: Array<{ session: FakeSession }> = []+ initRelayHost(win as never, platform, {+ loadKeys: async () => genKeyPair(),+ mintToken: async () => ({ pairingToken: 'tok' }),+ isPremium: () => true,+ relayAllowed: () => true,+ getEntitlement: () => 'ent',+ licensedSeats: () => 1,+ connect: () => {+ const session = makeFakeSession(captured.length)+ captured.push({ session })+ return session as unknown as RelayHostSession+ }+ })+ await h.handlers[IPC.relayHostStart]({})+ // A second start does NOT supersede the first (which would close it); it is refused at cap 1.+ await expect(h.handlers[IPC.relayHostStart]({})).rejects.toThrow(E_SEATS_FULL)+ expect(captured[0].session.close).not.toHaveBeenCalled()+ })+})diff --git a/src/main/remote/relay-host-service.ts b/src/main/remote/relay-host-service.tsindex 81966bf1f..786d90773 100644--- a/src/main/remote/relay-host-service.ts+++ b/src/main/remote/relay-host-service.ts@@ -1,9 +1,15 @@-// The interactive-host DRIVER (docs/remote-sessions.md 4c): give the reviewed `connectRelayHost`-// machinery an IPC surface. `initRelayHost` is the Stage-4 twin of the legacy `initRemoteHost`-// (host-service.ts) — it runs BESIDE it (the phone still uses the old flow; that is deleted with the-// dialect in Task 10). It shares the same offer format and pairing-token mint, but everything a-// bridged peer does afterwards flows through `connectRelayHost` (→ `platform.dispatch`/`cast`), not-// the legacy phone RPC vocabulary.+// The interactive-host DRIVER (docs/remote-sessions.md 4c; Team Access, docs/superpowers/specs+// 2026-07-15-team-access-design.md): give the reviewed `connectRelayHost` machinery an IPC surface.+// `initRelayHost` is the Stage-4 twin of the legacy `initRemoteHost` (host-service.ts) — it runs+// BESIDE it (the phone still uses the old flow; that is deleted with the dialect in Task 10). It+// shares the same offer format and pairing-token mint, but everything a bridged peer does afterwards+// flows through `connectRelayHost` (→ `platform.dispatch`/`cast`), not the legacy phone RPC vocabulary.+//+// TEAM ACCESS — a POOL, not one listener. A paying host shares this Mac with up to `seats` devices+// (one seat per connected device). This module manages a POOL of independent `RelayHostSession`s;+// each seat still goes through the UNCHANGED per-session mutual-SAS + ConsentNotice gate in+// relay-host.ts. `relay:host:invite` (and the legacy `relay:host:start`) ADD a seat (cap-checked, no+// supersede); `relay:host:revoke` cuts ONE; `stop()` closes ALL.//// SECURITY — nothing is served before MUTUAL approval. This file only FORWARDS the reviewed gate:// - `onPeerPending` (the E2EE handshake completed, the SAS is known) → send `relay:host:peer-pending`@@ -16,18 +22,23 @@//// REVOCATION reaches sessions started here for free: `connectRelayHost` adds every session to its own// module-level `live` set, and index.ts's revoker calls `killRelayHostsByPeerKey` (relay-host.ts)-// against THAT set — independent of the bookkeeping below.+// against THAT set — independent of the bookkeeping below. `relay:host:revoke` here uses the same cut.import { randomUUID } from 'crypto'import { ipcMain, type BrowserWindow } from 'electron'import { IPC } from '../../shared/ipc'import type { ElectronPlatform } from '../platform-electron'-import { connectRelayHost, type RelayHostSession } from './relay-host'+import { connectRelayHost, killRelayHostsByPeerKey, type RelayHostSession } from './relay-host'import type { RelayTransport } from './relay-socket'import { publicKeyToB64, type KeyPair } from './e2ee'import { encodeOffer } from './pairing'import { loadOrCreatePeerKeyPair } from './peer-identity'-import { isPremium as licenseIsPremium, getStoredEntitlement } from '../../core/license'+import { isPremium as licenseIsPremium, getStoredEntitlement, licensedSeats as licenseSeats } from '../../core/license'import { RELAY_URL, relayAllowed as hostRelayAllowed, mintPairingToken } from './host-service'+import { canAcceptSeat } from './seat-cap'++/** Thrown (as an Error message) when a new invite would exceed the licensed seat cap. The renderer+ * maps it to "All seats in use — add a seat." Host-side/UX enforcement only (see below). */+export const E_SEATS_FULL = 'E_SEATS_FULL'/** Injectable seams — production defaults hit the real license gate / API / OS keyring; tests pass* an in-process transport, a fake mint, and a fixed keypair so nothing touches the network. */@@ -43,19 +54,29 @@ export interface RelayHostDeps {isPremium?: () => booleanrelayAllowed?: () => booleangetEntitlement?: () => string | null+ /** The licensed seat cap (Team Access). Defaults to the real `licensedSeats()` (core/license.ts). */+ licensedSeats?: () => number/** TEST ONLY: override the wire-up (defaults to `connectRelayHost`). */connect?: typeof connectRelayHost}+/** Metadata options for a new seat. `email` is a DISPLAY label only (never trust/identity — the SAS+ * is the gate); it tags the pending/live seat in the Team Access list. */+export interface AddSeatOptions {+ projectId?: string+ email?: string+}+export interface RelayHost {- /** Tear down the current listener / bridged peer (app quit). Idempotent. */+ /** Tear down EVERY listener / bridged peer in the pool (app quit). Idempotent. */stop(): void}/**- * Wire the interactive relay-host IPC. `relay:host:start` gates on Pro, mints a pairing token,- * opens a relay host listener via `connectRelayHost`, and returns the offer to hand to a peer.- * `relay:host:confirm` approves the pending peer; `relay:host:stop` tears the listener down.+ * Wire the interactive relay-host IPC. `relay:host:invite` (and legacy `relay:host:start`) gate on+ * Pro + a free seat, mint a pairing token, open a NEW relay host listener via `connectRelayHost`, and+ * return the offer to hand to a peer — ADDING it to the pool (no supersede). `relay:host:confirm`+ * approves a pending peer; `relay:host:revoke` cuts one; `relay:host:stop` tears the whole pool down.*/export function initRelayHost(win: BrowserWindow,@@ -69,14 +90,17 @@ export function initRelayHost(const isPremium = deps.isPremium ?? licenseIsPremiumconst relayAllowed = deps.relayAllowed ?? hostRelayAllowedconst getEntitlement = deps.getEntitlement ?? getStoredEntitlement+ const licensedSeats = deps.licensedSeats ?? licenseSeats// Renderer-facing token → the pending/live session it names. Populated once the peer is pending- // (its SAS is known); the confirm/close paths resolve the session through it so a stray IPC event- // can only ever act on the session it addresses. Mirrors initRemoteHost's `pendingApprovalId`.+ // (its SAS is known); the confirm/revoke/close paths resolve the session through it so a stray IPC+ // event can only ever act on the session it addresses. Mirrors initRemoteHost's `pendingApprovalId`.const byId = new Map<string, RelayHostSession>()- // The current listener. A fresh `start()` supersedes it (like initRemoteHost's single `session`),- // and `stop()` closes it — both idempotent via `RelayHostSession.close()`.- let current: RelayHostSession | null = null+ // The POOL of minted listeners (Team Access): a session JOINS at mint and LEAVES on close. Its size+ // is the live+pending seat count the cap compares against `licensedSeats()`. The value holds the+ // invite `email` label (display only) that rides this seat's peer-pending/open events. Replaces the+ // old single `current` slot — a pool of N is the whole point of Team Access.+ const pool = new Map<RelayHostSession, { email?: string }>()function send(channel: string, ...args: unknown[]): void {if (!win.isDestroyed()) win.webContents.send(channel, ...args)@@ -86,7 +110,11 @@ export function initRelayHost(for (const [id, s] of byId) if (s === session) byId.delete(id)}- ipcMain.handle(IPC.relayHostStart, async (_e, projectId?: string): Promise<{ offer: string }> => {+ /**+ * Mint ONE pairing + open ONE relay host listener, ADDING it to the pool (no supersede). Cap-checked+ * against the licensed seats. Returns the offer to hand to the invited device.+ */+ async function addSeat({ projectId, email }: AddSeatOptions): Promise<{ offer: string }> {if (!isPremium()) {throw new Error('Remote access requires nodeterm Pro.')}@@ -98,12 +126,15 @@ export function initRelayHost(throw new Error('No entitlement found — please re-activate nodeterm Pro.')}- // Supersede any existing listener before opening a fresh one (single-listener, like the legacy- // interactive host). close() is idempotent, so an already-dropped one is a no-op.- current?.close()- current = null+ // SEAT CAP — count minted (pending + live) sessions in the pool. This is HOST-SIDE / UX+ // enforcement, NOT a server-guaranteed limit: a host that patched it out only cheats itself (it+ // is paying for the seats). Real, un-bypassable enforcement is v2, server-side (the relay refuses+ // the (seats+1)th bridge per account). Do NOT close others here — Team Access is ADDITIVE.+ if (!canAcceptSeat(pool.size, licensedSeats())) {+ throw new Error(E_SEATS_FULL)+ }- // A locked keyring surfaces here as a rejected start() (PeerKeyLockedError / E_PEER_KEY_LOCKED):+ // A locked keyring surfaces here as a rejected invite (PeerKeyLockedError / E_PEER_KEY_LOCKED):// the identity on disk is intact and must not be rotated — the renderer tells the human to unlock.const keys = await loadKeys()const { pairingToken } = await mintToken(entitlement)@@ -118,31 +149,33 @@ export function initRelayHost(ourKeys: keys,platform,transport: deps.transport,- // The single project this hosting session shares with the peer (Task 2 scopes the- // workspace:load response to it). Absent → unscoped, exactly as before.+ // The single project this hosting session shares with the peer. Absent → unscoped, as before.sharedProjectId: projectId,- // The SAS is known — ask the human to compare it. NOTHING is served yet.+ // The SAS is known — ask the human to compare it. NOTHING is served yet. The invite `email`+ // tags this seat in the renderer (display only).onPeerPending: (s) => {rendererId = randomUUID()byId.set(rendererId, s)send(IPC.relayHostPeerPending, {id: rendererId,sas: s.sas(),- peerKeyB64: s.peerKeyB64() ?? ''+ peerKeyB64: s.peerKeyB64() ?? '',})},// Both humans confirmed: the peer is a live CorePlatform client now.onOpen: () => {- if (rendererId) send(IPC.relayHostOpen, { id: rendererId })+ if (rendererId) send(IPC.relayHostOpen, { id: rendererId, email })},- // The relay socket dropped (the peer is already torn down when this fires).+ // The relay socket dropped (the peer is already torn down when this fires). Free the seat.onClose: () => {forget(session)- if (current === session) current = null+ pool.delete(session)if (rendererId) send(IPC.relayHostClosed, { id: rendererId })}})- current = session+ // Join the pool immediately (before any peer connects) so the cap counts this seat from mint.+ pool.set(session, { email })return {offer: encodeOffer({@@ -151,7 +184,21 @@ export function initRelayHost(hostPublicKeyB64: publicKeyToB64(keys.publicKey)})}- })+ }++ // Legacy entry point (RemoteAccessDialog / RemoteSection). Now ADDITIVE + cap-checked (no supersede)+ // — with cap 1 this is bit-for-bit today's single-peer behavior (a 2nd start is refused until the+ // first drops), and with cap N it adds a seat.+ ipcMain.handle(IPC.relayHostStart, (_e, projectId?: string): Promise<{ offer: string }> =>+ addSeat({ projectId })+ )++ // Team Access entry point (Settings → Team Access, Task 4): add a seat tagged with the invitee email.+ ipcMain.handle(+ IPC.relayHostInvite,+ (_e, opts: AddSeatOptions = {}): Promise<{ offer: string }> =>+ addSeat({ projectId: opts?.projectId, email: opts?.email })+ )// The human compared the SAS and pressed Confirm → advance the trust gate for THAT peer. Only the// session named by the id is touched; an unknown id (stale event) is a no-op.@@ -160,9 +207,30 @@ export function initRelayHost(session?.confirm()})+ // Per-peer revoke (Team Access, closes the 4c follow-up): cut ONE bridged peer's LIVE socket+ // immediately and free its seat. Only the session named by the id is touched; an unknown/stale id is+ // a no-op.+ ipcMain.on(IPC.relayHostRevoke, (_e, msg: { id?: string } = {}) => {+ const session = msg?.id ? byId.get(msg.id) : undefined+ if (!session) return+ const peerKeyB64 = session.peerKeyB64()+ // Cut the live socket by peer IDENTITY — the same primitive index.ts's 4c revoker uses+ // (killRelayHostsByPeerKey, relay-host.ts). It closes every live session holding that key, which+ // is the right "remove this device" semantic. Host-side revoke + the seat cap above are UX/host+ // enforcement, NOT a server-guaranteed limit (v2 = server-side). On the desktop relay path a pin+ // never auto-admits (isPinned is phone-only), so cutting the socket already forces a fresh+ // SAS+consent re-pair — no separate unpin is needed to keep the removed device out.+ if (peerKeyB64) killRelayHostsByPeerKey(peerKeyB64)+ // killRelayHostsByPeerKey → session.close() does NOT fire our `onClose` (that runs only on a wire+ // drop, not a local close), so free the seat and notify the renderer here.+ forget(session)+ pool.delete(session)+ send(IPC.relayHostClosed, { id: msg.id })+ })+const stop = (): void => {- current?.close()- current = null+ for (const session of pool.keys()) session.close()+ pool.clear()byId.clear()}diff --git a/src/main/remote/seat-cap.test.ts b/src/main/remote/seat-cap.test.tsnew file mode 100644index 000000000..3873109e8--- /dev/null+++ b/src/main/remote/seat-cap.test.ts@@ -0,0 +1,18 @@+import { describe, it, expect } from 'vitest'+import { canAcceptSeat } from './seat-cap'++describe('canAcceptSeat', () => {+ it('admits when live peers are below the seat cap', () => {+ expect(canAcceptSeat(0, 1)).toBe(true)+ expect(canAcceptSeat(2, 3)).toBe(true)+ })++ it('refuses when the cap is reached', () => {+ expect(canAcceptSeat(1, 1)).toBe(false)+ expect(canAcceptSeat(3, 3)).toBe(false)+ })++ it('refuses every seat when the cap is 0 (free / no entitlement)', () => {+ expect(canAcceptSeat(0, 0)).toBe(false)+ })+})diff --git a/src/main/remote/seat-cap.ts b/src/main/remote/seat-cap.tsnew file mode 100644index 000000000..6a72af04f--- /dev/null+++ b/src/main/remote/seat-cap.ts@@ -0,0 +1,12 @@+// Team Access seat cap (pure). The relay host may hold up to `seats` live/pending peer sessions at+// once; `seats` is resolved from the license entitlement (core/license.ts `licensedSeats()`).+//+// This is HOST-SIDE / UX enforcement, NOT a server-guaranteed limit: a host that patched this out+// only cheats itself (it is paying for the seats). Real, un-bypassable enforcement is v2, server-side+// (the relay refuses the (seats+1)th bridge per account) — see docs/superpowers/specs Team Access.+//+// `seats` of 0 (free / no entitlement) always refuses — defence in depth behind the `isPremium` gate,+// which already blocks free users from hosting at all.+export function canAcceptSeat(liveCount: number, seats: number): boolean {+ return liveCount < seats+}diff --git a/src/preload/index.ts b/src/preload/index.tsindex ddcce94f0..aa7fbf358 100644--- a/src/preload/index.ts+++ b/src/preload/index.ts@@ -47,7 +47,7 @@ const subscribePeerPending = subscribe<[{ sas: string | null; id: string }]>(IPC// New relay tunnel (Stage 4). Non-per-id host events reuse the fan-out helper; per-connection// client events (sas/approved/frame/closed) attach directly per connectionId.const subscribeRelayPeerPending = subscribe<[RelayPeerPending]>(IPC.relayHostPeerPending)-const subscribeRelayHostOpen = subscribe<[{ id: string }]>(IPC.relayHostOpen)+const subscribeRelayHostOpen = subscribe<[{ id: string; email?: string }]>(IPC.relayHostOpen)const subscribeRelayHostClosed = subscribe<[{ id: string }]>(IPC.relayHostClosed)const api: NodeTerminalApi = {@@ -367,7 +367,10 @@ const api: NodeTerminalApi = {},relayHost: {start: (projectId?: string) => ipcRenderer.invoke(IPC.relayHostStart, projectId),+ invite: (opts?: { projectId?: string; email?: string }) =>+ ipcRenderer.invoke(IPC.relayHostInvite, opts ?? {}),stop: () => ipcRenderer.invoke(IPC.relayHostStop),+ revoke: (id: string) => ipcRenderer.send(IPC.relayHostRevoke, { id }),onPeerPending: subscribeRelayPeerPending,confirm: (id: string) => ipcRenderer.send(IPC.relayHostConfirm, { id }),onOpen: subscribeRelayHostOpen,diff --git a/src/renderer/bridge/stubs.test.ts b/src/renderer/bridge/stubs.test.tsindex 1b98212f7..ec6cb06a1 100644--- a/src/renderer/bridge/stubs.test.ts+++ b/src/renderer/bridge/stubs.test.ts@@ -33,6 +33,7 @@ describe('bridge stubs', () => {const s = buildStubApi()// Entry points reject with the coded error so the renderer hides the affordance.await expect(s.relayHost.start()).rejects.toMatchObject({ code: E_UNSUPPORTED })+ await expect(s.relayHost.invite({ email: '[email protected]' })).rejects.toMatchObject({ code: E_UNSUPPORTED })await expect(s.relayHost.stop()).rejects.toMatchObject({ code: E_UNSUPPORTED })await expect(s.relayClient.connect('offer')).rejects.toMatchObject({ code: E_UNSUPPORTED })// Subscriptions must return callable no-op unsubscribes (used as React effect cleanups).@@ -51,6 +52,7 @@ describe('bridge stubs', () => {// Void gate/frame members are inert (no connection ever exists here).expect(() => {s.relayHost.confirm('id')+ s.relayHost.revoke('id')s.relayClient.confirm('c')s.relayClient.send('c', '{}')s.relayClient.disconnect('c')diff --git a/src/renderer/bridge/stubs.ts b/src/renderer/bridge/stubs.tsindex 465dc092a..0c0c51085 100644--- a/src/renderer/bridge/stubs.ts+++ b/src/renderer/bridge/stubs.ts@@ -257,7 +257,9 @@ export function buildStubApi(): Omit<// inert no-ops (there is no connectionId to act on) and the subscriptions are no-op unsubscribes.relayHost: {start: U('relayHost.start'),+ invite: U('relayHost.invite'),stop: U('relayHost.stop'),+ revoke: noop,onPeerPending: noopUnsub,confirm: noop,onOpen: noopUnsub,diff --git a/src/shared/ipc.ts b/src/shared/ipc.tsindex 1cba96c7a..6e11eb08b 100644--- a/src/shared/ipc.ts+++ b/src/shared/ipc.ts@@ -231,6 +231,12 @@ export const IPC = {// the host human answers with `relayHostConfirm` (id). `relayHostOpen` / `relayHostClosed` fire// main → renderer when a bridged peer becomes a live client / drops (payload `{ id }`).relayHostStart: 'relay:host:start',+ // Team Access (multi-seat): `relayHostInvite` ADDS a seat (invoke, `{ projectId?, email? }` →+ // `{ offer }`, cap-checked → rejects `E_SEATS_FULL`); `relayHostRevoke` (send, `{ id }`) cuts one+ // bridged peer's live session. `relayHostPeerPending`/`relayHostOpen` now also carry the seat+ // `email` label. Host-side cap/revoke are UX/host enforcement, not a server-guaranteed limit (v2).+ relayHostInvite: 'relay:host:invite',+ relayHostRevoke: 'relay:host:revoke',relayHostStop: 'relay:host:stop',relayHostPeerPending: 'relay:host:peer-pending',relayHostConfirm: 'relay:host:confirm',diff --git a/src/shared/types.ts b/src/shared/types.tsindex 92e700f6a..3171d313d 100644--- a/src/shared/types.ts+++ b/src/shared/types.ts@@ -1149,6 +1149,9 @@ export interface RelayPeerPending {id: stringsas: string | nullpeerKeyB64: string+ /** Team Access: the invitee email this seat was invited with, if any. DISPLAY label only (never+ * trust/identity — the SAS is the gate); used to tag the row in the connected-devices list. */+ email?: string}/**@@ -1164,8 +1167,20 @@ export interface RelayHostApi {* single project this hosting session shares with the peer; omit for the legacy whole-workspace view.*/start(projectId?: string): Promise<{ offer: string }>- /** Leave host mode: close the relay connection (drops every bridged peer). */+ /**+ * Team Access: ADD a seat — mint a fresh pairing offer for one more device (no supersede), tagged+ * with the optional invitee `email` (display label only). Rejects `E_SEATS_FULL` when the licensed+ * seat cap is reached, and with the Pro / dev-build errors `start` uses. `projectId` scopes the+ * shared project as in `start`.+ */+ invite(opts?: { projectId?: string; email?: string }): Promise<{ offer: string }>+ /** Leave host mode: close every bridged peer in the pool. */stop(): Promise<void>+ /**+ * Team Access: per-peer revoke — cut ONE bridged peer's live session immediately (by its id) and+ * free its seat. Distinct from `stop()` (which drops all).+ */+ revoke(id: string): void/*** Fires when a client finishes the handshake and is awaiting approval. The host must `confirm()`* before the peer is admitted as a client. Returns an unsubscribe function.@@ -1173,8 +1188,9 @@ export interface RelayHostApi {onPeerPending(listener: (info: RelayPeerPending) => void): () => void/** Approve the pending peer (by its pending id) after comparing the SAS → it joins as a client. */confirm(id: string): void- /** Fires when a bridged peer becomes a live client (both humans confirmed). Returns unsubscribe. */- onOpen(listener: (info: { id: string }) => void): () => void+ /** Fires when a bridged peer becomes a live client (both humans confirmed). Returns unsubscribe.+ * `email` is the seat's invite label, if any (Team Access). */+ onOpen(listener: (info: { id: string; email?: string }) => void): () => void/** Fires when a bridged peer's connection drops. Returns an unsubscribe function. */onClosed(listener: (info: { id: string }) => void): () => void}