dashboard: stream the running rebuild's build log inline in the queue

The C0R3 rebuild queue only linked out to the logs page (logs →). Add an
inline live-log panel under the queue that streams the currently-running
rebuild's build output, so the operator watches progress without leaving the
page.

Extract the build-log SSE streaming logic (append stdout/stderr, sticky-bottom
scroll, stderr separator, reconnect-replay reset, done/error handling) into a
shared `openBuildLogStream(id, pre, {onDone, onError})` in common.js, and use it
from BOTH the L0GS page BUILD tab (logs.js, previously inline) and the new C0R3
panel (core.js) — one implementation, no duplication.

The panel is one persistent instance keyed to the running entry's build_log_id
(the queue runs one build at a time), in its own container (#rebuild-live-log)
outside rebuild-queue-section so the queue's per-row re-render — rows rebuild as
the build step advances — never tears down the open stream; it reconnects only
when the running build_log_id changes and won't reopen a stream that already
sent done. Collapsible, live/ok/fail badge, raw download. Hidden when nothing
is building; each row keeps its logs → link for full history.

Frontend-only — no backend change (endpoint + build_log_id already existed).
Closes #1860.
This commit is contained in:
iris 2026-06-22 01:55:38 +02:00
commit e797b75ca9
3 changed files with 79 additions and 78 deletions

View file

@ -11,7 +11,7 @@
// dashboard SYST3M tab); the dashboard keeps its own copies for now —
// de-duplication + removing the SYST3M tab is a deliberate follow-up.
import { $, el, form, openStream, initServerWarnings, bindAsyncForms } from './common.js';
import { $, el, form, openStream, openBuildLogStream, initServerWarnings, bindAsyncForms } from './common.js';
import { fmtAgo, fmtElapsed, truncate } from './util.js';
import { createTabStrip } from '@hive/shared/tabs.js';
@ -369,45 +369,24 @@ function renderRebuildLiveLog(queue) {
);
root.append(header, pre);
// Sticky-bottom: auto-scroll to bottom on new lines unless the operator
// scrolled up (track intent via the scroll event — same as the logs page).
let atBottom = true;
pre.addEventListener('scroll', () => {
atBottom = pre.scrollHeight - pre.scrollTop - pre.clientHeight < 40;
});
let stderrSeen = false;
const es = new EventSource('/api/build-logs/id/' + running.build_log_id + '/stream');
liveLogEs = es;
es.onmessage = (ev) => {
let frame;
try { frame = JSON.parse(ev.data); } catch { return; }
if (frame.stdout_append) {
pre.textContent += frame.stdout_append;
if (atBottom) pre.scrollTop = pre.scrollHeight;
}
if (frame.stderr_append) {
if (!stderrSeen) { pre.textContent += '\n--- stderr ---\n'; stderrSeen = true; }
pre.textContent += frame.stderr_append;
if (atBottom) pre.scrollTop = pre.scrollHeight;
}
if (frame.done) {
// Stream via the shared helper (same path the L0GS BUILD tab uses). It owns
// the append / sticky-scroll / stderr-separator / reconnect-replay logic; we
// just wire the badge. onDone keeps liveLogId + liveLogDone set so a
// re-render before the entry leaves 'running' won't reopen the finished
// stream — the next render with no running entry clears the panel.
liveLogEs = openBuildLogStream(running.build_log_id, pre, {
onDone: (status) => {
liveLogDone = true;
badge.className = 'rebuild-live-log-badge '
+ (frame.status === 'ok' ? 'rll-ok' : 'rll-fail');
badge.textContent = frame.status || 'done';
if (es === liveLogEs) { es.close(); liveLogEs = null; }
// Keep liveLogId + liveLogDone so a re-render before the entry leaves
// 'running' doesn't reopen the finished stream; the next render with no
// running entry clears the panel.
}
};
es.onerror = () => {
if (es.readyState === EventSource.CONNECTING) return; // transient reconnect
badge.className = 'rebuild-live-log-badge rll-fail';
badge.textContent = 'stream error';
if (es === liveLogEs) { es.close(); liveLogEs = null; }
};
badge.className = 'rebuild-live-log-badge ' + (status === 'ok' ? 'rll-ok' : 'rll-fail');
badge.textContent = status;
liveLogEs = null;
},
onError: () => {
badge.className = 'rebuild-live-log-badge rll-fail';
badge.textContent = 'stream error';
liveLogEs = null;
},
});
}
// ─── kept state (tombstones) ──────────────────────────────────────────────