pr-cleanup)
[!NOTE]
This skill targets the personal repository layout (
~/githuband~/github/kevmoo/*) and invokes the unifiedkscriptsAOT CLI.
Quick Start & Prerequisites
Ensure kscripts is installed and up to date on PATH. If kscripts is
missing, install it from the canonical Git remote:
dart install 'kevmoo_scripts@{git: https://github.com/kevmoo/scripts.dart}'
Thereafter upkeep update dart_install keeps it current -- it re-reads the
source descriptor from the installed bundle's own pubspec.lock and reinstalls
from the same remote.
[!WARNING]
Do not run
dart install ~/github/kevmoo/scripts.dart. Installing from a local path builds whatever branch that checkout is on, and it replaces theapp-bundles/kevmoo_scripts/git/<sha>/bundle with alocal/one -- which permanently repointsupkeep update dart_installat that checkout instead of the remote. Only use a path install to test uncommitted work, and reinstall from Git afterwards.
1. Read-Only Pre-Flight Sweep (Always Start Read-Only)
Never pass --apply on the initial scan. Execute the 3 read-only collectors in
parallel to build a unified view of ~/github:
- Merged/Closed PRs, Stale Worktrees & Dangling Remote Branches:
kscripts gh-clean -l 50 --markdown - Open Active GitHub PRs & Reviewer/CI Next Steps:
(Omitkscripts gh-view -d 14 --markdown-d 14if the user asks for all open PRs regardless of recency, or adjust-d <days>to match the user's window). - Dart SDK Gerrit Worktrees & CL Status (when
~/github/dart-sdkexists):
(Automatically resolveskscripts gerrit-view -p ~/github/dart-sdk~/github/dart-sdk/core/main/sdkon bare-clone layouts, matches worktrees and local branches viaChange-Id:footers, commit SHAs, andbranch.*.gerritissue, reconstructsin_reply_tocomment chains so only leaf comments are evaluated for resolution, and outputs reviewers, CQ dry run status, and next steps). - Open Assigned GitHub Issues (optional — run when asked for broader
backlog/next-steps triage):
kscripts gh-issues --linked-prs --markdown
2. Active Worktree & Session Ownership Cross-Reference
Before proposing to delete any worktree, local branch, or unpushed commit:
- Inspect Dirty / Unpushed Worktrees:
- For any worktree flagged by
kscripts gh-cleanas having uncommitted changes or unpushed commits, run:git -C <worktree_path> status -s git -C <worktree_path> log -n 2 --oneline - Squash-Merge Ancestry Check: If a merged PR branch still reports
unpushed commits past PR HEAD, fetch
origin/mainfirst and check whether the branch is an ancestor oforigin/main:
If the count isgit -C <repo_path> fetch origin main --quiet git -C <repo_path> rev-list --count origin/main..<branch>0, the branch was reset onto the squash-merge commit and is safe to delete viagit -C <repo_path> branch -D <branch>.
- For any worktree flagged by
- Cross-Reference Active Sessions & Local Tasks:
- Check whether any worktree is actively in use by another running terminal or agent session before proposing deletion.
- If a worktree belongs to an active session or an open PR/CL, classify
it in Bucket A (
🚫 DO NOT TOUCH). - If a worktree belongs to a waiting/idle session whose PR/CL has already merged, include pruning its VCS state in Bucket B and reconcile any linked local tasks or waiting sessions according to your workspace rules.
3. Three-Bucket Classification & Report
Present the findings in a structured Markdown report (or artifact for large sweeps) divided into 3 buckets:
- Bucket A —
🚫 Active / Hands-Off(Open PRs, Active Gerrit CLs, In-Flight Worktrees):- List open PRs from
kscripts gh-viewand active Gerrit CLs fromkscripts gerrit-viewwith their CI status, reviewer state (⏳ Awaitingvs🔔 Ping Reviewervs🔄 Re-request Reviewvs❌ Action Needed), and local worktree mapping. - When
kscripts gh-viewflags🔄 **Re-request Review** (@reviewer), that human reviewer previously submitted a review (COMMENTED,CHANGES_REQUESTED, orDISMISSED) and was dropped from GitHub'sreviewRequests. Even if an@reviewer PTALcomment was posted, the PR is not in their GitHub Review Queue (review-requested:@me) until re-requested viagh pr edit <PR> -R <owner/repo> --add-reviewer <login>. - Three-State
CHANGES_REQUESTEDDisambiguation (Zero ExtraghCalls):🔴 **Changes Requested** (@reviewer): Author has not yet pushed a fix or replied since the review (⚠️ Action Needed— author's ball).🔄 **Re-request Review** (@reviewer): Author pushed a fix or replied after the review and resolved threads, but@reviewerwas dropped fromreviewRequests(⚠️ Action Needed— run--add-reviewer <login>).🟡 **Re-review Requested** (@reviewer):@revieweris already inreviewRequests(🟡 In Review Queue— reviewer's ball). Even though GitHub's rawreviewDecisionremainsCHANGES_REQUESTED, do not re-run--add-revieweror runpr-triage. Only if another maintainer has alreadyAPPROVED(🟢 Approved (@approver)) and the priorCHANGES_REQUESTEDreview is a stale veto on an older commit, surface the option (gated viaask_question) to dismiss the stale review.
- List open PRs from
- Bucket B —
✅ Safe to Prune Immediately(Merged PRs/CLs & Clean Worktrees):- Clean worktrees (
git worktree remove), merged local feature branches (git branch -D), dangling remote head branches on writable repos, and trunk fast-forwards (--ff-only). - List any linked tasks or waiting sessions whose PRs have landed so they can be reconciled after VCS cleanup.
- Clean worktrees (
- Bucket C —
⚠️ Requires Explicit Confirmation(Closed-Unmerged PRs, Dirty Worktrees, Unpushed Experiments):- Detail the exact modified/untracked files (
git status -s) or unmerged commits so the user can decide whether to discard or keep each item.
- Detail the exact modified/untracked files (
4. Approval Gate & Execution
Gate execution via ask_question with explicit bucket choices:
(Recommended) Execute Bucket B only (prune merged PRs, clean worktrees & remote branches)Execute Bucket B + Bucket C (also force-remove dirty/closed-unmerged worktrees)Stop here (keep read-only report only)
Once approved:
- Execute Bucket B Pruning:
- If any merged-PR worktree was held back in Bucket A (because an
active session is still using it), run
kscripts gh-clean -R <owner/repo> --applyfor each approved Bucket B repository individually so the Bucket A worktree is not touched. - Only run unscoped
kscripts gh-clean -l 50 --applywhen zero merged-PR worktrees were reclassified into Bucket A.
- If any merged-PR worktree was held back in Bucket A (because an
active session is still using it), run
- Execute Bucket C Pruning (only if Bucket C was explicitly approved):
- Run
git -C <parent_repo> worktree remove --force <worktree_path>andgit -C <parent_repo> branch -D <branch>.
- Run
- Reconcile Linked Tasks & Waiting Sessions:
- After pruning landed PRs/CLs, verify and close any linked local tasks or notify waiting sessions as configured in your local workspace rules.