feat: run snippet retention from the opencode plugin (#37)
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.
This commit is contained in:
@@ -339,6 +339,7 @@ func newSnippetsExpireCmd(kdb *db.KnoxDB) *cobra.Command {
|
||||
var days int
|
||||
var dryRun bool
|
||||
var reason string
|
||||
var every time.Duration
|
||||
cmd := &cobra.Command{
|
||||
Use: "expire",
|
||||
Short: "Reject uncurated candidates older than a retention window",
|
||||
@@ -361,16 +362,22 @@ every rejected technique at once).`,
|
||||
n, cutoff.Format(time.RFC3339))
|
||||
return nil
|
||||
}
|
||||
n, err := kdb.ExpireSnippets(cutoff, reason)
|
||||
n, ran, err := kdb.ExpireSnippetsDue(cutoff, every, reason, time.Now().UTC())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !ran {
|
||||
fmt.Printf("Not due: next sweep after %s.\n",
|
||||
kdb.NextSnippetExpiry(every).Format(time.RFC3339))
|
||||
return nil
|
||||
}
|
||||
fmt.Printf("Expired %d candidate(s) discovered before %s.\n",
|
||||
n, cutoff.Format(time.RFC3339))
|
||||
return nil
|
||||
},
|
||||
}
|
||||
cmd.Flags().IntVar(&days, "days", 0, "Retention window in days (candidates older than this are rejected)")
|
||||
cmd.Flags().DurationVar(&every, "every", 0, "Only run when the last sweep is at least this old (e.g. 24h); 0 always runs")
|
||||
cmd.Flags().BoolVar(&dryRun, "dry-run", false, "Report the count without rejecting")
|
||||
cmd.Flags().StringVar(&reason, "reason", "", "Rejection reason")
|
||||
return cmd
|
||||
|
||||
Reference in New Issue
Block a user