← All writing

Developer tooling 5 min read

A laptop that maintains itself

A tiny launchd job keeps my developer tools upgraded and their caches fresh, and tells me out loud how it went.

My developer tools go stale quietly. An AI coding tool caches its plugins, a CLI falls a few versions behind, and the first sign is a bug someone fixed weeks ago. I wanted those chores to happen on their own, on a schedule, and to tell me when something went wrong.

The result is routine-maintenance, a few shell scripts and one macOS launchd job.

The routine-maintenance desktop widget listing four tasks (opencode-upgrade, opencode-desktop-upgrade, brew-upgrade-glab and opencode-cache-clear), each with a green tick, when it last ran, when it runs next and a play button

One folder of small tasks

Each chore is one small script in a tasks.d/ folder. The name follows an old Unix convention (/etc/cron.d/, /etc/sudoers.d/): a folder of independent drop-in pieces that together make one thing. Today there are four:

  • clear OpenCode’s plugin cache every 14 days;
  • upgrade glab through Homebrew every 14 days;
  • upgrade the OpenCode CLI, and the OpenCode desktop app, every Saturday.

A task declares its own schedule in a comment at the top, such as # interval_days: 14, and optionally # run_on: Sat. Changing a schedule means editing one line in one file. Adding a task means dropping in a new script.

Check in daily, run when due

launchd can run a job at a set time, but it has no “every two weeks, and catch up if the laptop was asleep”. So the job fires once a day at 9am and only checks in. The runner looks at each task, compares the last successful run with the task’s interval, and runs only what’s due. If the laptop was closed on a Saturday, the weekly task runs at the next check-in instead of waiting another week.

The weekly tasks use an interval of six days, not seven, with the Saturday rule doing the real work. A seven-day interval could miss by a few seconds, because the job never starts at exactly the same moment.

Built to fail safely

  • One retry. A task that fails is retried once after 30 seconds, so every task must be safe to run twice.
  • One failure doesn’t stop the rest. A task that still fails is tried again at the next daily check-in.
  • Before and after, every time. Each task logs a snapshot before and after its work. Version checks log the two versions; list checks, such as a cache folder, log a diff, or “(no changes)”.
  • It won’t pull the rug out. Homebrew swaps an app on disk even while it’s running, so the desktop-app upgrade skips itself while OpenCode is open and tries again next Saturday.

It talks to me

A chime marks the start of a check-in, and a different chime marks each failure. Successes stay silent, with only a banner. At the end, macOS reads the summary out loud, for example: “Check-in finished: 3 ran, 3 ok, 0 failed, 5 skipped.” The volume is set to a fixed level first, so I hear it whatever it was before.

Two macOS surprises

launchd has almost no PATH. Jobs get /usr/bin:/bin:/usr/sbin:/sbin and no shell profile, so anything installed by Homebrew silently isn’t found. One shared helper file sets the PATH once, and every task loads it.

Background jobs can’t touch your Desktop. macOS privacy protection quietly blocks launchd agents from reading ~/Desktop, ~/Documents and ~/Downloads. The same job that worked from /tmp failed from the Desktop with “can’t open input file”, and the file permissions were fine. The real folder lives in ~/.config/routine-maintenance, and a symlink on the Desktop keeps it easy to find.

Seeing it without a terminal

./next-run.sh prints when each task last ran, whether it passed and when it’s next due. The desktop widget above reads the same data, with a ▶ to run any task now. The widget is part of my desktop widgets.