dashboard: add hive infra containers to the logs UI agent selector

Extends GET /api/journal/{name} to also accept the four hive infra
container names (hive-ci, hive-forge, hive-gateway, hive-matrix —
hive_priv_sock::InfraContainer is the allowlist), reusing the same
journalctl -M / hive-priv delegation path already used for agent
containers. Infra containers don't run the per-agent hive daemons, so
the unit filter is skipped for them — always the full machine journal.

Frontend: the AGENT tab's agent selector now lists infra containers
in a separate optgroup (sourced from /api/state's existing
infra_containers field), and disables the unit-filter select when one
is chosen.
This commit is contained in:
iris 2026-07-18 16:28:31 +02:00 committed by mara
commit 66c715842f
2 changed files with 66 additions and 10 deletions

View file

@ -45,8 +45,15 @@ import { createTabStrip } from '@hive/shared/tabs.js';
return 'fetched ' + (ageSecs < 5 ? 'just now' : fmtAgeSecs(ageSecs) + ' ago');
}
// Populate agent selector from /api/state, then honour any `?agent=` /
// `?unit=` URL params (used by the per-agent ⋮ menu's deep-link).
// Names from `state.infra_containers` (hive-ci / hive-forge / hive-gateway
// / hive-matrix) — kept in sync with the fetched list so fetchAgent() can
// tell an infra container apart from an agent and skip the (inapplicable)
// unit filter for it.
let infraContainerNames = new Set();
// Populate agent selector from /api/state (agents, then the four infra
// containers in their own optgroup), then honour any `?agent=` / `?unit=`
// URL params (used by the per-agent ⋮ menu's deep-link).
async function loadAgentList() {
try {
const resp = await fetch('/api/state');
@ -58,6 +65,14 @@ import { createTabStrip } from '@hive/shared/tabs.js';
for (const c of (state.containers || [])) {
agentSelect.append(el('option', { value: c.name }, c.name));
}
infraContainerNames = new Set((state.infra_containers || []).map((c) => c.name));
if (infraContainerNames.size) {
const infraGroup = el('optgroup', { label: 'infra' });
for (const name of infraContainerNames) {
infraGroup.append(el('option', { value: name }, name));
}
agentSelect.append(infraGroup);
}
// Deep-link: honour ?agent= and ?unit= URL params.
const urlAgent = new URLSearchParams(location.search).get('agent');
const urlUnit = new URLSearchParams(location.search).get('unit');
@ -70,12 +85,24 @@ import { createTabStrip } from '@hive/shared/tabs.js';
.some((o) => o.value === urlUnit);
if (unitFound) agentUnitSelect.value = urlUnit;
}
syncUnitSelectForSelection();
fetchAgent();
}
}
} catch { /**/ }
}
// Infra containers don't run the per-agent hive daemons, so the unit
// filter is meaningless for them — disable the selector and always fetch
// the full machine journal to avoid a picked unit silently doing nothing.
function syncUnitSelectForSelection() {
if (!agentUnitSelect) return;
const isInfra = infraContainerNames.has(agentSelect ? agentSelect.value : '');
agentUnitSelect.disabled = isInfra;
if (isInfra) agentUnitSelect.value = '';
}
if (agentSelect) agentSelect.addEventListener('change', syncUnitSelectForSelection);
let agentFetching = false;
let agentLastFetch = 0;
async function fetchAgent() {
@ -86,7 +113,8 @@ import { createTabStrip } from '@hive/shared/tabs.js';
agentFetching = true;
agentOutput.textContent = 'fetching…';
if (agentFetchTs) agentFetchTs.hidden = true;
const unit = agentUnitSelect ? agentUnitSelect.value : '';
const isInfra = infraContainerNames.has(name);
const unit = (!isInfra && agentUnitSelect) ? agentUnitSelect.value : '';
const params = new URLSearchParams({ lines: '500' });
if (unit) params.set('unit', unit);
try {