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- **Pre-commit flow**: `task fmt lint-fix test`
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- **Comments**: End comments in periods unless comments are at the end of the line.
31
32## Testing with Mock Providers
33
34When writing tests that involve provider configurations, use the mock providers to avoid API calls:
35
36```go
37func TestYourFunction(t *testing.T) {
38 // Enable mock providers for testing
39 originalUseMock := config.UseMockProviders
40 config.UseMockProviders = true
41 defer func() {
42 config.UseMockProviders = originalUseMock
43 config.ResetProviders()
44 }()
45
46 // Reset providers to ensure fresh mock data
47 config.ResetProviders()
48
49 // Your test code here - providers will now return mock data
50 providers := config.Providers()
51 // ... test logic
52}
53```
54
55## Formatting
56
57- ALWAYS format any Go code you write.
58 - First, try `gofumpt -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`.
63
64## Comments
65
66- Comments that live on their own lines should start with capital letters and
67 end with periods. Wrap comments at 78 columns.
68
69## Committing
70
71- ALWAYS use semantic commits (`fix:`, `feat:`, `chore:`, `refactor:`, `docs:`, `sec:`, etc).
72- Try to keep commits to one line, not including your attribution. Only use
73 multi-line commits when additional context is truly necessary.