Last Updated: 2025-10-17
CANARY is a requirement tracking system that embeds tokens directly into source code, enabling precise tracking of features, tests, and documentation. This guide walks you through installing CANARY, understanding core concepts, and using the system effectively for both AI agents and human developers.
What You'll Learn:
- Installing and initializing CANARY
- Understanding CANARY tokens and their lifecycle
- Core workflow: specify → plan → implement → verify
- Querying and inspecting implementation progress
- Maintaining documentation currency
- Go 1.20 or later installed
- Git repository for your project (recommended)
- Text editor or IDE
# Clone the repository
git clone https://github.com/yourusername/canary.git
cd canary
# Install the CLI
go install ./cmd/canary
# Verify installation
canary versioncanary --helpYou should see available commands including init, specify, plan, show, next, and more.
CANARY tokens are structured comments embedded in your code:
// CANARY: REQ=CBIN-105; FEATURE="Authentication"; ASPECT=API; STATUS=TESTED; UPDATED=2025-10-17Token Fields:
REQ- Requirement ID (format: CBIN-###)FEATURE- Short feature name (CamelCase, quoted)ASPECT- Architecture aspect (API, CLI, Engine, Storage, Docs, etc.)STATUS- Implementation status (STUB, IMPL, TESTED, BENCHED)TEST- Test function name (when STATUS=TESTED)BENCH- Benchmark function name (when STATUS=BENCHED)DOC- Documentation reference (type:path, e.g., user:docs/user/guide.md)DOC_HASH- SHA256 hash of documentation (first 16 chars)UPDATED- Last modification date (YYYY-MM-DD)OWNER- Owner/team identifier
Features follow a strict lifecycle:
STUB → IMPL → TESTED → BENCHED
- STUB: Not yet implemented (placeholder)
- IMPL: Implementation exists, tests missing
- TESTED: Implementation complete with passing tests
- BENCHED: Fully tested and performance benchmarked
CANARY organizes code by architectural aspects:
- API - Public interfaces, exported functions
- CLI - Command-line interfaces
- Engine - Core logic and algorithms
- Storage - Database, persistence layer
- Security - Authentication, authorization, encryption
- Docs - Documentation files
- Wire - Serialization, network protocols
- Planner - Planning and scheduling logic
- Bench - Performance benchmarks
- FrontEnd - User interface components
- Dist - Distribution and deployment
# Create project directory
mkdir my-app
cd my-app
# Initialize Go module
go mod init github.com/yourusername/my-app
# Initialize CANARY
canary init my-appWhat this creates:
my-app/
├── .canary/
│ ├── memory/
│ │ └── constitution.md # Project principles (empty template)
│ ├── templates/
│ │ ├── spec-template.md # Requirement specification template
│ │ └── plan-template.md # Implementation plan template
│ └── specs/ # Individual requirement directories
├── GAP_ANALYSIS.md # Requirement tracking
└── README.md # Project documentation
Before implementing features, define your project's governing principles:
# For AI agents (using slash commands)
/canary.constitution Create principles for test-first development and simplicity
# For human developers (manual creation)
# Edit .canary/memory/constitution.md with your team's principlesExample constitution.md:
# Project Constitution
## Article I: Test-First Imperative
All features SHALL be implemented using test-first development.
Tests MUST be written before implementation.
## Article II: Simplicity First
Prefer simple, direct solutions over complex abstractions.
Use Go standard library when possible.
## Article III: Documentation Currency
All TESTED features MUST have current documentation.
Documentation MUST be updated when behavior changes.Use the /canary.specify command (AI agents) or canary specify CLI to create structured requirements:
# AI agent approach
/canary.specify Add user authentication with JWT tokens and password hashing
# Human developer approach (interactive)
canary specify
# Follow prompts to create requirementThis creates a specification at .canary/specs/CBIN-001-user-authentication/spec.md with:
- Requirement ID (auto-generated)
- User stories
- Functional requirements
- Acceptance criteria
- Success metrics
- Dependencies and constraints
See Specification Modification Guide for detailed information.
Generate technical guidance for your requirement:
# AI agent approach
/canary.plan CBIN-001 Use bcrypt for password hashing, standard library JWT
# Human developer approach
canary plan CBIN-001This creates .canary/specs/CBIN-001-user-authentication/plan.md with:
- Technical approach
- File structure
- Token placement strategy
- Test plan
- Implementation checklist
Follow test-first development:
// internal/auth/auth_test.go
// CANARY: REQ=CBIN-001; FEATURE="Authentication"; ASPECT=Security; STATUS=STUB; UPDATED=2025-10-17
func TestCANARY_CBIN_001_Security_PasswordHashing(t *testing.T) {
password := "secure-password-123"
// Hash password
hashed, err := HashPassword(password)
if err != nil {
t.Fatalf("HashPassword failed: %v", err)
}
// Verify correct password
if !VerifyPassword(hashed, password) {
t.Error("VerifyPassword failed for correct password")
}
// Verify wrong password
if VerifyPassword(hashed, "wrong-password") {
t.Error("VerifyPassword succeeded for wrong password")
}
}Run tests (should fail):
go test ./internal/auth/
# Expected: FAIL (HashPassword and VerifyPassword don't exist yet)// internal/auth/auth.go
// CANARY: REQ=CBIN-001; FEATURE="Authentication"; ASPECT=Security; STATUS=IMPL; UPDATED=2025-10-17
package auth
import (
"golang.org/x/crypto/bcrypt"
)
// HashPassword generates a bcrypt hash for the given password.
func HashPassword(password string) (string, error) {
bytes, err := bcrypt.GenerateFromPassword([]byte(password), bcrypt.DefaultCost)
return string(bytes), err
}
// VerifyPassword checks if the password matches the hash.
func VerifyPassword(hash, password string) bool {
err := bcrypt.CompareHashAndPassword([]byte(hash), []byte(password))
return err == nil
}Run tests (should pass):
go test ./internal/auth/
# Expected: PASS// internal/auth/auth_test.go
// CANARY: REQ=CBIN-001; FEATURE="Authentication"; ASPECT=Security; STATUS=TESTED; TEST=TestCANARY_CBIN_001_Security_PasswordHashing; UPDATED=2025-10-17
func TestCANARY_CBIN_001_Security_PasswordHashing(t *testing.T) {
// ... test code ...
}// internal/auth/auth.go
// CANARY: REQ=CBIN-001; FEATURE="Authentication"; ASPECT=Security; STATUS=TESTED; TEST=TestCANARY_CBIN_001_Security_PasswordHashing; UPDATED=2025-10-17
package auth
// ... implementation ...Build the database for fast queries:
canary indexInspect your implementation:
# Show all tokens for CBIN-001
canary show CBIN-001
# List implementation files
canary files CBIN-001
# Check completion status
canary status CBIN-001See Query Commands Guide for detailed query capabilities.
Generate progress reports:
# Scan codebase for all tokens
canary scan --out status.json --csv status.csv
# Verify GAP_ANALYSIS.md claims
canary scan --verify GAP_ANALYSIS.mdCreate user documentation:
# Create documentation file
vim docs/user/authentication-guide.md
# Write comprehensive user guide...
# Update token with DOC field
# In your source file:
// CANARY: REQ=CBIN-001; FEATURE="Authentication"; ASPECT=Security; STATUS=TESTED; TEST=TestCANARY_CBIN_001_Security_PasswordHashing; DOC=user:docs/user/authentication-guide.md; UPDATED=2025-10-17
# Calculate and add hash
canary doc update --req CBIN-001 --feature Authentication
# Verify documentation status
canary doc status CBIN-001 Authentication
# Expected: DOC_CURRENTSee Documentation Tracking Guide for details.
AI agents can work independently using slash commands:
1. Agent completes current task
2. Agent runs: /canary.next
3. System returns next priority requirement with full guidance
4. Agent implements following test-first approach
5. Agent places CANARY tokens and updates status
6. Agent verifies with /canary.scan
7. Repeat from step 2
This creates a continuous implementation loop.
# Morning: Check what's next
canary next
# Review requirement
cat .canary/specs/CBIN-105-fuzzy-search/spec.md
# Get implementation guidance
canary next --prompt > implementation-guidance.md
# Implement following guidance
# ... write tests ...
# ... write implementation ...
# ... place tokens ...
# Verify progress
canary status CBIN-105
canary scan --verify GAP_ANALYSIS.md
# Check what's next
canary nextSee Next Priority Guide for advanced usage.
Search and update existing requirements:
# Search for authentication-related features
canary grep Authentication
# Find specific requirement
canary list --status IMPL | grep "Auth"
# Update existing specification
canary specify update CBIN-001
# Interactive prompts guide you through modificationSee Specification Modification Guide for details.
Get detailed guidance for specific requirements:
# Get full implementation prompt
canary implement CBIN-105
# Or use fuzzy matching
canary implement fuzzy
# Selects best match for "fuzzy" keywordSee Implement Command Guide for details.
CANARY provides four powerful query commands:
canary show CBIN-105Displays all tokens for a requirement with:
- Feature name
- Aspect
- Status
- File location and line number
- Test names
- Owner
canary files CBIN-105Shows which files contain implementations, grouped by aspect, with token counts.
canary status CBIN-105Displays:
- Total tokens
- Count by status (STUB, IMPL, TESTED, BENCHED)
- Completion percentage
- List of incomplete work
canary grep "FuzzyMatch"Searches across:
- Requirement IDs
- Feature names
- Aspects
- Owners
- Keywords
See Query Commands Guide for complete reference.
- Always start with constitution - Reference
.canary/memory/constitution.mdbefore implementing - Use test-first workflow - RED → GREEN → REFACTOR
- Update tokens immediately - Change STATUS as you progress
- Run /canary.next after each completion - Get next priority automatically
- Verify with /canary.scan - Ensure tokens are correctly placed
- Morning routine - Start with
canary nextto see priorities - Write tests first - Follow RED → GREEN → REFACTOR religiously
- Use query commands - Inspect progress with show/files/status
- Update UPDATED field - Change date when modifying implementations
- Document TESTED features - Add DOC= fields for completed work
- Verify regularly - Run
canary scan --verify GAP_ANALYSIS.md
- Establish constitution early - Define principles before implementing
- Use ASPECT consistently - Agree on aspect taxonomy
- Review token placement - Ensure tokens mark actual implementation locations
- Track documentation currency - Use DOC= and DOC_HASH= fields
- Automate scanning - Add
canary scanto CI/CD pipeline - Update priorities - Use
canary prioritizeto reflect changing needs
Problem: Marking STATUS=TESTED without TEST= field
Solution:
// Wrong
// CANARY: REQ=CBIN-105; FEATURE="Search"; ASPECT=API; STATUS=TESTED; UPDATED=2025-10-17
// Correct
// CANARY: REQ=CBIN-105; FEATURE="Search"; ASPECT=API; STATUS=TESTED; TEST=TestCANARY_CBIN_105_API_FuzzySearch; UPDATED=2025-10-17Problem: Documentation exists but hasn't been updated after code changes
Solution: Use documentation tracking:
canary doc status CBIN-105 Search
# Shows: DOC_STALE (hash mismatch)
# Update documentation, then:
canary doc update --req CBIN-105 --feature SearchProblem: Specification has tokens, implementation files don't
Solution: Place tokens at actual implementation locations:
// internal/search/fuzzy.go
// CANARY: REQ=CBIN-105; FEATURE="FuzzySearch"; ASPECT=Engine; STATUS=TESTED; TEST=TestFuzzyMatch; UPDATED=2025-10-17
func FuzzyMatch(pattern, text string) bool {
// Implementation...
}Problem: Forgetting to update UPDATED field when modifying code
Solution: Use automated staleness detection:
canary scan --update-stale
# Automatically updates UPDATED field for tokens older than 30 dayscanary show CBIN-999
# Error: no tokens found for CBIN-999Solutions:
- Verify requirement exists:
canary list | grep CBIN-999 - Check token format:
grep -r "CBIN-999" . - Rebuild database:
canary index
canary show CBIN-105
# Takes >1 secondSolutions:
- Check database exists:
ls .canary/canary.db - Rebuild index:
canary index - Check file count: Database is optimized for <10,000 files
canary doc status CBIN-105 Search
# Status: DOC_STALE (hash mismatch)Solutions:
- Verify documentation was updated:
git diff docs/user/search-guide.md - Recalculate hash:
canary doc update --req CBIN-105 --feature Search - Check for typos in DOC path
Define project-specific aspects in your constitution:
## Valid Aspects
- **CustomerAPI** - Customer-facing API endpoints
- **AdminAPI** - Administrative API endpoints
- **Reporting** - Report generation and analyticsUse consistently across all tokens.
Control implementation order:
// CANARY: REQ=CBIN-105; FEATURE="Search"; ASPECT=API; STATUS=STUB; PRIORITY=1; UPDATED=2025-10-17Lower numbers = higher priority. Use canary next to automatically select highest priority.
Express dependencies between requirements:
// CANARY: REQ=CBIN-106; FEATURE="AdvancedSearch"; ASPECT=API; STATUS=STUB; DEPENDS_ON=CBIN-105; UPDATED=2025-10-17canary next will automatically select CBIN-105 before CBIN-106.
Add to your GitHub Actions workflow:
name: CANARY Verification
on: [push, pull_request]
jobs:
verify:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup Go
uses: actions/setup-go@v4
with:
go-version: '1.20'
- name: Install CANARY
run: go install ./cmd/canary
- name: Verify requirements
run: canary scan --verify GAP_ANALYSIS.md --strict
- name: Check documentation currency
run: canary doc reportcanary init <project> # Initialize new CANARY project
canary index # Build/rebuild token database
canary list [flags] # List requirements with filtering
canary show <req-id> # Display all tokens for requirement
canary files <req-id> # List implementation files
canary status <req-id> # Show progress summary
canary grep <pattern> # Search tokens by pattern
canary next [flags] # Get next priority requirement
canary implement <req-id> # Get implementation guidance
canary specify [update] # Create/modify specifications
canary plan <req-id> # Generate implementation plan
canary scan [flags] # Scan for tokens and verify
canary doc status <req> <feat> # Check documentation currency
canary doc update [flags] # Update documentation hashes
canary doc report [flags] # Generate documentation report
canary prioritize <req> <pri> # Adjust requirement priority- Getting Started - This guide
- Query Commands Guide - show, files, status, grep
- Next Priority Guide - Automated workflow assistant
- Implement Command Guide - Implementation guidance
- Specification Modification Guide - Creating and updating specs
- Documentation Tracking Guide - DOC= and DOC_HASH= fields
.canary/
├── memory/
│ └── constitution.md # Project principles
├── templates/
│ ├── spec-template.md # Requirement template
│ └── plan-template.md # Implementation plan template
├── specs/
│ └── CBIN-XXX-feature/ # Individual requirements
│ ├── spec.md # Specification
│ └── plan.md # Implementation plan
└── canary.db # SQLite token database
GAP_ANALYSIS.md # Requirement tracking
CLAUDE.md # AI agent context
canary --help # General help
canary show --help # Command-specific help- README.md - Project overview
- CLAUDE.md - AI agent guide
- .canary/AGENT_CONTEXT.md - Complete agent context
- User Guides - All user documentation
- GitHub Issues: Report bugs and request features
- Discussions: Ask questions and share experiences
Now that you understand the basics:
- Initialize your project:
canary init my-project - Establish principles: Edit
.canary/memory/constitution.md - Create your first requirement: Use
/canary.specifyorcanary specify - Follow the workflow: specify → plan → implement → verify
- Explore query commands:
canary show,canary files,canary status - Use automated prioritization:
canary next
For AI Agents: Reference this guide alongside CLAUDE.md for complete context.
For Human Developers: Bookmark the Query Commands Guide and Next Priority Guide for daily use.
Happy tracking!
Last verified: 2025-10-17 with canary v0.1.0