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(phone): quick-pair popover on a top-right phone button
enesb97ca3b4a6cc
diff --git a/src/renderer/canvas/Canvas.tsx b/src/renderer/canvas/Canvas.tsxindex fbf41c51a..d001dbc59 100644--- a/src/renderer/canvas/Canvas.tsx+++ b/src/renderer/canvas/Canvas.tsx@@ -51,6 +51,7 @@ import {IconLock,IconMarkdown,IconNote,+ IconPhone,IconProject,IconRemote,IconSave,@@ -73,6 +74,7 @@ import { describeOs, REPO_URL } from '../lib/bugReport'import { UpdateCard } from '../components/UpdateCard'import { AnnouncementBanner } from '../components/AnnouncementBanner'import { TmuxBanner } from '../components/TmuxBanner'+import { PhonePairPopover } from '../components/PhonePairPopover'import { ConflictBar } from '../components/ConflictBar'import { ConfirmDialog } from '../components/ConfirmDialog'import { ConsentNotice } from '../remote/ConsentNotice'@@ -436,6 +438,8 @@ export function Canvas() {const [bufferCache, setBufferCache] = useState<Record<string, string>>({})const captureTsRef = useRef<Record<string, number>>({})const [settingsOpen, setSettingsOpen] = useState(false)+ // Quick phone-pair popover (top-right phone button); non-null = open, anchored to the button.+ const [phonePairAnchor, setPhonePairAnchor] = useState<{ right: number; bottom: number } | null>(null)// "+" opens the start screen (WelcomeScreen) on demand over existing projects.const [welcomeOpen, setWelcomeOpen] = useState(false)// Optional deep-link target when opening settings (e.g. RemotePicker → the SSH section).@@ -5546,6 +5550,15 @@ export function Canvas() {<button title="Source Control (⌘⇧G)" onClick={() => setScOpen(true)}><IconBranch /></button>+ <button+ title="Pair phone"+ onClick={(e) => {+ const r = e.currentTarget.getBoundingClientRect()+ setPhonePairAnchor((cur) => (cur ? null : { right: r.right, bottom: r.bottom }))+ }}+ >+ <IconPhone />+ </button><buttontitle="Settings (⌘,)"onClick={() => {@@ -5688,6 +5701,18 @@ export function Canvas() {/></div>+ {phonePairAnchor && (+ <PhonePairPopover+ anchor={phonePairAnchor}+ onClose={() => setPhonePairAnchor(null)}+ onOpenSettings={() => {+ setPhonePairAnchor(null)+ setSettingsSection('phone')+ setSettingsOpen(true)+ }}+ />+ )}+{remoteDialogOpen && <RemoteAccessDialog onClose={() => setRemoteDialogOpen(false)} />}{sshDialogOpen && (diff --git a/src/renderer/components/PhonePairPopover.tsx b/src/renderer/components/PhonePairPopover.tsxnew file mode 100644index 000000000..d07d4a9ac--- /dev/null+++ b/src/renderer/components/PhonePairPopover.tsx@@ -0,0 +1,138 @@+import { useEffect } from 'react'+import { createPortal } from 'react-dom'+import { Switch } from '@renderer/ui/Switch'+import { useSettings } from '@renderer/state/settings'+import { useEntitlement } from '@renderer/state/entitlement'+import { useUpgradeGate } from '@renderer/state/upgradeGate'+import { usePhonePairing } from './settings/usePhonePairing'++/** Same deep link the Phone settings section uses for the Remote Login toggle. */+const REMOTE_LOGIN_SETTINGS_URL =+ 'x-apple.systempreferences:com.apple.preferences.sharing?Services_RemoteLogin'+const isMac = /Mac/i.test(navigator.platform || navigator.userAgent)++/**+ * Quick phone pairing, anchored under the top-right phone button: opens straight into a live QR+ * (no "Start pairing" click — that's the whole point of the shortcut), with the standing+ * "Reach this Mac from anywhere" toggle below and a link into the full Phone settings.+ * Closing the popover stops an unfinished pairing (the shared hook's unmount rule).+ */+export function PhonePairPopover({+ anchor,+ onClose,+ onOpenSettings+}: {+ /** Viewport rect of the phone button — the popover right-aligns under it. */+ anchor: { right: number; bottom: number }+ onClose: () => void+ onOpenSettings: () => void+}): React.JSX.Element {+ const { phase, qr, sshOpen, sshHealed, error, busy, start } = usePhonePairing()++ const isPremium = useEntitlement((s) => s.isPremium)+ const phoneAccessEnabled = useSettings((s) => s.settings.phoneAccessEnabled)+ const updateSettings = useSettings((s) => s.update)++ const togglePhoneAccess = (next: boolean): void => {+ updateSettings({ phoneAccessEnabled: next })+ // Start/stop the standing relay host immediately (main also honors the Pro gate).+ window.nodeTerminal.remoteHost.setPhoneAccess(next)+ }++ // Straight into the QR on open (local-network pairing is free — no gate here).+ useEffect(() => {+ void start()+ // eslint-disable-next-line react-hooks/exhaustive-deps -- run exactly once, on open+ }, [])++ useEffect(() => {+ const onKey = (e: KeyboardEvent): void => {+ if (e.key === 'Escape') onClose()+ }+ window.addEventListener('keydown', onKey)+ return () => window.removeEventListener('keydown', onKey)+ }, [onClose])++ return createPortal(+ <>+ <div className="phone-pair__backdrop" onClick={onClose} />+ <div+ className="phone-pair"+ style={{ top: anchor.bottom + 8, right: Math.max(8, window.innerWidth - anchor.right) }}+ role="dialog"+ aria-label="Pair phone"+ >+ <div className="phone-pair__title">Pair your phone</div>++ {phase === 'waiting' && qr ? (+ <>+ <img src={qr} width={208} height={208} alt="Pairing QR code" className="phone-pair__qr" />+ <div className="phone-pair__hint">Scan with the nodeterm iOS app · waiting (2 min)</div>+ {!sshOpen ? (+ <div className="phone-pair__warn">+ SSH isn't reachable — turn on <strong>Remote Login</strong>+ {isMac ? (+ <>+ {' '}+ (+ <button+ className="phone-pair__link"+ onClick={() => window.nodeTerminal.shell.openExternal(REMOTE_LOGIN_SETTINGS_URL)}+ >+ System Settings+ </button>+ — watching, this clears itself).+ </>+ ) : (+ '.'+ )}+ </div>+ ) : sshHealed ? (+ <div className="phone-pair__ok">✓ Remote Login is on.</div>+ ) : null}+ </>+ ) : phase === 'paired' ? (+ <div className="phone-pair__ok">✓ Paired — your phone can now connect.</div>+ ) : phase === 'timeout' ? (+ <>+ <div className="phone-pair__hint">Pairing timed out.</div>+ <button className="phone-pair__btn" disabled={busy} onClick={() => void start()}>+ Show a new code+ </button>+ </>+ ) : (+ <div className="phone-pair__hint">{busy ? 'Starting…' : error || 'Starting…'}</div>+ )}+ {error && phase !== 'idle' ? <div className="phone-pair__warn">{error}</div> : null}++ <div className="phone-pair__divider" />++ <div className="phone-pair__row">+ <div className="phone-pair__row-text">+ <div className="phone-pair__row-title">+ Reach this Mac from anywhere+ {!isPremium && <span className="phone-pair__pro">PRO</span>}+ </div>+ <div className="phone-pair__row-sub">E2E encrypted over the relay — not just your LAN.</div>+ </div>+ <Switch+ checked={isPremium && phoneAccessEnabled}+ onChange={(next) => {+ if (!isPremium) {+ useUpgradeGate.getState().show('Remote access from your phone')+ return+ }+ togglePhoneAccess(next)+ }}+ ariaLabel="Reach this Mac from anywhere"+ />+ </div>++ <button className="phone-pair__link phone-pair__footer" onClick={onOpenSettings}>+ All phone settings…+ </button>+ </div>+ </>,+ document.body+ )+}diff --git a/src/renderer/components/icons.tsx b/src/renderer/components/icons.tsxindex 4b88cc94b..90cba2037 100644--- a/src/renderer/components/icons.tsx+++ b/src/renderer/components/icons.tsx@@ -231,3 +231,12 @@ export const IconBellFilled = () => (<path d="M9.7 18.7a2.4 2.4 0 0 0 4.6 0z" /></svg>)++/* Smartphone outline — the quick phone-pairing button in the top-right cluster. */+export const IconPhone = () => (+ <svg {...S}>+ <rect x="7" y="2.5" width="10" height="19" rx="2.5" />+ <path d="M10.5 5h3" />+ <circle cx="12" cy="18" r="0.9" fill="currentColor" stroke="none" />+ </svg>+)diff --git a/src/renderer/components/settings/sections/PhoneSection.tsx b/src/renderer/components/settings/sections/PhoneSection.tsxindex ad5ae83cf..ac32572bf 100644--- a/src/renderer/components/settings/sections/PhoneSection.tsx+++ b/src/renderer/components/settings/sections/PhoneSection.tsx@@ -1,5 +1,4 @@-import { useCallback, useEffect, useRef, useState } from 'react'-import { toDataURL } from 'qrcode'+import { useCallback, useEffect, useState } from 'react'import type { PairedDevice } from '@shared/types'import { SettingsSection } from '../SettingsSection'import { SearchableRow } from '../SearchableRow'@@ -8,6 +7,7 @@ import { Button } from '@renderer/ui/Button'import { Switch } from '@renderer/ui/Switch'import { useSettings } from '@renderer/state/settings'import { useEntitlement } from '@renderer/state/entitlement'+import { usePhonePairing } from '../usePhonePairing'const ROWS = {remote: {@@ -35,11 +35,6 @@ function formatPairedAt(ms: number): string {})}-type Phase = 'idle' | 'waiting' | 'paired' | 'timeout'--/** How often the Remote Login warning re-probes sshd while it is showing. */-const SSH_RECHECK_MS = 2000-/** Deep link straight to System Settings → General → Sharing (the Remote Login toggle lives* there). The `Services_RemoteLogin` query selected the service in the pre-Ventura prefpane and* is harmless on newer macOS, which opens the Sharing pane either way. macOS-only. */@@ -50,18 +45,8 @@ const REMOTE_LOGIN_SETTINGS_URL =const isMac = /Mac/i.test(navigator.platform || navigator.userAgent)export function PhoneSection({ isActive }: { isActive: boolean }): React.JSX.Element {- const [phase, setPhase] = useState<Phase>('idle')- const [qr, setQr] = useState('')- const [sshOpen, setSshOpen] = useState(true)- // Went from unreachable → reachable while the warning was showing: show a green confirmation- // instead of silently dropping the warning (the user just flipped a toggle; acknowledge it).- const [sshHealed, setSshHealed] = useState(false)- const [error, setError] = useState('')- const [busy, setBusy] = useState(false)const [devices, setDevices] = useState<PairedDevice[]>([])const [pendingRevoke, setPendingRevoke] = useState<PairedDevice | null>(null)- // Track whether a pairing listener is currently running so unmount can stop it.- const runningRef = useRef(false)const isPremium = useEntitlement((s) => s.isPremium)const phoneAccessEnabled = useSettings((s) => s.settings.phoneAccessEnabled)@@ -81,69 +66,11 @@ export function PhoneSection({ isActive }: { isActive: boolean }): React.JSX.Ele}}, [])- // Live re-check while the Remote Login warning is visible: the initial probe runs once at- // pairing start, so without this the warning could never clear — the user enables Remote Login- // in System Settings and nothing changes on screen. Poll only in that exact state (waiting +- // unreachable); the interval dies with the warning.- useEffect(() => {- if (phase !== 'waiting' || sshOpen) return- let cancelled = false- const timer = setInterval(() => {- void window.nodeTerminal.pairing- .probeSsh()- .then((open) => {- if (!cancelled && open) {- setSshOpen(true)- setSshHealed(true)- }- })- .catch(() => {- // transient probe error: keep the warning, try again on the next tick- })- }, SSH_RECHECK_MS)- return () => {- cancelled = true- clearInterval(timer)- }- }, [phase, sshOpen])-- const startPairing = async (): Promise<void> => {- setError('')- setBusy(true)- try {- const { payload, sshOpen: open } = await window.nodeTerminal.pairing.start()- const dataUrl = await toDataURL(payload, { margin: 1, width: 240 })- setQr(dataUrl)- setSshOpen(open)- setSshHealed(false)- setPhase('waiting')- runningRef.current = true- } catch (err) {- setError((err as Error).message)- } finally {- setBusy(false)- }- }-- const stopPairing = (): void => {- if (runningRef.current) {- runningRef.current = false- void window.nodeTerminal.pairing.stop()- }- setPhase('idle')- setQr('')- }-- // Subscribe to the completion event; drives paired/timeout state.- useEffect(() => {- const off = window.nodeTerminal.pairing.onDone((result) => {- runningRef.current = false- setQr('')- setPhase(result.ok ? 'paired' : 'timeout')- if (result.ok) void refreshDevices()- })- return off- }, [refreshDevices])+ // The shared pairing machine (also behind the top-right quick-pair popover); a completed+ // pairing refreshes the device list below.+ const { phase, qr, sshOpen, sshHealed, error, busy, start, stop, reset } = usePhonePairing(+ () => void refreshDevices()+ )// Load the paired-device list on mount.useEffect(() => {@@ -159,16 +86,6 @@ export function PhoneSection({ isActive }: { isActive: boolean }): React.JSX.Ele}}- // Stop any in-flight pairing when the section unmounts (settings closed / navigated away).- useEffect(() => {- return () => {- if (runningRef.current) {- runningRef.current = false- void window.nodeTerminal.pairing.stop()- }- }- }, [])-return (<SettingsSectionid="phone"@@ -220,7 +137,7 @@ export function PhoneSection({ isActive }: { isActive: boolean }): React.JSX.ElePairing timed out. Start again and scan the new code within two minutes.</p>) : null}- <Button variant="primary" disabled={busy} onClick={() => void startPairing()}>+ <Button variant="primary" disabled={busy} onClick={() => void start()}>{busy ? 'Starting…' : 'Start pairing'}</Button></div>@@ -254,7 +171,7 @@ export function PhoneSection({ isActive }: { isActive: boolean }): React.JSX.Ele✓ Remote Login is on — your phone can connect after pairing.</p>) : null}- <Button onClick={stopPairing}>Cancel</Button>+ <Button onClick={stop}>Cancel</Button></div>) : null}@@ -263,7 +180,7 @@ export function PhoneSection({ isActive }: { isActive: boolean }): React.JSX.Ele<p className="text-sm font-medium" style={{ color: '#30d158' }}>✓ Paired. Your phone can now connect with its own key.</p>- <Button onClick={() => setPhase('idle')}>Pair another phone</Button>+ <Button onClick={reset}>Pair another phone</Button></div>) : null}diff --git a/src/renderer/components/settings/usePhonePairing.ts b/src/renderer/components/settings/usePhonePairing.tsnew file mode 100644index 000000000..4b6f21e69--- /dev/null+++ b/src/renderer/components/settings/usePhonePairing.ts@@ -0,0 +1,115 @@+import { useEffect, useRef, useState } from 'react'+import { toDataURL } from 'qrcode'++export type PairingPhase = 'idle' | 'waiting' | 'paired' | 'timeout'++/** How often the Remote Login warning re-probes sshd while it is showing. */+const SSH_RECHECK_MS = 2000++/**+ * The phone-pairing state machine, shared by Settings → Phone and the quick-pair popover:+ * start/stop, the QR data URL, the completion event, and the live Remote-Login (sshd) re-probe+ * while the warning is visible. Any in-flight pairing is stopped when the OWNING view unmounts —+ * both hosts are transient surfaces, and a headless listener would silently pair whoever scans a+ * QR that is no longer on screen.+ */+export function usePhonePairing(onPaired?: () => void): {+ phase: PairingPhase+ qr: string+ sshOpen: boolean+ sshHealed: boolean+ error: string+ busy: boolean+ start: () => Promise<void>+ stop: () => void+ reset: () => void+} {+ const [phase, setPhase] = useState<PairingPhase>('idle')+ const [qr, setQr] = useState('')+ const [sshOpen, setSshOpen] = useState(true)+ // Went from unreachable → reachable while the warning was showing: show a green confirmation+ // instead of silently dropping the warning (the user just flipped a toggle; acknowledge it).+ const [sshHealed, setSshHealed] = useState(false)+ const [error, setError] = useState('')+ const [busy, setBusy] = useState(false)+ // Track whether a pairing listener is currently running so unmount can stop it.+ const runningRef = useRef(false)++ // Live re-check while the Remote Login warning is visible: the initial probe runs once at+ // pairing start, so without this the warning could never clear — the user enables Remote Login+ // in System Settings and nothing changes on screen. Poll only in that exact state (waiting ++ // unreachable); the interval dies with the warning.+ useEffect(() => {+ if (phase !== 'waiting' || sshOpen) return+ let cancelled = false+ const timer = setInterval(() => {+ void window.nodeTerminal.pairing+ .probeSsh()+ .then((open) => {+ if (!cancelled && open) {+ setSshOpen(true)+ setSshHealed(true)+ }+ })+ .catch(() => {+ // transient probe error: keep the warning, try again on the next tick+ })+ }, SSH_RECHECK_MS)+ return () => {+ cancelled = true+ clearInterval(timer)+ }+ }, [phase, sshOpen])++ const start = async (): Promise<void> => {+ setError('')+ setBusy(true)+ try {+ const { payload, sshOpen: open } = await window.nodeTerminal.pairing.start()+ const dataUrl = await toDataURL(payload, { margin: 1, width: 240 })+ setQr(dataUrl)+ setSshOpen(open)+ setSshHealed(false)+ setPhase('waiting')+ runningRef.current = true+ } catch (err) {+ setError((err as Error).message)+ } finally {+ setBusy(false)+ }+ }++ const stop = (): void => {+ if (runningRef.current) {+ runningRef.current = false+ void window.nodeTerminal.pairing.stop()+ }+ setPhase('idle')+ setQr('')+ }++ // Subscribe to the completion event; drives paired/timeout state. `onPaired` rides a ref so+ // a re-rendered callback never resubscribes the event.+ const onPairedRef = useRef(onPaired)+ onPairedRef.current = onPaired+ useEffect(() => {+ return window.nodeTerminal.pairing.onDone((result) => {+ runningRef.current = false+ setQr('')+ setPhase(result.ok ? 'paired' : 'timeout')+ if (result.ok) onPairedRef.current?.()+ })+ }, [])++ // Stop any in-flight pairing when the owning view unmounts (closed / navigated away).+ useEffect(() => {+ return () => {+ if (runningRef.current) {+ runningRef.current = false+ void window.nodeTerminal.pairing.stop()+ }+ }+ }, [])++ return { phase, qr, sshOpen, sshHealed, error, busy, start, stop, reset: () => setPhase('idle') }+}diff --git a/src/renderer/styles.css b/src/renderer/styles.cssindex aff90da1b..99eeae340 100644--- a/src/renderer/styles.css+++ b/src/renderer/styles.css@@ -5728,3 +5728,102 @@ body,line-height: 1.5;color: var(--muted);}++/* ---- quick phone-pair popover (top-right phone button) ---- */+.phone-pair__backdrop {+ position: fixed;+ inset: 0;+ z-index: 90;+}+.phone-pair {+ position: fixed;+ z-index: 91;+ width: 264px;+ padding: 14px 16px;+ border-radius: 12px;+ background: rgba(20, 20, 22, 0.98);+ border: 1px solid rgba(255, 255, 255, 0.1);+ box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);+ color: var(--label, #fff);+ display: flex;+ flex-direction: column;+ align-items: center;+ gap: 10px;+}+.phone-pair__title {+ align-self: flex-start;+ font-size: 13px;+ font-weight: 600;+}+.phone-pair__qr {+ border-radius: 10px;+ background: #fff;+ padding: 8px;+}+.phone-pair__hint {+ font-size: 12px;+ color: var(--muted, rgba(255, 255, 255, 0.55));+ text-align: center;+}+.phone-pair__warn {+ font-size: 12px;+ color: #ff9f0a;+ text-align: center;+}+.phone-pair__ok {+ font-size: 12px;+ color: #30d158;+ text-align: center;+}+.phone-pair__btn {+ font-size: 12px;+ padding: 5px 12px;+ border-radius: 7px;+ border: 1px solid rgba(255, 255, 255, 0.14);+ background: rgba(255, 255, 255, 0.08);+ color: var(--label, #fff);+ cursor: pointer;+}+.phone-pair__btn:hover { background: rgba(255, 255, 255, 0.14); }+.phone-pair__divider {+ align-self: stretch;+ height: 1px;+ background: rgba(255, 255, 255, 0.08);+}+.phone-pair__row {+ align-self: stretch;+ display: flex;+ align-items: center;+ justify-content: space-between;+ gap: 10px;+}+.phone-pair__row-title {+ font-size: 12.5px;+ font-weight: 500;+ display: flex;+ align-items: center;+ gap: 6px;+}+.phone-pair__pro {+ font-size: 9px;+ font-weight: 700;+ letter-spacing: 0.5px;+ padding: 1px 5px;+ border-radius: 999px;+ color: var(--accent, #0a84ff);+ border: 1px solid var(--accent, #0a84ff);+}+.phone-pair__row-sub {+ font-size: 11px;+ color: var(--muted, rgba(255, 255, 255, 0.55));+ margin-top: 2px;+}+.phone-pair__link {+ background: none;+ border: none;+ padding: 0;+ font-size: 12px;+ color: var(--accent, #0a84ff);+ cursor: pointer;+}+.phone-pair__footer { align-self: flex-start; }