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