Spaces:
Sleeping
Sleeping
File size: 3,492 Bytes
660b778 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 | """
Co-evolution dashboard. Renders a merged GitHub Step Summary showing the health of
BOTH self-evolving siblings β this InsightsEngine and World Digest β so the two
organisms can be watched in one place.
CI-only and NOT frozen; nothing in the evolution loop edits it. Best-effort: a
failed sibling fetch degrades to a notice and never fails the job. Writes markdown
to $GITHUB_STEP_SUMMARY when set (GitHub Actions), otherwise to stdout.
"""
import json
import os
from pathlib import Path
import requests
ROOT = Path(__file__).resolve().parent.parent
LOCAL_METRICS = ROOT / "evolution" / "metrics.json"
SIBLING_METRICS_URL = os.environ.get(
"SIBLING_METRICS_URL",
"https://raw.githubusercontent.com/colesr/World.alive/main/evolution/metrics.json",
)
SIBLING_DIGEST_URL = os.environ.get(
"DIGEST_JSON_URL",
"https://raw.githubusercontent.com/colesr/World.alive/main/public/digest.json",
)
def out(line: str = "") -> None:
target = os.environ.get("GITHUB_STEP_SUMMARY")
if target:
with open(target, "a", encoding="utf-8") as f:
f.write(line + "\n")
else:
print(line)
def _load_local() -> list:
try:
return json.loads(LOCAL_METRICS.read_text() or "[]")
except Exception:
return []
def _fetch_json(url: str):
try:
resp = requests.get(url, timeout=10)
if resp.ok:
return resp.json()
except Exception as exc: # noqa: BLE001 - dashboard must never fail the job
print(f"[warn] fetch failed {url}: {exc}")
return None
def main() -> None:
out("## π Co-evolution dashboard\n")
local = _load_local()
out("### InsightsEngine (this repo)\n")
if local:
m = local[-1]
out(
f"- {m.get('indicator_count', 'β')} indicators Β· {m.get('builtin_dataset_count', 'β')} datasets Β· "
f"{m.get('globe_country_count', 'β')} globe countries Β· {m.get('rss_feed_count', 'β')} feeds"
)
out(
f"- health {m.get('health_ms', 'β')}ms Β· correlation {m.get('correlation_ms_50x6', 'β')}ms Β· "
f"{len(local)} runs logged"
)
else:
out("_No metrics logged yet._")
out("\n### World Digest (sibling)\n")
sib = _fetch_json(SIBLING_METRICS_URL)
if isinstance(sib, list) and sib:
m = sib[-1]
out(
f"- {m.get('items_fetched', 'β')} items Β· {m.get('clusters', 'β')} clusters Β· "
f"{len(m.get('regions_covered', []))} regions Β· digest {m.get('digest_words', 'β')} words"
)
out(
f"- does World Digest see *us*? reachable={m.get('sibling_reachable', 'β')}, "
f"enriched={m.get('sentiment_enriched', 'β')}"
)
else:
out("_Sibling metrics unreachable β World Digest may not have run yet._")
out("\n### Exchange (`world-digest/news-exchange@1`)\n")
digest = _fetch_json(SIBLING_DIGEST_URL)
if isinstance(digest, dict):
n = len(digest.get("clusters", []))
out(
f"- World Digest is publishing: {n} clusters, {digest.get('digest_words', 'β')} words, "
f"generated {digest.get('generated_at', 'β')}"
)
out("- InsightsEngine surfaces this via `/api/news/world-digest` + the globe Digest view.")
else:
out("- World Digest's `public/digest.json` not reachable yet β the globe Digest view shows its quiet fallback.")
if __name__ == "__main__":
main()
|