Repository navigation
refactor(wt-open): generalize to any directory; formalize launcher contract - #2
Conversation
…ntract Loosens wt open's git-repo precondition so it works on any directory, making it the canonical directory launcher in the toolchain. hop's existing subprocess delegation via WT_CD_FILE/WT_WRAPPER continues to work and is now formally documented as a stable contract in docs/specs/launcher-contract.md. Changes: - src/cmd/wt/open.go: replace hard ValidateGitRepo() fail with soft detection; add path-from-non-git, no-args-cwd, name-from-non-git branches; introduce errWorktreeNotFound sentinel so name-not-found maps to ExitGeneralError while real git failures map to ExitGitError - src/internal/worktree/apps.go: tabName(repoName, wtName) helper for byobu/tmux tab/session naming, falling back to wtName alone in non-git invocations - docs/specs/launcher-contract.md (new): formal contract documenting WT_CD_FILE, WT_WRAPPER, exit codes, and stability guarantees - docs/specs/cli-surface.md: updated wt open entry per loosened precondition; cross-references launcher-contract.md - Tests: 4 new unit tests + 1 integration test exercising the contract end-to-end against a non-git tempdir; all 6 pre-existing wt-open tests continue to pass
There was a problem hiding this comment.
Pull request overview
Refactors wt open so it can launch any existing directory (even outside a git repo) while preserving the existing in-repo worktree behavior, and formalizes the subprocess launcher contract (WT_CD_FILE / WT_WRAPPER) in documentation with new tests.
Changes:
- Loosened
wt open’s hard git-repo precondition into soft git-context detection, adding non-git fallbacks (open cwd / accept path args). - Introduced
tabName(repoName, wtName)to preserve historical tmux/byobu naming while avoiding a leading dash for non-git invocations. - Added a formal launcher contract spec plus unit/integration coverage for the new non-git branches and env-var contract.
Reviewed changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
src/internal/worktree/apps.go |
Adds tabName helper and uses it for tmux/byobu naming when repo context may be absent. |
src/internal/worktree/apps_test.go |
Adds unit test coverage for tabName. |
src/cmd/wt/open.go |
Refactors argument/context resolution to allow non-git operation and adds sentinel error for “worktree not found” vs git failure. |
src/cmd/wt/open_test.go |
Adds tests for non-git no-args/path/name behavior and for in-repo “not found” exit-code mapping. |
src/cmd/wt/integration_test.go |
Adds end-to-end integration test for WT_CD_FILE + WT_WRAPPER contract in a non-git temp dir. |
docs/specs/launcher-contract.md |
New spec documenting subprocess launcher contract, env vars, exit-code semantics, and stability guarantees. |
docs/specs/index.md |
Adds the launcher-contract spec to the specs index. |
docs/specs/cli-surface.md |
Updates wt open CLI documentation to reflect the relaxed precondition and links to launcher-contract. |
fab/changes/260508-evbf-wt-open-any-directory/spec.md |
Change spec capturing requirements, scenarios, and design decisions for the refactor. |
fab/changes/260508-evbf-wt-open-any-directory/plan.md |
Execution plan/tasks and acceptance checklist for the change. |
fab/changes/260508-evbf-wt-open-any-directory/intake.md |
Intake/problem statement and scope decisions for the change. |
fab/changes/260508-evbf-wt-open-any-directory/.status.yaml |
FAB change tracking metadata for this work item. |
fab/changes/260508-evbf-wt-open-any-directory/.history.jsonl |
FAB stage transition history for this work item. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if info, err := os.Stat(target); err == nil && info.IsDir() { | ||
| wtPath = target | ||
| wtName = filepath.Base(wtPath) | ||
| } else { | ||
| // Try as worktree name | ||
| if inRepo { | ||
| repoName = ctx.RepoName | ||
| } | ||
| } else if inRepo { | ||
| // Try as worktree name (requires git context to walk worktrees). |
There was a problem hiding this comment.
Fixed — handled the os.Stat success + !info.IsDir() case explicitly with a clear 'target exists but is not a directory' ExitGeneralError, and added TestOpen_PathArg_ExistsButNotDir. (a8af131)
| // Resolve symlinks (macOS /tmp -> /private/tmp); wt's filepath.Base on | ||
| // the resolved path is what ends up in WT_CD_FILE. |
There was a problem hiding this comment.
Fixed — rewrote the comment to clarify symlink resolution is about path stability (macOS /tmp vs /private/tmp), not basenames; WT_CD_FILE receives the full resolved path. (a8af131)
| directory path to that file (mode `0600`) instead of printing a `cd --` line | ||
| to stdout. | ||
| - Consumers read the file after a zero-exit `wt open` invocation and apply the | ||
| `cd` to the parent shell themselves (via shell wrapper, eval, or whatever | ||
| mechanism the consumer uses). | ||
| - The file is overwritten on each invocation; truncate-on-open semantics. | ||
| - Mode `0600` is intentional — the file may contain a path the user considers | ||
| private; consumers MUST NOT relax this. |
There was a problem hiding this comment.
Fixed — clarified §3 to note that os.WriteFile only applies the 0600 mode on file creation (no chmod of existing files), so consumers are responsible for supplying a fresh path (e.g., via mktemp) or a pre-mode-0600 file. (a8af131)
Summary
wt open's precondition: replaces the hardValidateGitRepo()fail with soft git-context detection so the command works on any existing directory (path arg, no-args cwd) while preserving every prior in-repo branch.docs/specs/launcher-contract.md: documentsWT_CD_FILE,WT_WRAPPER, exit-code semantics, stability guarantees, and directory-only non-goals.hop's existing subprocess delegation viaWT_CD_FILE/WT_WRAPPERis unchanged — it continues to work and is now backed by a stable, tested spec rather than implicit producer/consumer comments.wt openinvocation that worked before this change behaves identically afterward (verified by unchanged in-repo test paths and integration tests).Test plan
go test ./...in src/)