From eb606e9b9148691efb5a6cdc14fee0e4f1c66fd0 Mon Sep 17 00:00:00 2001 From: archae0pteryx Date: Thu, 3 Dec 2026 11:23:35 -0800 Subject: [PATCH] feat: add clean-tree checkout synchronization skill --- .claude-plugin/marketplace.json | 13 +++ .cursor-plugin/marketplace.json | 9 ++ .github/plugin/marketplace.json | 13 +++ README.md | 1 + skills/.cursor-plugin/plugin.json | 1 + skills/clean-tree/.cursor-plugin/plugin.json | 4 + skills/clean-tree/SKILL.md | 97 ++++++++++++++++++++ skills/clean-tree/agents/openai.yaml | 5 + 8 files changed, 143 insertions(+) create mode 100644 skills/clean-tree/.cursor-plugin/plugin.json create mode 100644 skills/clean-tree/SKILL.md create mode 100644 skills/clean-tree/agents/openai.yaml diff --git a/.claude-plugin/marketplace.json b/.claude-plugin/marketplace.json index 113c98f..5aaa6b6 100644 --- a/.claude-plugin/marketplace.json +++ b/.claude-plugin/marketplace.json @@ -31,6 +31,18 @@ "homepage": "https://github.com/killallgit/killall-skills", "version": "6.2.0" }, + { + "name": "clean-tree", + "source": "./", + "description": "Bring the current checkout onto origin's latest default branch while preserving local work, then concisely summarize any leftovers. Use only when the user invokes /clean-tree; account for uncommitted changes, unpublished commits, and stashes without discarding them.", + "strict": false, + "skills": [ + "./skills/clean-tree" + ], + "category": "workflow", + "homepage": "https://github.com/killallgit/killall-skills", + "version": "6.2.0" + }, { "name": "end-session", "source": "./", @@ -195,6 +207,7 @@ "skills": [ "./skills/architectural-review", "./skills/catch-up", + "./skills/clean-tree", "./skills/end-session", "./skills/git-janitor", "./skills/house-rules", diff --git a/.cursor-plugin/marketplace.json b/.cursor-plugin/marketplace.json index 51ef75e..3ea51f2 100644 --- a/.cursor-plugin/marketplace.json +++ b/.cursor-plugin/marketplace.json @@ -24,6 +24,14 @@ "homepage": "https://github.com/killallgit/killall-skills", "version": "6.2.0" }, + { + "name": "clean-tree", + "source": "./skills/clean-tree", + "description": "Bring the current checkout onto origin's latest default branch while preserving local work, then concisely summarize any leftovers. Use only when the user invokes /clean-tree; account for uncommitted changes, unpublished commits, and stashes without discarding them.", + "category": "workflow", + "homepage": "https://github.com/killallgit/killall-skills", + "version": "6.2.0" + }, { "name": "end-session", "source": "./skills/end-session", @@ -138,6 +146,7 @@ "skills": [ "./architectural-review", "./catch-up", + "./clean-tree", "./end-session", "./git-janitor", "./house-rules", diff --git a/.github/plugin/marketplace.json b/.github/plugin/marketplace.json index d99d1c9..723f402 100644 --- a/.github/plugin/marketplace.json +++ b/.github/plugin/marketplace.json @@ -32,6 +32,18 @@ "homepage": "https://github.com/killallgit/killall-skills", "version": "6.2.0" }, + { + "name": "clean-tree", + "source": "./", + "description": "Bring the current checkout onto origin's latest default branch while preserving local work, then concisely summarize any leftovers. Use only when the user invokes /clean-tree; account for uncommitted changes, unpublished commits, and stashes without discarding them.", + "strict": false, + "skills": [ + "./skills/clean-tree" + ], + "category": "workflow", + "homepage": "https://github.com/killallgit/killall-skills", + "version": "6.2.0" + }, { "name": "end-session", "source": "./", @@ -196,6 +208,7 @@ "skills": [ "./skills/architectural-review", "./skills/catch-up", + "./skills/clean-tree", "./skills/end-session", "./skills/git-janitor", "./skills/house-rules", diff --git a/README.md b/README.md index 6796e33..c112758 100644 --- a/README.md +++ b/README.md @@ -79,6 +79,7 @@ does not install these instructions. | --- | --- | --- | | `/architectural-review` | user only | Review a codebase's architecture. | | `/catch-up` | user or model | Rebuild a human's lost context on the work in flight after reconciling the current checkout's dangling changes — commit what belongs to an open PR, discard what already landed, sync the branch — then summarize the state of play, decisions, live PRs and tickets, and the single next step. | +| `/clean-tree` | user only | Bring the current checkout onto origin's latest default branch while preserving local work, then concisely summarize any leftovers. | | `/end-session` | user only | Bring this session's branch up to date, land or discard its work, and archive the session. | | `/git-janitor` | user only | Clean up local Git, only when the user runs /git-janitor. | | `/house-rules` | user or model | House rules for writing, changing, or reviewing code — simplicity, deletion, naming, comments, tests, verification. | diff --git a/skills/.cursor-plugin/plugin.json b/skills/.cursor-plugin/plugin.json index f705633..b4504cf 100644 --- a/skills/.cursor-plugin/plugin.json +++ b/skills/.cursor-plugin/plugin.json @@ -4,6 +4,7 @@ "skills": [ "./architectural-review", "./catch-up", + "./clean-tree", "./end-session", "./git-janitor", "./house-rules", diff --git a/skills/clean-tree/.cursor-plugin/plugin.json b/skills/clean-tree/.cursor-plugin/plugin.json new file mode 100644 index 0000000..031ed45 --- /dev/null +++ b/skills/clean-tree/.cursor-plugin/plugin.json @@ -0,0 +1,4 @@ +{ + "name": "clean-tree", + "description": "Bring the current checkout onto origin's latest default branch while preserving local work, then concisely summarize any leftovers. Use only when the user invokes /clean-tree; account for uncommitted changes, unpublished commits, and stashes without discarding them." +} diff --git a/skills/clean-tree/SKILL.md b/skills/clean-tree/SKILL.md new file mode 100644 index 0000000..84deac2 --- /dev/null +++ b/skills/clean-tree/SKILL.md @@ -0,0 +1,97 @@ +--- +name: clean-tree +description: Bring the current checkout onto origin's latest default branch while preserving local work, then concisely summarize any leftovers. Use only when the user invokes /clean-tree; account for uncommitted changes, unpublished commits, and stashes without discarding them. +disable-model-invocation: true +--- + +# Clean tree + +Run in the checkout where invoked, even from a subdirectory. The target is the +remote's default branch, not necessarily `main`. Invocation authorizes fetching, +stashing, switching branches, fast-forwarding, and restoring this run's stash. +It does not authorize committing, pushing, deleting work, or rewriting history. +Do the safe work without repeated prompts; stop at a blocker and report it. + +## 1. Inventory before changing anything + +- Resolve the checkout root with `git rev-parse --show-toplevel`. Stay in this + worktree; do not operate on other worktrees or repositories. +- Record the starting branch (or detached HEAD), HEAD OID, local branch tips, + `git status --porcelain=v1 --untracked-files=all`, staged and unstaged diffs, + untracked paths, `git stash list`, and `git worktree list --porcelain`. + Inspect enough content to summarize the work, without printing secrets. +- Stop before stashing if a merge, rebase, cherry-pick, revert, bisect, or + unresolved conflict is in progress. Do not abort someone else's operation. +- Check submodule status. Dirty submodules are not protected by the parent + repository's stash: stop and report them rather than changing them. +- Require `origin`. Fetch it with `git fetch origin`; on failure, stop without + claiming the checkout is current. Resolve the live default using + `git ls-remote --symref origin HEAD`. Do not trust a stale `origin/HEAD` or + guess `main` when the live default cannot be established. Ensure the target + remote-tracking ref is fetched, including in single-branch clones. +- Compare the starting HEAD and local default branch, if present, with the + freshly fetched `origin/`. Record commits not reachable from it, + their subjects, and ahead-of-upstream counts where an upstream exists. + Missing upstream means unpublished status unknown, not zero unpublished + commits. Keep the starting branch; do not replay its commits onto default. + For detached HEAD commits not reachable from a local branch, create a unique + `clean-tree/recovery-` branch at that OID before switching. +- If the default branch is checked out in another worktree, stop and name that + worktree. Never force a switch or move the task into that directory. +- If the local default has commits absent from `origin/` (ahead or + diverged), stop and summarize them. Do not reset, merge, or rebase it to make + the checkout appear synchronized. Behind-only is safe to fast-forward. + +## 2. Preserve, switch, update, restore + +Run each step only after verifying the preceding one succeeded. Do not paste +an unconditional command chain. + +1. If tracked or untracked changes exist, create a uniquely named stash with + `git stash push --include-untracked -m "clean-tree "`. + Record the newly created stash OID and verify the tracked/untracked worktree + is clean before switching. If creation fails or leaves work behind, stop. + Never pop an older stash when this run created none. Leave ignored files + alone: never use `--all`, delete them, or overwrite them to unblock a switch. +2. Switch to the local default with `git switch `, or, if missing, + create it with `git switch --track -c origin/`. +3. Fast-forward explicitly from origin with + `git merge --ff-only origin/`. This is the fetch-then-pull portion + of the workflow; do not rely on a potentially different configured upstream + or a pull configuration that might rebase or create a merge commit. +4. Restore only this run's stash, preserving the index. Prefer + `git stash apply --index ` so the recovery copy survives + until restoration is verified. On success, verify the work is present, find + its current `stash@{n}` by OID, recheck that mapping, and drop only that entry. + This is the guarded equivalent of `git stash pop --index`. + +If switching or updating fails, leave the stash intact and report the actual +branch and stash OID. If restoration conflicts or fails (including an index or +untracked-path collision), stop: preserve the stash and current files, name the +conflicts, and do not retry, reset, clean, auto-resolve, or drop the stash. +Pre-existing stashes are never applied or dropped. + +## 3. Verify and give a concise receipt + +Re-read the branch, HEAD, `origin/`, status, staged/unstaged diffs, +untracked paths, and stash list. Success means **on the default branch with +HEAD equal to the freshly fetched origin tip**. Restored local edits may still +make the tree dirty; say so rather than claiming it is clean. This is a snapshot +of origin at fetch time, not a guarantee against later remote changes. + +Keep the final response to a short status line and only meaningful leftovers: + +- **Status:** branch, synchronized or blocked, clean or dirty. +- **Leftovers:** group staged/unstaged/untracked changes by purpose, with paths + and a phrase explaining each group. Inspect the restored content; don't just + dump `git status` or assume a feature-branch diff describes it. All restored + edits remain unaccounted for until committed or explicitly handled. +- **Preserved work:** starting-branch commits absent from default (branch and + count/intent), detached recovery branch, and retained stashes (identify this + run's recovery stash separately from older ones). Do not label commits as + definitely unmerged merely because squash merging changed their OIDs. +- **Blocker / next:** any conflict, failed command, or decision needed, and one + concrete next action. Never claim success when a step was skipped or failed. + +Omit empty categories. If fully clean and synchronized with no leftovers, one +line suffices. End at the receipt; don't start reconciling or deleting leftovers. diff --git a/skills/clean-tree/agents/openai.yaml b/skills/clean-tree/agents/openai.yaml new file mode 100644 index 0000000..81e7f51 --- /dev/null +++ b/skills/clean-tree/agents/openai.yaml @@ -0,0 +1,5 @@ +interface: + display_name: "Clean tree" + short_description: "Sync this checkout to origin's default branch and account for local work." +policy: + allow_implicit_invocation: false