|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Project Overview |
| 6 | + |
| 7 | +Sentire is a CLI tool for the Sentry API written in Go, providing comprehensive access to Sentry's debugging data including complete stack traces, contexts, and event details. The tool features both 1:1 API mapping commands and user-friendly custom commands like `inspect` for parsing Sentry URLs. |
| 8 | + |
| 9 | +## Build and Development Commands |
| 10 | + |
| 11 | +```bash |
| 12 | +# Building |
| 13 | +make build # Standard build |
| 14 | +make build-release # Optimized build with stripped symbols |
| 15 | +go build -o sentire ./cmd/sentire # Direct go build |
| 16 | + |
| 17 | +# Testing |
| 18 | +make test # Run all tests |
| 19 | +make test-coverage # Run tests with HTML coverage report |
| 20 | +go test ./tests/ -v # Run tests with verbose output |
| 21 | +go test ./tests/inspect_test.go ./tests/events_test.go -v # Run specific test files |
| 22 | + |
| 23 | +# Development |
| 24 | +make fmt # Format all Go code |
| 25 | +make lint # Run golangci-lint (requires installation) |
| 26 | +make deps # Download and tidy dependencies |
| 27 | +make clean # Remove build artifacts |
| 28 | + |
| 29 | +# Cross-compilation |
| 30 | +make build-all # Build for Linux, macOS (Intel/ARM), and Windows |
| 31 | +``` |
| 32 | + |
| 33 | +## Code Architecture |
| 34 | + |
| 35 | +### Layer Structure |
| 36 | +- **`cmd/sentire/main.go`**: Entry point that calls CLI executor |
| 37 | +- **`internal/cli/`**: Cobra-based CLI commands and user interface |
| 38 | +- **`internal/api/`**: Sentry API method implementations (1:1 mapping) |
| 39 | +- **`internal/client/`**: HTTP client with auth, rate limiting, and pagination |
| 40 | +- **`pkg/models/`**: Comprehensive data models matching Sentry's API responses |
| 41 | +- **`tests/`**: Test suite with mock servers and integration tests |
| 42 | + |
| 43 | +### Key Design Patterns |
| 44 | + |
| 45 | +**CLI Command Registration**: Each command group (events, org, projects, inspect) has its own file in `internal/cli/` and registers with the root command via `init()` functions. |
| 46 | + |
| 47 | +**API Client Architecture**: The `internal/client/client.go` provides a base HTTP client that handles: |
| 48 | +- Bearer token authentication via `SENTRY_API_TOKEN` env var |
| 49 | +- Rate limit tracking from Sentry's response headers |
| 50 | +- Cursor-based pagination parsing from Link headers |
| 51 | +- Proper error handling with meaningful messages |
| 52 | + |
| 53 | +**Data Models**: The `pkg/models/` contain comprehensive structs that capture ALL available data from Sentry APIs: |
| 54 | +- **Event model**: Complete debugging data including stack traces, breadcrumbs, contexts, exceptions |
| 55 | +- **Issue model**: Enhanced with priority, substatus, culprit, ownership, and detailed metadata |
| 56 | +- **Project model**: All capability flags, insights flags, and configuration options |
| 57 | +- **Organization models**: Detailed statistics with category breakdowns |
| 58 | + |
| 59 | +### Special Features |
| 60 | + |
| 61 | +**Inspect Command**: Custom command (`internal/cli/inspect.go`) that parses Sentry URLs using regex to extract organization and issue ID, then automatically fetches the "recommended" event with full debugging context. |
| 62 | + |
| 63 | +**Pagination Handling**: Automatic pagination support with `--all` flag that continues fetching until all results are retrieved using cursor-based pagination. |
| 64 | + |
| 65 | +**Comprehensive Event Data**: Unlike many Sentry tools, this captures complete event data including stack frames with context lines, variable values, breadcrumbs trail, and all debugging contexts. |
| 66 | + |
| 67 | +## Authentication and Configuration |
| 68 | + |
| 69 | +Set `SENTRY_API_TOKEN` environment variable before using any commands. The client validates this on startup and provides clear error messages if missing. |
| 70 | + |
| 71 | +## Testing Strategy |
| 72 | + |
| 73 | +**Mock Server Testing**: Tests use `httptest.NewServer` to create mock Sentry API endpoints, allowing comprehensive testing without live API calls. |
| 74 | + |
| 75 | +**Integration Testing**: Tests verify complete request/response cycles including URL construction, header parsing, and JSON marshaling/unmarshaling. |
| 76 | + |
| 77 | +**Error Case Testing**: Comprehensive error handling tests for invalid URLs, missing authentication, API errors, and malformed responses. |
| 78 | + |
| 79 | +## Model Field Mapping |
| 80 | + |
| 81 | +When adding new API endpoints or updating existing ones, ensure data models capture ALL available fields from Sentry's API documentation. The project prioritizes completeness over simplicity - users should get access to all debugging data available through the API. |
| 82 | + |
| 83 | +Critical model components: |
| 84 | +- **Event.Entries**: Contains stack traces, exceptions, breadcrumbs |
| 85 | +- **Event.Contexts**: Browser, OS, runtime, device information |
| 86 | +- **Issue metadata**: Now uses `interface{}` to capture complex nested structures |
| 87 | +- **Project capability flags**: All `has*` and `hasInsights*` boolean flags |
| 88 | + |
| 89 | +## Output and User Experience |
| 90 | + |
| 91 | +All commands output JSON by default with proper indentation. The `inspect` command demonstrates the user-friendly approach - parse URLs that users commonly encounter (from Slack notifications, emails) and provide immediate access to debugging data. |
| 92 | + |
| 93 | +Commands follow the pattern: `./sentire <resource> <action> [args] [flags]` with the exception of the custom `inspect` command which prioritizes ease of use over API consistency. |
| 94 | + |
| 95 | +## New release |
| 96 | + |
| 97 | +When asked to create a new release please refer to @.opencode/agent/new-release.md |
0 commit comments