AGENTS.md

 1# Crush Development Guide
 2
 3## Build/Test/Lint Commands
 4
 5- **Build**: `go build .` or `go run .`
 6- **Test**: `task test` or `go test ./...` (run single test: `go test ./internal/llm/prompt -run TestGetContextFromPaths`)
 7- **Update Golden Files**: `go test ./... -update` (regenerates .golden files when test output changes)
 8  - Update specific package: `go test ./internal/tui/components/core -update` (in this case, we're updating "core")
 9- **Lint**: `task lint:fix`
10- **Format**: `task fmt` (gofumpt -w .)
11- **Dev**: `task dev` (runs with profiling enabled)
12
13## Code Style Guidelines
14
15- **Imports**: Use goimports formatting, group stdlib, external, internal packages
16- **Formatting**: Use gofumpt (stricter than gofmt), enabled in golangci-lint
17- **Naming**: Standard Go conventions - PascalCase for exported, camelCase for unexported
18- **Types**: Prefer explicit types, use type aliases for clarity (e.g., `type AgentName string`)
19- **Error handling**: Return errors explicitly, use `fmt.Errorf` for wrapping
20- **Context**: Always pass context.Context as first parameter for operations
21- **Interfaces**: Define interfaces in consuming packages, keep them small and focused
22- **Structs**: Use struct embedding for composition, group related fields
23- **Constants**: Use typed constants with iota for enums, group in const blocks
24- **Testing**: Use testify's `require` package, parallel tests with `t.Parallel()`,
25  `t.SetEnv()` to set environment variables. Always use `t.Tempdir()` when in
26  need of a temporary directory. This directory does not need to be removed.
27- **JSON tags**: Use snake_case for JSON field names
28- **File permissions**: Use octal notation (0o755, 0o644) for file permissions
29- **Log messages**: Log messages must start with a capital letter (e.g., "Failed to save session" not "failed to save session")
30  - This is enforced by `task lint:log` which runs as part of `task lint`
31- **Comments**: End comments in periods unless comments are at the end of the line.
32
33## Testing with Mock Providers
34
35When writing tests that involve provider configurations, use the mock providers to avoid API calls:
36
37```go
38func TestYourFunction(t *testing.T) {
39    // Enable mock providers for testing
40    originalUseMock := config.UseMockProviders
41    config.UseMockProviders = true
42    defer func() {
43        config.UseMockProviders = originalUseMock
44        config.ResetProviders()
45    }()
46
47    // Reset providers to ensure fresh mock data
48    config.ResetProviders()
49
50    // Your test code here - providers will now return mock data
51    providers := config.Providers()
52    // ... test logic
53}
54```
55
56## Formatting
57
58- ALWAYS format any Go code you write.
59  - First, try `gofumpt -w .`.
60  - If `gofumpt` is not available, use `goimports`.
61  - If `goimports` is not available, use `gofmt`.
62  - You can also use `task fmt` to run `gofumpt -w .` on the entire project,
63    as long as `gofumpt` is on the `PATH`.
64
65## Comments
66
67- Comments that live on their own lines should start with capital letters and
68  end with periods. Wrap comments at 78 columns.
69
70## Committing
71
72- ALWAYS use semantic commits (`fix:`, `feat:`, `chore:`, `refactor:`, `docs:`, `sec:`, etc).
73- Try to keep commits to one line, not including your attribution. Only use
74  multi-line commits when additional context is truly necessary.
75
76## Working on the TUI (UI)
77Anytime you need to work on the tui before starting work read the internal/ui/AGENTS.md file