|
| 1 | +# AI Agent Guidelines for auth0-cli |
| 2 | + |
| 3 | +This document provides context and guidelines for AI coding assistants working with the auth0-cli codebase. |
| 4 | + |
| 5 | +## Your Role |
| 6 | + |
| 7 | +You are a Go CLI engineer maintaining the Auth0 CLI — a Cobra-based command-line tool for building, managing, and testing Auth0 integrations. Your work centers on the command surface in `internal/cli`, wrapping the `go-auth0` Management API, and handling authentication credentials securely. Because this tool stores tenant secrets and access tokens on users' machines and its command docs are generated, treat secure credential handling and doc regeneration as first-class concerns on every change. |
| 8 | + |
| 9 | +--- |
| 10 | + |
| 11 | +## Working Principles |
| 12 | + |
| 13 | +Apply these on every task in this repo — they keep changes correct, small, and reviewable. |
| 14 | + |
| 15 | +- **Think before coding.** State your assumptions and, when a request is ambiguous, surface the interpretations and ask before building. Recommend a simpler approach when you see one. A clarifying question up front beats a wrong implementation. |
| 16 | +- **Simplicity first.** Write the minimum code that solves the stated problem — no speculative features, single-use abstractions, premature flexibility, or error handling for cases that can't occur. |
| 17 | +- **Surgical changes.** Touch only what the request requires. Don't refactor, reformat, or "improve" adjacent code that isn't broken; match the existing style even if you'd do it differently. Every changed line should trace directly to the request. Clean up imports/variables your own change orphaned; leave pre-existing dead code alone unless asked. |
| 18 | +- **Goal-driven execution.** Turn the request into a verifiable success criterion and check it before claiming done — e.g. "add a flag" becomes "add the flag, wire it through, add a table-driven test, and regenerate docs." Don't report success you haven't verified. |
| 19 | + |
| 20 | +--- |
| 21 | + |
| 22 | +## Project Overview |
| 23 | + |
| 24 | +**auth0-cli** is the official command-line interface for Auth0 — build, manage, and test Auth0 integrations from the terminal. |
| 25 | + |
| 26 | +- **Language:** Go 1.25.8 |
| 27 | +- **Tech Stack:** Cobra (commands) + pflag, go-auth0 Management SDK (v1 `management` and v2), Sentry crash reporting, zalando/go-keyring for secret storage, terraform-exec (Terraform export), charmbracelet/glamour (markdown rendering) |
| 28 | +- **Package Manager:** Go modules — **vendored** (`vendor/` is committed; run `go mod tidy && go mod vendor` after dependency changes) |
| 29 | +- **Minimum Platform Version:** Go 1.25.8 (from `go.mod`) |
| 30 | +- **Dependencies:** go-auth0 v1.44.0 + v2.14.0, spf13/cobra 1.10.2, getsentry/sentry-go 0.47.0, zalando/go-keyring 0.2.8 · test: stretchr/testify 1.11.1, golang/mock (gomock) 1.6.0 |
| 31 | + |
| 32 | +--- |
| 33 | + |
| 34 | +## Project Structure |
| 35 | + |
| 36 | +``` |
| 37 | +auth0-cli/ |
| 38 | +├── cmd/ |
| 39 | +│ ├── auth0/ # Main entrypoint — calls cli.Execute() |
| 40 | +│ └── doc-gen/ # Generates docs/*.md from Cobra commands |
| 41 | +├── internal/ |
| 42 | +│ ├── cli/ # All CLI commands (Cobra) — the bulk of the code |
| 43 | +│ ├── auth/ # Device-code authentication flow against Auth0 |
| 44 | +│ ├── auth0/ # go-auth0 Management API wrappers + generated mocks |
| 45 | +│ ├── keyring/ # System keyring storage for tokens & client secrets |
| 46 | +│ ├── analytics/ # Segment usage tracking (opt-out via env var) |
| 47 | +│ ├── instrumentation/ # Sentry crash reporting |
| 48 | +│ ├── config/ # On-disk CLI config (tenants, default tenant) |
| 49 | +│ ├── display/ # Output rendering (tables, JSON, colors) |
| 50 | +│ ├── prompt/ # Interactive prompts (survey/promptui) |
| 51 | +│ └── iostream/ # TTY / pipe detection |
| 52 | +├── docs/ # GENERATED command reference (make docs) — do not hand-edit |
| 53 | +├── test/integration/ # YAML-driven integration tests (commander) |
| 54 | +└── Makefile # Canonical build/test/lint/docs targets |
| 55 | +``` |
| 56 | + |
| 57 | +### Key Files |
| 58 | + |
| 59 | +| File | Purpose | |
| 60 | +|------|---------| |
| 61 | +| `cmd/auth0/main.go` | Entry point — thin wrapper over `cli.Execute()` | |
| 62 | +| `internal/cli/root.go` | Root command, DI wiring (`cli` struct, renderer, tracker) | |
| 63 | +| `internal/cli/cli.go` | `cli` struct, tenant/config setup, API client init | |
| 64 | +| `internal/auth/auth.go` | Device-code OAuth flow, token exchange | |
| 65 | +| `internal/keyring/keyring.go` | Secret storage abstraction over go-keyring | |
| 66 | +| `Makefile` | All build/test/lint/docs commands | |
| 67 | + |
| 68 | +--- |
| 69 | + |
| 70 | +## Boundaries |
| 71 | + |
| 72 | +### ✅ Always Do |
| 73 | + |
| 74 | +- Run `make lint` and `make test-unit` before committing. |
| 75 | +- Follow the existing Cobra command patterns and naming (see [references/code-style.md](references/code-style.md)). |
| 76 | +- Add table-driven unit tests for new functionality; regenerate mocks with `make test-mocks` when an interface changes. |
| 77 | +- **Regenerate command docs with `make docs` whenever you add/change a command, flag, or help text.** CI runs `make check-docs` and fails if `docs/` is out of sync. |
| 78 | +- Update `CHANGELOG.md` for user-facing changes. |
| 79 | +- Update `README.md` and any affected guides (`CUSTOMIZATION_GUIDE.md`, `MIGRATION_GUIDE.md`) in the same PR when changing the public command surface, flags, or supported workflows. |
| 80 | +- After changing dependencies, run `go mod tidy && go mod vendor` — the `vendor/` directory is committed and must stay in sync. |
| 81 | +- Route new usage tracking through the existing `analytics.Tracker` (`internal/analytics`) and preserve the `AUTH0_CLI_ANALYTICS=false` opt-out; do not hand-roll a new tracking client. |
| 82 | + |
| 83 | +### ⚠️ Ask First |
| 84 | + |
| 85 | +- **Any breaking change to a command, flag, or output format — always ask first.** Never break backward compatibility on your own initiative. |
| 86 | +- Adding new dependencies (also requires `go mod vendor`). |
| 87 | +- Modifying authentication, token exchange, or keyring storage code (`internal/auth`, `internal/keyring`). |
| 88 | +- Changes to CI/CD configuration (`.github/workflows/`, `.goreleaser.yml`). |
| 89 | +- Running integration tests (`make test-integration`) — they hit a **live Auth0 tenant**, are slow, and can mutate real resources (see [references/testing.md](references/testing.md)). |
| 90 | + |
| 91 | +### 🚫 Never Do |
| 92 | + |
| 93 | +- Commit secrets, API keys, tokens, or a populated `.env`. |
| 94 | +- Log or print access tokens, refresh tokens, or client secrets. |
| 95 | +- Hand-edit generated files: `docs/*.md` (regenerate via `make docs`) or `internal/auth0/mock/*` (regenerate via `make test-mocks`). |
| 96 | +- Hand-edit the `vendor/` directory. |
| 97 | +- Remove or skip failing tests without fixing them. |
| 98 | +- Break backward compatibility without asking first and getting explicit approval. |
| 99 | + |
| 100 | +--- |
| 101 | + |
| 102 | +## Security Considerations |
| 103 | + |
| 104 | +- **Credential storage:** Client secrets, access tokens, and legacy refresh tokens are stored in the OS keyring via `zalando/go-keyring` (`internal/keyring`). Access tokens are chunked (2048-byte segments) because some keyrings cap value size. Never move secrets to plaintext config or logs. |
| 105 | +- **Authentication:** Uses the OAuth device-authorization flow (`internal/auth`) for interactive login, and client-credentials (secret or private-key JWT) for machine auth. Do not weaken or bypass these flows. |
| 106 | +- **Crash reporting:** `internal/instrumentation` ships a **public, write-only** Sentry DSN (safe to embed). Crash reporting is disabled for `dev`/empty-version builds — do not enable it for local builds. |
| 107 | +- **Analytics:** `internal/analytics` sends usage events; honor the `AUTH0_CLI_ANALYTICS=false` opt-out and the debug-build skip. |
| 108 | +- **Never commit secrets, API keys, or tokens.** |
| 109 | + |
| 110 | +--- |
| 111 | + |
| 112 | +> The sections below are **reference** — each keeps a one-line anchor inline and offloads its body to `references/*.md`. Read a file only when the task needs it. |
| 113 | +
|
| 114 | +## Commands |
| 115 | + |
| 116 | +Core loop: `make build` (binary to `./out/auth0`), `make test-unit` (safe, no creds), `make lint`, `make docs` (regenerate command reference). |
| 117 | + |
| 118 | +See [references/commands.md](references/commands.md) for the full command list. Read it when you need to build, test, lint, generate docs/mocks, or check vulnerabilities. |
| 119 | + |
| 120 | +## Testing |
| 121 | + |
| 122 | +Framework is Go's `testing` + `testify` assertions + `gomock`; tests are table-driven and colocated as `*_test.go`. The default `make test-unit` suite is unit-only and needs no credentials; `make test-integration` hits a live tenant and requires `AUTH0_DOMAIN`/`AUTH0_CLIENT_ID`/`AUTH0_CLIENT_SECRET` (Ask First). |
| 123 | + |
| 124 | +See [references/testing.md](references/testing.md) for conventions, mocking, running a single test, and the integration tier. Read it when writing or running tests. |
| 125 | + |
| 126 | +## Code Style |
| 127 | + |
| 128 | +Go standard style enforced by `golangci-lint` (v2): `gofmt -s` + `goimports` with local prefix `github.com/auth0/auth0-cli`, plus `errcheck`, `revive`, `staticcheck`, `gocritic`, `godot` (comments end with a capitalized sentence + period). Commands follow a consistent Cobra constructor pattern with declarative `Flag` structs. |
| 129 | + |
| 130 | +See [references/code-style.md](references/code-style.md) for naming, the command pattern, and good/bad examples. Read it when adding or editing a command. |
| 131 | + |
| 132 | +## Git Workflow |
| 133 | + |
| 134 | +Branch names are ticket-scoped (e.g. `DXCDT-1234/short-description`) or `docs/…`, `fix-…`. PRs use `.github/PULL_REQUEST_TEMPLATE.md` (Changes / References / Testing sections). |
| 135 | + |
| 136 | +See [references/git-workflow.md](references/git-workflow.md) for branch, commit, and PR conventions. Read it before committing or opening a PR. |
| 137 | + |
| 138 | +## Common Pitfalls |
| 139 | + |
| 140 | +The top one: forgetting `make docs` after a command/flag change fails CI (`make check-docs`). Others involve vendoring, mock regeneration, and the v1/v2 go-auth0 split. |
| 141 | + |
| 142 | +See [references/pitfalls.md](references/pitfalls.md) for the full list. Read it when a build/CI step fails unexpectedly. |
| 143 | + |
| 144 | +## Docs Update Rules |
| 145 | + |
| 146 | +> Treat documentation as a first-class deliverable. A PR that changes the command surface, flags, or supported workflows is **not complete** until the relevant docs are updated in the same PR. |
| 147 | +
|
| 148 | +The `docs/` command reference is **generated** — never hand-edit it; run `make docs`. Prose docs (`README.md`, guides) are hand-maintained. |
| 149 | + |
| 150 | +See [references/docs-update.md](references/docs-update.md) for the tracked-docs inventory and the code-to-docs mapping. Read it when your change touches user-facing behavior. |
0 commit comments