AGENTS.md
AGENTS.mdAGENTS.mdroot
Quality
96/100
Scores the file, not the repository.Length
806 words
20 headings · 9 code blocksRepository
46k
— · pushed 0 days agoLast changed
3 days ago
First indexed 3 days ago.1# AGENTS.md23This is the GitHub CLI (`gh`), a command-line tool for interacting with GitHub. The module path is `github.com/cli/cli/v2`.45## Security Disclosures67**Never** post security-related content - vulnerabilities, exploits, proofs of concept, or attack details - in any issue, pull request, comment, commit, or discussion. Stop and file a security advisory per [`.github/SECURITY.md`](.github/SECURITY.md).89## Build, Test, and Lint1011```bash12make # Build (Unix) — outputs bin/gh13go run script/build.go # Build (Windows)14go test ./... # All unit tests15go test ./pkg/cmd/issue/list/... -run TestIssueList_nontty # Single test16go test -tags acceptance ./acceptance # Acceptance tests17make lint # golangci-lint (same as CI)18```1920**Before committing, ensure both tests and linter pass:**21```bash22go test ./...23make lint24```2526## Architecture2728Entry point: `cmd/gh/main.go` → `internal/ghcmd.Main()` → `pkg/cmd/root.NewCmdRoot()`.2930Key packages:31- `pkg/cmd/<command>/<subcommand>/` — CLI command implementations32- `pkg/cmdutil/` — Factory, error types, flag helpers (`NilStringFlag`, `NilBoolFlag`, `StringEnumFlag`)33- `pkg/iostreams/` — I/O abstraction with TTY detection, color, pager34- `pkg/httpmock/` — HTTP mocking for tests35- `api/` — GitHub API client (GraphQL + REST)36- `internal/featuredetection/` — GitHub.com vs GHES capability detection37- `internal/tableprinter/` — Table output for list commands3839## Command Structure4041A command `gh foo bar` lives in `pkg/cmd/foo/bar/` with `bar.go`, `bar_test.go`, and optionally `http.go`/`http_test.go`.4243### Canonical Examples4445- **Command + tests**: `pkg/cmd/issue/list/list.go` and `list_test.go`46- **Factory wiring**: `pkg/cmd/factory/default.go`47- **Unit tests**: `internal/agents/detect_test.go`4849### The Options + Factory Pattern5051Every command follows this structure (see `pkg/cmd/issue/list/list.go`):52531. `Options` struct with `IO`, `HttpClient`, `Config`, `BaseRepo` + flags542. `NewCmdFoo(f *cmdutil.Factory, runF func(*FooOptions) error)` constructor — `runF` is the test injection point553. Separate `fooRun(opts)` function with the business logic5657Key rules:58- Lazy-init `BaseRepo`, `Remotes`, `Branch` inside `RunE`, not the constructor59- Commands register in `pkg/cmd/root/root.go`; subcommand groups use `cmdutil.AddGroup()`6061### Command Examples and Help Text6263Use `heredoc.Doc` for examples with `#` comment lines and `$ ` command prefixes:64```go65Example: heredoc.Doc(`66 # Do the thing67 $ gh foo bar --flag value68`),69```7071### JSON Output7273Add `--json`, `--jq`, `--template` flags via `cmdutil.AddJSONFlags(cmd, &opts.Exporter, fieldNames)`. In the run function: `if opts.Exporter != nil { return opts.Exporter.Write(opts.IO, data) }`. See `pkg/cmd/pr/list/list.go`.7475## Testing7677Test architecture for commands should generally follow this pattern:7879- One table test for the command constructor (`NewCmdFoo`) to verify flag parsing and `Opts` curation.80- One table test for the run function (`fooRun`) to verify business logic, output, and mocked HTTP/Git interactions.8182### HTTP Mocking8384Use `httpmock.Registry` with `defer reg.Verify(t)` to ensure all stubs are called:8586```go87reg := &httpmock.Registry{}88defer reg.Verify(t)8990reg.Register(91 httpmock.REST("GET", "repos/OWNER/REPO"),92 httpmock.JSONResponse(someData),93)94reg.Register(95 httpmock.GraphQL(`query PullRequestList\b`),96 httpmock.FileResponse("./fixtures/prList.json"),97)98client := &http.Client{Transport: reg}99```100101Common: `REST(method, path)`, `GraphQL(pattern)`, `JSONResponse(body)`, `FileResponse(path)`. See `pkg/httpmock/` for all matchers/responders.102103### IOStreams in Tests104105```go106ios, stdin, stdout, stderr := iostreams.Test()107ios.SetStdoutTTY(true) // simulate terminal108```109110### Assertions111112Use `testify`. Always use `require` (not `assert`) for error checks so the test halts immediately:113114```go115require.NoError(t, err)116require.Error(t, err)117assert.Equal(t, "expected", actual)118```119120### Generated Mocks121122Interfaces use `moq`: `//go:generate moq -rm -out prompter_mock.go . Prompter`. Run `go generate ./...` after interface changes.123124### Table-Driven Tests125126Use table-driven tests for functions with multiple input/output scenarios. See `internal/agents/detect_test.go` or `pkg/cmd/issue/list/list_test.go` for examples:127128```go129tests := []struct {130 name string131 // inputs and expected outputs132}{133 {name: "descriptive case name", ...},134}135for _, tt := range tests {136 t.Run(tt.name, func(t *testing.T) {137 // arrange, act, assert138 })139}140```141142## Code Style143144- Add godoc comments to all exported functions, types, and constants145- Avoid unnecessary code comments — only comment when the *why* isn't obvious from the code146- Comments that imbue sanitized and summarized context from your conversation with a human are very valuable. For example, if you found during development that without the code something downstream would break, that's good context to include.147- Do not comment just to restate what the code does148- Never use em dashes (—) in code, comments, or documentation; use regular dashes (-) or rewrite the sentence instead149150## Error Handling151152Error types in `pkg/cmdutil/errors.go`:153- `FlagErrorf(...)` — flag validation (prints usage)154- `cmdutil.SilentError` — exit 1, no message155- `cmdutil.CancelError` — user cancelled156- `cmdutil.PendingError` — outcome pending157- `cmdutil.NoResultsError` — empty results158159Use `cmdutil.MutuallyExclusive("message", cond1, cond2)` for mutually exclusive flags.160161## Feature Detection162163Commands using feature detection must include a `// TODO <cleanupIdentifier>` comment directly above the if-statement for linter compliance:164165```go166// TODO someFeatureCleanup167if features.SomeCapability {168 // use new API169} else {170 // fallback for older GHES171}172```173174Use feature detection only when an API is not GA on all supported GHES versions; skip it for long-established APIs.175176## API Patterns177178```go179client := api.NewClientFromHTTP(httpClient)180client.GraphQL(hostname, query, variables, &data)181client.REST(hostname, "GET", "repos/owner/repo", nil, &data)182```183184For host resolution, use `cfg.Authentication().DefaultHost()`; do not use `ghinstance.Default()` which always returns `github.com`.185186Avoid extra round-trips.187188## Code Review189190Review pull requests with the [`cli-code-reviewer` skill](.github/skills/cli-code-reviewer/SKILL.md).191
Similar configs
Same format, overlapping stack, ranked by quality.
| Repository | Format | Stack | Covers | Score | Changed |
|---|---|---|---|---|---|
| trick77/agents-md-syncAGENTS.md · 2 | AGENTS.md | setupbuildteststyle+5 | 100/100 | 3 days ago | |
| SkeneTechnologies/skene-cookbookAGENTS.md · 51 | AGENTS.md | setupbuildtestlint-format+7 | 100/100 | 2 days ago | |
| duckduckgo/content-scope-scriptsspecial-pages/AGENTS.md · 70 | AGENTS.md | buildteststylearch+3 | 100/100 | 3 days ago | |
| wpscanteam/wpscanAGENTS.md · 9.7k | AGENTS.md | setupbuildteststyle+6 | 100/100 | 2 days ago | |
| OnlyTerp/prompt-cache-skillsAGENTS.md · 112 | AGENTS.md | setupbuildtestlint-format+5 | 100/100 | 3 days ago | |
| mui/material-uiAGENTS.md · 99k | AGENTS.md | setupbuildtestlint-format+9 | 100/100 | 3 days ago | |
| n8n-io/n8npackages/@n8n/agents/AGENTS.md · 199k | AGENTS.md | buildteststylearch+3 | 100/100 | 3 days ago | |
| aaif-goose/gooseAGENTS.md · 52k | AGENTS.md | setupbuildtestlint-format+6 | 100/100 | 3 days ago |
