Guidance for coding agents working in github.com/algolia/cli.
- Applies to the whole repository.
- Prefer small, local changes over broad refactors.
- Follow existing Go + Cobra CLI patterns.
- Language: Go.
- Module:
github.com/algolia/cli. - Go version:
1.23.0; toolchain:go1.23.4. - Main binary entrypoint:
cmd/algolia/main.go. - Docs generator entrypoint:
cmd/docs/main.go. - Command tree:
pkg/cmd/....
- No
.cursor/rules/directory was found. - No
.cursorrulesfile was found. - No
.github/copilot-instructions.mdfile was found. - Use this file plus the existing codebase as the repo-specific source of truth.
- Preferred toolchain is listed in
devbox.json. - Common tools expected here:
go,task,golangci-lint,gofumpt,golines,gh,curl. - E2E tests require
ALGOLIA_APPLICATION_IDandALGOLIA_API_KEYin the environment or root.env.
Preferred:
task buildgo generate ./...
go build -ldflags "-s -w -X=github.com/algolia/cli/pkg/version.Version=main" -o algolia cmd/algolia/main.go
go build -v ./...task buildruns generation first.- CI also checks
go build -v ./....
All unit tests:
task test
go test ./...
go test ./... -p 1Single package / single test:
go test ./pkg/cmd/search
go test ./pkg/cmd/apikeys/list -run Test_runListCmd
go test ./pkg/cmd/apikeys/list -run 'Test_runListCmd/list_tty'
go test ./... -run Test_runListCmd
go test ./pkg/cmd/apikeys/list -run Test_runListCmd -v -count=1E2E tests:
task e2e
go test ./e2e -tags=e2e
go test ./e2e -tags=e2e -run TestIndices
go test ./e2e -tags=e2e -run TestAgentReady -v- E2E uses
github.com/cli/go-internal/testscript. - E2E makes real Algolia API requests.
- Keep E2E runs narrow when possible.
task lint
golangci-lint run
task format
gofumpt -w pkg cmd test internal api e2e
golines -w pkg cmd test internal api e2egosecgofumptstylecheck
go generate ./...
go run ./cmd/docs --app_data-path tmp
go run ./cmd/docs --app_data-path tmp --target newRun generation when changing generated flags or API-spec-derived code.
For substantial changes, prefer this order:
task format
go test ./path/to/touched/package -run TestName
task lint
task buildUse narrower verification for small edits.
- Add CLI commands under
pkg/cmd/<domain>. - Construct commands with
New...Cmdfunctions. - Keep option structs close to their commands.
- Inject dependencies via
*cmdutil.Factory. - Put shared command logic in focused helper packages, usually
pkg/cmdutil. - Keep docs-generation logic in
internal/docsandcmd/docs.
- Use standard Go grouping: stdlib, third-party, local module.
- Let
gofumpthandle ordering and spacing. - Avoid aliases unless they prevent collisions or materially improve clarity.
- Run
gofumpton all modified Go files. - Run
golinesif wrapping becomes awkward. - Preserve existing multiline layout for structs, literals, and signatures.
- Prefer explicit structs for command options and helper state.
- Keep exported APIs minimal.
- Use
anyonly where JSON-like dynamic values are genuinely needed.
- Exported names: PascalCase.
- Unexported names: camelCase.
- Command constructors:
NewXCmd. - Command runners:
runXCmd. - Match surrounding test naming, commonly
Test_runXCmd,TestNewXCmd, orTest_Feature.
- Use
RunE, notRun, for command handlers. - Validate args with
cobra.ExactArgs,cobra.MinimumNArgs, or repo validators. - Use
ValidArgsFunctionwhen completion helpers already exist. - Reuse
cmdutilhelpers for usage text, print flags, JSON flags, and validations. - Use heredocs for multiline examples and help text.
- Return errors instead of exiting except in true entrypoints like
main(). - Wrap with
%wwhen the original cause matters. - Use plain
return errwhen extra context adds no value. - Prefer actionable CLI-facing error messages.
- Use
cmdutil.FlagErrorffor invalid flag combinations and user input issues. - Stop progress indicators on all error paths after starting them.
- Use factory-provided
IOStreamsfor stdout, stderr, TTY checks, colors, and progress indicators. - Keep non-TTY output deterministic and script-friendly.
- Use structured output helpers for commands that support
--output. - Preserve dry-run behavior: validate, summarize, and avoid side effects.
- Read config through
config.IConfig. - Acquire API clients from injected functions like
SearchClientandCrawlerClient. - Do not hardcode credentials, hosts, or profile logic.
- Prefer table-driven tests for flags, output modes, and edge cases.
- Use
test.NewFactory(...)andtest.Execute(...)for command tests. - Stub API calls with
pkg/httpmock. - Use
assert/requirefromtestifyconsistently with nearby tests. - Use
t.Cleanup(...)for restoring globals. - For E2E, add new
txtarcases undere2e/testscripts/<area>and register them ine2e/e2e_test.go.
- Check for an existing helper before adding a new utility.
- If flag surfaces or generated spec flags change, run
go generate ./.... - If command help or command trees change, consider whether docs generation should be rerun.
- Add or update tests when behavior changes.
- Avoid unrelated formatting churn.