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