THE SUBSTRATE — doctrine → code

The implemented libraries, mapped to the doctrine documents they mechanize. Nothing here is aspirational: every library ships with a stdlib unittest suite, and the v1 audit's bugs are kept dead by adversarial reproduction. ↳ lib/ · gates/ · bin/ · tests/

6
libraries (lib/)
2
gate scripts (gates/)
209
tests
3
adversarial checks

1 · Library cards — which doctrine each implements

lib/ledgerlib.py 816 LOC
ledgerlib — the append-only ledger substrate (specs/LEDGER.md).
implements → system/specs/LEDGER.md: envelope validation, the 10 record types, prev_hash chain, per-day segments, kill-at-ingest
gates/gatelib.py 1296 LOC
gatelib.py — the shared gate library (GATES.md v2 contract, §1–§5).
implements → system/specs/GATES.md: count_corroboration, cooldowns, mark_consumed, graduation, write_qualified, apply_console
lib/manifestlib.py 415 LOC
manifestlib — worker-manifest schema validation, commissioning pre-flight.
implements → system/specs/CHANNELS.md (four channels, C1–C7 preflight) + GATES.md §6 commissioning contract
lib/valuesgate.py 218 LOC
valuesgate — the floor gate template carried by every worker (GATES.md §6).
implements → system/specs/GATES.md §6: the dumb, un-overridable values floor checked on every outbound action
lib/monitorlib.py 479 LOC
monitorlib — monitoring-layer primitives (corpus/LOOP-CLOSURE.md §3).
implements → system/corpus/LOOP-CLOSURE.md §3: memory and comparison — meters, baselines, drift arithmetic over the ledger
lib/sklib.py 886 LOC
sklib — self-knowledge layer primitives (BLUEPRINT.md self-knowledge table).
implements → system/corpus/LOOP-CLOSURE.md §5: set reconciliation, orphan detection, canary planting/checking — findings, never actions
lib/funnellib.py 676 LOC
funnellib — executive funnel primitives (system/corpus/FUNNEL.md).
implements → system/corpus/FUNNEL.md: condensers, bad-news conservation traces, flag reconciliation, the Executive Brief
bin/podrun.py 266 LOC
podrun — the pod-runner harness.
implements → system/ops/DEPLOYMENT.md §3–§4: manifest + directive → one scheduled tick with the full substrate enforced around it
gates/voice-pattern-gate.py 42 LOC
voice-pattern-gate.py — thin wrapper over gatelib (GATES.md §4).
implements → system/specs/GATES.md §4: the per-gate script shape — declare name + key extraction, delegate everything to gatelib
workers/health_probe.py 39 LOC
health-probe worker — the first real script worker.
the first commissioned worker run under podrun: heartbeats, ledger-mirrored

2 · VERIFIED DEAD — the four v1 bugs, killed by adversarial reproduction

tests/adversarial_check.py recreates each v1 failure scenario against the real API — exit 1 if any survives.
Adversarial check #2 — the canary discipline (tests/adversarial_check_sk.py, LOOP-CLOSURE.md §5): a planted fake-orphan canary must be CAUGHT by the real detector; a canary must NEVER leak into published findings; a detector deprived of its input must score MISSED, never silently fine — a blind detector is loud.
Adversarial check #3 — bad-news conservation (in tests/test_funnellib.py): a doctored condenser tier that drops a kill verdict's flag must be ruled DROPPED and named exactly; conservation_trace on a pass is an error — only bad news is traced.

3 · Test inventory

FileTestsCovers
tests/test_manifestlib.py44Tests for lib/manifestlib.py and lib/valuesgate.py — stdlib unittest only.
tests/test_sklib.py44Tests for lib/sklib.py — the self-knowledge layer primitives.
tests/test_gatelib.py35test_gatelib.py — stdlib unittest suite for gates/gatelib.py (GATES.md v2).
tests/test_funnellib.py34Tests for lib/funnellib.py against system/corpus/FUNNEL.md.
tests/test_ledgerlib.py30Tests for lib/ledgerlib.py against system/specs/LEDGER.md.
tests/test_monitorlib.py22Tests for lib/monitorlib.py against corpus/LOOP-CLOSURE.md §3.
tests/adversarial_check.pyAdversarial verification: the four v1 audit bugs must be DEAD in gatelib.
tests/adversarial_check_sk.pyAdversarial check #2 — the canary discipline (LOOP-CLOSURE.md §5).
Total209

4 · The podrun flow — one scheduled tick, substrate enforced

manifest
manifests/<worker>.yaml — the commissioning record + the directive file
preflight
commissioning pre-flight via manifestlib — an unwired worker does not run. Exit 6: NOT COMMISSIONED = refused.
values guard
the floor gate (valuesgate) checked on every outbound action. Exit 7: values block.
tick
script workers run inline; llm workers get the run envelope (prompt assembled from directive + delta-brief) and hand off to the scheduler — podrun never calls a model
ledger + broadcast + mirror
heartbeat/verdicts/records mirrored to the ledger (ledgerlib); state + log written; broadcast-up to the captured endpoint; Discord mirror queue (display, never transport)

↳ bin/podrun.py · system/ops/DEPLOYMENT.md §3–§4