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
113 changes: 93 additions & 20 deletions agents/conductors/cortex/_cortex.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 \"<one line on 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 "<td></td>"
return (f'<td><button class="copy text" '
f'data-cmd="{_attr(_retire_payload(key))}" '
f'aria-label="Copy the retire prompt">πŸ“‹ retire</button></td>')


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 "
Expand Down Expand Up @@ -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
Expand All @@ -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]:
Expand Down Expand Up @@ -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 `<details>` 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"<details><summary>{len(retired)} retired</summary>", ""]
L += [f"- {k} β€” {c['projects'][k].get('note') or '-'}"
for k in retired]
L += ["", "</details>", ""]

# 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
Expand Down Expand Up @@ -1269,13 +1324,25 @@ def phase_head(r, tone_pills=()):
else:
H.append('<p class="muted">(no active project)</p>')
if folded:
H += ["<h3>Nothing open</h3>", '<table class="map">',
"<tr><th>Project</th><th>Status</th><th>Phases</th></tr>"]
H += [f"<tr><td>{_summary_label(k)}</td><td>"
f"{_summary_label((c['projects'][k].get('status') or '?').strip())}"
f"</td><td>{_summary_label(project_counts(k, c))}</td></tr>"
for k in project_order(folded, c)]
H.append("</table>")
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 += ["<h3>Nothing open</h3>"]
if rest:
H += ['<table class="map">',
"<tr><th>Project</th><th>Status</th><th>Phases</th>"
"<th>Retire</th></tr>"]
H += [f"<tr><td>{_summary_label(k)}</td><td>"
f"{_summary_label(project_status(k, c))}</td>"
f"<td>{_summary_label(project_counts(k, c))}</td>"
f"{_retire_cell_html(k, c)}</tr>" for k in rest]
H.append("</table>")
if retired:
H += [f"<details><summary>{len(retired)} retired</summary><ul>"]
H += [f"<li>{_summary_label(k)} β€” "
f"{_summary_label(c['projects'][k].get('note') or '-')}</li>"
for k in retired]
H += ["</ul></details>"]

H.append(h2("projects"))
for key in project_order(shown, c):
Expand Down Expand Up @@ -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 ---
Expand Down
7 changes: 7 additions & 0 deletions skills/cortex/cortex.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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 <phase> ready` |
| `retire <project> --why "…"` (`scripts/cortex.py`) | Is this project over? Flips the row to `status: retired` and stamps `note: retired <today>: <why>`. 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 |
99 changes: 94 additions & 5 deletions tests/test_cortex_conductor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -484,24 +493,104 @@ 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 "<h3>Nothing open</h3>" in html
assert "<tr><td>dormant_one</td><td>dormant</td><td>none</td></tr>" in html
assert "<tr><td>dormant_one</td><td>dormant</td><td>none</td>" in html
# it reads under the summary, before the map
assert page.index("#### Nothing open") < page.index("## Projects")
assert html.index("<h3>Nothing open</h3>") < html.index("<h2>Projects")
for twin in (page, html):
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 "<th>Retire</th>" in html
assert (f'<button class="copy text" data-cmd="'
f'{_cortex._attr(payload)}" aria-label="Copy the retire prompt">'
f"πŸ“‹ retire</button>") 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 "<details><summary>πŸ“‹ retire dormant_one</summary>" 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 "<td></td>" 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 "<td>retired_one</td>" not in html
assert "<details><summary>1 retired</summary>" in page
assert "<details><summary>1 retired</summary><ul>" 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("<td>dormant_one</td>") < 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 '
'"<one line on 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:
Expand Down
Loading