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
44 changes: 41 additions & 3 deletions scripts/organism_board.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -275,7 +307,7 @@ def _render_html(snapshot: dict) -> str:
f"{_html.escape(b['name'])}</a>" if b.get("url")
else _html.escape(b["name"]))
rows.append(
f"<div class='organ'>"
f"<div class='organ' id='{_row_id(b['name'])}'>"
f"{_copy_btn(b['door'], 'copy the door command for an AI assistant chat')}"
f"<p><span class='name'>{link}</span> "
f"<span class='head'>{head}</span>"
Expand All @@ -290,7 +322,10 @@ def _render_html(snapshot: dict) -> str:
gh_owner = snapshot.get("owner")
github_link = (f' · <a href="https://github.com/{gh_owner}/PyAutoScientist'
'/blob/main/README.md">GitHub Page</a>' if gh_owner else "")
return f"""<!doctype html>
# 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"""<!doctype html>
<html lang="en"><head><meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>PyAutoScientist Dashboard</title>
Expand All @@ -300,13 +335,16 @@ def _render_html(snapshot: dict) -> str:
{hero}
{panel}
<p class="verdict {_VERDICT_CLS.get(word, '')}"><b>{_html.escape(route_hint(snapshot))}</b></p>
<section class="dashboards">
<h2 id="{SECTION_ID}">Organ dashboards</h2>
{''.join(rows)}
</section>
<p class="muted mdsrc"><a href="dashboard.md">markdown version</a>{github_link}</p>
<footer>Rendered by <code>scripts/organism_board.py</code> from the boards'
own published headlines · generated {_html.escape(str(snapshot.get('generated') or '?'))}.</footer>
<script>{t.JS}</script>
</body></html>
"""
""", section_summaries(snapshot))


def badge_endpoint(snapshot: dict) -> dict:
Expand Down
41 changes: 41 additions & 0 deletions tests/test_organism_board.py
Original file line number Diff line number Diff line change
Expand Up @@ -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('<details class="board-section">')
assert panel < nav < verdict < section
# Collapsed by default, one disclosure, the routing answer left outside it.
assert out.count('<details class="board-section"') == 1
assert '<details class="board-section" open' not in out
assert out.index('<h2 id="dashboards">') > section
# Every organ row keeps a stable fragment inside the disclosure, and the
# door chips survive the wrapping.
body = out[section:out.index("</details>", 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('<details class="board-section"><summary>')
summary = out[start:out.index("</summary>", start)]
assert '<span class="section-badge">3 of 4 reporting</span>' in summary
assert '<span class="section-badge section-status-red">Heart RED</span>' 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"
Loading