diff --git a/active.md b/active.md
index fe7e1b960..42c9da5a6 100644
--- a/active.md
+++ b/active.md
@@ -40,6 +40,7 @@
## cortex-assistant-entry
- issue: https://github.com/PyAutoLabs/PyAutoBrain/issues/362
- issued: 2026-09-07
+- prompt: active/cortex_projects_route_through_assistant.md
- session: claude --resume cb789199-9f67-400f-9f46-f68555932dc9
- status: library-shipped, awaiting-merge
- library-pr: https://github.com/PyAutoLabs/PyAutoBrain/pull/367
diff --git a/autonomy_log.md b/autonomy_log.md
index 8d0ab41f7..e8e6b8947 100644
--- a/autonomy_log.md
+++ b/autonomy_log.md
@@ -259,25 +259,35 @@ Outcome ∈ `merged-unchanged` / `amended` / `rejected` / `parked` /
| 2026-09-07 | mge-group-source-basis-scale (autolens_workspace_test#299 / PR#303) — corrective for Heart RED "release validation FAILED (stage integrate)" + "workspace validation not passing (5 failed, 2 timeout, cloud#34099198772: autolens notebooks/multi_dataset/modeling.ipynb, autolens scripts/multi_dataset/modeling.py, autolens_test scripts/imaging/delaunay.py, +4 more)" | human-authorized corrective-PR exception, live session 2026-09-07 (quote + approval recorded on the issue: https://github.com/PyAutoLabs/autolens_workspace_test/issues/299#issuecomment-5573411919) | witness three consecutive cold runs exit 0 `PASS: mass-sensitivity floor exceeded (\|delta\| = 29.2037 > 9.0)` with NumPy and JIT bit-identical (1185.535713267093); per-block probe source abs-sum 2.50 (8 of 30 non-zero), chi2 562.4 on 556 px (was chi2 5650 with the source block exactly 0), source-plane centroid (0.000, 0.023) / knife-edge check: response monotone 19–115 across satellite ceilings 0.01–0.15, 0.02 chosen where chi2 ~ N; 9.0 floor untouched / review architect-reviewed subagent report / heart RED — the named reasons, shipped under the exception | corrective (PR-open; merge stays human via /prm; validation = next scheduled Workspace Smoke + Release Integrate on fresh wheels) |
| 2026-09-07 | point-source-smoke-runtime-regression (autolens_workspace#537 / PR#538) — corrective for Heart RED "workspace validation not passing (5 failed, 2 timeout, cloud#34099198772: autolens notebooks/multi_dataset/modeling.ipynb, autolens scripts/multi_dataset/modeling.py, autolens_test scripts/imaging/delaunay.py, +4 more)" | human-authorized corrective-PR exception, live session 2026-09-07 (quote + approval recorded on the issue: https://github.com/PyAutoLabs/autolens_workspace/issues/537#issuecomment-5573412088) | witness `multi_dataset/features/imaging_and_point_source/modeling.py` under `profile_smoke.yaml` with the cache deleted (cold download) 8 s PASS and under `profile_release.yaml` 12 s PASS (was 302 s script / 303 s notebook against the 300 s cap, stack parked in `ssl.read` under an untimed `urlretrieve`, no library code on the stack); `weak/start_here.py` cold 4 s PASS (2.9 MB catalogue) / retry logic exercised directly: transient failure recovers on attempt 3, permanent raises after exactly 3 attempts / `black --check` + `py_compile` clean on all four scripts, four notebook twins regenerated by `generate.py` (356 scripts) / review architect-reviewed subagent report / heart RED — the named reason, shipped under the exception | corrective (PR-open; merge stays human via /prm; validation = next scheduled Workspace Smoke + Release Integrate on fresh wheels) |
| 2026-09-07 | agwt-multi-delaunay-release-timeout (autogalaxy_workspace_test#118 / PR#119) — corrective for Heart RED "release validation FAILED (stage integrate)" | human-authorized corrective-PR exception, live session 2026-09-07 (quote + approval recorded on the issue: https://github.com/PyAutoLabs/autogalaxy_workspace_test/issues/118#issuecomment-5573412233) | witness config-only quarantine: `config/build/no_run.yaml` parses (6 entries), `should_skip` True for `multi_dataset/jax_likelihood/delaunay.py` and False for `delaunay_mge.py`, `validate_env_profiles.py .` 0 errors; three cold-cache release-profile runs complete in 13 s — vacuous, the dev box cannot reproduce the family (10/10 release passes, 4/4 with the Eigen flag removed) / premise falsified: smoke and release env differ in 2 of 68 keys (`PYAUTO_TEST_MODE`, `PYAUTO_FAST_PLOTS`), neither read by the script; both CI hangs park in `_pjit_call_impl` under the vmap re-trace / containment, not a fix — remove when the xla-cpu-eigen-pool-deadlock epic lands / review architect-reviewed subagent report / heart RED — the named reason, shipped under the exception | corrective (PR-open; merge stays human via /prm; validation = next scheduled Workspace Smoke + Release Integrate on fresh wheels) |
+| 2026-09-07 | jax-grad-delaunay-fd-sweep-repin (autolens_workspace_test#304 / PR#305) — corrective for Heart RED "release validation FAILED (stage integrate)" (sole remaining script after #300–#303 + agwt#119: Release Integrate 34148543011 failed only scripts/imaging/jax_grad/delaunay.py, AD-vs-FD index 10) | human-authorized corrective-PR exception, live session 2026-09-07 (quote + approval recorded on the issue: https://github.com/PyAutoLabs/autolens_workspace_test/issues/304#issuecomment-5575042508) | diagnosis (Opus): AD matches CI to 1.7e-9 and is bit-identical under pre-#526 PyAutoArray — library exonerated; LL noise floor 1.0e-5 rms / 4.4e-5 ptp on mesh-moving params; old sweep (1e-8,1e-7,1e-6) inside round-off, dataset rebuild #294 shrank AD[10] 4x (noise/signal 1.8% → 6.8%) / per-parameter windows measured (ell_comps_0 clean h in [1e-7,3.4e-6], flip 1.13e-5; einstein_radius clean h ≤ 4.8e-6, flip -8e-6) / fix = rel_steps (1e-6,2e-6,3e-6,1e-5,3e-5): script exits 0 in 70 s, worst rel err 1.131e-3 (p10), p9 7.05e-4; control lp.py PASS 2.9e-8 / positive control (AD×1.05) fails at all 14 indices / heart RED at ship, exception invoked / witness = the script itself under the release env; validation = release-integrate re-dispatch on testpypi 2026.9.7.1.dev75601 after merge | corrective — PR-open (#305, pending-release; merge, close and release stay human) |
## Shadow window — the tier-`notify` merge decision
Opened **2026-08-30**. **RE-OPENED 2026-09-03**: the nominal 2026-09-27 close is
-void. The table below holds **2 rows** against the **40** the pre-registered rule
-requires, and nothing has fed it since 2026-08-31 — the append was anchored to a
-batch review slot, and the batch workflow was retired on 2026-09-03
-(`complete/archive/epics/two_slot_batching_epic.md`). The rule's own instruction
-governs: *extend the window; do not lower the bar*. The window now runs to **40
-candidates**, not to a date, and re-opens from the first row appended by `/prm`
-close-out. Protocol, power calculation and the **pre-registered decision rule**
-live in `draft/feature/pyautobrain/batch_notify_tier_merge.md` — read it before
-appending, and before interpreting anything here.
+void. The window is **counted, not dated** — it runs to **40 tier-`notify`
+candidates** and re-opens from the first row appended by `/prm` close-out. The
+rule's own instruction governs: *extend the window; do not lower the bar*.
+
+Nothing fed the table between 2026-08-31 and the row that re-opens the window,
+because the append was anchored to a **batch review slot**. The *two-slot
+batching epic* was retired on 2026-09-03
+(`complete/archive/epics/two_slot_batching_epic.md`), but the batch slot door
+itself was not: it lives on and runs only when a batch is launched, which on
+most days is never. So the append moved to `/prm` close-out — the one act that
+happens on every shipped task (PyAutoBrain#364).
+
+Protocol, power calculation and the **pre-registered decision rule** live in the
+tier-`notify` protocol prompt (`batch_notify_tier_merge` — in `active/` while
+this ships, `complete/` once it closes out) — read it before appending, and
+before interpreting anything here.
In one line: while the window runs, tier-`notify` work still waits for the human
as it always has, but the gate's verdict and the human's action are both
recorded, so the question "how often would auto-merge have been wrong on this
organism's own work?" is answered with data rather than intuition.
+Count toward 40: 1 (stage 1: 0, stage 2: 1) — window re-opened 2026-09-03; first /prm-appended row: none yet; legacy rows not counted: 1
+
One row per tier-`notify` candidate at close-out. `human action` ∈
`merged-unchanged` / `merged-after-substantive-change` / `not-merged`.
**Substantive** is fixed in advance: a change the human would have minded
@@ -292,4 +302,3 @@ add the independent-model adversarial leg. Never pool the two.
|------|------|------|-----------------------------------------------------|--------------|-------|
| 2026-08-31 | memory-queue-filing-gate (PyAutoMemory#75 / PR#76) | supervised (header safe, bug cap supervised) | tests PASS 169 (make validate + full pytest; no downstream — organ repo) / smoke n/a (organism repo, no script surface) / review CLEAN over ReviewSurface (flags no-test-changes + config-or-schema; retry semantics verified by scratch-repo simulation of the #69 conflict) / heart per shift heart-ack in batches/2026-08-31-pm.md (YELLOW 65 human-acked at dispatch; no re-measure possible in web container, no new reason in blast radius) / witness basis-cited (red/green repro of the 30 test_board.py gate failures; live run only possible post-merge) / adversary (independent model): witness HOLDS, FINDINGS no blockers — findings 1+2 fixed in b5bc248, finding 3 (same discarding retry in knowledge_board.yml + arxiv_refs.yml) recorded as follow-up | PR-open (#76, decision-taken label: ship-vs-park flagged per decide-and-flag — supervised parks at ship, batch dispatch budgeted notify/0; revert = close the PR; merge + re-drive of #69/#71/#72 stay human) | 2 |
| 2026-08-31 | restore-pipeline-narrative-prose | supervised | tests 61 pass / smoke 9-9 pass / review CLEAN (author-run; adversary leg not run — this parks to the human instead) / heart not re-evaluated (web container; dispatch YELLOW ack, batches/2026-08-31-pm.md) / no witness (Consequence: judge) | PR #48 opened on human request 2026-08-31 21:24Z, merged via /prm 2026-09-01 | shipped |
-| 2026-09-07 | jax-grad-delaunay-fd-sweep-repin (autolens_workspace_test#304 / PR#305) — corrective for Heart RED "release validation FAILED (stage integrate)" (sole remaining script after #300–#303 + agwt#119: Release Integrate 34148543011 failed only scripts/imaging/jax_grad/delaunay.py, AD-vs-FD index 10) | human-authorized corrective-PR exception, live session 2026-09-07 (quote + approval recorded on the issue: https://github.com/PyAutoLabs/autolens_workspace_test/issues/304#issuecomment-5575042508) | diagnosis (Opus): AD matches CI to 1.7e-9 and is bit-identical under pre-#526 PyAutoArray — library exonerated; LL noise floor 1.0e-5 rms / 4.4e-5 ptp on mesh-moving params; old sweep (1e-8,1e-7,1e-6) inside round-off, dataset rebuild #294 shrank AD[10] 4x (noise/signal 1.8% → 6.8%) / per-parameter windows measured (ell_comps_0 clean h in [1e-7,3.4e-6], flip 1.13e-5; einstein_radius clean h ≤ 4.8e-6, flip -8e-6) / fix = rel_steps (1e-6,2e-6,3e-6,1e-5,3e-5): script exits 0 in 70 s, worst rel err 1.131e-3 (p10), p9 7.05e-4; control lp.py PASS 2.9e-8 / positive control (AD×1.05) fails at all 14 indices / heart RED at ship, exception invoked / witness = the script itself under the release env; validation = release-integrate re-dispatch on testpypi 2026.9.7.1.dev75601 after merge | PR-open (#305, pending-release; merge, close and release stay human) | corrective |
diff --git a/dashboard.html b/dashboard.html
index d0022948f..4d07f0b7a 100644
--- a/dashboard.html
+++ b/dashboard.html
@@ -295,7 +295,7 @@
Fits a slot (ready to run unattended, cheapest to revie
Issued — each has an open GitHub issue and usually a branch.
-
+
diff --git a/dashboard.md b/dashboard.md
index 5a4b13dcb..1951deb46 100644
--- a/dashboard.md
+++ b/dashboard.md
@@ -264,7 +264,7 @@ Issued — each has an open GitHub issue and usually a branch. The full record f
-📋 Cortex projects route through the domain assistant at execution time — issued 2026-09-07
+📋 Cortex projects route through the domain assistant at execution time — issue #362 — issued 2026-09-07 — library-shipped, awaiting-merge — PRs: PyAutoBrain#367, PyAutoCortex#23
```
/start_dev active/cortex_projects_route_through_assistant.md
diff --git a/scripts/lifecycle.py b/scripts/lifecycle.py
index d038afd85..5bdd5078b 100644
--- a/scripts/lifecycle.py
+++ b/scripts/lifecycle.py
@@ -80,6 +80,29 @@
ARCHIVE_DIR = COMPLETE_DIR / "archive"
DRAFT_DIR = ROOT / "draft"
ACTIVE_MD = ROOT / "active.md"
+AUTONOMY_LOG = ROOT / "autonomy_log.md"
+
+# --- the tier-`notify` shadow window ---------------------------------------
+# The pre-registered decision rule (protocol prompt: batch_notify_tier_merge)
+# grades tier-`notify` candidates over a window of at least 40 rows. The window
+# is COUNTED, not dated: it re-opened on 2026-09-03 and runs from the first row
+# `/prm` close-out appended, because the old append was anchored to a batch
+# review slot that only runs when a batch is launched.
+SHADOW_HEADING = "## Shadow window"
+SHADOW_TABLE_HEADER = "| date | task | tier | gate"
+SHADOW_ACTIONS = (
+ "merged-unchanged",
+ "merged-after-substantive-change",
+ "not-merged",
+)
+SHADOW_STAGES = ("1", "2")
+SHADOW_TARGET = 40
+SHADOW_REOPENED = "2026-09-03"
+# Rows dated before this are the pre-`/prm` history: listed, never counted as
+# "the first row `/prm` appended".
+SHADOW_PRM_EPOCH = "2026-09-07"
+SHADOW_COUNT_PREFIX = "Count toward 40:"
+SHADOW_COUNT_ANCHOR = "One row per tier-`notify` candidate"
H2_RE = re.compile(r"^##\s+(.+?)\s*$")
@@ -1981,6 +2004,156 @@ def cmd_check(args) -> int:
return 0
+# --------------------------------------------------------------------------- #
+# the tier-`notify` shadow window (autonomy_log.md)
+# --------------------------------------------------------------------------- #
+def _md_cells(line: str) -> "list[str]":
+ """The cells of one markdown table row, honouring escaped pipes.
+
+ Rows in this ledger quote shell and Python (`\\|delta\\|`), so a plain
+ `split("|")` invents columns. Splitting on an unescaped pipe is the whole
+ difference between "six cells" and "eight cells" on those rows.
+ """
+ body = line.strip()
+ if body.startswith("|"):
+ body = body[1:]
+ if body.endswith("|") and not body.endswith("\\|"):
+ body = body[:-1]
+ return [c.strip() for c in re.split(r"(? "tuple[int, int]":
+ """[start, end) line indices of the shadow-window section, or ValueError."""
+ lines = text.splitlines()
+ start = None
+ for i, ln in enumerate(lines):
+ if ln.startswith(SHADOW_HEADING):
+ start = i
+ break
+ if start is None:
+ raise ValueError(f"no {SHADOW_HEADING!r} heading in the ledger")
+ end = len(lines)
+ for j in range(start + 1, len(lines)):
+ if lines[j].startswith("## "):
+ end = j
+ break
+ return start, end
+
+
+def shadow_table(text: str) -> "tuple[int, int]":
+ """(header line index, index one past the last data row) of the shadow table."""
+ lines = text.splitlines()
+ start, end = shadow_section(text)
+ header = None
+ for i in range(start, end):
+ if lines[i].startswith(SHADOW_TABLE_HEADER):
+ header = i
+ break
+ if header is None:
+ raise ValueError(
+ f"no row starting {SHADOW_TABLE_HEADER!r} under {SHADOW_HEADING!r}")
+ last = header + 2 # header + separator
+ while last < end and lines[last].startswith("|"):
+ last += 1
+ return header, last
+
+
+def shadow_rows(text: str) -> "list[list[str]]":
+ """Every data row of the shadow table, as cell lists."""
+ header, last = shadow_table(text)
+ lines = text.splitlines()
+ return [_md_cells(ln) for ln in lines[header + 2:last]]
+
+
+def shadow_count_line(rows: "list[list[str]]") -> str:
+ """The section's one-line state of the window, derived from the rows.
+
+ Only stage-1 and stage-2 rows count: the window's own rule forbids pooling
+ the two, and legacy rows carry neither (they predate the stage column's
+ meaning). They stay listed — deleting history to make a counter tidy is how
+ a pre-registered rule stops being pre-registered — and are named as
+ uncounted so the number cannot be read as "the table has N rows".
+ """
+ staged = [r for r in rows if len(r) > 5 and r[5] in SHADOW_STAGES]
+ legacy = len(rows) - len(staged)
+ one = sum(1 for r in staged if r[5] == "1")
+ two = sum(1 for r in staged if r[5] == "2")
+ firsts = sorted(r[0] for r in staged if r[0] >= SHADOW_PRM_EPOCH)
+ first = firsts[0] if firsts else "none yet"
+ line = (f"{SHADOW_COUNT_PREFIX} {len(staged)} (stage 1: {one}, stage 2: "
+ f"{two}) — window re-opened {SHADOW_REOPENED}; "
+ f"first /prm-appended row: {first}")
+ if legacy:
+ line += f"; legacy rows not counted: {legacy}"
+ return line
+
+
+def _shadow_cell(value: str) -> str:
+ """A pipe inside a cell silently splits the row — trade it for a slash."""
+ return " ".join(str(value).replace("|", "/").split())
+
+
+def shadow_apply(text: str, row: str) -> str:
+ """Append `row` under the shadow table and rewrite the count line."""
+ lines = text.splitlines()
+ header, last = shadow_table(text)
+ lines.insert(last, row)
+
+ rows = shadow_rows("\n".join(lines))
+ count = shadow_count_line(rows)
+
+ start, end = shadow_section("\n".join(lines))
+ for i in range(start, end):
+ if lines[i].startswith(SHADOW_COUNT_PREFIX):
+ lines[i] = count
+ break
+ else:
+ for i in range(start, end):
+ if lines[i].startswith(SHADOW_COUNT_ANCHOR):
+ lines.insert(i, "")
+ lines.insert(i, count)
+ break
+ else:
+ raise ValueError(
+ f"no {SHADOW_COUNT_PREFIX!r} line and no "
+ f"{SHADOW_COUNT_ANCHOR!r} paragraph to anchor it to")
+ return "\n".join(lines) + "\n"
+
+
+def cmd_shadow_row(args) -> int:
+ """Append one tier-`notify` row to the shadow window (the /prm close-out hook).
+
+ Dry-run by default: the row and the count line it would produce are printed
+ and nothing is written, because the caller is a skill reading a number back
+ to a human before committing to it.
+ """
+ log = Path(args.log) if args.log else AUTONOMY_LOG
+ if not log.is_file():
+ print(f"shadow-row: no ledger at {log}", file=sys.stderr)
+ return 2
+ text = log.read_text(encoding="utf-8")
+
+ date = args.date or _dt.datetime.now(_dt.timezone.utc).strftime("%Y-%m-%d")
+ row = "| " + " | ".join(_shadow_cell(c) for c in (
+ date, args.task, args.tier, args.gate, args.action, args.stage)) + " |"
+
+ try:
+ updated = shadow_apply(text, row)
+ except ValueError as exc:
+ print(f"shadow-row: {exc}", file=sys.stderr)
+ return 2
+
+ count = shadow_count_line(shadow_rows(updated))
+ print(row)
+ print(count)
+ if not args.apply:
+ print("shadow-row: dry run — nothing written (use --apply)")
+ return 0
+ log.write_text(updated, encoding="utf-8")
+ print(f"shadow-row: appended to {log}")
+ return 0
+
+
def main() -> int:
p = argparse.ArgumentParser(description="PyAutoMind prompt-file lifecycle engine")
sub = p.add_subparsers(dest="cmd", required=True)
@@ -2000,6 +2173,31 @@ def main() -> int:
r.add_argument("--apply", action="store_true")
r.set_defaults(func=cmd_record)
+ sr = sub.add_parser(
+ "shadow-row",
+ help="append one tier-`notify` row to the shadow window in "
+ "autonomy_log.md (the /prm close-out hook)",
+ )
+ sr.add_argument("--date", help="merge date YYYY-MM-DD (default: today, UTC)")
+ sr.add_argument("--task", required=True,
+ help="task slug plus the PR refs, e.g. "
+ "'my-task (PyAutoBrain#1 / PR#2)'")
+ sr.add_argument("--tier", default="notify",
+ help="the sizing tier (default: notify)")
+ sr.add_argument("--gate", required=True,
+ help="the gate cell, copied from the task's ship "
+ "calibration row (tests/smoke/review/heart/witness"
+ "[/adversary])")
+ sr.add_argument("--action", required=True, choices=list(SHADOW_ACTIONS),
+ help="what the human did with the PR")
+ sr.add_argument("--stage", default="1", choices=list(SHADOW_STAGES),
+ help="1 = four-leg gate + witness; 2 = plus the "
+ "independent-model adversary leg")
+ sr.add_argument("--apply", action="store_true",
+ help="write the row (default: dry run)")
+ sr.add_argument("--log", help="path to autonomy_log.md (default: this repo's)")
+ sr.set_defaults(func=cmd_shadow_row)
+
ix = sub.add_parser("index", help="generate complete/index.md (token-light archive navigation)")
ix.add_argument("--apply", action="store_true", help="write complete/index.md")
ix.add_argument("--check", action="store_true", help="fail if index.md is stale (CI)")
diff --git a/tests/test_autonomy_log_shadow.py b/tests/test_autonomy_log_shadow.py
new file mode 100644
index 000000000..ce83a9962
--- /dev/null
+++ b/tests/test_autonomy_log_shadow.py
@@ -0,0 +1,297 @@
+"""Contract tests for the tier-`notify` shadow window and its append hook.
+
+The shadow window is a **pre-registered** decision rule: over a window of at
+least 40 tier-`notify` candidates, the human's action at close-out decides
+whether an agent may ever merge its own low-consequence work. A pre-registered
+rule that anyone can quietly reshape is not pre-registered, so two things are
+pinned here:
+
+1. **The live ledger's schema** — heading, header row, six cells per row, an
+ allowed `human action` on every row the rule actually grades, and a count
+ line that agrees with the rows it claims to count. A count line drifting
+ from its table is the exact failure that would let the window "reach 40"
+ without 40 candidates.
+2. **The append itself** — `lifecycle.py shadow-row` on a fixture: dry run
+ writes nothing, `--apply` appends exactly one row and moves the count, and
+ an action outside the three allowed values is refused.
+
+Same two rules as the other lifecycle tests: fictional fixtures only (`tests/**`
+is KEEP-copied into the public template), and every leg must be shown to fail
+on input that should trip it. The live-ledger legs skip where there is no
+shadow window — a freshly spawned Mind ships the bare ledger header.
+"""
+
+import re
+import subprocess
+import sys
+from pathlib import Path
+
+import pytest
+
+ROOT = Path(__file__).resolve().parents[1]
+sys.path.insert(0, str(ROOT / "scripts"))
+
+import lifecycle # noqa: E402
+
+LIVE_LOG = ROOT / "autonomy_log.md"
+LIVE = LIVE_LOG.read_text(encoding="utf-8") if LIVE_LOG.is_file() else ""
+
+needs_window = pytest.mark.skipif(
+ lifecycle.SHADOW_HEADING not in LIVE,
+ reason="no shadow window in this ledger (e.g. a freshly-spawned Mind)",
+)
+
+HEADER_ROW = ("| date | task | tier | gate (tests/smoke/review/heart/witness"
+ "[/adversary]) | human action | stage |")
+
+
+# --------------------------------------------------------------------------- #
+# fixtures
+# --------------------------------------------------------------------------- #
+FIXTURE = """\
+# Autonomy calibration log
+
+| date | task | effective level | gates | outcome |
+|------|------|-----------------|-------|---------|
+| 2026-08-01 | sprocket-calibration (#1) | safe | tests pass | merged-unchanged |
+
+## Shadow window — the tier-`notify` merge decision
+
+Opened **2026-08-30**.
+
+Count toward 40: 1 (stage 1: 1, stage 2: 0) — window re-opened 2026-09-03; \
+first /prm-appended row: 2026-09-07
+
+One row per tier-`notify` candidate at close-out.
+
+| date | task | tier | gate (tests/smoke/review/heart/witness[/adversary]) \
+| human action | stage |
+|------|------|------|---------|--------------|-------|
+| 2026-09-07 | flywheel-tuning (Flywheel#1 / PR#2) | notify | tests 3 pass \
+| merged-unchanged | 1 |
+
+## Freeze overrides
+
+| date | task / PR | freeze reason | until | thawed by | why |
+"""
+
+
+def _fixture(tmp_path: Path, body: str = FIXTURE) -> Path:
+ log = tmp_path / "autonomy_log.md"
+ log.write_text(body, encoding="utf-8")
+ return log
+
+
+def _run(log: Path, *args: str) -> subprocess.CompletedProcess:
+ return subprocess.run(
+ [sys.executable, str(ROOT / "scripts" / "lifecycle.py"), "shadow-row",
+ "--log", str(log), *args],
+ capture_output=True, text=True)
+
+
+# --------------------------------------------------------------------------- #
+# the live ledger's schema
+# --------------------------------------------------------------------------- #
+@needs_window
+def test_the_window_still_has_its_heading_and_its_header_row():
+ """The append hook finds the table by these two strings — if either is
+ reworded the hook stops appending and says nothing, which is how a window
+ silently stops being fed."""
+ start, end = lifecycle.shadow_section(LIVE)
+ assert end > start
+ header, last = lifecycle.shadow_table(LIVE)
+ assert LIVE.splitlines()[header] == HEADER_ROW
+ assert last > header + 2, "the shadow table has no data rows"
+
+
+@needs_window
+def test_every_row_carries_all_six_cells():
+ """A dropped cell shifts `human action` into `stage` and the count silently
+ changes meaning."""
+ for row in lifecycle.shadow_rows(LIVE):
+ assert len(row) == 6, row
+ assert re.fullmatch(r"\d{4}-\d{2}-\d{2}", row[0]), row[0]
+
+
+@needs_window
+def test_every_prm_appended_row_records_one_of_the_three_allowed_actions():
+ """`human action` is a merge outcome, and the decision is a count over
+ exactly three of them.
+
+ The boundary is the window's own: rows before the `/prm` epoch were
+ appended at **PR-open** by the retired batch protocol, so their action cell
+ holds a PR state ("PR-open (#76, ...)") rather than what the human then did
+ — which is precisely why the append moved to close-out, and why the header
+ re-opens the window from the first `/prm`-appended row. They stay as
+ history; from the epoch on, the vocabulary is fixed.
+ """
+ for row in lifecycle.shadow_rows(LIVE):
+ if row[0] >= lifecycle.SHADOW_PRM_EPOCH:
+ assert row[4] in lifecycle.SHADOW_ACTIONS, row
+ assert row[5] in lifecycle.SHADOW_STAGES, row
+
+
+@needs_window
+def test_the_count_line_agrees_with_the_rows_it_counts():
+ """Recomputed from the table, not from the sentence — the whole point is
+ that the number cannot be edited independently of the evidence."""
+ rows = lifecycle.shadow_rows(LIVE)
+ line = next((ln for ln in LIVE.splitlines()
+ if ln.startswith(lifecycle.SHADOW_COUNT_PREFIX)), None)
+ assert line is not None, "the shadow window has no count line"
+
+ m = re.match(
+ lifecycle.SHADOW_COUNT_PREFIX
+ + r" (\d+) \(stage 1: (\d+), stage 2: (\d+)\)", line)
+ assert m, f"count line does not parse: {line!r}"
+ total, one, two = (int(g) for g in m.groups())
+
+ graded = [r for r in rows if r[5] in lifecycle.SHADOW_STAGES]
+ assert (total, one, two) == (
+ len(graded),
+ sum(1 for r in graded if r[5] == "1"),
+ sum(1 for r in graded if r[5] == "2"),
+ ), line
+ assert total == one + two, line
+ assert total < lifecycle.SHADOW_TARGET or "reached" in line.lower(), (
+ "the window has reached its pre-registered size — the decision is due, "
+ "and this line should say so")
+
+
+@needs_window
+def test_a_dropped_cell_would_be_caught():
+ """The schema check above is only worth its runtime if a malformed row
+ actually trips it (the positive control)."""
+ assert len(lifecycle._md_cells("| a | b | c | d | e |")) == 5
+
+
+@needs_window
+def test_escaped_pipes_do_not_invent_columns():
+ """Gate cells quote shell and Python; `\\|delta\\|` must stay one cell."""
+ cells = lifecycle._md_cells(r"| 2026-09-07 | t | notify | \|d\| = 1 "
+ r"| merged-unchanged | 1 |")
+ assert len(cells) == 6, cells
+ assert cells[3] == r"\|d\| = 1"
+
+
+# --------------------------------------------------------------------------- #
+# the append hook
+# --------------------------------------------------------------------------- #
+def test_a_dry_run_leaves_the_file_byte_identical(tmp_path):
+ """The hook is called by a skill that reads the count back to a human
+ before committing to it, so the default must not write."""
+ log = _fixture(tmp_path)
+ before = log.read_bytes()
+ r = _run(log, "--date", "2026-09-08", "--task", "widget-press (Widget#3)",
+ "--gate", "tests 4 pass", "--action", "merged-unchanged",
+ "--stage", "1")
+ assert r.returncode == 0, r.stderr
+ assert log.read_bytes() == before
+ assert "| 2026-09-08 | widget-press (Widget#3) | notify |" in r.stdout
+ assert "Count toward 40: 2 (stage 1: 2, stage 2: 0)" in r.stdout
+
+
+def test_apply_appends_exactly_one_row_and_moves_the_count(tmp_path):
+ log = _fixture(tmp_path)
+ before = lifecycle.shadow_rows(log.read_text())
+ r = _run(log, "--date", "2026-09-08", "--task", "widget-press (Widget#3)",
+ "--gate", "tests 4 pass", "--action",
+ "merged-after-substantive-change", "--stage", "2", "--apply")
+ assert r.returncode == 0, r.stderr
+
+ text = log.read_text()
+ after = lifecycle.shadow_rows(text)
+ assert len(after) == len(before) + 1
+ assert after[:-1] == before, "an existing row was rewritten"
+ assert after[-1] == ["2026-09-08", "widget-press (Widget#3)", "notify",
+ "tests 4 pass", "merged-after-substantive-change", "2"]
+ assert ("Count toward 40: 2 (stage 1: 1, stage 2: 1) — window re-opened "
+ "2026-09-03; first /prm-appended row: 2026-09-07") in text
+ # the rest of the ledger is untouched
+ assert "## Freeze overrides" in text
+ assert "| 2026-08-01 | sprocket-calibration (#1) |" in text
+
+
+def test_an_action_outside_the_three_values_is_refused(tmp_path):
+ """The window counts three outcomes. A fourth would be uncountable, and
+ the rule is pre-registered over exactly these."""
+ log = _fixture(tmp_path)
+ before = log.read_bytes()
+ r = _run(log, "--task", "t", "--gate", "g", "--action", "merged-ish",
+ "--apply")
+ assert r.returncode != 0
+ assert "merged-ish" in r.stderr
+ assert log.read_bytes() == before
+
+
+def test_a_stage_outside_one_and_two_is_refused(tmp_path):
+ """`stage: 1` and `stage: 2` are never pooled; a third stage would have no
+ pre-registered meaning."""
+ log = _fixture(tmp_path)
+ r = _run(log, "--task", "t", "--gate", "g", "--action", "not-merged",
+ "--stage", "3", "--apply")
+ assert r.returncode != 0
+
+
+def test_a_pipe_in_a_cell_cannot_split_the_row(tmp_path):
+ """An unescaped pipe in a free-text cell would silently add a column and
+ push `stage` off the end of the row."""
+ log = _fixture(tmp_path)
+ r = _run(log, "--date", "2026-09-08", "--task", "widget | press",
+ "--gate", "tests pass | smoke n/a", "--action", "not-merged",
+ "--stage", "1", "--apply")
+ assert r.returncode == 0, r.stderr
+ row = lifecycle.shadow_rows(log.read_text())[-1]
+ assert len(row) == 6, row
+ assert row[1] == "widget / press"
+ assert row[3] == "tests pass / smoke n/a"
+
+
+def test_a_ledger_with_no_shadow_window_is_an_error_not_a_silent_no_op(tmp_path):
+ """Exit 2, not 0: a hook that cannot find its table must stop the caller,
+ because the caller's next act is to commit and report a number."""
+ log = _fixture(tmp_path, "# Autonomy calibration log\n\n| date |\n|---|\n")
+ r = _run(log, "--task", "t", "--gate", "g", "--action", "not-merged",
+ "--apply")
+ assert r.returncode == 2
+ assert lifecycle.SHADOW_HEADING in r.stderr
+
+
+def test_the_count_line_is_created_when_the_section_has_none(tmp_path):
+ """A window that predates the count line still gets one, anchored before
+ the paragraph that defines the rows."""
+ body = FIXTURE.replace(
+ "Count toward 40: 1 (stage 1: 1, stage 2: 0) — window re-opened "
+ "2026-09-03; first /prm-appended row: 2026-09-07\n\n", "")
+ assert lifecycle.SHADOW_COUNT_PREFIX not in body
+ log = _fixture(tmp_path, body)
+ r = _run(log, "--date", "2026-09-08", "--task", "widget-press",
+ "--gate", "tests pass", "--action", "not-merged", "--stage", "1",
+ "--apply")
+ assert r.returncode == 0, r.stderr
+ text = log.read_text()
+ count = next(ln for ln in text.splitlines()
+ if ln.startswith(lifecycle.SHADOW_COUNT_PREFIX))
+ assert "Count toward 40: 2" in count
+ idx = text.index(count)
+ assert idx < text.index(lifecycle.SHADOW_COUNT_ANCHOR)
+
+
+def test_legacy_rows_are_listed_but_never_counted(tmp_path):
+ """Rows whose stage cell is neither 1 nor 2 predate the stage rule. They
+ stay in the table — deleting history to tidy a counter is how a
+ pre-registered rule stops being one — and are named as uncounted."""
+ body = FIXTURE.replace(
+ "| merged-unchanged | 1 |\n",
+ "| merged-unchanged | 1 |\n"
+ "| 2026-08-31 | old-flywheel-run | supervised | tests pass "
+ "| PR #9 opened, merged later | shipped |\n")
+ log = _fixture(tmp_path, body)
+ r = _run(log, "--date", "2026-09-08", "--task", "widget-press",
+ "--gate", "tests pass", "--action", "not-merged", "--stage", "1",
+ "--apply")
+ assert r.returncode == 0, r.stderr
+ text = log.read_text()
+ assert "| 2026-08-31 | old-flywheel-run |" in text
+ assert "Count toward 40: 2 (stage 1: 2, stage 2: 0)" in text
+ assert "legacy rows not counted: 1" in text