feat(infra): commit live infra-audit/cluster work to reconcile git with prod

This work (network_hosts inventory + infra_audit MCP tool, /api/cluster +
Sacred Valley cluster card, topbar cluster-health pill + SW self-heal) was
built in an earlier session and DEPLOYED to CT 311 as alpha.24–26, but was
never committed to git — prod was running code absent from the repo. Commits
it as-is (already prod-validated) so git matches the live state, and restores
its alpha.24/25/26 CHANGELOG entries. Files are disjoint from the fold-in
work; both now ship together under alpha.27.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
root
2026-06-08 15:20:38 +10:00
parent ae2ea09f0c
commit b0b23ba05d
19 changed files with 606 additions and 4 deletions

17
lib/api/routes/cluster.js Normal file
View File

@@ -0,0 +1,17 @@
import { Router } from 'express';
import { asyncWrap } from '../errors.js';
import { clusterHealth } from '../../proxmox/cluster.js';
// Read-only cluster health for the Sacred Valley card. Cached briefly so multiple
// polling clients coalesce into one PVE call. Owner or any authed agent.
export const router = Router();
let cache = { at: 0, data: null };
const TTL = 10_000;
router.get('/', asyncWrap(async (_req, res) => {
if (cache.data && Date.now() - cache.at < TTL) return res.json(cache.data);
const data = await clusterHealth();
cache = { at: Date.now(), data };
res.json(data);
}));

26
lib/api/routes/infra.js Normal file
View File

@@ -0,0 +1,26 @@
import { Router } from 'express';
import { asyncWrap } from '../errors.js';
import { pool } from '../../db/pool.js';
import * as monitored from '../../db/repos/monitored_services.js';
import * as networkHosts from '../../db/repos/network_hosts.js';
import { runAudit, tcpProbe } from '../../infra/audit.js';
// Read-only infra sanity check: probe every IP:port referenced in the wiki and
// every enabled service URL, and surface hosts missing a recorded MAC. Available
// to the owner or any authed agent (no mutations, just TCP connects).
export const router = Router();
const probe = (host, port) => tcpProbe(host, port, 1500);
router.get('/audit', asyncWrap(async (_req, res) => {
const { rows: pages } = await pool.query(
`SELECT p.title, p.body_md FROM pages p JOIN spaces s ON s.id = p.space_id WHERE s.slug = 'wiki'`);
const services = (await monitored.listEnabled()).filter(s => /^https?:\/\//.test(s.url || ''));
const report = await runAudit({ pages, services, probe });
const missingMac = (await networkHosts.missingMac()).map(h => h.id);
res.json({ ...report, inventory: { missing_mac: missingMac } });
}));
router.get('/hosts', asyncWrap(async (_req, res) => {
res.json({ hosts: await networkHosts.all() });
}));