Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion agents/conductors/health/AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,11 @@ 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
available and the existing published-board reader otherwise. A Heart CLI that
answers with no JSON board at all (a checkout that has never ticked, as in a
cloud session) also falls back to the published board; a local board that
parses but lacks or mangles its inventory is never replaced. The JSON names the
board it read in `source` (`local` or `published`). 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
Expand Down
45 changes: 37 additions & 8 deletions agents/conductors/health/dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,29 +55,58 @@ def assess(board):
return result


def _read_local(text):
"""The local Heart's board, or None when it printed no JSON object."""
try:
board = json.loads(text)
except ValueError:
return None
return board if isinstance(board, dict) else None


def _read_published():
faculty = Path(__file__).resolve().parents[2] / "faculties" / "vitals"
sys.path.insert(0, str(faculty))
import _vitals
base, repo = _vitals.pages_source()
return _vitals.read_published(base, repo)[1] if base else {}


def main():
parser = argparse.ArgumentParser()
parser.add_argument("--json", action="store_true")
parser.add_argument("--published", action="store_true")
parser.add_argument("--published-fallback", action="store_true",
help="read stdin, but fall back to the published board "
"when the local Heart printed no JSON board "
"(e.g. a checkout that has never ticked)")
parser.add_argument("--mode", choices=("assess", "triage", "recommend"), default="assess")
args = parser.parse_args()
source = "published" if args.published else "local"
board = {}
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 {}
board = _read_published()
else:
board = json.load(sys.stdin)
board = _read_local(sys.stdin.read())
if board is None and args.published_fallback:
# The local Heart answered with no board at all (it prints
# "No cache yet" before its first tick). That is an absent
# local vantage, not an inventory verdict: read the published
# board instead. A local board that parses but lacks or
# mangles its inventory is NOT replaced — that stays explicit.
source = "published"
board = _read_published()
except Exception:
board = {}
result = assess(board)
result = assess(board if isinstance(board, dict) else {})
result["source"] = source
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"]))
print("Monitoring score: " + str(result["score"]) + " · complete: " + str(result["complete"])
+ " · source: " + result["source"])
if args.mode != "recommend":
for finding in result["findings"]:
print(" [" + str(finding.get("status", "unknown")) + "] " + str(finding.get("summary", "")))
Expand Down
2 changes: 1 addition & 1 deletion agents/conductors/health/health.sh
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ if [[ "$scope" == "dashboard" ]]; then
[[ "$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[@]}"
python3 "$HERE/dashboard.py" --published-fallback "${dashboard_args[@]}"
exit $?
fi
python3 "$HERE/dashboard.py" --published "${dashboard_args[@]}"
Expand Down
51 changes: 51 additions & 0 deletions tests/test_health_conductor.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,3 +367,54 @@ def test_dashboard_statuses_and_inconsistent_findings_never_report_completion(tm
"--scope", "dashboard", "--json")
assert result.returncode == EXIT_UNKNOWN
assert json.loads(result.stdout)["findings"] == [finding]


def _run_no_local_cache(tmp_path, published, *args):
"""A Heart CLI that has never ticked (prints prose, no JSON board), with the
published board served from a local Pages mirror."""
stub_dir = tmp_path / "bin"
stub_dir.mkdir(exist_ok=True)
heart = stub_dir / "pyauto-heart"
heart.write_text("#!/usr/bin/env bash\n"
"echo 'No cache yet — run `pyauto-heart tick` first'\nexit 0\n")
heart.chmod(0o755)
pages = tmp_path / "pages" / "PyAutoHeart"
pages.mkdir(parents=True, exist_ok=True)
if published is not None:
(pages / "board.json").write_text(json.dumps(published))
empty_heart_repo = tmp_path / "no_heart_checkout"
empty_heart_repo.mkdir(exist_ok=True)
env = dict(os.environ)
env["PATH"] = f"{stub_dir}{os.pathsep}{env['PATH']}"
env["PYAUTO_HEART"] = str(empty_heart_repo)
env["BOARD_PAGES_BASE"] = (tmp_path / "pages").as_uri()
return subprocess.run([str(BRAIN), "health", *args],
capture_output=True, text=True, env=env)


def test_dashboard_without_a_local_cache_reads_the_published_board(tmp_path):
finding = {"id": "ci:a", "status": "red", "summary": "CI failed"}
board = _monitoring(status="red", score=27, complete=False,
findings=[finding], checks=[finding])
result = _run_no_local_cache(tmp_path, board, "--scope", "dashboard", "--json")
data = json.loads(result.stdout)
assert result.returncode == EXIT_RED
assert data["source"] == "published"
assert data["score"] == 27
assert data["findings"] == [finding]


def test_dashboard_without_local_cache_or_published_board_stays_unknown(tmp_path):
result = _run_no_local_cache(tmp_path, None, "--scope", "dashboard", "--json")
data = json.loads(result.stdout)
assert result.returncode == EXIT_UNKNOWN
assert data["complete"] is False
assert "inventory" in data["blocked_reason"]


def test_dashboard_local_board_is_never_replaced_by_the_published_one(tmp_path):
result = _run(tmp_path, {"verdict": "green", "monitoring": None},
"--scope", "dashboard", "--json")
data = json.loads(result.stdout)
assert result.returncode == EXIT_UNKNOWN
assert data["source"] == "local"
Loading