Skip to content

Conversation

@satococoa
Copy link
Owner

@satococoa satococoa commented Dec 16, 2025

This follows up on #63 (wtp cd without arguments defaults to the main worktree).

Changes:

  • Fix bash/zsh/fish hooks to allow wtp cd with no args (cd to main worktree).
  • Add e2e coverage for no-arg wtp cd returning the main worktree path.
  • Update README and architecture docs to reflect the new behavior.
  • Remove an unused cd-related error helper.

Tests:

  • GOCACHE=$PWD/.gocache go test ./...

Summary by CodeRabbit

  • New Features

    • Running cd with no arguments now defaults to the main worktree.
  • Documentation

    • Clarified main worktree navigation with improved examples showing the no-argument shorthand and a convenience form; architecture docs now specify pure-path output for cd.
  • Bug Fixes

    • Shell integration handles no-argument cd more reliably and avoids spurious usage messages.
  • Tests

    • Updated and added tests validating no-arg cd across shells.
  • Chores

    • Expanded .gitignore to exclude additional local caches and repro artifacts.

✏️ Tip: You can customize this high-level summary in your review settings.

Copilot AI review requested due to automatic review settings December 16, 2025 15:58
@coderabbitai
Copy link

coderabbitai bot commented Dec 16, 2025

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

Walkthrough

Adds no-argument support for wtp cd (defaults to main worktree), updates generated shell hooks (Bash/Zsh/Fish) to call wtp cd with no args and conditionally cd, removes an exported error constructor, and updates docs and tests to reflect the new behavior.

Changes

Cohort / File(s) Summary
Configuration
\.gitignore``
Added ignore entries for local Go caches and repro artifacts: .gocache/, .gomodcache/, .gopath/, .golangci-cache/, .tmp_repro/.
Documentation
\README.md`, `docs/architecture.md``
Clarified README examples and shorthand for main worktree navigation; updated architecture to require pure-path output from wtp cd, to describe shell wrapper invocation, and to document defaulting to the main worktree when no argument is given.
Hook implementation
\cmd/wtp/hook.go``
Modified generated Bash/Zsh/Fish hook script templates: on no-arg invocations the hook calls wtp cd with no args, captures output to target_dir, and conditionally cd to it (with fallbacks when appropriate); suppressed error output (2>/dev/null) and unified conditional branches.
Hook tests
\cmd/wtp/hook_test.go``
Updated tests to expect no-arg wtp cd handling across shells, added assertions ensuring usage messages are not emitted, and adjusted generated-hook content checks (including quoting for Fish).
Error handling
\internal/errors/errors.go``
Removed exported error constructor WorktreeNameRequired().
Error tests
\internal/errors/errors_test.go``
Removed TestWorktreeNameRequired; updated tests to use WorktreeNameRequiredForRemove and adjusted expected example commands to reference wtp remove / wtp list.
E2E tests
\test/e2e/shell_test.go``
Added CDCommandNoArgsDefaultsToMainWorktree test verifying no-arg cd returns the main worktree path; removed reliance on WTP_SHELL_INTEGRATION env simulation; used filepath.Clean for path comparisons.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Shell as Shell (Bash/Zsh/Fish)
    participant Hook as Shell Hook Script
    participant CLI as wtp CLI

    User->>Shell: run "cd" with hook (no args)
    Shell->>Hook: invoke hook logic for wtp cd
    activate Hook
    Hook->>CLI: call "wtp cd" (no args)
    activate CLI
    CLI-->>Hook: prints path (main worktree) or returns non-zero
    deactivate CLI
    alt CLI returned valid path
        Hook->>Shell: execute `cd "<target_dir>"`
        Shell->>User: CWD changed
    else no valid path
        Hook->>CLI: call "wtp cd <arg>" or show usage (fallback)
        Shell->>User: fallback behavior
    end
    deactivate Hook
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

  • Areas needing attention:
    • cmd/wtp/hook.go: verify correct quoting, consistent behavior across Bash/Zsh/Fish, and safe use of 2>/dev/null.
    • internal/errors/errors.go and tests: ensure removal of WorktreeNameRequired() left no unresolved references.
    • Tests: cmd/wtp/hook_test.go and test/e2e/shell_test.go — confirm assertions match exact output formatting and path normalization.

Possibly related PRs

Suggested labels

codex

Poem

🐇 I sniff the paths and take a hop,
No args today — I know the stop.
The hook calls home, I point the way,
To main worktree where paws may play,
A tiny hop, a tidy sway.

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 9.09% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: fixing shell hook behavior for 'wtp cd' with no arguments, which aligns with the primary objective across all modified files.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix-cd-no-args

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5720fda and adfd033.

📒 Files selected for processing (1)
  • cmd/wtp/hook_test.go (4 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.go

📄 CodeRabbit inference engine (AGENTS.md)

**/*.go: Follow standard Go style with tabs and gofmt; package names must be short and lowercase
Keep import groups tidy; use goimports for organization with local prefix following module path github.com/satococoa/wtp/v2
Adhere to linting rules in .golangci.yml (vet, staticcheck, gosec, mnd, lll=120)
Wrap errors with context; avoid ignoring errors in Go code
Use snake_case for Go filenames (e.g., remove.go, shell_integration.go)
Document exported items in Go when non-trivial; follow godoc conventions

Files:

  • cmd/wtp/hook_test.go
**/*_test.go

📄 CodeRabbit inference engine (AGENTS.md)

**/*_test.go: Unit tests must be placed alongside packages as *_test.go files in the same directory
Target 70% code coverage with unit tests focusing on fast feedback and mocked git interactions using table-driven test cases

Files:

  • cmd/wtp/hook_test.go
🧠 Learnings (12)
📓 Common learnings
Learnt from: CR
Repo: satococoa/wtp PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-02T13:33:48.693Z
Learning: Shell integration must separate completion and hooks for clarity; `wtp cd` outputs absolute worktree path with no side effects
Learnt from: CR
Repo: satococoa/wtp PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-02T13:33:48.693Z
Learning: Toggle shell integration paths with `WTP_SHELL_INTEGRATION=1` when testing cd behavior
Learnt from: CR
Repo: satococoa/wtp PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-02T13:33:48.693Z
Learning: Run commands from inside a worktree to mimic real usage (e.g., `go run ../cmd/wtp add feature/new-feature`)
Learnt from: CR
Repo: satococoa/wtp PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-02T13:33:48.693Z
Learning: Applies to .wtp.yml : Project hooks must be defined in `.wtp.yml`; keep commands deterministic and safe, avoiding destructive steps by default
Learnt from: CR
Repo: satococoa/wtp PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-02T13:33:48.693Z
Learning: CLI entrypoint is located at `cmd/wtp`; new command implementations must integrate with the main CLI structure
Learnt from: CR
Repo: satococoa/wtp PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-02T13:33:48.693Z
Learning: Worktree naming convention: main worktree is rendered as `@`; non-main worktrees display path relative to `base_dir` (e.g., `.worktrees/feat/hoge` → `feat/hoge`)
📚 Learning: 2025-12-02T13:33:48.693Z
Learnt from: CR
Repo: satococoa/wtp PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-02T13:33:48.693Z
Learning: Applies to **/*_test.go : Target 70% code coverage with unit tests focusing on fast feedback and mocked git interactions using table-driven test cases

Applied to files:

  • cmd/wtp/hook_test.go
📚 Learning: 2025-12-02T13:33:48.693Z
Learnt from: CR
Repo: satococoa/wtp PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-02T13:33:48.693Z
Learning: Shell integration must separate completion and hooks for clarity; `wtp cd` outputs absolute worktree path with no side effects

Applied to files:

  • cmd/wtp/hook_test.go
📚 Learning: 2025-12-02T13:33:48.693Z
Learnt from: CR
Repo: satococoa/wtp PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-02T13:33:48.693Z
Learning: Run commands from inside a worktree to mimic real usage (e.g., `go run ../cmd/wtp add feature/new-feature`)

Applied to files:

  • cmd/wtp/hook_test.go
📚 Learning: 2025-12-02T13:33:48.693Z
Learnt from: CR
Repo: satococoa/wtp PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-02T13:33:48.693Z
Learning: Run `go tool task dev` before committing to ensure code is formatted, linted, and tests pass

Applied to files:

  • cmd/wtp/hook_test.go
📚 Learning: 2025-12-02T13:33:48.693Z
Learnt from: CR
Repo: satococoa/wtp PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-02T13:33:48.693Z
Learning: CLI entrypoint is located at `cmd/wtp`; new command implementations must integrate with the main CLI structure

Applied to files:

  • cmd/wtp/hook_test.go
📚 Learning: 2025-12-02T13:33:48.693Z
Learnt from: CR
Repo: satococoa/wtp PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-02T13:33:48.693Z
Learning: Applies to **/*.go : Keep import groups tidy; use goimports for organization with local prefix following module path `github.com/satococoa/wtp/v2`

Applied to files:

  • cmd/wtp/hook_test.go
📚 Learning: 2025-12-02T13:33:48.693Z
Learnt from: CR
Repo: satococoa/wtp PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-02T13:33:48.693Z
Learning: Applies to test/e2e/**/*.go : End-to-end tests must be placed in `test/e2e` and exercise real git workflows using the built binary

Applied to files:

  • cmd/wtp/hook_test.go
📚 Learning: 2025-12-02T13:33:48.693Z
Learnt from: CR
Repo: satococoa/wtp PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-02T13:33:48.693Z
Learning: The root module is `github.com/satococoa/wtp/v2` running on Go 1.24; maintain module path consistency

Applied to files:

  • cmd/wtp/hook_test.go
📚 Learning: 2025-12-02T13:33:48.693Z
Learnt from: CR
Repo: satococoa/wtp PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-02T13:33:48.693Z
Learning: Use `go run ./cmd/wtp <args>` for rapid feedback during development instead of building binaries

Applied to files:

  • cmd/wtp/hook_test.go
📚 Learning: 2025-12-02T13:33:48.693Z
Learnt from: CR
Repo: satococoa/wtp PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-02T13:33:48.693Z
Learning: Toggle shell integration paths with `WTP_SHELL_INTEGRATION=1` when testing cd behavior

Applied to files:

  • cmd/wtp/hook_test.go
📚 Learning: 2025-12-02T13:33:48.693Z
Learnt from: CR
Repo: satococoa/wtp PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-02T13:33:48.693Z
Learning: Applies to .wtp.yml : Project hooks must be defined in `.wtp.yml`; keep commands deterministic and safe, avoiding destructive steps by default

Applied to files:

  • cmd/wtp/hook_test.go
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Build
🔇 Additional comments (4)
cmd/wtp/hook_test.go (4)

124-136: Excellent addition—addresses previous review feedback.

The zsh test case provides the missing coverage identified in the prior review. The test logic correctly mirrors the bash implementation, validating both the no-arg fallback to the main worktree and the explicit worktree name handling.


109-109: Good defensive testing with negative assertions.

The notContains field and corresponding assertions ensure that usage error messages are not present in the generated hooks, confirming the no-arg behavior works correctly without falling back to error states.

Also applies to: 170-172


112-123: Well-structured validation of no-arg cd behavior.

The updated test cases for bash and fish correctly validate the core logic changes:

  • Detection of missing second argument
  • Fallback to no-arg wtp cd (defaults to main worktree)
  • Explicit worktree name handling when provided
  • Absence of usage error messages

Shell-specific syntax differences are properly accounted for.

Also applies to: 138-150


160-161: Essential implementation for zsh test coverage.

The zsh case in the switch statement correctly invokes printZshHook to generate the hook output for validation, completing the test infrastructure for all three supported shells.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 85f338f and e512816.

📒 Files selected for processing (8)
  • .gitignore (1 hunks)
  • README.md (3 hunks)
  • cmd/wtp/hook.go (3 hunks)
  • cmd/wtp/hook_test.go (3 hunks)
  • docs/architecture.md (3 hunks)
  • internal/errors/errors.go (0 hunks)
  • internal/errors/errors_test.go (2 hunks)
  • test/e2e/shell_test.go (2 hunks)
💤 Files with no reviewable changes (1)
  • internal/errors/errors.go
🧰 Additional context used
📓 Path-based instructions (3)
**/*.go

📄 CodeRabbit inference engine (AGENTS.md)

**/*.go: Follow standard Go style with tabs and gofmt; package names must be short and lowercase
Keep import groups tidy; use goimports for organization with local prefix following module path github.com/satococoa/wtp/v2
Adhere to linting rules in .golangci.yml (vet, staticcheck, gosec, mnd, lll=120)
Wrap errors with context; avoid ignoring errors in Go code
Use snake_case for Go filenames (e.g., remove.go, shell_integration.go)
Document exported items in Go when non-trivial; follow godoc conventions

Files:

  • internal/errors/errors_test.go
  • test/e2e/shell_test.go
  • cmd/wtp/hook.go
  • cmd/wtp/hook_test.go
**/*_test.go

📄 CodeRabbit inference engine (AGENTS.md)

**/*_test.go: Unit tests must be placed alongside packages as *_test.go files in the same directory
Target 70% code coverage with unit tests focusing on fast feedback and mocked git interactions using table-driven test cases

Files:

  • internal/errors/errors_test.go
  • test/e2e/shell_test.go
  • cmd/wtp/hook_test.go
test/e2e/**/*.go

📄 CodeRabbit inference engine (AGENTS.md)

End-to-end tests must be placed in test/e2e and exercise real git workflows using the built binary

Files:

  • test/e2e/shell_test.go
🧠 Learnings (17)
📓 Common learnings
Learnt from: CR
Repo: satococoa/wtp PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-02T13:33:48.693Z
Learning: Shell integration must separate completion and hooks for clarity; `wtp cd` outputs absolute worktree path with no side effects
Learnt from: CR
Repo: satococoa/wtp PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-02T13:33:48.693Z
Learning: Toggle shell integration paths with `WTP_SHELL_INTEGRATION=1` when testing cd behavior
Learnt from: CR
Repo: satococoa/wtp PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-02T13:33:48.693Z
Learning: Run commands from inside a worktree to mimic real usage (e.g., `go run ../cmd/wtp add feature/new-feature`)
Learnt from: CR
Repo: satococoa/wtp PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-02T13:33:48.693Z
Learning: Worktree naming convention: main worktree is rendered as `@`; non-main worktrees display path relative to `base_dir` (e.g., `.worktrees/feat/hoge` → `feat/hoge`)
Learnt from: CR
Repo: satococoa/wtp PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-02T13:33:48.693Z
Learning: Applies to .wtp.yml : Project hooks must be defined in `.wtp.yml`; keep commands deterministic and safe, avoiding destructive steps by default
Learnt from: CR
Repo: satococoa/wtp PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-02T13:33:48.693Z
Learning: CLI entrypoint is located at `cmd/wtp`; new command implementations must integrate with the main CLI structure
📚 Learning: 2025-12-02T13:33:48.693Z
Learnt from: CR
Repo: satococoa/wtp PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-02T13:33:48.693Z
Learning: Applies to **/*_test.go : Target 70% code coverage with unit tests focusing on fast feedback and mocked git interactions using table-driven test cases

Applied to files:

  • internal/errors/errors_test.go
  • .gitignore
  • test/e2e/shell_test.go
  • cmd/wtp/hook_test.go
📚 Learning: 2025-12-02T13:33:48.693Z
Learnt from: CR
Repo: satococoa/wtp PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-02T13:33:48.693Z
Learning: Applies to test/e2e/**/*.go : End-to-end tests must be placed in `test/e2e` and exercise real git workflows using the built binary

Applied to files:

  • internal/errors/errors_test.go
  • test/e2e/shell_test.go
📚 Learning: 2025-12-02T13:33:48.693Z
Learnt from: CR
Repo: satococoa/wtp PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-02T13:33:48.693Z
Learning: Run commands from inside a worktree to mimic real usage (e.g., `go run ../cmd/wtp add feature/new-feature`)

Applied to files:

  • internal/errors/errors_test.go
  • test/e2e/shell_test.go
  • README.md
  • docs/architecture.md
  • cmd/wtp/hook.go
  • cmd/wtp/hook_test.go
📚 Learning: 2025-12-02T13:33:48.693Z
Learnt from: CR
Repo: satococoa/wtp PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-02T13:33:48.693Z
Learning: Applies to **/*.go : Document exported items in Go when non-trivial; follow godoc conventions

Applied to files:

  • .gitignore
📚 Learning: 2025-12-02T13:33:48.693Z
Learnt from: CR
Repo: satococoa/wtp PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-02T13:33:48.693Z
Learning: Applies to **/*.go : Keep import groups tidy; use goimports for organization with local prefix following module path `github.com/satococoa/wtp/v2`

Applied to files:

  • .gitignore
  • cmd/wtp/hook.go
📚 Learning: 2025-12-02T13:33:48.693Z
Learnt from: CR
Repo: satococoa/wtp PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-02T13:33:48.693Z
Learning: Applies to **/*.go : Follow standard Go style with tabs and gofmt; package names must be short and lowercase

Applied to files:

  • .gitignore
📚 Learning: 2025-12-02T13:33:48.693Z
Learnt from: CR
Repo: satococoa/wtp PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-02T13:33:48.693Z
Learning: Toggle shell integration paths with `WTP_SHELL_INTEGRATION=1` when testing cd behavior

Applied to files:

  • test/e2e/shell_test.go
  • README.md
  • docs/architecture.md
  • cmd/wtp/hook.go
  • cmd/wtp/hook_test.go
📚 Learning: 2025-12-02T13:33:48.693Z
Learnt from: CR
Repo: satococoa/wtp PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-02T13:33:48.693Z
Learning: Shell integration must separate completion and hooks for clarity; `wtp cd` outputs absolute worktree path with no side effects

Applied to files:

  • test/e2e/shell_test.go
  • README.md
  • docs/architecture.md
  • cmd/wtp/hook.go
  • cmd/wtp/hook_test.go
📚 Learning: 2025-12-02T13:33:48.693Z
Learnt from: CR
Repo: satococoa/wtp PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-02T13:33:48.693Z
Learning: CLI entrypoint is located at `cmd/wtp`; new command implementations must integrate with the main CLI structure

Applied to files:

  • test/e2e/shell_test.go
  • README.md
  • docs/architecture.md
  • cmd/wtp/hook.go
  • cmd/wtp/hook_test.go
📚 Learning: 2025-12-02T13:33:48.693Z
Learnt from: CR
Repo: satococoa/wtp PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-02T13:33:48.693Z
Learning: Applies to **/*_test.go : Unit tests must be placed alongside packages as `*_test.go` files in the same directory

Applied to files:

  • test/e2e/shell_test.go
📚 Learning: 2025-12-02T13:33:48.693Z
Learnt from: CR
Repo: satococoa/wtp PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-02T13:33:48.693Z
Learning: Document new workflows with realistic scenarios in `test/e2e` directory

Applied to files:

  • test/e2e/shell_test.go
📚 Learning: 2025-12-02T13:33:48.693Z
Learnt from: CR
Repo: satococoa/wtp PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-02T13:33:48.693Z
Learning: Use `go run ./cmd/wtp <args>` for rapid feedback during development instead of building binaries

Applied to files:

  • test/e2e/shell_test.go
  • docs/architecture.md
  • cmd/wtp/hook.go
📚 Learning: 2025-12-02T13:33:48.693Z
Learnt from: CR
Repo: satococoa/wtp PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-02T13:33:48.693Z
Learning: The root module is `github.com/satococoa/wtp/v2` running on Go 1.24; maintain module path consistency

Applied to files:

  • test/e2e/shell_test.go
  • cmd/wtp/hook.go
📚 Learning: 2025-12-02T13:33:48.693Z
Learnt from: CR
Repo: satococoa/wtp PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-02T13:33:48.693Z
Learning: Worktree naming convention: main worktree is rendered as `@`; non-main worktrees display path relative to `base_dir` (e.g., `.worktrees/feat/hoge` → `feat/hoge`)

Applied to files:

  • README.md
  • docs/architecture.md
  • cmd/wtp/hook.go
📚 Learning: 2025-12-02T13:33:48.693Z
Learnt from: CR
Repo: satococoa/wtp PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-02T13:33:48.693Z
Learning: Update README and CLI help text when user-facing behavior changes

Applied to files:

  • README.md
📚 Learning: 2025-12-02T13:33:48.693Z
Learnt from: CR
Repo: satococoa/wtp PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-02T13:33:48.693Z
Learning: Applies to .wtp.yml : Project hooks must be defined in `.wtp.yml`; keep commands deterministic and safe, avoiding destructive steps by default

Applied to files:

  • docs/architecture.md
  • cmd/wtp/hook.go
  • cmd/wtp/hook_test.go
🧬 Code graph analysis (2)
internal/errors/errors_test.go (1)
internal/errors/errors.go (1)
  • WorktreeNameRequiredForRemove (51-63)
test/e2e/shell_test.go (1)
test/e2e/framework/assertions.go (2)
  • AssertNoError (75-78)
  • AssertTrue (162-165)
🪛 GitHub Check: Lint
cmd/wtp/hook_test.go

[failure] 115-115:
File is not properly formatted (gofmt)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: Agent
  • GitHub Check: Test (macos-latest, 1.24)
🔇 Additional comments (15)
.gitignore (1)

39-44: LGTM!

The added ignore entries for local caches and temporary directories are appropriate for development and CI workflows. The comment clearly explains their purpose.

cmd/wtp/hook.go (3)

70-101: LGTM! Bash hook correctly handles no-arg cd.

The implementation properly:

  • Captures the target directory from wtp cd with stderr suppression
  • Conditionally invokes with or without the worktree argument
  • Falls back to showing errors when the command fails
  • Handles spaces correctly with proper quoting

103-134: LGTM! Zsh hook correctly handles no-arg cd.

The implementation mirrors the bash hook with proper zsh syntax, maintaining consistency across shells.


136-166: LGTM! Fish hook correctly handles no-arg cd.

The implementation properly adapts the bash/zsh pattern to Fish syntax:

  • Uses set -l for local variables
  • Uses $argv[2] for argument access
  • Properly quotes "$target_dir" for paths with spaces
cmd/wtp/hook_test.go (1)

104-160: LGTM! Test coverage for no-arg cd behavior is solid.

The tests properly verify:

  • No-arg branch detection for both bash and fish
  • Default behavior when no worktree is specified
  • Explicit worktree handling
  • Absence of legacy usage messages
  • Proper quoting for paths with spaces (fish)

Note: Zsh is not explicitly tested in edge cases, but since its logic is identical to bash, the coverage is acceptable.

README.md (3)

61-61: LGTM! Clear documentation of the no-arg shorthand.

The parenthetical note effectively communicates that wtp cd without arguments works as a shorthand to the main worktree.


287-302: LGTM! Examples clearly demonstrate both forms.

The documentation now shows:

  1. The no-arg form: cd "$(wtp cd)"
  2. The explicit form: cd "$(wtp cd @)"

This helps users understand they have options while emphasizing the convenience of the no-arg form.


312-325: LGTM! Hook usage examples are clear and well-structured.

The examples effectively demonstrate the simplified syntax with hooks:

  • No-arg form shown first as the primary pattern
  • Explicit @ form shown as an alternative
  • Comments clarify the equivalence
test/e2e/shell_test.go (1)

15-30: LGTM! E2E test correctly verifies no-arg cd behavior.

The test properly:

  • Invokes wtp cd without arguments
  • Verifies the command succeeds
  • Compares the output path to the main worktree
  • Uses filepath.Clean for robust path comparison

The assumption that the first worktree from ListWorktrees() is the main worktree is reasonable and aligns with git's worktree list behavior.

internal/errors/errors_test.go (3)

82-90: LGTM! Test correctly renamed and updated.

The test function properly validates the WorktreeNameRequiredForRemove error constructor, ensuring it contains:

  • Clear error message
  • Remove command examples
  • Helpful hint to run wtp list

415-453: LGTM! Test case properly updated for remove command context.

The test case now correctly validates that WorktreeNameRequiredForRemove contains examples relevant to the remove command rather than cd command, which aligns with the PR's goal of making wtp cd with no args valid.


455-481: LGTM! Error format test updated consistently.

The test array now includes WorktreeNameRequiredForRemove, maintaining format validation coverage for all error constructors.

docs/architecture.md (3)

154-160: LGTM! Architecture docs accurately describe the no-arg behavior.

The documentation clearly states:

  1. The [worktree] argument is optional
  2. Defaults to main worktree when omitted
  3. Maintains the pure path output contract

162-176: LGTM! Shell integration flow accurately documented.

The flow correctly shows direct command invocation without environment variable triggers, matching the actual implementation.


178-183: LGTM! Key design decisions are clearly articulated.

The documentation effectively emphasizes:

  1. Pure Path Output: Clarifies that wtp cd has no side effects
  2. Shell Function Wrapper: Explains the technical necessity

These points help future contributors understand the design rationale.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR enables wtp cd to work without arguments, defaulting to the main worktree (similar to how cd without arguments goes to $HOME). The implementation removes the previous shell integration environment variable requirement and updates all shell hooks (bash/zsh/fish) to support this new behavior.

Key Changes:

  • Modified shell hooks to handle wtp cd with no arguments, calling the command with default behavior instead of showing a usage error
  • Added e2e test coverage for the no-argument case
  • Removed the unused WorktreeNameRequired() error helper function

Reviewed changes

Copilot reviewed 7 out of 8 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
cmd/wtp/hook.go Updated bash/zsh/fish shell hooks to support no-arg wtp cd by conditionally calling the command with or without arguments, and added proper quoting for paths with spaces
cmd/wtp/hook_test.go Updated tests to verify hooks support no-arg wtp cd and don't show usage errors, plus added assertions for proper space handling
test/e2e/shell_test.go Added test for wtp cd with no arguments returning main worktree path; removed obsolete WTP_SHELL_INTEGRATION environment variable usage
internal/errors/errors.go Removed unused WorktreeNameRequired() error helper function
internal/errors/errors_test.go Updated tests to remove references to deleted WorktreeNameRequired() function
docs/architecture.md Updated documentation to reflect optional worktree argument and removal of environment variable check
README.md Added examples showing wtp cd with no arguments as equivalent to wtp cd @
.gitignore Added local cache directories for development environments

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@satococoa satococoa merged commit 3afdc10 into main Dec 16, 2025
7 checks passed
@satococoa satococoa deleted the fix-cd-no-args branch December 16, 2025 16:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants