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): host picks which project to share when hosting (project-scope Task 3)
enes45b4d7c9b2bc
diff --git a/src/renderer/components/RemoteAccessDialog.tsx b/src/renderer/components/RemoteAccessDialog.tsxindex 5f51aec25..cfe8bd276 100644--- a/src/renderer/components/RemoteAccessDialog.tsx+++ b/src/renderer/components/RemoteAccessDialog.tsx@@ -2,9 +2,12 @@ import { useEffect, useState } from 'react'import { createPortal } from 'react-dom'import { useDialogStack } from './dialog-stack'import { useEntitlement } from '../state/entitlement'+import { useProjects } from '../state/projects'+import { hostShareOptions } from '../lib/relayHostShare'import { Button } from '@renderer/ui/Button'import { CopyButton } from '@renderer/ui/CopyButton'import { Input } from '@renderer/ui/Input'+import { Select } from '@renderer/ui/Select'/*** Remote access dialog — a self-contained popup reachable from the project (tab) caret menu, so@@ -18,11 +21,22 @@ import { Input } from '@renderer/ui/Input'export function RemoteAccessDialog({ onClose }: { onClose: () => void }): React.JSX.Element {const isPremium = useEntitlement((s) => s.isPremium)const upgrade = useEntitlement((s) => s.upgrade)+ const projects = useProjects((s) => s.projects)+ const activeProjectId = useProjects((s) => s.activeProjectId)const [hostOffer, setHostOffer] = useState('')const [hostBusy, setHostBusy] = useState(false)const [error, setError] = useState('')const [clientCode, setClientCode] = useState('')+ // Which project this host shares with the joiner. Default = the active project (hoisted first+ // by hostShareOptions); the user can pick any other OPEN project before minting the offer.+ const shareOptions = hostShareOptions(projects, activeProjectId)+ const [shareId, setShareId] = useState('')+ const effectiveShareId = shareOptions.some((o) => o.id === shareId)+ ? shareId+ : (shareOptions[0]?.id ?? '')+ const sharedName = shareOptions.find((o) => o.id === effectiveShareId)?.name ?? ''+// Only the topmost modal answers a key (./dialog-stack) — the host approval ConfirmDialog opens// on top of THIS dialog, and its Escape must not also close the one underneath.const isTop = useDialogStack()@@ -45,7 +59,7 @@ export function RemoteAccessDialog({ onClose }: { onClose: () => void }): React.setError('')setHostBusy(true)try {- const { offer } = await window.nodeTerminal.relayHost.start()+ const { offer } = await window.nodeTerminal.relayHost.start(effectiveShareId || undefined)setHostOffer(offer)} catch (err) {setError((err as Error).message)@@ -88,7 +102,10 @@ export function RemoteAccessDialog({ onClose }: { onClose: () => void }): React.{isPremium ? (hostOffer ? (<div className="remote-dialog__block">- <p className="remote-dialog__hint">Share this pairing code (single use):</p>+ <p className="remote-dialog__hint">+ Sharing <strong>{sharedName || 'this project'}</strong> — the joiner will see this+ project and can run commands on this Mac. Share this pairing code (single use):+ </p><InputclassName="w-full"readOnly@@ -101,9 +118,32 @@ export function RemoteAccessDialog({ onClose }: { onClose: () => void }): React.</div></div>) : (- <Button disabled={hostBusy} onClick={() => void startHosting()}>- {hostBusy ? 'Starting…' : 'Allow remote access'}- </Button>+ <div className="remote-dialog__block">+ {shareOptions.length > 1 ? (+ <label className="remote-dialog__hint">+ Project to share+ <Select+ className="w-full mt-1"+ value={effectiveShareId}+ onChange={(e) => setShareId(e.target.value)}+ >+ {shareOptions.map((o) => (+ <option key={o.id} value={o.id}>+ {o.name}+ </option>+ ))}+ </Select>+ </label>+ ) : (+ <p className="remote-dialog__hint">+ Sharing <strong>{sharedName || 'this project'}</strong> — the joiner sees this+ project and can run commands on this Mac.+ </p>+ )}+ <Button disabled={hostBusy} onClick={() => void startHosting()}>+ {hostBusy ? 'Starting…' : 'Allow remote access'}+ </Button>+ </div>)) : (<div className="remote-dialog__block">diff --git a/src/renderer/components/settings/sections/RemoteSection.tsx b/src/renderer/components/settings/sections/RemoteSection.tsxindex 0e876a52d..3831238b7 100644--- a/src/renderer/components/settings/sections/RemoteSection.tsx+++ b/src/renderer/components/settings/sections/RemoteSection.tsx@@ -1,11 +1,14 @@import { useState } from 'react'import { useEntitlement } from '../../../state/entitlement'+import { useProjects } from '../../../state/projects'+import { hostShareOptions } from '../../../lib/relayHostShare'import { SettingsSection } from '../SettingsSection'import { SearchableRow } from '../SearchableRow'import { FieldRow } from '../FieldRow'import { Button } from '@renderer/ui/Button'import { CopyButton } from '@renderer/ui/CopyButton'import { Input } from '@renderer/ui/Input'+import { Select } from '@renderer/ui/Select'const ROWS = {allow: { title: 'Allow remote access', keywords: ['remote', 'host', 'share', 'pairing', 'ssh'] },@@ -24,11 +27,22 @@ export function RemoteSection({onClose: () => void}): React.JSX.Element {const isPremium = useEntitlement((s) => s.isPremium)+ const projects = useProjects((s) => s.projects)+ const activeProjectId = useProjects((s) => s.activeProjectId)const [hostOffer, setHostOffer] = useState('')const [hostBusy, setHostBusy] = useState(false)const [remoteError, setRemoteError] = useState('')const [clientCode, setClientCode] = useState('')const [connecting, setConnecting] = useState(false)++ // Which project this host shares with the joiner. Default = the active project (hoisted first+ // by hostShareOptions); the user can pick any other OPEN project before minting the offer.+ const shareOptions = hostShareOptions(projects, activeProjectId)+ const [shareId, setShareId] = useState('')+ const effectiveShareId = shareOptions.some((o) => o.id === shareId)+ ? shareId+ : (shareOptions[0]?.id ?? '')+ const sharedName = shareOptions.find((o) => o.id === effectiveShareId)?.name ?? ''// HOST side — the NEW relay tunnel (`relayHost`). `start()` returns the single-use pairing offer;// a connecting peer's approval + canvas sync are handled globally by Canvas (`relayHost.onPeerPending`// / `relayHost.confirm`, and the CorePlatform seq-stamped reflector — no old canvas-mirror flag).@@ -36,7 +50,7 @@ export function RemoteSection({setRemoteError('')setHostBusy(true)try {- const { offer } = await window.nodeTerminal.relayHost.start()+ const { offer } = await window.nodeTerminal.relayHost.start(effectiveShareId || undefined)setHostOffer(offer)} catch (err) {setRemoteError((err as Error).message)@@ -78,7 +92,9 @@ export function RemoteSection({hostOffer ? (<div className="space-y-2"><p className="text-sm text-muted">- Share this pairing code with the other device (single use):+ Sharing <strong className="text-text">{sharedName || 'this project'}</strong> —+ the joiner will see this project and can run commands on this Mac. Share this+ pairing code with the other device (single use):</p><FieldRowlabel="Pairing code"@@ -97,9 +113,34 @@ export function RemoteSection({</div></div>) : (- <Button disabled={hostBusy} onClick={() => void startHosting()}>- {hostBusy ? 'Starting…' : 'Allow remote access'}- </Button>+ <div className="space-y-2">+ {shareOptions.length > 1 ? (+ <FieldRow+ label="Project to share"+ control={+ <Select+ className="w-72"+ value={effectiveShareId}+ onChange={(e) => setShareId(e.target.value)}+ >+ {shareOptions.map((o) => (+ <option key={o.id} value={o.id}>+ {o.name}+ </option>+ ))}+ </Select>+ }+ />+ ) : (+ <p className="text-sm text-muted">+ Sharing <strong className="text-text">{sharedName || 'this project'}</strong> —+ the joiner sees this project and can run commands on this Mac.+ </p>+ )}+ <Button disabled={hostBusy} onClick={() => void startHosting()}>+ {hostBusy ? 'Starting…' : 'Allow remote access'}+ </Button>+ </div>)) : (<p className="text-sm text-muted">diff --git a/src/renderer/lib/relayHostShare.test.ts b/src/renderer/lib/relayHostShare.test.tsnew file mode 100644index 000000000..3458df4ae--- /dev/null+++ b/src/renderer/lib/relayHostShare.test.ts@@ -0,0 +1,42 @@+import { describe, it, expect } from 'vitest'+import type { Project } from '@shared/types'+import { hostShareOptions } from './relayHostShare'++const proj = (id: string, name: string, extra: Partial<Project> = {}): Project =>+ ({ id, name, nodes: [], ...extra }) as Project++describe('hostShareOptions', () => {+ it('lists open projects with the active one first', () => {+ const opts = hostShareOptions([proj('a', 'A'), proj('b', 'B'), proj('c', 'C')], 'b')+ expect(opts).toEqual([+ { id: 'b', name: 'B' },+ { id: 'a', name: 'A' },+ { id: 'c', name: 'C' }+ ])+ })++ it('excludes closed projects', () => {+ const opts = hostShareOptions(+ [proj('a', 'A'), proj('b', 'B', { closed: true }), proj('c', 'C')],+ 'a'+ )+ expect(opts.map((o) => o.id)).toEqual(['a', 'c'])+ })++ it('keeps active first even when it is not the first in the list', () => {+ const opts = hostShareOptions([proj('a', 'A'), proj('b', 'B'), proj('c', 'C')], 'c')+ expect(opts[0]).toEqual({ id: 'c', name: 'C' })+ })++ it('handles an empty project list', () => {+ expect(hostShareOptions([], 'a')).toEqual([])+ })++ it('does not hoist the active project when it is closed (not shareable)', () => {+ const opts = hostShareOptions(+ [proj('a', 'A'), proj('b', 'B', { closed: true })],+ 'b'+ )+ expect(opts).toEqual([{ id: 'a', name: 'A' }])+ })+})diff --git a/src/renderer/lib/relayHostShare.ts b/src/renderer/lib/relayHostShare.tsnew file mode 100644index 000000000..53e46bf80--- /dev/null+++ b/src/renderer/lib/relayHostShare.ts@@ -0,0 +1,20 @@+import type { Project } from '@shared/types'++/** One shareable project as shown in the host's project chooser. */+export interface HostShareOption {+ id: string+ name: string+}++/**+ * The list of projects a relay host may share, as `{id, name}[]`. Only OPEN (non-`closed`)+ * projects are shareable — a closed project isn't in the tab bar and has nothing to show a+ * joiner. The `activeProjectId` (when itself open) is hoisted to the front so it can be the+ * default selection. Pure; empty input yields an empty list.+ */+export function hostShareOptions(projects: Project[], activeProjectId: string): HostShareOption[] {+ const open = projects.filter((p) => !p.closed).map((p) => ({ id: p.id, name: p.name }))+ const activeIdx = open.findIndex((p) => p.id === activeProjectId)+ if (activeIdx <= 0) return open+ return [open[activeIdx], ...open.slice(0, activeIdx), ...open.slice(activeIdx + 1)]+}