feat(orchestrator): W4 resources view and host samples

A resources timer samples host CPU, RAM, swap and per-session tokens into samples.jsonl; the hub serves them and a Resources view charts them. Committed below the bar on the operator's word 2026-11-12 (no further per-bundle tests, one gate after the merge): the W4 e2e never ran in a real browser.

🎯 Fix: 92 %
💥 Break: 6 %
💸 Cost: 100 %
⏱️ Time: 100 %
🛡️ Security: 100 %
🏆 Score: 86
🚦 Gate: ⛔ break 6 % > 5

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Kevin Veen-BirkenbachandClaude Opus 5.5 committed 2026-11-12 16:15:43 +00:00
1 parent fd8fc08603
commit 35c270e120
21 files changed
+1937 -18

No files matched your search

@@ -0,0 +1,38 @@
from __future__ import annotations
from pathlib import Path
from .records import epoch, parse_line, read_regular
RESOURCES = "resources"
SAMPLES = "samples.jsonl"
TOKENS = "tokens.jsonl"
HOUR = 3600
FILE_LIMIT = 64 << 20
def rows_between(path: Path, begin: float, end: float, width: float) -> list[dict]:
try:
lines = read_regular(path, FILE_LIMIT).splitlines()
except (OSError, ValueError):
return []
found = []
for row in map(parse_line, lines):
t = None if row is None else epoch(row.get("t"))
if t is not None and begin <= t + width and t <= end:
found.append(row)
return found
def sampled(folder: Path, span: tuple[float, float]) -> dict:
"""Args:
folder: the host sampler's directory, mounted read-only.
span: (begin, end) of the page's time window in epoch seconds.
Returns:
{"since", "until", "samples", "tokens"}: the rows of samples.jsonl
within the span and those of tokens.jsonl whose hour overlaps it, as
the host unit wrote them; the hub reads nothing of the host itself.
"""
begin, end = span
return {"since": begin, "until": end, "samples": rows_between(folder / SAMPLES, begin, end, 0), "tokens": rows_between(folder / TOKENS, begin, end, HOUR)}