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(relay): thread sharedProjectId through relayHost.start → session (project-scope Task 1)

enes080f3bc7d95e
diff --git a/src/main/remote/relay-host-service.test.ts b/src/main/remote/relay-host-service.test.ts
index f7873c83e..cbe70f0ff 100644
--- a/src/main/remote/relay-host-service.test.ts
+++ b/src/main/remote/relay-host-service.test.ts
@@ -42,6 +42,7 @@ vi.mock('./approved-devices', () => ({
}))
import { initRelayHost } from './relay-host-service'
+import type { RelayHostSession } from './relay-host'
import { connectRelay, type RelayTransport } from './relay-socket'
import { createTrustGate, type TrustGate } from './relay-trust'
import { genKeyPair, publicKeyToB64 } from './e2ee'
@@ -286,6 +287,46 @@ describe('initRelayHost — confirm() opens the session', () => {
})
})
+describe('initRelayHost — sharedProjectId threads start → connect', () => {
+ /** Inject a fake `connect` that records the options it was called with. */
+ function wireWithCapture(): { opts: () => any } {
+ let captured: any = null
+ const win = fakeWin()
+ initRelayHost(win as never, platform, {
+ loadKeys: async () => genKeyPair(),
+ mintToken: async () => ({ pairingToken: 'tok-123' }),
+ isPremium: () => true,
+ relayAllowed: () => true,
+ getEntitlement: () => 'ent-abc',
+ connect: (o) => {
+ captured = o
+ // A no-op session; start() only needs the offer, which it builds itself.
+ return {
+ clientId: () => null,
+ sas: () => null,
+ peerKeyB64: () => null,
+ sharedProjectId: () => o.sharedProjectId,
+ confirm: () => {},
+ close: () => {}
+ } as unknown as RelayHostSession
+ }
+ })
+ return { opts: () => captured }
+ }
+
+ it('start(projectId) passes sharedProjectId to connect', async () => {
+ const cap = wireWithCapture()
+ await h.handlers[IPC.relayHostStart]({}, 'proj-1')
+ expect(cap.opts()?.sharedProjectId).toBe('proj-1')
+ })
+
+ it('start() with no arg leaves sharedProjectId undefined', async () => {
+ const cap = wireWithCapture()
+ await h.handlers[IPC.relayHostStart]({})
+ expect(cap.opts()?.sharedProjectId).toBeUndefined()
+ })
+})
+
describe('initRelayHost — teardown', () => {
it('stop() tears the live peer down and notifies the renderer', async () => {
const host = wireHost()
diff --git a/src/main/remote/relay-host-service.ts b/src/main/remote/relay-host-service.ts
index 988f4b4a2..81966bf1f 100644
--- a/src/main/remote/relay-host-service.ts
+++ b/src/main/remote/relay-host-service.ts
@@ -86,7 +86,7 @@ export function initRelayHost(
for (const [id, s] of byId) if (s === session) byId.delete(id)
}
- ipcMain.handle(IPC.relayHostStart, async (): Promise<{ offer: string }> => {
+ ipcMain.handle(IPC.relayHostStart, async (_e, projectId?: string): Promise<{ offer: string }> => {
if (!isPremium()) {
throw new Error('Remote access requires nodeterm Pro.')
}
@@ -118,6 +118,9 @@ 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.
+ sharedProjectId: projectId,
// The SAS is known — ask the human to compare it. NOTHING is served yet.
onPeerPending: (s) => {
rendererId = randomUUID()
diff --git a/src/main/remote/relay-host.ts b/src/main/remote/relay-host.ts
index 2ae4a59e5..2f083b4ec 100644
--- a/src/main/remote/relay-host.ts
+++ b/src/main/remote/relay-host.ts
@@ -37,6 +37,8 @@ export interface RelayHostSession {
sas(): string | null
/** The peer's stable box public key (base64), or null before the handshake learned it. */
peerKeyB64(): string | null
+ /** The single project this hosting session shares with the peer, or undefined if unscoped. */
+ sharedProjectId(): string | undefined
/** This human confirmed the SAS (from the approve dialog). */
confirm(): void
/** Tear down: unregister the sink (leave + dropClient + prune), close the socket. Idempotent. */
@@ -50,6 +52,9 @@ export interface ConnectRelayHostOptions {
platform: ElectronPlatform
/** TEST ONLY: an in-process RelayTransport. Production opens a real ws (relay-socket.ts). */
transport?: RelayTransport
+ /** The single project this hosting session shares with the peer. Undefined → unscoped (legacy
+ * behaviour: the peer sees the whole workspace). Held on the session for Task 2's scoped serve. */
+ sharedProjectId?: string
/** The SAS is known — ask the human to compare it. */
onPeerPending(session: RelayHostSession): void
/** Mutually approved: the peer is a CorePlatform client of this core now. */
@@ -96,6 +101,7 @@ export function connectRelayHost(opts: ConnectRelayHostOptions): RelayHostSessio
clientId: () => clientId,
sas: () => gate?.sas() ?? null,
peerKeyB64: () => gate?.peerKeyB64() ?? null,
+ sharedProjectId: () => opts.sharedProjectId,
confirm: () => gate?.confirmHere(),
close() {
if (closed) return
diff --git a/src/preload/index.ts b/src/preload/index.ts
index 6708adfba..51387b0bd 100644
--- a/src/preload/index.ts
+++ b/src/preload/index.ts
@@ -365,7 +365,7 @@ const api: NodeTerminalApi = {
setPhoneAccess: (enabled) => ipcRenderer.send(IPC.remoteStandingHostSet, enabled)
},
relayHost: {
- start: () => ipcRenderer.invoke(IPC.relayHostStart),
+ start: (projectId?: string) => ipcRenderer.invoke(IPC.relayHostStart, projectId),
stop: () => ipcRenderer.invoke(IPC.relayHostStop),
onPeerPending: subscribeRelayPeerPending,
confirm: (id: string) => ipcRenderer.send(IPC.relayHostConfirm, { id }),
diff --git a/src/shared/types.ts b/src/shared/types.ts
index 77bf1a5e7..c39b5125f 100644
--- a/src/shared/types.ts
+++ b/src/shared/types.ts
@@ -1131,9 +1131,10 @@ export interface RelayPeerPending {
export interface RelayHostApi {
/**
* Enter host mode over the relay: connect and return a pairing offer string to hand to a client.
- * Rejects if the device is not entitled (or a dev build without the relay URL).
+ * Rejects if the device is not entitled (or a dev build without the relay URL). `projectId` is the
+ * single project this hosting session shares with the peer; omit for the legacy whole-workspace view.
*/
- start(): Promise<{ offer: string }>
+ start(projectId?: string): Promise<{ offer: string }>
/** Leave host mode: close the relay connection (drops every bridged peer). */
stop(): Promise<void>
/**