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.
Team Access Implementation Plan
For agentic workers: REQUIRED SUB-SKILL: superpowers:subagent-driven-development. Each task is a fresh subagent + two-stage review. TDD, minimal diffs, commit per task.
Goal: Turn the single-peer relay host into a paid, multi-seat "Team Access" — the paying host
shares this Mac with up to seats devices (one seat per connected device), invited by email,
$5/seat (billed by Stripe, backend).
Architecture: The core (CorePlatform.clientIds(), presence, canvas-sync) is already N-client;
only the relay-host LISTENER is single (relay-host-service.ts current). Change it to a pool of up
to seats RelayHostSessions; seats comes from the license entitlement (backend adds the field;
absent → 1). Add a Settings → Team Access section (pitch, seat counter, connected-device list with
email labels + per-peer Remove, invite→code+share, add-seats CTA). Trust is unchanged: each seat is a
separate mutual-SAS + ConsentNotice grant.
Tech Stack: Electron main/renderer/preload, TypeScript, the existing relay tunnel
(connectRelayHost, mintPairingToken, killRelayHostsByPeerKey), Ed25519 entitlement
(core/license.ts), zustand renderer stores, vitest.
Global Constraints
- No crypto/handshake file changes (relay-socket/trust/client/host, e2ee, pairing, revocation, mutual-approval, identity). This is pool-management + one entitlement field + UI. The whole-branch review verifies the diff touches none of them.
- Backward compat:
seatsabsent → 1 → bit-for-bit today's single-peer behavior. Hosting still gates onisPremium(unchanged) — a free user cannot host. - Trust unchanged: every seat goes through the existing per-session mutual-SAS + ConsentNotice. The seat cap is UX/host enforcement, NOT a security boundary (comment it at the enforcement site).
- Backend is a separate repo (api.nodeterm.dev): the
seatssigner (Stripe per-seat), real email delivery, and v2 server-side enforcement are documented follow-ups, not built here. - English for all code/comments/UI copy. Match surrounding style. Subagent model: Opus 4.8.
Task 1: seats in the license entitlement
Files:
- Modify:
src/core/license.ts(Payload,LicenseStatus,statusFrom, agetSeats()/exposed field) - Modify:
src/shared/types.ts(theLicenseStatus/license-api shape the renderer sees, if seats surface there) - Test:
src/core/license.test.ts(or the existing license test)
Interfaces:
- Produces:
LicenseStatus.seats: number(resolved: premium+field → N; premium+no field → 1; not active → 0). A main-side getterlicensedSeats(): numberthe relay-host reads (Task 2).
What to build:
Payloadgains optionalseats?: number(the backend signs it into the Ed25519 token; verified offline exactly liketier/exp— no new verification path).statusFromresolvesseats: active premium →payload.seats ?? 1; inactive/free →0.- Expose
seatsonLicenseStatusand alicensedSeats()helper (reads the current verified token → the resolved seats) for the main process to consult for the cap. - Do NOT change the
isPremiumgate or any verification/expiry logic.
Tests (TDD): a token with seats:5 (premium) → status.seats 5; a premium token with no seats
field → 1; an expired/invalid/free token → 0. licensedSeats() returns the same.
Task 2: Multi-peer relay pool + invite/revoke (the core)
Files:
- Modify:
src/main/remote/relay-host-service.ts(singlecurrent→ a pool;relay:host:invite,relay:host:revoke;onOpen/onClosedcarry seat id + email;stop()closes all) - Modify:
src/shared/ipc.ts(relayHostInvite,relayHostRevoke;relay:host:open/closed/peer-pendingpayloads gainemail?) - Modify:
src/preload/index.ts+src/shared/types.ts(relayHost.invite(opts) → {offer},relayHost.revoke(id)) +src/renderer/bridge/*(shims — desktop-only path; a browser bridge stub/degrade is fine since hosting is Electron) - Create:
src/main/remote/seat-cap.ts(purecanAcceptSeat(liveCount, seats): boolean) - Test:
src/main/remote/relay-host-service.test.ts,src/main/remote/seat-cap.test.ts
Interfaces:
- Consumes:
licensedSeats()(Task 1); the existingconnectRelayHost,mintPairingToken,killRelayHostsByPeerKey,RelayHostSession(unchanged — do NOT modify the handshake files). - Produces:
relay:host:invite {projectId?, email?} → { offer }(mints ONE pairing, adds to pool, cap-checked, returns the offer to share; refuses withE_SEATS_FULLat cap);relay:host:revoke {id}(closes ONE live session);relay:host:open/closed/peer-pendingevents now carry the seat's renderer id +email?.
What to build:
- Generalize the single
currentto a pool (keepbyId: Map<rendererId, RelayHostSession>as the live/pending set; drop thecurrentsingle-slot supersede). relay:host:invite: gate onisPremium+relayAllowed(asstartdoes today) → checkcanAcceptSeat(livePeers, licensedSeats()); if full, throwE_SEATS_FULL. ElseconnectRelayHost(...)a NEW session (do NOT close others), hold the{email}on it, add to the pool, return{ offer }. (This REPLACES the supersedingstart; keepstartas an alias/compat if anything calls it, or migrate callers — checkRemoteAccessDialog/RemoteSectionwhich callrelayHost.start()and route them toinvite.)onOpen(session)→ emitrelay:host:open { id, email };onClosed→ remove from pool, emitrelay:host:closed { id }. Peer-pending carriesemail.relay:host:revoke {id}→ resolve the session in the pool →killRelayHostsByPeerKey(peerKey)for its peer (orsession.close()), which cuts the live socket + unpins (the 4c mechanism); remove from pool. A code comment: host-side cap is UX, not server-guaranteed.stop()closes ALL sessions in the pool.- Cap comment: enforcement is host-side/UX (v2 = server-side).
Tests (TDD): invite adds a session + returns an offer; a 2nd invite at cap(1) →
E_SEATS_FULL; with cap 3, three invites succeed and a 4th is refused; revoke(id) closes only that
session (spy the close) and frees a seat so a fresh invite succeeds; onClosed frees the seat;
stop() closes all; email rides peer-pending/open. seat-cap.test.ts: canAcceptSeat(0,1)=true,
(1,1)=false, (2,3)=true, (3,3)=false, (n,0)=false. Run the crypto/carrier gate unchanged.
Task 3: Team Access renderer store (live seats + pending)
Files:
- Create:
src/renderer/state/teamAccess.ts(zustand store) + pureteamAccessCore.tsif a reducer helps - Modify:
src/renderer/canvas/Canvas.tsxOR a small effect module — subscribe torelayHost.onPeerPending/onOpen/onClosedand feed the store (mirror how the existing relay-host renderer events are consumed) - Test:
src/renderer/state/teamAccess.test.ts
Interfaces:
- Consumes:
relayHost.onPeerPending/onOpen/onClosed(Task 2 events, now withemail/id). - Produces:
useTeamAccessstore:{ seats: SeatEntry[] }whereSeatEntry = { id, email?, name?, color?, status: 'pending' | 'connected' }; selectorsusedCount(),pending().
What to build: a transient store of the live/pending seats, updated on open (→ connected, attach the peer's presence name/color if resolvable) / closed (→ remove) / peer-pending (→ pending, with email). Cleared on host stop. The presence name/color for a seat can come from the presence store by matching the peer — keep v1 simple (email label + a generic "connected" if the presence name isn't easily joinable; note it).
Tests (TDD): peer-pending adds a pending seat with its email; open flips it to connected;
closed removes it; usedCount() counts connected. RED→GREEN.
Task 4: Settings → Team Access section (the product surface)
Files:
- Create:
src/renderer/components/settings/sections/TeamAccessSection.tsx - Modify:
src/renderer/components/settings/SettingsPage.tsx(register the nav entry + route) - Modify:
src/renderer/components/settings/nav.ts(or wherever the section list lives) - Create:
src/renderer/components/settings/teamAccessView.ts(pure view-model — testable) - Modify:
src/renderer/styles.css(section styling) - Test:
src/renderer/components/settings/teamAccessView.test.ts
Interfaces:
- Consumes:
useTeamAccess(Task 3), the license statusseats(Task 1),relayHost.invite/revoke(Task 2), the license checkout opener (existing),shell.openExternal(for mailto/checkout). - Produces: the UI. Pure helpers:
teamAccessView({ premium, seats, used }) → { gated, counterText, canInvite };inviteShare({ offer, email }) → { copyText, mailtoUrl }.
What to build:
- Gate: not premium → the pitch ("Share this Mac with your team — $5/seat/month") + a
Get Team Access button opening the Stripe checkout (existing
licensecheckout URL). Premium → the panel. - Seat counter:
Used {used} / {seats}from the store + license. - Connected devices list: one row per seat (
useTeamAccess) — email label + presence name/color (if available) + a Remove button →relayHost.revoke(id). Pending rows show "waiting to connect…". - Invite: an email
<input>→ Generate invite →relayHost.invite({ email })→ show the returned offer code + a share row [Copy] [Open in Mail] (inviteSharebuilds the copy text + amailto:{email}?subject=...&body=...with the code+link;shell.openExternalopens it). At cap, the invite is disabled with "All seats in use — add a seat". - Add seats CTA: opens the checkout (quantity handled by Stripe).
- Match the existing settings-section look; keep copy honest (this grants shell access — reuse the ConsentNotice framing in the pitch).
Tests (TDD): teamAccessView — not premium → gated; premium+used<seats → canInvite; used==seats →
!canInvite; counterText. inviteShare — the mailto contains the code + the invitee email + a body.
JSX relies on typecheck.
Task 5: Gate + docs + acceptance
Files:
- Modify:
docs/remote-sessions.md(Team Access section: multi-seat, device-seat model, host-side cap, per-peer revoke now wired, the backend contract follow-ups); flip the 4c "per-peer revoke UI" follow-up to landed. - Modify: the Team Access spec status → landed.
What to build / do:
npm run typecheck+ fullnpx vitest rungreen (the pre-existing workspace-watcher fs-timing failure is the only allowed red — confirm it also fails on plain main).- Confirm NO crypto/handshake file changed (
git diff --name-only main..HEAD | grep -iE 'relay-socket|relay-trust|relay-client|relay-host\.ts|e2ee|pairing|revocation|mutual-approval| identity'→ empty; noterelay-host-service.tsandrelay-host.tsare different — the service is ours to change, the.tshandshake is NOT). - Docs: the Team Access model + the N-instance acceptance checklist (host seats≥3, invite 2, both connect via SAS+consent, list shows email labels + Used 2/3, Remove drops one, a 4th invite past cap is refused, cursors/chat/dino from all peers).
- Backend contract recorded for the api.nodeterm.dev effort (seats signer, email delivery, v2 server enforcement).
Merge gate
Whole-branch security review: multi-peer shell access (each seat a separate SAS grant), the cap is UX, revoke cuts the LIVE socket, no crypto/handshake file touched, backward-compat (seats absent → 1, free can't host). Then merge to main; the backend items ship separately.
Self-review (coverage)
- Spec A (multi-peer pool) → Task 2. B (entitlement seats) → Task 1. C (settings section) → Task 4. D (per-peer revoke) → Task 2 (mechanism/IPC) + Task 4 (Remove button). E (email label) → Task 2 (carried) + Task 3 (store) + Task 4 (shown). Backend contract → Task 5 docs. Security → Task 5 review gate. All covered.