mirror of
https://github.com/stablyai/orca.git
synced 2026-11-17 03:15:01 +00:00
Merge pull request #183 from nwparker/cloud/w2-wake-visibility
fix(cloud): wake visibility (W10 audit): slow hint at 10s, Connecting… until the pane re-attaches, type-through fixtures
This commit is contained in:
@@ -10,7 +10,7 @@ import { wakeElapsedSeconds } from '@/lib/orca-cloud/orca-cloud-workspace-state'
|
||||
import type { CloudWakeProgressEvent } from '../../../../shared/hosted-sandbox/cloud-workspace-api'
|
||||
|
||||
/** After this long the pill says it's slower than usual; after STUCK_S it offers recovery inline. */
|
||||
export const WAKE_SLOW_S = 20
|
||||
export const WAKE_SLOW_S = 10
|
||||
export const WAKE_STUCK_S = 60
|
||||
|
||||
// Prompt lines and output lines of varied length: reads as "a terminal is coming".
|
||||
@@ -56,7 +56,7 @@ function TerminalSkeleton({ still }: { still: boolean }): React.JSX.Element {
|
||||
/**
|
||||
* Covers the workspace while it wakes: a terminal-shaped skeleton (never a blank pane) with a
|
||||
* live "Waking… Ns" pill. The same overlay for every wake source (open, message, Wake, restart,
|
||||
* unarchive). Slow wakes say so at 20 s and offer recovery at 60 s; a failed wake becomes a
|
||||
* unarchive). Slow wakes say so at 10 s and offer recovery at 60 s; a failed wake becomes a
|
||||
* dismissible card. `leaving` fades it out over the live terminal without moving layout.
|
||||
*/
|
||||
export function CloudWakingOverlay({
|
||||
@@ -104,20 +104,26 @@ export function CloudWakingOverlay({
|
||||
}
|
||||
}, [failed, autoFocus])
|
||||
const name = workspaceName || t('orcaCloudWorkspace.thisWorkspaceTitle', 'This workspace')
|
||||
// Once the sandbox is up the pill says so; the clock still counts from the wake's start.
|
||||
const title =
|
||||
wake.source === 'restart'
|
||||
? t('orcaCloudWorkspace.overlay.restarting', 'Restarting…')
|
||||
: wake.source === 'unarchive'
|
||||
? t('orcaCloudWorkspace.overlay.unarchiving', 'Restoring from archive…')
|
||||
: t('orcaCloudWorkspace.overlay.waking', 'Waking…')
|
||||
wake.phase === 'connecting'
|
||||
? t('orcaCloudWorkspace.overlay.connecting', 'Connecting…')
|
||||
: wake.source === 'restart'
|
||||
? t('orcaCloudWorkspace.overlay.restarting', 'Restarting…')
|
||||
: wake.source === 'unarchive'
|
||||
? t('orcaCloudWorkspace.overlay.unarchiving', 'Restoring from archive…')
|
||||
: t('orcaCloudWorkspace.overlay.waking', 'Waking…')
|
||||
const hint = stuck
|
||||
? t('orcaCloudWorkspace.overlay.stuck', 'This is taking much longer than usual.')
|
||||
: slow
|
||||
? t('orcaCloudWorkspace.overlay.slow', 'Taking longer than usual…')
|
||||
? t(
|
||||
'orcaCloudWorkspace.overlay.slow',
|
||||
'Taking longer than usual. Your files and chats are safe.'
|
||||
)
|
||||
: wake.source === 'message'
|
||||
? t('orcaCloudWorkspace.overlay.messageQueued', 'Your message sends as soon as it’s up.')
|
||||
: null
|
||||
// Announced once each (the text changes only when crossing 20 s and 60 s).
|
||||
// Announced once each (the text changes only when crossing WAKE_SLOW_S and WAKE_STUCK_S).
|
||||
const slowAnnouncement = stuck ? hint : slow ? hint : ''
|
||||
const passThrough = typeThrough && !failed
|
||||
return (
|
||||
@@ -126,7 +132,8 @@ export function CloudWakingOverlay({
|
||||
tabIndex={-1}
|
||||
className={cn(
|
||||
passThrough
|
||||
? 'pointer-events-none absolute inset-x-0 top-3 flex justify-center outline-none'
|
||||
? // Top-right, clear of the prompt line and what is being typed into it.
|
||||
'pointer-events-none absolute inset-x-0 top-3 flex justify-end pr-3 outline-none'
|
||||
: 'absolute inset-0 bg-background outline-none',
|
||||
'motion-safe:animate-in motion-safe:fade-in-0 motion-safe:duration-150',
|
||||
'motion-safe:transition-opacity motion-safe:duration-200',
|
||||
@@ -153,7 +160,7 @@ export function CloudWakingOverlay({
|
||||
<div
|
||||
className={
|
||||
passThrough
|
||||
? 'pointer-events-auto flex flex-col items-center gap-1.5 px-4'
|
||||
? 'pointer-events-auto flex flex-col items-end gap-1.5'
|
||||
: 'absolute inset-0 flex items-center justify-center p-4'
|
||||
}
|
||||
>
|
||||
@@ -200,7 +207,8 @@ export function CloudWakingOverlay({
|
||||
) : (
|
||||
<div
|
||||
className={cn(
|
||||
'flex flex-col items-center text-card-foreground',
|
||||
'flex flex-col text-card-foreground',
|
||||
passThrough ? 'items-end' : 'items-center',
|
||||
hint && 'w-full max-w-xs gap-2 rounded-lg border border-border bg-card p-3 shadow-xs'
|
||||
)}
|
||||
>
|
||||
@@ -220,7 +228,16 @@ export function CloudWakingOverlay({
|
||||
{formatElapsedTime(seconds * 1000)}
|
||||
</span>
|
||||
</div>
|
||||
{hint ? <p className="text-center text-xs text-muted-foreground">{hint}</p> : null}
|
||||
{hint ? (
|
||||
<p
|
||||
className={cn(
|
||||
'text-xs text-muted-foreground',
|
||||
passThrough ? 'text-left' : 'text-center'
|
||||
)}
|
||||
>
|
||||
{hint}
|
||||
</p>
|
||||
) : null}
|
||||
{passThrough && pendingInput > 0 ? (
|
||||
<div
|
||||
className="flex items-center gap-1.5 rounded-md border border-dashed border-border bg-card/95 py-0.5 pr-0.5 pl-2 text-xs shadow-xs"
|
||||
@@ -229,10 +246,11 @@ export function CloudWakingOverlay({
|
||||
<span className="text-muted-foreground">
|
||||
{t(
|
||||
'orcaCloudWorkspace.overlay.pendingKeys',
|
||||
'{{count}} keys waiting · go to the terminal when it’s up',
|
||||
'{{count}} keys waiting · they go to the terminal when it’s up',
|
||||
{
|
||||
count: pendingInput,
|
||||
defaultValue_one: '{{count}} key waiting · goes to the terminal when it’s up'
|
||||
defaultValue_one:
|
||||
'{{count}} key waiting · it goes to the terminal when it’s up'
|
||||
}
|
||||
)}
|
||||
</span>
|
||||
|
||||
@@ -150,6 +150,52 @@ describe('Orca Cloud surfaces', () => {
|
||||
expect(queryByRole('button', { name: 'Try again' })).not.toBeNull()
|
||||
})
|
||||
|
||||
it('type-through: slow at 10 s with the reassurance, Connecting… once up, keys waiting in plural', () => {
|
||||
vi.useFakeTimers()
|
||||
vi.setSystemTime(T0)
|
||||
const wake = {
|
||||
workspaceId: 'ws',
|
||||
phase: 'waking' as const,
|
||||
source: 'open' as const,
|
||||
startedAt: T0 - 9_000,
|
||||
at: T0
|
||||
}
|
||||
const props = {
|
||||
workspaceName: 'w',
|
||||
autoFocus: false,
|
||||
typeThrough: true,
|
||||
onRetry: noop,
|
||||
onRestart: noop,
|
||||
onDismiss: noop
|
||||
}
|
||||
const { container, queryByRole, rerender } = render(
|
||||
<CloudWakingOverlay wake={wake} pendingInput={1} {...props} />
|
||||
)
|
||||
expect(container.textContent).not.toContain('Taking longer')
|
||||
expect(container.textContent).toContain('1 key waiting · it goes to the terminal when it’s up')
|
||||
rerender(
|
||||
<CloudWakingOverlay wake={{ ...wake, startedAt: T0 - 10_000 }} pendingInput={12} {...props} />
|
||||
)
|
||||
expect(container.textContent).toContain(
|
||||
'Taking longer than usual. Your files and chats are safe.'
|
||||
)
|
||||
expect(container.textContent).toContain(
|
||||
'12 keys waiting · they go to the terminal when it’s up'
|
||||
)
|
||||
// Still the pill (no skeleton cover), and recovery only once stuck.
|
||||
expect(container.querySelector('[data-cloud-waking-overlay]')?.className).toContain(
|
||||
'justify-end'
|
||||
)
|
||||
expect(queryByRole('button', { name: 'Try again' })).toBeNull()
|
||||
rerender(
|
||||
<CloudWakingOverlay
|
||||
wake={{ ...wake, phase: 'connecting', startedAt: T0 - 4_000 }}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
expect(container.textContent).toMatch(/Connecting…\s*4s/)
|
||||
})
|
||||
|
||||
it('a failed wake is a dismissible alert whose primary action is Try again', () => {
|
||||
const onRetry = vi.fn()
|
||||
const onDismiss = vi.fn()
|
||||
|
||||
@@ -25,6 +25,7 @@ import { CloudWorkspaceOfflineView } from './offline/CloudWorkspaceOfflineView'
|
||||
import { useCloudOfflineData } from './offline/use-cloud-offline-data'
|
||||
import { useCloudWorkspaceView } from './use-cloud-workspace-view'
|
||||
import { useWakeInput, useWakeInputNotices } from './use-wake-input'
|
||||
import { useWakeAttachHold } from './use-wake-attach-hold'
|
||||
import { clearWakeInput } from '@/components/terminal-pane/input/wake-input-buffer'
|
||||
import {
|
||||
runRestartCloudWorkspace,
|
||||
@@ -223,13 +224,17 @@ function CloudSurface({ workspaceId }: { workspaceId: string }): React.JSX.Eleme
|
||||
const t = useTranslate()
|
||||
const view = useCloudWorkspaceView(workspaceId)
|
||||
const name = useAppStore((state) => findWorktreeById(state, workspaceId)?.displayName ?? null)
|
||||
const now = useNow(1_000, view.wake !== undefined)
|
||||
// Ready means the server answers; the pill stays ("Connecting…") until the pane in front has
|
||||
// re-attached and can take keys.
|
||||
const attachHold = useWakeAttachHold(workspaceId, view.wake)
|
||||
const shownWake = attachHold ?? view.wake
|
||||
const now = useNow(1_000, shownWake !== undefined)
|
||||
// Typing is accepted while a wake is in flight, so the terminal stays visible and typeable.
|
||||
const wakeInput = useWakeInput(workspaceId)
|
||||
useWakeInputNotices(workspaceId)
|
||||
const overlay = useWakeOverlay(
|
||||
view.wake,
|
||||
Math.max(now, view.wake?.at ?? 0),
|
||||
shownWake,
|
||||
Math.max(now, shownWake?.at ?? 0),
|
||||
t('orcaCloudWorkspace.overlay.stalled', 'Orca Cloud stopped responding while waking.'),
|
||||
wakeInput.pending > 0
|
||||
)
|
||||
|
||||
@@ -0,0 +1,89 @@
|
||||
// Waking in type-through mode: the terminal stays visible and typeable under a small pill.
|
||||
// (A sibling of OrcaCloudWorkspace.fixture.tsx, which is at its size limit.)
|
||||
import React from 'react'
|
||||
import { defineFixture } from '../../component-fixtures/component-fixture'
|
||||
import type { CloudWakeProgressEvent } from '../../../../shared/hosted-sandbox/cloud-workspace-api'
|
||||
import { CloudWakingOverlay } from './CloudWakingOverlay'
|
||||
|
||||
const noop = (): void => {}
|
||||
|
||||
const wake = (over: Partial<CloudWakeProgressEvent> = {}): CloudWakeProgressEvent => ({
|
||||
workspaceId: 'ws',
|
||||
phase: 'waking',
|
||||
source: 'open',
|
||||
startedAt: Date.now() - 3_200,
|
||||
at: Date.now(),
|
||||
...over
|
||||
})
|
||||
|
||||
function Pane({ children }: { children: React.ReactNode }): React.JSX.Element {
|
||||
return (
|
||||
<div className="relative h-[340px] overflow-hidden rounded-md border border-border bg-background">
|
||||
{children}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
// Started `ms` before render (not module load), so the pill reads its exact elapsed time.
|
||||
const startedAgo = (
|
||||
ms: number,
|
||||
over: Partial<CloudWakeProgressEvent> = {}
|
||||
): CloudWakeProgressEvent => wake({ startedAt: Date.now() - ms, at: Date.now(), ...over })
|
||||
|
||||
// Type-through: the terminal stays visible and typeable under a small pill.
|
||||
function TypeThrough({
|
||||
value,
|
||||
pendingInput = 0
|
||||
}: {
|
||||
value: CloudWakeProgressEvent
|
||||
pendingInput?: number
|
||||
}): React.JSX.Element {
|
||||
return (
|
||||
<Pane>
|
||||
<div className="absolute inset-0 px-4 py-3 font-mono text-xs text-foreground">
|
||||
<div className="text-muted-foreground">Last login: Mon Nov 9 20:41 on ttys004</div>
|
||||
<div>
|
||||
<span className="text-muted-foreground">~/fix-auth-redirect $</span> git status
|
||||
</div>
|
||||
</div>
|
||||
<CloudWakingOverlay
|
||||
wake={value}
|
||||
workspaceName="fix-auth-redirect"
|
||||
autoFocus={false}
|
||||
typeThrough
|
||||
pendingInput={pendingInput}
|
||||
onClearPending={noop}
|
||||
onRetry={noop}
|
||||
onRestart={noop}
|
||||
onDismiss={noop}
|
||||
/>
|
||||
</Pane>
|
||||
)
|
||||
}
|
||||
|
||||
export const wakingTypeThrough = defineFixture({
|
||||
width: 640,
|
||||
render: () => <TypeThrough value={startedAgo(3_200)} />
|
||||
})
|
||||
|
||||
export const wakingTypeThroughPending = defineFixture({
|
||||
width: 640,
|
||||
render: () => <TypeThrough value={startedAgo(3_200)} pendingInput={12} />
|
||||
})
|
||||
|
||||
export const wakingTypeThroughSlow = defineFixture({
|
||||
width: 640,
|
||||
render: () => <TypeThrough value={startedAgo(12_000)} pendingInput={12} />
|
||||
})
|
||||
|
||||
// The sandbox is up and the pane in front is re-attaching: the clock still counts from the start.
|
||||
export const wakingConnecting = defineFixture({
|
||||
width: 640,
|
||||
render: () => <TypeThrough value={startedAgo(6_000, { phase: 'connecting' })} />
|
||||
})
|
||||
|
||||
// Woken on intent (hover) 3 s before the click: the pill opens already counting.
|
||||
export const wakingFromPredictive = defineFixture({
|
||||
width: 640,
|
||||
render: () => <TypeThrough value={startedAgo(3_000)} />
|
||||
})
|
||||
@@ -0,0 +1,108 @@
|
||||
// @vitest-environment happy-dom
|
||||
|
||||
import { act, cleanup, renderHook } from '@testing-library/react'
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import type { CloudWakeProgressEvent } from '../../../../shared/hosted-sandbox/cloud-workspace-api'
|
||||
import {
|
||||
isActiveWakePaneAttached,
|
||||
registerWakePane,
|
||||
resetWakePanesForTests
|
||||
} from '@/components/terminal-pane/input/wake-pane-attach'
|
||||
import {
|
||||
WAKE_ATTACH_HOLD_MAX_MS,
|
||||
WAKE_ATTACH_POLL_MS,
|
||||
useWakeAttachHold
|
||||
} from './use-wake-attach-hold'
|
||||
|
||||
const T0 = 1_800_000_000_000
|
||||
const waking: CloudWakeProgressEvent = {
|
||||
workspaceId: 'ws',
|
||||
phase: 'waking',
|
||||
source: 'open',
|
||||
startedAt: T0 - 5_000,
|
||||
at: T0
|
||||
}
|
||||
const start: { wake: CloudWakeProgressEvent | undefined } = { wake: waking }
|
||||
|
||||
beforeEach(() => {
|
||||
vi.useFakeTimers()
|
||||
vi.setSystemTime(T0)
|
||||
resetWakePanesForTests()
|
||||
})
|
||||
afterEach(() => {
|
||||
vi.useRealTimers()
|
||||
cleanup()
|
||||
})
|
||||
|
||||
describe('wake pane registry', () => {
|
||||
it('answers for the pane in front only, null when none is known, and keeps a remount’s entry', () => {
|
||||
expect(isActiveWakePaneAttached('ws')).toBeNull()
|
||||
let frontReady = false
|
||||
const offBack = registerWakePane('ws', 'back', { isReady: () => true, isActive: () => false })
|
||||
expect(isActiveWakePaneAttached('ws')).toBeNull()
|
||||
const offFront = registerWakePane('ws', 'front', {
|
||||
isReady: () => frontReady,
|
||||
isActive: () => true
|
||||
})
|
||||
expect(isActiveWakePaneAttached('ws')).toBe(false)
|
||||
frontReady = true
|
||||
expect(isActiveWakePaneAttached('ws')).toBe(true)
|
||||
// A remount registers again under the same leaf; the old session's removal leaves it alone.
|
||||
registerWakePane('ws', 'front', { isReady: () => false, isActive: () => true })
|
||||
offFront()
|
||||
expect(isActiveWakePaneAttached('ws')).toBe(false)
|
||||
offBack()
|
||||
})
|
||||
})
|
||||
|
||||
describe('useWakeAttachHold', () => {
|
||||
it('holds a ready wake as Connecting… until the pane in front re-attaches, keeping its start', () => {
|
||||
let attached: boolean | null = false
|
||||
const { result, rerender } = renderHook(
|
||||
({ wake }: { wake: CloudWakeProgressEvent | undefined }) =>
|
||||
useWakeAttachHold('ws', wake, () => attached),
|
||||
{ initialProps: start }
|
||||
)
|
||||
expect(result.current).toBeUndefined()
|
||||
rerender({ wake: { ...waking, phase: 'ready', at: T0 + 1_000 } })
|
||||
expect(result.current).toMatchObject({ phase: 'connecting', startedAt: waking.startedAt })
|
||||
// The store drops the settled wake; the hold stays.
|
||||
rerender({ wake: undefined })
|
||||
act(() => vi.advanceTimersByTime(WAKE_ATTACH_POLL_MS * 5))
|
||||
expect(result.current?.phase).toBe('connecting')
|
||||
attached = true
|
||||
act(() => vi.advanceTimersByTime(WAKE_ATTACH_POLL_MS))
|
||||
expect(result.current).toBeUndefined()
|
||||
})
|
||||
|
||||
it('does not hold when the pane is already attached or none is known, nor after a failure', () => {
|
||||
let attached: boolean | null = true
|
||||
const { result, rerender } = renderHook(
|
||||
({ wake }: { wake: CloudWakeProgressEvent | undefined }) =>
|
||||
useWakeAttachHold('ws', wake, () => attached),
|
||||
{ initialProps: start }
|
||||
)
|
||||
rerender({ wake: { ...waking, phase: 'ready' } })
|
||||
expect(result.current).toBeUndefined()
|
||||
attached = null
|
||||
rerender({ wake: { ...waking, startedAt: T0 } })
|
||||
rerender({ wake: { ...waking, startedAt: T0, phase: 'ready' } })
|
||||
expect(result.current).toBeUndefined()
|
||||
attached = false
|
||||
rerender({ wake: { ...waking, startedAt: T0 + 1 } })
|
||||
rerender({ wake: { ...waking, startedAt: T0 + 1, phase: 'failed' } })
|
||||
expect(result.current).toBeUndefined()
|
||||
})
|
||||
|
||||
it('gives up on a pane that never re-attaches', () => {
|
||||
const { result, rerender } = renderHook(
|
||||
({ wake }: { wake: CloudWakeProgressEvent | undefined }) =>
|
||||
useWakeAttachHold('ws', wake, () => false),
|
||||
{ initialProps: start }
|
||||
)
|
||||
rerender({ wake: { ...waking, phase: 'ready' } })
|
||||
expect(result.current?.phase).toBe('connecting')
|
||||
act(() => vi.advanceTimersByTime(WAKE_ATTACH_HOLD_MAX_MS + WAKE_ATTACH_POLL_MS))
|
||||
expect(result.current).toBeUndefined()
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,71 @@
|
||||
import { useEffect, useState } from 'react'
|
||||
import { isActiveWakePaneAttached } from '@/components/terminal-pane/input/wake-pane-attach'
|
||||
import { installWindowVisibilityInterval } from '@/lib/window-visibility-interval'
|
||||
import type { CloudWakeProgressEvent } from '../../../../shared/hosted-sandbox/cloud-workspace-api'
|
||||
|
||||
/** How often the hold checks the pane in front while it waits. */
|
||||
export const WAKE_ATTACH_POLL_MS = 100
|
||||
/** A pane that never re-attaches (closed, broken) stops holding the pill after this. */
|
||||
export const WAKE_ATTACH_HOLD_MAX_MS = 8_000
|
||||
|
||||
type Track = {
|
||||
/** The last in-flight report of the current wake: what the pill showed before ready. */
|
||||
last: CloudWakeProgressEvent | undefined
|
||||
/** The wake shown as still connecting while the pane in front re-attaches. */
|
||||
held: CloudWakeProgressEvent | undefined
|
||||
}
|
||||
|
||||
/**
|
||||
* A wake reports ready once the server answers; the pane in front re-attaches to its terminal a
|
||||
* moment later. Until it has, this returns the wake as still `connecting` (same start time and
|
||||
* source, so the pill keeps counting from the wake's start), then `undefined` hands back to the
|
||||
* store's wake. Bounded, so a pane that never attaches can't hold the pill forever.
|
||||
*/
|
||||
export function useWakeAttachHold(
|
||||
workspaceId: string,
|
||||
wake: CloudWakeProgressEvent | undefined,
|
||||
isAttached: (workspaceId: string) => boolean | null = isActiveWakePaneAttached
|
||||
): CloudWakeProgressEvent | undefined {
|
||||
const [track, setTrack] = useState<Track>({ last: undefined, held: undefined })
|
||||
|
||||
// Adjusted during render (not in an effect), so the pill never shows a stale frame.
|
||||
if (wake && (wake.phase === 'waking' || wake.phase === 'connecting')) {
|
||||
const last = track.last
|
||||
if (!last || last.startedAt !== wake.startedAt || last.phase !== wake.phase || track.held) {
|
||||
setTrack({ last: wake, held: undefined })
|
||||
}
|
||||
} else if (wake?.phase === 'failed') {
|
||||
if (track.last || track.held) {
|
||||
setTrack({ last: undefined, held: undefined })
|
||||
}
|
||||
} else if (track.last && (!wake || wake.startedAt === track.last.startedAt)) {
|
||||
// Ready, or the settled entry already dropped: hold only a wake that was in flight here.
|
||||
const held =
|
||||
isAttached(workspaceId) === false
|
||||
? { ...track.last, phase: 'connecting' as const }
|
||||
: undefined
|
||||
setTrack({ last: undefined, held })
|
||||
}
|
||||
|
||||
// Release once the pane is attached, or after the cap. The store dropping the settled wake
|
||||
// doesn't cancel this: it is keyed on the held wake only.
|
||||
const heldStart = track.held?.startedAt
|
||||
useEffect(() => {
|
||||
if (heldStart === undefined) {
|
||||
return
|
||||
}
|
||||
const since = Date.now()
|
||||
return installWindowVisibilityInterval({
|
||||
run: () => {
|
||||
if (isAttached(workspaceId) !== false || Date.now() - since >= WAKE_ATTACH_HOLD_MAX_MS) {
|
||||
setTrack((current) =>
|
||||
current.held?.startedAt === heldStart ? { ...current, held: undefined } : current
|
||||
)
|
||||
}
|
||||
},
|
||||
intervalMs: WAKE_ATTACH_POLL_MS
|
||||
})
|
||||
}, [heldStart, workspaceId, isAttached])
|
||||
|
||||
return track.held
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
// Which terminal panes a workspace has, whether each is the one in front, and whether its
|
||||
// transport is attached to a live terminal. A wake reports ready once the server answers, but the
|
||||
// pane in front re-attaches to its terminal a moment later; the waking pill waits for that, so it
|
||||
// never disappears over a pane that can't take a keystroke yet.
|
||||
|
||||
export type WakePaneEntry = {
|
||||
/** Attached to the woken terminal and taking input. */
|
||||
isReady: () => boolean
|
||||
/** The pane in front: its tab is the active, visible one and it is that tab's active pane. */
|
||||
isActive: () => boolean
|
||||
}
|
||||
|
||||
const panes = new Map<string, Map<string, WakePaneEntry>>()
|
||||
|
||||
/** Registers a pane (keyed by its layout leaf, which outlives remounts); returns its removal. */
|
||||
export function registerWakePane(
|
||||
workspaceId: string | null | undefined,
|
||||
paneKey: string,
|
||||
entry: WakePaneEntry
|
||||
): () => void {
|
||||
if (!workspaceId) {
|
||||
return () => {}
|
||||
}
|
||||
const forWorkspace = panes.get(workspaceId) ?? new Map<string, WakePaneEntry>()
|
||||
forWorkspace.set(paneKey, entry)
|
||||
panes.set(workspaceId, forWorkspace)
|
||||
return () => {
|
||||
const current = panes.get(workspaceId)
|
||||
// A remount registered a newer entry under the same key: leave that one.
|
||||
if (current?.get(paneKey) === entry) {
|
||||
current.delete(paneKey)
|
||||
if (current.size === 0) {
|
||||
panes.delete(workspaceId)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function safely(read: () => boolean): boolean {
|
||||
try {
|
||||
return read()
|
||||
} catch {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the pane in front of this workspace attached? `null` when no pane in front is known (nothing
|
||||
* mounted, or another tab type is showing): there is nothing to wait for.
|
||||
*/
|
||||
export function isActiveWakePaneAttached(workspaceId: string): boolean | null {
|
||||
const forWorkspace = panes.get(workspaceId)
|
||||
if (!forWorkspace) {
|
||||
return null
|
||||
}
|
||||
for (const entry of forWorkspace.values()) {
|
||||
if (safely(entry.isActive)) {
|
||||
return safely(entry.isReady)
|
||||
}
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
/** Tests. */
|
||||
export function resetWakePanesForTests(): void {
|
||||
panes.clear()
|
||||
}
|
||||
+41
-29
@@ -25,6 +25,7 @@ import {
|
||||
rebindWakeInputTarget
|
||||
} from '../../input/wake-input-buffer'
|
||||
import { findColdRestoreResumeSource } from '../startup/cold-restore-resume-startup'
|
||||
import { registerWakePane } from '../../input/wake-pane-attach'
|
||||
|
||||
export function installPtyInputForward(session: ConnectPanePtySession): void {
|
||||
session.forwardPtyInput = (data: string, wasUserInput = false): void => {
|
||||
@@ -172,6 +173,14 @@ export function installPtyInputForward(session: ConnectPanePtySession): void {
|
||||
return Boolean(transport?.isConnected() && (phase ?? 'connected') === 'connected')
|
||||
}
|
||||
rebindWakeInputTarget(session.deps.worktreeId, wakeInputKey, forwardUserInput, wakeInputReady)
|
||||
// The waking pill stays until the pane in front is attached again (it can take keys then).
|
||||
const unregisterWakePane = registerWakePane(session.deps.worktreeId, wakeInputKey, {
|
||||
isReady: wakeInputReady,
|
||||
isActive: () =>
|
||||
!session.disposed &&
|
||||
Boolean(session.deps.isActiveRef.current) &&
|
||||
session.manager.getActivePane()?.id === session.pane.id
|
||||
})
|
||||
// Typing is only held for shell panes: a woken agent pane relaunches the agent, and text typed
|
||||
// for the old screen must not become its prompt.
|
||||
const isAgentPane = (): boolean => {
|
||||
@@ -182,36 +191,39 @@ export function installPtyInputForward(session: ConnectPanePtySession): void {
|
||||
)
|
||||
}
|
||||
const forwardUnclassifiedInput = (data: string): void => session.forwardPtyInput(data, false)
|
||||
session.onDataDisposable = subscribeToTerminalInputData(
|
||||
session.pane.terminal,
|
||||
(data, wasUserInput) => {
|
||||
if (wasUserInput) {
|
||||
noteUserInputForPane(wakeInputKey, Date.now(), session.deps.worktreeId)
|
||||
}
|
||||
// Typing into a workspace whose server is waking is accepted now and delivered, in order,
|
||||
// once this pane is attached to the woken terminal.
|
||||
if (
|
||||
wasUserInput &&
|
||||
hasWakeInput(session.deps.worktreeId) &&
|
||||
!isAgentPane() &&
|
||||
captureWakeInput(
|
||||
session.deps.worktreeId,
|
||||
wakeInputKey,
|
||||
data,
|
||||
forwardUserInput,
|
||||
wakeInputReady
|
||||
)
|
||||
) {
|
||||
return
|
||||
}
|
||||
const forward = wasUserInput ? forwardUserInput : forwardUnclassifiedInput
|
||||
if (session.deps.deferPtyInput) {
|
||||
session.deps.deferPtyInput(session.pane.id, data, forward)
|
||||
return
|
||||
}
|
||||
forward(data)
|
||||
const inputData = subscribeToTerminalInputData(session.pane.terminal, (data, wasUserInput) => {
|
||||
if (wasUserInput) {
|
||||
noteUserInputForPane(wakeInputKey, Date.now(), session.deps.worktreeId)
|
||||
}
|
||||
)
|
||||
// Typing into a workspace whose server is waking is accepted now and delivered, in order,
|
||||
// once this pane is attached to the woken terminal.
|
||||
if (
|
||||
wasUserInput &&
|
||||
hasWakeInput(session.deps.worktreeId) &&
|
||||
!isAgentPane() &&
|
||||
captureWakeInput(
|
||||
session.deps.worktreeId,
|
||||
wakeInputKey,
|
||||
data,
|
||||
forwardUserInput,
|
||||
wakeInputReady
|
||||
)
|
||||
) {
|
||||
return
|
||||
}
|
||||
const forward = wasUserInput ? forwardUserInput : forwardUnclassifiedInput
|
||||
if (session.deps.deferPtyInput) {
|
||||
session.deps.deferPtyInput(session.pane.id, data, forward)
|
||||
return
|
||||
}
|
||||
forward(data)
|
||||
})
|
||||
session.onDataDisposable = {
|
||||
dispose: () => {
|
||||
unregisterWakePane()
|
||||
inputData.dispose()
|
||||
}
|
||||
}
|
||||
session.imeCompositionRouteDisposable = installTerminalImeCompositionRoute({
|
||||
terminalElement: session.pane.terminal.element,
|
||||
terminal: session.pane.terminal,
|
||||
|
||||
+2
-2
@@ -2239,8 +2239,8 @@
|
||||
"idleSleptMinutes_one": "{{name}} slept after {{count}} minute idle",
|
||||
"idleSleptMinutes_other": "{{name}} slept after {{count}} minutes idle",
|
||||
"overlay": {
|
||||
"pendingKeys_one": "{{count}} key waiting · goes to the terminal when it’s up",
|
||||
"pendingKeys_other": "{{count}} keys waiting · go to the terminal when it’s up"
|
||||
"pendingKeys_one": "{{count}} key waiting · it goes to the terminal when it’s up",
|
||||
"pendingKeys_other": "{{count}} keys waiting · they go to the terminal when it’s up"
|
||||
}
|
||||
},
|
||||
"pet": {
|
||||
|
||||
@@ -26478,15 +26478,16 @@
|
||||
"restarting": "Restarting…",
|
||||
"unarchiving": "Restoring from archive…",
|
||||
"waking": "Waking…",
|
||||
"connecting": "Connecting…",
|
||||
"stuck": "This is taking much longer than usual.",
|
||||
"slow": "Taking longer than usual…",
|
||||
"slow": "Taking longer than usual. Your files and chats are safe.",
|
||||
"messageQueued": "Your message sends as soon as it’s up.",
|
||||
"failedTitle": "Couldn’t wake {{name}}",
|
||||
"failedDetail": "Your files and chats are saved.",
|
||||
"tryAgain": "Try again",
|
||||
"stalled": "Orca Cloud stopped responding while waking.",
|
||||
"pendingKeys_one": "{{count}} key waiting · goes to the terminal when it’s up",
|
||||
"pendingKeys_other": "{{count}} keys waiting · go to the terminal when it’s up",
|
||||
"pendingKeys_one": "{{count}} key waiting · it goes to the terminal when it’s up",
|
||||
"pendingKeys_other": "{{count}} keys waiting · they go to the terminal when it’s up",
|
||||
"clearPendingKeys": "Discard waiting keys"
|
||||
},
|
||||
"announce": {
|
||||
|
||||
Reference in New Issue
Block a user