Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
142 changes: 21 additions & 121 deletions AGENTS.md
Original file line number Diff line number Diff line change
@@ -1,121 +1,21 @@
# Repository Guidelines

## Document Purpose
- Single source of truth for AI assistants contributing to `wtp`.
- Consolidates design decisions, workflow expectations, and coding standards previously split across `AGENTS.md` and `CLAUDE.md`.

## Project Structure & Modules
- Root module: `github.com/satococoa/wtp/v2` (Go 1.24).
- CLI entrypoint: `cmd/wtp`.
- Internal packages: `internal/{git,config,hooks,command,errors,io,testutil}`.
- Tests: unit tests alongside packages (`*_test.go`), end-to-end tests in `test/e2e`.
- Tooling/config: `.golangci.yml`, `.goreleaser.yml`, `Taskfile.yml`, `.wtp.yml` (project hooks), `docs/`.

## Build, Test, and Dev Commands
- Build: `go tool task build` (or `task build`) → outputs `./wtp`.
- Install: `go tool task install` → installs to `GOBIN`/`GOPATH/bin`.
- Test (unit + race + coverage): `go tool task test` → writes `coverage.out`.
- Lint: `go tool task lint` (golangci-lint).
- Format: `go tool task fmt` (golangci-lint fmt → gofmt + goimports).
- E2E tests: `go tool task test-e2e` (uses built binary; override with `WTP_E2E_BINARY=/abs/path/wtp`).
- Direct build (no Task): `go build -o wtp ./cmd/wtp`.
- Dev cycle: `go tool task dev` (runs clean, fmt, lint, test, build).

## Coding Style & Naming
- Follow standard Go style (tabs, gofmt) and idioms; package names are short and lowercase.
- Imports: keep groups tidy; `goimports` organizes, local prefix follows module path.
- Linting: adhere to rules in `.golangci.yml` (vet, staticcheck, gosec, mnd, lll=120, etc.).
- Errors: wrap with context; avoid ignoring errors.
- Files/identifiers: `snake_case.go`, exported items documented when non-trivial.

## Commit & PR Guidelines
- Conventional Commits: `feat:`, `fix:`, `docs:`, `refactor:`, `test:`, `chore:`, `style:` (see `git log`).
- Branch naming: `feature/...`, `fix/...`, `hotfix/...` aligns with worktree paths.
- Before opening a PR: format, lint, tests green, update docs if needed.
- PR description: what/why/how, testing notes, related issues (e.g., `Closes #123`).
- Add CLI output or screenshots when UX changes.

## Security & Configuration Tips
- Project hooks are defined in `.wtp.yml`. Keep commands deterministic and safe; avoid destructive steps by default.
- Do not commit secrets; use example files (e.g., `.env.example`) and copy in hooks.

## TDD Workflow
### Development Cycle Expectations
- Run `go tool task dev` before committing; it runs clean, fmt, lint, test, and build.
- Keep the repository in a buildable state; never commit failing tests or lint errors.
- Update README/CLI help when user-facing behavior changes.

### RED → GREEN → REFACTOR Example
1. **RED**: write an end-to-end or unit test that captures the desired behavior. Example: add a failing E2E test for `wtp prune` that asserts a detached worktree is removed.
2. **GREEN**: implement the minimum code to satisfy that test. Keep the change small and focused on the behavior under test.
3. **REFACTOR**: clean up duplication, rename helpers, and harden edge cases while keeping tests green.

### Quick Testing Tips
- Use `go run ./cmd/wtp <args>` for rapid feedback instead of building binaries.
- Run commands from inside a worktree to mimic real usage (e.g., `go run ../cmd/wtp add feature/new-feature`).

### Testing Strategy
- Unit tests target 70% of coverage: fast feedback, mocked git interactions, table-driven cases.
- E2E tests cover 30%: real git workflows in `test/e2e` exercising command plumbing.
- See `docs/testing-guidelines.md` for extended advice on fixtures, naming, and reliability.

### Guidelines for New Commands
- Start with tests: design executor behavior through failing tests.
- Prefer existing command builders; add new ones when patterns diverge.
- Mock git operations in unit tests; rely on E2E suites for real git interactions.
- Document new workflows with realistic scenarios in `test/e2e`.

## Core Design Decisions
### Why Go Instead of Shell Script?
1. **Cross-platform compatibility**: native support for Windows without WSL.
2. **Better error handling**: types and structured errors instead of brittle shell parsing.
3. **Unified shell completion**: one implementation for all supported shells.
4. **Easier testing**: standard Go testing beats shell-script harnesses.
5. **Single binary distribution**: simplifies packaging for brew, scoop, etc.

### Configuration Format (Why YAML?)
- Human-readable and writable.
- Expressive enough for arrays, maps, and nested structures used by hooks.
- Well-supported in the Go ecosystem.
- Familiar syntax for developers accustomed to CI/CD tooling.

### Hook System Design
- Post-create hooks handle both file copying (e.g., `.env`) and command execution.
- Captures the common 90% of project bootstrap needs without over-engineering.
- Hooks are declared in `.wtp.yml`, keeping repository-specific automation explicit.

### Worktree Naming Convention
1. **Main worktree**: always rendered as `@`.
2. **Non-main worktrees**: display the path relative to `base_dir` (e.g., `.worktrees/feat/hoge` → `feat/hoge`).
3. **Fallback**: directory name is used if path resolution fails so that UX remains consistent.

**Implementation Notes**
- `getWorktreeNameFromPath()` in `cmd/wtp/remove.go` resolves display names.
- Shared across shell completion, user-facing errors, and command parsing.
- Ensures commands such as `wtp remove feat/foo` and `wtp cd feat/foo` share the same identifier.

## Shell Integration Architecture (v1.2.0)
### "Less is More" Approach
- Completion and shell integration are separated for clarity and maintainability.
- Homebrew and direct installs can compose the pieces they need.

### Command Structure
- **`wtp cd <worktree>`**: outputs the absolute worktree path with no side effects.
- **`wtp completion <shell>`**: generates pure completion scripts via `urfave/cli`.
- **`wtp hook <shell>`**: emits shell functions that intercept `wtp cd` for seamless navigation (bash, zsh, fish).
- **`wtp shell-init <shell>`**: convenience command that combines completion and hook output.

### User Experience Matrix
| Installation Method | Tab Completion | cd Functionality |
|---------------------|----------------|------------------|
| Homebrew | Automatic | `eval "$(wtp hook <shell>)"` |
| `go install` | `eval "$(wtp completion <shell>)"` | `eval "$(wtp hook <shell>)"` |

### Migration Notes
- `wtp cd` no longer depends on `WTP_SHELL_INTEGRATION=1`; the command itself only prints paths.
- Existing completion scripts from v1.1.x still work but omit cd helpers unless users add hooks.
- Future Homebrew enhancements may lazy-load integration by wrapping `wtp shell-init` on first use.

## Additional References
- Architecture overview: `docs/architecture.md`.
- Testing deep dive: `docs/testing-guidelines.md`.
# AGENTS

`wtp` is a Go CLI that simplifies `git worktree` workflows for creating, listing, moving, and removing worktrees.

## Essentials
- Toolchain: Go 1.24
- Package manager: Go modules (`go`)
- Project task runner: `go tool task`
- Non-standard project commands:
- `go tool task build`
- `go tool task test`
- `go tool task lint`
- `go tool task fmt`
- `go tool task test-e2e`
- `go tool task dev`

## Docs
- [Dev commands](docs/agents/dev-commands.md)
- [Code and tests](docs/agents/code-and-tests.md)
- [Workflow](docs/agents/workflow.md)
- [Architecture](docs/architecture.md)
Copy link

Copilot AI Feb 11, 2026

Choose a reason for hiding this comment

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

Several important sections from the original AGENTS.md are not present in the new modular documentation:

  1. Core Design Decisions (Why Go vs Shell, Configuration format, Hook system design, Worktree naming convention) - This provides valuable context for understanding architectural choices
  2. Shell Integration Architecture (v1.2.0 details about command structure and user experience matrix) - Important for understanding the shell integration design
  3. Project Structure & Modules - Helps contributors understand the codebase organization

Consider either:

  • Adding these sections to docs/architecture.md or a new docs/agents/design-decisions.md file
  • Or documenting in the PR description why these sections are intentionally removed (if they're outdated or no longer needed)

The refactoring should preserve important historical and architectural context that helps contributors understand the "why" behind implementation choices.

Suggested change
- [Architecture](docs/architecture.md)
- [Architecture](docs/architecture.md)
- Core design decisions (e.g., Go vs shell, configuration format, hook system design, worktree naming convention)
- Shell integration architecture (including v1.2.0 command structure and user experience matrix)
- Project structure and modules (high-level overview of packages and responsibilities)

Copilot uses AI. Check for mistakes.
20 changes: 20 additions & 0 deletions docs/agents/code-and-tests.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Code and Tests

## Go Conventions
- Package names are short and lowercase.
- Keep imports tidy; rely on `goimports` with the module local prefix.
- Follow lint rules in `.golangci.yml`.
- Wrap errors with context; do not ignore errors.
- Use `snake_case.go` filenames.

## TDD Flow
1. RED: add a failing unit or E2E test for the behavior.
2. GREEN: implement the minimum change to pass.
3. REFACTOR: improve touched code while tests stay green.

## Testing Expectations
- Prefer unit tests for fast feedback (table-driven, mocked git interactions).
- Use E2E tests in `test/e2e` for real git workflow validation.
- Unit test naming: `TestFunction_Condition`.
- E2E naming: `TestUserAction_WhenCondition_ShouldOutcome`.
Copy link

Copilot AI Feb 11, 2026

Choose a reason for hiding this comment

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

The testing guidance is significantly reduced compared to the deleted testing-guidelines.md. The existing E2E tests follow detailed conventions (Given-When-Then structure, User Stories, Business Value documentation) that are no longer documented anywhere. Consider adding a reference to at least one example test that demonstrates the expected E2E test structure, or include key points about:

  • Test pyramid ratios (70% unit, 30% E2E)
  • E2E tests requiring Given-When-Then comments and business value documentation
  • Unit tests avoiding excessive documentation
  • When to use table-driven tests

Without this guidance, future contributors may not understand why existing E2E tests have extensive documentation or how to write new tests consistently.

Suggested change
- Prefer unit tests for fast feedback (table-driven, mocked git interactions).
- Use E2E tests in `test/e2e` for real git workflow validation.
- Unit test naming: `TestFunction_Condition`.
- E2E naming: `TestUserAction_WhenCondition_ShouldOutcome`.
- Aim for a test pyramid of roughly **70% unit tests** and **30% E2E** by count.
- Prefer unit tests for fast feedback (table-driven where it reduces duplication, mocked git interactions).
- Use E2E tests in `test/e2e` for real git workflow validation; use existing tests there as examples of structure and documentation.
- Unit test naming: `TestFunction_Condition`.
- E2E naming: `TestUserAction_WhenCondition_ShouldOutcome`.
- E2E tests must document:
- a short “Business value” / user story comment explaining why the flow matters, and
- Given / When / Then comments that outline the scenario steps.
- Keep unit tests focused and readable; avoid extensive prose documentation unless the behavior is unusually subtle.
- Use table-driven tests when validating multiple input/output combinations or edge cases for the same behavior; prefer simple tests for one-off scenarios.

Copilot uses AI. Check for mistakes.
- Update README or CLI help when user-facing behavior changes.
18 changes: 18 additions & 0 deletions docs/agents/dev-commands.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Dev Commands

Use Task commands as the default interface for local development.

- Build: `go tool task build`
- Install: `go tool task install`
- Test: `go tool task test`
- Lint: `go tool task lint`
- Format: `go tool task fmt`
- E2E: `go tool task test-e2e`
- Full local check: `go tool task dev`

Fast feedback loop:
- `go run ./cmd/wtp <args>`

Notes:
- `go tool task test` writes `coverage.out`.
- `go tool task test-e2e` uses the built binary and supports `WTP_E2E_BINARY=/abs/path/wtp`.
13 changes: 13 additions & 0 deletions docs/agents/workflow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Workflow

## Git and PR
- Conventional Commits: `feat:`, `fix:`, `docs:`, `refactor:`, `test:`, `chore:`, `style:`.
- Branch naming: `feature/...`, `fix/...`, `hotfix/...`.
- Before opening a PR, run: format, lint, tests.
- Include test notes and related issues in PR descriptions (for example `Closes #123`).
- Add CLI output or screenshots when UX changes.

## Config and Secrets
- Project hooks are defined in `.wtp.yml`.
- Never commit secrets.
- Prefer example files (for example `.env.example`) for hook-based setup.
Loading
Loading