mirror of
https://github.com/stablyai/orca.git
synced 2026-11-17 19:34:29 +00:00
feat(cloud): pre-sleep scrollback stays greyed behind the Asleep since divider while waking, until the new terminal attaches (JA-15)
This commit is contained in:
@@ -23,10 +23,13 @@ export function formatAsleepSince(at: number, now = Date.now()): string {
|
||||
*/
|
||||
export function CloudAsleepTerminalNotice({
|
||||
workspaceId,
|
||||
asleepSince
|
||||
asleepSince,
|
||||
waking = false
|
||||
}: {
|
||||
workspaceId: string
|
||||
asleepSince: number | null
|
||||
/** Waking: the waking pill speaks; keep only the greyed history and its divider. */
|
||||
waking?: boolean
|
||||
}): React.JSX.Element {
|
||||
const t = useTranslate()
|
||||
return (
|
||||
@@ -55,21 +58,27 @@ export function CloudAsleepTerminalNotice({
|
||||
<span className="h-px flex-1 bg-border" />
|
||||
</div>
|
||||
) : null}
|
||||
<div
|
||||
role="status"
|
||||
className="pointer-events-auto flex items-center justify-between gap-3 rounded-md border border-border bg-popover px-3.5 py-2.5 text-xs text-muted-foreground"
|
||||
>
|
||||
<span>
|
||||
{t(
|
||||
'orcaCloudWorkspace.terminal.asleepHistoryKept',
|
||||
'This workspace is asleep. Your terminal history is kept.'
|
||||
)}
|
||||
</span>
|
||||
<Button size="xs" variant="outline" onClick={() => void wakeCloudWorkspace(workspaceId)}>
|
||||
<Play />
|
||||
{t('orcaCloudWorkspace.wake', 'Wake')}
|
||||
</Button>
|
||||
</div>
|
||||
{waking ? null : (
|
||||
<div
|
||||
role="status"
|
||||
className="pointer-events-auto flex items-center justify-between gap-3 rounded-md border border-border bg-popover px-3.5 py-2.5 text-xs text-muted-foreground"
|
||||
>
|
||||
<span>
|
||||
{t(
|
||||
'orcaCloudWorkspace.terminal.asleepHistoryKept',
|
||||
'This workspace is asleep. Your terminal history is kept.'
|
||||
)}
|
||||
</span>
|
||||
<Button
|
||||
size="xs"
|
||||
variant="outline"
|
||||
onClick={() => void wakeCloudWorkspace(workspaceId)}
|
||||
>
|
||||
<Play />
|
||||
{t('orcaCloudWorkspace.wake', 'Wake')}
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
|
||||
+13
@@ -27,6 +27,7 @@ import {
|
||||
getWakeProcessHint,
|
||||
readTerminalTail,
|
||||
resetWakeProcessCapture,
|
||||
wakeShowsStaleHistory,
|
||||
useWakeProcessHintsVersion
|
||||
} from '@/lib/orca-cloud/cloud-wake-process-hints'
|
||||
import { paneShowsWslHostStoppedCard } from '@/runtime/hosts/wsl/wsl-host-stopped-status'
|
||||
@@ -232,6 +233,18 @@ export function TerminalPaneRecoveryPortals({
|
||||
`cloud-asleep-${pane.id}`
|
||||
)
|
||||
}
|
||||
// Waking: the pre-sleep scrollback is still there and must not read as live (JA-15).
|
||||
if (cloudWaking && wakeShowsStaleHistory(pane.leafId)) {
|
||||
return createPortal(
|
||||
<CloudAsleepTerminalNotice
|
||||
workspaceId={controller.worktreeId}
|
||||
asleepSince={cloud?.asleepSince ?? null}
|
||||
waking
|
||||
/>,
|
||||
pane.container,
|
||||
`cloud-waking-history-${pane.id}`
|
||||
)
|
||||
}
|
||||
// Up again after a sleep: the process that was running is gone; say so once, never rerun it.
|
||||
const wokeHint = cloudAwake ? getWakeProcessHint(pane.leafId) : null
|
||||
if (wokeHint) {
|
||||
|
||||
@@ -69,6 +69,8 @@ export function readTerminalTail(terminal: TailSource, count = 200): string[] {
|
||||
const hints = new Map<string, WakeProcessHint>()
|
||||
// Panes already looked at in this sleep: the first look sees the pre-sleep scrollback.
|
||||
const captured = new Set<string>()
|
||||
// Panes whose pre-sleep scrollback had any text: greyed while waking until the new terminal attaches.
|
||||
const withHistory = new Set<string>()
|
||||
const listeners = new Set<() => void>()
|
||||
let version = 0
|
||||
|
||||
@@ -85,9 +87,15 @@ export function captureWakeProcessHint(leafId: string, lines: readonly string[])
|
||||
return
|
||||
}
|
||||
captured.add(leafId)
|
||||
const hasHistory = lines.some((line) => line.trim() !== '')
|
||||
if (hasHistory) {
|
||||
withHistory.add(leafId)
|
||||
}
|
||||
const hint = detectForegroundCommand(lines)
|
||||
if (hint) {
|
||||
hints.set(leafId, hint)
|
||||
}
|
||||
if (hasHistory || hint) {
|
||||
emit()
|
||||
}
|
||||
}
|
||||
@@ -96,9 +104,15 @@ export function captureWakeProcessHint(leafId: string, lines: readonly string[])
|
||||
export function resetWakeProcessCapture(leafIds: readonly string[]): void {
|
||||
for (const id of leafIds) {
|
||||
captured.delete(id)
|
||||
withHistory.delete(id)
|
||||
}
|
||||
}
|
||||
|
||||
/** The pane still shows output from before the sleep (looked at during this sleep, with any text). */
|
||||
export function wakeShowsStaleHistory(leafId: string): boolean {
|
||||
return withHistory.has(leafId)
|
||||
}
|
||||
|
||||
export function dismissWakeProcessHint(leafId: string): void {
|
||||
if (hints.delete(leafId)) {
|
||||
emit()
|
||||
@@ -123,5 +137,6 @@ export function useWakeProcessHintsVersion(): number {
|
||||
export function resetWakeProcessHintsForTests(): void {
|
||||
hints.clear()
|
||||
captured.clear()
|
||||
withHistory.clear()
|
||||
version = 0
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ export type CloudRecoveryContext = {
|
||||
asleep: boolean
|
||||
/** What the person calls it (never the sandbox's server name or id). */
|
||||
workspaceName: string | null
|
||||
/** When this computer last saw it go to sleep (the local record's suspend time); null if unknown. */
|
||||
/** While asleep or waking: when it went to sleep (the local record's suspend time); null if unknown. */
|
||||
asleepSince: number | null
|
||||
}
|
||||
|
||||
@@ -42,5 +42,5 @@ export function useCloudRecoveryContext(
|
||||
const asleep =
|
||||
!waking &&
|
||||
(reported === 'sleeping' || reported === 'stopping' || reported === 'archived' || vmSuspended)
|
||||
return { waking, asleep, workspaceName, asleepSince: asleep ? suspendedAt : null }
|
||||
return { waking, asleep, workspaceName, asleepSince: asleep || waking ? suspendedAt : null }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user