From 07116bdc5b1ec87bf7f3516a133732574b7f8522 Mon Sep 17 00:00:00 2001 From: "juvenal.diaz" Date: Wed, 4 Nov 2026 14:27:00 -0600 Subject: [PATCH] Add fast and deep status modes --- cmd/jeannie-core/main.go | 5 ++- docs/app-ops.md | 9 +++++ docs/templates/app-ops.md.tmpl | 9 +++++ jeannie | 2 +- lib/jeannie/commands.sh | 57 ++++++++++++++++++++++++------ scripts/heal | 4 ++- tests/jeannie/test_status_modes.py | 40 +++++++++++++++++++++ 7 files changed, 112 insertions(+), 14 deletions(-) create mode 100644 tests/jeannie/test_status_modes.py diff --git a/cmd/jeannie-core/main.go b/cmd/jeannie-core/main.go index c0db7c7..6d6e6e7 100644 --- a/cmd/jeannie-core/main.go +++ b/cmd/jeannie-core/main.go @@ -275,7 +275,7 @@ func runReportRender(args []string, in io.Reader, out io.Writer) error { if *asJSON { encoder := json.NewEncoder(out) encoder.SetIndent("", " ") - return encoder.Encode(map[string]any{"title": *title, "rows": rows, "cluster": map[string]string{ + return encoder.Encode(map[string]any{"title": *title, "mode": os.Getenv("JEANNIE_STATUS_MODE"), "rows": rows, "cluster": map[string]string{ "profile": os.Getenv("LAB_CLUSTER_PROFILE"), "runtime": os.Getenv("LAB_CLUSTER_RUNTIME"), "kubeconfig": os.Getenv("KUBECONFIG_PATH"), @@ -387,6 +387,9 @@ func renderReportText(out io.Writer, title string, rows []reportRow, details boo if profile := os.Getenv("LAB_CLUSTER_PROFILE"); profile != "" { fmt.Fprintf(out, "profile=%s runtime=%s kubeconfig=%s\n", profile, os.Getenv("LAB_CLUSTER_RUNTIME"), os.Getenv("KUBECONFIG_PATH")) } + if mode := os.Getenv("JEANNIE_STATUS_MODE"); mode != "" { + fmt.Fprintf(out, "mode=%s\n", mode) + } fmt.Fprintf(out, "fail=%d warn=%d info=%d ok=%d skip=%d\n", counts["fail"], counts["warn"], counts["info"], counts["ok"], counts["skip"]) if len(rows) == 0 { diff --git a/docs/app-ops.md b/docs/app-ops.md index 0aa6cd6..c9b340b 100644 --- a/docs/app-ops.md +++ b/docs/app-ops.md @@ -2,6 +2,15 @@ ## Current status and recent events +`./jeannie status` defaults to fast mode: it checks current host, cluster, +workload, DNS, registry, and public-route health without log scans, OCI backup +freshness, or an AI response. `./jeannie status --deep` adds those checks, +restart history, inventory/storage checks, and the optional AI hypothesis. +`--no-local-rca` suppresses the hypothesis; `--verbose` implies deep mode. The +report identifies its mode, and fast mode cannot establish backup freshness or +the absence of recent errors. Healing collects deep evidence and rejects an +explicitly supplied fast status report. + Compact `status` and `doctor-homelab` run independent read-only probes in parallel (four at a time by default, capped at eight). Set `LAB_REPORT_PARALLELISM=1` to serialize them or `LAB_REPORT_TIMING=true` to diff --git a/docs/templates/app-ops.md.tmpl b/docs/templates/app-ops.md.tmpl index 6a37514..c735980 100644 --- a/docs/templates/app-ops.md.tmpl +++ b/docs/templates/app-ops.md.tmpl @@ -2,6 +2,15 @@ ## Current status and recent events +`./jeannie status` defaults to fast mode: it checks current host, cluster, +workload, DNS, registry, and public-route health without log scans, OCI backup +freshness, or an AI response. `./jeannie status --deep` adds those checks, +restart history, inventory/storage checks, and the optional AI hypothesis. +`--no-local-rca` suppresses the hypothesis; `--verbose` implies deep mode. The +report identifies its mode, and fast mode cannot establish backup freshness or +the absence of recent errors. Healing collects deep evidence and rejects an +explicitly supplied fast status report. + Compact `status` and `doctor-homelab` run independent read-only probes in parallel (four at a time by default, capped at eight). Set `LAB_REPORT_PARALLELISM=1` to serialize them or `LAB_REPORT_TIMING=true` to diff --git a/jeannie b/jeannie index 5fa7227..22c02f6 100755 --- a/jeannie +++ b/jeannie @@ -110,7 +110,7 @@ Cluster Lifecycle Check Kubernetes/container tooling versions. Operator View And Reports - status [--all|--details|--verbose|--json] Problems-first cascade from host to public URLs. + status [--fast|--deep] [--all|--details|--verbose|--json] Check current health; --deep includes logs and backups. status --heal-plan Build a guarded self-heal plan from status. status --heal Dry-run auto-eligible self-heal actions. scorecard Compact pass/warn/fail operator scorecard. diff --git a/lib/jeannie/commands.sh b/lib/jeannie/commands.sh index 92cf1c4..00c6cb0 100644 --- a/lib/jeannie/commands.sh +++ b/lib/jeannie/commands.sh @@ -1954,8 +1954,10 @@ status_cascade_report() { local failures=0 status_section "Status Cascade" - status_cascade_check "inventory YAML" inventory_check || failures=$((failures + 1)) - status_cascade_check "Debian Docker root" check_debian_docker_root || failures=$((failures + 1)) + if [[ "${JEANNIE_STATUS_MODE:-deep}" == deep ]]; then + status_cascade_check "inventory YAML" inventory_check || failures=$((failures + 1)) + status_cascade_check "Debian Docker root" check_debian_docker_root || failures=$((failures + 1)) + fi status_cascade_check "Debian Docker service" check_systemd_active docker || failures=$((failures + 1)) status_cascade_check "Debian containerd service" check_systemd_active containerd || failures=$((failures + 1)) status_cascade_check "Debian Tailscale IP" check_debian_tailscale_ip || failures=$((failures + 1)) @@ -1968,11 +1970,15 @@ status_cascade_report() { status_cascade_warn "Arr Prowlarr HTTP" status_http_ok "http://127.0.0.1:9696/" status_section "RPi Bootstrap And DNS" - status_cascade_check "RPi SSH" check_rpi_ssh || failures=$((failures + 1)) - status_cascade_check "RPi Docker root state" check_rpi_docker_root_state || failures=$((failures + 1)) + if [[ "${JEANNIE_STATUS_MODE:-deep}" == deep ]]; then + status_cascade_check "RPi SSH" check_rpi_ssh || failures=$((failures + 1)) + status_cascade_check "RPi Docker root state" check_rpi_docker_root_state || failures=$((failures + 1)) + fi status_cascade_check "Pi-hole DNS" check_pihole_dns_query || failures=$((failures + 1)) - status_cascade_warn "RPi Tailscale IP" check_rpi_tailscale_ip - status_cascade_warn "Uptime Kuma HTTP" status_rpi_uptime_kuma_ok + if [[ "${JEANNIE_STATUS_MODE:-deep}" == deep ]]; then + status_cascade_warn "RPi Tailscale IP" check_rpi_tailscale_ip + status_cascade_warn "Uptime Kuma HTTP" status_rpi_uptime_kuma_ok + fi status_section "Cluster (${LAB_CLUSTER_PROFILE} / ${LAB_CLUSTER_RUNTIME})" status_cascade_check "Cluster storage" status_cluster_storage || failures=$((failures + 1)) @@ -1987,13 +1993,19 @@ status_cascade_report() { status_cascade_warn "No problem pods" status_no_problem_pods status_section "What Broke Signals" - status_cascade_warn "Backup freshness" backup_status + if [[ "${JEANNIE_STATUS_MODE:-deep}" == deep ]]; then + status_cascade_warn "Backup freshness" backup_status + fi status_cascade_warn "Recent deployments healthy" status_recent_deployments - status_cascade_warn "Pod restart pressure" status_pod_restart_pressure + if [[ "${JEANNIE_STATUS_MODE:-deep}" == deep ]]; then + status_cascade_warn "Pod restart pressure" status_pod_restart_pressure + fi status_cascade_warn "Node pressure" status_node_pressure status_cascade_warn "Disk usage" status_disk_pressure - status_cascade_warn "Traefik 5xx/404 signals" status_traefik_error_rates - status_cascade_recent_gitea + if [[ "${JEANNIE_STATUS_MODE:-deep}" == deep ]]; then + status_cascade_warn "Traefik 5xx/404 signals" status_traefik_error_rates + status_cascade_recent_gitea + fi status_section "Platform And Apps" status_cascade_check "Local registry" status_registry_ok || failures=$((failures + 1)) @@ -2002,7 +2014,9 @@ status_cascade_report() { status_cascade_warn "Argo CD server" status_kubernetes_deployment_ready argocd argocd-server status_section "Edge And Public URLs" - status_cascade_check "OCI edge SSH" check_edge_ssh || failures=$((failures + 1)) + if [[ "${JEANNIE_STATUS_MODE:-deep}" == deep ]]; then + status_cascade_check "OCI edge SSH" check_edge_ssh || failures=$((failures + 1)) + fi status_cascade_check "Traefik LoadBalancer HTTP" status_http_reachable "http://${LAB_TRAEFIK_LB_IP:?LAB_TRAEFIK_LB_IP is required from homelab.yml}/" || failures=$((failures + 1)) status_cascade_check "Website public URL" status_http_ok "${LAB_PUBLIC_URL:?LAB_PUBLIC_URL is required from homelab.yml}/" || failures=$((failures + 1)) status_cascade_check "Gitea public route" status_gitea_public_ok || failures=$((failures + 1)) @@ -2364,6 +2378,8 @@ fi" || printf 'unable to reach %s@%s\n' "${rpi_user}" "${rpi_host}" status_report() { local cascade_status=0 local heal_mode="" + local requested_mode="" + local -x JEANNIE_STATUS_MODE=fast local status_json local -a status_args=() @@ -2371,6 +2387,14 @@ status_report() { while (($# > 0)); do case "$1" in + --fast|--deep) + if [[ -n "${requested_mode}" && "${requested_mode}" != "${1#--}" ]]; then + echo "Choose either --fast or --deep." >&2 + return 2 + fi + requested_mode="${1#--}" + shift + ;; --heal-plan) heal_mode="plan" shift @@ -2390,6 +2414,17 @@ status_report() { return 1 fi + if [[ "${requested_mode}" == fast && ( -n "${heal_mode}" || "${REPORT_UI_VERBOSE}" == true ) ]]; then + echo "Healing and verbose status require deep checks; omit --fast." >&2 + return 2 + fi + if [[ "${requested_mode}" == deep || -n "${heal_mode}" || "${REPORT_UI_VERBOSE}" == true ]]; then + JEANNIE_STATUS_MODE=deep + else + # Fast status reports deterministic health without waiting for a model. + local REPORT_UI_LOCAL_RCA=false + fi + if [[ -n "${heal_mode}" ]]; then status_json="$(mktemp "${TMPDIR:-/tmp}/jeannie-status-json.XXXXXX")" # shellcheck disable=SC2034 diff --git a/scripts/heal b/scripts/heal index bbef5c2..8c2c56b 100755 --- a/scripts/heal +++ b/scripts/heal @@ -186,7 +186,7 @@ def load_status(path: Path | None) -> dict[str, object]: return json.loads(path.read_text(encoding="utf-8")) process = subprocess.run( - [str(REPO_ROOT / "jeannie"), "status", "--json"], + [str(REPO_ROOT / "jeannie"), "status", "--deep", "--json"], cwd=REPO_ROOT, capture_output=True, text=True, @@ -255,6 +255,8 @@ def command_for(row: dict[str, str], rule: HealRule) -> tuple[str, str, int]: def build_plan(status: dict[str, object]) -> list[dict[str, object]]: + if status.get("mode") == "fast": + raise SystemExit("Heal refused: fast status omits diagnostic evidence; collect status --deep --json") report_cluster = status.get("cluster") or {} if (report_cluster.get("profile") != CLUSTER["profile"] or report_cluster.get("kubeconfig") != CLUSTER["kubeconfig"] or not CLUSTER["uid"] or report_cluster.get("uid") != CLUSTER["uid"]): diff --git a/tests/jeannie/test_status_modes.py b/tests/jeannie/test_status_modes.py new file mode 100644 index 0000000..c12b93e --- /dev/null +++ b/tests/jeannie/test_status_modes.py @@ -0,0 +1,40 @@ +"""Status mode selection regressions; run on the Debian deployment host.""" + +from pathlib import Path +import subprocess +import unittest + + +ROOT = Path(__file__).resolve().parents[2] +PROGRAM = r''' +set -euo pipefail +source scripts/report-ui +source lib/jeannie/commands.sh +require_debian_server() { :; } +report_ui_begin() { :; } +report_ui_finish() { REPORT_UI_FAILURES=0; } +report_ui_render() { :; } +report_ui_cleanup() { :; } +status_cascade_report() { printf 'mode=%s ai=%s\n' "$JEANNIE_STATUS_MODE" "$REPORT_UI_LOCAL_RCA"; } +status_report "$@" +''' + + +class StatusModeTests(unittest.TestCase): + def run_status(self, *args): + return subprocess.run(["bash", "-c", PROGRAM, "status-test", *args], cwd=ROOT, + text=True, capture_output=True) + + def test_fast_is_default_and_skips_ai(self): + result = self.run_status() + self.assertEqual(result.returncode, 0) + self.assertIn("mode=fast ai=false", result.stdout) + + def test_deep_and_explicit_no_ai(self): + result = self.run_status("--deep", "--no-local-rca") + self.assertEqual(result.returncode, 0) + self.assertIn("mode=deep ai=false", result.stdout) + + def test_conflicting_modes_are_rejected(self): + self.assertNotEqual(self.run_status("--fast", "--deep").returncode, 0) + self.assertNotEqual(self.run_status("--fast", "--heal").returncode, 0)