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
53 changes: 52 additions & 1 deletion agents/conductors/batch/_batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import html
import importlib.util
import json
import os
import re
import shutil
import subprocess
Expand All @@ -53,7 +54,7 @@
# `CORTEX_BOARD_STATES`) so existing importers of `_batch` keep working.
sys.path.insert(0, str(Path(__file__).resolve().parent))
from _status import ( # noqa: E402
PENDING_RE, RULING_WORDS, CORTEX_BOARD_STATES, _carried_slugs,
PENDING_RE, RULING_WORDS, CORTEX_BOARD_STATES, _carried_slugs, freeze_line,
)

# One slot's worth of the human's attention, and only the DEFAULT: the human
Expand Down Expand Up @@ -1593,6 +1594,11 @@ def collect(mind: Path, slot: str, *, evidence: dict | None = None,
"review": review,
"not_delivered": [s["slug"] for s in scored
if s["health"] == "NOT-DELIVERED"],
# Heart's release freeze, read at collect time: the packet is where a
# human decides what to merge, so the window has to be on the page.
# Empty whenever nothing is frozen (or Heart's state is absent — this
# runs on a laptop, in CI and in a web container).
"freeze": freeze_line(heart_freeze()),
"rulings": [(s["slug"], _ruling_line(s)) for s in scored],
"unparsable": rec["unparsable"],
# `members` above is sorted by HEALTH, so it cannot drive a merge
Expand Down Expand Up @@ -1685,6 +1691,42 @@ def _integration_report(d: dict) -> list:
return L + [""]


#: PyAutoHeart's freeze flag, read straight off its sidecar. Brain never
#: writes it — Heart owns the file (`PyAutoHeart/heart/freeze.py`), and this is
#: a read of state that lives on the same box, in the same spirit as the
#: profiling conductor's read of `~/.pyauto-heart`. A shell-out to
#: `pyauto-heart freeze --show --json` would say the same thing; the file read
#: keeps `collect` runnable where Heart is not on PATH.
HEART_STATE_DIR = Path(os.environ.get("HEART_STATE_DIR")
or Path.home() / ".pyauto-heart")


def heart_freeze(now: _dt.datetime | None = None,
state_dir: Path | None = None) -> dict:
"""`{"state": clear|active|expired, ...}` — Heart's reading, re-derived.

Expiry is applied here rather than trusted from the file, so a flag whose
window has passed reads as thawed even if nobody cleared it. Anything
unreadable reads as clear: a freeze nobody can parse must not be able to
stop a batch from being collected.
"""
path = (state_dir or HEART_STATE_DIR) / "freeze.json"
try:
rec = json.loads(path.read_text(encoding="utf-8"))
except (OSError, ValueError):
return {"state": "clear"}
if not isinstance(rec, dict):
return {"state": "clear"}
try:
until = _dt.datetime.fromisoformat(str(rec.get("until", "")).replace("Z", "+00:00"))
except ValueError:
return {"state": "clear"}
if until.tzinfo is None:
until = until.replace(tzinfo=_dt.timezone.utc)
ref = now or _dt.datetime.now(_dt.timezone.utc)
return {**rec, "state": "active" if ref < until else "expired"}


def collect_report(d: dict) -> str:
L = [f"# Batch collect {d['slot']}", ""]
if d["not_delivered"]:
Expand All @@ -1696,6 +1738,13 @@ def collect_report(d: dict) -> str:
f"{slug} ({_short(by_slug[slug]['legs']['pr'][1] if by_slug[slug]['legs']['pr'][0] == FAIL else _evidence_line(by_slug[slug]))})"
for slug in d["not_delivered"])
L += [f"**NOT DELIVERED — {n} of {total}**: {why}", ""]
if d.get("freeze"):
# One line, above the members: whoever reads this packet is deciding
# what to merge, and a library merge landing inside a validation window
# restales the whole rehearsal. `/prm` is what actually stops.
L += [f"**{d['freeze']}** — library `main`s are frozen; `/prm` will "
"refuse a library PR until it clears (`--thaw` overrides, "
"logged).", ""]
L += _integration_report(d)
L += _merge_order_report(d)
for s in d["members"]:
Expand Down Expand Up @@ -1748,6 +1797,8 @@ def emit_collect(d: dict, out: str = "") -> None:
n, total = d["delivered"]
print(f"collect {d['slot']}: {len(d['members'])} members, "
f"delivered {n}/{total}")
if d.get("freeze"):
print(d["freeze"])
body = collect_report(d)
if out:
Path(out).write_text(body, encoding="utf-8")
Expand Down
40 changes: 35 additions & 5 deletions agents/conductors/batch/_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,21 @@ def _first_word(text: str) -> str:
return words[0].strip("(,.").upper() if words else ""


def freeze_line(rec: dict | None) -> str:
"""The Heart freeze flag as one line — `""` when nothing is frozen.

`rec` is PyAutoHeart's own reading (`pyauto-heart freeze --show --json`, or
the `freeze.json` sidecar read straight off disk). Heart owns the flag and
is its only writer; this is the Brain-side copy of the *wording*, kept
byte-identical to `PyAutoHeart/heart/freeze.py::render_line` so the batch
box, `vitals` and `/prm` all say the same sentence. `expired` reads as
thawed, exactly as Heart reads it.
"""
if not rec or rec.get("state") != "active":
return ""
return f"FROZEN: {rec.get('reason', 'unspecified')} until {rec.get('until', '?')}"


def _carried_slugs(keys: dict, members: list) -> set:
"""The members a `- carried:` line hands to the next slot.

Expand All @@ -151,7 +166,7 @@ def _carried_slugs(keys: dict, members: list) -> set:


def dev_status(slot: str, keys: dict, members: list, review_exists: bool,
pages: str) -> dict | None:
pages: str, freeze: str = "") -> dict | None:
"""The Mind's (development) reading — today's behaviour, unchanged.

A dev batch is dispatched at once and reviewed at once: it is open until
Expand All @@ -174,11 +189,12 @@ def dev_status(slot: str, keys: dict, members: list, review_exists: bool,
rows.append({"slug": m.get("slug", ""), "state": state,
"detail": detail})
return _status(slot, "dev", keys, rows,
reviewable=bool(_one(keys, "collected")), pages=pages)
reviewable=bool(_one(keys, "collected")), pages=pages,
freeze=freeze)


def cortex_status(slot: str, keys: dict, members: list, states: dict,
live: dict, pages: str) -> dict | None:
live: dict, pages: str, freeze: str = "") -> dict | None:
"""The Cortex's (science) reading — a rolling board, not one sitting.

A science slot stays open while anything is still ON the board: members
Expand Down Expand Up @@ -210,11 +226,20 @@ def cortex_status(slot: str, keys: dict, members: list, states: dict,
return None
return _status(slot, "cortex", keys, rows,
reviewable=any(r["state"] == AWAITING for r in rows),
pages=pages)
pages=pages, freeze=freeze)


def _status(slot: str, kind: str, keys: dict, rows: list, reviewable: bool,
pages: str) -> dict:
pages: str, freeze: str = "") -> dict:
"""`freeze` is a caller-supplied FACT, and defaults to nothing on purpose.

The flag lives in the dev box's `~/.pyauto-heart/`, which is machine state
and not in any checkout — so a surface that renders a **committed**
artifact must not pass it. The Mind's dashboard is regenerated in CI, where
that state does not exist, and a freeze folded into the page would read as
dashboard drift on the next `--check`. `batch collect`, which runs on the
box that holds the state and prints to a terminal, passes it.
"""
return {
"slot": slot,
"kind": kind,
Expand All @@ -225,6 +250,7 @@ def _status(slot: str, kind: str, keys: dict, rows: list, reviewable: bool,
"reviewable": reviewable,
"url": review_url(pages, slot) if reviewable else "",
"packet": f"batches/packets/{slot}.html",
"freeze": freeze,
}


Expand Down Expand Up @@ -261,6 +287,8 @@ def render_html(st: dict | None) -> str:
esc = _html.escape
tone = "warn" if st["reviewable"] else "ok"
H = [f'<div class="verdict {tone}"><b>{esc(_headline(st))}</b>']
if st.get("freeze"):
H.append(f'<p class="facets">{esc(st["freeze"])}</p>')
for r in st["members"]:
line = (f'<code>{esc(r["slug"])}</code>'
f'{pills((r["state"], _TONE.get(r["state"], "n")))}')
Expand All @@ -286,6 +314,8 @@ def render_md(st: dict | None) -> str:
if st is None:
return f"> **{FIXTURE}**"
L = [f"> **{_headline(st)}**", ">"]
if st.get("freeze"):
L += [f"> {st['freeze']}", ">"]
for r in st["members"]:
line = f"> - `{r['slug']}` — {r['state']}"
if r["detail"]:
Expand Down
17 changes: 17 additions & 0 deletions agents/faculties/vitals/AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,20 @@ faculty every cycle.)
`~/.pyauto-heart/release_ready.json`; if neither exists, the verdict is
**unknown -> treat as YELLOW** and recommend running `pyauto-heart tick`.

1b. **Read the freeze window.** The verdict does not carry it, deliberately:

```bash
pyauto-heart freeze --show --json # {state: clear|active|expired, reason, until, ...}
```

While `state` is `active`, report `FROZEN: <reason> until <ts>` as a warning
line (below). It is **not** a `yellow_reasons` entry and it does **not**
change Heart's verdict — a freeze is not a health problem, it is the release
validation saying the library `main`s should not move for now. `clear` and
`expired` both mean thawed; say nothing (an `expired` reading is worth one
line only when someone asks why it is still on disk). An older Heart with no
`freeze` verb prints nothing and that is not an error.

2. **Collect detail for explanation.** Pull the full snapshot when you need to
explain a reason or craft a recommendation:
```bash
Expand Down Expand Up @@ -144,6 +158,9 @@ Status: <GREEN | STALE | YELLOW | RED> (score <0-100>, snapshot <ts>)

### Warnings
- <yellow reason, mapped to its capability> (or "None")
- FROZEN: <reason> until <ts> (only while the freeze flag is active; not a
verdict input — it says library `main`s should not move, and `/prm` is the
one surface that actually stops on it)

### Evidence Gaps
- <stale reason, mapped to its capability, with the check to re-run — the
Expand Down
8 changes: 7 additions & 1 deletion agents/faculties/vitals/vitals.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,13 @@ if [[ $# -eq 0 ]]; then
# Render the ONE unified board (readiness verdict + every check + the
# release-validation state), not just the raw verdict. Same renderer as the
# web page and the mobile card, so the surfaces cannot disagree.
exec "$heart" dashboard
"$heart" dashboard
# ...and, under it, the release freeze window if one is open. It is NOT part
# of the verdict (a freeze is not a health problem) and Heart is its only
# writer — this faculty reads the line Heart prints and passes it on. An
# older Heart without the verb prints nothing, which is not an error.
"$heart" freeze --show 2>/dev/null | grep '^FROZEN:' || true
exit 0
fi

exec "$heart" "$@"
44 changes: 40 additions & 4 deletions skills/prm/prm.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ never hand-writing a generated page.
/prm 380 # PR #380 in the current or inferred repo
/prm PyAutoArray#42 # or Jammy2211/PyAutoArray#42, or the full PR URL
/prm --no-wait # judge CI once and report; merge only if already green
/prm --thaw "<why>" # merge a LIBRARY PR through an active Heart freeze (logged)
```

## Environment: decide your GitHub surface first
Expand Down Expand Up @@ -114,14 +115,44 @@ every run for the sha and every job in it, and treat anything not `completed` as

Green on every leg → merge, in this order:

1. **Library PR first.** The workspace PR may not merge until its upstream
1. **The Heart freeze window — library PRs only.** A release validation is a
window in which the library `main`s must not move: a merge landing inside it
invalidates the evidence and restales the rehearsal (~75 minutes, measured
2026-08-29). Heart's flag says whether one is open:

```bash
pyauto-heart freeze --show # exit 3 = frozen; 0 = clear or expired
```

Active **and** a target PR is in a **library** repo (the `category: library`
entries of `PyAutoMind/repos.yaml`) → stop, report the `FROZEN: …` line
verbatim, and say when it expires. Organ and workspace repos are not gated;
a workspace PR whose library half is held waits on the library-first gate
below anyway. Where Heart is not installed (mobile, web, CI) there is
nothing to read — say so in one line; an absent flag is not a freeze.

**`--thaw "<why>"` is the only way past**, and it is loggable by
construction: merge, then append one row to `PyAutoMind/autonomy_log.md`
under a `## Freeze overrides` heading (create the section, with this header,
on first use) —

```
| date | task / PR | freeze reason | until | thawed by | why |
```

— in the same Mind push the close-out already makes (step 5.4). The override
exists because a freeze is advice about evidence, not a protected branch,
and an unloggable override is one people route around instead of recording.
Never thaw silently, and never thaw to get past a red check: this gate is
about *when*, and step 2 is about *whether*.
2. **Library PR first.** The workspace PR may not merge until its upstream
library PR is `MERGED` — the library-first gate
([`../ship_workspace/reference.md`](../ship_workspace/reference.md)). Refuse
otherwise; there is no `--auto`-flag workaround.
2. `gh pr merge <n> --merge` per PR (`-R owner/repo` when you have no checkout),
3. `gh pr merge <n> --merge` per PR (`-R owner/repo` when you have no checkout),
then confirm the state is `MERGED` — queued or auto-merge is not merged. Never
`--delete-branch`: it takes the local branch too, orphaning a task worktree.
3. **Clear anything an older run left armed.** Step 3 arms nothing, so this is
4. **Clear anything an older run left armed.** Step 3 arms nothing, so this is
hygiene: if the harness's routine list shows a subscription or a
`send_later` reminder on a target PR, drop it (`unsubscribe_pr_activity`,
cancel the reminder). Never create one.
Expand Down Expand Up @@ -224,6 +255,8 @@ the page is true. 5 and 6 are local-only — name 5 outstanding, say nothing of
Stop and report instead of pressing on when:

- a branch in the task is **unmerged** with no open PR (step 5.1) — the waves trap;
- Heart's **freeze** is active and a target PR is in a library repo (step 4),
and no `--thaw "<why>"` was given;
- `worktree_remove` **refuses** (dirty repo, stale claim) — fix the cause, never
`PYAUTO_WT_FORCE=1` past it;
- the worktree holds **gitignored data products** (reduced datasets, caches,
Expand All @@ -238,7 +271,10 @@ Stop and report instead of pressing on when:
exception is Mind's own close-out commit, which needs no PR at all: pushing
the branch is what lands it (step 5.4).
- It never bypasses the Heart readiness gate — that ran at ship time, and a red
Heart is not something a merge shortcut may re-judge. Nor does merge ever stop
Heart is not something a merge shortcut may re-judge. The **freeze** flag
(step 4) is a different thing and does not re-run anything: readiness answers
"is the organism healthy", the freeze answers "is a validation window open
right now". Nor does merge ever stop
being human: `/prm` is a human-typed door, never invoked by the `--auto` queue.
- A task with no issue, no Mind prompt, or no worktree (a direct wiring change,
say) skips those sub-steps and says so — not an error. That licence does **not**
Expand Down
9 changes: 9 additions & 0 deletions skills/prm/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ re-run; `/prm` does not decide that for them.
## Merging in gate order

```bash
# 0. the freeze window — library PRs only; exit 3 means a validation is open
pyauto-heart freeze --show || echo "frozen: stop unless /prm --thaw \"<why>\""

# 1. library PR
gh pr merge <lib_n> -R <owner>/<lib_repo> --merge
gh pr view <lib_n> -R <owner>/<lib_repo> --json state --jq '.state' # must print MERGED
Expand All @@ -105,6 +108,12 @@ The library-first gate is `../ship_workspace/reference.md` → "Library-first me
gate": a workspace PR linked to an upstream library PR may only merge once that
PR reads `MERGED`. There is no workaround — not `--auto`, not `--admin`.

The freeze gate is `PyAutoHeart/REFERENCE.md` → "The release freeze window":
Heart owns the flag, `/prm` is the one surface that stops on it, and it stops
only for **library** repos. `--thaw "<why>"` merges anyway and appends the
override row to `PyAutoMind/autonomy_log.md` (`## Freeze overrides`). An
expired flag reads as clear, so a forgotten `--set` never blocks anyone.

## The close-out

### 1. Prove every branch merged (before recording anything)
Expand Down
Loading
Loading