diff --git a/agents/conductors/intake/_intake.py b/agents/conductors/intake/_intake.py index 185edf2d..624bedff 100755 --- a/agents/conductors/intake/_intake.py +++ b/agents/conductors/intake/_intake.py @@ -667,6 +667,64 @@ def _entry_date(fields: dict) -> tuple: return "", "" +# The PR ledger keys. `library-pr:` / `workspace-pr:` are written by +# ship_library / ship_workspace, read by /prm, and schematised in +# PyAutoMind/REFERENCE.md ("The PR keys"). They are REPEATABLE — one task may +# open several PRs of a kind — so the parse below collects every occurrence +# rather than the first, which is what the rest of `parse_registry` does. +# +# `pending-release: @` and `release-gate: ` carry the +# merged-but-unpublished chain (REFERENCE.md "The pending-release chain"). +# Mind holds the LINK and the GATE; GitHub's label and the Hands release stay +# the source of truth, and this renderer never asks either at render time. +PR_KEYS = ("library-pr", "workspace-pr") +_PR_URL = re.compile(r"https://github\.com/[^/\s]+/([^/\s]+)/pull/(\d+)") +_PENDING_RELEASE = re.compile(r"([\w.-]+)@(https://\S+)") + + +def _pr_links(values: list) -> list: + """`[{url, label}]` for every PR URL across a repeated key's values. + + Both written forms collapse here: one line per URL, and the older single + line of `, `. The label is `Repo#N` — the shortest thing that + still says which repo, which is the whole reason the column exists.""" + out, seen = [], set() + for value in values or []: + for m in _PR_URL.finditer(value): + if m.group(0) in seen: + continue + seen.add(m.group(0)) + out.append({"url": m.group(0), + "label": f"{m.group(1)}#{m.group(2)}"}) + return out + + +def _pending_links(values: list) -> list: + """`[{lib, url, label}]` for `pending-release: @` lines.""" + out, seen = [], set() + for value in values or []: + for m in _PENDING_RELEASE.finditer(value): + url = m.group(2).rstrip(").,;") + if url in seen: + continue + seen.add(url) + pr = _PR_URL.search(url) + out.append({"lib": m.group(1), "url": url, + "label": f"{pr.group(1)}#{pr.group(2)}" if pr else url}) + return out + + +def _gate_libs(values: list) -> list: + """`release-gate: [, ]` -> the library names, in order.""" + out = [] + for value in values or []: + for lib in re.split(r"[,\s]+", value.strip()): + lib = lib.strip("`") + if lib and lib not in out: + out.append(lib) + return out + + def parse_registry(path: Path) -> list: """Parse one registry file into `[{slug, issue, issue_no, status, prompt}]`. @@ -681,7 +739,7 @@ def parse_registry(path: Path) -> list: head = _REG_HEAD.match(line) if head: cur = {"slug": head.group(1), "issue": "", "issue_no": "", - "status": "", "prompt": "", "fields": {}, + "status": "", "prompt": "", "fields": {}, "multi": {}, "date": "", "event": ""} entries.append(cur) continue @@ -692,6 +750,9 @@ def parse_registry(path: Path) -> list: continue key, value = field.group(1), field.group(2).strip() cur["fields"].setdefault(key, value) + # `fields` is first-wins (how a reader scans a block); `multi` keeps + # every occurrence, which is what the repeatable PR keys need. + cur["multi"].setdefault(key, []).append(value) if key in ("issue", "status", "prompt") and not cur[key]: cur[key] = value if key == "issue": @@ -702,6 +763,11 @@ def parse_registry(path: Path) -> list: cur["issue"], cur["issue_no"] = m.group(0), m.group(1) for e in entries: e["date"], e["event"] = _entry_date(e["fields"]) + e["prs"] = [dict(link, kind=key) + for key in PR_KEYS + for link in _pr_links(e["multi"].get(key))] + e["pending_release"] = _pending_links(e["multi"].get("pending-release")) + e["release_gate"] = _gate_libs(e["multi"].get("release-gate")) return entries @@ -1595,6 +1661,12 @@ def _count(key): # at conception ("filed"/"formalised") and is stale the moment the # task is issued, so it would report the opposite of live state. "status": row.get("status", ""), + # The PR ledger (REFERENCE.md "The PR keys"). Empty lists for a row + # that has shipped nothing yet — the common case, and the renderer + # must draw nothing rather than an empty column. + "prs": row.get("prs", []), + "pending_release": row.get("pending_release", []), + "release_gate": row.get("release_gate", []), }) c = { @@ -1626,9 +1698,78 @@ def _count(key): "batch": _batch_status(mind), } c["recent"] = recent_events(c) + # Needs `in_flight` in place, so it is derived after the dict is built. + c["pending_release"] = pending_release(c, mind) return c +# `complete/` records carry `pending-release:` too — /prm copies the key over +# from the active.md row at close-out, so the obligation outlives the row that +# opened it. The ledger holds ~1300 records, so only the head of each file is +# read: the record's own fields sit at the top, and everything past +# `## Original prompt` is the starting prompt verbatim (which may quote another +# task's keys and must not be attributed to this record). +_RECORD_HEAD_BYTES = 4096 +_ORIGINAL_PROMPT = re.compile(r"^##\s+Original prompt\s*$", re.M | re.I) + + +def _record_pending(mind: Path) -> list: + """`[{lib, url, label, source, task}]` for uncleared `complete/` records.""" + comp = mind / "complete" + if not comp.is_dir(): + return [] + archive = comp / "archive" + out = [] + for f in sorted(comp.rglob("*.md")): + if archive in f.parents or f.name == "index.md": + continue + with f.open(encoding="utf-8", errors="replace") as fh: + head = _ORIGINAL_PROMPT.split(fh.read(_RECORD_HEAD_BYTES), 1)[0] + if "pending-release:" not in head: + continue + task = "" + values = [] + for line in head.splitlines(): + m = _REG_HEAD.match(line) + if m and not task: + task = m.group(1) + fm = _REG_FIELD.match(line) + if fm and fm.group(1) == "pending-release": + values.append(fm.group(2).strip()) + rel = f.relative_to(mind).as_posix() + for link in _pending_links(values): + out.append(dict(link, source=rel, task=task or f.stem)) + return out + + +def pending_release(c: dict, mind: Path) -> list: + """The merged-but-unpublished chain, grouped by library. + + `[{lib, prs: [...], gated: [...]}]`, empty when nothing is pending. Read + from the LEDGER only — `active.md` rows plus `complete/` records — never a + live GitHub query: the dashboard renders in CI and on a phone, and a page + that needs a token to draw a section is a page that silently loses it. + The Brain board's live `pending-release` search stays the fresh view.""" + groups: dict = {} + for row in c["in_flight"]: + for link in row.get("pending_release") or []: + g = groups.setdefault(link["lib"], {"lib": link["lib"], "prs": [], + "gated": []}) + g["prs"].append(dict(link, source=row["path"], task=row["title"])) + for link in _record_pending(mind): + g = groups.setdefault(link["lib"], {"lib": link["lib"], "prs": [], + "gated": []}) + g["prs"].append(link) + # A gate names a library that may have no pending PR recorded (the row was + # written by hand, or the PR's own record has been cleared). Show it + # anyway: a task declaring itself blocked is the more urgent half. + for row in c["in_flight"]: + for lib in row.get("release_gate") or []: + g = groups.setdefault(lib, {"lib": lib, "prs": [], "gated": []}) + g["gated"].append(row) + return [groups[k] for k in sorted(groups)] + + def _cell(value: str) -> str: return str(value).replace("|", "\\|") @@ -1730,9 +1871,13 @@ def _batch_status(mind: Path) -> dict | None: def _cortex_root(mind: Path): """`$PYAUTO_CORTEX`, then beside the Mind. `None` when there is none.""" + # `.resolve()` before `.parent`: CI runs the renderer as `--mind .` from + # inside the Mind checkout, and `Path(".").parent` is `.` — so the sibling + # lookup pointed at `PyAutoMind/PyAutoCortex`, never resolved, and every CI + # render silently dropped the Cortex-gate badges (found 2026-09-03). env = os.environ.get("PYAUTO_CORTEX", "").strip() for candidate in ([Path(env).expanduser()] if env else - []) + [mind.parent / CORTEX_REPO]: + []) + [mind.resolve().parent / CORTEX_REPO]: if (candidate / "phases").is_dir(): return candidate return None @@ -2210,12 +2355,15 @@ def render_dashboard(c: dict) -> str: head += _dated(r) if r["status"]: head += f" — {_summary_label(_clip(r['status']))}" + head += _pr_column(r) for rel in _gated_phases(c, r): head += f" — ⚠️ gates a Cortex phase → {rel}" flight.append(_task_row(head, f"/start_dev {r['path']}")) L += _items(flight) or ["- _(nothing in flight)_"] L += [""] + L += _pending_release_section(c.get("pending_release") or []) + # Directly under In flight: both are live obligations, and a review that # sank below the 140-prompt backlog would never be read. reviews = c.get("human_review") or [] @@ -2390,6 +2538,57 @@ def render_dashboard(c: dict) -> str: """ +# The PR column. In-flight rows render inside a ``, so this is HTML +# (see `_summary_label`) — and it is deliberately a suffix on the task line +# rather than a real table column: the page is read on a phone, where a +# five-column table wraps into unreadability. +PENDING_RELEASE_BLURB = ( + "Library PRs the ledger records as merged but not yet released, and the " + "in-flight tasks waiting on each. Rendered from the ledger — `active.md` " + "and the `complete/` records — never a live GitHub query; the Brain " + "board's `pending-release` search is the fresh view, this is what the Mind " + "believes.") + + +def _pr_column(r: dict) -> str: + """The `— PRs: Repo#N, Repo#N` suffix, plus the ledger's own badges.""" + out = "" + prs = r.get("prs") or [] + if prs: + links = ", ".join(f'{pr["label"]}' + for pr in prs) + out += f" — PRs: {links}" + # The badge is the LEDGER's `pending-release:` key, not a live label read. + for link in r.get("pending_release") or []: + out += f" — ⏳ pending release: {_summary_label(link['lib'])}" + for lib in r.get("release_gate") or []: + out += f" — ⏸ waiting on {_summary_label(lib)}'s release" + return out + + +def _pending_release_section(groups: list) -> list: + """The Pending release section, or nothing at all when the chain is empty. + + Omitted rather than rendered empty: a heading that is almost always + followed by "(none)" trains the eye to skip it, and the whole value of this + section is that its presence means something is waiting.""" + if not groups: + return [] + L = ["## Pending release", "", PENDING_RELEASE_BLURB, ""] + for g in groups: + L += [f"**{_summary_label(g['lib'])}**", ""] + rows = [] + for pr in g["prs"]: + rows.append(f"- [{pr['label']}]({pr['url']}) — " + f"`{pr['source']}`") + for row in g["gated"]: + rows.append(f"- ⏸ waiting: [{_md_inline(row['title'])}]" + f"({row['path']})") + L += rows or ["- _(no PR recorded — the gate names this library only)_"] + L += [""] + return L + + def _md_inline(text: str) -> str: """Render the inline markdown this module authors (`code` spans only) as HTML. @@ -2518,6 +2717,7 @@ def h2(title, src): if r["status"]: text += (f' — ' f'{_summary_label(_clip(r["status"]))}') + text += _pr_column(r) gated = _gated_phases(c, r) if gated: text += pills(*[(f"gates a Cortex phase → {rel}", "y") @@ -2526,6 +2726,21 @@ def h2(title, src): if not c["in_flight"]: H.append('

(nothing in flight)

') + groups = c.get("pending_release") or [] + if groups: + H += ['' + h2("Pending release", "active.md"), + f'

{_md_inline(PENDING_RELEASE_BLURB)}

'] + for g in groups: + H.append(f"

{_summary_label(g['lib'])}

") + items = [f'
  • {pr["label"]} ' + f'{_summary_label(pr["source"])}
  • ' + for pr in g["prs"]] + items += [f'
  • ⏸ waiting: {link(row["path"], _summary_label(row["title"]))}' + "
  • " for row in g["gated"]] + H.append("
      " + "".join( + items or ["
    • (no PR recorded — the gate names this library " + "only)
    • "]) + "
    ") + reviews = c.get("human_review") or [] H += ['' + h2("Human review", "draft/human_review").replace( diff --git a/skills/prm/prm.md b/skills/prm/prm.md index 52515a04..c02a985c 100644 --- a/skills/prm/prm.md +++ b/skills/prm/prm.md @@ -150,6 +150,14 @@ Typing `/prm` authorized all of this; the only questions are the guards in step `draft///` prompt pointing back at the record. Recording a prompt whole on a partial merge is what leaves half-done work on the dashboard as pickable backlog. + + **Carry `pending-release:` into the record.** A library PR merged here is not + a released library, and the `active.md` row that held that fact is about to + be pruned. Copy every uncleared `- pending-release: @` line from + the row into the completion body, so the obligation outlives the row and the + dashboard's **Pending release** section keeps showing it. `/prm` never + clears the key — only `/review_release` does, on a release that actually + published (`PyAutoMind/REFERENCE.md` → "The pending-release chain"). 4. **Mind: leave the page true** — the close-out is finished when `dashboard.md` stops offering this work, not when the claim is released. `dashboard_refresh.yml` heals a stale *render*, never a stale *prompt*, so diff --git a/skills/ship_library/reference.md b/skills/ship_library/reference.md index 8214109b..d398cd39 100644 --- a/skills/ship_library/reference.md +++ b/skills/ship_library/reference.md @@ -141,12 +141,33 @@ Created" comment (PR URLs, "Next: /start_workspace", API-change summary), set th `active.md` status to `library-shipped, workspace-pending`, add `library-pr:`, push Mind. Do **not** record completion yet. +**The PR keys are schematised** — `PyAutoMind/REFERENCE.md` → "The PR keys". +Write one `- library-pr: ` line **per PR** (the key is repeatable; the +older single line of `, ` still parses, but new rows use one line +each). A row whose `status:` says `awaiting-merge` / `PR open` / `shipped` and +carries no `*-pr:` is drift — `lifecycle.py check` exits 1 on it, because it is +a task `/prm` cannot close. + +**And the pending-release link.** Every PR this skill opens carries the +`pending-release` label, so also write + +```markdown +- pending-release: @ +``` + +on the `active.md` row — one line per merged-but-unpublished library PR. That +is the Mind's half of the chain in `REFERENCE.md` → "The pending-release +chain": GitHub's label and the Hands release stay the source of truth, Mind +holds only the link. The dashboard's **Pending release** section renders it, +and `/review_release` clears it once a release has actually published. + **Shipped (option iii passed):** offer to merge the library PR (`gh pr merge --merge --auto`), post a "Shipped" comment (PRs, summary, optional session notes), then record completion — the dated record **is** the ledger (issues #71/#81; the monolithic `complete.md` was retired 2026-07-16): - **Draft the rich completion body** to a temp file — `## `, `issue`, - `completed: `, `library-pr:`, then the summary/traps/notes bullets. + `completed: `, `library-pr:`, any uncleared `pending-release:` carried + over from the `active.md` row, then the summary/traps/notes bullets. - **Write the record** — one step: it folds + removes the `active/` prompt, refreshes `complete/index.md`, and prunes the task's `active.md` section (all the state `lifecycle.py check` drift-checks): diff --git a/skills/ship_workspace/reference.md b/skills/ship_workspace/reference.md index 01ebbb03..e06063b3 100644 --- a/skills/ship_workspace/reference.md +++ b/skills/ship_workspace/reference.md @@ -114,6 +114,7 @@ SHIP_EOF - completed: - library-pr: - workspace-pr: +- pending-release: @ # any still uncleared, carried from active.md - summary: ``` diff --git a/skills/ship_workspace/ship_workspace.md b/skills/ship_workspace/ship_workspace.md index ba956541..c21647af 100644 --- a/skills/ship_workspace/ship_workspace.md +++ b/skills/ship_workspace/ship_workspace.md @@ -95,6 +95,18 @@ workspace PR may merge; refuse otherwise (no `gh pr merge --auto`-flag workaround — unrelated to the workflow's `--auto` mode, which never merges). See [`reference.md`](reference.md) → "Library-first merge gate". +**Blocked behind an unreleased library?** Merged is not released, and a +workspace change that needs the new API cannot ship until the library is on +PyPI. Record that on the `active.md` row: + +```markdown +- release-gate: +``` + +one line per library. The Mind dashboard's **Pending release** section lists +the task under that library's pending PRs, so the block is visible without a +GitHub query — `PyAutoMind/REFERENCE.md` → "The pending-release chain". + ### 6. Complete the issue + Mind state Detect the issue, generate a session summary, post a "Shipped" comment, write diff --git a/tests/test_intake_dashboard.py b/tests/test_intake_dashboard.py index ca1fc2ac..7320427e 100644 --- a/tests/test_intake_dashboard.py +++ b/tests/test_intake_dashboard.py @@ -1809,3 +1809,132 @@ def test_batch_box_md_and_html_agree_on_slugs_and_the_review_url(tmp_path): for slug in ("autofit-resampling-info", "autonerves-colab-silence"): assert slug in page and slug in html assert url in page and url in html + + +# --------------------------------------------------------------------------- # +# the PR ledger — `library-pr:` / `workspace-pr:` / `pending-release:` +# +# The keys were written by ship_library and read by /prm for months while the +# page rendered only the free-text `status:`, so a reader on a phone could see +# that a task was "awaiting-merge" and had no way to reach the PR. The whole +# section is a LEDGER render: no `gh` call may happen here, at any input. +# --------------------------------------------------------------------------- # +PR_LEDGER_ACTIVE = """# Active + +## widget-rework +- issue: https://github.com/ExampleOrg/Widgets/issues/42 +- prompt: active/widget_rework.md +- status: library-shipped, awaiting-merge +- library-pr: https://github.com/ExampleOrg/Widgets/pull/7 +- library-pr: https://github.com/ExampleOrg/Gadgets/pull/8 +- workspace-pr: https://github.com/ExampleOrg/widgets_workspace/pull/9 +""" + + +def test_in_flight_rows_link_every_pr_key_labelled_by_repo(tmp_path): + mind = _mind(tmp_path, + active={"widget_rework.md": _prompt("Widget rework")}, + registries={"active.md": PR_LEDGER_ACTIVE}) + flight = _page(mind).split("## In flight")[1].split("## Parked")[0] + for label, url in (("Widgets#7", "https://github.com/ExampleOrg/Widgets/pull/7"), + ("Gadgets#8", "https://github.com/ExampleOrg/Gadgets/pull/8"), + ("widgets_workspace#9", + "https://github.com/ExampleOrg/widgets_workspace/pull/9")): + assert f'{label}' in flight, \ + "every *-pr: key must render as one repo-labelled link" + + +def test_the_older_single_line_comma_form_of_a_pr_key_still_links(tmp_path): + """Rows written before the key was schematised must not lose their links.""" + mind = _mind( + tmp_path, + active={"widget_rework.md": _prompt("Widget rework")}, + registries={"active.md": ( + "# Active\n\n## widget-rework\n" + "- prompt: active/widget_rework.md\n" + "- status: shipped\n" + "- library-pr: https://github.com/ExampleOrg/Widgets/pull/7, " + "https://github.com/ExampleOrg/Gadgets/pull/8\n")}) + flight = _page(mind).split("## In flight")[1].split("## Parked")[0] + assert "Widgets#7" in flight and "Gadgets#8" in flight + + +PENDING_ACTIVE = """# Active + +## widget-rework +- issue: https://github.com/ExampleOrg/Widgets/issues/42 +- prompt: active/widget_rework.md +- status: library-shipped, awaiting-merge +- library-pr: https://github.com/ExampleOrg/Widgets/pull/7 +- pending-release: Widgets@https://github.com/ExampleOrg/Widgets/pull/7 + +## gadget-polish +- prompt: active/gadget_polish.md +- status: workspace-dev +- release-gate: Widgets +""" + + +def test_a_pending_release_badge_is_read_from_the_ledger_not_github(tmp_path): + mind = _mind(tmp_path, + active={"widget_rework.md": _prompt("Widget rework"), + "gadget_polish.md": _prompt("Gadget polish")}, + registries={"active.md": PENDING_ACTIVE}) + flight = _page(mind).split("## In flight")[1].split("## Pending release")[0] + assert "⏳ pending release: Widgets" in flight + assert "⏸ waiting on Widgets's release" in flight + + +def test_pending_release_groups_the_prs_and_the_tasks_waiting_on_them(tmp_path): + mind = _mind( + tmp_path, + active={"widget_rework.md": _prompt("Widget rework"), + "gadget_polish.md": _prompt("Gadget polish")}, + registries={"active.md": PENDING_ACTIVE}, + complete={"2026/01/sprocket_fix.md": ( + "## sprocket-fix\n- completed: 2026-01-01\n" + "- pending-release: Sprockets@https://github.com/ExampleOrg/Sprockets/pull/3\n" + "\n## Original prompt\n\n" + "- pending-release: Decoys@https://github.com/ExampleOrg/Decoys/pull/99\n")}) + section = _page(mind).split("## Pending release")[1].split("## Human review")[0] + assert "**Widgets**" in section and "**Sprockets**" in section + assert "[Widgets#7](https://github.com/ExampleOrg/Widgets/pull/7)" in section + assert "Sprockets#3" in section, \ + "a complete/ record's uncleared pending-release: belongs in the section" + assert "Decoys" not in section, \ + "the appended Original prompt is not the record's own fields" + assert "⏸ waiting: [Gadget polish]" in section + assert "never a live GitHub query" in section + + +def test_an_empty_pending_release_section_is_omitted_entirely(tmp_path): + mind = _mind(tmp_path, + active={"widget_rework.md": _prompt("Widget rework")}, + registries={"active.md": ACTIVE_MD}) + page = _page(mind) + assert "## Pending release" not in page + assert "## Pending release" not in _intake.render_dashboard_html( + _intake.census(mind)) + + +def test_pending_release_renders_on_the_html_page_too(tmp_path): + mind = _mind(tmp_path, + active={"widget_rework.md": _prompt("Widget rework"), + "gadget_polish.md": _prompt("Gadget polish")}, + registries={"active.md": PENDING_ACTIVE}) + html = _intake.render_dashboard_html(_intake.census(mind)) + assert 'id="pending-release"' in html + assert 'Widgets#7' in html + + +def test_the_cortex_root_resolves_from_a_relative_mind_path(tmp_path, monkeypatch): + """CI runs the renderer as `--mind .` from inside the Mind checkout. + `Path(".").parent` is `.`, so the sibling lookup used to point at + `PyAutoMind/PyAutoCortex` and every CI render silently dropped the + Cortex-gate badges.""" + mind = tmp_path / "PyAutoMind" + mind.mkdir() + (tmp_path / _intake.CORTEX_REPO / "phases").mkdir(parents=True) + monkeypatch.delenv("PYAUTO_CORTEX", raising=False) + monkeypatch.chdir(mind) + assert _intake._cortex_root(Path(".")) == (tmp_path / _intake.CORTEX_REPO)