Repository navigation
feat: add clean-tree checkout synchronization skill #55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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." | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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/<default>`. 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-<timestamp>` 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/<default>` (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 <unique-run-id>"`. | ||
| 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 <default>`, or, if missing, | ||
| create it with `git switch --track -c <default> origin/<default>`. | ||
| 3. Fast-forward explicitly from origin with | ||
| `git merge --ff-only origin/<default>`. 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 <recorded-stash-OID>` 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. | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Positional stash drop can delete another worktree's stash. Step 2.4 rechecks the OID-to-index mapping of this run's stash, then drops Require one of these before dropping:
Do not rely on the positional recheck alone.
|
||
| 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/<default>`, 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. | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prevent Git from overwriting ignored files.
If an ignored
local.cfgexists locally and the incoming default branch starts tracking that path, the fast-forward can silently replace the local file.git mergeoverwrites ignored files by default. The stash does not protect this file. (git-scm.com)The switch commands also enable overwriting ignored files by default. Add
--no-overwrite-ignoreto both switch forms and the merge command. This makes collisions stop without losing the ignored content and keeps collision-free synchronization available. (raw.githubusercontent.com)Also applies to: 59-59