diff --git a/agents/conductors/cortex/_cortex.py b/agents/conductors/cortex/_cortex.py index b194d074..b9b24471 100644 --- a/agents/conductors/cortex/_cortex.py +++ b/agents/conductors/cortex/_cortex.py @@ -347,6 +347,17 @@ def _clip(text: str, n: int) -> str: return text if len(text) <= n else text[:n - 1].rstrip() + "…" +def _clipped(text: str, n: int) -> bool: + """Whether `_clip` would shorten the text.""" + return len(" ".join((text or "").split())) > n + + +def _md_text(value: str) -> str: + """Ledger prose inside a markdown fold: `<` and `&` as entities, so a + literal `` in a ledger line cannot close the card on GitHub.""" + return str(value).replace("&", "&").replace("<", "<") + + def _cell(value: str) -> str: return str(value).replace("|", "\\|") @@ -462,65 +473,141 @@ def _ledger_link(d: dict, blob: str) -> str: return f"{blob}{d['rel']}" if blob else d["rel"] -def _facts_md(d: dict, blob: str) -> str: - issue = (f"[{d['issue']}]({d['issue_url']})" if d["issue_url"] - else "no issue yet") - return (f"{d['status']} · {d['partition']} · {issue} · " - f"[{d['rel']}]({_ledger_link(d, blob)}) · " - f"local `{_cell(d['local_path'])}` · RAL `{_cell(d['ral_root'])}`") +def run_line(r: dict) -> str: + """One run as a terminal line (the check-in read-back).""" + return (f"{r['ident']} — {r['state']} — {r['partition']} — {r['date']} — " + f"{_clip(r['what'], RUN_CLIP)}") -def _facts_html(d: dict, blob: str) -> str: - issue = (f'{_esc(d["issue"])}' - if d["issue_url"] else "no issue yet") - return (f"{_esc(d['status'])} · {_esc(d['partition'])} · {issue} · " - f'{_esc(d["rel"])} · ' - f'local {_esc(d["local_path"])} · ' - f'RAL {_esc(d["ral_root"])}') +# A project is one disclosure: the closed summary is everything a glance +# needs (name, purpose, the recorded run counts, the ledger's newest date); +# opening it shows the current position, the resume chip, the runs as an +# aligned table, and — each collapsed again — the recent history and the +# technical locations. Every field is the parsed ledger's own; nothing is +# read out of a run's prose. +LOG_SHOWN = 5 -def run_line(r: dict) -> str: - return (f"{r['ident']} — {r['state']} — {r['partition']} — {r['date']} — " - f"{_clip(r['what'], RUN_CLIP)}") +def _overview(d: dict) -> tuple[int, int, str]: + running = sum(1 for r in d["runs"] if r["state"] == "running") + open_ = sum(1 for r in d["runs"] if r["state"] == "open") + return running, open_, d["updated"] or "-" + + +def _overview_text(d: dict) -> str: + """The closed card's meta line, in words (both pages).""" + running, open_, updated = _overview(d) + runs = (f"{running} running · {open_} open" if d["runs"] + else "no runs recorded") + status = "" if d["status"] == "active" else f"{d['status']} · " + return f"{status}{runs} · updated {updated}" + + +def _history_label(d: dict) -> str: + shown = min(LOG_SHOWN, len(d["log"])) + if not d["log"]: + return "Recent log — empty" + noun = "entry" if len(d["log"]) == 1 else "entries" + return f"Recent log — {shown} of {len(d['log'])} {noun}" def _card_md(d: dict, row: dict, blob: str) -> list[str]: - L = [f"### {d['key']} — {_cell(d['summary'])}", "", _facts_md(d, blob), "", - "**Now**", "", d["now"] or "_(nothing yet)_", "", "**Runs**", ""] - L += [f"- {_cell(run_line(r))}" for r in d["runs"]] or ["- _nothing on the cluster_"] - L += ["", "**Last 5**", ""] - L += [f"- {e['date']} — *{e['kind']}* — {_cell(_clip(e['text'], LOG_CLIP))}" - for e in d["log"][:5]] or ["- _empty_"] - L += ["", f"[full log]({_ledger_link(d, blob)})", ""] + issue = (f"[{d['issue']}]({d['issue_url']})" if d["issue_url"] + else "no issue yet") + L = [f'
{_esc(d["key"])} — ' + f"{_esc(d['summary'])} · {_esc(_overview_text(d))}", "", + f"{d['status']} · {d['partition']} · {issue}", "", + "**Current position**", "", _md_text(d["now"]) or "_(nothing yet)_", ""] if d["status"] == "active": L += [_task_row(f"resume {d['key']}", resume_payload(d["key"], row)), ""] + L += [f"**Runs** ({len(d['runs'])})", ""] + if d["runs"]: + L += ["| Job | State | Partition | Date | Description |", + "|---|---|---|---|---|"] + L += [f"| `{r['ident']}` | {r['state']} | {_cell(r['partition'])} | " + f"{r['date']} | {_cell(_md_text(_clip(r['what'], RUN_CLIP)))} |" + for r in d["runs"]] + clipped = [r for r in d["runs"] if _clipped(r["what"], RUN_CLIP)] + if clipped: + L += ["", f"
Full descriptions ({len(clipped)} " + "shortened above)", ""] + L += [f"- `{r['ident']}` — {_md_text(r['what'])}" for r in clipped] + L += ["", "
"] + else: + L.append("_nothing on the cluster_") + L += ["", f"
{_history_label(d)}", ""] + L += [f"- {e['date']} — *{e['kind']}* — {_md_text(e['text'])}" + for e in d["log"][:LOG_SHOWN]] or ["- _empty_"] + L += ["", f"[full log]({_ledger_link(d, blob)})", "", "
", "", + "
Locations", "", + f"- Ledger: [{d['rel']}]({_ledger_link(d, blob)})", + f"- Local: `` {d['local_path']} ``", + f"- RAL: `` {d['ral_root']} ``", "", "
", "", "
", ""] return L +def _full_text_html(text: str, clip: int) -> str: + """A description that fits is plain text; a longer one is a disclosure + whose summary is the clipped line and whose body is the whole text — + keyboard-reachable (`` is focusable) and never truncated away.""" + if not _clipped(text, clip): + return _esc(text) + short = _clip(text, clip) + return (f'
{_esc(short)}' + f'show less' + f"

{_esc(text)}

") + + +def _runs_table_html(d: dict) -> list[str]: + if not d["runs"]: + return ['

nothing on the cluster

'] + H = [f'', + '' + '' + '', ""] + for r in d["runs"]: + tone = "y" if r["state"] == "running" else "n" + H.append(f'' + f'' + f'' + f'' + f'') + H += ["", "
JobStatePartitionDateDescription
{_esc(r["ident"])}{_esc(r["state"])}{_esc(r["partition"])}{_esc(r["date"])}{_full_text_html(r["what"], RUN_CLIP)}
"] + return H + + def _card_html(d: dict, row: dict, blob: str) -> list[str]: - H = ['
', - f"

{_esc(d['key'])} — {_esc(d['summary'])}

", - f'

{_facts_html(d, blob)}

', - "

Now

", + issue = (f'{_esc(d["issue"])}' + if d["issue_url"] else "no issue yet") + H = [f'
', + f'

{_esc(d["key"])}

' + f'{_esc(d["summary"])}' + f'{_esc(_overview_text(d))}
', + '
', + f'

{_esc(d["status"])} · {_esc(d["partition"])} · {issue}

', + "

Current position

", "

" + ("
".join(_esc(x) for x in d["now"].split("\n")) if d["now"] else '(nothing yet)') - + "

", - "

Runs

"] - if d["runs"]: - H += ["
    "] + [f"
  • {_esc(run_line(r))}
  • " for r in d["runs"]] + ["
"] - else: - H.append('

nothing on the cluster

') - H.append("

Last 5

") + + "

"] + if d["status"] == "active": + H.append(_html_task(f"resume {_esc(d['key'])}", resume_payload(d["key"], row))) + H.append(f"

Runs ({len(d['runs'])})

") + H += _runs_table_html(d) + H.append(f'
{_esc(_history_label(d))}') if d["log"]: - H += ["
    "] + [f"
  • {_esc(e['date'])} — {_esc(e['kind'])} — " - f"{_esc(_clip(e['text'], LOG_CLIP))}
  • " - for e in d["log"][:5]] + ["
"] + H += ['
    '] + [ + f"
  • {_esc(e['date'])} — {_esc(e['kind'])} — " + f"{_full_text_html(e['text'], LOG_CLIP)}
  • " + for e in d["log"][:LOG_SHOWN]] + ["
"] else: H.append('

empty

') - H.append(f'

full log

') - if d["status"] == "active": - H.append(_html_task(f"resume {_esc(d['key'])}", resume_payload(d["key"], row))) - H.append("
") + H += [f'

full log

', + "", + '
Locations
', + f'
Ledger
{_esc(d["rel"])}
', + f'
Local
{_esc(d["local_path"])}
', + f'
RAL
{_esc(d["ral_root"])}
', + "
", "", ""] return H @@ -595,7 +682,41 @@ def render_dashboard(c: dict) -> str: "table.map{width:100%;border-collapse:collapse;font-size:.95em}" "table.map th{text-align:left;color:var(--muted);font-weight:600}" "table.map td,table.map th{border-bottom:1px solid var(--line);padding:.4rem .5rem .4rem 0;vertical-align:top}" - ".project h3{font-size:1.35rem;font-weight:700;padding-bottom:.2rem;border-bottom:2px solid var(--accent);letter-spacing:.01em;margin-top:1.6rem}" + # one project = one disclosure; the closed summary is a wrapping row + "details.project{margin:.6rem 0;border:1px solid var(--line);border-radius:10px;padding:0}" + "details.project>summary{display:flex;flex-wrap:wrap;align-items:baseline;gap:.2rem .7rem;padding:.75rem 1rem;min-height:48px;list-style:none;color:var(--fg);font-weight:400}" + "details.project>summary::-webkit-details-marker{display:none}" + "details.project>summary::before{content:\"\u25b8\";color:var(--accent);flex:none}" + "details.project[open]>summary::before{content:\"\u25be\"}" + "details.project>summary:focus-visible,details.full>summary:focus-visible,details.sub>summary:focus-visible{outline:3px solid var(--accent);outline-offset:2px}" + "details.project>summary h3{display:inline;margin:0;padding:0;border:0;font-size:1.1rem;font-weight:700}" + "details.project .purpose{flex:1 1 18rem;min-width:0}" + "details.project .meta{color:var(--muted);font-size:.88em;font-variant-numeric:tabular-nums}" + ".project-body{padding:0 1rem .8rem;border-top:1px solid var(--line)}" + ".project-body h4{margin:1rem 0 .4rem;font-size:1rem}" + # the runs: aligned columns on a wide screen, stacked rows on a phone + "table.runs{width:100%;border-collapse:collapse;font-size:.92em}" + "table.runs th{text-align:left;color:var(--muted);font-weight:600;white-space:nowrap;overflow-wrap:normal}" + "table.runs td,table.runs th{border-bottom:1px solid var(--line);padding:.35rem .7rem .35rem 0;vertical-align:top}" + "table.runs td.job,table.runs td.date,table.runs td.part,table.runs td.state{white-space:nowrap;font-variant-numeric:tabular-nums}" + "table.runs td.what{width:100%}" + "details.full,details.sub{margin:0}" + "details.full>summary{font-weight:400;color:inherit;padding:0}" + "details.full>summary .less{display:none;color:var(--muted)}" + "details.full[open]>summary .clip{display:none}" + "details.full[open]>summary .less{display:inline}" + "details.full>p{margin:.2rem 0 0}" + "details.sub{margin:.6rem 0}" + "ul.log{margin:.3rem 0;padding-left:1.2rem}" + "dl.where{display:grid;grid-template-columns:max-content minmax(0,1fr);gap:.3rem .8rem;margin:.4rem 0}" + "dl.where dd{margin:0;min-width:0}" + "@media(max-width:34rem){" + "table.runs,table.runs tbody{display:block}" + "table.runs thead{position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0 0 0 0)}" + "table.runs tr{display:flex;flex-wrap:wrap;align-items:baseline;gap:0 .6rem;padding:.5rem 0;border-bottom:1px solid var(--line)}" + "table.runs td{display:block;border:0;padding:0}" + "table.runs td[data-label]::before{content:attr(data-label) \": \";color:var(--muted);font-size:.85em}" + "table.runs td.what{flex:1 0 100%;margin-top:.15rem}}" ".pathchip{display:inline-block;background:var(--accent);color:#fff;font-family:ui-monospace,SFMono-Regular,Menlo,monospace;font-size:.88em;padding:.12em .5em;border-radius:.3rem;overflow-wrap:anywhere}" "@media(prefers-color-scheme:dark){.pathchip{background:color-mix(in srgb,var(--accent) 55%,#000)}}" ".stale{color:var(--bad);font-weight:600}") diff --git a/tests/test_cortex_conductor.py b/tests/test_cortex_conductor.py index 4adcf612..92209773 100644 --- a/tests/test_cortex_conductor.py +++ b/tests/test_cortex_conductor.py @@ -208,25 +208,71 @@ def test_one_resume_chip_per_active_project_and_no_other_chips(skeleton): assert "retire" not in page.lower().replace("retired", "") -def test_a_project_card_shows_now_runs_and_the_last_five(skeleton): +def _md_card(page: str, key: str) -> str: + """One project's disclosure in dashboard.md, opening tag to its close.""" + start = page.index(f'
') + # the card's own close is the `
` that ends a blank-line block + # after the Locations fold + loc = page.index("
Locations", start) + close = "
\n\n" + return page[start:page.index(close, loc) + len(close)] + + +def test_a_project_is_a_collapsed_disclosure_with_a_compact_overview(skeleton): + page = _cortex.render_dashboard(_cortex.census(skeleton)) + card = _md_card(page, "example") + head = card.splitlines()[0] + assert head == ('
example — Does the ' + "example pipeline recover the truth on the fixture lens · 1 running " + "· 1 open · updated 2026-09-02") + assert "
") + + +def test_an_expanded_card_shows_position_runs_table_history_and_locations(skeleton): page = _cortex.render_dashboard(_cortex.census(skeleton)) - card = page.split("### example — ")[1].split("### single — ")[0] - assert card.startswith("Does the example pipeline recover the truth on the fixture lens") + card = _md_card(page, "example") assert (f"active · both · [example#7](https://github.com/{_owner()}/example/" - "issues/7) · [projects/example.md](projects/example.md) · local " - "`/tmp/example` · RAL `/mnt/ral/example`") in card - assert "**Now**\n\nWave 2 is on the cluster" in card - assert "- 3002_[0-3] — running — ral — 2026-09-01 — wave 2, four seeds" in card - assert "- 3003 — open — gpu — 2026-09-02 — joint fit on the same four seeds chained" in card - last = card.split("**Last 5**")[1].split("[full log]")[0] + "issues/7)") in card + assert "**Current position**\n\nWave 2 is on the cluster" in card + assert "**Runs** (2)\n\n| Job | State | Partition | Date | Description |\n|---|---|---|---|---|\n" in card + assert "| `3002_[0-3]` | running | ral | 2026-09-01 | wave 2, four seeds on the corrected settings |" in card + assert ("| `3003` | open | gpu | 2026-09-02 | joint fit on the same four seeds " + "chained after 3002 with afterok |") in card + # the order is resume chip → runs → history → locations + assert (card.index("📋 resume example") < card.index("**Runs**") + < card.index("Recent log — 5 of 7 entries") + < card.index("Locations")) + last = card.split("Recent log — 5 of 7 entries")[1].split("[full log]")[0] assert len([ln for ln in last.splitlines() if ln.startswith("- ")]) == 5 assert "- 2026-09-01 — *lesson* — the adapt image" in last assert "3001_[0-3] submitted" not in last # the sixth entry - single = page.split("### single — ")[1] - assert "no issue yet" in single and "- _nothing on the cluster_" in single + where = card.split("Locations")[1] + assert "- Ledger: [projects/example.md](projects/example.md)" in where + assert "- Local: `` /tmp/example ``" in where and "- RAL: `` /mnt/ral/example ``" in where + single = _md_card(page, "single") + assert "no issue yet" in single and "**Runs** (0)\n\n_nothing on the cluster_" in single + assert "Recent log — 1 of 1 entry" in single -def test_run_and_log_text_are_truncated_on_the_card(tmp_skeleton): +def test_an_empty_ledger_renders_every_fold_without_inventing_content(tmp_skeleton): + led = tmp_skeleton / "projects" / "single.md" + led.write_text(led.read_text(encoding="utf-8").replace( + "- 2026-09-01 — note — ledger opened\n", ""), encoding="utf-8") + c = _cortex.census(tmp_skeleton) + page = _cortex.render_dashboard(c) + card = _md_card(page, "single") + assert "· no runs recorded · updated -
" in card + assert "Recent log — empty\n\n- _empty_" in card + html = _cortex.render_dashboard_html(c) + body = html.split('id="project-single"')[1].split('id="project-')[0] + assert "no runs recorded · updated -" in body + assert '

nothing on the cluster

' in body + assert "Recent log — empty" in body and '

empty

' in body + + +def test_long_run_and_log_text_is_shortened_with_the_full_text_one_step_away(tmp_skeleton): led = tmp_skeleton / "projects" / "example.md" text = led.read_text(encoding="utf-8") long_what = "w" * 300 @@ -236,30 +282,45 @@ def test_run_and_log_text_are_truncated_on_the_card(tmp_skeleton): text = text.replace("- 2026-09-02 — run — 3003 submitted: joint fit on the same four seeds", f"- 2026-09-02 — note — {long_note}") led.write_text(text, encoding="utf-8") - page = _cortex.render_dashboard(_cortex.census(tmp_skeleton)) - run = re.search(r"^- 3003 — open — gpu — 2026-09-02 — (w+…)$", page, re.M) + c = _cortex.census(tmp_skeleton) + page = _cortex.render_dashboard(c) + run = re.search(r"^\| `3003` \| open \| gpu \| 2026-09-02 \| (w+…) \|$", page, re.M) assert run and len(run.group(1)) == _cortex.RUN_CLIP - note = re.search(r"^- 2026-09-02 — \*note\* — (n+…)$", page, re.M) - assert note and len(note.group(1)) == _cortex.LOG_CLIP - assert long_what not in page and long_note not in page + full = page.split("Full descriptions (1 shortened above)")[1] + assert f"- `3003` — {long_what} chained after 3002 with afterok" in full.split("")[0] + assert f"- 2026-09-02 — *note* — {long_note}" in page # the folded history is whole + led.write_text(led.read_text(encoding="utf-8").replace(long_note, "a b"), + encoding="utf-8") + assert "a </details> b" in _cortex.render_dashboard(_cortex.census(tmp_skeleton)) + html = _cortex.render_dashboard_html(c) + cell = re.search(r'
' + r'(w+…)show less' + r"

(w+[^<]*)

", html) + assert cell and len(cell.group(1)) == _cortex.RUN_CLIP + assert cell.group(2) == f"{long_what} chained after 3002 with afterok" + assert f'{"n" * (_cortex.LOG_CLIP - 1)}…' in html + assert f"

{long_note}

" in html + # a short description is plain text, not a disclosure + assert ('wave 2, four seeds on the corrected settings') in html def test_retired_projects_fold_and_dormant_rows_without_a_ledger_table(skeleton): page = _cortex.render_dashboard(_cortex.census(skeleton)) - assert "### wound_down" not in page + assert 'id="project-wound_down"' not in page fold = page.split("
1 retired")[1].split("
")[0] assert "[wound_down](projects/wound_down.md) — A project that finished and was retired — retired 2026-09-01: done" in fold table = page.split("#### No ledger")[1] assert "| Project | Status | Note |" in table assert "| sleeping | dormant | no ledger yet |" in table - assert "### sleeping" not in page + assert 'id="project-sleeping"' not in page def test_active_cards_lead_and_a_broken_tree_is_said_out_loud(tmp_skeleton): """The card order is projects.yaml order, active first; a tree that does not check says so on the page rather than rendering as if it did.""" page = _cortex.render_dashboard(_cortex.census(tmp_skeleton)) - assert page.index("### example — ") < page.index("### single — ") < page.index("1 retired") + assert (page.index('id="project-example"') < page.index('id="project-single"') + < page.index("1 retired")) led = tmp_skeleton / "projects" / "single.md" led.write_text(led.read_text(encoding="utf-8").replace("## Now\n\nNothing", "## Now\n\n\nNothing").replace( "Nothing submitted yet; the first run goes out once the dataset is on RAL.", ""), @@ -300,7 +361,8 @@ def test_the_html_twin_wears_the_theme_with_real_copy_buttons(skeleton): assert "table.map{width:100%" in html assert ("ProjectRunningOpen" "Last update") in html - assert html.count('
') == 2 + assert html.count('
1 retired" in html assert "

No ledger

" in html assert 'class="pathchip">/tmp/example' in html @@ -316,6 +378,51 @@ def test_the_html_escapes_the_ledgers_text(tmp_skeleton): assert "<script>alert(1)</script> & co" in html +def test_the_html_card_is_a_keyboard_disclosure_with_an_aligned_runs_table(skeleton): + html = _cortex.render_dashboard_html(_cortex.census(skeleton)) + card = html.split('
')[1] + card = card.split('
')[0] + assert card.startswith('\n

example

Does the example ' + 'pipeline recover the truth on the fixture lens' + '1 running · 1 open · updated 2026-09-02
') + assert ('' + '\n' + '' + '') in card + assert ('' + '') in card + assert 'open' in card + # the resume chip stays on the card, before the runs; history and paths fold + assert card.index('data-cmd="Use the cortex skill. — resume example:') < card.index("

Runs (2)

") + assert '
Recent log — 5 of 7 entries' in card + assert '
Locations
' in card + assert '
/mnt/ral/example
' in card + # keyboard focus is visible; the table stacks under the shared phone breakpoint + assert "details.project>summary:focus-visible" in html + assert "@media(max-width:34rem){table.runs,table.runs tbody{display:block}" in html + # an anchor to a project opens it (the shared section script walks DETAILS) + assert "p.tagName==='DETAILS'" in html + + +def test_the_card_overview_and_runs_table_escape_ledger_text(tmp_skeleton): + led = tmp_skeleton / "projects" / "example.md" + led.write_text(led.read_text(encoding="utf-8") + .replace("Does the example pipeline", "Does x & the example pipeline") + .replace("wave 2, four seeds on", "wave | 2 on"), + encoding="utf-8") + c = _cortex.census(tmp_skeleton) + html = _cortex.render_dashboard_html(c) + assert "x" not in html and "" not in html + assert 'Does <b>x</b> & the example' in html + assert "wave <img src=x> | 2 on" in html + page = _cortex.render_dashboard(c) + assert "example — Does <b>x</b> & the example" in page + # a pipe cannot split the markdown row; a tag cannot open or close a fold + assert "wave <img src=x> \\| 2 on" in page + assert " \\| 2 on the corrected settings |" in page + + # --- --check / --apply ----------------------------------------------------- def test_apply_then_check_is_clean_and_a_ledger_edit_is_drift(tmp_skeleton): assert _run(["dashboard", "--cortex", str(tmp_skeleton), "--apply"]).returncode == 0
JobStatePartitionDateDescription
3002_[0-3]' + 'runningral2026-09-01