Problem: node and cross-cutting narratives lived at the repo root
(containers/, vms/, infrastructure/, host .md files), interleaved with the
machine-readable substrate.
Change:
- Move containers/ -> knowledge/wiki/containers/, vms/ -> knowledge/wiki/vms/,
infrastructure/ -> knowledge/wiki/infrastructure/, hosts/{hubris,strong}.md ->
knowledge/wiki/hosts/, infrastructure/references/ -> knowledge/sources/references/,
GLOSSARY.md -> knowledge/GLOSSARY.md.
- Add knowledge/{index.md,log.md,sources/index.md} scaffolding.
- Rewrite all relative links repo-wide via a path-resolving mapper (inbound +
outbound + between-moved-files), including .hermes/, runbooks, operations,
investigations, plans, README, AGENTS.
- Repoint inventory.yaml doc_page fields and regenerate hosts/*.yaml (which
embed doc_page); update oikos/gen-topology.py output path, candidate doc
paths, and footer links; update code-comment doc paths.
Substrate untouched in place: inventory.yaml, hosts/*.yaml (regenerated,
idempotent), oikos/ code, mcp/, secrets/, bin/.
Verification:
- Logical broken-link set identical to pre-move baseline (net 128 -> 127; the
topology regen fixed one, introduced none). Remaining are pre-existing refs
to destroyed/archived nodes, out of scope for this move.
- gen-topology.py --check exit 0 (in sync); cards carry knowledge/wiki/ doc paths.
- build_host_files.py idempotent; all inventory doc_page targets resolve.
- MCP contract verified: get_page/search_docs/get_changelog resolve moved pages.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
153 lines
5.8 KiB
Python
153 lines
5.8 KiB
Python
#!/usr/bin/env python3
|
|
"""oikos/report.py — daily morning brief + weekly operator report.
|
|
|
|
Both are generated text, not sent directly to Matrix — same integration
|
|
contract as oikos/approve.py: there's no dedicated Matrix bot in this
|
|
homelab, so Hermes (already posting alerts as @dtoro:avispero, see
|
|
knowledge/wiki/infrastructure/monitoring.md) is the one that actually delivers this text.
|
|
The daily brief is meant to run once a day (e.g. chained after an early
|
|
oikos-scheduler.service run, or its own systemd timer); the weekly report
|
|
is a deeper markdown review.
|
|
|
|
Both are grounded only in what's actually implemented: signal state,
|
|
pending approvals, and change-ledger history. There's no Prometheus yet
|
|
(Week-3 backlog item pending LXC provisioning), so there are no trend
|
|
lines here — only point-in-time counts.
|
|
|
|
CLI:
|
|
python3 oikos/report.py daily
|
|
python3 oikos/report.py weekly
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import sys
|
|
from datetime import datetime, timedelta, timezone
|
|
from pathlib import Path
|
|
|
|
REPO = Path(__file__).resolve().parent.parent
|
|
sys.path.insert(0, str(REPO))
|
|
from oikos import approve as oikos_approve # noqa: E402
|
|
from oikos import ledger as oikos_ledger # noqa: E402
|
|
from oikos import scheduler as oikos_scheduler # noqa: E402
|
|
from oikos import signal as oikos_signal # noqa: E402
|
|
|
|
|
|
def _recent_ledger_entries(since: datetime) -> list[dict]:
|
|
since_s = since.isoformat(timespec="seconds")
|
|
out = []
|
|
if not oikos_ledger.LEDGER_DIR.exists():
|
|
return out
|
|
for path in sorted(oikos_ledger.LEDGER_DIR.glob("*.jsonl")):
|
|
for line in path.read_text().splitlines():
|
|
if not line.strip():
|
|
continue
|
|
import json
|
|
try:
|
|
e = json.loads(line)
|
|
except json.JSONDecodeError:
|
|
continue
|
|
if e.get("ts", "") >= since_s:
|
|
out.append(e)
|
|
out.sort(key=lambda e: e.get("ts", ""))
|
|
return out
|
|
|
|
|
|
def daily_brief() -> str:
|
|
now = datetime.now(timezone.utc)
|
|
since = now - timedelta(hours=24)
|
|
|
|
state = oikos_scheduler.read_state()
|
|
if state is None:
|
|
health_line = "no scheduler snapshot yet — has oikos-scheduler.timer run?"
|
|
else:
|
|
svcs = state.get("services", {})
|
|
checked = [s for s in svcs.values() if s.get("checked")]
|
|
healthy = sum(1 for s in checked if s.get("ok"))
|
|
health_line = f"{healthy}/{len(checked)} services healthy (as of {state['generated_at']})"
|
|
|
|
open_signals = oikos_signal.list_signals()
|
|
open_signals = [s for s in open_signals if s.get("state") in ("raised", "acknowledged", "acting")]
|
|
by_sev = {"critical": 0, "warning": 0, "info": 0}
|
|
for s in open_signals:
|
|
by_sev[s.get("severity", "info")] = by_sev.get(s.get("severity", "info"), 0) + 1
|
|
|
|
pending = oikos_approve.list_approvals(state="pending")
|
|
changes = _recent_ledger_entries(since)
|
|
|
|
lines = [
|
|
f"Oikos daily brief — {now.strftime('%Y-%m-%d')}",
|
|
f"health: {health_line}",
|
|
f"signals: {by_sev['critical']} critical, {by_sev['warning']} warning, "
|
|
f"{by_sev['info']} info ({len(open_signals)} open)",
|
|
f"pending approvals: {len(pending)}",
|
|
f"changes in last 24h: {len(changes)}",
|
|
]
|
|
if by_sev["critical"]:
|
|
lines.append("")
|
|
lines.append("Critical signals:")
|
|
for s in open_signals:
|
|
if s.get("severity") == "critical":
|
|
lines.append(f" - {s['id']} {s['entity']}: {s['evidence']}")
|
|
if pending:
|
|
lines.append("")
|
|
lines.append("Pending approvals:")
|
|
for a in pending:
|
|
lines.append(f" - {a['id']} {a['entity']} {a['action']} ({a['risk']})")
|
|
return "\n".join(lines)
|
|
|
|
|
|
def weekly_report() -> str:
|
|
now = datetime.now(timezone.utc)
|
|
since = now - timedelta(days=7)
|
|
changes = _recent_ledger_entries(since)
|
|
decisions = [c for c in changes if c.get("action", "").startswith("decide:")]
|
|
auto_act = sum(1 for d in decisions if d.get("result") == "auto-act")
|
|
escalate = sum(1 for d in decisions if d.get("result") == "escalate")
|
|
mutations = [c for c in changes if not c.get("action", "").startswith("decide:")]
|
|
|
|
all_signals = oikos_signal.list_signals()
|
|
recent_signals = [s for s in all_signals if s.get("ts", "") >= since.isoformat(timespec="seconds")]
|
|
by_kind: dict[str, int] = {}
|
|
for s in recent_signals:
|
|
by_kind[s.get("kind", "?")] = by_kind.get(s.get("kind", "?"), 0) + 1
|
|
|
|
lines = [
|
|
f"# Oikos weekly report — {since.strftime('%Y-%m-%d')} to {now.strftime('%Y-%m-%d')}",
|
|
"",
|
|
"## Changes",
|
|
f"- {len(mutations)} mutation(s) recorded in the change ledger",
|
|
f"- {len(decisions)} classifier decision(s): {auto_act} auto-act, {escalate} escalate",
|
|
"",
|
|
"## Signals raised this week",
|
|
]
|
|
if by_kind:
|
|
for kind, count in sorted(by_kind.items(), key=lambda kv: -kv[1]):
|
|
lines.append(f"- {kind}: {count}")
|
|
else:
|
|
lines.append("- none")
|
|
lines += [
|
|
"",
|
|
"## Open at time of report",
|
|
f"- {len([s for s in all_signals if s.get('state') in ('raised', 'acknowledged', 'acting')])} signal(s)",
|
|
f"- {len(oikos_approve.list_approvals(state='pending'))} pending approval(s)",
|
|
"",
|
|
"## Not yet available",
|
|
"- Trend lines (disk-full prediction, temp creep) — pending Prometheus provisioning",
|
|
"- Stale-doc detection — not yet implemented (60/90-day backlog)",
|
|
]
|
|
return "\n".join(lines)
|
|
|
|
|
|
def main() -> int:
|
|
import argparse
|
|
p = argparse.ArgumentParser(description="oikos daily brief / weekly report")
|
|
p.add_argument("kind", choices=["daily", "weekly"])
|
|
args = p.parse_args()
|
|
print(daily_brief() if args.kind == "daily" else weekly_report())
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(main())
|