#!/usr/bin/env bash # KNELPerf -> KNELPerfHub publisher. # # Architecture ruling (founder, 2026-09-06): NO server-side tooling runs in # the Grav container. This script renders pages as markdown into the # KNELPerfHub git repo and PUSHES; the Cloudron VPS's ukrrs-hub-pull.timer # git-pulls that repo into the Grav pages dir every 5 min (Grav # cache.check=file picks changes up). Scraping/collectors run on the # tooling hosts, not in the app container. # # Env: HUB_REPO (default below), SOLAR_REPO. set -euo pipefail REPO_ROOT=$(cd "$(dirname "$0")/.." && pwd) HUB_REPO=${HUB_REPO:-$HOME/projects/KNEL/KNELPerfHub} SOLAR_REPO=${SOLAR_REPO:-$HOME/projects/KNEL/PhysicalPlant/SITER-Solar} PAGES=$HUB_REPO/performance fm() { printf -- '---\ntitle: %s\nvisibility: private\n---\n\n' "$1"; } # ---------- home dashboard ---------- DASH=$(mktemp) { fm "Performance Hub" echo "# ⚡ KNEL Performance Hub" echo echo "Auto-published $(date -Is) from KNELPerf (#826). Repo:" echo "https://git.knownelement.com/KNEL/KNELPerf" echo echo "## ⚡ ERCOT risk (LZ_SOUTH)" echo '```json' if [ -x "$SOLAR_REPO/solar-analysis/ercot-brief.sh" ]; then "$SOLAR_REPO/solar-analysis/ercot-brief.sh" 2>/dev/null \ || tail -1 /var/tmp/ercot-brief-history.tsv 2>/dev/null \ || echo '{"error":"no source yet (API key pending)"}' else tail -1 /var/tmp/ercot-brief-history.tsv 2>/dev/null || echo '{"error":"no data yet"}' fi echo '```' echo echo "## 🌤️ Solar arbitrage verdict (latest run)" if [ -x "$SOLAR_REPO/solar-analysis/oncor-arbitrage.sh" ]; then echo '```json' "$SOLAR_REPO/solar-analysis/oncor-arbitrage.sh" 2>/dev/null || echo '{"error":"source unavailable"}' echo '```' fi echo echo "## 📋 Baseline index" echo echo "| host | latest bundle |" echo "|---|---|" found=0 for d in "$REPO_ROOT"/data/baselines/*/; do [ -d "$d" ] || continue h=$(basename "$d"); l=$(find "$d" -maxdepth 1 -mindepth 1 -type d -printf '%f\n' 2>/dev/null | sort | tail -1) if [ -n "$l" ]; then echo "| $h | $l |"; found=1; fi done [ "$found" = 1 ] || echo "| (none yet — first fleet baseline wave pending) | |" } > "$DASH" mkdir -p "$PAGES" mv "$DASH" "$PAGES/page.md" # ---------- reports (WHITELIST: public content only — NEVER revenue/expense detail, see hub README transparency policy) for report in report-amt-power-telemetry report-moonlight-desktop; do R=$(mktemp) { fm "$report"; sed -n '/^# /,$p' "$REPO_ROOT/docs/$report.md"; } > "$R" mkdir -p "$PAGES/reports"; mv "$R" "$PAGES/reports/$report.md" done # ---------- push ---------- cd "$HUB_REPO" if [ -n "$(git status --porcelain)" ]; then git add performance git commit -q -m "Auto-publish $(date +%F_%H:%M) (#826) https://projects.knownelement.com/issues/826" git push -q origin main echo "pushed to KNEL/KNELPerfHub ($(date -Is)); site refreshes within 5 min" else echo "no changes to publish ($(date -Is))" fi