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): free-tier standing host — quota-gated admission, n/5 notices, hard block at 6th
enes9a5afea069fa
diff --git a/src/main/remote/standing-host.ts b/src/main/remote/standing-host.tsindex d815a961b..1770ceb51 100644--- a/src/main/remote/standing-host.ts+++ b/src/main/remote/standing-host.ts@@ -1,7 +1,8 @@// Standing (always-on) phone host — the desktop side of the iOS relay-client "reach my Mac from// anywhere" flow.//-// When Settings → phoneAccessEnabled is on AND the device is Pro, this keeps a HOST relay+// When Settings → phoneAccessEnabled is on AND the device is Pro **or has free-tier quota left**,+// this keeps a HOST relay// connection registered under the host's stable id (base64url(sha256(hostPublicKey)).slice(0,22)),// so a previously-paired phone can join over the relay at any time and attach to the host's tmux// sessions after approval. Unlike the interactive host (a single-use offer you hand out), the@@ -18,11 +19,13 @@// unit-tested `approved-devices-core`.import { randomUUID } from 'crypto'-import { dialog, ipcMain, type BrowserWindow } from 'electron'+import { dialog, ipcMain, Notification, type BrowserWindow } from 'electron'import { IPC } from '../../shared/ipc'import type { CanvasMutation, Settings } from '../../shared/types'import { PtyManager } from '../../core/pty-manager'import { getStoredEntitlement, isPremium } from '../../core/license'+import { consumeRelayUse, relayQuotaAvailable } from '../../core/relay-quota'+import { getDeviceId } from '../../core/device-id'import { createPhonePresence, type PhonePresence } from './phone-presence'import { publicKeyToB64, type KeyPair } from './e2ee'import {@@ -51,9 +54,14 @@ interface HostTokenResponse {exp: number}-/** Mint a standing host token from the API, proving Pro entitlement. Returns null on any failure. */+/**+ * Mint a standing host token from the API. Pro proves entitlement; the free tier sends+ * its deviceId instead (backend admits it against the server-side free-tier policy —+ * until that ships, the mint fails and free hosting simply stays down, i.e. today's+ * behavior). Returns null on any failure.+ */async function mintHostToken(- entitlement: string,+ entitlement: string | null,hostPublicKeyB64: string): Promise<HostTokenResponse | null> {const ctrl = new AbortController()@@ -62,7 +70,9 @@ async function mintHostToken(const res = await fetch(`${API_BASE}/v1/relay/host-token`, {method: 'POST',headers: { 'content-type': 'application/json' },- body: JSON.stringify({ entitlement, hostPublicKeyB64 }),+ body: JSON.stringify(+ entitlement ? { entitlement, hostPublicKeyB64 } : { deviceId: getDeviceId(), hostPublicKeyB64 }+ ),signal: ctrl.signal})if (!res.ok) return null@@ -102,6 +112,15 @@ function reportKeyLocked(err: Error): void {console.error('[standing-host] host identity is locked:', err.message)}+/** Quota notices surface as OS notifications: the standing host has no UI of its own. */+function notifyQuota(body: string): void {+ try {+ new Notification({ title: 'nodeterm — remote access', body }).show()+ } catch {+ // Notifications unavailable (headless/CI): the renderer banner still shows the state.+ }+}+export interface StandingHost {/** Explicit toggle (from the Settings switch). Reconciles the connection immediately. */setEnabled(enabled: boolean): void@@ -239,6 +258,21 @@ export function initStandingHost(}const s = pooled.sessionconst pub = s.peerPublicKeyB64()+ // Free-tier metering: every bridged phone consumes a (peer, local-day) slot — pinned+ // or not. 1st use of the month is silent, 2nd+ notifies, over-limit is refused+ // BEFORE any approval so an exhausted free host never serves a new pair.+ const q = consumeRelayUse(pub ?? 'unknown-peer')+ if (q.kind === 'exhausted') {+ notifyQuota(+ `Remote access limit reached (${q.limit}/${q.limit} this month). Upgrade to Pro for unlimited access.`+ )+ removeFromPool(pooled)+ ensurePool()+ return+ }+ if (q.kind === 'ok' && q.used >= 2) {+ notifyQuota(`Remote access ${q.used}/${q.limit} this month`)+ }let storetry {store = await loadApprovedDevices()@@ -269,10 +303,11 @@ export function initStandingHost(if (!running || opening || pendingCount() >= TARGET_PENDING) returnopening = truetry {- // Re-verify Pro on every (re)connect so a lapsed entitlement tears the standing host down.- if (!isPremium()) return stop()- const entitlement = getStoredEntitlement()- if (!entitlement) return stop()+ // Re-verify admission on every (re)connect: a lapsed Pro tears the host down; a+ // free-tier host runs only while the monthly quota could still admit a bridge.+ if (!isPremium() && !relayQuotaAvailable()) return stop()+ const entitlement = getStoredEntitlement() // null on free tier → mint by deviceId+ if (isPremium() && !entitlement) return stop()// The host key is the identity every paired phone PINNED. If the OS keyring is locked we// cannot READ it (host-identity refuses to regenerate over it — that would rotate the// identity and force every phone to re-approve). There is nothing to advertise, so stop:@@ -354,7 +389,7 @@ export function initStandingHost(}function reconcile(): void {- const want = enabled && isPremium() && relayAllowed()+ const want = enabled && (isPremium() || relayQuotaAvailable()) && relayAllowed()if (want && !running) start()else if (!want && running) stop()}