|
| 1 | +# AGENTS.md |
| 2 | + |
| 3 | +Guidance for agentic coding assistants working in `github.com/ncode/pretty`. |
| 4 | + |
| 5 | +## Quick Start for Agents |
| 6 | + |
| 7 | +Run these first from repo root: |
| 8 | + |
| 9 | +1. `go env -w GOTOOLCHAIN=go1.25.0+auto` |
| 10 | +2. `gofmt -w .` |
| 11 | +3. `go test -v ./...` |
| 12 | + |
| 13 | +When narrowing scope: |
| 14 | + |
| 15 | +- Single package: `go test -v ./internal/shell` |
| 16 | +- Single test: `go test -v ./internal/shell -run '^TestParseCommandAsync$'` |
| 17 | +- Subtest: `go test -v ./cmd -run '^TestParseHostSpec$/host_with_port$'` |
| 18 | + |
| 19 | +## Project Snapshot |
| 20 | + |
| 21 | +- Language: Go (`go 1.25` in `go.mod`) |
| 22 | +- Binary entrypoint: `main.go` |
| 23 | +- CLI layer: `cmd/` |
| 24 | +- Core packages: `internal/shell`, `internal/sshConn`, `internal/jobs` |
| 25 | +- Main user docs: `README.md` |
| 26 | + |
| 27 | +## Toolchain and Environment |
| 28 | + |
| 29 | +- Use Go 1.25. |
| 30 | +- Match CI behavior when possible: |
| 31 | + - `go env -w GOTOOLCHAIN=go1.25.0+auto` |
| 32 | +- A `Makefile` is provided. Run `make` to build, `make test` for tests, `make demo` for the full testbed workflow. |
| 33 | +- No dedicated linter config (`.golangci.yml`) is present. |
| 34 | + |
| 35 | +## Build / Lint / Test Commands |
| 36 | + |
| 37 | +Run from repository root. |
| 38 | + |
| 39 | +### Build |
| 40 | + |
| 41 | +- Build all packages: `go build -v ./...` |
| 42 | +- Build binary only: `go build -o pretty .` |
| 43 | + |
| 44 | +### Test (standard) |
| 45 | + |
| 46 | +- Full suite: `go test -v ./...` |
| 47 | +- Full suite with race detector: `go test -race ./...` |
| 48 | +- CI-like coverage command: |
| 49 | + - `go test -coverpkg=./... ./... -race -coverprofile=coverage.out -covermode=atomic` |
| 50 | + |
| 51 | +### Test (single package / file / test) |
| 52 | + |
| 53 | +- Single package: |
| 54 | + - `go test -v ./internal/shell` |
| 55 | +- Single test function: |
| 56 | + - `go test -v ./internal/shell -run '^TestParseCommandAsync$'` |
| 57 | +- Single test in another package: |
| 58 | + - `go test -v ./cmd -run '^TestParseHostSpec$'` |
| 59 | +- Subtest target (table-driven tests): |
| 60 | + - `go test -v ./cmd -run '^TestParseHostSpec$/host_with_port$'` |
| 61 | +- Repeat a flaky test deterministically: |
| 62 | + - `go test -v ./internal/sshConn -run '^TestResolveHostPatternMatchWildcard$' -count=1` |
| 63 | + |
| 64 | +### Lint / Static checks |
| 65 | + |
| 66 | +Because no project-specific linter config exists, use baseline Go checks: |
| 67 | + |
| 68 | +- Format check and rewrite: `gofmt -w .` |
| 69 | +- Vet all packages: `go vet ./...` |
| 70 | +- Optional stronger check (if installed): `staticcheck ./...` |
| 71 | + |
| 72 | +If a change touches many files, run at least: |
| 73 | + |
| 74 | +1. `gofmt -w .` |
| 75 | +2. `go test -v ./...` |
| 76 | + |
| 77 | +If concurrency/networking code changes, also run: |
| 78 | + |
| 79 | +3. `go test -race ./...` |
| 80 | + |
| 81 | +## Workflow Expectations for Agents |
| 82 | + |
| 83 | +- Prefer small, focused diffs. |
| 84 | +- Do not introduce new dependencies unless clearly necessary. |
| 85 | +- Preserve existing CLI behavior and command semantics. |
| 86 | +- Keep public behavior aligned with `README.md`. |
| 87 | +- Add or update tests when behavior changes. |
| 88 | + |
| 89 | +## Code Style Guidelines |
| 90 | + |
| 91 | +These reflect patterns already used in this repository. |
| 92 | + |
| 93 | +### Formatting and file layout |
| 94 | + |
| 95 | +- Always use `gofmt` formatting. |
| 96 | +- Keep package names short and lowercase; follow existing names (including `sshConn`). |
| 97 | +- Keep functions cohesive and avoid deep nesting. |
| 98 | +- Prefer early returns to reduce indentation. |
| 99 | + |
| 100 | +### Imports |
| 101 | + |
| 102 | +- Group imports in three blocks when needed: |
| 103 | + 1. Go standard library |
| 104 | + 2. Third-party libraries |
| 105 | + 3. Internal project imports (`github.com/ncode/pretty/...`) |
| 106 | +- Keep imports sorted as `gofmt` outputs. |
| 107 | +- Use import aliases only when needed for clarity or conflicts (for example `tea`, `homedir`). |
| 108 | + |
| 109 | +### Naming |
| 110 | + |
| 111 | +- Exported identifiers: PascalCase. |
| 112 | +- Unexported identifiers: camelCase. |
| 113 | +- Constants: |
| 114 | + - exported: PascalCase if part of API |
| 115 | + - internal/private: camelCase (`defaultPrompt`, `maxOutputLines`) |
| 116 | +- Test names: `TestXxx` with descriptive suffixes. |
| 117 | + |
| 118 | +### Types and data structures |
| 119 | + |
| 120 | +- Prefer concrete structs for domain state (`Manager`, `HostSpec`, `ResolvedHost`). |
| 121 | +- Use pointers for shared/mutable state. |
| 122 | +- Initialize slices/maps with capacity when size is known. |
| 123 | +- Keep zero-value behavior sensible. |
| 124 | + |
| 125 | +### Error handling |
| 126 | + |
| 127 | +- In library/internal packages: |
| 128 | + - return errors to caller |
| 129 | + - wrap with context using `%w` when rethrowing (`fmt.Errorf("...: %w", err)`). |
| 130 | +- In CLI command execution paths (`cmd/`), current pattern is: |
| 131 | + - print user-facing error |
| 132 | + - exit non-zero (`os.Exit(1)`). |
| 133 | +- Avoid panics for expected runtime errors. |
| 134 | + |
| 135 | +### Concurrency and synchronization |
| 136 | + |
| 137 | +- Guard shared mutable state with `sync.Mutex`/atomics as currently done. |
| 138 | +- Keep lock scope tight; avoid blocking operations while holding locks. |
| 139 | +- For goroutines in tests/helpers, use `t.Cleanup` to shut down resources. |
| 140 | + |
| 141 | +### Testing conventions |
| 142 | + |
| 143 | +- Prefer table-driven tests for parser/validation behavior. |
| 144 | +- Use `t.Run` with stable, descriptive case names. |
| 145 | +- Use `t.Helper()` in test helpers. |
| 146 | +- Use `t.Fatalf` for fatal assertions; include expected vs got details. |
| 147 | +- Prefer deterministic tests; avoid sleeps unless absolutely required. |
| 148 | + |
| 149 | +### Comments and docs |
| 150 | + |
| 151 | +- Add comments for non-obvious logic, invariants, or protocol details. |
| 152 | +- Do not add redundant comments that restate code. |
| 153 | +- Keep exported APIs understandable from names and function signatures. |
| 154 | + |
| 155 | +## Validation Checklist Before Finishing |
| 156 | + |
| 157 | +- Code is `gofmt`-formatted. |
| 158 | +- Relevant package tests pass. |
| 159 | +- Full `go test -v ./...` passes for non-trivial changes. |
| 160 | +- `go test -race ./...` run when touching concurrent code. |
| 161 | +- `README.md` updated if CLI behavior or config format changed. |
| 162 | + |
| 163 | +## Repository-Specific Rules Files |
| 164 | + |
| 165 | +Checked paths: |
| 166 | + |
| 167 | +- `.cursor/rules/` |
| 168 | +- `.cursorrules` |
| 169 | +- `.github/copilot-instructions.md` |
| 170 | + |
| 171 | +Current status in this repo: none of the above files exist. |
| 172 | + |
| 173 | +If any are added later, treat their guidance as authoritative and merge it into this document. |
0 commit comments