feat: run snippet retention from the opencode plugin (#37) #38

Merged
david merged 1 commits from feat/rolling-retention into main 2026-11-05 05:28:43 +00:00
Owner

Closes #37.

knox snippets expire landed in #36 but nothing called it. Rather than a systemd timer — a second thing to install, firing on an idle machine — retention runs from the opencode plugin while the machine is in use.

The clock lives in the index

expire --every 24h consults and updates settings['snippets_expire_last_run']. That makes it safe for many callers:

  • a restarted OpenCode reloads the plugin but cannot cause a burst of sweeps
  • a cron job or a human running the same command shares the schedule
  • the run is recorded even when nothing expired, because the window was still checked

The plugin

plugins/maintenance registers a prompt hook and runs knox snippets expire --days 7 --every 24h, fire-and-forget. The in-process 24h guard only avoids spawning a CLI that would immediately decide it is not due — the authoritative check is in knox.

Registered in opencode.json (user config, not in this repo) between claims and recall.

Tests

TestExpireSnippetsDue: first run sweeps and records; a second call inside the interval is a no-op even with work pending; past the interval it sweeps again. NextSnippetExpiry reports the next due time.

go build ./... && go vet ./... && go test ./... pass.

Not covered

Retention only runs when OpenCode is used. If the index should age out on an idle box, the watcher is the right owner — say so and I'll move it there instead.

Closes #37. `knox snippets expire` landed in #36 but nothing called it. Rather than a systemd timer — a second thing to install, firing on an idle machine — retention runs from the opencode plugin while the machine is in use. ### The clock lives in the index `expire --every 24h` consults and updates `settings['snippets_expire_last_run']`. That makes it safe for many callers: - a restarted OpenCode reloads the plugin but cannot cause a burst of sweeps - a cron job or a human running the same command shares the schedule - the run is recorded even when nothing expired, because the window was still checked ### The plugin `plugins/maintenance` registers a `prompt` hook and runs `knox snippets expire --days 7 --every 24h`, fire-and-forget. The in-process 24h guard only avoids spawning a CLI that would immediately decide it is not due — the authoritative check is in knox. Registered in `opencode.json` (user config, not in this repo) between `claims` and `recall`. ### Tests `TestExpireSnippetsDue`: first run sweeps and records; a second call inside the interval is a no-op *even with work pending*; past the interval it sweeps again. `NextSnippetExpiry` reports the next due time. `go build ./... && go vet ./... && go test ./...` pass. ### Not covered Retention only runs when OpenCode is used. If the index should age out on an idle box, the watcher is the right owner — say so and I'll move it there instead.
david added 1 commit 2026-11-05 05:28:16 +00:00
feat: run snippet retention from the opencode plugin (#37)
build / test (push) Has been cancelled
build / image (push) Has been cancelled
17f75d49b6
expire existed but nothing called it, so the queue refilled until someone
ran it by hand.

expire --every N now runs only when the last sweep is at least that old
and records the run in settings['snippets_expire_last_run'] — including
runs that found nothing, since the window was still checked. The clock
lives in the index, not the caller, so an agent hook, a cron job and a
human share one schedule and a reloaded plugin cannot cause a burst.

plugins/maintenance runs it from the prompt hook (fire-and-forget) with
an in-process guard that only avoids spawning a CLI that would decide it
is not due.
david merged commit bdde79e268 into main 2026-11-05 05:28:43 +00:00
Sign in to join this conversation.
No Reviewers
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: david/knox#38