Lessons to guards

Every mistake an agent was corrected for becomes a numbered lesson, and a lesson that recurs is moved out of prose into a hook, gate or test that refuses the mistake. A checker on every push keeps the claimed status of all 168 lessons honest.

  • Self-improving harness
  • Guardrails
  • Agent evaluation
  • Context engineering
What it is
A ledger of behavioural rules (LESSONS.md), the story behind each one (docs/lessons-cases.md), a declared home and enforcer per rule (docs/lessons-status.json), and a checker (bin/lessons_status.py) that derives each rule's status and fails the push when a claim contradicts the tree.
What it isn't
Not a project wiki or a decision log. Project facts go to the task board, visual patterns to a UI registry. A lesson must be about agent behaviour, must have been actually corrected, and must generalise to a different repo. The checker also does not prove a guard fires: that is each guard's own test.
Why it exists
The first design held rules in a file until they had been seen three times, then proposed promoting them into the global prompt. Across 26 rules that never fired once: recurrence needed the rule to be loaded, and loading only happened after promotion. Lessons now route on first sighting, and a rule that recurs after routing has proved prose cannot hold it.
168lessons, L01 to L168
34enforced by a hook, gate or test
23promised a guard, not built
102prose only
37one-line habits in the global prompt

How it works

A lesson enters at the end of a session. /wrap-up step 2.5 runs two report-only scanners over the session's own transcript: confession_scan.py lists every place the agent admitted a mistake in prose, and failure_harvest.py lists shell calls that failed and then passed on a retry. Neither logs anything. Each hit gets a disposition from the agent and operator: a new lesson, a bump of an existing one, or a one-line dismissal in the session report. Zero lessons is the expected result for a session nobody corrected.

A logged lesson gets an id, a row in the ledger and a row in the status file naming its home (where the rule text lives) and its enforced_by list (what stops the mistake). The status is never typed. lessons_status.py derives it on every run from those two fields and the tree:

StatusMeansCount today
enforcedAn enforced_by file exists, cites the lesson id, and is switched on (a registered hook, a test on pre-push, or a gate)34
promisedThe ledger routed it to code (a hook, test or taskman check) that is not built or not wired yet23
proseLives as text in the global prompt, a skill, a command or a workflow doc102
stagingLogged, no destination named yet6
external / droppedLives in a product repo's own docs; or retired with a measured reason2 / 1
lessons_status.py --check on every push · a claimed status must match the tree Correction test, review, operator Ledger row id + status-file row Prose home global prompt · skill Measured guard_score on corpus Guard hook · gate · test Do not build measurement kept wrap-up route recurs passes <3 true hits or FP stays prose
A rule climbs only when it fails as prose and its shape is measurable. The bar for a shell guard is at least 3 true hits in the transcript corpus, zero false positives after a hand check, and no more than 1% of all shell calls, because a built guard runs before every one of them.

Two rules make the ladder move. First, log_lesson.py --recurrence-of L<n> refuses a prose destination for a rule that has already recurred once: the new entry must name something that runs. Second, a guard is scored before it is built. bin/guard_score.py replays a candidate regex, or an existing hook, over every recorded shell call and prints the base rate and each hit for a hand check. In one measured round five candidate shapes were scored over about 67,000 calls: two were built, three were recorded as do-not-build with their numbers kept.

What does the enforcing

KindEnforced lessonsExamples
Gate in a workflow script15mow's wave-landing, tracker, verification and action-report checks; commit-own; the board CLI
Hook12hooks/guard-shell-status.py (pipe status, exported index, tied zsh parameters, ungated commits), hooks/peer-session-guard.py, the git pre-push checks
Test on pre-push7prompt budget, UI bans, guard test suites

Four cases

Each lesson cost a real session. These four show the range, from a prose rule that failed to a guard built the same day. Project names are removed.

A semicolon that committed a failed gate (L87, then L167)

L87 said to chain a dependent step with &&, never ;. It came from git push …; git merge … merging after a refused push, leaving a merge commit that claimed the work was on the remote. It lived in the global prompt. When its shape was scored over the corpus it found one true hit, and the intent ("this step depends on that one") is not readable from command text, so it was recorded do-not-build and stayed prose.

A week later it recurred in a narrower form: one shell call ran a mow gate check, then on a later line, after a newline, committed the record of that check. The gate exited 1 and the record was committed anyway. That narrower shape is decidable: a gate script reaching git commit through anything but &&. It became L167 and was built into guard-shell-status the same day. Over 81,598 corpus shell calls it hits 29 (0.036%), every one a commit its gate did not gate. It asks rather than denies, because committing a failed gate's record on purpose is legitimate, and five first-pass false positives became stand-down test fixtures.

An amend that rewrote a peer's commit (L55)

In a checkout shared by two sessions, an agent folded a forgotten file into its last commit with git commit --amend -- <paths>. A peer had committed in the seconds between. The amend rewrote the peer's commit under the agent's message, absorbing 84 lines of the peer's work and dropping the agent's own two files. Only a diffstat that read 84 insertions where about 3 were expected gave it away. peer-session-guard now asks before any amend while another session is live.

Green tests and dead mutants that still missed (L54)

A rewritten parser for mow's wave map had 36 passing tests and killed five of five mutants, and still dropped a lane whose label used an em dash. Every fixture had been invented by hand. The 105-line corpus of real wave maps that had diagnosed the original bug exposed the fix's own bug. The rule, mutation coverage is not fixture coverage, lives in the tdd and adversarial-tester skills. It is prose, because "a real corpus exists on disk" is not visible in a command.

A push that became a branch delete (L95, L96)

Two shell mistakes in one session. An exported GIT_INDEX_FILE was inherited by a pre-push hook's test suite, which committed against the wrong index. Later, after a failed step joined with ;, git push origin "${C}:refs/heads/master" ran with C empty and sent :refs/heads/master, which is a delete, refused only because it was the default branch. Both now have guards: guard-shell-status denies a commit or push while the index variable is exported, and a pre-push hook refuses a deleting push unless an override is set.

AI engineering practices it demonstrates

  • Measure before you guard. Every shell guard has a base rate from real sessions and a hand-checked hit list before it ships, under a written build bar. Failing candidates keep their numbers.
  • Status is derived, never typed. The checker reads the declared claim and the tree and computes the status; a hand-written "enforced" cannot survive a push if the file does not cite the lesson.
  • Recurrence is the promotion signal. A rule that recurs after landing is evidence its home cannot hold it, and the logger refuses another prose home.
  • Asks, not denies, where intent is legitimate. Guards that would block correct commands downgrade to a prompt for the operator.
  • Context budget. The global prompt carries one line per habit with its id; the full story lives in docs/lessons-cases.md, read only when the why is needed.
  • A lesson cannot loosen the harness. The ledger's guardrail: no entry may weaken the global rules, license skipping a gate, or excuse reporting unfinished work as done.
  • Privacy of the corpus. Scoring tools print real commands to stdout only; counts from the real corpus never go into the status file, and a repo-shape test refuses personal paths in tracked files.

Capabilities

ToolDoes
skills/wrap-up/scripts/log_lesson.pyWrites the ledger row and the status-file row together; --bump, --route, --recurrence-of.
bin/lessons_status.pyGrouped report of every lesson's derived status; --check exits 1 on a contradiction and runs in githooks/pre-push.
bin/guard_score.pyBase rate of a regex or a hook over the transcript corpus; --rules labels probed prose rules holding, not-holding, never-fires or too-new.
bin/failure_harvest.py, confession_scan.pyFind candidate lessons in a session: retried failures, and admitted mistakes. Report only.

Benefits

  • Enforced lessons rose from 10 at plan time (2026-09-29) to 34 today, each with a test that proves the guard fires.
  • A rule's status is visible in one command, so "is this enforced or just written down?" has an answer that cannot drift.
  • The global prompt stays short: 37 one-line habits, each pointing at an id whose full case is a file away.
  • Rejected guards are recorded with their numbers, so the same idea is not re-proposed from scratch.

Limits

Where it loses

Most of the rules are still prose. 102 of 168 depend on an agent reading and obeying a line of text, and 23 more are promised a guard that does not exist yet. The case above shows how that fails: L87 sat in the global prompt and still recurred.

  • "Enforced" means cited and switched on. The checker confirms the named file cites the lesson and is registered; it does not run the guard. Whether it fires is left to that guard's own test, and 15 gate rows print "wiring unchecked".
  • Only shell commands are measurable. Rules about reading a file before editing it, or which tool to call first, leave no regex-matchable trace, so the corpus scorer cannot say whether they hold.
  • Text matching is a contest. Shell guards match command text. Absolute-path git, unusual option orders and nested subshells are known misses listed on the board.
  • Capture depends on wrap-up. A mistake nobody corrected, or a session that never wraps up, leaves no lesson.
  • One operator's corpus. Base rates come from one person's sessions on one machine; they say little about another team's habits.

Roadmap

ItemWhy it mattersStatus
Reconcile a guard with its own measurementThe probe for the exported-index rule shows post-landing violations and zero denies although a guard carries that rule; either the guard allows those shapes or the probe is wrongcorrectness
Derive recurrence when routing a staged lessonToday the prose refusal applies only if the caller passes --recurrence-of; a recurring rule can still be routed to prosehigh
Guard tests that run git under a pre-push hookPoint each suite at a decoy repo and refuse the push if the decoy changedhigh
Pass-through filter before &&cmd | wc -l && commit commits whatever cmd did; waits on an operator ruling on scopedecision
Classify the first 24-rule batchRules routed together in August were never sorted into prose versus guard candidatesbacklog
A/B evals for prose rulesA headless with/without test for rules the corpus cannot seerevisit

Sources

  • LESSONS.md: ledger, routing table, the "seen ×3" history and the guardrail.
  • docs/lessons-cases.md: the full cases for L54, L55, L87, L95/L96 and L167.
  • docs/lessons-status.json and bin/lessons_status.py: counts above are that script's output on 2026-10-08 (enforced 34 · promised 23 · prose 102 · staging 6 · dropped 1 · external 2).
  • global/CLAUDE.md, section "Verification habits": 37 one-line rules.
  • skills/wrap-up/SKILL.md step 2.5 and skills/wrap-up/scripts/.
  • docs/workflow/guard-scoring.md, bin/guard_score.py, bin/failure_harvest.py.
  • docs/plans/lessons-to-guards/plan.md (build bar, plan-time count of 10) and evidence/shape-scores.md (five shapes, two built).
  • githooks/pre-push: runs lessons_status.py --check.
  • Task board: open items for the guards and checks listed in the roadmap.

Facts as of 2026-10-08. Counts read from bin/lessons_status.py output and source on that date.