diff --git a/agents/conductors/cortex/_cortex.py b/agents/conductors/cortex/_cortex.py index b69c1e5c..6d09a432 100644 --- a/agents/conductors/cortex/_cortex.py +++ b/agents/conductors/cortex/_cortex.py @@ -538,6 +538,34 @@ def _checkin_payload(c: dict) -> str: "the by-project summary with the prompt each phase needs next.") +def _retire_payload(key: str) -> str: + """The paste that ends a project โ€” the whole retirement as one sentence. + + It names the project twice on purpose: once in the prose, so a chat that + reads the sentence aloud says which project is being ended, and once + inside the command, so the command is runnable without re-reading the + sentence. Retiring keeps the row, the phases and the rulings; only the + status and the note change, and the ledger has to be pushed afterwards or + the board goes stale.""" + return (f"/cortex โ€” retire the science project {key}: confirm it is " + f"holding nothing live, then in PyAutoCortex run `python3 " + f"scripts/cortex.py retire {key} --why \"\"`, " + f"`python3 scripts/cortex.py check`, `pyauto-brain cortex " + f"dashboard --apply`, and push the ledger. The row, its phases " + f"and its rulings all stay โ€” only the status and the note change.") + + +def _retire_cell_html(key: str, c: dict) -> str: + """The Retire column of the Nothing-open table: a copy chip on a dormant + row, an empty cell on any other. A `planned` project has not started, so + it is not offered retirement.""" + if project_status(key, c) != "dormant": + return "" + return (f'') + + def _ruling_payload(r: dict) -> str: return (f"Review the PyAutoCortex phase {r['rel']} and help me rule on it: " f"read its `## Witness` and the pulled evidence under its " @@ -724,8 +752,9 @@ def project_groups(key: str, c: dict) -> list[tuple[str, list[dict]]]: #: `status` in the order the reader wants it: what is running, then what is -#: coming, then what is asleep. An unrecognised status sorts last. -STATUS_RANK = {"active": 0, "planned": 1, "dormant": 2} +#: coming, then what is asleep, then what is over. An unrecognised status +#: sorts last. +STATUS_RANK = {"active": 0, "planned": 1, "dormant": 2, "retired": 3} #: The buckets a project's open phases live in, in the order "what is the #: next thing" is answered: a verdict owed beats a job out there beats a @@ -734,9 +763,16 @@ def project_groups(key: str, c: dict) -> list[tuple[str, list[dict]]]: def project_order(keys: list[str], c: dict) -> list[str]: - """Active, then planned, then dormant; alphabetical inside each rank.""" + """Active, then planned, then dormant, then retired; alphabetical inside + each rank.""" return sorted(keys, key=lambda k: ( - STATUS_RANK.get((c["projects"][k].get("status") or "").strip(), 3), k)) + STATUS_RANK.get((c["projects"][k].get("status") or "").strip(), + len(STATUS_RANK)), k)) + + +def project_status(key: str, c: dict) -> str: + """One row's `status:`, `?` when the row does not declare one.""" + return (c["projects"][key].get("status") or "?").strip() def open_phases(key: str, c: dict) -> list[dict]: @@ -1007,13 +1043,32 @@ def h2(key: str) -> list: else: L += ["- _(no active project)_", ""] if folded: - L += ["#### Nothing open", "", - "| Project | Status | Phases |", "|---|---|---|"] - L += [f"| {_cell(k)} | " - f"{_cell((c['projects'][k].get('status') or '?').strip())} | " - f"{_cell(project_counts(k, c))} |" - for k in project_order(folded, c)] - L += [""] + # Retired projects leave the table: the reader of "nothing open" is + # looking for something to do, and a retired project is a fact to be + # able to find, not a row to scan past. It folds under the table with + # the note that says when and why. + ordered = project_order(folded, c) + retired = [k for k in ordered if project_status(k, c) == "retired"] + rest = [k for k in ordered if project_status(k, c) != "retired"] + L += ["#### Nothing open", ""] + if rest: + L += ["| Project | Status | Phases | Retire |", "|---|---|---|---|"] + L += [f"| {_cell(k)} | {_cell(project_status(k, c))} | " + f"{_cell(project_counts(k, c))} | " + f"{'retire โ†“' if project_status(k, c) == 'dormant' else ''} |" + for k in rest] + L += [""] + # The payload itself cannot live in the cell โ€” a `
` inside + # a table cell does not render on GitHub โ€” so the cell points down + # at one copy row per dormant project. + L += _items([_task_row(f"retire {k}", _retire_payload(k)) + for k in rest if project_status(k, c) == "dormant"]) + L += [""] + if retired: + L += [f"
{len(retired)} retired", ""] + L += [f"- {k} โ€” {c['projects'][k].get('note') or '-'}" + for k in retired] + L += ["", "
", ""] # The map: active projects, then planned, then dormant. Each card is # where the project lives, what it holds and the ONE phase to act on @@ -1269,13 +1324,25 @@ def phase_head(r, tone_pills=()): else: H.append('

(no active project)

') if folded: - H += ["

Nothing open

", '', - ""] - H += [f"" - for k in project_order(folded, c)] - H.append("
ProjectStatusPhases
{_summary_label(k)}" - f"{_summary_label((c['projects'][k].get('status') or '?').strip())}" - f"{_summary_label(project_counts(k, c))}
") + ordered = project_order(folded, c) + retired = [k for k in ordered if project_status(k, c) == "retired"] + rest = [k for k in ordered if project_status(k, c) != "retired"] + H += ["

Nothing open

"] + if rest: + H += ['', + "" + ""] + H += [f"" + f"" + f"{_retire_cell_html(k, c)}" for k in rest] + H.append("
ProjectStatusPhasesRetire
{_summary_label(k)}" + f"{_summary_label(project_status(k, c))}{_summary_label(project_counts(k, c))}
") + if retired: + H += [f"
{len(retired)} retired
    "] + H += [f"
  • {_summary_label(k)} โ€” " + f"{_summary_label(c['projects'][k].get('note') or '-')}
  • " + for k in retired] + H += ["
"] H.append(h2("projects")) for key in project_order(shown, c): @@ -1434,8 +1501,14 @@ def emit_by_project(c: dict) -> None: for key in shown: print("\n".join(project_digest(key, c["projects"][key], c, {}))) if folded: - print(f"Dormant, nothing open: " - + " ยท ".join(f"{k} ({project_counts(k, c)})" for k in folded)) + retired = [k for k in folded if project_status(k, c) == "retired"] + rest = [k for k in folded if project_status(k, c) != "retired"] + if rest: + print("Dormant, nothing open: " + + " ยท ".join(f"{k} ({project_counts(k, c)})" for k in rest)) + if retired: + print("Retired: " + + " ยท ".join(f"{k} ({project_counts(k, c)})" for k in retired)) # ---------------------------------------------------------------- collect --- diff --git a/skills/cortex/cortex.md b/skills/cortex/cortex.md index 0a8999f6..b33a62f8 100644 --- a/skills/cortex/cortex.md +++ b/skills/cortex/cortex.md @@ -109,6 +109,12 @@ and nothing for the human to merge. **Never `main` directly, never `--force`.** - **The door runs once and ends.** No timer, no subscription, no cron, no loop โ€” you check in, you report, you stop. - **`rulings/` is append-only.** Never edit or delete one. +- **Retiring ends a project, it does not erase one.** `cortex.py retire` + changes a `projects.yaml` row's `status:` and `note:` and nothing else: + the row stays (it is the only record of where that project's data + lives), its phases stay, its rulings stay. It refuses while the project + holds a phase outside `accepted | rerun | dropped | planned` โ€” rule or + drop the live questions first. ## Appendix โ€” the verbs it composes @@ -123,4 +129,5 @@ checkout. | `dashboard --check` | Are the committed pages current? Exit **1** = stale (the refresh workflow's contract) | | `dashboard --apply` | Regenerate `dashboard.md` + `dashboard.html` โ€” never hand-edit those two | | `gates` | What is each gated phase waiting on? Read-only and offline; a human types `move ready` | +| `retire --why "โ€ฆ"` (`scripts/cortex.py`) | Is this project over? Flips the row to `status: retired` and stamps `note: retired : `. The ๐Ÿ“‹ chip on the board's **Nothing open** table is this command. Exit **1** = an unknown key, an already-retired row, or a phase still live | | `collect [--phase REL] [--pull] [--refreshed ISO] [--apply] [--out F]` | The scorer `checkin` composes: one block per phase โ€” six legs each `PASS`/`FAIL`/`UNOBSERVABLE`, the readout, a **blank** ruling line. Exit **1** = a phase the human must look at | diff --git a/tests/test_cortex_conductor.py b/tests/test_cortex_conductor.py index 4c039396..f7acfd42 100644 --- a/tests/test_cortex_conductor.py +++ b/tests/test_cortex_conductor.py @@ -470,6 +470,15 @@ def test_census_by_project_prints_the_same_tree(skeleton): " ledger: wiki/state.md\n witness_file: out/**/*.json\n" " partition: gpu\n status: dormant\n") +#: Two more, so the Nothing-open table can be read for all three of the +#: statuses that fold: one that has not started and one that is over. +_PLANNED_ROW = _DORMANT_ROW.replace("dormant_one", "planned_one") \ + .replace("status: dormant", "status: planned") +_RETIRED_ROW = _DORMANT_ROW.replace("dormant_one", "retired_one") \ + .replace("status: dormant", + 'status: retired\n note: "retired 2026-09-04: the question ' + 'was answered"') + def test_a_project_with_nothing_open_is_a_row_under_the_summary(tmp_skeleton): """It gets no card โ€” a dormant project with nothing open is a fact, not @@ -484,9 +493,9 @@ def test_a_project_with_nothing_open_is_a_row_under_the_summary(tmp_skeleton): html = _cortex.render_dashboard_html(c) assert "### dormant_one" not in page assert "#### Nothing open" in page - assert "| dormant_one | dormant | none |" in page + assert "| dormant_one | dormant | none | retire โ†“ |" in page assert "

Nothing open

" in html - assert "dormant_onedormantnone" in html + assert "dormant_onedormantnone" in html # it reads under the summary, before the map assert page.index("#### Nothing open") < page.index("## Projects") assert html.index("

Nothing open

") < html.index("

Projects") @@ -494,14 +503,94 @@ def test_a_project_with_nothing_open_is_a_row_under_the_summary(tmp_skeleton): assert "project(s) with nothing open" not in twin -def test_the_projects_run_active_then_planned_then_dormant(skeleton): - """The order the human asked for, alphabetical inside each rank.""" +def test_the_projects_run_active_then_planned_then_dormant_then_retired(skeleton): + """The order the human asked for, alphabetical inside each rank. Retired + sorts after dormant and an unrecognised status still sorts last.""" c = {"projects": {"zeta": {"status": "active"}, "alpha": {"status": "active"}, "plan_b": {"status": "planned"}, "sleepy": {"status": "dormant"}, + "over": {"status": "retired"}, "odd": {"status": "who-knows"}}} assert _cortex.project_order(list(c["projects"]), c) == \ - ["alpha", "zeta", "plan_b", "sleepy", "odd"] + ["alpha", "zeta", "plan_b", "sleepy", "over", "odd"] + + +def test_a_dormant_row_carries_the_retire_chip_in_both_twins(tmp_skeleton): + """The chip is the door: the board's only offer of retirement, and the + payload behind it is the `cortex.py retire` command for that project.""" + (tmp_skeleton / "projects.yaml").write_text( + (tmp_skeleton / "projects.yaml").read_text(encoding="utf-8") + + _DORMANT_ROW + _PLANNED_ROW, encoding="utf-8") + c = _cortex.census(tmp_skeleton) + page = _cortex.render_dashboard(c) + html = _cortex.render_dashboard_html(c) + payload = _cortex._retire_payload("dormant_one") + # HTML: a real copy button in the row's own Retire cell + assert "Retire" in html + assert (f'") in html + assert "cortex.py retire dormant_one --why" in html + # markdown: the cell points down at the copy row under the table + assert "| dormant_one | dormant | none | retire โ†“ |" in page + assert "
๐Ÿ“‹ retire dormant_one" in page + assert payload in page + # a planned project has not started โ€” no chip, an empty cell, no row + assert "| planned_one | planned | none | |" in page + assert "retire planned_one" not in page + assert "cortex.py retire planned_one" not in html + assert "" in html + + +def test_a_retired_project_leaves_the_table_for_the_fold(tmp_skeleton): + """Retiring never deletes a row, so the project stays findable โ€” but the + reader of "nothing open" is looking for something to do, and a retired + project is not it.""" + (tmp_skeleton / "projects.yaml").write_text( + (tmp_skeleton / "projects.yaml").read_text(encoding="utf-8") + + _DORMANT_ROW + _RETIRED_ROW, encoding="utf-8") + c = _cortex.census(tmp_skeleton) + assert _cortex.project_status("retired_one", c) == "retired" + page = _cortex.render_dashboard(c) + html = _cortex.render_dashboard_html(c) + note = "retired 2026-09-04: the question was answered" + for twin in (page, html): + assert "retired_one" in twin + assert "1 retired" in twin + assert note in twin + # no chip: it is already retired + assert "cortex.py retire retired_one" not in twin + assert "| retired_one |" not in page + assert "retired_one" not in html + assert "
1 retired" in page + assert "
1 retired
    " in html + assert f"- retired_one โ€” {note}" in page + # it reads after the table it left, and the dormant row is still in it + assert page.index("| dormant_one |") < page.index("1 retired") + assert html.index("dormant_one") < html.index("1 retired") + + +def test_the_retire_payload_is_the_command_and_the_sentence(skeleton): + """It names the project in prose and again inside the command, so a chat + that reads it aloud says what is ending and can run it without re-reading.""" + payload = _cortex._retire_payload("dormant_one") + assert payload.startswith("/cortex โ€” retire the science project dormant_one:") + assert ('`python3 scripts/cortex.py retire dormant_one --why ' + '""`') in payload + assert "`python3 scripts/cortex.py check`" in payload + assert "`pyauto-brain cortex dashboard --apply`" in payload + assert "push the ledger" in payload + assert "rulings all stay" in payload + + +def test_census_by_project_lists_retired_on_its_own_line(tmp_skeleton): + (tmp_skeleton / "projects.yaml").write_text( + (tmp_skeleton / "projects.yaml").read_text(encoding="utf-8") + + _DORMANT_ROW + _RETIRED_ROW, encoding="utf-8") + r = _run(["census", "--cortex", str(tmp_skeleton), "--by-project"]) + assert r.returncode == _cortex.RC_OK, r.stdout + r.stderr + assert "Dormant, nothing open: dormant_one (none)" in r.stdout + assert "Retired: retired_one (none)" in r.stdout def _bucketed(**buckets) -> dict: