Access the Floating Workspace from mobile (#8405) (#9523)

* Access the Floating Workspace from mobile (#8405)

Surface the desktop Floating Workspace (the global, repo-less scratchpad
of terminal tabs under the synthetic `global-floating-terminal` id) on the
mobile app so a Claude session left running there is reachable from a phone.

Adds a terminal-icon button to the mobile host header (phone + tablet
sidebar) that opens the existing Session screen for the floating id. The
sentinel already had host-side RPC support (#5946: local runtime, homedir
cwd, explicit-id fast paths in session.tabs.*); this wires up the mobile
surface and gates it on a new `floatingWorkspaceEnabled` status flag so the
entry hides on hosts that predate it or where the feature is disabled.

The Session screen learns an `isFloatingWorkspaceRoute` flag (mirroring the
existing `folder:` route pattern) that hides repo-backed surfaces — Files,
Source Control, PR/checks, agent history — skips the diff-comment and GitHub
probes, routes terminal URL taps to the phone browser, and limits the New
Tab drawer to terminals + agents (browser/markdown creation resolves a real
worktree host-side and stays desktop-only). useLiveWorktreeName
short-circuits for the sentinel so it no longer polls worktree.show forever.

Extracted the host status.get gating into a useHostStatusGates hook to keep
the host screen under the max-lines ratchet.

* Harden mobile Floating Workspace routing

* Fix mobile host gate reuse race

* Harden floating mobile session polling

* fix(mobile): harden floating workspace route reuse

* fix(mobile): skip floating workspace repo lookup

* fix(mobile): clarify floating workspace header action
This commit is contained in:
Brennan Benson
2026-07-20 21:05:40 -07:00
committed by GitHub
parent 6c9be228ad
commit e3c8d96638
21 changed files with 1037 additions and 168 deletions
+104 -6
View File
@@ -902,6 +902,7 @@ type RuntimeStore = {
agentDefaultArgs?: GlobalSettings['agentDefaultArgs']
agentDefaultEnv?: GlobalSettings['agentDefaultEnv']
terminalWindowsShell?: GlobalSettings['terminalWindowsShell']
floatingTerminalEnabled?: GlobalSettings['floatingTerminalEnabled']
agentStatusHooksEnabled?: GlobalSettings['agentStatusHooksEnabled']
defaultTaskSource?: GlobalSettings['defaultTaskSource']
defaultTaskViewPreset?: GlobalSettings['defaultTaskViewPreset']
@@ -1293,6 +1294,8 @@ type RuntimePtyController = {
hasChildProcesses?(ptyId: string): Promise<boolean>
clearBuffer?(ptyId: string): Promise<void>
resize?(ptyId: string, cols: number, rows: number): boolean
// Why: exact-id mobile polls should not enumerate every local and SSH PTY.
hasPty?(ptyId: string): boolean | null
listProcesses?(): Promise<PtyProcessInfo[]>
serializeBuffer?(
ptyId: string,
@@ -3213,6 +3216,7 @@ export class OrcaRuntimeService {
capabilities,
hostPlatform: process.platform,
terminalWindowsShell: this.store?.getSettings?.().terminalWindowsShell ?? null,
floatingWorkspaceEnabled: this.store?.getSettings?.().floatingTerminalEnabled !== false,
protocolVersion: RUNTIME_PROTOCOL_VERSION,
minCompatibleMobileVersion: MIN_COMPATIBLE_RUNTIME_CLIENT_VERSION
}
@@ -3558,7 +3562,7 @@ export class OrcaRuntimeService {
const explicitWorktreeId = this.getValidatedExplicitWorktreeIdSelector(worktreeSelector)
if (explicitWorktreeId) {
this.hydrateHeadlessMobileSessionTabsFromWorkspaceSession(explicitWorktreeId)
await this.refreshMobileSessionPtyRecords()
await this.refreshMobileSessionPtyRecords(explicitWorktreeId)
return this.getMobileSessionTabsForWorktree(explicitWorktreeId)
}
const worktree = await this.resolveWorktreeSelector(worktreeSelector)
@@ -4599,12 +4603,19 @@ export class OrcaRuntimeService {
}
}
private async refreshMobileSessionPtyRecords(): Promise<void> {
if (!this.ptyController?.listProcesses) {
private async refreshMobileSessionPtyRecords(
targetWorktreeId: string | null = null
): Promise<void> {
if (!this.ptyController?.listProcesses && !this.ptyController?.hasPty) {
return
}
const resolvedWorktrees = await this.listResolvedWorktrees()
await this.refreshPtyWorktreeRecordsFromController(resolvedWorktrees)
// Why: floating PTY identity is explicit, so polling must not resolve every Git/SSH worktree.
const isFloatingWorkspace = targetWorktreeId === FLOATING_TERMINAL_WORKTREE_ID
const resolvedWorktrees = isFloatingWorkspace ? [] : await this.listResolvedWorktrees()
await this.refreshPtyWorktreeRecordsFromController(
resolvedWorktrees,
isFloatingWorkspace ? targetWorktreeId : null
)
}
async activateMobileSessionTab(
@@ -4617,7 +4628,7 @@ export class OrcaRuntimeService {
const worktreeId =
explicitWorktreeId ?? (await this.resolveWorktreeSelector(worktreeSelector)).id
this.hydrateHeadlessMobileSessionTabsFromWorkspaceSession(worktreeId)
await this.refreshMobileSessionPtyRecords()
await this.refreshMobileSessionPtyRecords(worktreeId)
const snapshot = this.mobileSessionTabsByWorktree.get(worktreeId)
const directTab = snapshot?.tabs.find((candidate) => candidate.id === tabId)
const tab = leafId
@@ -21983,6 +21994,12 @@ export class OrcaRuntimeService {
resolvedWorktrees: ResolvedWorktree[],
targetWorktreeId: string | null = null
): Promise<Set<string> | null> {
if (targetWorktreeId === FLOATING_TERMINAL_WORKTREE_ID) {
const targetedLiveness = this.refreshFloatingWorkspacePtyLiveness()
if (targetedLiveness !== null) {
return targetedLiveness
}
}
if (!this.ptyController?.listProcesses) {
return null
}
@@ -22027,6 +22044,87 @@ export class OrcaRuntimeService {
return livePtyIds
}
private refreshFloatingWorkspacePtyLiveness(): Set<string> | null {
const controller = this.ptyController
if (!controller?.hasPty) {
return null
}
const knownPtyIds = new Set<string>()
const persistedBindingByPtyId = new Map<string, { tabId: string; paneKey: string }>()
for (const pty of this.ptysById.values()) {
if (pty.worktreeId === FLOATING_TERMINAL_WORKTREE_ID) {
knownPtyIds.add(pty.ptyId)
}
}
for (const leaf of this.leaves.values()) {
if (leaf.worktreeId === FLOATING_TERMINAL_WORKTREE_ID && leaf.ptyId) {
knownPtyIds.add(leaf.ptyId)
}
}
const snapshot = this.mobileSessionTabsByWorktree.get(FLOATING_TERMINAL_WORKTREE_ID)
for (const tab of snapshot?.tabs ?? []) {
if (tab.type !== 'terminal') {
continue
}
if (tab.ptyId) {
knownPtyIds.add(tab.ptyId)
persistedBindingByPtyId.set(tab.ptyId, {
tabId: tab.parentTabId,
paneKey: this.getMobileTerminalPaneKey(tab)
})
}
for (const [leafId, ptyId] of Object.entries(tab.parentLayout?.ptyIdsByLeafId ?? {})) {
knownPtyIds.add(ptyId)
persistedBindingByPtyId.set(ptyId, {
tabId: tab.parentTabId,
paneKey: isTerminalLeafId(leafId)
? makePaneKey(tab.parentTabId, leafId)
: `${tab.parentTabId}:${/^pane:(\d+)$/.exec(leafId)?.[1] ?? leafId}`
})
}
}
const liveness = new Map<string, boolean>()
try {
for (const ptyId of knownPtyIds) {
const live = controller.hasPty(ptyId)
if (live === null) {
return null
}
liveness.set(ptyId, live)
}
} catch {
return null
}
const livePtyIds = new Set<string>()
for (const [ptyId, live] of liveness) {
let pty = this.ptysById.get(ptyId)
if (live) {
livePtyIds.add(ptyId)
const binding = persistedBindingByPtyId.get(ptyId)
if (!pty && binding) {
// Why: a live daemon PTY restored from disk needs its pane identity before mobile can issue a safe handle.
pty = this.recordPtyWorktree(ptyId, FLOATING_TERMINAL_WORKTREE_ID, {
connected: true,
tabId: binding.tabId,
paneKey: binding.paneKey
})
}
if (pty) {
pty.connected = true
pty.disconnectedAt = null
this.refreshPtyForegroundAgent(ptyId)
}
} else if (pty && !this.leafExistsForPty(ptyId)) {
pty.connected = false
pty.disconnectedAt ??= Date.now()
}
}
this.pruneDisconnectedPtyRecords()
return livePtyIds
}
private pruneDisconnectedPtyTranscript(pty: RuntimePtyWorktreeRecord): void {
if (pty.connected) {
return