promptdojo_

The ratchet — every mistake becomes a rule — step 7 of 9

Write add_to_ratchet(log, failure) that appends a new entry to a ratchet log and returns a NEW list (don't mutate the input).

Rules:

  • log is a list of dicts, each with keys: date (YYYY-MM-DD), failure, rule, remove_when.
  • failure is a dict with the same four keys.
  • Return a new list with the new entry inserted, sorted by date ascending.
  • Do NOT mutate the original log.

Two failures appended in sequence. Expected output:

After first add:
2026-02-20: use Tailwind, never inline styles
2026-03-15: never skip failing tests
2026-04-02: no force push to main
After second add:
2026-02-20: use Tailwind, never inline styles
2026-03-15: never skip failing tests
2026-04-02: no force push to main
2026-05-01: use structlog, not stdlib logging

full-screen editor opens — close anytime to keep reading.