Section 02 — count-gate-trigger
Goal
Compute the code-bearing disposition count since the watermark and fire a threshold gate via an exception-safe sibling of the evolution trigger.
Implementation Sketch
Add a status-filtered count over {KEPT,REFINED,PARTIAL} since the watermark in scripts/plan_orchestrator/route_walk.py (adapting read_ledger_cycle_count; entries carry a status field). Add a named constant default interval 20 (overridable by plan’s hygiene_sweep.interval). Add forward_hygiene_sweep_trigger(plan_dir) + attach_hygiene_sweep_advisory(env, plan_dir) as exception-safe siblings of forward_ledger_evolution_trigger (return None / no-op on any error; never break serve emission). Gate fires when count - last_swept_count >= interval AND hygiene_sweep.enabled.
Spec References
scripts/plan_orchestrator/route_walk.py:read_ledger_cycle_count + forward_ledger_evolution_trigger; scripts/plan_corpus/schemas.py:LEDGER_STATUSES; scripts/ledger_evolution_runtime/gates.py:evaluate_trigger (gate-math precedent).
Work Items
- Add status-filtered code-bearing count {KEPT,REFINED,PARTIAL} since watermark in route_walk.py.
- Add the named-constant default interval (20) + threshold check (count - last_swept_count >= interval, gated on enabled).
- Add forward_hygiene_sweep_trigger + attach_hygiene_sweep_advisory as exception-safe siblings of the evolution trigger.
- pytest: count filters non-code-bearing statuses; gate fires/doesn’t at the boundary; watermark-relative not modulo.
Fresh intel (regenerated)
{ “schema_version”: 1, “target”: { “kind”: “plan-section”, “ref”: “grind-hygiene-sweep/s-5464304c” }, “generated_at”: “2026-06-19T18:39:19.550150+00:00”, “graph_state”: { “head_sha”: “dbb10f0e”, “last_code_import_at”: “2026-06-19T17:39:41.692Z”, “embedding_stale”: false, “insights_stale”: false, “cpg_stale”: false }, “surfaces”: {}, “summary”: “intel-package[plan-section:grind-hygiene-sweep/s-5464304c] agent-authored dossier”, “degraded”: false, “dossier”: { “objective_symbols”: [], “tiers”: {}, “agent_authored”: true, “difficulty”: { “class”: “routine”, “research_online”: false, “research_mode”: “auto”, “signals”: [], “plan_dir”: “/home/eric/projects/ori_lang/plans/grind-hygiene-sweep” } } }
(full dossier: count-gate-trigger—s-5464304c.intel.json)