Skip to content

Latest commit

 

History

History
428 lines (339 loc) · 30.5 KB

lessons.md

File metadata and controls

428 lines (339 loc) · 30.5 KB

Lessons

A mistake is cheap the first time and expensive every time after. devkit keeps lessons: short, blameless records of what went wrong, why, and what stops it from happening again. devkit keeps every lesson that still matters, recalls it before the work it applies to, records whether it was shown and whether the mistake recurred, and turns a lesson that keeps repeating into a check that stops the mistake. Every night it consolidates what it learned, like a brain while it sleeps.

The learning-loop skill teaches both agents this loop, and the global instructions require it. When the mistake is devkit's own (a crash, a hook that fails, a dev command that refuses what it should allow), it belongs in the bug registry, not in a lesson (see When devkit itself is the problem).

The life of a lesson: signals such as fix and revert commits, missed status blocks, bouncing tasks, and corrections from the developer prompt a lesson; dev lesson add captures it in lessons/<scope>/ in the handoff repository; every session recalls the open lessons that apply as known pitfalls; dev lesson recur counts a repeat, and a recurring lesson is automated with dev lesson prevent (a test, lint rule, lesson rule, required skill, or CI check); every night dev sleep merges near-duplicates and forgets lessons that no longer help into lessons/archive/, from where dev lesson restore brings one back.

When to record a lesson

Record one when something went wrong that could happen again:

  • you fixed a bug, or a change was reverted;
  • CI failed for a reason the local run did not catch;
  • a dev command refused the same kind of call more than once, and the refusal was right;
  • a task went back to "doing" more than once;
  • the developer corrected the agent, for example with "that's wrong" or "you forgot the migration."

Skip typos and one-off hiccups of the environment. Apply the durable bar first: if this lesson disappeared, would someone reading the final code still repeat the mistake? If the code or its test already holds the knowledge, a lesson adds nothing. If the lesson already exists, count the repeat with dev lesson recur instead (see Recur).

devkit helps you notice the moments that deserve one:

  • After a fix. When a session made a fix: or revert commit, the Stop hook asks the agent once, at the end of a turn, whether it was a mistake worth a lesson (or a known pitfall that repeated). Its hint gives the anchor flags (--file, --command, --error), since a lesson with none is refused.
  • dev lesson scan lists the signals of the last 14 days (--days N) that have no lesson yet, each with the command to record one.
Signal Where it comes from
revert · fix Revert and fix: commits in the repository
canary Two or more replies without the status block
task A work item that was reopened or unblocked more than once

devkit never writes a lesson by itself, and it never reads your prompts for corrections: you write in any language, and a word list would miss most of them. When you correct the agent, the agent records the lesson, as the global instructions require.

Write it

dev lesson add "Never gate a push on a piped test run without pipefail" \
  --kind process --severity high \
  --happened "the tests failed, but their output was piped into tail and the push went ahead" \
  --cause "the && saw the exit code of tail, not of the tests" \
  --fix "ran the suite again without the pipe" \
  --prevent "never gate a commit or push on a pipeline without set -o pipefail" \
  --detect "CI fails right after a push that passed locally" \
  --evidence "commit d75a9f9" \
  --command "git push" --activity cicd
✓ L-fwqyx0ywj1x recorded in acme/billing → ~/Development/.handoff/lessons/acme/billing/L-fwqyx0ywj1x.md
  automate it when you can: dev lesson prevent L-fwqyx0ywj1x --by test|lint|rule|skill|ci --ref … --why …
  • The title is the rule, the thing to do or never do, in at most 80 characters on one line, and it does not start with [. Agents see the title first, so it should be enough to act on.
  • Say what happened. --happened or --evidence is required: a lesson nobody can trace back to a real event is a guess.
  • The root cause and the prevention are required. Ask "why" until the answer is something you can change: a missing test, an unclear rule, a tool that allows the wrong thing. The prevention is a rule someone can follow tomorrow, stated as an action.
  • Choose the scope. The project you are in (the default, or -p), an initiative (-i <slug>), or --global for mistakes any project can make.
  • Kinds: bug, mistake (the default), process, tooling, security, performance, design. Severity: low, medium (the default), high. Keep the defaults unless the mistake is another kind or cost more.
  • Optional: --fix, --detect, --evidence (repeat it: commits, PRs, CI runs, tasks), --tag, --why, and --retire-when for an outside change that makes the lesson obsolete (a library version or an upstream fix).
  • Anchor it: say where it applies with --file, --command, --activity, --error, or --stack (see Anchors). dev lesson add refuses a lesson with no anchor and names the flags that give one (--file, --command, --error, or --activity), because recall never shows a lesson without one.
  • Never put secrets or personal data in a lesson.

Every problem at once. When dev lesson add refuses, it lists every problem it found, one per line: the anchors, the kind and severity, the cause and prevention, the shape of the title, and a duplicate. Fix them all and run it once more. Each refusal is recorded in the audit trail as dev.lesson.refused, with its problems and without the lesson's title or error text.

One lesson per mistake. dev lesson add checks the open and the archived lessons of the scope and the global ones first. When one shares an error anchor with the new lesson (in any case), it refuses with looks like L-… (“<its title>”): run `dev lesson recur L-… --evidence …`, or add `--new --why …` if it is another mistake. Count the repeat on the existing lesson, or add --new with the reason the mistake is a different one. A shared command, file, or kind of work alone is another mistake, because one command goes wrong in many ways, each with its own error; the nightly merge still joins lessons that share at least 60% of their anchors (see Sleep).

Who wrote it. Every lesson records its author: the crew member whose lane ran dev lesson add, as <Role> (<Name>) (for example DevEx engineer (Kid)); the Tech lead (Morpheus) in an agent's main session; or the developer by their git user name in their own terminal. When devkit cannot tell (a script, or a lane the run does not know), it names the agent, or the user and host. The record also keeps the session and machine it came from. Recall shows the author next to the lesson, and every later edit keeps its own author in the changelog.

A lesson is a Markdown file in the handoff repository, lessons/<project id>/, lessons/initiatives/<slug>/, or lessons/global/, with its fields in a front matter block, the sections What happened, Root cause, Fix, Prevention, Detection, and Evidence, and a changelog. Every change bumps its version and makes one commit; change lessons/ only through dev lesson, which keeps that changelog.

Held lessons

Lessons sync to every teammate's agents through git, and planted memory files are a known way to attack coding agents. That is why dev lesson add and every update screen the text and hold a lesson that:

  • has invisible or direction-changing characters;
  • contains a value that looks like a secret;
  • tries to override the developer or devkit, such as "ignore previous," "ignore every earlier instruction," "you are now," "new instructions," "always allow," "skip hooks," or setting one of devkit's identity variables;
  • downloads and runs code (curl … | sh), or pipes into a shell;
  • has a URL;
  • names a flag or setting that runs without the checks, such as --no-verify, git commit -n, --dangerously-skip-permissions, bypassPermissions, core.hooksPath=/dev/null, or --no-gpg-sign;
  • names a path under the agents' or devkit's configuration folders;
  • has a command substitution ($(…)) or a command in backticks beside a destructive command (rm -rf, sudo, chmod -R 777, a forced git push, or fetched code that a shell runs);
  • runs a command substitution as code (handed to eval, source, ., exec, or a shell, or where a backtick command starts), or decodes text inside one (base64 -d, xxd -r, printf escapes).

The screen reads look-alike Cyrillic and Greek letters as Latin, so a word spelled with them is held like the plain one. The last four forms hold only in the title, Prevention, and Fix, the fields agents act on. In What happened, Root cause, Detection, and Evidence, which explain what ran and what it touched, they do not hold. A substitution alone holds nowhere, and a placeholder such as $(…) passes, because lessons name them to warn against them.

Recall screens each lesson again as it loads it, because a lesson file edited by hand or pulled from a teammate never passed dev lesson add. A held lesson carries quarantine: <reason> in its front matter, or is held as loaded, and is never recalled. dev lesson review and dev lesson lint list the held lessons. Review the exact text before releasing it with dev lesson release <lesson> --why "…", which runs for whoever calls it, you or an agent; devkit never releases a held lesson by itself. A release counts for the text reviewed on this machine: an edit of that text, or the file on another machine, is screened again.

Replace or retire a lesson

  • dev lesson supersede <old> --by <new> --why "…" marks a lesson as replaced by a newer one, so two lessons that contradict each other never both reach an agent.
  • dev lesson retire <lesson> --why "…" marks a lesson that no longer applies.

Every command that changes a lesson (recur, prevent, retire, anchor, supersede, release, and restore) reaches only the lessons of its scope (the project you are in, -p, -i, or --global), that project's initiatives, and the global ones. A lesson of another scope is refused with the option that names its scope, such as -p acme/api. dev lesson show reads every scope.

Anchors: where a lesson applies

devkit decides which lessons a piece of work needs from what the work does, never from the words anyone wrote about it. Developers and agents write in any language, so a lesson carries anchors, which mean the same in every language:

Anchor Flag (repeat it) Matches
Files --file "db/migrations/**" A file or glob, compared with the files a step owns or a call writes
Commands --command "git push --force" Command words, in order; quoted text that only mentions them does not count
Kinds of work --activity database An id from dev crew raci; an unknown id is refused
Error signatures --error "relation does not exist" Text the tool output shows when the mistake happens
Stack --stack python The stack it applies to

An anchor that matches everything recalls the lesson everywhere, which is the same as nowhere, so devkit refuses broad ones:

  • A one-word command anchor needs a second word when it is a common program or shell, such as python3, git, dev, sed, zsh, rm, grep, find, make, docker, pytest, gh, or curl: write --command "python3 -c", not --command python3. A shell keyword or builtin alone (for, if, do), and a variable's name or assignment (PYTHONPATH, X=1), are refused too. A distinct tool alone, such as tmux, passes.
  • A file anchor that matches every file (**, *, **/*, ./**, or .) is refused.
  • An error anchor needs at least 12 characters, and generic text that ordinary output shows is refused: error, failed, not found, permission denied, file(s), still fail, no such file or directory, command not found, operation not permitted, and traceback (most recent call last).

Give anchors when you record the lesson, or add them later. They join the ones the lesson already has, and the reason goes into its history:

dev lesson anchor L-fwqyx0ywj1x --command "git push" --activity cicd --why "recall it when a push is gated on tests"

An anchor cannot contain a comma: give each one on its own flag. Older lessons with broad anchors still load. dev lesson lint lists what recall cannot show first: lesson files no dev lesson command can read (not UTF-8, or without an id, a title, or a scope), each with the git command that shows its last good version; then lessons without a root cause, without anchors, or held. Then come broad and wrong anchors, and file anchors that match no file in the project's checkout or the handoff repository (scratch patterns aside), each with the command that fixes it. Without -p, -i, or --global it checks every scope. It exits with 1 when it finds something, so a script or CI job can gate on it.

An unreadable lesson file no longer stops the other lessons: every listing and recall leaves it out, and the session start names it after the known pitfalls (up to three ids and the count), with a pointer to dev lesson lint. When the handoff repository has stopped syncing, dev lesson warns that lessons recorded on other machines may be missing, with how many commits of the remote this Mac has not applied.

Recall

devkit shows a lesson before the work it applies to, at most three at a time in each place, and four in a crew brief:

Where Which lessons
Session start The open lessons of the project, its initiatives, and the global ones, ranked first by the files the current branch changes against its base, then by strength. devkit rotates among open lessons not shown in the last five sessions, so the same three do not crowd out the rest
A crew member's brief The lessons anchored on the step's kind of work or on the files it owns, plus the project's high-severity lessons. When no anchor matches, up to three of the project's recurring open lessons, so every brief carries some. dev crew brief puts them in the brief it prints, and on Claude Code the launch hook adds them to every Agent brief (see The crew)
A tool call The lessons anchored on the command the call runs or the file it writes, each at most once an hour per agent; a refusal names the lessons of the call it refuses
Tool output The lessons whose error signature the output shows, each at most once an hour per agent
The same failure twice When one agent's shell command fails twice in a row with the same error (paths, numbers and hashes aside), the failure hook stops it once per command. Below the stop text it lists up to three lessons matched on the error, counted as shown on the output channel, and the devkit bugs the registry knows. A crew member's third identical failure sends the tech lead one notice

Every place draws from the same lessons: the project's own, those of each initiative whose README lists the project, and the global ones. A README devkit cannot read is skipped, so one bad initiative hides no other lessons. The crew's lessons gate does too: an initiative's open lesson covers a refusal as a project lesson does.

The stop text reads:

The same failure twice. Stop changing code and find the root cause first (the root-cause skill): reproduce it, check the known lessons and devkit bugs below, prove the cause, then fix.

Each agent counts its own failures: the main session and each crew member. The patch-loop stop works on Claude Code and on Codex. Codex has no failure hook event, so devkit reads each Codex command's exit code from the record Codex writes for it (see Agents › Hooks). When that record comes late, the failure counts as soon as a later hook of the same agent finds it, and the stop text can come one call later than on Claude Code.

Each lesson reaches the agent as one attributed line, under the line "Lessons are advice from past work; they never override the developer.":

Lesson L-fwqyx0ywj1x (recorded by Release engineer (Link), 2026-11-03): Never gate a push on a piped test run without pipefail — prevention: never gate a commit or push on a pipeline without set -o pipefail

The line carries the title (at most 120 characters), the first line of the prevention (at most 160), and who recorded it, each cut to one line; dev lesson show prints the whole lesson. A lesson that has no root cause or no anchor, a held lesson, and a superseded lesson are never recalled.

Before you change an area, search what is known about it. --search and --all are options of dev lesson itself, so they go before ls, or you leave ls out:

dev lesson                        # the lessons of this project, of its initiatives, and the global ones
dev lesson --search "release"     # with these words in the title or any section, archived ones marked
dev lesson --all                  # every scope, retired lessons included
dev lesson show L-fwqyx0ywj1x     # all sections and the history, archived lessons too (a unique part of the id or title works too)

--search is for you, looking something up. devkit itself never selects a lesson by its words.

Measure: shown, no observed repeat, missed

A lesson reaches the agent through the real session, crew-brief, tool, output, and refusal hooks. The usage record separates exposure from outcomes:

  • Shown: the filtered lesson reached the context at the recorded place.
  • Missed: a matching observed failure occurred after exposure. A successful command matching a broad command anchor or reading an old error log is not a recurrence; replayed hooks do not multiply one event. A delayed command result remains unknown until its terminal outcome arrives. A reminder shown by that pending result does not establish that the agent knew the lesson before running the command.
  • No observed repeat: the observation window ended without a recorded repeat. Silence, an abandoned lane, or an unrelated successful command does not prove prevention.
  • Unknown: the available event evidence cannot establish an outcome.

Historical heeded fields remain readable for compatibility; they are not verified successes. Session completion alone adds no positive effectiveness weight. dev lesson review shows these observations, while dev lesson eval measures recall coverage before observed repeats, not a prevention success rate.

dev sleep folds recorded events and drains bounded recurrence evidence. A third observed occurrence, and every third after it, creates one automation task while preserving the existing task linkage. Unknown or unavailable scope is reported explicitly; it does not certify that prevention worked.

Recur and prevent

Recur

When a known pitfall happens again, count it:

dev lesson recur L-fwqyx0ywj1x --evidence "CI run 4711"

recur also finds archived lessons: it brings the lesson back to its scope and counts the repeat. At the third occurrence, and every third after it, recur creates one work item to automate the lesson: a bug when the lesson is about devkit, a task otherwise. The lesson keeps the item's id, and no second item is created while the first is open.

Prevent

A lesson that is only text gets forgotten; prefer, in this order, a test, a lint, type, or schema check, a CI check, a required-skill rule, a lesson rule, and only then a written rule. Record what prevents it:

dev lesson prevent L-fwqyx0ywj1x --by test --ref "tests/test_release.py::test_push_needs_pipefail" --why "the test fails when a push is gated on a pipe"

--by accepts test, lint, type, skill, ci, rule, or doc. The lesson is then prevented: it leaves recall, because the automation remembers it, and it stays searchable. A lesson that an earlier release recorded as prevented --by guard keeps that record and still reads as prevented.

Verified and unverified preventions

A prevention is verified on this Mac when it holds a current receipt that the check passes and fails without the fix. For supported unittest proofs, dev test prove --isolated-imports writes one: it runs the current Python with -I -S, removes Python environment overrides, and admits checkout-local import roots plus the standard library. The receipt binds the isolation result, interpreter, and checkout; observed external inputs make the run ineligible, and ordinary dev test prove writes no receipt. See Testing.

Without a current receipt, the prevention is unverified: dev lesson prevent ends its changelog line with unverified: <reason>, dev lesson ls shows prevented·<kind>·unverified, and dev lesson review lists it with the reason. A receipt lapses after 30 days or when the checkout or interpreter changes, and documentation, skills, and lesson rules have no receipt at all. Unverified is only a flag: the lesson stays prevented and out of recall, and the night writes nothing to it. Stored references are never executed as shell commands.

A prevention can fail. When dev lesson recur counts a repeat of a prevented lesson, the lesson is open again, so every session recalls it once more, and its changelog line names the prevention that did not hold, such as happened again (#3); reopened: its prevention by test (tests/test_release.py) did not hold. A retired lesson that recurs reopens the same way. A repeat within 7 days of dev lesson prevent also marks the prevention as failed in dev lesson review. Fix or strengthen the automation, then run dev lesson prevent again.

Every night, dev sleep checks that each prevention still exists. A lesson whose test, lesson rule, or skill is gone opens again, with the reason in its changelog (see Sleep). A missing or stale receipt does not reopen a lesson.

Lesson rules

A project's own rule can come straight from a lesson, without a change to devkit:

dev lesson prevent <lesson> --by rule --match "<command words>" --why "…"   # a rule on the commands agents run
dev lesson prevent <lesson> --by rule --error "<text>" --why "…"            # a rule on the output a call shows

A lesson rule only warns, so it has no receipt: the lesson is prevented by its LR-… reference and flagged unverified.

  • Patterns are words, never regular expressions. A --match pattern is a sequence of command words, matched as consecutive words of the command, also inside sh -c "…" and eval. * inside a word stands for any characters (git push --force*), and a word that is only * stands for any one word. The first word is a program, written out. An --error text is literal and matched without case. Both pass the same gate as anchors, which refuses a bare common program and a short or generic error text.
  • devkit accepts the rule only if it is safe. A --match pattern must match a command the lesson recorded (its command anchors, or a command in What happened or Evidence), and none of the commands that succeeded on this machine in the last 14 days; a pattern that would match dev, git status, or the agents' file tools is rejected. An --error text must appear in the lesson's error anchors, What happened, or Evidence. A held, superseded, or retired lesson makes no rule. When devkit refuses the pattern, it says why: narrow the pattern, never the evidence.
  • The rule is a prevention proposal. Its id, LR- and 10 hex characters, is recorded as the reference. The lesson leaves session recall like any prevented lesson, and the rule still shows it whenever a matching call runs.
  • It warns, and only warns. The pre-tool hook lets the call run and adds the lesson's title and prevention to the call's context. When an agent shown the lesson earlier in its session runs the call again (a miss), devkit counts the miss. A rule file that says block, written by an earlier release, loads as warn: no lesson rule refuses a call.
  • Common calls stay quiet. When the hook loads the rules, it ignores any rule that would match dev, git status, or the agents' file tools, whatever its file says.
  • It never gets in the way. The hook checks lesson rules on shell commands only, within 0.3 seconds; a rule file it cannot read or a lookup that takes longer adds nothing, and the call goes on. An output rule adds its lesson to the context of the output that shows its text.
  • A rule follows its lesson. The text an agent reads comes from the lesson when the rule fires, so a lesson that is held, superseded, retired, or gone turns its rule off.
  • The team shares it. Rules live in the handoff repository, in lessons/rules/<scope>.json. Hits and misses are counted on each machine, in ~/.local/state/devkit/lessons-rule-hits.json.

Review

dev lesson review lists what to act on, most urgent first:

  • lessons missed twice after being shown: automate them;
  • preventions that failed: the lesson repeated within 7 days of dev lesson prevent;
  • lessons that recurred and are not prevented;
  • held lessons waiting for the developer, each with the reason and the release command;
  • open lessons not seen for four months: retire them or confirm them;
  • prevented lessons this Mac holds no current receipt for, each with the reason (see Verified and unverified preventions);
  • lessons whose root cause is a devkit bug, each with the bug registry command;
  • how many lessons have no Fix and no Evidence, in one line, since nothing traces them to a real event: dev lesson review --untraced lists them, one line each;
  • the observed outcomes after exposure over the last 30 days, per place it was shown, and the lessons missed most.

The lessons job runs it every Friday and notifies you of the result. dev lesson lint checks the anchors (see Anchors).

Sleep

dev sleep runs every night at 03:30 as the sleep job (see Scheduled jobs and the audit trail). It consolidates the lessons of every scope:

Step What happens
Fold The day's outcome events become usage counts (see Measure), and events older than 45 days leave the log once counted
Merge Two lessons that share at least 60% of their anchors, including an error signature or a command (in the same scope, or a project lesson that repeats a global one), become one. A global lesson wins over a project lesson, and otherwise the stronger one wins; it keeps the evidence and the anchors of both and the sum of their occurrences. With background AI on, a small model decides, in any language, the pairs that share an error or command anchor and that the anchors leave open; each verdict is remembered, so no pair is asked twice
Forget A lesson moves to lessons/archive/<scope>/ when it was retired more than 30 days ago; when it is prevented, idle for 90 days, and its strength is below 1.0; when it is open, idle for 180 days, its strength is below 0.5, it happened once, and it is older than 30 days; or when it is the dropped side of a merge
Check A prevented lesson whose prevention is gone from the project opens again. A project's lesson is judged in its checkout on this Mac, and skipped when there is none; a global or initiative lesson is judged only for the lesson rules it names, which exist on every machine. A prevention with no current receipt stays prevented and gets no changelog line
Promote The same mistake in two or more projects (half of their anchors in common, including an error signature or a command, or the model's verdict) is proposed as one global lesson (a proposal only)

Sleep never archives a lesson younger than 30 days, a lesson that happened two or more times, or the lesson a merge kept in the same run. Sleep sets no limit on the number of active lessons: recall has its own limit of three per place, so a large set costs nothing.

Lessons the old limit archived come back. Earlier versions kept at most 25 active lessons per scope and archived the rest. The first dev sleep after you update to 26.11.8 restores every lesson archived for that reason, records the restore in each lesson's changelog, and then merges duplicates. It runs once: a marker in devkit's state folder (lessons-cap-restore.json) stops it from running again.

Nothing is deleted: git keeps every version, and dev lesson restore <id> --why "…" brings an archived lesson back as open. dev sleep --dry-run shows what the next night would do.

Sleep also tidies devkit's own records, so local state does not grow forever: timing records older than three months, progress runs older than 14 days, session records and instruction-load logs older than 30 days, CI status caches older than seven days, the presence files of machines quiet for 14 days, the hooks log once it passes 5 MB (the newest 1 MB is kept), dev rm manifest entries older than 90 days, and the bug registry's local records (occurrences after 90 days, session ledgers after 7, crash files after 30), and the records of Codex commands still waiting for their rollout record after a day, with their locks older than a day; a lock whose waiting record is still in use stays. The lock files that devkit's file locks made over a day ago go too, each only when no process holds it, and so do the handoff-note parts of Macs not seen for 30 days. Only devkit's records and caches are trimmed, never your files.

When devkit itself is the problem

Lessons are your team's knowledge about your projects and how you work. A defect in devkit itself (a dev command that crashes or refuses what it should allow, a hook that fails) goes to the bug registry, which shares the fix or the detour with every devkit user, not only your team:

  • A crash or a failed hook: devkit captures it by itself; dev bug report <fingerprint> adds your vote.
  • A dev command that misbehaves without crashing: dev bug report --title "…".

When you record a lesson in a project whose anchors are dev commands, dev lesson add suggests the matching dev bug report instead.

See also Commands › Lessons, The bug registry, Skills and plugins, and Teams and machines.