diff --git a/scripts/organism_board.py b/scripts/organism_board.py index ae1eaa5..1ae9ea7 100644 --- a/scripts/organism_board.py +++ b/scripts/organism_board.py @@ -234,6 +234,38 @@ def _copy_btn(payload: str, label: str = "copy") -> str: # would say something the page does not know. _VERDICT_CLS = {"RED": "bad", "YELLOW": "warn", "STALE": "warn", "GREEN": "ok"} +# The same word in the shared section-status vocabulary (Brain +# ``section_layout``). Anything the Heart did not say — an unreadable badge, an +# unfamiliar word — is "unknown", never green. +_SECTION_STATUS = {"RED": "red", "YELLOW": "yellow", "STALE": "stale", "GREEN": "green"} + +SECTION_ID = "dashboards" + + +def _row_id(name: str) -> str: + """The stable fragment of one organ row (``#board-heart``).""" + return "board-" + re.sub(r"[^a-z0-9]+", "-", name.lower()).strip("-") + + +def section_summaries(snapshot: dict) -> dict: + """Owner-computed header facts for the collapsed "Organ dashboards" section. + + The count is how many boards actually answered out of how many are listed, + so a missing headline reads as a gap ("4 of 5 reporting"), not as a quiet + zero. The status is the Heart's own word, labelled as such; it routes, it + does not restate release readiness. + """ + rows = snapshot.get("boards") or [] + word = heart_word(snapshot) + info: dict = { + "status": _SECTION_STATUS.get(word, "unknown"), + "label": "Heart " + (word if word in _SECTION_STATUS else "unknown"), + } + if rows: + live = sum(1 for b in rows if b.get("headline")) + info["count"] = f"{live} of {len(rows)} reporting" + return {SECTION_ID: info} + # What the shared sheet has no opinion on: this board is a router, so its one # page-specific shape is the organ row — a name, that board's own headline, # and what it is for. Written against the theme's variables, so it follows the @@ -275,7 +307,7 @@ def _render_html(snapshot: dict) -> str: f"{_html.escape(b['name'])}" if b.get("url") else _html.escape(b["name"])) rows.append( - f"
" + f"
" f"{_copy_btn(b['door'], 'copy the door command for an AI assistant chat')}" f"

{link} " f"{head}" @@ -290,7 +322,10 @@ def _render_html(snapshot: dict) -> str: gh_owner = snapshot.get("owner") github_link = (f' · GitHub Page' if gh_owner else "") - return f""" + # Brain's shared layout puts the slogan panel above the navigation cards + # and folds the titled section into a collapsed native disclosure; the + # verdict banner stays outside it so the routing answer is always visible. + return t.section_layout(f""" PyAutoScientist Dashboard @@ -300,13 +335,16 @@ def _render_html(snapshot: dict) -> str: {hero} {panel}

{_html.escape(route_hint(snapshot))}

+
+

Organ dashboards

{''.join(rows)} +

markdown version{github_link}

Rendered by scripts/organism_board.py from the boards' own published headlines · generated {_html.escape(str(snapshot.get('generated') or '?'))}.
-""" +""", section_summaries(snapshot)) def badge_endpoint(snapshot: dict) -> dict: diff --git a/tests/test_organism_board.py b/tests/test_organism_board.py index 67faffc..2ae1830 100644 --- a/tests/test_organism_board.py +++ b/tests/test_organism_board.py @@ -152,3 +152,44 @@ def test_panel_refresh_uses_router_capture(monkeypatch): snap["boards"] = [] ob.render(snap, "html") assert calls[-1]["refreshed_at"] is None + + +def test_shared_layout_puts_slogan_above_cards_and_folds_the_section(): + out = ob.render(_snap("YELLOW · 70", "yellow"), "html") + panel = out.index("data-orchestration-panel") + nav = out.index('class="board-nav"') + verdict = out.index('class="verdict') + section = out.index('
') + assert panel < nav < verdict < section + # Collapsed by default, one disclosure, the routing answer left outside it. + assert out.count('
') > section + # Every organ row keeps a stable fragment inside the disclosure, and the + # door chips survive the wrapping. + body = out[section:out.index("
", section)] + for name in ("mind", "heart", "hands", "memory"): + assert f"id='board-{name}'" in body + assert body.count("copy the door command") == 4 + + +def test_section_header_counts_live_boards_and_labels_the_heart(): + out = ob.render(_snap("RED · 40", "red"), "html") + start = out.index('
') + summary = out[start:out.index("", start)] + assert '3 of 4 reporting' in summary + assert 'Heart RED' in summary + + +def test_missing_evidence_is_never_green_or_zero(): + snap = _snap() + for row in snap["boards"]: + row["headline"] = None + info = ob.section_summaries(snap)["dashboards"] + assert info == {"status": "unknown", "label": "Heart unknown", + "count": "0 of 4 reporting"} + snap["boards"] = [] + assert ob.section_summaries(snap)["dashboards"] == { + "status": "unknown", "label": "Heart unknown"} + assert ob.section_summaries(_snap("STALE · 65"))["dashboards"]["status"] == "stale" + assert ob.section_summaries(_snap("WHATEVER"))["dashboards"]["status"] == "unknown"