# knox.maintenance — OpenCode plugin Rolling retention for the knowledge index, driven by use instead of a timer. ## Why Snippet candidates pile up: every successful `write`/`edit`/`shell` call is extracted as a candidate, and only a fraction ever gets curated. Without retention the queue grows until it is unusable — at one point 17,262 candidates against 25 encoded. A systemd timer would work, but it is a second thing to install, it fires on an idle machine, and it duplicates the scheduling knox already needs to know about. Curating while the machine is in use is both simpler and more useful. ## How it works `setup` registers a `prompt` session hook. On the first prompt of the session (and at most once every 24 hours in-process) the plugin runs: ```sh knox snippets expire --days 7 --every 24h ``` Fire-and-forget: output is discarded and the prompt is never delayed. ## Where the clock lives In the index, not in the plugin: `knox snippets expire --every` records its last run in `settings['snippets_expire_last_run']` and no-ops while the interval has not elapsed. So: - restarting OpenCode reloads this module but cannot cause a burst of sweeps; - a cron job or a human running the same command shares the same schedule; - the in-process `lastAttempt` guard is only an optimisation, to avoid spawning a CLI that would immediately decide it is not due. ## Configuration | Variable | Default | Meaning | |---|---|---| | `KNOX_SNIPPET_RETENTION_DAYS` | `7` | How long an uncurated candidate stays reviewable | | `KNOX_BIN` | `~/assistant/knox/knox` | Binary to invoke | ## What it never does - It never touches `encoded` snippets; only uncurated `candidate` rows expire. - Nothing is deleted. Expiry is a status change with a reason, reversible with `knox snippets reopen` (or `--scope techniques` for every rejected technique).