Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/changed-progressive-dashboard-loading.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Show the dashboard shell before downloading its cacheable application script, prioritize the selected and visible panels, limit background refresh concurrency, and progressively render the latest live data without waiting for every panel before restoring navigation.
2 changes: 1 addition & 1 deletion src/docs/api-reference/snapshots-and-style.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Part of the [Dashboard REST API reference](../api-reference.md); see that page f
| Method | Path | Auth | Purpose | Source |
|---|---|---|---|---|
| `GET` | `/api/style` | Public | Sanitized custom dashboard CSS | `pkg/dashboard/api.go:46` |
| `GET` | `/branding/custom.css` | Dashboard auth/session | Operator branding stylesheet override, read per request (see [branding](../branding.md)) | `pkg/dashboard/server.go:1726` |
| `GET` | `/branding/custom.css` | Dashboard auth/session | Operator branding stylesheet override, read per request (see [branding](../branding.md)) | `pkg/dashboard/server.go:1733` |
| `GET` | `/api/snapshot/frame-ancestors` | Public | Snapshot framing allowlist | `pkg/dashboard/api.go:82` |
| `GET` | `/api/snapshot` | Public | Snapshot data | `pkg/dashboard/api.go:83` |
| `GET` | `/snapshot` | Public | Public read-only snapshot page | `pkg/dashboard/api.go:84` |
2 changes: 1 addition & 1 deletion src/pkg/dashboard/deferred_init_promise_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ func TestDeferredInitGuardsCoverEveryEntry(t *testing.T) {
// Count TOP-LEVEL entries only: one per line, at the array's indentation.
// Counting every `() =>` in the block would also count the nested arrows
// inside each entry's own .then chains.
entryLine := regexp.MustCompile(`(?m)^\s+\(\)\s*=>`)
entryLine := regexp.MustCompile(`(?m)^\s+\['[^']+',\s*\(\)\s*=>`)
entries := len(entryLine.FindAllString(block, -1))
matched := len(deferredEntryCall.FindAllString(block, -1))
if entries == 0 {
Expand Down
3 changes: 2 additions & 1 deletion src/pkg/dashboard/pr_throughput_ui_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ func TestPRThroughputCardPinned(t *testing.T) {
"function prtWindowLabel",
"dto.recorded_since",
"of recorded history",
"fetchPRThroughput(); fetchApprovals();",
"['pr-throughput', fetchPRThroughput]",
"['approvals', fetchApprovals]",
"'governor','pr-throughput-section','repos-section',",
} {
if !strings.Contains(html, snippet) {
Expand Down
366 changes: 366 additions & 0 deletions src/pkg/dashboard/progressive_loading.test.js

Large diffs are not rendered by default.

16 changes: 16 additions & 0 deletions src/pkg/dashboard/progressive_loading_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package dashboard

import (
"os/exec"
"testing"
)

func TestDashboardProgressiveLoading(t *testing.T) {
node, err := exec.LookPath("node")
if err != nil {
t.Skip("node not on PATH — progressive dashboard behavior not executed")
}
if out, err := exec.Command(node, "--test", "progressive_loading.test.js").CombinedOutput(); err != nil {
t.Fatalf("progressive dashboard behavior failed: %v\n%s", err, out)
}
}
2 changes: 1 addition & 1 deletion src/pkg/dashboard/review_queue_view_9607_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func TestReviewQueueViewStaticWiring(t *testing.T) {
`reviewEvidenceButtonHtml(e.repo, e.number) +`,
`function reviewEvidenceButtonHtml(repo, number)`,
`data-action="openReviewEvidence"`,
`() => fetchReviewQueue().then(() => { dashboardSetInterval('review-queue', fetchReviewQueue, REVIEW_QUEUE_POLL_MS); }),`,
`['review-queue', () => fetchReviewQueue().then(() => { dashboardSetInterval('review-queue', fetchReviewQueue, REVIEW_QUEUE_POLL_MS); })],`,
} {
if !strings.Contains(html, want) {
t.Errorf("index.html is missing review-queue wiring %q", want)
Expand Down
22 changes: 16 additions & 6 deletions src/pkg/dashboard/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -1686,13 +1686,12 @@ func (s *Server) Start() error {
if err != nil {
return fmt.Errorf("loading embedded static files: %w", err)
}
// The SPA document gets a dedicated handler with a strong ETag and one-time
// gzip cache (see pkg/dashboard/webstatic): http.FileServer would serve the
// ~1.3 MB inline document uncompressed with no cache validators (embed.FS
// has a zero ModTime, so not even Last-Modified), forcing a full re-download
// on every visit. "/{$}" matches the root path exactly; every other static
// path falls through to the revalidating file server below.
// The SPA shell and content-addressed main script get dedicated ETag/gzip
// handlers. The generated monolith remains embedded for source consumers;
// extraction happens after all startup injections. "/{$}" matches the root
// exactly; other static paths use the revalidating file server below.
var idx *webstatic.IndexDocument
var mainScript *webstatic.DashboardScript
if rawIndex, err := fs.ReadFile(staticContent, "index.html"); err == nil {
// Strings are baked in ONCE here, unlike custom.css which is read per
// request: the document carries a strong ETag and one immutable gzip
Expand All @@ -1703,6 +1702,14 @@ func (s *Server) Start() error {
// The kiosk call-to-action badge (#16236) is baked in the same way:
// its QR code and copy are static per process.
branded = kioskcta.Inject(branded, s.kioskCTAOptions())
branded, mainScript = webstatic.ExternalizeDashboardScript(branded)
if mainScript != nil {
// Keep registration statically discoverable by route parity checks;
// the handler serves only its exact content-addressed path.
s.mux.Handle("GET /assets/{script}", mainScript)
} else {
s.logger.Warn("dashboard main script extraction unavailable; serving original inline dashboard")
}
idx = webstatic.NewIndexDocument(branded)
// Hand the FINAL served bytes to the CSP layer explicitly, rather than
// having the document constructor reach out and set global state:
Expand Down Expand Up @@ -1750,6 +1757,9 @@ func (s *Server) Start() error {
// answer even when a saturated node is slow to build the static cache.
go idx.Precompress()
}
if mainScript != nil {
go mainScript.Precompress()
}
// Viewer-independent cost sampling (#13483); the ring's throttle is the
// same interval, so this is exactly one snapshot per period.
costTicker := time.NewTicker(costHistoryMinIntervalMs * time.Millisecond)
Expand Down
2 changes: 1 addition & 1 deletion src/pkg/dashboard/static-src/js/agent-detail.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@
document.querySelectorAll('.oc-nav-item').forEach(i => i.classList.remove('active'));
const active = document.querySelector(`.oc-nav-item[data-agent-nav="${(window.CSS && CSS.escape) ? CSS.escape(name) : String(name).replace(/["\\]/g, '\\$&')}"]`);
if (active) active.classList.add('active');
if (typeof dashboardProgressiveWake === 'function') dashboardProgressiveWake();
navPeekRestore('agents-section', { instant: true });
const expanded = navPeekExpand('agents-section');
if (!expanded && isSectionCollapsed('agents-section')) toggleSection('agents-section', { collapsed: false, persist: false, navPeek: true });
Expand Down Expand Up @@ -934,4 +935,3 @@
// Agent descriptions now come from the JSON status payload (agent.description field).
// This empty map serves as a fallback for agents without a description in config.
const AGENT_DESCRIPTIONS = {};

11 changes: 8 additions & 3 deletions src/pkg/dashboard/static-src/js/approvals.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,13 @@

// Prime both panels and poll them on a modest independent interval. Do not
// block initial paint: these run after the main poll is already wired.
function v4RefreshPanels() { fetchHiveAdvice(); fetchACMMReco(); fetchLifecycle(); fetchPRThroughput(); fetchApprovals(); }
function v4RefreshPanels() {
[['hive-advice', fetchHiveAdvice], ['acmm-reco', fetchACMMReco],
['lifecycle', fetchLifecycle], ['pr-throughput', fetchPRThroughput],
['approvals', fetchApprovals]].forEach(function([key, fn]) {
dashboardScheduleWork(key, fn).catch(console.error);
});
}
v4RefreshPanels();
dashboardSetInterval('v4-panels', v4RefreshPanels, V4_PANELS_POLL_MS);

Expand Down Expand Up @@ -193,7 +199,7 @@
}
} catch (_) { /* dashboard unreachable — different problem */ }
}
checkGhAuth();
dashboardScheduleWork('gh-auth-banner', checkGhAuth).catch(console.error);
dashboardSetInterval('gh-auth-banner', checkGhAuth, GH_AUTH_POLL_MS);

function renderGhRateLimits(ghRateLimits) {
Expand Down Expand Up @@ -305,4 +311,3 @@
function setIfChanged(el, html) {
if (el.innerHTML !== html) el.innerHTML = html;
}

6 changes: 3 additions & 3 deletions src/pkg/dashboard/static-src/js/backends-tokens.js
Original file line number Diff line number Diff line change
Expand Up @@ -392,11 +392,11 @@
return INFERENCE_MODELS[backend] || [];
}
}
function refreshBackendDiscovery(force) {
INFERENCE_BACKENDS.forEach(b => fetchInferenceModels(b, force));
async function refreshBackendDiscovery(force) {
for (const backend of INFERENCE_BACKENDS) await fetchInferenceModels(backend, force);
// Load configured gateway names so the backend/method pickers list them
// (e.g. openrouter) alongside KNOWN_BACKENDS after the first paint.
fetchConfiguredGateways();
await fetchConfiguredGateways();
}

const CLI_MODEL_CACHE_TTL_MS = 30000;
Expand Down
6 changes: 1 addition & 5 deletions src/pkg/dashboard/static-src/js/boot.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Apply layout immediately and hide content until first data render.
// Apply layout immediately; keep the shell visible while live data loads.
// NOTE: only body classes are set here — the .layout-toggle buttons do NOT
// exist in the DOM yet at this point, so any label write here is a no-op.
// applyLayout() (defined in the main script) is the single source of truth
Expand Down Expand Up @@ -84,9 +84,6 @@
if(window.HIVE_KIOSK){ var kt=null; try { kt=new URL(window.location.href).searchParams.get('theme'); } catch(e) {} m=(kt==='light')?'light':'dark'; }
if(!m)m='light';
if(m==='light'){document.body.classList.add('light-mode')}
document.body.style.opacity='0';
document.body.style.transition='opacity 0.15s ease-in';
setTimeout(function(){ document.body.style.opacity='1'; }, 3000);
document.addEventListener('DOMContentLoaded', function(){
if (typeof applyLayout === 'function' && typeof getLayout === 'function') {
applyLayout(getLayout());
Expand Down Expand Up @@ -171,4 +168,3 @@
document.addEventListener('DOMContentLoaded', renderStyleState);
}
})();

5 changes: 2 additions & 3 deletions src/pkg/dashboard/static-src/js/chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -468,8 +468,8 @@
chatInput.value = localStorage.getItem(CHAT_DRAFT_KEY) || '';
renderChatCheatsheet();
renderChatSuggestions();
detectChatCapabilities();
refreshChatPresence();
dashboardScheduleWork('chat-capabilities', detectChatCapabilities).catch(console.error);
dashboardScheduleWork('chat-presence', refreshChatPresence).catch(console.error);
dashboardSetInterval('chat-presence', refreshChatPresence, 30000);

chatFab.onclick = () => {
Expand Down Expand Up @@ -595,4 +595,3 @@
handle.classList.remove('dragging');
});
})();

3 changes: 1 addition & 2 deletions src/pkg/dashboard/static-src/js/config-governor.js
Original file line number Diff line number Diff line change
Expand Up @@ -1590,7 +1590,7 @@
}
return _statSources;
}
ensureStatSources();
dashboardScheduleWork('stat-sources', ensureStatSources).catch(console.error);

/* statSourcesForDialog returns the source catalogue for the agent the
config dialog is showing. The agent config response carries a catalogue
Expand Down Expand Up @@ -1802,4 +1802,3 @@
<span style="opacity:0.8">— fixed progression; the last step is the cap.</span>
</div>`;
}

3 changes: 1 addition & 2 deletions src/pkg/dashboard/static-src/js/cost.js
Original file line number Diff line number Diff line change
Expand Up @@ -707,6 +707,5 @@
renderCost(cost);
} catch (e) { /* transient — leave last render in place */ }
}
fetchCost();
dashboardScheduleWork('cost', fetchCost).catch(console.error);
dashboardSetInterval('cost', fetchCost, COST_POLL_MS);

16 changes: 12 additions & 4 deletions src/pkg/dashboard/static-src/js/history-sparklines.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,28 @@
}
function dashboardSetInterval(key, fn, ms) {
dashboardClearInterval(key);
const entry = { fn, ms, timer: null };
const entry = { key, fn, ms, timer: null };
DASHBOARD_INTERVALS[key] = entry;
if (!document.hidden) dashboardStartInterval(entry);
return entry;
}
function dashboardStartInterval(entry) {
entry.timer = setInterval(entry.fn, entry.ms);
entry.timer = setInterval(function() {
try { Promise.resolve(dashboardRunInterval(entry)).catch(console.error); } catch (err) { console.error(err); }
}, entry.ms);
}
function dashboardClearInterval(key) {
if (!DASHBOARD_INTERVALS[key]) return;
clearInterval(DASHBOARD_INTERVALS[key].timer);
delete DASHBOARD_INTERVALS[key];
}
function dashboardRunInterval(entry) {
if (typeof dashboardScheduleWork === 'function' &&
Object.prototype.hasOwnProperty.call(DASHBOARD_TASK_SECTIONS, entry.key)) {
return dashboardScheduleWork(entry.key, entry.fn);
}
return entry.fn();
}
document.addEventListener('visibilitychange', () => {
for (const [key, entry] of Object.entries(DASHBOARD_INTERVALS)) {
if (DASHBOARD_INTERVALS[key] !== entry) continue;
Expand All @@ -43,7 +52,7 @@
// A refresh failure must not prevent the other panels from resuming.
// Snapshot iteration also permits a callback to clear/replace itself.
if (DASHBOARD_INTERVALS[key] === entry) {
try { Promise.resolve(entry.fn()).catch(console.error); } catch (err) { console.error(err); }
try { Promise.resolve(dashboardRunInterval(entry)).catch(console.error); } catch (err) { console.error(err); }
}
}
});
Expand Down Expand Up @@ -493,4 +502,3 @@
capHistory(historyData);
}
}

2 changes: 1 addition & 1 deletion src/pkg/dashboard/static-src/js/layout.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading