Add 'enter' command to open a subshell in an existing worktree#42
Add 'enter' command to open a subshell in an existing worktree#42Tsha0 wants to merge 2 commits into
Conversation
treehouse enter <name> drops into an existing pool worktree (identified by the number shown in 'treehouse status'), including worktrees that are already in use. Unlike 'get', it does not acquire, reset, or return the worktree, leaving all pool state untouched on exit -- useful for attaching to a worktree another agent is using. Amp-Thread-ID: https://ampcode.com/threads/T-019f0476-3777-70a8-a117-f9b788fb6c98 Co-authored-by: Amp <amp@ampcode.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 2b78886138
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| func enterRunE(cmd *cobra.Command, args []string) error { | ||
| name := args[0] | ||
|
|
||
| repoRoot, err := git.FindRepoRoot() |
There was a problem hiding this comment.
Use the owning repo when resolving the pool
When enter is run from inside one of Treehouse's linked worktrees for a local-only repository, or for a repo that uses a relative root, git rev-parse --show-toplevel returns the linked worktree path rather than the original repository root. That makes config.ResolvePoolDir hash/resolve a different pool, so treehouse enter <name> reports an empty or wrong pool instead of finding sibling worktrees; this flow is likely when users are already inside a Treehouse shell and want to hop to another worktree. Resolve the main repo root here (as the return/destroy paths do) before loading config and computing the pool directory.
Useful? React with 👍 / 👎.
Add a --print-path flag to 'enter' that prints only the worktree's absolute path to stdout (no subshell), so a shell function can change its own directory: cd "$(treehouse enter --print-path 1)". Amp-Thread-ID: https://ampcode.com/threads/T-019f0476-3777-70a8-a117-f9b788fb6c98 Co-authored-by: Amp <amp@ampcode.com>
What
Adds
treehouse enter <name>, which opens a subshell in an existing pool worktree identified by its name (the number shown bytreehouse status), including worktrees that are already in use.Why
getalways hands out a free worktree and skips anything in-use/leased/dirty. There was no first-class way to re-attach to a specific existing worktree (e.g. to peek at what another agent is doing, or to hop back into a worktree you know by number). The workaround wascd-ing into the raw pool path by hand.Behavior
pool.List, then spawns a subshell in its directory (setsTREEHOUSE_DIR), mirroring howgetenters.get,enteris a guest: it does not acquire, reset, lease, or return the worktree, and writes no pool state. On exit it leaves everything exactly as it was.Tests
Adds two e2e tests (
TestEnterByNameOpensSubshellWithoutChangingPool,TestEnterUnknownNameFails). Full suite passes;gofmt/go vetclean. Reuses the cross-platformshell.Spawn, so no Windows-specific handling is needed.Docs (README CLI reference, AGENTS.md command list) updated.