Experience
Projects
My Stack
Case studies
Contact me
Open my CV

·5 min read

DailyBrief's board file only grew, so I added a daily compactor that moves, never deletes

Every check, every digest and every board view in DailyBrief reads one file, kanban.json, and nothing in the app ever shrank it. Each AI check appended an aiNote to a task. Finished tasks stayed on the board for good. Deleted tasks went to an archive array inside the same file. The cost was not a bug anyone could point at, it was a slope: every run paid a little more than the one before.

Project
DailyBrief
Date
Oct 2026
Stack
PowerShell 5.1, Electron, JSON
Commit
6197543

Why growth was the problem

DailyBrief is an Electron app that shells out to PowerShell scripts, and several of those scripts hand the board to a model. The model's input is built from the board, so a board that grows is a prompt that grows. I had already spent effort trimming the digest and running leaner Claude calls. Trimming the digest does not help if the thing the digest is built from keeps getting bigger underneath it.

So I treated the file as the source of the problem rather than the readers. The header comment of the script says it plainly: kanban.json only ever grows, "every check appends an aiNote, and finished work stays on the board forever", and everything that reads the board pays for that on every run.

The rule: move, do not delete

I did not want a cleanup job that could lose a task. The design rule I wrote at the top of the script is that nothing is deleted. Old notes and old finished tasks are moved, whole, with their comments, and ids never change. They land in kanban-archive.json, next to the board, in three lists: tasks for done tasks, archive for deleted ones, notes for old aiNotes.

The script takes three parameters:

powershell
param(
    [switch]$DryRun,
    [int]$KeepNotes = 5,
    [int]$Days = 30
)

-DryRun prints what would move and writes nothing. KeepNotes is how many aiNotes stay on each task, and Days is the age after which a done or deleted task moves out.

Three small decisions that matter

A pending comment keeps a task on the board. A comment whose state is new is an order the AI has not acted on yet. If the task it sits on were archived, that order would silently never run. So a done task with a pending comment stays, however old it is:

powershell
function Has-PendingComment($t) {
    foreach ($c in @(AsArr $t.comments)) { if ([string]$c.state -eq 'new') { return $true } }
    return $false
}

An undatable task counts as recent. The age check reads updatedAt or createdAt and tries to parse it. If neither parses, Get-Stamp returns $null, and the move condition requires a real date. The comment above that function gives the reasoning: moving something I cannot date would be a guess, and keeping it costs only bytes.

Order of the two writes. The script writes the archive file first and the board second. If the process dies between the two writes, an item exists in both files, which is harmless: the next run dedupes by id, because $putInto removes any existing entry with the same id before adding the newer copy. The opposite order could lose an item in a crash. Both writes happen inside Invoke-WithBoardLock, the same lock the parallel checks use, so the compactor cannot race a check that is saving its result.

Idempotent by construction

I wanted a second run right after the first to move nothing. Tasks are filtered by cutoff date, so the ones already moved are gone from the board. Old notes are keyed by taskId|at|text, and a note whose key is already in the archive is not added again. Notes are appended in order, so the newest are at the end and Select-Object -Last $KeepNotes keeps exactly the recent ones. When there is nothing to do the script prints compact: nothing to move and writes no file at all.

PowerShell 5.1 details

The script is ASCII-only on purpose, because Windows PowerShell 5.1 reads scripts without a BOM in the system code page. And there is a helper called AsArr, because 5.1 round-trips an empty array through JSON as $null or as an empty object depending on the path. Every array read from the board goes through it.

I also pass $false to the UTF-8 encoding constructor so no BOM is written, matching what every other board writer in the app does, and strip a leading 0xFEFF when reading.

How it is triggered

The Electron side has maybeCompact() in main.js. It runs at launch, before the pipeline, and skips if lastCompact already holds today's date. It resolves when the script exits or after 60 seconds, whichever is first, because a stuck compaction must not hold the morning brief hostage. The date is stored only when the script exited with code 0, so a failure retries on the next launch instead of waiting a day. A missing script, as on an older install, is ignored and the board simply stays the size it was. A long-running instance compacts on the same daily beat, but only while nothing is running.

What I took from it

The earlier performance work in this project was about reading less. This was about writing less in the first place, and it was the cheaper fix: one script, no model calls, and every later run benefits without knowing about it. Appending is the easy default for anything an AI loop writes, and an append-only file needs a retirement policy at the time you add the append, not after the slope shows up. The part I would repeat is the rule that the policy moves data and never deletes it. It made the script safe to ship without a long argument about thresholds, because a wrong threshold costs a lookup in another file, not a lost task.

#powershell#electron#json#performance#data-retention

Keep reading

Have a project in mind?