|
| 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 | +toolhive-core is a shared Go library providing stable, well-tested utilities for the ToolHive ecosystem. It serves as a common dependency for toolhive, dockyard, toolhive-registry, and toolhive-registry-server projects. |
| 8 | + |
| 9 | +## Build and Development Commands |
| 10 | + |
| 11 | +This project uses [Task](https://taskfile.dev/) for automation: |
| 12 | + |
| 13 | +```bash |
| 14 | +task # Run all checks (lint + test) |
| 15 | +task lint # Run golangci-lint and go vet |
| 16 | +task test # Run tests with race detection |
| 17 | +``` |
| 18 | + |
| 19 | +Run a single test: |
| 20 | +```bash |
| 21 | +go test -race -run TestFunctionName ./path/to/package |
| 22 | +``` |
| 23 | + |
| 24 | +Other commands: |
| 25 | +```bash |
| 26 | +task lint-fix # Auto-fix linting issues |
| 27 | +task test-coverage # Run tests with coverage report |
| 28 | +task gen # Generate mocks using mockgen |
| 29 | +task tidy # go mod tidy && go mod verify |
| 30 | +task license-check # Verify SPDX license headers |
| 31 | +task license-fix # Add missing license headers |
| 32 | +``` |
| 33 | + |
| 34 | +## Development Workflow |
| 35 | + |
| 36 | +1. Implement changes with tests (≥70% coverage) |
| 37 | +2. Run `task` to verify lint + tests pass |
| 38 | +3. If adding mocks: add `//go:generate` directive, run `task gen` |
| 39 | +4. Run `task license-check` before committing |
| 40 | + |
| 41 | +## Boundaries |
| 42 | + |
| 43 | +### Never |
| 44 | +- Remove or skip existing tests |
| 45 | +- Change exported interface signatures without discussion |
| 46 | +- Modify `go.mod` dependencies without being asked |
| 47 | + |
| 48 | +### Ask First |
| 49 | +- Adding new packages (need to consider stability track) |
| 50 | +- Adding new dependencies |
| 51 | +- Changes to error codes in `httperr` |
| 52 | + |
| 53 | +### Always |
| 54 | +- Run `task` before considering work complete |
| 55 | +- Include table-driven tests for new functions |
| 56 | +- Use interface-based design for new packages (see `env.Reader` pattern) |
| 57 | + |
| 58 | +## Architecture |
| 59 | + |
| 60 | +### Package Design Principles |
| 61 | + |
| 62 | +1. **Interface-based design** - Public APIs expose interfaces for testability and mock generation |
| 63 | +2. **Dependency injection** - Enables mocking (see `env.Reader` interface pattern) |
| 64 | +3. **Error wrapping** - Uses Go 1.13+ error wrapping compatible with `errors.Is()` and `errors.As()` |
| 65 | +4. **Security-first validation** - All validators check for injection attacks (CRLF, control chars) and enforce length limits |
| 66 | + |
| 67 | +### Current Packages |
| 68 | + |
| 69 | +| Package | Purpose | |
| 70 | +|---------|---------| |
| 71 | +| `env` | Environment variable abstraction with `Reader` interface for testable code | |
| 72 | +| `httperr` | Wrap errors with HTTP status codes; use `WithCode()`, `Code()`, `New()` | |
| 73 | +| `validation/http` | RFC 7230/8707 compliant HTTP header and URI validation | |
| 74 | +| `validation/group` | Group name validation (lowercase alphanumeric, underscore, dash, space) | |
| 75 | + |
| 76 | +### Mock Generation |
| 77 | + |
| 78 | +Mocks are generated using `go.uber.org/mock`. Add `//go:generate` directives in source files, then run `task gen`. |
| 79 | + |
| 80 | +## Code Quality Notes |
| 81 | + |
| 82 | +- **Test coverage**: ≥70% required for package graduation |
| 83 | +- **License headers**: Run `task license-check` before committing to verify SPDX headers |
| 84 | + |
| 85 | +## Stability Guarantees |
| 86 | + |
| 87 | +Packages follow graduation tracks: |
| 88 | +- **Stable**: Production-ready, semantic versioning applies |
| 89 | +- **Beta**: API may change with deprecation notices |
| 90 | +- **Alpha**: Experimental, breaking changes possible |
0 commit comments