Thank you for your interest in contributing to TokenRouter! This document provides guidelines and instructions for contributing.
- Code of Conduct
- Getting Started
- Development Setup
- Making Changes
- Pull Request Guidelines
- Coding Standards
- Testing
- Documentation
Please read and follow our Code of Conduct to maintain a welcoming and inclusive community.
Click the "Fork" button on GitHub and clone your fork:
git clone https://github.com/YOUR_USERNAME/TokenRouter.git
cd TokenRouter# Install Go 1.21 or later
go version
# Install dependencies
go mod download
# Install development tools
make install-tools# Run all tests
make test
# Run specific test package
go test ./internal/chunker -v
# Run with coverage
go test ./... -coverprofile=coverage.out
go tool cover -html=coverage.out# Make sure you're on the main branch
git checkout dev
# Pull latest changes
git pull origin dev
# Create a feature branch
git checkout -b feature/your-feature-nameBranch naming conventions:
feature/- New featuresbugfix/- Bug fixesdocs/- Documentation changestest/- Test additions/updatesrefactor/- Code refactoringperf/- Performance improvements
Make your changes following our coding standards.
# Stage changes
git add .
# Commit with conventional commit message
git commit -m "feat: add your feature description"Commit message format:
<type>(<scope>): <subject>
<body>
<footer>
Types:
feat: New featurefix: Bug fixdocs: Documentationstyle: Formattingrefactor: Refactoringtest: Testschore: Maintenance
Example:
feat(cache): add cache optimization for tool blocks
- Implement alphabetical sorting of tools
- Add configuration option to disable sorting
- Update documentation
Closes #123
- Run all tests:
make test - Run linters:
make lint - Update documentation
- Add tests for new functionality
- Check for security issues
- Review your own code first
# Push your branch
git push origin feature/your-feature-name
# Then open a PR on GitHubUse the provided PR template and fill in all sections.
- Automated Checks: CI/CD will run tests and linters
- Code Review: Maintainers will review your code
- Address Feedback: Make requested changes
- Approval: Once approved, your PR will be merged
- Follow Effective Go
- Follow Go Code Review Comments
- Run
gofmtbefore committing - Use
golintfor linting
- Keep functions small and focused
- Use meaningful variable names
- Add comments for complex logic
- Avoid global variables
// Good
if err != nil {
return fmt.Errorf("failed to process request: %w", err)
}
// Bad
if err != nil {
log.Fatal(err) // Don't exit in library code
}// Use structured logging
logger.Infof("Request processed: model=%s, tokens=%d", model, tokens)
// Avoid
fmt.Println("Request processed") // Don't use fmt.Println for loggingMinimum coverage requirements:
- Chunker: 80%
- Arranger: 80%
- Canonicalizer: 100% (critical for correctness)
- Hasher: 80%
- Outbound Adapters: 70%
func TestMyFunction(t *testing.T) {
// Arrange
input := "test"
expected := "result"
// Act
result := MyFunction(input)
// Assert
if result != expected {
t.Errorf("expected %s, got %s", expected, result)
}
}# All tests
make test
# Specific package
go test ./internal/chunker -v
# With coverage
go test ./... -coverprofile=coverage.out
# View coverage
go tool cover -html=coverage.out- Exported functions should have doc comments
- Complex logic should be explained
- Include examples when helpful
When adding features, update:
- README.md - Usage examples
- docs/ - Technical documentation
- CODE_WIKI.md - API changes
- Use clear, concise language
- Include code examples
- Add diagrams when helpful
- Keep documentation in sync with code
If you have questions, please:
- Check existing issues
- Start a discussion
- Ask in the PR description
Your contributions make TokenRouter better for everyone. We appreciate your time and effort!