remove the 1NFR4 dashboard panel and the now-writer-less audit log
This commit is contained in:
parent
c3cd36bc41
commit
22adfd1451
21 changed files with 61 additions and 983 deletions
|
|
@ -5,7 +5,7 @@
|
|||
// dist/dashboard.html the operator dashboard SPA — served
|
||||
// at GET /dashboard.html
|
||||
// dist/flow.html served at GET /flow.html
|
||||
// dist/logs.html served at GET /logs.html (AGENT/SYSTEM/AUDIT)
|
||||
// dist/logs.html served at GET /logs.html (AGENT/INFRA/SYSTEM)
|
||||
// dist/core.html served at GET /core.html (C0R3: kept
|
||||
// state / container load)
|
||||
// dist/builds.html served at GET /builds.html (BU1LDS:
|
||||
|
|
@ -18,7 +18,7 @@
|
|||
// tab routing + refreshState
|
||||
// dist/static/flow.js /flow.html entry — broker terminal +
|
||||
// @-mention composer
|
||||
// dist/static/logs.js /logs.html entry — agent/system/audit
|
||||
// dist/static/logs.js /logs.html entry — agent/infra/system
|
||||
// log viewer sub-tabs
|
||||
// dist/static/builds.js /builds.html entry — rebuild queue,
|
||||
// meta inputs, build log history
|
||||
|
|
|
|||
|
|
@ -22,11 +22,11 @@ body.core-shell {
|
|||
panes; ensure it wins over any inherited display. */
|
||||
.core-pane[hidden] { display: none; }
|
||||
|
||||
/* ─── K3PT ST4T3 + 1NFR4 container cards ────────────────────────────
|
||||
/* ─── K3PT ST4T3 container cards ────────────────────────────────────
|
||||
core.html doesn't load dashboard.css (that's the operator SPA),
|
||||
so the .container-row card styles aren't inherited. Redefine them
|
||||
here so tombstone and infra entries look like proper cards (similar
|
||||
to agent cards on the main dashboard) rather than bare list items. */
|
||||
here so tombstone entries look like proper cards (similar to agent
|
||||
cards on the main dashboard) rather than bare list items. */
|
||||
.containers {
|
||||
list-style: none;
|
||||
padding: 0;
|
||||
|
|
|
|||
|
|
@ -16,12 +16,14 @@
|
|||
/core.html) carved out of the dashboard's old SYST3M tab so the
|
||||
dashboard tab strip stays lean. Same minimal chrome as
|
||||
/logs.html — a `← home` back-link to the H0M3 hub + a
|
||||
<hive-tab-strip> sub-tab nav. Three sub-tabs: kept state (tombstones),
|
||||
container load, and infra containers (start/stop/restart the four
|
||||
hive infra containers). Rebuild queue + meta inputs have moved to
|
||||
<hive-tab-strip> sub-tab nav. Two sub-tabs: kept state (tombstones)
|
||||
and container load. Rebuild queue + meta inputs have moved to
|
||||
/builds.html (the build lifecycle hub). Default tab: K3PT ST4T3.
|
||||
The section <div> ids (tombstones-section, container-load-section,
|
||||
infra-containers-section) match what core.js's renderers target. -->
|
||||
The section <div> ids (tombstones-section, container-load-section)
|
||||
match what core.js's renderers target. Hive infra containers
|
||||
(`hive-ci`, `hive-forge`, `hive-gateway`, `hive-matrix`) have no
|
||||
dashboard panel — `hivectl stop`/`start`/`restart` is the only
|
||||
control surface. -->
|
||||
<header class="page-header">
|
||||
<a class="page-back" href="/">← home</a>
|
||||
<hive-tab-strip class="hive-tabbar core-tabbar" id="core-tabbar" prefix="core"
|
||||
|
|
@ -55,19 +57,6 @@
|
|||
</div>
|
||||
</section>
|
||||
|
||||
<!-- 1NFR4: start / stop the four hive infrastructure containers
|
||||
(hive-ci, hive-forge, hive-gateway, hive-matrix) directly from
|
||||
the dashboard — operator-only, no agent-facing equivalent.
|
||||
Status polled every 5s while this sub-tab is open, same cadence
|
||||
as C0NT41N3R L04D. -->
|
||||
<section class="core-pane" id="core-pane-infra" data-tab-pane="infra"
|
||||
role="tabpanel" aria-labelledby="core-tab-infra">
|
||||
<p class="meta">hive infrastructure containers — ci, forge, gateway, matrix. actions are logged to the AUDIT log.</p>
|
||||
<div id="infra-containers-section">
|
||||
<p class="meta">loading…</p>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
</main>
|
||||
|
||||
<script type="module" src="/static/core.js" defer></script>
|
||||
|
|
|
|||
|
|
@ -381,66 +381,6 @@ function stopContainerLoadPolling() {
|
|||
if (containerLoadTimer) { clearInterval(containerLoadTimer); containerLoadTimer = null; }
|
||||
}
|
||||
|
||||
// ─── infra containers (start/stop the 4 hive infra containers) ────────────
|
||||
let infraTimer = null;
|
||||
|
||||
function renderInfraContainers(rows) {
|
||||
const root = $('infra-containers-section');
|
||||
if (!root) return;
|
||||
root.replaceChildren();
|
||||
if (!Array.isArray(rows) || !rows.length) {
|
||||
root.append(el('p', { class: 'meta' }, 'no infra container data'));
|
||||
return;
|
||||
}
|
||||
const ul = el('ul', { class: 'containers' });
|
||||
for (const c of rows) {
|
||||
const li = el('li', { class: 'container-row' });
|
||||
const head = el('div', { class: 'head' });
|
||||
head.append(
|
||||
el('span', { class: 'name' }, c.name),
|
||||
el('span', { class: 'hive-pill-sm ' + (c.running ? 'badge-ok' : 'badge-fail') },
|
||||
c.running ? 'running' : 'stopped'),
|
||||
);
|
||||
li.append(head);
|
||||
|
||||
const actions = el('div', { class: 'actions' });
|
||||
const base = '/api/infra-container/' + encodeURIComponent(c.name) + '/';
|
||||
if (c.running) {
|
||||
actions.append(form(base + 'stop', 'btn-stop', '■ ST0P',
|
||||
'stop ' + c.name + '?'));
|
||||
} else {
|
||||
actions.append(form(base + 'start', 'btn-start', '▶ ST4RT',
|
||||
'start ' + c.name + '?'));
|
||||
}
|
||||
li.append(actions);
|
||||
ul.append(li);
|
||||
}
|
||||
root.append(ul);
|
||||
}
|
||||
|
||||
async function refreshInfraContainers() {
|
||||
try {
|
||||
const resp = await fetch('/api/state');
|
||||
if (!resp.ok) throw new Error('http ' + resp.status);
|
||||
const s = await resp.json();
|
||||
renderInfraContainers(s.infra_containers || []);
|
||||
} catch (e) {
|
||||
const root = $('infra-containers-section');
|
||||
if (root) {
|
||||
root.replaceChildren();
|
||||
root.append(el('p', { class: 'meta' }, 'infra container fetch failed: ' + e));
|
||||
}
|
||||
}
|
||||
}
|
||||
function startInfraPolling() {
|
||||
refreshInfraContainers();
|
||||
if (infraTimer) return;
|
||||
infraTimer = setInterval(refreshInfraContainers, 5000);
|
||||
}
|
||||
function stopInfraPolling() {
|
||||
if (infraTimer) { clearInterval(infraTimer); infraTimer = null; }
|
||||
}
|
||||
|
||||
// ─── render-all (cold load + any full re-render) ──────────────────────────
|
||||
function renderAll() {
|
||||
renderTombstones({ tombstones: tombstonesState });
|
||||
|
|
@ -505,14 +445,11 @@ async function init() {
|
|||
tabs: [
|
||||
{ id: 'kept', label: 'K3PT ST4T3' },
|
||||
{ id: 'load', label: 'C0NT41N3R L04D' },
|
||||
{ id: 'infra', label: '1NFR4' },
|
||||
],
|
||||
defaultId: 'kept',
|
||||
onShow: (id) => {
|
||||
if (id === 'load') startContainerLoadPolling();
|
||||
else stopContainerLoadPolling();
|
||||
if (id === 'infra') startInfraPolling();
|
||||
else stopInfraPolling();
|
||||
// Lazy-load stale-perms on first K3PT ST4T3 activation; always
|
||||
// re-fetch on subsequent visits in case perms changed.
|
||||
if (id === 'kept') fetchAndRenderStalePerms();
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@
|
|||
<body class="cred-shell">
|
||||
|
||||
<!-- Minimal chrome: back link + sub-tab strip, same pattern as
|
||||
logs.html (MATRIX / GITHUB instead of AGENT/SYSTEM/AUDIT). Back
|
||||
logs.html (MATRIX / GITHUB instead of AGENT/INFRA/SYSTEM). Back
|
||||
link points to the H0M3 hub (served at /). -->
|
||||
<header class="page-header">
|
||||
<a class="page-back" href="/">← home</a>
|
||||
|
|
|
|||
|
|
@ -65,7 +65,7 @@
|
|||
<span class="home-tile-icon" aria-hidden="true">📜</span>
|
||||
<span class="home-tile-label">Logs</span>
|
||||
</span>
|
||||
<span class="home-tile-desc">agent · system logs · privileged-action audit</span>
|
||||
<span class="home-tile-desc">agent · infra · system logs</span>
|
||||
</a>
|
||||
|
||||
<a class="home-tile" href="/stats.html">
|
||||
|
|
|
|||
|
|
@ -41,14 +41,6 @@ body.logs-shell {
|
|||
flex-direction: column;
|
||||
padding-bottom: 1.2em;
|
||||
}
|
||||
/* The AUDIT tab uses a <div> for its list instead of a <pre>, so give
|
||||
it the same flex-grow + internal scroll that .journal-output already has. */
|
||||
#audit-list {
|
||||
flex: 1 1 0;
|
||||
min-height: 0;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.logs-toolbar {
|
||||
display: flex;
|
||||
gap: 0.6em;
|
||||
|
|
@ -202,65 +194,3 @@ body.logs-shell {
|
|||
|
||||
.build-logs-runtime { font-size: 0.85em; color: var(--muted); }
|
||||
|
||||
/* ─── AUDIT tab — privileged-actions audit trail table ──────────────── */
|
||||
.audit-filter {
|
||||
flex: 1 1 18em;
|
||||
min-width: 0;
|
||||
padding: 0.35em 0.6em;
|
||||
background: var(--bg-elev);
|
||||
color: var(--fg);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 4px;
|
||||
font-family: inherit;
|
||||
font-size: 0.9em;
|
||||
}
|
||||
.audit-table-wrap { overflow-x: auto; }
|
||||
.audit-table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
font-size: 0.88em;
|
||||
}
|
||||
.audit-table th,
|
||||
.audit-table td {
|
||||
text-align: left;
|
||||
padding: 0.4em 0.7em;
|
||||
border-bottom: 1px solid var(--border);
|
||||
vertical-align: top;
|
||||
}
|
||||
.audit-table th {
|
||||
color: var(--muted);
|
||||
font-weight: bold;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.06em;
|
||||
font-size: 0.82em;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.audit-table tbody tr:hover {
|
||||
background: color-mix(in srgb, var(--bg-elev) 45%, transparent);
|
||||
}
|
||||
.audit-when, .audit-when-th { white-space: nowrap; }
|
||||
.audit-agent { font-weight: bold; white-space: nowrap; }
|
||||
.audit-action { font-family: monospace; white-space: nowrap; }
|
||||
.audit-target { white-space: nowrap; }
|
||||
.audit-detail { word-break: break-word; }
|
||||
.audit-outcome-th, .audit-outcome-td { white-space: nowrap; }
|
||||
.audit-outcome {
|
||||
display: inline-block;
|
||||
padding: 0 0.5em;
|
||||
border-radius: 999px;
|
||||
font-size: 0.82em;
|
||||
font-weight: bold;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.audit-outcome-ok {
|
||||
background: color-mix(in srgb, var(--green) 22%, transparent);
|
||||
color: var(--green);
|
||||
}
|
||||
.audit-outcome-err {
|
||||
background: color-mix(in srgb, var(--red) 22%, transparent);
|
||||
color: var(--red);
|
||||
}
|
||||
.audit-outcome-denied {
|
||||
background: color-mix(in srgb, var(--yellow) 22%, transparent);
|
||||
color: var(--yellow);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@
|
|||
<!-- Minimal chrome: back link + sub-tab strip.
|
||||
Same pattern as flow.html — no full dashboard tabbar. Back link
|
||||
points to the H0M3 hub (served at /), not the dashboard.
|
||||
Four sub-tabs: AGENT, INFRA, SYSTEM, AUDIT. Build log history has
|
||||
Three sub-tabs: AGENT, INFRA, SYSTEM. Build log history has
|
||||
moved to /builds.html (the build lifecycle hub). -->
|
||||
<header class="page-header">
|
||||
<a class="page-back" href="/">← home</a>
|
||||
|
|
@ -75,21 +75,6 @@
|
|||
<pre id="system-output" class="journal-output">loading…</pre>
|
||||
</section>
|
||||
|
||||
<!-- AUDIT: operator-visible trail of agent-initiated privileged
|
||||
actions (infra-container restarts, etc.). Filterable table backed
|
||||
by GET /api/audit-log ({ entries, total }), newest first, server
|
||||
clamped to the latest 500. -->
|
||||
<section class="logs-pane" id="logs-pane-audit" data-tab-pane="audit"
|
||||
role="tabpanel" aria-labelledby="logs-tab-audit">
|
||||
<div class="logs-toolbar">
|
||||
<input type="text" id="audit-filter" class="audit-filter"
|
||||
placeholder="filter agent / action / target / detail…" autocomplete="off">
|
||||
<button type="button" class="btn btn-restart" id="audit-refresh">↻ refresh</button>
|
||||
<span id="audit-count" class="meta"></span>
|
||||
</div>
|
||||
<div id="audit-list"><p class="meta">loading…</p></div>
|
||||
</section>
|
||||
|
||||
</main>
|
||||
|
||||
<script type="module" src="/static/logs.js" defer></script>
|
||||
|
|
|
|||
|
|
@ -1,13 +1,11 @@
|
|||
// /logs.html entry point: log viewer with four sub-tabs (AGENT, INFRA,
|
||||
// SYSTEM, AUDIT). Build log history has moved to /builds.html.
|
||||
// /logs.html entry point: log viewer with three sub-tabs (AGENT, INFRA,
|
||||
// SYSTEM). Build log history has moved to /builds.html.
|
||||
// AGENT — per-container journald viewer, backed by GET /api/journal/{name}
|
||||
// INFRA — infra-container journald viewer (hive-ci, hive-forge, …),
|
||||
// same API but full machine journal only (no unit filter)
|
||||
// SYSTEM — host service logs, backed by GET /api/journal-host
|
||||
// AUDIT — agent-initiated privileged-action trail, GET /api/audit-log;
|
||||
// live-appends via the `audit_entry_added` /dashboard/stream event
|
||||
//
|
||||
// Tab routing via URL hash (#agent, #infra, #system, #audit). Default: #agent.
|
||||
// Tab routing via URL hash (#agent, #infra, #system). Default: #agent.
|
||||
//
|
||||
// URL params `?agent=name` and `?unit=svc` pre-select the agent + unit.
|
||||
// When `?agent=` names an infra container the INFRA tab is activated instead.
|
||||
|
|
@ -15,10 +13,9 @@
|
|||
// INFRA, and SYSTEM tabs so the operator knows how stale the output is.
|
||||
|
||||
import {
|
||||
$, fmtAgeSecs, openStream, initServerWarnings,
|
||||
$, fmtAgeSecs, initServerWarnings,
|
||||
} from './common.js';
|
||||
import { el } from '@hive/shared/dom.js';
|
||||
import { epochSec } from './util.js';
|
||||
import '@hive/shared/hive-tab-strip.js';
|
||||
|
||||
(() => {
|
||||
|
|
@ -127,12 +124,25 @@ import '@hive/shared/hive-tab-strip.js';
|
|||
if (infraSelect) infraSelect.addEventListener('change', fetchInfra);
|
||||
if (infraRefresh) infraRefresh.addEventListener('click', fetchInfra);
|
||||
|
||||
// Fixed allowlist — the four hive infra services never change at
|
||||
// runtime, and there's no dashboard API exposing just the name list
|
||||
// (the one that used to, `/api/state`'s `infra_containers` field, was
|
||||
// start/stop-panel-only and is gone). Mirrors `hive_priv_sock::InfraContainer::ALL`.
|
||||
const INFRA_NAMES = ['hive-ci', 'hive-forge', 'hive-gateway', 'hive-matrix'];
|
||||
|
||||
// ─── container list init ──────────────────────────────────────────────
|
||||
// Fetch /api/state once and populate both the AGENT selector (agents only)
|
||||
// and the INFRA selector (infra containers only). Also handles the
|
||||
// ?agent= / ?unit= deep-link, routing to the INFRA tab when the named
|
||||
// container is an infra container.
|
||||
// Fetch /api/state once to populate the AGENT selector (agents only);
|
||||
// INFRA is a fixed list (see INFRA_NAMES). Also handles the ?agent= /
|
||||
// ?unit= deep-link, routing to the INFRA tab when the named container
|
||||
// is an infra container.
|
||||
async function loadContainerLists() {
|
||||
if (infraSelect) {
|
||||
infraSelect.replaceChildren();
|
||||
infraSelect.append(el('option', { value: '' }, '— select container —'));
|
||||
for (const name of INFRA_NAMES) {
|
||||
infraSelect.append(el('option', { value: name }, name));
|
||||
}
|
||||
}
|
||||
try {
|
||||
const resp = await fetch('/api/state');
|
||||
if (!resp.ok) return;
|
||||
|
|
@ -147,21 +157,11 @@ import '@hive/shared/hive-tab-strip.js';
|
|||
}
|
||||
}
|
||||
|
||||
// Populate INFRA selector.
|
||||
const infraNames = new Set((state.infra_containers || []).map((c) => c.name));
|
||||
if (infraSelect) {
|
||||
infraSelect.replaceChildren();
|
||||
infraSelect.append(el('option', { value: '' }, '— select container —'));
|
||||
for (const name of infraNames) {
|
||||
infraSelect.append(el('option', { value: name }, name));
|
||||
}
|
||||
}
|
||||
|
||||
// Deep-link: honour ?agent= and ?unit= URL params.
|
||||
const urlAgent = new URLSearchParams(location.search).get('agent');
|
||||
const urlUnit = new URLSearchParams(location.search).get('unit');
|
||||
if (urlAgent) {
|
||||
if (infraNames.has(urlAgent)) {
|
||||
if (INFRA_NAMES.includes(urlAgent)) {
|
||||
// Route to INFRA tab.
|
||||
logTabs.show('infra');
|
||||
if (infraSelect) {
|
||||
|
|
@ -225,180 +225,25 @@ import '@hive/shared/hive-tab-strip.js';
|
|||
if (systemUnitSelect) systemUnitSelect.addEventListener('change', fetchSystem);
|
||||
if (systemRefresh) systemRefresh.addEventListener('click', fetchSystem);
|
||||
|
||||
// ─── AUDIT tab ──────────────────────────────────────────────────────
|
||||
// Operator-visible trail of agent-initiated privileged actions, backed
|
||||
// by GET /api/audit-log → { entries: [...], total: N } (entries
|
||||
// newest-first, server-clamped to 500; `total` drives "latest 500 of N").
|
||||
// Per-entry: { id, ts_unix (secs), agent, action, target, outcome, detail }.
|
||||
// outcome is 'ok' | 'err'; a capability denial is 'err' with detail
|
||||
// starting "denied:" — coloured amber to read apart from an execution
|
||||
// failure. Lazy-fetched on tab show (like SYSTEM); filter is a
|
||||
// client-side substring on the cached rows.
|
||||
|
||||
const auditList = $('audit-list');
|
||||
const auditFilter = $('audit-filter');
|
||||
const auditRefresh = $('audit-refresh');
|
||||
const auditCount = $('audit-count');
|
||||
|
||||
let auditEntries = [];
|
||||
let auditTotal = 0;
|
||||
let auditFetching = false;
|
||||
|
||||
// ts_unix arrives as an RFC 3339 string — fmtAgeSecs wants an age
|
||||
// in seconds, so normalize via epochSec first.
|
||||
function auditFmtWhen(ts) {
|
||||
if (!ts) return '';
|
||||
const age = Math.floor(Date.now() / 1000) - epochSec(ts);
|
||||
return fmtAgeSecs(Math.max(0, age)) + ' ago';
|
||||
}
|
||||
|
||||
// outcome → badge. 'ok' green; an 'err' whose detail starts "denied:" is a
|
||||
// capability refusal (amber, labelled "denied"); other 'err' red. The
|
||||
// literal outcome is the fallback label so a new value still renders.
|
||||
function auditOutcomeBadge(outcome, detail) {
|
||||
const denied = outcome === 'err'
|
||||
&& typeof detail === 'string' && detail.startsWith('denied:');
|
||||
const cls = outcome === 'ok'
|
||||
? 'audit-outcome audit-outcome-ok'
|
||||
: denied
|
||||
? 'audit-outcome audit-outcome-denied'
|
||||
: 'audit-outcome audit-outcome-err';
|
||||
return el('span', { class: cls }, denied ? 'denied' : (outcome || '?'));
|
||||
}
|
||||
|
||||
function auditMatches(e, q) {
|
||||
if (!q) return true;
|
||||
return `${e.agent || ''} ${e.action || ''} ${e.target || ''} ${e.detail || ''}`
|
||||
.toLowerCase().includes(q);
|
||||
}
|
||||
|
||||
function renderAudit() {
|
||||
if (!auditList) return;
|
||||
const q = (auditFilter ? auditFilter.value : '').trim().toLowerCase();
|
||||
const rows = auditEntries.filter((e) => auditMatches(e, q));
|
||||
|
||||
if (auditCount) {
|
||||
const shown = auditEntries.length;
|
||||
const clamped = auditTotal > shown;
|
||||
let txt = clamped
|
||||
? `latest ${shown} of ${auditTotal}`
|
||||
: `${shown} entr${shown === 1 ? 'y' : 'ies'}`;
|
||||
if (q) txt += ` · ${rows.length} match${rows.length === 1 ? '' : 'es'}`;
|
||||
auditCount.textContent = txt;
|
||||
}
|
||||
|
||||
auditList.replaceChildren();
|
||||
if (rows.length === 0) {
|
||||
auditList.append(el('p', { class: 'meta' },
|
||||
q ? '(no matching entries)' : '(no privileged actions recorded yet)'));
|
||||
return;
|
||||
}
|
||||
|
||||
const table = el('table', { class: 'audit-table' });
|
||||
table.append(el('thead', {},
|
||||
el('tr', {},
|
||||
el('th', { class: 'audit-when-th' }, 'when'),
|
||||
el('th', {}, 'agent'),
|
||||
el('th', {}, 'action'),
|
||||
el('th', {}, 'target'),
|
||||
el('th', { class: 'audit-outcome-th' }, 'outcome'),
|
||||
el('th', {}, 'detail'),
|
||||
)));
|
||||
const tbody = el('tbody', {});
|
||||
for (const e of rows) {
|
||||
tbody.append(el('tr', {},
|
||||
el('td', {
|
||||
class: 'audit-when meta',
|
||||
title: e.ts_unix ? new Date(e.ts_unix).toISOString() : '',
|
||||
}, auditFmtWhen(e.ts_unix)),
|
||||
el('td', { class: 'audit-agent' }, e.agent || ''),
|
||||
el('td', { class: 'audit-action' }, e.action || ''),
|
||||
el('td', { class: 'audit-target' }, e.target || ''),
|
||||
el('td', { class: 'audit-outcome-td' }, auditOutcomeBadge(e.outcome, e.detail)),
|
||||
el('td', { class: 'audit-detail meta' }, e.detail || ''),
|
||||
));
|
||||
}
|
||||
table.append(tbody);
|
||||
const wrap = el('div', { class: 'audit-table-wrap' });
|
||||
wrap.append(table);
|
||||
auditList.append(wrap);
|
||||
}
|
||||
|
||||
async function fetchAudit() {
|
||||
if (!auditList || auditFetching) return;
|
||||
auditFetching = true;
|
||||
try {
|
||||
const resp = await fetch('/api/audit-log');
|
||||
if (!resp.ok) throw new Error('http ' + resp.status);
|
||||
const data = await resp.json();
|
||||
auditEntries = Array.isArray(data.entries) ? data.entries : [];
|
||||
auditTotal = typeof data.total === 'number' ? data.total : auditEntries.length;
|
||||
renderAudit();
|
||||
} catch (err) {
|
||||
auditList.replaceChildren();
|
||||
auditList.append(el('p', { class: 'meta' }, 'fetch failed: ' + err));
|
||||
} finally {
|
||||
auditFetching = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (auditRefresh) auditRefresh.addEventListener('click', fetchAudit);
|
||||
if (auditFilter) auditFilter.addEventListener('input', renderAudit);
|
||||
|
||||
// Live-append: an `audit_entry_added` event on /dashboard/stream carries a
|
||||
// new row flattened at the top level ({ kind, seq, id, ts_unix, agent,
|
||||
// action, target, outcome, detail }). Prepend it (newest-first), de-duped
|
||||
// by id against whatever the cold fetch already returned, and bump the
|
||||
// total so the "latest N of M" header stays right. Re-render only while
|
||||
// the AUDIT tab is in view; otherwise the next tab-show fetch is
|
||||
// authoritative anyway. Wired into the shared stream onmessage above.
|
||||
function onAuditEntryAdded(ev) {
|
||||
if (auditEntries.some((e) => e.id === ev.id)) return;
|
||||
auditEntries.unshift({
|
||||
id: ev.id, ts_unix: ev.ts_unix, agent: ev.agent, action: ev.action,
|
||||
target: ev.target, outcome: ev.outcome, detail: ev.detail,
|
||||
});
|
||||
auditTotal += 1;
|
||||
if (logTabs.active() === 'audit') renderAudit();
|
||||
}
|
||||
|
||||
// ─── init ─────────────────────────────────────────────────────────────
|
||||
|
||||
// Wire the shared tab strip now that fetchSystem + the element refs it
|
||||
// needs are defined. Its initial show() paints the active pane and, if
|
||||
// the deep-linked tab is SYSTEM/AUDIT, kicks off the lazy fetch via onShow.
|
||||
// the deep-linked tab is SYSTEM, kicks off the lazy fetch via onShow.
|
||||
// Default: AGENT (build logs moved to /builds.html).
|
||||
logTabs = document.getElementById('logs-tabbar').configure({
|
||||
tabs: [
|
||||
{ id: 'agent', label: 'AGENT' },
|
||||
{ id: 'infra', label: 'INFRA' },
|
||||
{ id: 'system', label: 'SYSTEM' },
|
||||
{ id: 'audit', label: 'AUDIT' },
|
||||
],
|
||||
defaultId: 'agent',
|
||||
onShow: (id) => {
|
||||
if (id === 'system') fetchSystem();
|
||||
else if (id === 'audit') fetchAudit();
|
||||
},
|
||||
});
|
||||
loadContainerLists();
|
||||
|
||||
// Subscribe to the dashboard SSE stream for audit live-appends.
|
||||
// kinds= narrows this from all 17 wire kinds down to the 1 this page
|
||||
// acts on. This page was one of 4 unfiltered `/api/dashboard/stream`
|
||||
// subscribers before this (subscription discipline, part 1 of the
|
||||
// dashboard-event-stream-split issue).
|
||||
{
|
||||
const es = openStream('/api/dashboard/stream?kinds=audit_entry_added');
|
||||
if (es) {
|
||||
es.onmessage = (e) => {
|
||||
let ev;
|
||||
try { ev = JSON.parse(e.data); } catch { return; }
|
||||
if (ev.kind === 'audit_entry_added') onAuditEntryAdded(ev);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
// Tick the last-fetched timestamps every 30s so "fetched 1m ago" stays
|
||||
// accurate without a manual refresh.
|
||||
setInterval(() => {
|
||||
|
|
@ -411,8 +256,6 @@ import '@hive/shared/hive-tab-strip.js';
|
|||
if (systemLastFetch && systemFetchTs && !systemFetchTs.hidden) {
|
||||
systemFetchTs.textContent = fmtFetchTs(systemLastFetch);
|
||||
}
|
||||
// Keep the audit "ago" column honest while that tab is in view.
|
||||
if (auditEntries.length && logTabs.active() === 'audit') renderAudit();
|
||||
}, 30_000);
|
||||
|
||||
})();
|
||||
|
|
|
|||
|
|
@ -308,7 +308,7 @@ window.marked = marked;
|
|||
//
|
||||
// kinds= matches MUTATION_HANDLERS below verbatim, plus `sent`
|
||||
// (checked separately, just above, for the operator inbox) —
|
||||
// narrows this from all 17 wire kinds down to the 11 this page
|
||||
// narrows this from all 15 wire kinds down to the 11 this page
|
||||
// actually acts on. This page was one of 4 unfiltered
|
||||
// `/api/dashboard/stream` subscribers before this (subscription
|
||||
// discipline, part 1 of the dashboard-event-stream-split issue).
|
||||
|
|
|
|||
Loading…
Reference in a new issue