Repository navigation
Add worktree-cleanup - #22
Conversation
geodro
left a comment
There was a problem hiding this comment.
The plugin reads well and the guards are thought through, two things stand in the way before it can be listed.
The schedule writes a LaunchAgent into ~/Library/LaunchAgents, outside the plugin's folders, which term 9 rules out. Lerd now has this built in (lerd-env/lerd#2554, merged, shipping in the next release): declare schedules: in plugin.yaml with a name, every and the script to run, and lerd runs it from its dashboard service once the user allows it, asked at install and again whenever the schedules change. A run gets LERD_SURFACE=schedule. To keep SCHEDULE_EVERY as a user setting, declare the shortest interval you offer, say 15m, and have the script skip runs until its own interval has passed. That lets bin/schedule, the launchctl calls and the plist go, and with a portable stat in place of stat -f nothing left is macOS only, so platforms can go too. It needs lerd: set to the release that ships schedules, since an older lerd ignores the key and would never run it.
The leftover folder cleanup deletes .env files under .claude/worktrees, which belong to another tool and can hold the only copy of a worktree's config. Please drop LEFTOVER_FOLDERS, or leave a folder alone when it holds a .env.
Smaller ones. The notification goes out after every applied run, Clean up now and terminal runs included, while the README says only after a scheduled run; checking for LERD_SURFACE=schedule fixes that. plugin.yaml lists no screenshots, so docs/page.png won't show on the plugin's card. The sites API already gives each worktree db_isolated, which saves reading both .env files.
|
Thanks! All addressed in 2baa74c: the schedule now uses schedules: (15m, skipping until SCHEDULE_EVERY passes) with lerd: ">=1.39", bin/schedule, launchctl and platforms are gone (portable find -mmin/ps -eo), LEFTOVER_FOLDERS is removed, |
geodro
left a comment
There was a problem hiding this comment.
Read the whole change from the last commit and ran it in a VM against lerd built from main: the dry run kept the right worktrees, the scheduled run removed only the landed one once allowed, hostile settings and site names went nowhere, and removing it left lerd's config and sites as they were. Three small things for a later update, none blocking. A lerd: ">=1.39" bound also lets the 1.39 betas 1 to 3 load it, which have no schedules yet, so it only runs by hand there. The page points at System > Plugins, but Plugins has its own rail item now. And a settings value with a line break in it gets half applied before the rest is refused. Thanks for turning this around so quickly.
Plugin
What it does
Every worktree of a proxy site runs its own dev server, and a Laravel worktree can have its own database, so finished worktrees pile up and keep fseventsd busy. This plugin removes the finished ones: PR merged, PR closed, or a detached / no-PR HEAD that has been on a base branch for a day. It skips worktrees a process is sitting in or that lerd saw recent traffic on. Uncommitted changes are saved as a patch first, or the worktree is kept, depending on your settings. Every rule is a toggle on its dashboard page.
What it adds to Lerd
worktree-cleanup:run,:config,:schedule.worktree-cleanup_runwith a skill (dry run first).api, GET/POST,loopback_only) used by the page.NOTIFY).What it reads, changes and sends
/api/sites; each site's git repo (git fetch origin, status, merge-base);DB_DATABASEfrom the site's and worktree's.env, only to tell whether the worktree has its own database; process working folders (ps,lsof) to skip worktrees in use.lerd worktree removeand drops a worktree's own database throughlerd db:share; deletes leftover dependency-only folders in<site>/.claude/worktrees/; writes its settings, log and patches to its data folder. When the user runsschedule on(off by default), it writes~/Library/LaunchAgents/sh.lerd.plugin.worktree-cleanup.plist;schedule offremoves it.gh, PR lists for each site'soriginrepository and a commit-SHA PR search for detached HEADs, to GitHub. Only when the user runs it (or turns the schedule on).Requirements
requires: [curl, jq, git, lsof], plusghlogged in, checked at run time because the dashboard's PATH has no Homebrew.lerd: ">=1.38",platforms: [macos](the schedule uses launchd).Images
Notes for the reviewer
schedule onwrites a user LaunchAgent outside the plugin's folders. It is off until the user turns it on. I'd rather lerd offered a periodic plugin hook (e.g.hooks: every: 1h); happy to drop the schedule if that is preferred.gh, the plugin's core function. Nothing is sent until the user runs it.Checklist
plugin.yamldeclareslerdas a lower bound, andplatformsif it runs on only one..envonly when the README says why.plugin.yamland only tell the user something they need to know or act on.