Development Setup Guide
This guide walks you through setting up a development environment for contributing to Terraphim AI, including code quality tools and pre-commit hooks.
Prerequisites
Required
- Git: Version control system
- Rust: Latest stable version via rustup
- Node.js: Version 18+ for desktop app development
- Yarn: Package manager for JavaScript dependencies
Optional but Recommended
- Pre-commit hook manager: One of the following:
- prek (Rust-based, no Python required)
- lefthook (Go-based, single binary)
- pre-commit (Python-based, original)
Quick Start
- Clone the repository:
- Install development dependencies:
# Install Rust dependencies
# Install desktop dependencies
- Set up code quality tools:
- Configure Git remotes (if working with private code):
# Add private repository remote
This script will automatically:
- Detect available hook managers (prek, lefthook, pre-commit)
- Install appropriate hooks
- Set up Biome for JavaScript/TypeScript formatting
- Create secrets detection baseline
- Install native Git hooks as fallback
- Set up branch protection validation
Pre-commit Hooks Overview
Our pre-commit hooks enforce code quality and security standards:
Code Quality Checks
- Rust formatting:
cargo fmt --check - Rust linting:
cargo clippywith strict warnings - JavaScript/TypeScript: Biome for linting and formatting
- Trailing whitespace: Automatic removal
- File syntax: YAML, TOML, JSON validation
Security Checks
- Secret detection: Prevents accidental credential commits
- Private key detection: Blocks SSH keys and certificates
- Large file prevention: Stops accidental binary commits (>1MB)
Commit Standards
- Conventional commits: Enforces structured commit messages
- Message validation: Checks format and content
Branch Protection System
Terraphim AI uses a dual-repository approach with comprehensive branch protection:
Repository Structure
- Public Repository (
terraphim/terraphim-ai): Open-source code only - Private Repository (
zestic-ai/terraphim-private): Proprietary and sensitive code
Pre-Push Hook Protection
The repository includes a pre-push hook that automatically validates:
Branch Naming Validation
Blocked patterns (will be rejected):
Allowed patterns:
Content Validation
- Commit message scanning: Blocks
[PRIVATE],[INTERNAL],private:, etc. - Sensitive keyword detection: Scans for
truthforge,private.*cloud, etc. - File pattern validation: Uses
.gitprivateignorefor custom patterns
Working with Private Code
If you need to work with private or sensitive code:
- Switch to private repository:
- Create private branch:
- Develop and push normally:
- Switch back to public (when ready):
Troubleshooting Branch Protection
"Branch matches private pattern" Error
Solution:
# Configure branch for private remote
# Push to private repository
"Sensitive keyword found" Error
Solution:
- Remove or replace sensitive content
- Use private repository for sensitive development
- Update
.gitprivateignoreif false positive
For detailed information, see Branch Protection and Security.
Hook Manager Options
Option 1: prek (Recommended - No Python Required)
Installation:
# Linux/macOS
|
# Windows PowerShell
# Then install hooks
Features:
- Single binary, no dependencies
- ~10x faster than pre-commit
- Fully compatible with existing configurations
- Built in Rust
Option 2: lefthook (Go-based Alternative)
Installation:
# Install lefthook
|
# Or via Homebrew
# Install hooks
Features:
- Single binary (Go-based)
- Parallel hook execution
- YAML configuration
- Fast and lightweight
Option 3: pre-commit (Python-based Original)
Installation:
# Via pip
# Via Homebrew
# Install hooks
Features:
- Original and most mature
- Extensive plugin ecosystem
- Wide language support
- Requires Python runtime
Option 4: Native Git Hooks (Fallback)
If you prefer not to install additional tools, native Git hooks are automatically installed as a fallback:
# These are copied to .git/hooks/ by the install script
Manual Commands
Running Hooks Manually
# Run all pre-commit checks manually
# Check commit message format
# With hook managers:
Code Quality Commands
# Rust formatting
# Rust linting
# JavaScript/TypeScript (Biome)
Secret Detection
# Scan for secrets (if detect-secrets is available)
# Update baseline with new findings
Conventional Commits
We enforce Conventional Commits format:
Format
<type>(<scope>): <description>
<body>
<footer>Types
- feat: New feature
- fix: Bug fix
- docs: Documentation changes
- style: Code style changes (formatting, etc.)
- refactor: Code refactoring
- perf: Performance improvements
- test: Adding or updating tests
- chore: Maintenance tasks
- build: Build system changes
- ci: CI/CD changes
- revert: Reverting previous commits
Examples
Breaking Changes
For breaking changes, use:
feat!:orfix!:(with exclamation mark)- Or include
BREAKING CHANGE:in commit body
Biome Configuration
Biome is configured in desktop/biome.json with:
- Linting: TypeScript, JavaScript, and JSON files
- Formatting: Consistent code style
- Import sorting: Automatic import organization
- Performance: ~10x faster than ESLint + Prettier
Biome Commands
# Check and fix all issues
# Check without fixing
# Format only
# Lint only
IDE Integration
VS Code
Install these extensions for the best experience:
- rust-analyzer: Rust language support
- Biome: JavaScript/TypeScript formatting and linting
- Conventional Commits: Commit message assistance
Other IDEs
- Most editors support Rust via rust-analyzer
- Biome has plugins for major editors
- Git hooks work regardless of editor
Bypassing Hooks (Emergency Only)
Sometimes you need to bypass hooks for emergency commits:
# Skip all hooks
# Skip specific hook manager checks but keep native checks
SKIP=cargo-clippy Note: Use sparingly and fix issues in follow-up commits.
Troubleshooting
Common Issues
Hooks not running
# Check if hooks are installed
# Reinstall hooks
Biome not found
# or
Rust tools not available
# Install Rust
|
# Add required components
Permission denied on hooks
Secrets detection false positives
# Update baseline to ignore false positives
# Or edit .secrets.baseline manuallyGetting Help
-
Check hook manager documentation:
-
Run hooks manually to see detailed error messages
-
Check our development chat for community support
Contributing
When contributing to Terraphim AI:
- Fork the repository
- Create a feature branch:
git checkout -b feat/your-feature - Install development tools:
./scripts/install-hooks.sh - Make your changes: Code, test, commit with conventional format
- Push and create PR: Automated checks will run
Your commits will be automatically validated for:
- Code formatting and style
- Security vulnerabilities
- Conventional commit format
- Breaking changes detection
This ensures consistent code quality across all contributions!