fix(cloud): JA-15 review: woke-up note is a space-reserving pane strip that leaves on typing, middle-truncated mono command, Asleep since includes the date across days; catalog keys

This commit is contained in:
Neil
2026-11-10 21:04:27 -08:00
parent 16c9afc546
commit 09739d8e3e
5 changed files with 117 additions and 43 deletions
@@ -5,10 +5,14 @@ import { useTranslate } from '@/i18n/use-translate'
import { getIntlLocale } from '@/i18n/i18n'
import { wakeCloudWorkspace } from '../cloud-workspace-actions'
export function formatAsleepSince(at: number): string {
return new Intl.DateTimeFormat(getIntlLocale(), { hour: 'numeric', minute: '2-digit' }).format(
new Date(at)
)
/** "3:10 PM" today; "Nov 10, 3:10 PM" once it has been asleep across a day boundary. */
export function formatAsleepSince(at: number, now = Date.now()): string {
const sameDay = new Date(at).toDateString() === new Date(now).toDateString()
return new Intl.DateTimeFormat(getIntlLocale(), {
...(sameDay ? {} : { month: 'short', day: 'numeric' }),
hour: 'numeric',
minute: '2-digit'
}).format(new Date(at))
}
/**
@@ -1,8 +1,9 @@
// @vitest-environment happy-dom
import { afterEach, describe, expect, it, vi } from 'vitest'
import { cleanup, fireEvent, render, screen } from '@testing-library/react'
import { CloudAsleepTerminalNotice } from './CloudAsleepTerminalNotice'
import { CloudWokeProcessesNotice } from './CloudWokeProcessesNotice'
import { CloudAsleepTerminalNotice, formatAsleepSince } from './CloudAsleepTerminalNotice'
import { CloudWokeProcessesNotice, truncateMiddle } from './CloudWokeProcessesNotice'
import { noteUserInputForPane } from '@/components/terminal-pane/input/pane-user-input'
vi.mock('../cloud-workspace-actions', () => ({ wakeCloudWorkspace: vi.fn() }))
vi.mock('@/i18n/use-translate', () => ({
@@ -12,6 +13,13 @@ vi.mock('@/i18n/use-translate', () => ({
)
}))
afterEach(() => cleanup())
if (globalThis.ResizeObserver === undefined) {
globalThis.ResizeObserver = class {
observe(): void {}
unobserve(): void {}
disconnect(): void {}
} as unknown as typeof ResizeObserver
}
describe('CloudAsleepTerminalNotice', () => {
it('greys the scrollback and shows the "Asleep since" divider', () => {
@@ -35,8 +43,44 @@ describe('CloudWokeProcessesNotice', () => {
const onRerun = vi.fn()
render(<CloudWokeProcessesNotice command="pnpm dev" onRerun={onRerun} onDismiss={vi.fn()} />)
expect(screen.getByText('Woke up · processes stopped while asleep')).toBeTruthy()
expect(screen.getByRole('button', { name: /Rerun pnpm dev/ }).getAttribute('title')).toBe(
'pnpm dev'
)
expect(onRerun).not.toHaveBeenCalled()
fireEvent.click(screen.getByRole('button', { name: /Rerun pnpm dev/ }))
expect(onRerun).toHaveBeenCalledTimes(1)
})
it('truncates a long command in the middle, keeping both ends', () => {
const long = 'python3 -m http.server --directory /very/long/path/to/site 8000'
const short = truncateMiddle(long, 24)
expect(short.length).toBe(24)
expect(short.startsWith('python3')).toBe(true)
expect(short.endsWith('8000')).toBe(true)
})
it('goes away once the person types in the pane', () => {
vi.useFakeTimers()
const onDismiss = vi.fn()
render(
<CloudWokeProcessesNotice
command="pnpm dev"
paneLeafId="leaf-x"
onRerun={vi.fn()}
onDismiss={onDismiss}
/>
)
noteUserInputForPane('leaf-x', Date.now() + 1)
vi.advanceTimersByTime(600)
expect(onDismiss).toHaveBeenCalled()
vi.useRealTimers()
})
})
describe('formatAsleepSince', () => {
it('adds the date once it has been asleep across a day boundary', () => {
const at = new Date(2026, 10, 10, 15, 10).getTime()
expect(formatAsleepSince(at, new Date(2026, 10, 10, 18, 0).getTime())).not.toMatch(/Nov/)
expect(formatAsleepSince(at, new Date(2026, 10, 11, 9, 0).getTime())).toMatch(/Nov/)
})
})
@@ -1,55 +1,76 @@
import React from 'react'
import { RotateCcw, X } from 'lucide-react'
import React, { useEffect, useState } from 'react'
import { RotateCcw } from 'lucide-react'
import { Button } from '@/components/ui/button'
import { useTranslate } from '@/i18n/use-translate'
import { PaneTopWarningBanner } from '@/components/terminal-pane/appearance/pane-top-banner/PaneTopWarningBanner'
import { paneHadUserInputSince } from '@/components/terminal-pane/input/pane-user-input'
const MAX_COMMAND_CHARS = 48
/** "python3 -m http…server 8000": keeps both ends of a long command readable. */
export function truncateMiddle(text: string, max = MAX_COMMAND_CHARS): string {
if (text.length <= max) {
return text
}
const keep = max - 1
const head = Math.ceil(keep / 2)
return `${text.slice(0, head)}…${text.slice(text.length - (keep - head))}`
}
/**
* After a wake, in a pane that was running something when the workspace went to sleep: sleep is a
* reboot, so the process is gone. One line says so and offers the command back; it never runs it
* by itself (JA-15).
* reboot, so the process is gone. A strip at the top of the pane (it reserves its height, so it
* never covers terminal rows) says so and offers the command back; it never runs it by itself, and
* it goes away once the person types in the pane (JA-15).
*/
export function CloudWokeProcessesNotice({
command,
paneLeafId,
onRerun,
onDismiss
}: {
command: string
/** When set, typing into this pane dismisses the strip. */
paneLeafId?: string
onRerun: () => void
onDismiss: () => void
}): React.JSX.Element {
const t = useTranslate()
const [shownAt] = useState(() => Date.now())
useEffect(() => {
if (!paneLeafId) {
return
}
const timer = setInterval(() => {
if (paneHadUserInputSince(paneLeafId, shownAt)) {
onDismiss()
}
}, 500)
return () => clearInterval(timer)
}, [paneLeafId, shownAt, onDismiss])
return (
<div
data-cloud-woke-processes-notice=""
role="status"
className="absolute inset-x-3 bottom-3 z-50 flex items-center gap-3 rounded-md border border-border bg-popover px-3.5 py-2 text-xs text-muted-foreground"
>
<span className="min-w-0 flex-1 truncate">
{t(
'orcaCloudWorkspace.terminal.wokeProcessesStopped',
'Woke up · processes stopped while asleep'
)}
</span>
<Button
size="xs"
variant="outline"
className="min-w-0 max-w-[50%]"
onClick={onRerun}
title={command}
>
<RotateCcw />
<span className="truncate font-mono">
{t('orcaCloudWorkspace.terminal.rerun', 'Rerun {{command}}', { command })}
</span>
</Button>
<Button
size="icon-xs"
variant="ghost"
onClick={onDismiss}
aria-label={t('orcaCloudWorkspace.terminal.dismissWoke', 'Dismiss')}
>
<X />
</Button>
</div>
<PaneTopWarningBanner
tone="neutral"
title={t(
'orcaCloudWorkspace.terminal.wokeProcessesStopped',
'Woke up · processes stopped while asleep'
)}
primaryAction={
<Button
type="button"
size="xs"
variant="outline"
onClick={onRerun}
title={command}
aria-label={t('orcaCloudWorkspace.terminal.rerun', 'Rerun {{command}}', { command })}
data-cloud-woke-rerun=""
>
<RotateCcw />
{t('orcaCloudWorkspace.terminal.rerunLabel', 'Rerun')}
<span className="font-mono">{truncateMiddle(command)}</span>
</Button>
}
onDismiss={onDismiss}
/>
)
}
@@ -238,6 +238,7 @@ export function TerminalPaneRecoveryPortals({
return createPortal(
<CloudWokeProcessesNotice
command={wokeHint.command}
paneLeafId={pane.leafId}
onRerun={() => {
dismissWakeProcessHint(pane.leafId)
paneTransportsRef.current
+5 -1
View File
@@ -26967,7 +26967,11 @@
"recentCommits": "Recent commits"
},
"terminal": {
"asleepHistoryKept": "This workspace is asleep. Your terminal history is kept."
"asleepHistoryKept": "This workspace is asleep. Your terminal history is kept.",
"asleepSince": "Asleep since {{time}}",
"rerun": "Rerun {{command}}",
"rerunLabel": "Rerun",
"wokeProcessesStopped": "Woke up · processes stopped while asleep"
}
},
"cloudAgentSetup": {