--- name: compact-memory description: Use when flywheel.py check reports the memory index over budget, after about five archived changes, or when the user asks to clean up memory. Runs the compact, verify, and retire pass with fixed selection rules, no rewriting of entries, and a diff for human review. status: active --- # Compact, verify, and retire The pass keeps the stores small and current. It never rewrites the text of an entry: it marks entries stale or superseded, merges sources, and regenerates the index. The same input gives the same result. ## Trigger - `flywheel.py check` reports the index over budget. - About every five archived changes. - The user asks to clean up memory or retire a skill. ## Workflow 1. **Analyse with the curator agent.** Delegate to the `flywheel-curator` agent. It runs `status`, `verify`, and `dupes` and returns a proposal; it does not change files. 2. **Verify (stale detection).** - Entries whose backticked paths no longer exist: `python3 .flywheel/bin/flywheel.py verify --apply` marks them `stale` and refreshes `last_verified` on entries whose paths all exist. - Entries with no checkable paths and an old `last_verified`: list them for the user to confirm or retire. 3. **Duplicates.** For each pair from `dupes` that the curator confirms is the same lesson, keep one **representative** chosen by these rules, in order: more `occurrences`; then the more recent `last_verified`; then the longer body; then the name that sorts first. Then: - add each source of the other entry to the representative (`add-source`); - `set-status superseded --superseded-by `. 4. **Contradictions.** For entries with a `Contradicts:` line, show both to the user. On their decision, the newer correction supersedes the older entry (`set-status ... superseded`). Never resolve a contradiction without the user. 5. **Retire skills.** A skill whose latest eval results fail the gate, or that the user marks obsolete: set `status: deprecated` and add `deprecated_reason:` (and `replaced_by:` if any) in its frontmatter, after the user approves. Do not delete it. 6. **Regenerate and check:** `python3 .flywheel/bin/flywheel.py index` and `check`. 7. **Review.** Show `git diff --stat` and the list of superseded, stale, and deprecated items. The user reviews the diff before it is committed. If the index is still over budget after the pass, report it and ask the user whether to retire more entries or raise `index_budget` in `.flywheel/config.json`. Do not shorten entry text to fit. ## Anti-patterns - Rewriting or summarizing entry text with a model (it breaks auditability and determinism). - Deleting entries or skill folders instead of marking them. - Superseding an entry because it is old; age alone only triggers a review.