Skip to content

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.

feat: expose relayQuota over preload/bridge and init it in main

enes1831bb99dc04
diff --git a/src/main/index.ts b/src/main/index.ts
index f15ed94b5..e3ac624f6 100644
--- a/src/main/index.ts
+++ b/src/main/index.ts
@@ -49,6 +49,7 @@ import { initTranscriptIndex, searchTranscripts } from '../core/transcript-index
import { initTelemetry } from './telemetry'
import { initClaudeUsage } from './claude-usage'
import { initLicense, isPremium, getStoredEntitlement } from '../core/license'
+import { initRelayQuota, broadcastRelayQuota } from '../core/relay-quota'
import { initClaudeAccounts } from './claude-accounts'
import { claudeCliCaps, registerClaudeCliIpc } from '../core/claude-cli'
import { claudeConfigDirFor } from '../core/claude-config-dir'
@@ -1019,7 +1020,12 @@ app.whenReady().then(async () => {
// async launch-time entitlement refresh settles (fixes the boot race where Pro isn't yet valid
// when syncFromSettings first runs).
let standingHost: ReturnType<typeof initStandingHost> | undefined
- initLicense(() => standingHost?.syncFromSettings())
+ initRelayQuota()
+ initLicense(() => {
+ standingHost?.syncFromSettings()
+ // A Pro flip changes `unlimited` in the quota status — push the fresh value.
+ broadcastRelayQuota()
+ })
// 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)
diff --git a/src/preload/index.ts b/src/preload/index.ts
index aa7fbf358..cd738bd18 100644
--- a/src/preload/index.ts
+++ b/src/preload/index.ts
@@ -287,6 +287,14 @@ const api: NodeTerminalApi = {
return () => ipcRenderer.removeListener(IPC.licenseChanged, handler)
}
},
+ relayQuota: {
+ getStatus: () => ipcRenderer.invoke(IPC.relayQuotaStatus),
+ onChange: (listener) => {
+ const h = (_e: unknown, s: Parameters<typeof listener>[0]) => listener(s)
+ ipcRenderer.on(IPC.relayQuotaChanged, h)
+ return () => ipcRenderer.removeListener(IPC.relayQuotaChanged, h)
+ }
+ },
announcements: {
fetch: () => ipcRenderer.invoke(IPC.announcementsFetch)
},
diff --git a/src/renderer/bridge/relay-api.test.ts b/src/renderer/bridge/relay-api.test.ts
index 014b549e8..08d44e5a0 100644
--- a/src/renderer/bridge/relay-api.test.ts
+++ b/src/renderer/bridge/relay-api.test.ts
@@ -46,6 +46,7 @@ function fakeLocalApi() {
settings: { NAME: 'local-settings' },
dialog: { NAME: 'local-dialog' },
license: { NAME: 'local-license' },
+ relayQuota: { NAME: 'local-relay-quota' },
pty: { onData: ptyOnData },
claude: { cliCaps: () => Promise.resolve({}), readTranscript: () => Promise.reject() },
relayClient: { disconnect: vi.fn() }
@@ -91,6 +92,7 @@ describe('buildRelayApi', () => {
expect(api.clipboard).toBe(local.clipboard)
expect(api.settings).toBe(local.settings)
expect(api.license).toBe(local.license)
+ expect(api.relayQuota).toBe(local.relayQuota)
})
it('routes the folder/file picker to the HOST fs, not the local native dialog', () => {
diff --git a/src/renderer/bridge/relay-api.ts b/src/renderer/bridge/relay-api.ts
index a9ec33760..6ea9d3831 100644
--- a/src/renderer/bridge/relay-api.ts
+++ b/src/renderer/bridge/relay-api.ts
@@ -12,8 +12,8 @@
// the `onAgentStatus`/`onSubagentActivity` streams, `claude.cliCaps`, `userDataDir`) route over the
// relay RpcClient → they hit the REMOTE core. This is what makes the tab actually remote: its
// terminals, repos, files, canvas and presence all live on the host's machine.
-// • APP-GLOBAL namespaces (`updates`, `license`, `clipboard`, `shell`, `dialog`, `media`, `settings`,
-// `pairing`, `announcements`, `usage`, `ssh*`, `remote*`, `relay*`, notifications, menu events)
+// • APP-GLOBAL namespaces (`updates`, `license`, `relayQuota`, `clipboard`, `shell`, `dialog`, `media`,
+// `settings`, `pairing`, `announcements`, `usage`, `ssh*`, `remote*`, `relay*`, notifications, menu events)
// stay LOCAL (`window.nodeTerminal.*`). Your update banner shows YOUR version, a file picker
// browses YOUR disk, your UI settings/theme are yours, and the relay-tunnel machinery itself is
// your local main process. Routing one of these to the remote core would be a latent bug.
@@ -73,7 +73,7 @@ export function buildRelayApi(connectionId: string, transport?: FrameTransport):
const api: NodeTerminalApi = {
// ── Base: every APP-GLOBAL namespace stays LOCAL. Spreading the whole preload gives the real
- // desktop implementations (updates/license/clipboard/shell/dialog/media/settings/pairing/
+ // desktop implementations (updates/license/relayQuota/clipboard/shell/dialog/media/settings/pairing/
// announcements/usage/ssh*/remote*/relay*/notifications/menu events). The core-bound spreads
// below override the handful that must hit the remote core.
...local,
diff --git a/src/renderer/bridge/stubs.ts b/src/renderer/bridge/stubs.ts
index 0c0c51085..77a82c27b 100644
--- a/src/renderer/bridge/stubs.ts
+++ b/src/renderer/bridge/stubs.ts
@@ -201,6 +201,12 @@ export function buildStubApi(): Omit<
getStatus: U('license.getStatus'),
onChange: noopUnsub
},
+ relayQuota: {
+ // Server Edition does not host the phone relay; report unlimited so every quota
+ // surface hides in the browser instead of showing a broken meter.
+ getStatus: async () => ({ month: '', used: 0, limit: 5, unlimited: true }),
+ onChange: noopUnsub
+ },
contextLink: {
setLinks: pnoop,
info: U('contextLink.info')
diff --git a/src/renderer/state/relayQuota.ts b/src/renderer/state/relayQuota.ts
new file mode 100644
index 000000000..791a40465
--- /dev/null
+++ b/src/renderer/state/relayQuota.ts
@@ -0,0 +1,18 @@
+import { create } from 'zustand'
+import type { RelayQuotaStatus } from '@shared/types'
+
+interface RelayQuotaState {
+ status: RelayQuotaStatus | null
+ hydrate(): Promise<void>
+}
+
+/** Mirror of the main-process relay quota (free-tier remote-access meter). */
+export const useRelayQuota = create<RelayQuotaState>((set) => {
+ window.nodeTerminal.relayQuota.onChange((status) => set({ status }))
+ return {
+ status: null,
+ async hydrate() {
+ set({ status: await window.nodeTerminal.relayQuota.getStatus() })
+ }
+ }
+})