Validate Before Every Commit
Add validation to your pre-commit hook. Catch issues before they reach CI/CD.
The cortex-tms validate command performs automated health checks on your TMS project. It verifies file existence, schema compliance, size limits, placeholder completion, and archive status to ensure documentation matches reality.
cortex-tms validate [options]Zero-drift governance through automated validation. This command is the enforcement mechanism for TMS best practices, catching documentation drift before it becomes technical debt.
What it checks:
Typical workflow:
# Make changes to documentationvim NEXT-TASKS.md
# Validate before committingcortex-tms validate
# Fix any errors# ...
# Commit with confidencegit commit -am "docs: update sprint tasks"-s, --strictTreat warnings as errors and enable additional validation checks.
Standard mode (default):
Strict mode:
[Project Name])Example:
# Standard validation (warnings allowed)cortex-tms validate
# Strict validation (warnings = errors)cortex-tms validate --strictUse strict mode:
-v, --verboseShow detailed check information including passing checks.
Standard output (default):
Verbose output:
Example:
cortex-tms validate --verboseOutput comparison:
🔍 Cortex TMS Validation
✓ Running health checks...
📋 Mandatory Files ✓ NEXT-TASKS.md exists ✓ CLAUDE.md exists ✓ .github/copilot-instructions.md exists
📊 Summary Total Checks: 12 ✓ Passed: 12
✨ Validation passed! Your TMS project is healthy.🔍 Cortex TMS Validation
✓ Running health checks...
📋 Mandatory Files ✓ NEXT-TASKS.md exists /home/user/project/NEXT-TASKS.md ✓ CLAUDE.md exists /home/user/project/CLAUDE.md ✓ .github/copilot-instructions.md exists /home/user/project/.github/copilot-instructions.md
📏 File Size Limits (Rule 4) ✓ NEXT-TASKS.md under limit (185/200 lines) Current: 185 lines, Limit: 200 lines, Buffer: 15 lines ✓ copilot-instructions.md under limit (95/100 lines) Current: 95 lines, Limit: 100 lines, Buffer: 5 lines
🔧 Placeholder Completion ✓ No placeholders found in NEXT-TASKS.md ✓ No placeholders found in CLAUDE.md ✓ No placeholders found in copilot-instructions.md
📦 Archive Status ✓ NEXT-TASKS.md has no completed tasks requiring archive ✓ docs/archive/ directory exists
📊 Summary Total Checks: 12 ✓ Passed: 12
✨ Validation passed! Your TMS project is healthy.-f, --fixAuto-fix issues where possible (future feature for common problems).
What can be auto-fixed:
.gitkeep files in archive directoriesExample:
# Run validation and auto-fixcortex-tms validate --fixOutput:
🔍 Cortex TMS Validation
✓ Running health checks...✗ Placeholders found in NEXT-TASKS.md
🔧 Auto-fixing 1 issue(s)...
✓ Fixed: NEXT-TASKS.md Replaced [Project Name] with acme-api Replaced [Tech Stack] with Next.js 15
✨ Auto-fix complete! Re-running validation...
✓ All checks passedCheck: Required files exist in expected locations
Files checked:
NEXT-TASKS.md (HOT tier)CLAUDE.md (HOT tier).github/copilot-instructions.md (HOT tier).cortexrc (Configuration)Failure example:
✗ NEXT-TASKS.md not found
Recommendations: - Run `cortex-tms init` to create missing files - Check that you're in the project root directoryFix:
# Create missing files with initcortex-tms init
# Or manually createtouch NEXT-TASKS.mdCheck: .cortexrc exists and is valid JSON with required fields
Required fields:
{ "version": "2.6.0", "scope": "standard", "projectName": "acme-api", "createdAt": "2026-01-19T10:30:00.000Z"}Failure example:
✗ .cortexrc invalid Missing required field: scope
Recommendations: - Add "scope" field to .cortexrc - Valid scopes: nano, standard, enterprise, custom - Or run `cortex-tms init --force` to regenerateFix:
# Regenerate configurationcortex-tms init --force
# Or manually editvim .cortexrcCheck: HOT files respect size limits to preserve AI context budget
Limits:
| File | Max Lines | Rationale |
|---|---|---|
NEXT-TASKS.md | 200 | Current sprint only (1-2 weeks) |
.github/copilot-instructions.md | 100 | Critical rules only |
Failure example:
✗ NEXT-TASKS.md exceeds limit (245/200 lines)
Recommendations: - Archive completed tasks to docs/archive/sprint-YYYY-MM.md - Move backlog items to FUTURE-ENHANCEMENTS.md - Break large tasks into smaller incrementsFix strategies:
# Create archive directorymkdir -p docs/archive
# Move completed tasks to archive# Edit NEXT-TASKS.md and move ✅ tasks to:echo "# Sprint: User Auth (2026-01-15 to 2026-01-28)" > docs/archive/sprint-2026-01.mdecho "" >> docs/archive/sprint-2026-01.mdecho "✅ JWT token generation - Completed 2026-01-18" >> docs/archive/sprint-2026-01.md
# Remove completed tasks from NEXT-TASKS.mdvim NEXT-TASKS.md<!-- In NEXT-TASKS.md: KEEP ONLY CURRENT SPRINT -->## Active Sprint: User Authentication
**Why this matters**: Mobile app needs secure login
- [ ] JWT token generation- [ ] Token validation middleware
<!-- MOVE FUTURE WORK TO FUTURE-ENHANCEMENTS.md --><!-- In FUTURE-ENHANCEMENTS.md -->## Future: Analytics Dashboard
- [ ] User activity heatmap- [ ] Revenue charts- [ ] Engagement metrics
## Future: Email Notifications
- [ ] Welcome email flow- [ ] Password reset emails<!-- Bad: One huge task (50 lines of subtasks) -->- [ ] Build complete authentication system - Research JWT libraries - Design database schema - Implement signup endpoint - Implement login endpoint - Add password hashing - Create middleware - Write tests - ... (40+ more lines)
<!-- Good: Multiple focused tasks -->## Active Sprint: User Authentication
- [ ] JWT token generation (see PATTERNS.md#auth)- [ ] Token validation middleware- [ ] Refresh token rotation
## Next Sprint: Auth Enhancements
- [ ] Password reset flow- [ ] Email verification- [ ] OAuth integrationCheck: Production docs should not contain unreplaced placeholders
Placeholders detected (using [Bracket Syntax]):
[Project Name][Tech Stack][e.g., examples][Your description here][Briefly describe...]Failure example:
⚠ Placeholders found in production files: - CLAUDE.md:5 - [Project Name] - docs/core/ARCHITECTURE.md:12 - [Frontend Framework]
Recommendations: - Replace placeholders before committing - Use plain text for production docsFix:
# Manually replace placeholdersvim CLAUDE.md# Replace [Project Name] with "Acme API"
# Or use auto-fixcortex-tms validate --fixNote: Placeholders are expected in templates/ directory but forbidden in root documentation.
Check: Documentation links resolve to real files
Example links checked:
<!-- In docs/core/PATTERNS.md -->**Canonical Example**: `src/components/Button.tsx:15`
<!-- In NEXT-TASKS.md -->Follow patterns in `docs/core/PATTERNS.md#authentication`Validation:
src/components/Button.tsx existsdocs/core/PATTERNS.md existsFailure example:
✗ Broken link in docs/core/PATTERNS.md:42 Target: src/components/Button.tsx (not found)
Recommendations: - File moved? Update link to new location - File deleted? Remove link or document deprecationFix:
# Find where file movedgit log --follow src/components/Button.tsx
# Update link in PATTERNS.mdvim docs/core/PATTERNS.md# Change: src/components/Button.tsx# To: src/ui/components/Button.tsxCheck: Structured files follow expected formats
Required sections:
## Active Sprint: [Name]**Why this matters**: [Context]Valid format:
## Active Sprint: User Authentication
**Why this matters**: Mobile app needs secure API access
- [ ] JWT token generation- [ ] Token validation middleware- [x] Database schema for usersInvalid format (missing required sections):
## Tasks
- Implement auth- Add testsFailure example:
✗ NEXT-TASKS.md malformed Missing required section: ## Active Sprint Missing context: **Why this matters**
Recommendations: - Add sprint name with descriptive title - Add "Why this matters" to provide AI contextFix:
## Active Sprint: API Security Hardening
**Why this matters**: Penetration test revealed auth vulnerabilities
- [ ] Implement rate limiting- [ ] Add CSRF protection- [ ] Enable security headersRequired sections:
Valid format:
## Tech Stack
- Framework: Next.js 15- Database: PostgreSQL- ORM: Drizzle
## Critical Rules
- Never store secrets in localStorage- All API routes require authentication
## Read Order
1. NEXT-TASKS.md - Current sprint2. docs/core/PATTERNS.md - Code conventions3. docs/core/ARCHITECTURE.md - System designFailure example:
✗ copilot-instructions.md malformed Missing required section: ## Tech Stack
Recommendations: - Add tech stack section at top of file - List framework, database, key librariesCheck: Completed tasks are archived to COLD tier
Rules:
NEXT-TASKS.md triggers warningdocs/archive/sprint-YYYY-MM.mddocs/archive/ directory existsFailure example:
⚠ NEXT-TASKS.md has 15 completed tasks This exceeds the recommended limit of 10
Recommendations: - Archive completed tasks from NEXT-TASKS.md - Create docs/archive/sprint-2026-01.md if needed - Keep NEXT-TASKS.md focused on current sprintFix:
Create archive directory
mkdir -p docs/archiveCreate sprint archive file
vim docs/archive/sprint-2026-01.md# Sprint: User Authentication (2026-01-15 to 2026-01-28)
## Completed Tasks
✅ JWT token generation - Implemented RS256 signing - Added token refresh logic - Created middleware
✅ Database schema for users - Migration: 20260115_create_users_table.sql - Added indexes for email lookups
✅ Password hashing with bcrypt - Cost factor: 12 - Salting handled automaticallyRemove completed tasks from NEXT-TASKS.md
vim NEXT-TASKS.md# Delete all ✅ tasksRe-validate
cortex-tms validate| Code | Meaning | Scenario |
|---|---|---|
0 | Success | All checks passed |
1 | Failure | One or more checks failed |
Standard mode:
Strict mode (--strict):
Use in scripts:
cortex-tms validate --strictif [ $? -eq 0 ]; then echo "✅ Documentation valid, proceeding with deployment" npm run deployelse echo "❌ Documentation validation failed, aborting" exit 1fi# Quick check during developmentcortex-tms validate
# Detailed output for debuggingcortex-tms validate --verbose
# Strict enforcement (pre-commit)cortex-tms validate --strictname: Validate Documentation
on: pull_request: paths: - 'NEXT-TASKS.md' - 'docs/**' - '.github/copilot-instructions.md' - '.cortexrc'
jobs: validate: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4
- name: Setup Node.js uses: actions/setup-node@v4 with: node-version: '20'
- name: Install Cortex TMS
- name: Validate Documentation run: cortex-tms validate --strict
- name: Check File Sizes run: | NEXT_TASKS_LINES=$(wc -l < NEXT-TASKS.md) if [ $NEXT_TASKS_LINES -gt 200 ]; then echo "❌ NEXT-TASKS.md exceeds 200 lines" exit 1 fi echo "✅ File size checks passed"validate-docs: stage: test image: node:20 script: - cortex-tms validate --strict only: changes: - NEXT-TASKS.md - docs/** - .github/copilot-instructions.mdversion: 2.1
jobs: validate-docs: docker: - image: cimg/node:20.0 steps: - checkout - run: name: Install Cortex TMS - run: name: Validate Documentation command: cortex-tms validate --strict
workflows: version: 2 validate: jobs: - validate-docs: filters: branches: only: - main - develop# .husky/pre-commit or .git/hooks/pre-commit#!/bin/bash
echo "🔍 Validating documentation..."
# Run Cortex TMS validationcortex-tms validate --strict
if [ $? -ne 0 ]; then echo "❌ Documentation validation failed" echo "Fix errors above before committing" exit 1fi
echo "✅ Documentation validation passed"Install:
# Using Huskynpm install --save-dev huskynpx husky installnpx husky add .husky/pre-commit "cortex-tms validate --strict"
# Or manuallychmod +x .git/hooks/pre-commit# Run validation and auto-fixcortex-tms validate --fix
# Output shows what was fixed# 🔧 Auto-fixing 3 issue(s)...# ✓ Fixed: NEXT-TASKS.md (replaced placeholders)# ✓ Fixed: docs/archive/.gitkeep (created)# ✓ Fixed: CLAUDE.md (removed trailing whitespace)
# Re-validate to confirmcortex-tms validate --strictProblem: File has grown beyond 200 lines
Solution 1: Archive completed tasks
mkdir -p docs/archivevim docs/archive/sprint-2026-01.md# Copy completed tasks here, then delete from NEXT-TASKS.mdSolution 2: Move backlog to FUTURE-ENHANCEMENTS.md
vim FUTURE-ENHANCEMENTS.md# Move non-urgent tasks hereSolution 3: Break down large tasks
<!-- Instead of one 50-line task, create 5 smaller tasks -->Problem: Template placeholders not replaced during init
Solution:
# Auto-fix (if .cortexrc has project metadata)cortex-tms validate --fix
# Or manually replacevim NEXT-TASKS.md# Find: [Project Name]# Replace: Acme APIProblem: File was moved but documentation not updated
Solution:
# Find where file movedgit log --follow src/old/path.ts
# Update all referencesgrep -r "src/old/path.ts" docs/vim docs/core/PATTERNS.md# Update link to new pathProblem: Missing required sections
Solution:
<!-- Add required structure -->## Active Sprint: [Descriptive Name]
**Why this matters**: [Business/technical context]
- [ ] First task- [ ] Second taskProblem: More than 10 completed tasks in NEXT-TASKS.md
Solution:
# Create sprint archivemkdir -p docs/archivecat > docs/archive/sprint-2026-01.md << EOF# Sprint: User Authentication (2026-01-15 to 2026-01-28)
## Completed Tasks
✅ JWT token generation - Implemented RS256 signing✅ Token validation middleware - Added to Express pipeline✅ Refresh token rotation - httpOnly cookies with 7-day expiry
## Metrics
- Duration: 2 weeks- Velocity: 3 tasks completed- Team size: 2 developers
## Retrospective
**What went well**: Clear requirements, good test coverage**What to improve**: Better estimation for middleware complexityEOF
# Remove completed tasks from NEXT-TASKS.mdvim NEXT-TASKS.md# Delete all ✅ tasksPossible causes:
--strict levelSolution:
# Match CI behavior locallycortex-tms validate --strict
# Check for uncommitted filesgit status
# Standardize line endingsgit config core.autocrlf inputPossible causes:
Solution:
# Skip strict checks temporarilycortex-tms validate
# Check for large filesfind . -type f -size +1M
# Check for broken symlinksfind . -type l ! -exec test -e {} \; -printProblem: Legitimate bracket text flagged as placeholder
Example:
<!-- This is NOT a placeholder but gets flagged -->Use syntax: `git commit -m "[type]: message"`Solution:
<!-- Escape brackets or use different syntax -->Use syntax: `git commit -m "<type>: message"`Validate Before Every Commit
Add validation to your pre-commit hook. Catch issues before they reach CI/CD.
Use Strict Mode in CI
Always use --strict in production pipelines. Warnings in dev become errors in CI.
Archive Regularly
Don’t wait for validation to warn about file size. Archive completed tasks weekly.
Fix Auto-Fixable Issues
Run --fix flag for simple issues (placeholders, whitespace). Saves manual editing time.
Before marking a task as complete:
cortex-tms validate --strictAutomation: Add this checklist to your Definition of Done in NEXT-TASKS.md.
cortex-tms init --scope standardcortex-tms validate --strict
# Should show all checks passed# Fix any issues firstcortex-tms validate --fix
# Then view dashboardcortex-tms status# Validate current statecortex-tms validate
# Upgrade templatescortex-tms migrate --apply
# Re-validate after migrationcortex-tms validate --strictcortex-tms init - Initialize TMS (creates files to validate)cortex-tms status - View dashboard (uses validation for health)cortex-tms migrate - Upgrade templates (validate before/after)