feat: run snippet retention on a rolling schedule from the opencode plugin #37

Closed
opened 2026-11-05 05:27:35 +00:00 by david · 0 comments
Owner

knox snippets expire exists (#36) but nothing calls it, so the candidate queue refills until someone remembers to run it by hand. The alternative on the table was a systemd timer.

A timer is a second thing to install, fires on an idle machine, and duplicates a schedule knox already tracks. Retention is curation, and curation happens while the agent is in use — so drive it from the plugin.

Design

  1. knox snippets expire --every 24h runs only when settings['snippets_expire_last_run'] is at least that old, and records the run (even when nothing expired, since the window was still checked).
  2. A new plugins/maintenance plugin calls it from the prompt hook, fire-and-forget, with an in-process 24h guard.

The clock lives in the index rather than the plugin on purpose: this plugin is one caller among several. A cron job or a human running the same command shares one schedule, and restarting OpenCode (which reloads the module) cannot cause a burst of sweeps. The in-process guard is only an optimisation, to avoid spawning a CLI that would immediately decide it is not due.

Expected

  • Retention happens at most once a day, only while the machine is in use.
  • Repeated prompts, plugin reloads and multiple callers do not compound.
  • encoded snippets are never touched; expiry stays reversible with reopen.
`knox snippets expire` exists (#36) but nothing calls it, so the candidate queue refills until someone remembers to run it by hand. The alternative on the table was a systemd timer. A timer is a second thing to install, fires on an idle machine, and duplicates a schedule knox already tracks. Retention is curation, and curation happens while the agent is in use — so drive it from the plugin. ## Design 1. `knox snippets expire --every 24h` runs only when `settings['snippets_expire_last_run']` is at least that old, and records the run (even when nothing expired, since the window was still checked). 2. A new `plugins/maintenance` plugin calls it from the `prompt` hook, fire-and-forget, with an in-process 24h guard. The clock lives in the index rather than the plugin on purpose: this plugin is one caller among several. A cron job or a human running the same command shares one schedule, and restarting OpenCode (which reloads the module) cannot cause a burst of sweeps. The in-process guard is only an optimisation, to avoid spawning a CLI that would immediately decide it is not due. ## Expected - Retention happens at most once a day, only while the machine is in use. - Repeated prompts, plugin reloads and multiple callers do not compound. - `encoded` snippets are never touched; expiry stays reversible with `reopen`.
david closed this issue 2026-11-05 05:28:46 +00:00
Sign in to join this conversation.
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: david/knox#37