feat: run snippet retention from the opencode plugin (#37) (#38)
build / test (push) Successful in 5m38s
build / image (push) Successful in 42s

Co-authored-by: David Gwilliam <dhgwilliam@gmail.com>
Co-committed-by: David Gwilliam <dhgwilliam@gmail.com>
This commit was merged in pull request #38.
This commit is contained in:
2026-11-05 05:28:28 +00:00
committed by david
parent f410d3b46c
commit bdde79e268
5 changed files with 209 additions and 1 deletions
+8 -1
View File
@@ -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