diff --git a/changelog.d/added-activity-monitor-display-stale.md b/changelog.d/added-activity-monitor-display-stale.md new file mode 100644 index 0000000000..31152cbd48 --- /dev/null +++ b/changelog.d/added-activity-monitor-display-stale.md @@ -0,0 +1 @@ +- Activity Monitor display mode (`?display=1`) now says when its data is stale ([#15930](https://github.com/hivecommons/hive/issues/15930), part of [#15860](https://github.com/hivecommons/hive/issues/15860)). A wall screen used to keep showing its last payload as if it were live after the event stream or the spoke went quiet. Now the display header shows the hive id, a clock and a live dot. When the stream has been silent for more than two poll intervals, or the payload is older than two cache TTLs, the dot turns amber, the board dims and a banner reads *Stale: last update N ago*. The display recovers by itself when updates resume. After five failed reconnects it reloads on a 30 s → 10 min backoff, and it reloads once after an upgrade finishes. The URL, and so the view, survives the reload. The ordinary Activity Monitor and headless `?kiosk=1` output are unchanged. diff --git a/changelog.d/added-activity-monitor-display-tv-density.md b/changelog.d/added-activity-monitor-display-tv-density.md new file mode 100644 index 0000000000..e94b116955 --- /dev/null +++ b/changelog.d/added-activity-monitor-display-tv-density.md @@ -0,0 +1 @@ +- Activity Monitor display mode (`?display=1`) gains wall-screen options ([#15931](https://github.com/hivecommons/hive/issues/15931), part of [#15860](https://github.com/hivecommons/hive/issues/15860)). `density=tv` uses larger type and shows only each row's stage, title and actor. It shows only the rows that fit the screen, with a "+N more" footer instead of the pager. `shift=1` moves the board 1–2 px every 4 minutes to protect OLED screens from burn-in. With *reduce motion* on, a display plays no row movement and no shift. Both options are ignored without `display=1`, so the ordinary Activity Monitor and `?kiosk=1` render exactly as before. The TV layout adds nothing that changes state. diff --git a/src/docs/streaming-the-activity-monitor.md b/src/docs/streaming-the-activity-monitor.md index f49b36966c..59ad882d19 100644 --- a/src/docs/streaming-the-activity-monitor.md +++ b/src/docs/streaming-the-activity-monitor.md @@ -229,6 +229,30 @@ time per view with `interval`: - Playlists exist only in the URL. There are no named presets in `hive.yaml`, and playlists apply only in display mode, never to `?kiosk=1`. +A display says honestly when its data is old. Its header shows the hive id, +a clock and a live dot. When the event stream has been silent for more than +two poll intervals (about a minute), or the tracker payload is older than two +server cache TTLs, the dot turns amber, the board dims and a banner reads +*Stale: last update N ago*. It recovers by itself when updates resume. If +the stream fails to reconnect five times in a row, the display reloads +itself after 30 s, doubling on each further reload up to 10 minutes; it also +reloads once after a hive upgrade finishes. A reload keeps the URL, so the +view survives. The ordinary Activity Monitor and `?kiosk=1` do not dim, and +the "updated … ago" chip behaves as before everywhere. + +Two wall-screen options apply only together with `display=1` and are ignored +otherwise: + +| Parameter | Effect | +|---|---| +| `density=tv` | Larger type and only the stage, title and actor of each row. No filters, row chips or pager: the rows that fit the screen, then a "+N more" footer. Recomputed when the window is resized. `tv` is the only value; anything else is ignored. | +| `shift=1` | OLED burn-in protection: the board moves 1–2 px to a new spot every 4 minutes. Off by default. | + +With the operating system's *reduce motion* setting on, a display plays no +row movement, no burn-in shift and no dim transition. + +Example: `/?display=1&density=tv&shift=1#section-activity-monitor-section`. + Any Activity Monitor filter can be described in the URL with `am.*` parameters, so a display link reproduces the view in a fresh browser profile: diff --git a/src/pkg/dashboard/kiosk_mode_test.go b/src/pkg/dashboard/kiosk_mode_test.go index 1297132688..89d0b7fba0 100644 --- a/src/pkg/dashboard/kiosk_mode_test.go +++ b/src/pkg/dashboard/kiosk_mode_test.go @@ -68,6 +68,36 @@ func TestDisplayModeWiring(t *testing.T) { } } +// TestDisplayOptionsWiring guards the display-mode wall options (#15931): +// `density=tv` and `shift=1` set their body classes only inside the +// display-mode branch of boot.js, so `?density=tv` or `?shift=1` without +// `display=1` (and any kiosk URL, where display mode is off) renders exactly +// as before, and `density` accepts only `tv`. +func TestDisplayOptionsWiring(t *testing.T) { + html := indexHTML(t) + for _, want := range []string{ + `density=u.searchParams.get('density')==='tv'?'tv':'';`, + `shift=u.searchParams.get('shift')==='1';`, + `window.HIVE_DISPLAY_DENSITY=window.HIVE_DISPLAY?density:'';`, + `window.HIVE_DISPLAY_SHIFT=window.HIVE_DISPLAY&&shift;`, + } { + if !strings.Contains(html, want) { + t.Errorf("index.html missing display option wiring %q", want) + } + } + branch := "if(window.HIVE_DISPLAY){\n document.body.classList.add('display-mode');\n document.body.classList.add('ham-chromeless');\n" + + " if(window.HIVE_DISPLAY_DENSITY==='tv') document.body.classList.add('display-density-tv');\n" + + " if(window.HIVE_DISPLAY_SHIFT) document.body.classList.add('display-shift');\n" + if !strings.Contains(html, branch) { + t.Error("display-density-tv / display-shift must be added only inside boot.js's display-mode branch") + } + for _, cls := range []string{"display-density-tv", "display-shift"} { + if n := strings.Count(html, "classList.add('"+cls+"')"); n != 1 { + t.Errorf("%s added %d times; want exactly once, in the display-mode branch", cls, n) + } + } +} + // TestKioskSoundDefault guards the streamer's audio path: in kiosk mode the // tracker sounds are on unless the URL says `&sound=off`, the context is // resumed at init without waiting for a gesture (the streamer's Chromium diff --git a/src/pkg/dashboard/stage_tracker_display.test.js b/src/pkg/dashboard/stage_tracker_display.test.js index 211f070b81..91995250d8 100644 --- a/src/pkg/dashboard/stage_tracker_display.test.js +++ b/src/pkg/dashboard/stage_tracker_display.test.js @@ -146,16 +146,22 @@ test('display mode wiring: header button, boot flag, chrome-less CSS and hidden assert.match(html, /id="activity-monitor-display" data-action="toggleStageTrackerDisplay" data-stop="1" aria-pressed="false"/); assert.ok(html.includes("display=u.searchParams.get('display')==='1'")); assert.ok(html.includes('window.HIVE_DISPLAY=display&&!kiosk;'), 'kiosk wins'); - assert.ok(html.includes("document.body.classList.add('display-mode');")); + assert.ok(html.includes("document.body.classList.add('display-mode');\n document.body.classList.add('ham-chromeless');"), 'display shares the chrome-less layout class'); for (const rule of [ - 'body.display-mode .hive-chat-panel, body.display-mode #welcome-overlay, body.display-mode .nps-card { display: none !important; }', - 'html body.display-mode #oc-topbar[id] { display: none !important; }', - 'body.display-mode #hive-dashboard-root > [data-dashboard-section]:not(#activity-monitor-section) { display: none !important; }', + 'body.ham-chromeless #dash-notices, body.ham-chromeless #oc-agent-detail, body.ham-chromeless .hive-chat-fab,', + 'body.display-mode #welcome-overlay, body.display-mode .nps-card { display: none !important; }', + 'html body.ham-chromeless #oc-topbar[id] { display: none !important; }', + 'body.ham-chromeless #hive-dashboard-root > [data-dashboard-section]:not(#activity-monitor-section) { display: none !important; }', 'body.display-mode #activity-monitor-section .ham-row-tools, body.display-mode #activity-monitor-selbar,', 'body.display-mode .ham-decision-acts { display: none !important; }', 'body.kiosk-mode .ham-header-tool, body.kiosk-mode .ham-popout-return { display: none !important; }', ]) assert.ok(html.includes(rule), 'missing CSS rule: ' + rule); assert.ok(!/body\.display-mode[^{]*\{[^}]*cursor:\s*none/.test(html), 'display mode keeps the cursor'); + assert.ok(!/body\.ham-chromeless[^{]*\{[^}]*cursor:\s*none/.test(html), 'the shared layout keeps the cursor'); + // One shared class, not one selector copy per chrome-less view (#15956). + const popoutCss = fs.readFileSync(path.join(__dirname, 'static-src', 'css', 'popout.css'), 'utf8'); + assert.ok(!popoutCss.includes('body.ham-fullscreen #hive-dashboard-root'), 'full screen rides ham-chromeless'); + assert.ok(!popoutCss.includes('body.display-mode #hive-dashboard-root'), 'display rides ham-chromeless'); assert.ok(html.includes('function setLayout(mode) { if (window.hiveDisplayMode && window.hiveDisplayMode()) return; localStorage.setItem(LAYOUT_KEY, mode); }'), 'theme is never persisted from a display'); assert.ok(html.includes('function dashboardLayoutWrite(){if(window.hiveDisplayMode&&window.hiveDisplayMode())return;'), 'layout is never persisted from a display'); }); @@ -203,8 +209,8 @@ const controlsSrc = [ 'var _stageTrackerDisplayLastPointer = 0;', 'var _stageTrackerDisplayHideTimer = null;', 'var _stageTrackerWakeLock = null;', 'var _stageTrackerWakeLockError = null;', 'var _stageTrackerWakeLockWanted = false;', ...['stageTrackerDisplayMode', 'stageTrackerDisplayUrl', 'toggleStageTrackerDisplay', - 'stageTrackerFullscreenTarget', 'stageTrackerFullscreenButton', 'stageTrackerIsFullscreen', 'stageTrackerFullscreenLabel', - 'stageTrackerRenderFullscreenButton', 'toggleStageTrackerFullscreen', + 'stageTrackerFullscreenTarget', 'stageTrackerFullscreenButton', 'stageTrackerIsFullscreen', 'stageTrackerSetFullscreenLayout', + 'stageTrackerFullscreenLabel', 'stageTrackerRenderFullscreenButton', 'toggleStageTrackerFullscreen', 'stageTrackerDisplayControlsEl', 'stageTrackerDisplayControlsSync', 'stageTrackerDisplayControlsPing', 'stageTrackerWakeLockSupported', 'stageTrackerRenderDisplayControls', 'stageTrackerWakeLockAcquire', 'stageTrackerWakeLockRelease', 'stageTrackerToggleWakeLock', 'stageTrackerWakeLockOnVisible', 'stageTrackerDisplayExit', diff --git a/src/pkg/dashboard/stage_tracker_display_layout.test.js b/src/pkg/dashboard/stage_tracker_display_layout.test.js new file mode 100644 index 0000000000..8d5d969a60 --- /dev/null +++ b/src/pkg/dashboard/stage_tracker_display_layout.test.js @@ -0,0 +1,74 @@ +// Display-mode wall layout (hivecommons/hive#15931): `density=tv` caps the +// rows to what fits the viewport with a "+N more" footer instead of the +// pager, `shift=1` is a burn-in shift, and reduced motion turns row movement +// off on a display. The helpers are lifted by marker out of index.html so +// this runs against the shipped source. +const test = require('node:test'); +const assert = require('node:assert'); +const fs = require('node:fs'); +const path = require('node:path'); + +const html = fs.readFileSync(path.join(__dirname, 'static', 'index.html'), 'utf8'); +const m = html.match(/\/\/ tracker display layout helpers begin\n([\s\S]*?)\/\/ tracker display layout helpers end/); +assert.ok(m, 'tracker display layout helpers not found'); +const h = new Function(m[1] + '; return { stageTrackerDisplayRowCap, stageTrackerDisplayCapPage, stageTrackerDisplayMoreHtml, stageTrackerDisplayMotionEffect };')(); + +test('row cap: the rows that fit below the header', () => { + assert.strictEqual(h.stageTrackerDisplayRowCap(1080, 200, 80), 11); + assert.strictEqual(h.stageTrackerDisplayRowCap(2160, 200, 80), 24); + assert.strictEqual(h.stageTrackerDisplayRowCap(1080, 0, 100), 10); + assert.strictEqual(h.stageTrackerDisplayRowCap(1079, 0, 100), 10, 'a partial row does not count'); +}); + +test('row cap: never below one row, and one when sizes are unknown', () => { + assert.strictEqual(h.stageTrackerDisplayRowCap(300, 400, 80), 1, 'header taller than the viewport'); + assert.strictEqual(h.stageTrackerDisplayRowCap(1080, 200, 0), 1); + assert.strictEqual(h.stageTrackerDisplayRowCap(0, 0, 80), 1); + assert.strictEqual(h.stageTrackerDisplayRowCap(NaN, 0, 80), 1); + assert.strictEqual(h.stageTrackerDisplayRowCap(1080, -50, 100), 10, 'a negative header is ignored'); +}); + +test('capped page: first rows, no pager, a correct "+N more" count', () => { + const rows = Array.from({ length: 23 }, (_, i) => i); + const p = h.stageTrackerDisplayCapPage(rows, 10); + assert.deepStrictEqual(p.rows, rows.slice(0, 10)); + assert.strictEqual(p.pages, 1, 'no pager'); + assert.strictEqual(p.total, 23); + assert.strictEqual(p.more, 13); + assert.strictEqual(p.from, 1); + assert.strictEqual(p.to, 10); + const all = h.stageTrackerDisplayCapPage(rows.slice(0, 4), 10); + assert.strictEqual(all.more, 0); + assert.strictEqual(all.rows.length, 4); + const none = h.stageTrackerDisplayCapPage([], 10); + assert.strictEqual(none.from, 0); + assert.strictEqual(none.more, 0); +}); + +test('"+N more" footer only when rows were left out', () => { + assert.strictEqual(h.stageTrackerDisplayMoreHtml(13), '+13 more'); + assert.strictEqual(h.stageTrackerDisplayMoreHtml(0), ''); + assert.strictEqual(h.stageTrackerDisplayMoreHtml(-2), ''); +}); + +test('reduced motion turns row movement off on a display only', () => { + assert.strictEqual(h.stageTrackerDisplayMotionEffect('rm-fade', true, true), ''); + assert.strictEqual(h.stageTrackerDisplayMotionEffect('wash', true, false), 'wash'); + assert.strictEqual(h.stageTrackerDisplayMotionEffect('rm-fade', false, true), 'rm-fade', 'the ordinary monitor keeps its crossfade'); + assert.strictEqual(h.stageTrackerDisplayMotionEffect('wash', false, false), 'wash'); +}); + +test('wiring: density and shift are honoured only with display=1; TV replaces the pager; shift is inert under reduced motion', () => { + assert.ok(html.includes("density=u.searchParams.get('density')==='tv'?'tv':'';"), 'density accepts only tv'); + assert.ok(html.includes("window.HIVE_DISPLAY_DENSITY=window.HIVE_DISPLAY?density:'';")); + assert.ok(html.includes('window.HIVE_DISPLAY_SHIFT=window.HIVE_DISPLAY&&shift;')); + assert.ok(html.includes("if(window.HIVE_DISPLAY_DENSITY==='tv') document.body.classList.add('display-density-tv');")); + assert.ok(html.includes("if(window.HIVE_DISPLAY_SHIFT) document.body.classList.add('display-shift');")); + assert.ok(html.includes("const grouping = _stageTrackerGroup === 'repo' && !tv;")); + assert.ok(html.includes('? stageTrackerDisplayCapPage(ordered, stageTrackerDisplayTvCap())')); + assert.ok(html.includes('if (foot) setIfChanged(foot, tv ? stageTrackerDisplayMoreHtml(page.more) : ')); + assert.ok(html.includes("if (typeof stageTrackerDisplayEffect === 'function') effect = stageTrackerDisplayEffect(effect);")); + assert.ok(html.includes('body.display-shift #activity-monitor-section { animation: ham-display-shift 16min steps(1, end) infinite; }')); + assert.match(html, /@media \(prefers-reduced-motion: reduce\) \{\n\s*body\.display-shift #activity-monitor-section \{ animation: none; \}/); + assert.ok(html.includes('body.display-density-tv #activity-monitor-section .ham-head-pr, body.display-density-tv #activity-monitor-section .ham-badges,'), 'TV drops the PR column and chips'); +}); diff --git a/src/pkg/dashboard/stage_tracker_display_liveness.test.js b/src/pkg/dashboard/stage_tracker_display_liveness.test.js new file mode 100644 index 0000000000..7d9ddcf14c --- /dev/null +++ b/src/pkg/dashboard/stage_tracker_display_liveness.test.js @@ -0,0 +1,102 @@ +// Display-mode liveness (hivecommons/hive#15930): a display board dims and +// says "Stale: last update N ago" once the event stream has been silent for +// more than two poll intervals or the payload is older than two cache TTLs, +// and a display that cannot reconnect reloads itself on a capped backoff. +// The helpers are lifted by marker out of index.html so this runs against +// the shipped source. +const test = require('node:test'); +const assert = require('node:assert'); +const fs = require('node:fs'); +const path = require('node:path'); + +const html = fs.readFileSync(path.join(__dirname, 'static', 'index.html'), 'utf8'); +const m = html.match(/\/\/ tracker display liveness helpers begin\n([\s\S]*?)\/\/ tracker display liveness helpers end/); +assert.ok(m, 'tracker display liveness helpers not found'); +const h = new Function(m[1] + '; return { stageTrackerDisplayStale, stageTrackerDisplayReloadDelayMs, stageTrackerDisplayRollReload, stageTrackerDisplayAgo, stageTrackerDisplayStaleText };')(); + +const POLL = 30000; +const TTL = 30000; +const NOW = 10_000_000; + +test('fresh: a recent frame and a recent payload are not stale', () => { + assert.deepStrictEqual(h.stageTrackerDisplayStale(NOW, NOW - 1000, POLL, NOW - 5000, TTL), { stale: false, sinceMs: 0, reason: '' }); + // Exactly two intervals is still live; the threshold is "more than". + assert.strictEqual(h.stageTrackerDisplayStale(NOW, NOW - 2 * POLL, POLL, NOW - 2 * TTL, TTL).stale, false); +}); + +test('SSE silent for more than two poll intervals is stale, since the last frame', () => { + const last = NOW - 2 * POLL - 1; + assert.deepStrictEqual(h.stageTrackerDisplayStale(NOW, last, POLL, NOW - 1000, TTL), { stale: true, sinceMs: last, reason: 'sse' }); +}); + +test('a payload older than two cache TTLs is stale, since generated_at', () => { + const gen = NOW - 4 * 60 * 1000; + assert.deepStrictEqual(h.stageTrackerDisplayStale(NOW, NOW - 1000, POLL, gen, TTL), { stale: true, sinceMs: gen, reason: 'ttl' }); + // No TTL in the payload: the payload age judges nothing. + assert.strictEqual(h.stageTrackerDisplayStale(NOW, NOW - 1000, POLL, gen, 0).stale, false); +}); + +test('both quiet: stale, since the newer of the two', () => { + const last = NOW - 5 * 60 * 1000, gen = NOW - 4 * 60 * 1000; + assert.deepStrictEqual(h.stageTrackerDisplayStale(NOW, last, POLL, gen, TTL), { stale: true, sinceMs: gen, reason: 'both' }); +}); + +test('never connected and no payload yet: nothing to judge, not stale', () => { + assert.deepStrictEqual(h.stageTrackerDisplayStale(NOW, 0, POLL, 0, TTL), { stale: false, sinceMs: 0, reason: '' }); + assert.strictEqual(h.stageTrackerDisplayStale(NOW, undefined, POLL, NaN, TTL).stale, false); + // The caller judges a never-connected stream from page load instead. + const loaded = NOW - 3 * POLL; + assert.strictEqual(h.stageTrackerDisplayStale(NOW, loaded, POLL, 0, TTL).reason, 'sse'); +}); + +test('recovery: a frame after a silence clears the stale state', () => { + assert.strictEqual(h.stageTrackerDisplayStale(NOW, NOW - 10 * POLL, POLL, NOW - 1000, TTL).stale, true); + assert.strictEqual(h.stageTrackerDisplayStale(NOW, NOW, POLL, NOW - 1000, TTL).stale, false); +}); + +test('banner text reads "Stale: last update N ago"', () => { + const st = h.stageTrackerDisplayStale(NOW, NOW - 4 * 60 * 1000, POLL, NOW - 1000, TTL); + assert.strictEqual(h.stageTrackerDisplayStaleText(st, NOW), 'Stale: last update 4 m ago'); + assert.strictEqual(h.stageTrackerDisplayStaleText({ stale: false }, NOW), ''); + assert.strictEqual(h.stageTrackerDisplayStaleText({ stale: true, sinceMs: 0 }, NOW), 'Stale: no update yet'); + assert.strictEqual(h.stageTrackerDisplayAgo(61 * 1000), '1 m'); + assert.strictEqual(h.stageTrackerDisplayAgo(45 * 1000), '45 s'); + assert.strictEqual(h.stageTrackerDisplayAgo(2 * 3600 * 1000), '2 h'); + assert.strictEqual(h.stageTrackerDisplayAgo(3 * 86400 * 1000), '3 d'); + assert.strictEqual(h.stageTrackerDisplayAgo(-5), '0 s'); +}); + +test('reload backoff: none before 5 failed reconnects, then 30 s doubling per attempt, capped at 10 min', () => { + for (let f = 0; f < 5; f++) assert.strictEqual(h.stageTrackerDisplayReloadDelayMs(f, 0), 0, f + ' failures'); + const schedule = [0, 1, 2, 3, 4, 5, 6, 50].map(a => h.stageTrackerDisplayReloadDelayMs(5, a)); + assert.deepStrictEqual(schedule, [30000, 60000, 120000, 240000, 480000, 600000, 600000, 600000]); + assert.strictEqual(h.stageTrackerDisplayReloadDelayMs(12, 0), 30000, 'more failures do not shorten the wait'); + assert.strictEqual(h.stageTrackerDisplayReloadDelayMs(5, -3), 30000); + assert.strictEqual(h.stageTrackerDisplayReloadDelayMs(undefined, 0), 0); +}); + +test('roll signal: reload once for a roll that finished after the page loaded', () => { + const loaded = NOW - 60000; + assert.strictEqual(h.stageTrackerDisplayRollReload({ source: 'roll', completedAt: NOW }, loaded), true); + assert.strictEqual(h.stageTrackerDisplayRollReload({ source: 'roll', completedAt: loaded - 1 }, loaded), false, 'the reloaded page does not reload again'); + assert.strictEqual(h.stageTrackerDisplayRollReload({ source: 'roll', completedAt: 0 }, loaded), false, 'still rolling'); + assert.strictEqual(h.stageTrackerDisplayRollReload({ source: 'hub', completedAt: NOW }, loaded), false, 'only the roll signal'); + assert.strictEqual(h.stageTrackerDisplayRollReload(null, loaded), false); +}); + +test('wiring: display mode only — the tick, banner and reload are gated on stageTrackerDisplayMode', () => { + assert.ok(html.includes("document.addEventListener('DOMContentLoaded', function() {\n if (!stageTrackerDisplayMode()) return;\n stageTrackerDisplayMountHead();")); + assert.ok(html.includes("dashboardSetInterval('display-liveness', stageTrackerDisplayTick, STAGE_TRACKER_DISPLAY_TICK_MS);")); + assert.ok(html.includes("function stageTrackerDisplayNoteReconnectFailed() {\n if (!stageTrackerDisplayMode()) return;")); + assert.ok(html.includes("if (typeof stageTrackerDisplayNoteReconnectFailed === 'function') stageTrackerDisplayNoteReconnectFailed();"), 'the SSE onerror counts failures'); + assert.ok(html.includes("if (typeof stageTrackerDisplayNoteFrame === 'function') stageTrackerDisplayNoteFrame();"), 'any frame resets them'); + assert.ok(html.includes("document.body.classList.toggle('display-stale', st.stale);")); + for (const rule of [ + 'body.display-mode.display-stale .ham-display-dot { color: var(--amber); }', + 'body.display-mode.display-stale #activity-monitor-panel, body.display-mode.display-stale #activity-monitor-meta,', + '.ham-display-head, .ham-display-stale { display: none; }', + ]) assert.ok(html.includes(rule), 'missing CSS rule: ' + rule); + // The "updated … ago" chip keeps its behaviour everywhere. + assert.ok(html.includes('const stale = failing || (ttlMs > 0 && ageMs > 2 * ttlMs);')); + assert.ok(!html.includes("localStorage.setItem('hive-display"), 'nothing persisted in localStorage'); +}); diff --git a/src/pkg/dashboard/stage_tracker_popout.test.js b/src/pkg/dashboard/stage_tracker_popout.test.js index 3f5521c5fb..d53dabbf0f 100644 --- a/src/pkg/dashboard/stage_tracker_popout.test.js +++ b/src/pkg/dashboard/stage_tracker_popout.test.js @@ -51,6 +51,7 @@ function load(env) { pick(/function stageTrackerFullscreenTarget\(\) \{[\s\S]*?\n \}\n/, 'stageTrackerFullscreenTarget'), pick(/function stageTrackerFullscreenButton\(\) \{[\s\S]*?\n \}\n/, 'stageTrackerFullscreenButton'), pick(/function stageTrackerIsFullscreen\(\) \{[\s\S]*?\n \}\n/, 'stageTrackerIsFullscreen'), + pick(/function stageTrackerSetFullscreenLayout\(on\) \{[\s\S]*?\n \}\n/, 'stageTrackerSetFullscreenLayout'), pick(/function stageTrackerFullscreenLabel\(isFull\) \{[\s\S]*?\n \}\n/, 'stageTrackerFullscreenLabel'), pick(/function stageTrackerRenderFullscreenButton\(\) \{[\s\S]*?\n \}\n/, 'stageTrackerRenderFullscreenButton'), pick(/function toggleStageTrackerFullscreen\(\) \{[\s\S]*?\n \}\n/, 'toggleStageTrackerFullscreen'), @@ -107,13 +108,13 @@ test('⧉ opens one named popup window with the popup features and focuses it; a test('popout mode: boot flags the body before paint and the CSS removes every piece of chrome', () => { assert.ok(html.includes("popout=u.searchParams.get('popout')==='1'"), 'boot.js reads ?popout=1'); assert.ok(html.includes("window.hivePopoutMode=function(){ return !!window.HIVE_POPOUT; };")); - assert.ok(html.includes("document.body.classList.add('popout-mode');")); + assert.ok(html.includes("document.body.classList.add('popout-mode');\n document.body.classList.add('ham-chromeless');"), 'popout shares the chrome-less layout class'); assert.ok(html.includes("if(kiosk||window.HIVE_POPOUT){\n if(!location.hash) history.replaceState(null,'',location.pathname+location.search+'#section-activity-monitor-section');"), 'popout lands on the tracker section'); for (const rule of [ - 'body.popout-mode .oc-sidebar, body.popout-mode .oc-sidebar-resize, body.popout-mode .oc-topbar,', - 'html body.popout-mode #oc-topbar[id], html body.ham-fullscreen #oc-topbar[id] { display: none !important; }', - 'body.popout-mode #hive-dashboard-root > [data-dashboard-section]:not(#activity-monitor-section),', - 'body.ham-fullscreen #hive-dashboard-root > [data-dashboard-section]:not(#activity-monitor-section) { display: none !important; }', + 'body.ham-chromeless .oc-sidebar, body.ham-chromeless .oc-sidebar-resize, body.ham-chromeless .oc-topbar,', + 'html body.ham-chromeless #oc-topbar[id] { display: none !important; }', + 'body.ham-chromeless #hive-dashboard-root > [data-dashboard-section]:not(#activity-monitor-section) { display: none !important; }', + 'body.popout-mode #welcome-overlay, body.popout-mode .nps-card,', 'body.popout-mode .ham-popout-return { display: inline-flex; align-items: center; }', 'body.popout-mode .ham-popout-btn, body.ham-fullscreen .ham-popout-btn,', ]) assert.ok(html.includes(rule), 'missing CSS rule: ' + rule); @@ -161,12 +162,14 @@ test('⛶ requests full screen on the document, sets body.ham-fullscreen and fli assert.strictEqual(await api.toggleStageTrackerFullscreen(), true); assert.deepStrictEqual(root.calls, ['request']); assert.ok(body.classList.contains('ham-fullscreen')); + assert.ok(body.classList.contains('ham-chromeless'), 'full screen takes the shared chrome-less layout'); assert.strictEqual(btn.textContent, '⛶ Exit full screen'); assert.strictEqual(btn.attrs['aria-pressed'], 'true'); assert.match(btn.title, /^Exit full screen/); assert.strictEqual(await api.toggleStageTrackerFullscreen(), true); assert.deepStrictEqual(root.calls, ['request', 'exit']); assert.ok(!body.classList.contains('ham-fullscreen')); + assert.ok(!body.classList.contains('ham-chromeless'), 'leaving full screen drops the layout in the main window'); assert.strictEqual(btn.textContent, '⛶'); assert.strictEqual(btn.attrs['aria-pressed'], 'false'); // Esc (native exit) fires fullscreenchange with no fullscreenElement: the layout drops. @@ -176,11 +179,25 @@ test('⛶ requests full screen on the document, sets body.ham-fullscreen and fli assert.ok(!body.classList.contains('ham-fullscreen')); }); +test('leaving full screen in a pop-out or display keeps the chrome-less layout the URL asked for', async () => { + for (const mode of ['popout-mode', 'display-mode']) { + const { api, body } = load(); + body.classList.add(mode); + body.classList.add('ham-chromeless'); + assert.strictEqual(await api.toggleStageTrackerFullscreen(), true); + assert.ok(body.classList.contains('ham-fullscreen') && body.classList.contains('ham-chromeless'), mode); + assert.strictEqual(await api.toggleStageTrackerFullscreen(), true); + assert.ok(!body.classList.contains('ham-fullscreen'), mode); + assert.ok(body.classList.contains('ham-chromeless'), mode + ' keeps ham-chromeless'); + } +}); + test('a refused requestFullscreen rolls the layout back and toasts', async () => { const { api, body, root } = load(); root.requestFullscreen = () => Promise.reject(new Error('denied')); assert.strictEqual(await api.toggleStageTrackerFullscreen(), false); assert.ok(!body.classList.contains('ham-fullscreen')); + assert.ok(!body.classList.contains('ham-chromeless')); assert.match(api.toasts[0].msg, /denied/); }); diff --git a/src/pkg/dashboard/static-src/css/popout.css b/src/pkg/dashboard/static-src/css/popout.css index c4d4b22db0..cf53fae2cd 100644 --- a/src/pkg/dashboard/static-src/css/popout.css +++ b/src/pkg/dashboard/static-src/css/popout.css @@ -5,56 +5,36 @@ menu, chat FAB or notices, every other section out of flow — but attended: the cursor stays, the gear works, and a ⤶ Return link goes back to the opener. The ⛶ button puts the document into the Fullscreen API and sets - body.ham-fullscreen, which shares every rule below — the document rather - than the section so the body-level toasts (waiting on you, merges) stay - visible while full screen. */ - body.popout-mode, body.ham-fullscreen, - body.display-mode { padding: var(--sp-5) var(--sp-7) var(--sp-7) var(--sp-7); --navbar-sticky-height: 0px; } - body.popout-mode .oc-sidebar, body.popout-mode .oc-sidebar-resize, body.popout-mode .oc-topbar, - body.popout-mode #dash-notices, body.popout-mode #oc-agent-detail, body.popout-mode .hive-chat-fab, - body.popout-mode .hive-chat-panel, body.popout-mode #welcome-overlay, body.popout-mode .nps-card, - body.ham-fullscreen .oc-sidebar, body.ham-fullscreen .oc-sidebar-resize, body.ham-fullscreen .oc-topbar, - body.ham-fullscreen #dash-notices, body.ham-fullscreen #oc-agent-detail, body.ham-fullscreen .hive-chat-fab, - body.ham-fullscreen .hive-chat-panel, - body.display-mode .oc-sidebar, body.display-mode .oc-sidebar-resize, body.display-mode .oc-topbar, - body.display-mode #dash-notices, body.display-mode #oc-agent-detail, body.display-mode .hive-chat-fab, - body.display-mode .hive-chat-panel, body.display-mode #welcome-overlay, body.display-mode .nps-card { display: none !important; } + body.ham-fullscreen — the document rather than the section so the + body-level toasts (waiting on you, merges) stay visible while full screen. + Every chrome-less view (pop-out, full screen, display mode) also carries + body.ham-chromeless, which the shared layout rules below key on, so a new + view adds the class instead of another copy of every selector. */ + body.ham-chromeless { padding: var(--sp-5) var(--sp-7) var(--sp-7) var(--sp-7); --navbar-sticky-height: 0px; } + body.ham-chromeless .oc-sidebar, body.ham-chromeless .oc-sidebar-resize, body.ham-chromeless .oc-topbar, + body.ham-chromeless #dash-notices, body.ham-chromeless #oc-agent-detail, body.ham-chromeless .hive-chat-fab, + body.ham-chromeless .hive-chat-panel { display: none !important; } + /* The welcome tour and NPS card stay in the main window; full screen + keeps them, as it always has. */ + body.popout-mode #welcome-overlay, body.popout-mode .nps-card, + body.display-mode #welcome-overlay, body.display-mode .nps-card { display: none !important; } /* /api/theme.css (theme/theme.go layoutGuardCSS) forces the topbar to display:grid!important with id specificity; beat it with (1,2,2). */ - html body.popout-mode #oc-topbar[id], html body.ham-fullscreen #oc-topbar[id] { display: none !important; } - html body.display-mode #oc-topbar[id] { display: none !important; } - body.popout-mode #hive-dashboard-root > [data-dashboard-section]:not(#activity-monitor-section), - body.ham-fullscreen #hive-dashboard-root > [data-dashboard-section]:not(#activity-monitor-section) { display: none !important; } - body.display-mode #hive-dashboard-root > [data-dashboard-section]:not(#activity-monitor-section) { display: none !important; } - body.popout-mode #activity-monitor-section .dashboard-grip, body.popout-mode #activity-monitor-section .section-chevron, - body.ham-fullscreen #activity-monitor-section .dashboard-grip, body.ham-fullscreen #activity-monitor-section .section-chevron, - body.display-mode #activity-monitor-section .dashboard-grip, body.display-mode #activity-monitor-section .section-chevron { display: none !important; } + html body.ham-chromeless #oc-topbar[id] { display: none !important; } + body.ham-chromeless #hive-dashboard-root > [data-dashboard-section]:not(#activity-monitor-section) { display: none !important; } + body.ham-chromeless #activity-monitor-section .dashboard-grip, body.ham-chromeless #activity-monitor-section .section-chevron { display: none !important; } /* The header cannot collapse the only section on the page, but its gear, full-screen and return buttons must still take clicks. */ - body.popout-mode #activity-monitor-section .section-header-toggle, - body.ham-fullscreen #activity-monitor-section .section-header-toggle, - body.display-mode #activity-monitor-section .section-header-toggle { pointer-events: none; } - body.popout-mode #activity-monitor-section .section-header-toggle button, - body.popout-mode #activity-monitor-section .section-header-toggle .config-info, - body.ham-fullscreen #activity-monitor-section .section-header-toggle button, - body.ham-fullscreen #activity-monitor-section .section-header-toggle .config-info, - body.display-mode #activity-monitor-section .section-header-toggle button, - body.display-mode #activity-monitor-section .section-header-toggle .config-info { pointer-events: auto; } + body.ham-chromeless #activity-monitor-section .section-header-toggle { pointer-events: none; } + body.ham-chromeless #activity-monitor-section .section-header-toggle button, + body.ham-chromeless #activity-monitor-section .section-header-toggle .config-info { pointer-events: auto; } /* A collapsed state saved from the main window would leave an empty page with a header that cannot be clicked: always show the body. */ - body.popout-mode #activity-monitor-section .section-body.collapsed, - body.ham-fullscreen #activity-monitor-section .section-body.collapsed, - body.display-mode #activity-monitor-section .section-body.collapsed { max-height: none !important; opacity: 1; pointer-events: auto; } - body.popout-mode #activity-monitor-section .dash-card.collapsed .dash-card-actions, - body.ham-fullscreen #activity-monitor-section .dash-card.collapsed .dash-card-actions, - body.display-mode #activity-monitor-section .dash-card.collapsed .dash-card-actions { display: inline-flex; } - body.popout-mode #activity-monitor-section .dash-card.collapsed .dash-card-summary, - body.ham-fullscreen #activity-monitor-section .dash-card.collapsed .dash-card-summary, - body.display-mode #activity-monitor-section .dash-card.collapsed .dash-card-summary { display: none; } - body.popout-mode .ham-sticky, body.ham-fullscreen .ham-sticky, - body.display-mode .ham-sticky { top: 0; } - body.popout-mode .ham-cols, body.ham-fullscreen .ham-cols, - body.display-mode .ham-cols { top: var(--ham-sticky-bar-h); } + body.ham-chromeless #activity-monitor-section .section-body.collapsed { max-height: none !important; opacity: 1; pointer-events: auto; } + body.ham-chromeless #activity-monitor-section .dash-card.collapsed .dash-card-actions { display: inline-flex; } + body.ham-chromeless #activity-monitor-section .dash-card.collapsed .dash-card-summary { display: none; } + body.ham-chromeless .ham-sticky { top: 0; } + body.ham-chromeless .ham-cols { top: var(--ham-sticky-bar-h); } /* Header tools: ⧉ pop out, ⛶ full screen and 📺 display sit beside the gear and share its chip styling; the return link is a pop-out-only text pill. */ @@ -100,3 +80,57 @@ body.display-mode .ham-playlist-track { display: none; } body.display-mode .ham-playlist-next { display: inline-block; } } + + /* Display liveness (#15930): a header with the hive id, a clock and a + live dot, and — once the stream or the payload goes quiet — a dimmed + board under a "Stale: last update N ago" banner. Display mode only; + the "updated … ago" chip is unchanged everywhere. */ + .ham-display-head, .ham-display-stale { display: none; } + body.display-mode .ham-display-head { display: flex; align-items: center; gap: var(--sp-4); margin-bottom: var(--sp-3); font-size: var(--fs-sm); color: var(--muted); font-variant-numeric: tabular-nums; } + body.display-mode .ham-display-dot { color: var(--green); } + body.display-mode .ham-display-hive { font-weight: 600; color: var(--text); } + body.display-mode .ham-display-clock { margin-left: auto; } + body.display-mode.display-stale .ham-display-dot { color: var(--amber); } + body.display-mode.display-stale .ham-display-stale:not([hidden]) { display: block; margin-bottom: var(--sp-3); padding: var(--sp-2) var(--sp-4); border: var(--line-width) solid var(--amber); border-radius: var(--r-sm); background: color-mix(in srgb, var(--amber) 14%, var(--panel)); color: var(--amber); font-size: var(--fs-md); font-weight: 600; } + body.display-mode #activity-monitor-panel, body.display-mode #activity-monitor-meta, + body.display-mode #activity-monitor-sticky, body.display-mode #activity-monitor-native-queue { transition: opacity .6s ease, filter .6s ease; } + body.display-mode.display-stale #activity-monitor-panel, body.display-mode.display-stale #activity-monitor-meta, + body.display-mode.display-stale #activity-monitor-sticky, body.display-mode.display-stale #activity-monitor-native-queue { opacity: .45; filter: grayscale(.7); } + + /* density=tv (#15931): larger type, only the stage strip, the title and + the stage/actor line, no filters or pager — the rows that fit and a + "+N more" footer (stageTrackerDisplayRowCap). */ + body.display-density-tv #activity-monitor-section { + --fs-2xs: .9rem; + --fs-xs: 1rem; + --fs-sm: 1.15rem; + --fs-base: 1.25rem; + --fs-md: 1.4rem; + } + body.display-density-tv #activity-monitor-toolbar, body.display-density-tv #activity-monitor-labels, + body.display-density-tv #activity-monitor-native-queue, body.display-density-tv #activity-monitor-section .ham-pager, + body.display-density-tv #activity-monitor-section .ham-head-pr, body.display-density-tv #activity-monitor-section .ham-badges, + body.display-density-tv #activity-monitor-section .ham-since, body.display-density-tv #activity-monitor-section [data-ham-sub-key], + body.display-density-tv #activity-monitor-section .cue-event, body.display-density-tv #activity-monitor-section .ham-review-notes { display: none !important; } + body.display-density-tv #activity-monitor-section .ham-head-cols .ham-seg.ham-head-lead { flex: 1 1 0; } + body.display-density-tv .ham-display-more { display: block; text-align: center; font-size: var(--fs-md); font-weight: 600; color: var(--muted); } + + /* shift=1 (#15931): an OLED burn-in shift — the board steps 1–2 px to a + new spot every 4 minutes. Off by default and inert under reduced + motion. */ + @keyframes ham-display-shift { + 0% { transform: translate(0, 0); } + 25% { transform: translate(2px, 1px); } + 50% { transform: translate(1px, 2px); } + 75% { transform: translate(-1px, 1px); } + 100% { transform: translate(0, 0); } + } + body.display-shift #activity-monitor-section { animation: ham-display-shift 16min steps(1, end) infinite; } + + /* Reduced motion on a display: no burn-in shift and no dim transition, + the way the toasts already go linear; row movement is switched off in + JS (stageTrackerDisplayMotionEffect plays no effect at all). */ + @media (prefers-reduced-motion: reduce) { + body.display-shift #activity-monitor-section { animation: none; } + body.display-mode #activity-monitor-panel, body.display-mode #activity-monitor-meta, + body.display-mode #activity-monitor-sticky, body.display-mode #activity-monitor-native-queue { transition: none; } } diff --git a/src/pkg/dashboard/static-src/js/boot.js b/src/pkg/dashboard/static-src/js/boot.js index 7aa3fa2b39..27296dde7a 100644 --- a/src/pkg/dashboard/static-src/js/boot.js +++ b/src/pkg/dashboard/static-src/js/boot.js @@ -25,12 +25,22 @@ // presentation only: the cursor stays, sound keeps the user's setting, it // never writes layout or theme to localStorage, and it hides the row action // affordances. Kiosk wins when both flags are present. +// Display options (#15931), honoured only together with display=1: +// `density=tv` (the only value; anything else is ignored) sets +// body.display-density-tv, a larger three-column wall layout, and `shift=1` +// sets body.display-shift, an OLED burn-in shift. Without display=1 both are +// ignored, so the ordinary dashboard and kiosk render exactly as before. +// Pop-out and display mode also set body.ham-chromeless, the one class the +// shared chrome-less layout in css/popout.css keys on (full screen adds it at +// runtime); popout-mode and display-mode keep their view-specific rules. (function(){ - var kiosk=false, popout=false, display=false, sound=true; - try { var u=new URL(window.location.href); kiosk=u.searchParams.get('kiosk')==='1'; popout=u.searchParams.get('popout')==='1'; display=u.searchParams.get('display')==='1'; sound=new URL(window.location.href).searchParams.get('sound')!=='off'; } catch(e) {} + var kiosk=false, popout=false, display=false, sound=true, density='', shift=false; + try { var u=new URL(window.location.href); kiosk=u.searchParams.get('kiosk')==='1'; popout=u.searchParams.get('popout')==='1'; display=u.searchParams.get('display')==='1'; density=u.searchParams.get('density')==='tv'?'tv':''; shift=u.searchParams.get('shift')==='1'; sound=new URL(window.location.href).searchParams.get('sound')!=='off'; } catch(e) {} window.HIVE_KIOSK=kiosk; window.HIVE_POPOUT=popout&&!kiosk; window.HIVE_DISPLAY=display&&!kiosk; + window.HIVE_DISPLAY_DENSITY=window.HIVE_DISPLAY?density:''; + window.HIVE_DISPLAY_SHIFT=window.HIVE_DISPLAY&&shift; window.HIVE_KIOSK_SOUND=kiosk&&sound; window.hiveKioskMode=function(){ return !!window.HIVE_KIOSK; }; window.hivePopoutMode=function(){ return !!window.HIVE_POPOUT; }; @@ -40,12 +50,16 @@ document.body.classList.add('kiosk-mode'); }else if(window.HIVE_POPOUT){ document.body.classList.add('popout-mode'); + document.body.classList.add('ham-chromeless'); } if(kiosk||window.HIVE_POPOUT){ if(!location.hash) history.replaceState(null,'',location.pathname+location.search+'#section-activity-monitor-section'); } if(window.HIVE_DISPLAY){ document.body.classList.add('display-mode'); + document.body.classList.add('ham-chromeless'); + if(window.HIVE_DISPLAY_DENSITY==='tv') document.body.classList.add('display-density-tv'); + if(window.HIVE_DISPLAY_SHIFT) document.body.classList.add('display-shift'); if(!location.hash) history.replaceState(null,'',location.pathname+location.search+'#section-activity-monitor-section'); } })(); diff --git a/src/pkg/dashboard/static-src/js/sse-bootstrap.js b/src/pkg/dashboard/static-src/js/sse-bootstrap.js index b5f87b6b7d..fae30573c3 100644 --- a/src/pkg/dashboard/static-src/js/sse-bootstrap.js +++ b/src/pkg/dashboard/static-src/js/sse-bootstrap.js @@ -2,7 +2,14 @@ var _eventSourceReconnectTimer = null; var _sseLastFrameAtMs = 0; var _sseOpenedAtMs = 0; - function noteSSEFrame() { _sseLastFrameAtMs = Date.now(); } + // The newest frame ever seen; unlike _sseLastFrameAtMs a reconnect does + // not reset it, so display mode can say how long the stream has been + // quiet (tracker-display.js). + var _sseEverFrameAtMs = 0; + function noteSSEFrame() { + _sseLastFrameAtMs = _sseEverFrameAtMs = Date.now(); + if (typeof stageTrackerDisplayNoteFrame === 'function') stageTrackerDisplayNoteFrame(); + } // sseWatchdogTick recycles a silent stream (see sseStreamIdle). `force` // (tab became visible again) always refetches /api/status: Safari and // Chrome throttle hidden-tab timers to once a minute or less, so the tick @@ -138,6 +145,7 @@ } source.close(); if (_eventSource === source) _eventSource = null; + if (typeof stageTrackerDisplayNoteReconnectFailed === 'function') stageTrackerDisplayNoteReconnectFailed(); if (!_eventSourceReconnectTimer) { _eventSourceReconnectTimer = setTimeout(function() { _eventSourceReconnectTimer = null; connect(); }, 3000); } diff --git a/src/pkg/dashboard/static-src/js/tracker-display.js b/src/pkg/dashboard/static-src/js/tracker-display.js new file mode 100644 index 0000000000..960a060f55 --- /dev/null +++ b/src/pkg/dashboard/static-src/js/tracker-display.js @@ -0,0 +1,235 @@ +/* ---- Display mode: honest liveness and wall layout --------------------- + Rendering-only additions for `?display=1` (body.display-mode, see + boot.js and tracker-popout.js); nothing here runs, or changes a pixel, + on the ordinary Activity Monitor or a headless `?kiosk=1` stream. + Liveness (hivecommons/hive#15930): a 1 s tick dims the board and says + "Stale: last update N ago" once the event stream or the payload goes + quiet, and a display that cannot reconnect reloads itself on a capped + backoff. Layout (hivecommons/hive#15931): `density=tv` keeps the stage, + title and actor at a larger type and caps the rows to the viewport + with a "+N more" footer; `shift=1` is a CSS burn-in shift; reduced + motion turns off row movement. No endpoint, credential or URL knob + beyond `density` and `shift`. */ + + // tracker display liveness helpers begin + const STAGE_TRACKER_DISPLAY_RELOAD_AFTER_FAILS = 5; + const STAGE_TRACKER_DISPLAY_RELOAD_BASE_MS = 30000; + const STAGE_TRACKER_DISPLAY_RELOAD_MAX_MS = 600000; + // Pure: is a display board's data stale? Stale when the event stream has + // been silent for more than two poll intervals, or the payload's + // generated_at is older than two cache TTLs. A zero/absent timestamp is + // "not known yet" and judges nothing. sinceMs is the last update of the + // signal that went quiet (the newer one when both did); reason is + // 'sse', 'ttl' or 'both', '' when fresh. + function stageTrackerDisplayStale(nowMs, sseLastFrameMs, pollMs, generatedAtMs, cacheTtlMs) { + const now = Number(nowMs) || 0; + const sseAt = Number(sseLastFrameMs) || 0; + const genAt = Number(generatedAtMs) || 0; + const poll = Number(pollMs) || 0; + const ttl = Number(cacheTtlMs) || 0; + const sse = sseAt > 0 && poll > 0 && now - sseAt > 2 * poll; + const old = genAt > 0 && ttl > 0 && now - genAt > 2 * ttl; + if (!sse && !old) return { stale: false, sinceMs: 0, reason: '' }; + if (sse && old) return { stale: true, sinceMs: Math.max(sseAt, genAt), reason: 'both' }; + return sse ? { stale: true, sinceMs: sseAt, reason: 'sse' } : { stale: true, sinceMs: genAt, reason: 'ttl' }; + } + // Pure: how long to wait before reloading a display whose stream keeps + // failing — 0 until STAGE_TRACKER_DISPLAY_RELOAD_AFTER_FAILS consecutive + // failed reconnects, then 30 s doubling per reload already tried this + // session (attempt), capped at 10 min. + function stageTrackerDisplayReloadDelayMs(failures, attempt) { + if ((Number(failures) || 0) < STAGE_TRACKER_DISPLAY_RELOAD_AFTER_FAILS) return 0; + const n = Math.min(30, Math.max(0, Math.floor(Number(attempt) || 0))); + return Math.min(STAGE_TRACKER_DISPLAY_RELOAD_MAX_MS, STAGE_TRACKER_DISPLAY_RELOAD_BASE_MS * Math.pow(2, n)); + } + // Pure: should a display reload for this roll record (#15804's + // versionReadUpgradeProgress)? Only for a roll that finished after the + // page loaded, so the reload itself never triggers another. + function stageTrackerDisplayRollReload(roll, loadedAtMs) { + if (!roll || roll.source !== 'roll') return false; + const done = Number(roll.completedAt) || 0; + return done > 0 && done > (Number(loadedAtMs) || 0); + } + // Pure: "45 s", "4 m", "2 h", "3 d" for the stale banner. + function stageTrackerDisplayAgo(ms) { + const s = Math.max(0, Math.floor((Number(ms) || 0) / 1000)); + if (s < 60) return s + ' s'; + if (s < 3600) return Math.floor(s / 60) + ' m'; + if (s < 86400) return Math.floor(s / 3600) + ' h'; + return Math.floor(s / 86400) + ' d'; + } + // Pure: the banner line for a stageTrackerDisplayStale result. + function stageTrackerDisplayStaleText(st, nowMs) { + if (!st || !st.stale) return ''; + return st.sinceMs ? 'Stale: last update ' + stageTrackerDisplayAgo(nowMs - st.sinceMs) + ' ago' : 'Stale: no update yet'; + } + // tracker display liveness helpers end + + // tracker display layout helpers begin + const STAGE_TRACKER_DISPLAY_TV = 'tv'; + const STAGE_TRACKER_DISPLAY_TV_ROW_PX = 96; + const STAGE_TRACKER_DISPLAY_TV_FOOT_PX = 48; + // Pure: how many rows fit a TV display — the viewport less everything + // above the rows (and the footer), over one row's height. At least one + // row, and one when the sizes are not known yet. + function stageTrackerDisplayRowCap(viewportPx, headerPx, rowPx) { + const v = Number(viewportPx), r = Number(rowPx); + const h = Math.max(0, Number(headerPx) || 0); + if (!(v > 0) || !(r > 0)) return 1; + return Math.max(1, Math.floor((v - h) / r)); + } + // Pure: a page-shaped slice of the first `cap` rows with no pager + // (pages 1) and `more` = the rows that did not fit. + function stageTrackerDisplayCapPage(rows, cap) { + const all = Array.isArray(rows) ? rows : []; + const n = Math.max(1, Math.floor(Number(cap) || 1)); + const shown = all.slice(0, n); + return { rows: shown, page: 1, pages: 1, from: shown.length ? 1 : 0, to: shown.length, total: all.length, size: n, more: all.length - shown.length }; + } + // Pure: the "+N more" footer that replaces the pager on a TV display. + function stageTrackerDisplayMoreHtml(more) { + const n = Math.max(0, Math.floor(Number(more) || 0)); + return n ? `+${n} more` : ''; + } + // Pure: the row-motion effect for a render — none at all on a display + // under prefers-reduced-motion, unchanged everywhere else. + function stageTrackerDisplayMotionEffect(effect, display, reduced) { + return display && reduced ? '' : effect; + } + // tracker display layout helpers end + + function stageTrackerDisplayTv() { + return stageTrackerDisplayMode() && window.HIVE_DISPLAY_DENSITY === STAGE_TRACKER_DISPLAY_TV; + } + function stageTrackerDisplayEffect(effect) { + const reduced = typeof stageTrackerReducedMotion === 'function' && stageTrackerReducedMotion(); + return stageTrackerDisplayMotionEffect(effect, stageTrackerDisplayMode(), reduced); + } + + // -- TV density: rows capped to the viewport --------------------------- + var _stageTrackerDisplayRowPx = 0; + var _stageTrackerDisplayCap = 0; + function stageTrackerDisplayTvCap() { + const panel = document.getElementById('activity-monitor-panel'); + const cols = panel && panel.querySelector('.ham-cols'); + const top = panel ? panel.getBoundingClientRect().top + (window.scrollY || 0) : 0; + const head = cols ? cols.getBoundingClientRect().height : 0; + _stageTrackerDisplayCap = stageTrackerDisplayRowCap(window.innerHeight, top + head + STAGE_TRACKER_DISPLAY_TV_FOOT_PX, _stageTrackerDisplayRowPx || STAGE_TRACKER_DISPLAY_TV_ROW_PX); + return _stageTrackerDisplayCap; + } + // After a TV render: measure the real row pitch and render again once if + // the estimate fitted a different number of rows. + function stageTrackerDisplayMeasureRows(el) { + if (!el || !stageTrackerDisplayTv()) return; + const rows = el.querySelectorAll('.ham-row'); + if (!rows.length) return; + const a = rows[0].getBoundingClientRect(); + const px = rows.length > 1 ? rows[1].getBoundingClientRect().top - a.top : a.height; + if (!(px > 0) || Math.abs(px - _stageTrackerDisplayRowPx) < 1) return; + _stageTrackerDisplayRowPx = px; + const before = _stageTrackerDisplayCap; + if (stageTrackerDisplayTvCap() !== before) requestAnimationFrame(function() { renderStageTracker(); }); + } + var _stageTrackerDisplayResizeTimer = null; + window.addEventListener('resize', function() { + if (!stageTrackerDisplayTv()) return; + clearTimeout(_stageTrackerDisplayResizeTimer); + _stageTrackerDisplayResizeTimer = setTimeout(function() { renderStageTracker(); }, 150); + }); + + // -- Liveness: stale dimming, header and self-recovery ------------------ + const STAGE_TRACKER_DISPLAY_TICK_MS = 1000; + const STAGE_TRACKER_DISPLAY_RELOAD_KEY = 'hive-display-reload-attempt'; + var _stageTrackerDisplayLoadedAtMs = Date.now(); + var _stageTrackerDisplayFails = 0; + var _stageTrackerDisplayReloadTimer = null; + var _stageTrackerDisplayAttemptCleared = false; + var _stageTrackerDisplayRollReloaded = false; + function stageTrackerDisplaySessionGet(key) { + try { return sessionStorage.getItem(key) || ''; } catch { return ''; } + } + function stageTrackerDisplaySessionSet(key, value) { + try { if (value === null) sessionStorage.removeItem(key); else sessionStorage.setItem(key, value); } catch {} + } + // sse-bootstrap.js: the stream's onerror. Consecutive failures past the + // threshold schedule one reload; the URL (and so the view) survives it. + function stageTrackerDisplayNoteReconnectFailed() { + if (!stageTrackerDisplayMode()) return; + _stageTrackerDisplayFails++; + if (_stageTrackerDisplayReloadTimer) return; + const attempt = Number(stageTrackerDisplaySessionGet(STAGE_TRACKER_DISPLAY_RELOAD_KEY)) || 0; + const delay = stageTrackerDisplayReloadDelayMs(_stageTrackerDisplayFails, attempt); + if (!delay) return; + _stageTrackerDisplayReloadTimer = setTimeout(function() { + stageTrackerDisplaySessionSet(STAGE_TRACKER_DISPLAY_RELOAD_KEY, String(attempt + 1)); + window.location.reload(); + }, delay); + } + // sse-bootstrap.js: any frame. A live stream cancels a pending reload + // and resets the backoff. + function stageTrackerDisplayNoteFrame() { + if (!_stageTrackerDisplayFails && !_stageTrackerDisplayReloadTimer && _stageTrackerDisplayAttemptCleared) return; + _stageTrackerDisplayFails = 0; + if (_stageTrackerDisplayReloadTimer) { clearTimeout(_stageTrackerDisplayReloadTimer); _stageTrackerDisplayReloadTimer = null; } + if (!stageTrackerDisplayMode()) return; + _stageTrackerDisplayAttemptCleared = true; + stageTrackerDisplaySessionSet(STAGE_TRACKER_DISPLAY_RELOAD_KEY, null); + } + function stageTrackerDisplayMountHead() { + const body = document.querySelector('#activity-monitor-section .section-body'); + if (!body || document.getElementById('activity-monitor-display-head')) return; + const head = document.createElement('div'); + head.className = 'ham-display-head'; + head.id = 'activity-monitor-display-head'; + head.innerHTML = ''; + const banner = document.createElement('div'); + banner.className = 'ham-display-stale'; + banner.id = 'activity-monitor-display-stale'; + banner.setAttribute('role', 'status'); + banner.setAttribute('aria-live', 'polite'); + banner.hidden = true; + body.insertBefore(banner, body.firstChild); + body.insertBefore(head, banner); + } + function stageTrackerDisplayTick(nowMs) { + if (!stageTrackerDisplayMode()) return; + const now = typeof nowMs === 'number' ? nowMs : Date.now(); + const d = typeof _stageTracker !== 'undefined' ? _stageTracker : null; + const genAt = Date.parse((d && d.generated_at) || '') || 0; + const ttlMs = (Number(d && d.cache_ttl_s) || 0) * 1000; + // Until the first frame the stream is judged from page load, so a + // display that never connects still goes stale. + const sseAt = (typeof _sseEverFrameAtMs === 'number' && _sseEverFrameAtMs) || _stageTrackerDisplayLoadedAtMs; + const st = stageTrackerDisplayStale(now, sseAt, STAGE_TRACKER_POLL_MS, genAt, ttlMs); + document.body.classList.toggle('display-stale', st.stale); + const banner = document.getElementById('activity-monitor-display-stale'); + if (banner) { + const text = stageTrackerDisplayStaleText(st, now); + if (banner.textContent !== text) banner.textContent = text; + banner.hidden = !st.stale; + } + const head = document.getElementById('activity-monitor-display-head'); + if (head) { + const hive = head.querySelector('.ham-display-hive'); + const id = typeof _stageTrackerPopoutHiveId === 'string' ? _stageTrackerPopoutHiveId : ''; + if (hive && hive.textContent !== id) hive.textContent = id; + const clock = head.querySelector('.ham-display-clock'); + const time = typeof formatDashboardTime === 'function' + ? formatDashboardTime(now, { hour: '2-digit', minute: '2-digit' }, '') + : ''; + if (clock && clock.textContent !== time) clock.textContent = time; + const dot = head.querySelector('.ham-display-dot'); + if (dot) dot.title = st.stale ? stageTrackerDisplayStaleText(st, now) : 'Live'; + } + const roll = typeof versionReadUpgradeProgress === 'function' ? versionReadUpgradeProgress(now) : null; + if (!_stageTrackerDisplayRollReloaded && stageTrackerDisplayRollReload(roll, _stageTrackerDisplayLoadedAtMs)) { + _stageTrackerDisplayRollReloaded = true; + window.location.reload(); + } + } + document.addEventListener('DOMContentLoaded', function() { + if (!stageTrackerDisplayMode()) return; + stageTrackerDisplayMountHead(); + stageTrackerDisplayTick(); + dashboardSetInterval('display-liveness', stageTrackerDisplayTick, STAGE_TRACKER_DISPLAY_TICK_MS); + }); diff --git a/src/pkg/dashboard/static-src/js/tracker-filter-render.js b/src/pkg/dashboard/static-src/js/tracker-filter-render.js index 94c3791ff2..82691100c3 100644 --- a/src/pkg/dashboard/static-src/js/tracker-filter-render.js +++ b/src/pkg/dashboard/static-src/js/tracker-filter-render.js @@ -88,11 +88,16 @@ if (stageTrackerRepoChipOn(stageTrackerRepoChipSetting(), repos.length)) ctx.repoChips = { primary: stageTrackerPrimaryRepo(), active: f.repo }; const visible = stageTrackerVisible(d.items, f, ctx); const ordered = stageTrackerTrainContiguous(stageTrackerSort(visible, stages, f)); - const grouping = _stageTrackerGroup === 'repo'; - const page = grouping - ? stageTrackerGroupPage(stageTrackerGroups(ordered, { primary: stageTrackerPrimaryRepo(), collapsed: _stageTrackerCollapsed, stages }), f) - : stageTrackerPage(ordered, f); - if (page.page !== f.page) f.page = page.page; + // A TV display (display=1&density=tv) shows the rows that fit the + // screen, ungrouped, with "+N more" in place of the pager. + const tv = typeof stageTrackerDisplayTv === 'function' && stageTrackerDisplayTv(); + const grouping = _stageTrackerGroup === 'repo' && !tv; + const page = tv + ? stageTrackerDisplayCapPage(ordered, stageTrackerDisplayTvCap()) + : grouping + ? stageTrackerGroupPage(stageTrackerGroups(ordered, { primary: stageTrackerPrimaryRepo(), collapsed: _stageTrackerCollapsed, stages }), f) + : stageTrackerPage(ordered, f); + if (!tv && page.page !== f.page) f.page = page.page; // The rows this render draws (this page, group headers aside), for // stageTrackerPRListedOwnRow: a covered issue defers to its PR's row // only when that row is actually on screen. Kept beside the payload, @@ -128,8 +133,9 @@ const meta = document.getElementById('activity-monitor-meta'); if (meta) setIfChanged(meta, `${esc(counts.showing)}${stageTrackerEngineHtml(d)}${stageTrackerUpdatedHtml(d, nowMs, _stageTrackerPollError, _stageTrackerPollErrorSince)}${stageTrackerPagerHtml(page)}`); const foot = document.getElementById('activity-monitor-meta-foot'); - if (foot) setIfChanged(foot, page.pages > 1 ? `${esc(counts.showing)}${stageTrackerPagerHtml(page)}` : ''); - const effect = stageTrackerMotionEffect(stageTrackerMotionSetting(), stageTrackerReducedMotion()); + if (foot) setIfChanged(foot, tv ? stageTrackerDisplayMoreHtml(page.more) : page.pages > 1 ? `${esc(counts.showing)}${stageTrackerPagerHtml(page)}` : ''); + let effect = stageTrackerMotionEffect(stageTrackerMotionSetting(), stageTrackerReducedMotion()); + if (typeof stageTrackerDisplayEffect === 'function') effect = stageTrackerDisplayEffect(effect); if (!visible.length && !Object.keys(_stageTrackerCelebrating).length) { _stageTrackerMoves = {}; stageTrackerSelectionSync(el, []); @@ -173,6 +179,7 @@ if (typeof stageTrackerPendingSync === 'function') stageTrackerPendingSync(el); stageTrackerCueAgeSync(el, nowMs); stageTrackerCueTick(); + if (tv) stageTrackerDisplayMeasureRows(el); // Moves play once, on the render that follows the payload; a filter // or paging re-render of the same payload does not replay them. if (Object.keys(_stageTrackerMoves).length) { stageTrackerAnimateMoves(el); _stageTrackerMoves = {}; } diff --git a/src/pkg/dashboard/static-src/js/tracker-motion.js b/src/pkg/dashboard/static-src/js/tracker-motion.js index 4c959bc88f..cced24e16e 100644 --- a/src/pkg/dashboard/static-src/js/tracker-motion.js +++ b/src/pkg/dashboard/static-src/js/tracker-motion.js @@ -625,7 +625,8 @@ // effect the setting picks, unless the tab is hidden or too many moved. function stageTrackerAnimateMoves(root) { if (!root) return 0; - const effect = stageTrackerMotionEffect(stageTrackerMotionSetting(), stageTrackerReducedMotion()); + let effect = stageTrackerMotionEffect(stageTrackerMotionSetting(), stageTrackerReducedMotion()); + if (typeof stageTrackerDisplayEffect === 'function') effect = stageTrackerDisplayEffect(effect); const strips = Array.from(root.querySelectorAll('.ham-strip[data-ham-prev-col]')); const play = !!effect && !document.hidden && strips.length > 0 && strips.length <= STAGE_TRACKER_MOTION_MAX_ROWS; let n = 0; diff --git a/src/pkg/dashboard/static-src/js/tracker-popout.js b/src/pkg/dashboard/static-src/js/tracker-popout.js index 5e78c4bdc2..71b2b00eda 100644 --- a/src/pkg/dashboard/static-src/js/tracker-popout.js +++ b/src/pkg/dashboard/static-src/js/tracker-popout.js @@ -93,13 +93,21 @@ function stageTrackerIsFullscreen() { return !!(document.fullscreenElement && document.fullscreenElement === stageTrackerFullscreenTarget()) && document.body.classList.contains('ham-fullscreen'); } + // body.ham-fullscreen marks browser full screen; body.ham-chromeless is + // the shared chrome-less layout (css/popout.css). Leaving full screen + // keeps the layout when the URL already asks for it (pop-out, display). + function stageTrackerSetFullscreenLayout(on) { + const cl = document.body.classList; + cl.toggle('ham-fullscreen', !!on); + cl.toggle('ham-chromeless', !!on || cl.contains('popout-mode') || cl.contains('display-mode')); + } // Pure: label + title for the ⛶ button given the current state. function stageTrackerFullscreenLabel(isFull) { return isFull ? STAGE_TRACKER_FULLSCREEN_LABELS.exit : STAGE_TRACKER_FULLSCREEN_LABELS.enter; } function stageTrackerRenderFullscreenButton() { // Esc (or the browser) leaving full screen must drop the layout too. - if (!document.fullscreenElement) document.body.classList.remove('ham-fullscreen'); + if (!document.fullscreenElement) stageTrackerSetFullscreenLayout(false); const full = stageTrackerIsFullscreen(); const btn = stageTrackerFullscreenButton(); if (!btn) return; @@ -114,17 +122,17 @@ if (!target) return Promise.resolve(false); let p; if (stageTrackerIsFullscreen()) { - document.body.classList.remove('ham-fullscreen'); + stageTrackerSetFullscreenLayout(false); p = document.exitFullscreen ? document.exitFullscreen() : Promise.resolve(); } else if (target.requestFullscreen) { - document.body.classList.add('ham-fullscreen'); + stageTrackerSetFullscreenLayout(true); p = target.requestFullscreen(); } else { if (typeof showToast === 'function') showToast('This browser does not support full screen here.', 'error'); return Promise.resolve(false); } return Promise.resolve(p).then(() => { stageTrackerRenderFullscreenButton(); return true; }, (err) => { - document.body.classList.remove('ham-fullscreen'); + stageTrackerSetFullscreenLayout(false); stageTrackerRenderFullscreenButton(); if (typeof showToast === 'function') showToast('Full screen was refused: ' + ((err && err.message) || err), 'error'); return false; diff --git a/src/pkg/dashboard/static-src/manifest.txt b/src/pkg/dashboard/static-src/manifest.txt index a30abaa5d1..73d3d76d35 100644 --- a/src/pkg/dashboard/static-src/manifest.txt +++ b/src/pkg/dashboard/static-src/manifest.txt @@ -88,6 +88,7 @@ js/tracker-queue.js js/tracker-sound.js js/tracker-waiting.js js/tracker-popout.js +js/tracker-display.js js/agent-cards.js js/banners.js js/governor-view.js diff --git a/src/pkg/dashboard/static/index.html b/src/pkg/dashboard/static/index.html index 41f50a9656..ca0b0449e9 100644 --- a/src/pkg/dashboard/static/index.html +++ b/src/pkg/dashboard/static/index.html @@ -6818,56 +6818,36 @@ menu, chat FAB or notices, every other section out of flow — but attended: the cursor stays, the gear works, and a ⤶ Return link goes back to the opener. The ⛶ button puts the document into the Fullscreen API and sets - body.ham-fullscreen, which shares every rule below — the document rather - than the section so the body-level toasts (waiting on you, merges) stay - visible while full screen. */ - body.popout-mode, body.ham-fullscreen, - body.display-mode { padding: var(--sp-5) var(--sp-7) var(--sp-7) var(--sp-7); --navbar-sticky-height: 0px; } - body.popout-mode .oc-sidebar, body.popout-mode .oc-sidebar-resize, body.popout-mode .oc-topbar, - body.popout-mode #dash-notices, body.popout-mode #oc-agent-detail, body.popout-mode .hive-chat-fab, - body.popout-mode .hive-chat-panel, body.popout-mode #welcome-overlay, body.popout-mode .nps-card, - body.ham-fullscreen .oc-sidebar, body.ham-fullscreen .oc-sidebar-resize, body.ham-fullscreen .oc-topbar, - body.ham-fullscreen #dash-notices, body.ham-fullscreen #oc-agent-detail, body.ham-fullscreen .hive-chat-fab, - body.ham-fullscreen .hive-chat-panel, - body.display-mode .oc-sidebar, body.display-mode .oc-sidebar-resize, body.display-mode .oc-topbar, - body.display-mode #dash-notices, body.display-mode #oc-agent-detail, body.display-mode .hive-chat-fab, - body.display-mode .hive-chat-panel, body.display-mode #welcome-overlay, body.display-mode .nps-card { display: none !important; } + body.ham-fullscreen — the document rather than the section so the + body-level toasts (waiting on you, merges) stay visible while full screen. + Every chrome-less view (pop-out, full screen, display mode) also carries + body.ham-chromeless, which the shared layout rules below key on, so a new + view adds the class instead of another copy of every selector. */ + body.ham-chromeless { padding: var(--sp-5) var(--sp-7) var(--sp-7) var(--sp-7); --navbar-sticky-height: 0px; } + body.ham-chromeless .oc-sidebar, body.ham-chromeless .oc-sidebar-resize, body.ham-chromeless .oc-topbar, + body.ham-chromeless #dash-notices, body.ham-chromeless #oc-agent-detail, body.ham-chromeless .hive-chat-fab, + body.ham-chromeless .hive-chat-panel { display: none !important; } + /* The welcome tour and NPS card stay in the main window; full screen + keeps them, as it always has. */ + body.popout-mode #welcome-overlay, body.popout-mode .nps-card, + body.display-mode #welcome-overlay, body.display-mode .nps-card { display: none !important; } /* /api/theme.css (theme/theme.go layoutGuardCSS) forces the topbar to display:grid!important with id specificity; beat it with (1,2,2). */ - html body.popout-mode #oc-topbar[id], html body.ham-fullscreen #oc-topbar[id] { display: none !important; } - html body.display-mode #oc-topbar[id] { display: none !important; } - body.popout-mode #hive-dashboard-root > [data-dashboard-section]:not(#activity-monitor-section), - body.ham-fullscreen #hive-dashboard-root > [data-dashboard-section]:not(#activity-monitor-section) { display: none !important; } - body.display-mode #hive-dashboard-root > [data-dashboard-section]:not(#activity-monitor-section) { display: none !important; } - body.popout-mode #activity-monitor-section .dashboard-grip, body.popout-mode #activity-monitor-section .section-chevron, - body.ham-fullscreen #activity-monitor-section .dashboard-grip, body.ham-fullscreen #activity-monitor-section .section-chevron, - body.display-mode #activity-monitor-section .dashboard-grip, body.display-mode #activity-monitor-section .section-chevron { display: none !important; } + html body.ham-chromeless #oc-topbar[id] { display: none !important; } + body.ham-chromeless #hive-dashboard-root > [data-dashboard-section]:not(#activity-monitor-section) { display: none !important; } + body.ham-chromeless #activity-monitor-section .dashboard-grip, body.ham-chromeless #activity-monitor-section .section-chevron { display: none !important; } /* The header cannot collapse the only section on the page, but its gear, full-screen and return buttons must still take clicks. */ - body.popout-mode #activity-monitor-section .section-header-toggle, - body.ham-fullscreen #activity-monitor-section .section-header-toggle, - body.display-mode #activity-monitor-section .section-header-toggle { pointer-events: none; } - body.popout-mode #activity-monitor-section .section-header-toggle button, - body.popout-mode #activity-monitor-section .section-header-toggle .config-info, - body.ham-fullscreen #activity-monitor-section .section-header-toggle button, - body.ham-fullscreen #activity-monitor-section .section-header-toggle .config-info, - body.display-mode #activity-monitor-section .section-header-toggle button, - body.display-mode #activity-monitor-section .section-header-toggle .config-info { pointer-events: auto; } + body.ham-chromeless #activity-monitor-section .section-header-toggle { pointer-events: none; } + body.ham-chromeless #activity-monitor-section .section-header-toggle button, + body.ham-chromeless #activity-monitor-section .section-header-toggle .config-info { pointer-events: auto; } /* A collapsed state saved from the main window would leave an empty page with a header that cannot be clicked: always show the body. */ - body.popout-mode #activity-monitor-section .section-body.collapsed, - body.ham-fullscreen #activity-monitor-section .section-body.collapsed, - body.display-mode #activity-monitor-section .section-body.collapsed { max-height: none !important; opacity: 1; pointer-events: auto; } - body.popout-mode #activity-monitor-section .dash-card.collapsed .dash-card-actions, - body.ham-fullscreen #activity-monitor-section .dash-card.collapsed .dash-card-actions, - body.display-mode #activity-monitor-section .dash-card.collapsed .dash-card-actions { display: inline-flex; } - body.popout-mode #activity-monitor-section .dash-card.collapsed .dash-card-summary, - body.ham-fullscreen #activity-monitor-section .dash-card.collapsed .dash-card-summary, - body.display-mode #activity-monitor-section .dash-card.collapsed .dash-card-summary { display: none; } - body.popout-mode .ham-sticky, body.ham-fullscreen .ham-sticky, - body.display-mode .ham-sticky { top: 0; } - body.popout-mode .ham-cols, body.ham-fullscreen .ham-cols, - body.display-mode .ham-cols { top: var(--ham-sticky-bar-h); } + body.ham-chromeless #activity-monitor-section .section-body.collapsed { max-height: none !important; opacity: 1; pointer-events: auto; } + body.ham-chromeless #activity-monitor-section .dash-card.collapsed .dash-card-actions { display: inline-flex; } + body.ham-chromeless #activity-monitor-section .dash-card.collapsed .dash-card-summary { display: none; } + body.ham-chromeless .ham-sticky { top: 0; } + body.ham-chromeless .ham-cols { top: var(--ham-sticky-bar-h); } /* Header tools: ⧉ pop out, ⛶ full screen and 📺 display sit beside the gear and share its chip styling; the return link is a pop-out-only text pill. */ @@ -6913,6 +6893,60 @@ body.display-mode .ham-playlist-track { display: none; } body.display-mode .ham-playlist-next { display: inline-block; } } + + /* Display liveness (#15930): a header with the hive id, a clock and a + live dot, and — once the stream or the payload goes quiet — a dimmed + board under a "Stale: last update N ago" banner. Display mode only; + the "updated … ago" chip is unchanged everywhere. */ + .ham-display-head, .ham-display-stale { display: none; } + body.display-mode .ham-display-head { display: flex; align-items: center; gap: var(--sp-4); margin-bottom: var(--sp-3); font-size: var(--fs-sm); color: var(--muted); font-variant-numeric: tabular-nums; } + body.display-mode .ham-display-dot { color: var(--green); } + body.display-mode .ham-display-hive { font-weight: 600; color: var(--text); } + body.display-mode .ham-display-clock { margin-left: auto; } + body.display-mode.display-stale .ham-display-dot { color: var(--amber); } + body.display-mode.display-stale .ham-display-stale:not([hidden]) { display: block; margin-bottom: var(--sp-3); padding: var(--sp-2) var(--sp-4); border: var(--line-width) solid var(--amber); border-radius: var(--r-sm); background: color-mix(in srgb, var(--amber) 14%, var(--panel)); color: var(--amber); font-size: var(--fs-md); font-weight: 600; } + body.display-mode #activity-monitor-panel, body.display-mode #activity-monitor-meta, + body.display-mode #activity-monitor-sticky, body.display-mode #activity-monitor-native-queue { transition: opacity .6s ease, filter .6s ease; } + body.display-mode.display-stale #activity-monitor-panel, body.display-mode.display-stale #activity-monitor-meta, + body.display-mode.display-stale #activity-monitor-sticky, body.display-mode.display-stale #activity-monitor-native-queue { opacity: .45; filter: grayscale(.7); } + + /* density=tv (#15931): larger type, only the stage strip, the title and + the stage/actor line, no filters or pager — the rows that fit and a + "+N more" footer (stageTrackerDisplayRowCap). */ + body.display-density-tv #activity-monitor-section { + --fs-2xs: .9rem; + --fs-xs: 1rem; + --fs-sm: 1.15rem; + --fs-base: 1.25rem; + --fs-md: 1.4rem; + } + body.display-density-tv #activity-monitor-toolbar, body.display-density-tv #activity-monitor-labels, + body.display-density-tv #activity-monitor-native-queue, body.display-density-tv #activity-monitor-section .ham-pager, + body.display-density-tv #activity-monitor-section .ham-head-pr, body.display-density-tv #activity-monitor-section .ham-badges, + body.display-density-tv #activity-monitor-section .ham-since, body.display-density-tv #activity-monitor-section [data-ham-sub-key], + body.display-density-tv #activity-monitor-section .cue-event, body.display-density-tv #activity-monitor-section .ham-review-notes { display: none !important; } + body.display-density-tv #activity-monitor-section .ham-head-cols .ham-seg.ham-head-lead { flex: 1 1 0; } + body.display-density-tv .ham-display-more { display: block; text-align: center; font-size: var(--fs-md); font-weight: 600; color: var(--muted); } + + /* shift=1 (#15931): an OLED burn-in shift — the board steps 1–2 px to a + new spot every 4 minutes. Off by default and inert under reduced + motion. */ + @keyframes ham-display-shift { + 0% { transform: translate(0, 0); } + 25% { transform: translate(2px, 1px); } + 50% { transform: translate(1px, 2px); } + 75% { transform: translate(-1px, 1px); } + 100% { transform: translate(0, 0); } + } + body.display-shift #activity-monitor-section { animation: ham-display-shift 16min steps(1, end) infinite; } + + /* Reduced motion on a display: no burn-in shift and no dim transition, + the way the toasts already go linear; row movement is switched off in + JS (stageTrackerDisplayMotionEffect plays no effect at all). */ + @media (prefers-reduced-motion: reduce) { + body.display-shift #activity-monitor-section { animation: none; } + body.display-mode #activity-monitor-panel, body.display-mode #activity-monitor-meta, + body.display-mode #activity-monitor-sticky, body.display-mode #activity-monitor-native-queue { transition: none; } } .var-empty{color:var(--muted);font-size:var(--fs-sm);padding:var(--sp-2) var(--sp-0)} .var-section{margin-top:var(--sp-6);border-top:1px solid var(--border);padding-top:var(--sp-5)} .var-heading{font-weight:600;font-size:var(--fs-sm);margin-bottom:var(--sp-4)} @@ -6957,12 +6991,22 @@ // presentation only: the cursor stays, sound keeps the user's setting, it // never writes layout or theme to localStorage, and it hides the row action // affordances. Kiosk wins when both flags are present. +// Display options (#15931), honoured only together with display=1: +// `density=tv` (the only value; anything else is ignored) sets +// body.display-density-tv, a larger three-column wall layout, and `shift=1` +// sets body.display-shift, an OLED burn-in shift. Without display=1 both are +// ignored, so the ordinary dashboard and kiosk render exactly as before. +// Pop-out and display mode also set body.ham-chromeless, the one class the +// shared chrome-less layout in css/popout.css keys on (full screen adds it at +// runtime); popout-mode and display-mode keep their view-specific rules. (function(){ - var kiosk=false, popout=false, display=false, sound=true; - try { var u=new URL(window.location.href); kiosk=u.searchParams.get('kiosk')==='1'; popout=u.searchParams.get('popout')==='1'; display=u.searchParams.get('display')==='1'; sound=new URL(window.location.href).searchParams.get('sound')!=='off'; } catch(e) {} + var kiosk=false, popout=false, display=false, sound=true, density='', shift=false; + try { var u=new URL(window.location.href); kiosk=u.searchParams.get('kiosk')==='1'; popout=u.searchParams.get('popout')==='1'; display=u.searchParams.get('display')==='1'; density=u.searchParams.get('density')==='tv'?'tv':''; shift=u.searchParams.get('shift')==='1'; sound=new URL(window.location.href).searchParams.get('sound')!=='off'; } catch(e) {} window.HIVE_KIOSK=kiosk; window.HIVE_POPOUT=popout&&!kiosk; window.HIVE_DISPLAY=display&&!kiosk; + window.HIVE_DISPLAY_DENSITY=window.HIVE_DISPLAY?density:''; + window.HIVE_DISPLAY_SHIFT=window.HIVE_DISPLAY&&shift; window.HIVE_KIOSK_SOUND=kiosk&&sound; window.hiveKioskMode=function(){ return !!window.HIVE_KIOSK; }; window.hivePopoutMode=function(){ return !!window.HIVE_POPOUT; }; @@ -6972,12 +7016,16 @@ document.body.classList.add('kiosk-mode'); }else if(window.HIVE_POPOUT){ document.body.classList.add('popout-mode'); + document.body.classList.add('ham-chromeless'); } if(kiosk||window.HIVE_POPOUT){ if(!location.hash) history.replaceState(null,'',location.pathname+location.search+'#section-activity-monitor-section'); } if(window.HIVE_DISPLAY){ document.body.classList.add('display-mode'); + document.body.classList.add('ham-chromeless'); + if(window.HIVE_DISPLAY_DENSITY==='tv') document.body.classList.add('display-density-tv'); + if(window.HIVE_DISPLAY_SHIFT) document.body.classList.add('display-shift'); if(!location.hash) history.replaceState(null,'',location.pathname+location.search+'#section-activity-monitor-section'); } })(); @@ -18713,7 +18761,8 @@

Where to get help

// effect the setting picks, unless the tab is hidden or too many moved. function stageTrackerAnimateMoves(root) { if (!root) return 0; - const effect = stageTrackerMotionEffect(stageTrackerMotionSetting(), stageTrackerReducedMotion()); + let effect = stageTrackerMotionEffect(stageTrackerMotionSetting(), stageTrackerReducedMotion()); + if (typeof stageTrackerDisplayEffect === 'function') effect = stageTrackerDisplayEffect(effect); const strips = Array.from(root.querySelectorAll('.ham-strip[data-ham-prev-col]')); const play = !!effect && !document.hidden && strips.length > 0 && strips.length <= STAGE_TRACKER_MOTION_MAX_ROWS; let n = 0; @@ -20051,11 +20100,16 @@

All labels

if (stageTrackerRepoChipOn(stageTrackerRepoChipSetting(), repos.length)) ctx.repoChips = { primary: stageTrackerPrimaryRepo(), active: f.repo }; const visible = stageTrackerVisible(d.items, f, ctx); const ordered = stageTrackerTrainContiguous(stageTrackerSort(visible, stages, f)); - const grouping = _stageTrackerGroup === 'repo'; - const page = grouping - ? stageTrackerGroupPage(stageTrackerGroups(ordered, { primary: stageTrackerPrimaryRepo(), collapsed: _stageTrackerCollapsed, stages }), f) - : stageTrackerPage(ordered, f); - if (page.page !== f.page) f.page = page.page; + // A TV display (display=1&density=tv) shows the rows that fit the + // screen, ungrouped, with "+N more" in place of the pager. + const tv = typeof stageTrackerDisplayTv === 'function' && stageTrackerDisplayTv(); + const grouping = _stageTrackerGroup === 'repo' && !tv; + const page = tv + ? stageTrackerDisplayCapPage(ordered, stageTrackerDisplayTvCap()) + : grouping + ? stageTrackerGroupPage(stageTrackerGroups(ordered, { primary: stageTrackerPrimaryRepo(), collapsed: _stageTrackerCollapsed, stages }), f) + : stageTrackerPage(ordered, f); + if (!tv && page.page !== f.page) f.page = page.page; // The rows this render draws (this page, group headers aside), for // stageTrackerPRListedOwnRow: a covered issue defers to its PR's row // only when that row is actually on screen. Kept beside the payload, @@ -20091,8 +20145,9 @@

All labels

const meta = document.getElementById('activity-monitor-meta'); if (meta) setIfChanged(meta, `${esc(counts.showing)}${stageTrackerEngineHtml(d)}${stageTrackerUpdatedHtml(d, nowMs, _stageTrackerPollError, _stageTrackerPollErrorSince)}${stageTrackerPagerHtml(page)}`); const foot = document.getElementById('activity-monitor-meta-foot'); - if (foot) setIfChanged(foot, page.pages > 1 ? `${esc(counts.showing)}${stageTrackerPagerHtml(page)}` : ''); - const effect = stageTrackerMotionEffect(stageTrackerMotionSetting(), stageTrackerReducedMotion()); + if (foot) setIfChanged(foot, tv ? stageTrackerDisplayMoreHtml(page.more) : page.pages > 1 ? `${esc(counts.showing)}${stageTrackerPagerHtml(page)}` : ''); + let effect = stageTrackerMotionEffect(stageTrackerMotionSetting(), stageTrackerReducedMotion()); + if (typeof stageTrackerDisplayEffect === 'function') effect = stageTrackerDisplayEffect(effect); if (!visible.length && !Object.keys(_stageTrackerCelebrating).length) { _stageTrackerMoves = {}; stageTrackerSelectionSync(el, []); @@ -20136,6 +20191,7 @@

All labels

if (typeof stageTrackerPendingSync === 'function') stageTrackerPendingSync(el); stageTrackerCueAgeSync(el, nowMs); stageTrackerCueTick(); + if (tv) stageTrackerDisplayMeasureRows(el); // Moves play once, on the render that follows the payload; a filter // or paging re-render of the same payload does not replay them. if (Object.keys(_stageTrackerMoves).length) { stageTrackerAnimateMoves(el); _stageTrackerMoves = {}; } @@ -24842,13 +24898,21 @@

All labels

function stageTrackerIsFullscreen() { return !!(document.fullscreenElement && document.fullscreenElement === stageTrackerFullscreenTarget()) && document.body.classList.contains('ham-fullscreen'); } + // body.ham-fullscreen marks browser full screen; body.ham-chromeless is + // the shared chrome-less layout (css/popout.css). Leaving full screen + // keeps the layout when the URL already asks for it (pop-out, display). + function stageTrackerSetFullscreenLayout(on) { + const cl = document.body.classList; + cl.toggle('ham-fullscreen', !!on); + cl.toggle('ham-chromeless', !!on || cl.contains('popout-mode') || cl.contains('display-mode')); + } // Pure: label + title for the ⛶ button given the current state. function stageTrackerFullscreenLabel(isFull) { return isFull ? STAGE_TRACKER_FULLSCREEN_LABELS.exit : STAGE_TRACKER_FULLSCREEN_LABELS.enter; } function stageTrackerRenderFullscreenButton() { // Esc (or the browser) leaving full screen must drop the layout too. - if (!document.fullscreenElement) document.body.classList.remove('ham-fullscreen'); + if (!document.fullscreenElement) stageTrackerSetFullscreenLayout(false); const full = stageTrackerIsFullscreen(); const btn = stageTrackerFullscreenButton(); if (!btn) return; @@ -24863,17 +24927,17 @@

All labels

if (!target) return Promise.resolve(false); let p; if (stageTrackerIsFullscreen()) { - document.body.classList.remove('ham-fullscreen'); + stageTrackerSetFullscreenLayout(false); p = document.exitFullscreen ? document.exitFullscreen() : Promise.resolve(); } else if (target.requestFullscreen) { - document.body.classList.add('ham-fullscreen'); + stageTrackerSetFullscreenLayout(true); p = target.requestFullscreen(); } else { if (typeof showToast === 'function') showToast('This browser does not support full screen here.', 'error'); return Promise.resolve(false); } return Promise.resolve(p).then(() => { stageTrackerRenderFullscreenButton(); return true; }, (err) => { - document.body.classList.remove('ham-fullscreen'); + stageTrackerSetFullscreenLayout(false); stageTrackerRenderFullscreenButton(); if (typeof showToast === 'function') showToast('Full screen was refused: ' + ((err && err.message) || err), 'error'); return false; @@ -25302,6 +25366,241 @@

All labels

stageTrackerDisplayControlsInit(); stageTrackerPlaylistInit(); }); +/* ---- Display mode: honest liveness and wall layout --------------------- + Rendering-only additions for `?display=1` (body.display-mode, see + boot.js and tracker-popout.js); nothing here runs, or changes a pixel, + on the ordinary Activity Monitor or a headless `?kiosk=1` stream. + Liveness (hivecommons/hive#15930): a 1 s tick dims the board and says + "Stale: last update N ago" once the event stream or the payload goes + quiet, and a display that cannot reconnect reloads itself on a capped + backoff. Layout (hivecommons/hive#15931): `density=tv` keeps the stage, + title and actor at a larger type and caps the rows to the viewport + with a "+N more" footer; `shift=1` is a CSS burn-in shift; reduced + motion turns off row movement. No endpoint, credential or URL knob + beyond `density` and `shift`. */ + + // tracker display liveness helpers begin + const STAGE_TRACKER_DISPLAY_RELOAD_AFTER_FAILS = 5; + const STAGE_TRACKER_DISPLAY_RELOAD_BASE_MS = 30000; + const STAGE_TRACKER_DISPLAY_RELOAD_MAX_MS = 600000; + // Pure: is a display board's data stale? Stale when the event stream has + // been silent for more than two poll intervals, or the payload's + // generated_at is older than two cache TTLs. A zero/absent timestamp is + // "not known yet" and judges nothing. sinceMs is the last update of the + // signal that went quiet (the newer one when both did); reason is + // 'sse', 'ttl' or 'both', '' when fresh. + function stageTrackerDisplayStale(nowMs, sseLastFrameMs, pollMs, generatedAtMs, cacheTtlMs) { + const now = Number(nowMs) || 0; + const sseAt = Number(sseLastFrameMs) || 0; + const genAt = Number(generatedAtMs) || 0; + const poll = Number(pollMs) || 0; + const ttl = Number(cacheTtlMs) || 0; + const sse = sseAt > 0 && poll > 0 && now - sseAt > 2 * poll; + const old = genAt > 0 && ttl > 0 && now - genAt > 2 * ttl; + if (!sse && !old) return { stale: false, sinceMs: 0, reason: '' }; + if (sse && old) return { stale: true, sinceMs: Math.max(sseAt, genAt), reason: 'both' }; + return sse ? { stale: true, sinceMs: sseAt, reason: 'sse' } : { stale: true, sinceMs: genAt, reason: 'ttl' }; + } + // Pure: how long to wait before reloading a display whose stream keeps + // failing — 0 until STAGE_TRACKER_DISPLAY_RELOAD_AFTER_FAILS consecutive + // failed reconnects, then 30 s doubling per reload already tried this + // session (attempt), capped at 10 min. + function stageTrackerDisplayReloadDelayMs(failures, attempt) { + if ((Number(failures) || 0) < STAGE_TRACKER_DISPLAY_RELOAD_AFTER_FAILS) return 0; + const n = Math.min(30, Math.max(0, Math.floor(Number(attempt) || 0))); + return Math.min(STAGE_TRACKER_DISPLAY_RELOAD_MAX_MS, STAGE_TRACKER_DISPLAY_RELOAD_BASE_MS * Math.pow(2, n)); + } + // Pure: should a display reload for this roll record (#15804's + // versionReadUpgradeProgress)? Only for a roll that finished after the + // page loaded, so the reload itself never triggers another. + function stageTrackerDisplayRollReload(roll, loadedAtMs) { + if (!roll || roll.source !== 'roll') return false; + const done = Number(roll.completedAt) || 0; + return done > 0 && done > (Number(loadedAtMs) || 0); + } + // Pure: "45 s", "4 m", "2 h", "3 d" for the stale banner. + function stageTrackerDisplayAgo(ms) { + const s = Math.max(0, Math.floor((Number(ms) || 0) / 1000)); + if (s < 60) return s + ' s'; + if (s < 3600) return Math.floor(s / 60) + ' m'; + if (s < 86400) return Math.floor(s / 3600) + ' h'; + return Math.floor(s / 86400) + ' d'; + } + // Pure: the banner line for a stageTrackerDisplayStale result. + function stageTrackerDisplayStaleText(st, nowMs) { + if (!st || !st.stale) return ''; + return st.sinceMs ? 'Stale: last update ' + stageTrackerDisplayAgo(nowMs - st.sinceMs) + ' ago' : 'Stale: no update yet'; + } + // tracker display liveness helpers end + + // tracker display layout helpers begin + const STAGE_TRACKER_DISPLAY_TV = 'tv'; + const STAGE_TRACKER_DISPLAY_TV_ROW_PX = 96; + const STAGE_TRACKER_DISPLAY_TV_FOOT_PX = 48; + // Pure: how many rows fit a TV display — the viewport less everything + // above the rows (and the footer), over one row's height. At least one + // row, and one when the sizes are not known yet. + function stageTrackerDisplayRowCap(viewportPx, headerPx, rowPx) { + const v = Number(viewportPx), r = Number(rowPx); + const h = Math.max(0, Number(headerPx) || 0); + if (!(v > 0) || !(r > 0)) return 1; + return Math.max(1, Math.floor((v - h) / r)); + } + // Pure: a page-shaped slice of the first `cap` rows with no pager + // (pages 1) and `more` = the rows that did not fit. + function stageTrackerDisplayCapPage(rows, cap) { + const all = Array.isArray(rows) ? rows : []; + const n = Math.max(1, Math.floor(Number(cap) || 1)); + const shown = all.slice(0, n); + return { rows: shown, page: 1, pages: 1, from: shown.length ? 1 : 0, to: shown.length, total: all.length, size: n, more: all.length - shown.length }; + } + // Pure: the "+N more" footer that replaces the pager on a TV display. + function stageTrackerDisplayMoreHtml(more) { + const n = Math.max(0, Math.floor(Number(more) || 0)); + return n ? `+${n} more` : ''; + } + // Pure: the row-motion effect for a render — none at all on a display + // under prefers-reduced-motion, unchanged everywhere else. + function stageTrackerDisplayMotionEffect(effect, display, reduced) { + return display && reduced ? '' : effect; + } + // tracker display layout helpers end + + function stageTrackerDisplayTv() { + return stageTrackerDisplayMode() && window.HIVE_DISPLAY_DENSITY === STAGE_TRACKER_DISPLAY_TV; + } + function stageTrackerDisplayEffect(effect) { + const reduced = typeof stageTrackerReducedMotion === 'function' && stageTrackerReducedMotion(); + return stageTrackerDisplayMotionEffect(effect, stageTrackerDisplayMode(), reduced); + } + + // -- TV density: rows capped to the viewport --------------------------- + var _stageTrackerDisplayRowPx = 0; + var _stageTrackerDisplayCap = 0; + function stageTrackerDisplayTvCap() { + const panel = document.getElementById('activity-monitor-panel'); + const cols = panel && panel.querySelector('.ham-cols'); + const top = panel ? panel.getBoundingClientRect().top + (window.scrollY || 0) : 0; + const head = cols ? cols.getBoundingClientRect().height : 0; + _stageTrackerDisplayCap = stageTrackerDisplayRowCap(window.innerHeight, top + head + STAGE_TRACKER_DISPLAY_TV_FOOT_PX, _stageTrackerDisplayRowPx || STAGE_TRACKER_DISPLAY_TV_ROW_PX); + return _stageTrackerDisplayCap; + } + // After a TV render: measure the real row pitch and render again once if + // the estimate fitted a different number of rows. + function stageTrackerDisplayMeasureRows(el) { + if (!el || !stageTrackerDisplayTv()) return; + const rows = el.querySelectorAll('.ham-row'); + if (!rows.length) return; + const a = rows[0].getBoundingClientRect(); + const px = rows.length > 1 ? rows[1].getBoundingClientRect().top - a.top : a.height; + if (!(px > 0) || Math.abs(px - _stageTrackerDisplayRowPx) < 1) return; + _stageTrackerDisplayRowPx = px; + const before = _stageTrackerDisplayCap; + if (stageTrackerDisplayTvCap() !== before) requestAnimationFrame(function() { renderStageTracker(); }); + } + var _stageTrackerDisplayResizeTimer = null; + window.addEventListener('resize', function() { + if (!stageTrackerDisplayTv()) return; + clearTimeout(_stageTrackerDisplayResizeTimer); + _stageTrackerDisplayResizeTimer = setTimeout(function() { renderStageTracker(); }, 150); + }); + + // -- Liveness: stale dimming, header and self-recovery ------------------ + const STAGE_TRACKER_DISPLAY_TICK_MS = 1000; + const STAGE_TRACKER_DISPLAY_RELOAD_KEY = 'hive-display-reload-attempt'; + var _stageTrackerDisplayLoadedAtMs = Date.now(); + var _stageTrackerDisplayFails = 0; + var _stageTrackerDisplayReloadTimer = null; + var _stageTrackerDisplayAttemptCleared = false; + var _stageTrackerDisplayRollReloaded = false; + function stageTrackerDisplaySessionGet(key) { + try { return sessionStorage.getItem(key) || ''; } catch { return ''; } + } + function stageTrackerDisplaySessionSet(key, value) { + try { if (value === null) sessionStorage.removeItem(key); else sessionStorage.setItem(key, value); } catch {} + } + // sse-bootstrap.js: the stream's onerror. Consecutive failures past the + // threshold schedule one reload; the URL (and so the view) survives it. + function stageTrackerDisplayNoteReconnectFailed() { + if (!stageTrackerDisplayMode()) return; + _stageTrackerDisplayFails++; + if (_stageTrackerDisplayReloadTimer) return; + const attempt = Number(stageTrackerDisplaySessionGet(STAGE_TRACKER_DISPLAY_RELOAD_KEY)) || 0; + const delay = stageTrackerDisplayReloadDelayMs(_stageTrackerDisplayFails, attempt); + if (!delay) return; + _stageTrackerDisplayReloadTimer = setTimeout(function() { + stageTrackerDisplaySessionSet(STAGE_TRACKER_DISPLAY_RELOAD_KEY, String(attempt + 1)); + window.location.reload(); + }, delay); + } + // sse-bootstrap.js: any frame. A live stream cancels a pending reload + // and resets the backoff. + function stageTrackerDisplayNoteFrame() { + if (!_stageTrackerDisplayFails && !_stageTrackerDisplayReloadTimer && _stageTrackerDisplayAttemptCleared) return; + _stageTrackerDisplayFails = 0; + if (_stageTrackerDisplayReloadTimer) { clearTimeout(_stageTrackerDisplayReloadTimer); _stageTrackerDisplayReloadTimer = null; } + if (!stageTrackerDisplayMode()) return; + _stageTrackerDisplayAttemptCleared = true; + stageTrackerDisplaySessionSet(STAGE_TRACKER_DISPLAY_RELOAD_KEY, null); + } + function stageTrackerDisplayMountHead() { + const body = document.querySelector('#activity-monitor-section .section-body'); + if (!body || document.getElementById('activity-monitor-display-head')) return; + const head = document.createElement('div'); + head.className = 'ham-display-head'; + head.id = 'activity-monitor-display-head'; + head.innerHTML = ''; + const banner = document.createElement('div'); + banner.className = 'ham-display-stale'; + banner.id = 'activity-monitor-display-stale'; + banner.setAttribute('role', 'status'); + banner.setAttribute('aria-live', 'polite'); + banner.hidden = true; + body.insertBefore(banner, body.firstChild); + body.insertBefore(head, banner); + } + function stageTrackerDisplayTick(nowMs) { + if (!stageTrackerDisplayMode()) return; + const now = typeof nowMs === 'number' ? nowMs : Date.now(); + const d = typeof _stageTracker !== 'undefined' ? _stageTracker : null; + const genAt = Date.parse((d && d.generated_at) || '') || 0; + const ttlMs = (Number(d && d.cache_ttl_s) || 0) * 1000; + // Until the first frame the stream is judged from page load, so a + // display that never connects still goes stale. + const sseAt = (typeof _sseEverFrameAtMs === 'number' && _sseEverFrameAtMs) || _stageTrackerDisplayLoadedAtMs; + const st = stageTrackerDisplayStale(now, sseAt, STAGE_TRACKER_POLL_MS, genAt, ttlMs); + document.body.classList.toggle('display-stale', st.stale); + const banner = document.getElementById('activity-monitor-display-stale'); + if (banner) { + const text = stageTrackerDisplayStaleText(st, now); + if (banner.textContent !== text) banner.textContent = text; + banner.hidden = !st.stale; + } + const head = document.getElementById('activity-monitor-display-head'); + if (head) { + const hive = head.querySelector('.ham-display-hive'); + const id = typeof _stageTrackerPopoutHiveId === 'string' ? _stageTrackerPopoutHiveId : ''; + if (hive && hive.textContent !== id) hive.textContent = id; + const clock = head.querySelector('.ham-display-clock'); + const time = typeof formatDashboardTime === 'function' + ? formatDashboardTime(now, { hour: '2-digit', minute: '2-digit' }, '') + : ''; + if (clock && clock.textContent !== time) clock.textContent = time; + const dot = head.querySelector('.ham-display-dot'); + if (dot) dot.title = st.stale ? stageTrackerDisplayStaleText(st, now) : 'Live'; + } + const roll = typeof versionReadUpgradeProgress === 'function' ? versionReadUpgradeProgress(now) : null; + if (!_stageTrackerDisplayRollReloaded && stageTrackerDisplayRollReload(roll, _stageTrackerDisplayLoadedAtMs)) { + _stageTrackerDisplayRollReloaded = true; + window.location.reload(); + } + } + document.addEventListener('DOMContentLoaded', function() { + if (!stageTrackerDisplayMode()) return; + stageTrackerDisplayMountHead(); + stageTrackerDisplayTick(); + dashboardSetInterval('display-liveness', stageTrackerDisplayTick, STAGE_TRACKER_DISPLAY_TICK_MS); + }); function parseCadenceMinutes(cadence) { if (!cadence || cadence === 'paused' || cadence === 'off' || cadence === 'on demand') return 0; const m = cadence.match(/^(\d+)(m|h)$/); @@ -49302,7 +49601,14 @@

Configure LiteLLM

var _eventSourceReconnectTimer = null; var _sseLastFrameAtMs = 0; var _sseOpenedAtMs = 0; - function noteSSEFrame() { _sseLastFrameAtMs = Date.now(); } + // The newest frame ever seen; unlike _sseLastFrameAtMs a reconnect does + // not reset it, so display mode can say how long the stream has been + // quiet (tracker-display.js). + var _sseEverFrameAtMs = 0; + function noteSSEFrame() { + _sseLastFrameAtMs = _sseEverFrameAtMs = Date.now(); + if (typeof stageTrackerDisplayNoteFrame === 'function') stageTrackerDisplayNoteFrame(); + } // sseWatchdogTick recycles a silent stream (see sseStreamIdle). `force` // (tab became visible again) always refetches /api/status: Safari and // Chrome throttle hidden-tab timers to once a minute or less, so the tick @@ -49438,6 +49744,7 @@

Configure LiteLLM

} source.close(); if (_eventSource === source) _eventSource = null; + if (typeof stageTrackerDisplayNoteReconnectFailed === 'function') stageTrackerDisplayNoteReconnectFailed(); if (!_eventSourceReconnectTimer) { _eventSourceReconnectTimer = setTimeout(function() { _eventSourceReconnectTimer = null; connect(); }, 3000); }