From cfe5c979447fee6202cac505f6a918be5cb0346d Mon Sep 17 00:00:00 2001 From: Jammy2211 Date: Fri, 2 Oct 2026 09:59:48 +0100 Subject: [PATCH] fix: assess complete Heart monitoring in dashboard health scope --- agents/conductors/health/AGENTS.md | 19 +++++ agents/conductors/health/dashboard.py | 99 +++++++++++++++++++++++++++ agents/conductors/health/health.sh | 29 +++++++- agents/faculties/vitals/_vitals.py | 15 ++-- board/AGENTS.md | 6 +- board/_board.py | 18 +++++ skills/health/health.md | 19 +++++ tests/test_board.py | 15 +++- tests/test_health_conductor.py | 88 +++++++++++++++++++++++- tests/test_vitals_pages.py | 6 ++ 10 files changed, 303 insertions(+), 11 deletions(-) create mode 100644 agents/conductors/health/dashboard.py diff --git a/agents/conductors/health/AGENTS.md b/agents/conductors/health/AGENTS.md index 02819c04..03b4757a 100644 --- a/agents/conductors/health/AGENTS.md +++ b/agents/conductors/health/AGENTS.md @@ -152,3 +152,22 @@ machine caller can tell "Heart says STALE" from "Heart unreachable" (`4`). a later, explicitly-scoped follow-up. - **Never escalate an unknown to GREEN or RED.** An unknown is YELLOW — surface it, recommend the leg that resolves it, and checkpoint. + +## Dashboard monitoring scope + +`bin/pyauto-brain health --scope dashboard [--json] [assess|triage|recommend]` +reads Heart's dashboard inventory without ticking, dispatching or writing state. +The default scope remains `release`; `--scope release` makes it explicit. + +Dashboard scope adopts `board.monitoring.status`, `score` and `complete` from +Heart, forwarding its checks, findings, applicability, evidence, penalties, +blocked reasons and action payloads unchanged. It uses the Heart CLI when +available and the existing published-board reader otherwise. Heart owns all +coverage judgments and remedies; the conductor presents them for review. + +Re-read after the chosen action completes. Stop only when Heart reports a +complete green monitoring inventory with no unresolved findings. Release GREEN +alone never ends this loop. Missing, malformed or unsupported inventory is +explicitly unknown and incomplete (exit 4); an incomplete green inventory also +exits 4. Red/yellow/stale retain exits 3/2/6; grey exits 4. Completion exits 0. +The JSON retains `release_verdict` and `release_score` as separate context. diff --git a/agents/conductors/health/dashboard.py b/agents/conductors/health/dashboard.py new file mode 100644 index 00000000..57d4a4b0 --- /dev/null +++ b/agents/conductors/health/dashboard.py @@ -0,0 +1,99 @@ +"""Read Heart's monitoring inventory and forward its findings unchanged.""" + +import argparse +import json +import sys +from pathlib import Path + + +def assess(board): + monitoring = board.get("monitoring") if isinstance(board, dict) else None + error = None + if not isinstance(monitoring, dict): + error = "Heart monitoring inventory is missing." + elif not ( + type(monitoring.get("schema_version")) is int + and monitoring.get("schema_version") == 1 + and monitoring.get("status") in {"green", "red", "yellow", "stale", "grey"} + and type(monitoring.get("score")) is int + and type(monitoring.get("complete")) is bool + and isinstance(monitoring.get("counts"), dict) + and isinstance(monitoring.get("checks"), list) + and isinstance(monitoring.get("findings"), list) + and isinstance(monitoring.get("penalties"), list) + and all(isinstance(c, dict) for c in monitoring["checks"] + monitoring["findings"]) + ): + error = "Heart monitoring inventory is malformed or unsupported." + if error: + return { + "scope": "dashboard", "verdict": "unknown", "score": None, + "complete": False, "status": "unknown", "counts": {}, + "checks": [], "findings": [], "items": [], "penalties": [], + "blocked_reason": error, + "recommendation": {"action": "blocked", "command": None, + "headline": error}, + } + result = dict(monitoring) + # Status and completion are Heart-owned. Preserve all inventory fields, + # including applicability, evidence, blocked reasons and action payloads. + result.update(scope="dashboard", verdict=monitoring["status"], + items=monitoring["findings"], + release_verdict=board.get("verdict"), + release_score=board.get("score")) + findings = monitoring["findings"] + done = monitoring["complete"] and monitoring["status"] == "green" and not findings + first = findings[0] if findings else {} + action = first.get("action") + result["recommendation"] = { + "action": "none" if done else "review-findings" if findings else "blocked", + "command": action.get("payload") if isinstance(action, dict) and action.get("kind") == "command" else None, + "heart_action": action, + "headline": "Monitoring complete — no unresolved findings." if done else + first.get("summary") or "Monitoring incomplete — review Heart inventory coverage.", + "blocked_reason": first.get("blocked_reason"), + } + return result + + +def main(): + parser = argparse.ArgumentParser() + parser.add_argument("--json", action="store_true") + parser.add_argument("--published", action="store_true") + parser.add_argument("--mode", choices=("assess", "triage", "recommend"), default="assess") + args = parser.parse_args() + try: + if args.published: + faculty = Path(__file__).resolve().parents[2] / "faculties" / "vitals" + sys.path.insert(0, str(faculty)) + import _vitals + base, repo = _vitals.pages_source() + board = _vitals.read_published(base, repo)[1] if base else {} + else: + board = json.load(sys.stdin) + except Exception: + board = {} + result = assess(board) + if args.json: + print(json.dumps(result, indent=2)) + else: + print("== health: dashboard monitoring = " + result["status"].upper() + " ==") + print("Monitoring score: " + str(result["score"]) + " · complete: " + str(result["complete"])) + if args.mode != "recommend": + for finding in result["findings"]: + print(" [" + str(finding.get("status", "unknown")) + "] " + str(finding.get("summary", ""))) + action = finding.get("action") + if isinstance(action, dict): + print(" " + str(action.get("payload", ""))) + if finding.get("blocked_reason"): + print(" Blocked: " + str(finding["blocked_reason"])) + print(result["recommendation"]["headline"]) + if args.mode == "recommend" and result["recommendation"].get("heart_action"): + print(json.dumps(result["recommendation"]["heart_action"])) + print("Re-read with pyauto-brain health --scope dashboard; completion requires Heart's complete inventory and no unresolved findings.") + status = result["status"] + done = result["complete"] and status == "green" and not result["findings"] + return 0 if done else {"red": 3, "yellow": 2, "stale": 6}.get(status, 4) + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/agents/conductors/health/health.sh b/agents/conductors/health/health.sh index 712b5b70..b64141ed 100755 --- a/agents/conductors/health/health.sh +++ b/agents/conductors/health/health.sh @@ -45,6 +45,8 @@ # health.sh assess # same as the no-arg assess # health.sh triage # triage + recommend only (no card re-render) # health.sh recommend # the single recommended next checkpoint only +# health.sh --scope dashboard [--json] [sub] # read-only monitoring inventory +# health.sh --scope release [--json] [sub] # default release readiness # health.sh --json [sub] # machine footing for the Brain session # health.sh -h|--help # this header # @@ -70,9 +72,14 @@ source "$HERE/../../_common.sh" # --------------------------------------------------------------------------- sub="assess" json_only=0 -for arg in "$@"; do +scope="release" +while [[ $# -gt 0 ]]; do + arg="$1" + shift case "$arg" in --json) json_only=1 ;; + --scope) scope="${1:-}"; [[ $# -gt 0 ]] && shift ;; + --scope=*) scope="${arg#--scope=}" ;; -h|--help) # Print only the comment header block (stop at the first non-comment line, # so the help never bleeds into `set -uo pipefail` / `source ...`). @@ -89,6 +96,26 @@ for arg in "$@"; do esac done +if [[ "$scope" != "release" && "$scope" != "dashboard" ]]; then + echo "health: scope must be release or dashboard" >&2 + exit 5 +fi + +# Dashboard monitoring is a read-only Heart inventory, with its own completion +# contract. It never refreshes checks, dispatches actions, or consults release +# GREEN as a stopping condition. +if [[ "$scope" == "dashboard" ]]; then + dashboard_args=(--mode "$sub") + [[ "$json_only" -eq 1 ]] && dashboard_args+=(--json) + if heart="$(resolve_heart 2>/dev/null)"; then + bash "$(_agents_dir)/faculties/vitals/vitals.sh" dashboard --json 2>/dev/null | + python3 "$HERE/dashboard.py" "${dashboard_args[@]}" + exit $? + fi + python3 "$HERE/dashboard.py" --published "${dashboard_args[@]}" + exit $? +fi + # --------------------------------------------------------------------------- # Locate the vitals faculty (the single component that talks to Heart) and the # Heart capability manifest (Heart self-describing its surface — never vendored). diff --git a/agents/faculties/vitals/_vitals.py b/agents/faculties/vitals/_vitals.py index d70dc316..c7788388 100755 --- a/agents/faculties/vitals/_vitals.py +++ b/agents/faculties/vitals/_vitals.py @@ -71,16 +71,19 @@ def read_published(pages_base, heart_repo): def verdict_of(badge, board): - """The organism-wide verdict word. The badge's `message` is the headline - contract every board publishes (`GREEN`, `RED 3 blockers`, ...); a board - that carries its own `verdict` is the fallback for a badge that did not - arrive.""" + """The explicit release verdict; older publishes fall back to the badge. + + Current badges headline monitoring, which cannot stand in for a release + gate. Heart retains the release verdict in board.json. + """ + own = str((board or {}).get("verdict", "") or "").strip().upper() + if own in VERDICTS: + return own message = str((badge or {}).get("message", "") or "").strip() head = message.split()[0].upper() if message else "" if head in VERDICTS: return head - own = str((board or {}).get("verdict", "") or "").strip().upper() - return own if own in VERDICTS else "UNKNOWN" + return "UNKNOWN" def board_timestamp(board): diff --git a/board/AGENTS.md b/board/AGENTS.md index c73d22db..f2c0e930 100644 --- a/board/AGENTS.md +++ b/board/AGENTS.md @@ -34,8 +34,10 @@ extra state: each render reads yesterday's page, appends today, caps at 30). **Compose, don't recompute** — the board re-derives nothing. The community section imports the community conductor's `build_scan()`; the resume counts -are parsed from the Mind's own generated `dashboard.md`; readiness comes from -the Heart board's published badge. Every unreachable source degrades into an +are parsed from the Mind's own generated `dashboard.md`; release readiness comes from +the Heart board's explicit `verdict` (older publishes fall back to the badge). +Monitoring headlines use Heart's `monitoring.score`, status and completion; +the published badge can describe monitoring independently of release readiness. Every unreachable source degrades into an honest "Degraded" row, never fabricated content. **Read-only** — the collect half touches only read-only `gh` endpoints and diff --git a/board/_board.py b/board/_board.py index 55de22bb..467fecd3 100755 --- a/board/_board.py +++ b/board/_board.py @@ -915,6 +915,11 @@ def collect(): # One read of the Heart's machine surface, two consumers: the blockers # and the test-performance block. heart_board = fetch_heart_board(pages_base, heart_repo, degraded) + # Badge headlines now describe monitoring; release labels and gates use + # Heart's explicit compatibility verdict from board.json. + if isinstance(heart_board, dict) and heart_board.get("verdict"): + heart = dict(heart or {}) + heart["message"] = str(heart_board["verdict"]).upper() heart_blockers = extract_heart_blockers(heart_board) heart_plan = extract_heart_plan(heart_board) performance = extract_heart_performance( @@ -937,6 +942,7 @@ def collect(): "repo": board_family.get("brain", "PyAutoBrain"), "overnight": overnight, "heart": heart, + "heart_monitoring": (heart_board or {}).get("monitoring"), "heart_blockers": heart_blockers, "heart_plan": heart_plan, "performance": performance, @@ -1233,6 +1239,11 @@ def render_md(data): L.append(f" - {r['blocked_reason']}") L.append("") L.append("## ❤️ Readiness & release") + monitoring = data.get("heart_monitoring") + if isinstance(monitoring, dict) and type(monitoring.get("score")) is int: + L.append(f"- Monitoring score: **{monitoring['score']}/100** — " + f"{monitoring.get('status', 'unknown')} · complete: " + f"{monitoring.get('complete', False)} · `pyauto-brain health --scope dashboard`") if data["heart"]: L.append(f"- Heart verdict: **{data['heart'].get('message', '?')}** — " f"[board]({data['boards'].get('heart', '')}) · re-run via the health skill") @@ -1556,6 +1567,13 @@ def render_html(data): H.append(_plain(text)) H.append("

❤️ Readiness & release

") + monitoring = data.get("heart_monitoring") + if isinstance(monitoring, dict) and type(monitoring.get("score")) is int: + H.append(_row( + "Monitoring score — " + _plain(str(monitoring["score"]) + "/100 · " + + str(monitoring.get("status", "unknown")) + " · complete: " + + str(monitoring.get("complete", False))), + "pyauto-brain health --scope dashboard")) heart_url = data["boards"].get("heart", "") if data["heart"]: msg = data["heart"].get("message", "?") diff --git a/skills/health/health.md b/skills/health/health.md index 5e9979bf..87264228 100644 --- a/skills/health/health.md +++ b/skills/health/health.md @@ -36,3 +36,22 @@ procedures are Heart's. On the shell side, the same vocabulary applies: `health` (git-sync dashboard), `health release`, and `health audit` (see `PyAutoHeart/scripts/health.sh`) — a separate local convenience layer, not this command. + +## Dashboard monitoring scope + +`bin/pyauto-brain health --scope dashboard [--json] [assess|triage|recommend]` +reads Heart's dashboard inventory without ticking, dispatching or writing state. +The default scope remains `release`; `--scope release` makes it explicit. + +Dashboard scope adopts `board.monitoring.status`, `score` and `complete` from +Heart, forwarding its checks, findings, applicability, evidence, penalties, +blocked reasons and action payloads unchanged. It uses the Heart CLI when +available and the existing published-board reader otherwise. Heart owns all +coverage judgments and remedies; the conductor presents them for review. + +Re-read after the chosen action completes. Stop only when Heart reports a +complete green monitoring inventory with no unresolved findings. Release GREEN +alone never ends this loop. Missing, malformed or unsupported inventory is +explicitly unknown and incomplete (exit 4); an incomplete green inventory also +exits 4. Red/yellow/stale retain exits 3/2/6; grey exits 4. Completion exits 0. +The JSON retains `release_verdict` and `release_score` as separate context. diff --git a/tests/test_board.py b/tests/test_board.py index 188952af..1888dc82 100644 --- a/tests/test_board.py +++ b/tests/test_board.py @@ -28,7 +28,7 @@ SURFACE_KEYS = { "generated", "org", "repo", "overnight", "heart", "heart_blockers", - "heart_plan", "performance", + "heart_plan", "heart_monitoring", "performance", "hands", "versions", "community", "resume", "open_issues", "hygiene", "devbox", "autonomy", "doors", "boards", "degraded", "history", # The science organ's own counts (its dashboard.md counts table), None @@ -1094,3 +1094,16 @@ def test_legacy_copy_payload_is_portable_but_terminal_payload_is_unchanged(): page = b._row("Legacy", "/health Inspect & preserve edits") assert 'data-cmd="Use the health skill. Inspect <repo> & preserve edits"' in page assert 'data-cmd="/health"' in b._row("Terminal", "/health", term=True) + + +def test_monitoring_headline_keeps_release_verdict_separate(tmp_path): + heart_board = {**HEART_BOARD_JSON, "verdict": "green", + "monitoring": {"score": 72, "status": "red", "complete": False}} + stub = _fabricate(tmp_path, _default_fixtures(), heart_board) + md = _run([], tmp_path, stub).stdout + assert "Monitoring score: **72/100**" in md + assert "Heart verdict: **GREEN**" in md + page = _run(["--html"], tmp_path, stub).stdout + assert "Monitoring score" in page + assert "72/100" in page + assert "pyauto-brain health --scope dashboard" in page diff --git a/tests/test_health_conductor.py b/tests/test_health_conductor.py index fcccaf08..8468118d 100644 --- a/tests/test_health_conductor.py +++ b/tests/test_health_conductor.py @@ -56,7 +56,7 @@ def _run(tmp_path, readiness, *args): heart = stub_dir / "pyauto-heart" heart.write_text( "#!/usr/bin/env bash\n" - 'if [[ "${1:-}" == "readiness" ]]; then cat "$STUB_READINESS"; fi\n' + 'if [[ "${1:-}" == "readiness" || "${1:-}" == "dashboard" ]]; then cat "$STUB_READINESS"; fi\n' "exit 0\n" ) heart.chmod(0o755) @@ -281,3 +281,89 @@ def test_human_render_shows_the_evidence_gap_section(tmp_path): assert "? [validate] no release validation for current source" in out assert "pyauto-brain release validate" in out assert "UNKNOWN" not in out + + +def _monitoring(**updates): + inventory = {"schema_version": 1, "status": "green", "score": 100, + "complete": True, "counts": {}, "checks": [], + "findings": [], "penalties": []} + inventory.update(updates) + return {"verdict": "green", "score": 100, "monitoring": inventory} + + +def test_dashboard_green_release_preserves_findings_and_actions(tmp_path): + finding = {"id": "ci:a", "family": "ci", "subject": "library-a", + "status": "red", "summary": "CI failed", "owner": "Heart", + "applicable": True, "evidence": {"url": "https://example.test/run"}, + "action": {"kind": "prompt", "payload": "Repair this exact CI failure"}, + "blocked_reason": None} + board = _monitoring(status="red", score=85, complete=False, + findings=[finding], checks=[finding]) + result = _run(tmp_path, board, "--scope", "dashboard", "--json") + data = json.loads(result.stdout) + assert result.returncode == EXIT_RED + assert data["score"] == 85 + assert data["release_verdict"] == "green" + assert data["findings"] == [finding] + assert data["recommendation"]["heart_action"] == finding["action"] + + +def test_dashboard_complete_inventory_stops(tmp_path): + result = _run(tmp_path, _monitoring(), "--scope=dashboard", "--json") + assert result.returncode == EXIT_GREEN + assert json.loads(result.stdout)["complete"] is True + + +def test_dashboard_incomplete_green_inventory_cannot_stop(tmp_path): + result = _run(tmp_path, _monitoring(complete=False), "--scope", "dashboard", "--json") + assert result.returncode == EXIT_UNKNOWN + data = json.loads(result.stdout) + assert data["complete"] is False + assert data["recommendation"]["action"] == "blocked" + + +def test_dashboard_missing_or_malformed_inventory_is_explicit(tmp_path): + for inventory in (None, {}, {"schema_version": 1}, "broken"): + result = _run(tmp_path, {"verdict": "green", "monitoring": inventory}, + "--scope", "dashboard", "--json") + assert result.returncode == EXIT_UNKNOWN + data = json.loads(result.stdout) + assert data["complete"] is False + assert "inventory" in data["blocked_reason"] + + +def test_dashboard_human_read_forwards_command_and_blocked_reason(tmp_path): + finding = {"status": "stale", "summary": "Inventory unavailable", + "blocked_reason": "Token unavailable", + "action": {"kind": "command", "payload": "pyauto-heart tick"}} + result = _run(tmp_path, _monitoring(status="stale", complete=False, + findings=[finding]), "--scope", "dashboard") + assert result.returncode == EXIT_STALE + assert "Token unavailable" in result.stdout + assert "pyauto-heart tick" in result.stdout + assert "release-healthy" not in result.stdout + + +def test_release_scope_remains_compatible(tmp_path): + result = _run(tmp_path, {"verdict": "green", "score": 100}, + "--scope", "release", "--json") + assert result.returncode == EXIT_GREEN + assert json.loads(result.stdout)["recommendation"]["action"] == "none" + + +def test_unknown_health_scope_is_usage_error(tmp_path): + assert _run(tmp_path, {}, "--scope", "unrecognised").returncode == EXIT_USAGE + + +def test_dashboard_statuses_and_inconsistent_findings_never_report_completion(tmp_path): + for status, expected in (("grey", EXIT_UNKNOWN), ("yellow", EXIT_YELLOW), + ("stale", EXIT_STALE), ("red", EXIT_RED)): + result = _run(tmp_path, _monitoring(status=status, complete=False), + "--scope", "dashboard", "--json") + assert result.returncode == expected + assert json.loads(result.stdout)["status"] == status + finding = {"status": "yellow", "summary": "Still unresolved"} + result = _run(tmp_path, _monitoring(findings=[finding]), + "--scope", "dashboard", "--json") + assert result.returncode == EXIT_UNKNOWN + assert json.loads(result.stdout)["findings"] == [finding] diff --git a/tests/test_vitals_pages.py b/tests/test_vitals_pages.py index 16d3cc40..2f8605b9 100644 --- a/tests/test_vitals_pages.py +++ b/tests/test_vitals_pages.py @@ -133,3 +133,9 @@ def test_blockers_are_never_capped_out_of_a_scoped_read(published, monkeypatch, assert _vitals.main(["--scope", "RepoA"]) == 0 out = capsys.readouterr().out assert "RepoA: install verification not run" in out + + +def test_release_verdict_uses_board_when_badge_describes_monitoring(): + badge = {"message": "Monitoring RED · 72; release GREEN"} + assert _vitals.verdict_of(badge, {"verdict": "green"}) == "GREEN" + assert _vitals.verdict_of({"message": "GREEN"}, {"verdict": "red"}) == "RED"