mirror of
https://github.com/stablyai/orca.git
synced 2026-11-17 03:15:01 +00:00
Merge pull request #761 from nwparker/cloud/agent-start-status
feat(cloud): "Starting Claude…" instead of a blank cursor; no "Asleep" flash on a new workspace
This commit is contained in:
@@ -167,6 +167,14 @@ describe('the paired cloud workspace surface', () => {
|
||||
expect(wakePaired).toHaveBeenCalledWith(ID, { source: 'open' })
|
||||
})
|
||||
|
||||
it('a just-created paired row with no status read and no pane yet is not shown as asleep', async () => {
|
||||
seedCloudWorkspaceSnapshot({ paired: { [ID]: 'env-paired' }, idsLoaded: true })
|
||||
const { container } = render(<OrcaCloudWorkspaceSurface worktreeId={ID} />)
|
||||
await flush()
|
||||
expect(container.querySelector('[data-cloud-cover="asleep"]')).toBeNull()
|
||||
expect(container.textContent).not.toContain('Wake to continue')
|
||||
})
|
||||
|
||||
it('after a paired Sleep: saving (never the empty states) until a new-enough sealed copy is read', async () => {
|
||||
// The old copy, then nothing new, then the one this Sleep sealed.
|
||||
reads = [
|
||||
|
||||
@@ -134,10 +134,13 @@ export function PairedCloudWorkspaceSurface({
|
||||
isWakeActive(view.wake, Math.max(now, view.wake.at))
|
||||
)
|
||||
// Sleep pressed here: its status read can still say ready, but it is going to sleep.
|
||||
// Before the first status read "sleeping" only means no pane has opened yet (a workspace that was
|
||||
// just created and is about to start its agent): never show it as asleep on that alone.
|
||||
const asleep =
|
||||
!wakeInFlight &&
|
||||
view.state !== 'archived' &&
|
||||
(view.state === 'sleeping' || copySaveEntry?.state === 'saving')
|
||||
((view.state === 'sleeping' && Boolean(view.entry?.status)) ||
|
||||
copySaveEntry?.state === 'saving')
|
||||
const layer: 'waking' | 'asleep' | null = overlay.wake ? 'waking' : asleep ? 'asleep' : null
|
||||
|
||||
const sandbox = usePairedSandboxId(workspaceId, layer === 'asleep')
|
||||
|
||||
@@ -13,6 +13,7 @@ import { isPaneOwnerRecoveryError } from '../errors/terminal-error-display'
|
||||
import { TerminalErrorToast } from '../errors/TerminalErrorToast'
|
||||
import { openTerminalBesideTab } from '../context-menu/open-terminal-beside-tab'
|
||||
import { AgentLaunchPaneNoticePortal } from '../launch-outcome/AgentLaunchPaneNotice'
|
||||
import { AgentStartingPortals } from '../launch-outcome/AgentStartingPortals'
|
||||
import { TerminalSessionStateSaveFailureDialog } from '../layout/persistence/TerminalSessionStateSaveFailureDialog'
|
||||
import { LinkActionPopover } from '@/components/link-actions/LinkActionPopover'
|
||||
import { TerminalAgentSessionForkDialog } from '../session-fork/TerminalAgentSessionForkDialog'
|
||||
@@ -233,6 +234,7 @@ export function TerminalPaneSurface({
|
||||
`terminal-error-${activePane.id}`
|
||||
)
|
||||
: null}
|
||||
<AgentStartingPortals controller={controller} />
|
||||
<TerminalPaneProcessExitPortals controller={controller} />
|
||||
<TerminalPaneSshReconnectPortals controller={controller} />
|
||||
<DaemonActionDialog api={daemonActions} />
|
||||
|
||||
@@ -0,0 +1,141 @@
|
||||
import { useEffect, useState } from 'react'
|
||||
import { createPortal } from 'react-dom'
|
||||
import { Loader2 } from 'lucide-react'
|
||||
import { useTranslate } from '@/i18n/use-translate'
|
||||
import { useNow } from '@/hooks/use-now'
|
||||
import type { Terminal } from '@xterm/xterm'
|
||||
import { TUI_AGENT_DISPLAY_NAMES } from '../../../../../shared/agent-launch/catalog/tui-agent-display-names'
|
||||
import type { TuiAgent } from '../../../../../shared/agent-launch/catalog/tui-agent'
|
||||
import type { TerminalPaneController } from '../controller/use-terminal-pane-controller'
|
||||
import {
|
||||
AGENT_STARTING_DELAY_MS,
|
||||
AGENT_STARTING_SLOW_MS,
|
||||
isAgentLaunchLeaf,
|
||||
terminalHasVisibleContent
|
||||
} from './agent-starting-state'
|
||||
|
||||
/** Terminals that have drawn something: once they have, the status never comes back. */
|
||||
const drawn = new WeakSet<Terminal>()
|
||||
|
||||
function useTerminalStillBlank(terminal: Terminal): boolean {
|
||||
const [blank, setBlank] = useState(
|
||||
() => !drawn.has(terminal) && !terminalHasVisibleContent(terminal.buffer)
|
||||
)
|
||||
useEffect(() => {
|
||||
if (!blank) {
|
||||
drawn.add(terminal)
|
||||
return
|
||||
}
|
||||
const check = (): void => {
|
||||
if (terminalHasVisibleContent(terminal.buffer)) {
|
||||
drawn.add(terminal)
|
||||
setBlank(false)
|
||||
}
|
||||
}
|
||||
check()
|
||||
const subscription = terminal.onWriteParsed(check)
|
||||
return () => subscription.dispose()
|
||||
}, [terminal, blank])
|
||||
return blank
|
||||
}
|
||||
|
||||
export function AgentStartingStatus({
|
||||
agent,
|
||||
startedAt
|
||||
}: {
|
||||
agent: TuiAgent
|
||||
startedAt: number
|
||||
}): React.JSX.Element | null {
|
||||
const t = useTranslate()
|
||||
const now = useNow(1_000)
|
||||
const elapsed = Math.max(0, now - startedAt)
|
||||
if (elapsed < AGENT_STARTING_DELAY_MS) {
|
||||
return null
|
||||
}
|
||||
const name = TUI_AGENT_DISPLAY_NAMES[agent] ?? agent
|
||||
return (
|
||||
<div
|
||||
data-agent-starting=""
|
||||
className="pointer-events-none absolute inset-0 z-40 flex items-center justify-center p-4 motion-safe:animate-in motion-safe:fade-in-0 motion-safe:duration-200"
|
||||
>
|
||||
<div
|
||||
role="status"
|
||||
className="flex flex-col items-center gap-1.5 text-center text-sm text-muted-foreground"
|
||||
>
|
||||
<span className="flex items-center gap-2">
|
||||
<Loader2 className="size-4 animate-spin" aria-hidden="true" />
|
||||
<span className="font-medium text-foreground">
|
||||
{t('terminalPane.agentStarting.title', 'Starting {{agent}}…', { agent: name })}
|
||||
</span>
|
||||
<span className="tabular-nums" aria-hidden="true">
|
||||
{Math.floor(elapsed / 1000)}s
|
||||
</span>
|
||||
</span>
|
||||
{elapsed >= AGENT_STARTING_SLOW_MS ? (
|
||||
<span className="text-xs">
|
||||
{t(
|
||||
'terminalPane.agentStarting.slow',
|
||||
'Taking longer than usual. It opens here as soon as it’s ready.'
|
||||
)}
|
||||
</span>
|
||||
) : null}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
function PaneAgentStarting({
|
||||
terminal,
|
||||
agent,
|
||||
container,
|
||||
paneId
|
||||
}: {
|
||||
terminal: Terminal
|
||||
agent: TuiAgent
|
||||
container: HTMLElement
|
||||
paneId: number
|
||||
}): React.JSX.Element | null {
|
||||
const blank = useTerminalStillBlank(terminal)
|
||||
// Counted from when this pane began waiting; the clock stops mattering once it draws.
|
||||
const [startedAt] = useState(() => Date.now())
|
||||
if (!blank) {
|
||||
return null
|
||||
}
|
||||
return createPortal(
|
||||
<AgentStartingStatus agent={agent} startedAt={startedAt} />,
|
||||
container,
|
||||
`agent-starting-${paneId}`
|
||||
)
|
||||
}
|
||||
|
||||
/** "Starting Claude…" over a launched agent's pane until the agent draws its first frame. */
|
||||
export function AgentStartingPortals({
|
||||
controller
|
||||
}: {
|
||||
controller: TerminalPaneController
|
||||
}): React.JSX.Element | null {
|
||||
const { managedPanes, terminalTab, paneProcessExitsByPaneId } = controller
|
||||
const agent = terminalTab?.launchAgent
|
||||
// Read once per render: a launch older than the window never shows the status.
|
||||
const [mountedAt] = useState(() => Date.now())
|
||||
if (!agent) {
|
||||
return null
|
||||
}
|
||||
return (
|
||||
<>
|
||||
{managedPanes.map((pane) =>
|
||||
// An exited agent shows its exit overlay (the error), never "Starting".
|
||||
isAgentLaunchLeaf(terminalTab, pane.leafId, managedPanes.length, mountedAt) &&
|
||||
!paneProcessExitsByPaneId[pane.id] ? (
|
||||
<PaneAgentStarting
|
||||
key={pane.id}
|
||||
terminal={pane.terminal}
|
||||
agent={agent}
|
||||
container={pane.container}
|
||||
paneId={pane.id}
|
||||
/>
|
||||
) : null
|
||||
)}
|
||||
</>
|
||||
)
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
import { useState } from 'react'
|
||||
import { defineFixture } from '../../../component-fixtures/component-fixture'
|
||||
import { AgentStartingStatus } from './AgentStartingPortals'
|
||||
|
||||
function Pane({ elapsedMs }: { elapsedMs: number }): React.JSX.Element {
|
||||
const [startedAt] = useState(() => Date.now() - elapsedMs)
|
||||
return (
|
||||
<div className="relative h-[260px] border border-border bg-background">
|
||||
<span className="absolute top-1 left-1.5 inline-block h-4 w-2 bg-foreground/80" />
|
||||
<AgentStartingStatus agent="claude" startedAt={startedAt} />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
/** A cloud Claude pane before Claude's first frame: says what is happening, never a bare cursor. */
|
||||
export const starting = defineFixture({ width: 720, render: () => <Pane elapsedMs={4_000} /> })
|
||||
|
||||
export const startingSlow = defineFixture({ width: 720, render: () => <Pane elapsedMs={24_000} /> })
|
||||
@@ -0,0 +1,38 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import {
|
||||
AGENT_STARTING_WINDOW_MS,
|
||||
isAgentLaunchLeaf,
|
||||
terminalHasVisibleContent
|
||||
} from './agent-starting-state'
|
||||
|
||||
function buffer(lines: string[]) {
|
||||
return {
|
||||
active: {
|
||||
length: lines.length,
|
||||
getLine: (y: number) => (y < lines.length ? { translateToString: () => lines[y] } : undefined)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
describe('agent starting status', () => {
|
||||
it('a pane with only a cursor (escape setup, blank rows) is still starting; any text ends it', () => {
|
||||
expect(terminalHasVisibleContent(buffer(['', ' ', '']))).toBe(false)
|
||||
expect(terminalHasVisibleContent(buffer(['', ' ╭─ Claude Code']))).toBe(true)
|
||||
})
|
||||
|
||||
it('shows only on the launched agent’s pane, and only for a fresh launch', () => {
|
||||
const now = 1_000_000
|
||||
const tab = { launchAgent: 'claude', createdAt: now - 1_000 }
|
||||
expect(isAgentLaunchLeaf(tab, 'leaf-1', 1, now)).toBe(true)
|
||||
// A split beside it is a plain terminal.
|
||||
expect(isAgentLaunchLeaf(tab, 'leaf-2', 2, now)).toBe(false)
|
||||
expect(
|
||||
isAgentLaunchLeaf({ ...tab, agentLaunchPane: { leafId: 'leaf-2' } }, 'leaf-2', 2, now)
|
||||
).toBe(true)
|
||||
// A plain terminal tab, or a restored launch from long ago (a reattach, not a start).
|
||||
expect(isAgentLaunchLeaf({ createdAt: now }, 'leaf-1', 1, now)).toBe(false)
|
||||
expect(
|
||||
isAgentLaunchLeaf({ ...tab, createdAt: now - AGENT_STARTING_WINDOW_MS - 1 }, 'leaf-1', 1, now)
|
||||
).toBe(false)
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,47 @@
|
||||
// "Starting <agent>…" while a launched agent's pane is still blank. A cloud agent starts behind
|
||||
// a shell whose echo is erased, so between the pane attaching and the agent's first frame there is
|
||||
// only a cursor; this says what is happening instead (Neil, n70: a blank cursor for ~10 s).
|
||||
|
||||
/** Below this, the agent usually draws first: no status flashes by. */
|
||||
export const AGENT_STARTING_DELAY_MS = 600
|
||||
/** Past this, the status says it's taking longer than usual. */
|
||||
export const AGENT_STARTING_SLOW_MS = 20_000
|
||||
|
||||
type BufferLike = {
|
||||
active: {
|
||||
length: number
|
||||
getLine: (y: number) => { translateToString: (trimRight?: boolean) => string } | undefined
|
||||
}
|
||||
}
|
||||
|
||||
/** Whether anything visible has been drawn yet (escape sequences and cursor moves don't count). */
|
||||
export function terminalHasVisibleContent(buffer: BufferLike): boolean {
|
||||
const { active } = buffer
|
||||
for (let y = 0; y < active.length; y++) {
|
||||
if (active.getLine(y)?.translateToString(true).trim()) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
/** Only a launch this recent can still be starting; an older blank pane is a reattach, not a start. */
|
||||
export const AGENT_STARTING_WINDOW_MS = 3 * 60_000
|
||||
|
||||
/**
|
||||
* The pane that runs the tab's freshly launched agent: its recorded leaf, else the tab's only pane.
|
||||
*/
|
||||
export function isAgentLaunchLeaf(
|
||||
tab:
|
||||
| { launchAgent?: string; agentLaunchPane?: { leafId: string }; createdAt: number }
|
||||
| null
|
||||
| undefined,
|
||||
leafId: string,
|
||||
paneCount: number,
|
||||
now: number
|
||||
): boolean {
|
||||
if (!tab?.launchAgent || now - tab.createdAt > AGENT_STARTING_WINDOW_MS) {
|
||||
return false
|
||||
}
|
||||
return tab.agentLaunchPane ? tab.agentLaunchPane.leafId === leafId : paneCount === 1
|
||||
}
|
||||
@@ -29269,5 +29269,11 @@
|
||||
"tryAgain": "Try again",
|
||||
"goneTitle": "Couldn’t find {{name}}",
|
||||
"goneDescription": "It may have been deleted."
|
||||
},
|
||||
"terminalPane": {
|
||||
"agentStarting": {
|
||||
"title": "Starting {{agent}}…",
|
||||
"slow": "Taking longer than usual. It opens here as soon as it’s ready."
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user