CRUSH.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- **Lint**: `task lint` (golangci-lint run) or `task lint-fix` (with --fix)
 8- **Format**: `task fmt` (gofumpt -w .)
 9- **Dev**: `task dev` (runs with profiling enabled)
10
11## Code Style Guidelines
12
13- **Imports**: Use goimports formatting, group stdlib, external, internal packages
14- **Formatting**: Use gofumpt (stricter than gofmt), enabled in golangci-lint
15- **Naming**: Standard Go conventions - PascalCase for exported, camelCase for unexported
16- **Types**: Prefer explicit types, use type aliases for clarity (e.g., `type AgentName string`)
17- **Error handling**: Return errors explicitly, use `fmt.Errorf` for wrapping
18- **Context**: Always pass context.Context as first parameter for operations
19- **Interfaces**: Define interfaces in consuming packages, keep them small and focused
20- **Structs**: Use struct embedding for composition, group related fields
21- **Constants**: Use typed constants with iota for enums, group in const blocks
22- **Testing**: Use testify/assert and testify/require, parallel tests with `t.Parallel()`
23- **JSON tags**: Use snake_case for JSON field names
24- **File permissions**: Use octal notation (0o755, 0o644) for file permissions
25- **Comments**: End comments in periods unless comments are at the end of the line.
26
27## Testing with Mock Providers
28
29When writing tests that involve provider configurations, use the mock providers to avoid API calls:
30
31```go
32func TestYourFunction(t *testing.T) {
33    // Enable mock providers for testing
34    originalUseMock := config.UseMockProviders
35    config.UseMockProviders = true
36    defer func() {
37        config.UseMockProviders = originalUseMock
38        config.ResetProviders()
39    }()
40
41    // Reset providers to ensure fresh mock data
42    config.ResetProviders()
43
44    // Your test code here - providers will now return mock data
45    providers := config.Providers()
46    // ... test logic
47}
48```
49
50The mock providers include:
51- **Anthropic**: claude-3-opus, claude-3-haiku, claude-3-5-sonnet-20241022, claude-3-5-haiku-20241022
52- **OpenAI**: gpt-4, gpt-3.5-turbo, gpt-4-turbo, gpt-4o, gpt-4o-mini
53- **Gemini**: gemini-2.5-pro, gemini-2.5-flash
54
55## Formatting
56
57- ALWAYS format any Go code you write.
58  - First, try `goftumpt -w .`.
59  - If `gofumpt` is not available, use `goimports`.
60  - If `goimports` is not available, use `gofmt`.
61  - You can also use `task fmt` to run `gofumpt -w .` on the entire project,
62    as long as `gofumpt` is on the `PATH`.