This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
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.
This project uses Task for automation:
task # Run all checks (lint + test)
task lint # Run golangci-lint and go vet
task test # Run tests with race detectionRun a single test:
go test -race -run TestFunctionName ./path/to/packageOther commands:
task lint-fix # Auto-fix linting issues
task test-coverage # Run tests with coverage report
task gen # Generate mocks using mockgen
task tidy # go mod tidy && go mod verify
task license-check # Verify SPDX license headers
task license-fix # Add missing license headers- Implement changes with tests (≥70% coverage)
- Run
taskto verify lint + tests pass - If adding mocks: add
//go:generatedirective, runtask gen - Run
task license-checkbefore committing
- Remove or skip existing tests
- Change exported interface signatures without discussion
- Modify
go.moddependencies without being asked
- Adding new packages (need to consider stability track)
- Adding new dependencies
- Changes to error codes in
httperr
- Run
taskbefore considering work complete - Include table-driven tests for new functions
- Use interface-based design for new packages (see
env.Readerpattern)
- Interface-based design - Public APIs expose interfaces for testability and mock generation
- Dependency injection - Enables mocking (see
env.Readerinterface pattern) - Error wrapping - Uses Go 1.13+ error wrapping compatible with
errors.Is()anderrors.As() - Security-first validation - All validators check for injection attacks (CRLF, control chars) and enforce length limits
| Package | Purpose |
|---|---|
cel |
Generic CEL expression compilation and evaluation (Alpha) |
env |
Environment variable abstraction with Reader interface for testable code |
httperr |
Wrap errors with HTTP status codes; use WithCode(), Code(), New() |
logging |
Pre-configured *slog.Logger factory with consistent ToolHive defaults (Alpha) |
oci/skills |
OCI artifact types, media types, and registry operations for ToolHive skills (Alpha) |
recovery |
HTTP panic recovery middleware (Beta) |
validation/http |
RFC 7230/8707 compliant HTTP header and URI validation |
validation/group |
Group name validation (lowercase alphanumeric, underscore, dash, space) |
Mocks are generated using go.uber.org/mock. Add //go:generate directives in source files, then run task gen.
- Test coverage: ≥70% required for package graduation
- License headers: Run
task license-checkbefore committing to verify SPDX headers
Packages follow graduation tracks:
- Stable: Production-ready, semantic versioning applies
- Beta: API may change with deprecation notices
- Alpha: Experimental, breaking changes possible