Repository navigation
fix(plugin): /wt-switch-create guesses whether a bare name is the repo or the branch - #4159
Conversation
…o or the branch A bare token like `worktrunk` could name a repository or a branch, and the old grammar always read it as a branch, so an invocation from outside the repo (or naming a sibling repo) created a branch in the wrong place or asked. The skill now reads a bare name as the repo when a git repository by that name exists where the user keeps repos, and as the branch otherwise; a subdirectory of the current repo stays a branch. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
worktrunk-bot
left a comment
There was a problem hiding this comment.
Two things on the new bare-name rule.
A guessed repo name never reaches the commands that consume it. The
grammar bullet now reads "optional path or name", but step 3 substitutes
<repo> into wt -C <repo> and cd <repo>, and wt's -C is a
working-directory path (Cli::directory in src/cli/mod.rs —
value_name = "path", Option<PathBuf>) resolved against the cwd. So
/wt-switch-create prql -- … from ~/workspace/worktrunk classifies prql
as the repo and then runs wt -C prql, which fails, and step 3's handling for
that is "Any other failure (not a git repo, invalid name): report it and
stop." The guess already had to locate the repository on disk, so the fix is
to say that resolved path is what carries forward — suggestion inline. This is
exactly the path the PR notes as unexercised ("a live session that has to find
the repository on disk before guessing"), which is what makes it worth pinning
in the prose rather than leaving to the model.
A bare name that is also a local branch has no tiebreak. The repo reading
wins unconditionally, so in a ~/workspace holding docs, api, cli, an
invocation like /wt-switch-create docs -- update the install page targets
~/workspace/docs with a branch name picked from the task, instead of
creating a docs branch here — and nothing in the output says which reading
it took. Naming an existing branch is supported usage (step 3 handles
Branch <branch> already exists by rerunning without --create), and
git show-ref --verify --quiet refs/heads/<name> is a cheaper check than the
workspace scan. Deferring to the branch would also match worktrunk's own
tiebreak for this shape of ambiguity — after_long_help in src/cli/mod.rs
says a path is "resolved after the branch, so a directory never shadows a
branch sharing its name". Your call whether the skill should follow that or
ask; the A/B table doesn't cover the collision.
…g branch win Review findings on the bare-name rule: a guessed name was never resolved to a path, though step 3 substitutes it into `wt -C <repo>` and `cd <repo>`, which take a directory; and a name that is already a branch here lost to a same-named repo. The guess now carries the repository's absolute path forward, and an existing branch wins, matching how `wt switch` resolves a branch before a path. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
A bare token like
worktrunkpassed to/wt-switch-createcould name a repository or a branch, and nothing in the invocation says which. The grammar read every non-path token as the branch, so/wt-switch-create worktrunk -- …from a directory outside any repo, orprql -- …from a worktrunk worktree, took the repo name as a branch (or asked).The skill now makes an informed guess:
wt switchresolves a branch before a path ("a directory never shadows a branch sharing its name",after_long_helpinsrc/cli/mod.rs).~/workspace), and the branch when none does. A subdirectory of the current repo stays a branch:docsis not thedocs/directory.wt -C <repo>andcd <repo>, both of which take a directory rather than a name.Two tokens that both read as branches still ask.
Testing
An A/B test gave the old and new passages the same scenarios, with the filesystem facts stated, 2 runs each:
worktrunk -- …from~(not a repo)worktrunk, asks~/workspace/worktrunkprql -- …from a worktrunk worktreeprql~/workspace/prqlfix-parser prql -- …fix-parser, repoprqldocs -- …(subdirectory only)fix-auth -- …The new wording read all 10 runs as intended. The revised passage was re-run on the repo, subdirectory and no-match cases, plus the collision the review raised — a local
docsbranch alongside a~/workspace/docsrepository, where the branch wins — for 8 further runs, all as intended.Not exercised: a live session that has to find the repository on disk before guessing.
🤖 Generated with Claude Code