The spinner ran a CSS animation on every active row for the whole turn, repainting a composited layer at frame rate. Rows now carry a static dot — primary while running, info while unread — and the metadata slot on the right shows how long the turn has been going, updating once per second in the dot's colour. The counter is the motion the spinner used to provide, at 1 fps. Collapsed groups, folders and projects take the dot only, since one counter cannot speak for several running turns. Elapsed time is measured client-side because SessionStatus carries no timestamps, and starts are persisted so a reload resumes the same count. Two rules keep that honest. Only a liveness stamp — refreshed while a session is observed active, stamped as the page hides, and compared against the page's navigation start so a slow bootstrap is not charged to the absence — and a 90s adoption window may expire a record; a snapshot that cannot yet see a session is not evidence its turn ended. And a busy event is never read as a turn boundary, because OpenCode republishes busy at every step of the agent loop, so after a reload one of those repeats normally beats the first status snapshot. Idle and error events do end a turn, and retire the record with it. Snapshot reconciliation walks the running turns and asks whether the snapshot covers each one, rather than being handed everything it covers: only a live start can settle, so the pass scales with timing work instead of with the directory's session list, and allocates nothing per poll. Also applied to the mobile sessions sheet and session switcher. The shared duration ticker moves to hooks/ now that it has a second consumer.
33 lines
1.1 KiB
TypeScript
33 lines
1.1 KiB
TypeScript
import type { I18nKey, I18nParams } from '@/lib/i18n';
|
|
|
|
type Translate = (key: I18nKey, params?: I18nParams) => string;
|
|
|
|
const SECOND_MS = 1000;
|
|
const MINUTE_MS = 60 * SECOND_MS;
|
|
const HOUR_MS = 60 * MINUTE_MS;
|
|
|
|
/**
|
|
* Compact turn duration for a session row: `7s`, `1m 23s`, `1h 2m`.
|
|
*
|
|
* Seconds are dropped past an hour so the label cannot outgrow the row's
|
|
* metadata slot, and the unit suffixes are translated rather than concatenated
|
|
* so locales that place or spell them differently stay correct.
|
|
*/
|
|
export const formatSessionActivityDuration = (durationMs: number, t: Translate): string => {
|
|
const total = Math.max(0, durationMs);
|
|
|
|
if (total < MINUTE_MS) {
|
|
return t('common.duration.secondsCompact', { seconds: Math.floor(total / SECOND_MS) });
|
|
}
|
|
if (total < HOUR_MS) {
|
|
return t('common.duration.minutesSecondsCompact', {
|
|
minutes: Math.floor(total / MINUTE_MS),
|
|
seconds: Math.floor((total % MINUTE_MS) / SECOND_MS),
|
|
});
|
|
}
|
|
return t('common.duration.hoursMinutesCompact', {
|
|
hours: Math.floor(total / HOUR_MS),
|
|
minutes: Math.floor((total % HOUR_MS) / MINUTE_MS),
|
|
});
|
|
};
|