Globally delete/compress recurring tasks

What I’m trying to do

I am trying to delete all completed recurring tasks in the whole repository at once, either with a manually started action, or automatically on a schedule, or even intelligently every time a task is flagged completed (which would be a feature request on the Tasks plugin itself and would have the huge benefit of avoiding having to scan the whole repo).

So… when we have the usual structure as such:

  • #task some task :repeat: every 4 weeks :date: 2024-09-01
  • #task some task :repeat: every 4 weeks :date: 2024-08-04 :white_check_mark: 2024-08-04
  • #task some task :repeat: every 4 weeks :date: 2024-07-07 :white_check_mark: 2024-07-07
  • #task some task :repeat: every 4 weeks :date: 2024-06-09 :white_check_mark: 2024-06-09
  • #task othertask :repeat: every 4 weeks :date: 2024-09-01

I want all the completed recurring tasks below the non-completed one, which share the same title, to be gone. Bonus features come to mind (i.e., keep the last X completed around; keep the very last one around (to see when the series started), etc.) but those are secondary to me, ending up with this:

  • #task some task :repeat: every 4 weeks :date: 2024-09-01
  • #task othertask :repeat: every 4 weeks :date: 2024-09-01

Or (optionally, maybe with a feature toggle):

  • #task some task :repeat: every 4 weeks :date: 2024-09-01
  • #task some task :repeat: every 4 weeks :date: 2024-08-04 :white_check_mark: 2024-08-04
  • … 1 completed recurring task(s) auto-deleted …
  • #task some task :repeat: every 4 weeks :date: 2024-06-09 :white_check_mark: 2024-06-09
  • #task othertask :repeat: every 4 weeks :date: 2024-09-01

i.e., keep the very first and last completed instance and place a little comment - this would make it very convenient to see when the series started and when it was most recently completed if one is interested in that.

Things I have tried

I looked for community plugins. The following seem related:

  • Tasks - this would be the obvious place, right when it creates the next recurring task on completion on the previous one. Checked the settings and docs and it doesn’t have the feature (yet? :slight_smile:)
  • Completed Tasks Display - great plugin, I use it often, but it only hides the tasks in the current note, doesn’t delete it from notes.
  • Archiver - I don’t want to archive, but delete. There is a post mentioning a hack where you use Archiver to move the tasks to a archive page and regularly delete that, but meh.
  • Completed Area - I don’t want to move them to a different area, but delete them.
  • Packrat - it’s the closest, but only works on the current note. I wish to do it for all notes.
  • Janitor, File Cleaner Redux etc. - these look like a great place to have such a feature; but alas, they don’t.