skills: add agent_worktree.py for isolated PR/branch checkouts - #205
Open
doomedraven wants to merge 2 commits into
Open
skills: add agent_worktree.py for isolated PR/branch checkouts#205doomedraven wants to merge 2 commits into
doomedraven wants to merge 2 commits into
Conversation
Reviewing a pull request or testing someone else's branch means checking it out somewhere. Doing that in your working clone is unsafe when it carries uncommitted work, and doing it with git worktree by hand means resolving which fork the branch lives in, fetching it under a name that will not collide, setting upstream, and remembering to tear it down. This repository uses the fork convention - origin is your fork, upstream is kevoreilly/capemon, and the default branch is 'capemon' - which makes the manual version more error-prone than usual. The script reads the canonical repository from upstream, so PR lookups go to the right place, and 'new --branch' searches origin, upstream and any other remote in turn. new --pr <id> / --branch <name> / --from <ref> list / path / update / remove / cleanup / info Standard library only; no dependencies and nothing to build. gh is needed only for --pr. Worktrees it creates are tagged inside the git admin directory, so git status stays clean and cleanup only ever removes its own. remove and cleanup refuse to discard uncommitted changes or unpushed commits. The same script lives in CAPEv2 as utils/agent_worktree.py.
Mirrors kevoreilly/CAPEv2#3228. The removal guard compared HEAD against the tracked upstream only, so a branch tracking 'upstream/capemon' while its commits were pushed to a fork looked unpushed and cleanup refused to remove it. Work now counts as unpushed only when no remote-tracking ref contains HEAD.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds
agent_worktree.pyto thecapemon-developerskill and documents it inSKILL.md: a wrapper aroundgit worktreefor reviewing PRs and testing branches without touching your working clone.Why
Checking out someone else's branch means either polluting your clone — unsafe when it carries uncommitted work, which most do — or doing the
git worktreeplumbing by hand.This repository makes the manual version more error-prone than usual: it uses the fork convention, so
originis your own fork andupstreamiskevoreilly/capemon, and the default branch iscapemonrather thanmaster. Getting a PR branch checked out means working out which of the two remotes (or which third-party fork) actually holds the head ref.Usage
--jsonon any command for scripted use.ghis needed only for--pr.Fork-layout handling
upstreamwhen configured, sonew --pr <id>querieskevoreilly/capemoninstead of your fork.new --prasksghwhich fork the head branch lives in and fetches from the matching remote; if no remote matches it fetches straight from the fork URL into a private ref namespace and warns that no upstream was set.new --branchtriesorigin, thenupstream, then any other remote, and reports which one supplied the branch.--remoteforces one.Safety
checkout,reset,stashorclean;removerefuses the main worktree outright.agent-meta.jsoninside.git/worktrees/<id>/, i.e. the git admin directory, sogit statusin the worktree stays empty and a hand-madegit worktree addis never touched bycleanup.removeandcleanupbail on uncommitted changes or unpushed commits;cleanupskips them and prints the reason.--forceoverrides.~/.cache/agent-worktrees/capemon/<name>, overridable with--base-dir,--pathor$AGENT_WORKTREE_DIR.Notes
Python standard library only — no dependencies, nothing to build, and no interaction with the MSBuild toolchain. A worktree is a full checkout, so the existing build commands work inside one unchanged.
The same script is maintained in CAPEv2 as
utils/agent_worktree.py(kevoreilly/CAPEv2#3228), where it ships with a test suite covering the CLI against throwaway local repositories.SKILL.mdnotes that the two copies should be kept in sync.