Health Registry System - Unified Specification v1.0
Status: AUTHORITATIVE - Supersedes VERSION-GUARD-SPEC.md and VERSION-GUARD-FINAL-DESIGN.md Created: 2025-12-20 Based on: 5 challenge agent analyses + sequential thinking synthesisExecutive Summary
This specification defines a comprehensive Health Registry System for cleo that goes beyond simple version guards to provide:- Central Project Registry - Track all initialized projects globally
- Health Monitoring - 36 checks across 6 dimensions with scoring
- LLM-Agent-First Design - JSON by default, structured errors, recovery hints
- Git Sync Support - Cross-machine identity via project UUID
Table of Contents
- Architecture Overview
- Central Project Registry
- Health Monitoring System
- Exit Code Taxonomy
- LLM-Agent-First Protocols
- Git Sync Support
- Implementation Roadmap
- Files to Create/Modify
1. Architecture Overview
What We’re Building
Design Principles
- Extend, Don’t Replace - Build on existing lib/validation.sh, not new files
- Performance First - head+grep for fast path, jq fallback for reliability
- LLM-Agent-First - JSON output by default, structured errors always
- Backward Compatible - Old projects work without modification
- Fail Safe - Warn by default for additive changes, block for breaking
2. Central Project Registry
Registry Schema
Location:~/.cleo/registry/registry.json
Project ID Generation
Deterministic SHA-256 hash of canonical absolute path, truncated to 12 hex chars:Project Identity (for Git Sync)
Each project gets a UUID stored in.cleo/project.json:
Registration Flow
Orphan Detection
Registry CLI Commands
3. Health Monitoring System
Health Dimensions (6 Categories, 36 Checks)
| Category | Weight | Description |
|---|---|---|
| Data Integrity (DI) | 40% | JSON validity, checksums, schema versions, required fields |
| Referential Integrity (RI) | 25% | Dependencies exist, parents exist, no orphans, no cycles |
| Semantic Integrity (SI) | 20% | Business rules (single active task, status consistency) |
| Session/Operational (SO) | 5% | Stale sessions, lock files, focus consistency |
| Backup Health (BH) | 5% | Recent backups exist, backup validation |
| Configuration Health (CH) | 5% | Config validity, version compatibility |
Complete Health Check Registry
Category 1: Data Integrity (DI) - 40% Weight
| ID | Check Name | Severity | Auto-Fix |
|---|---|---|---|
| DI-001 | JSON Syntax Valid | CRITICAL | NO |
| DI-002 | Checksum Verification | CRITICAL | SAFE |
| DI-003 | Config Version Match | CRITICAL | SAFE |
| DI-004 | Schema Version Compatible | CRITICAL | CONDITIONAL |
| DI-005 | Required Fields Present | CRITICAL | CONDITIONAL |
Category 2: Referential Integrity (RI) - 25% Weight
| ID | Check Name | Severity | Auto-Fix |
|---|---|---|---|
| RI-001 | Task ID Uniqueness | CRITICAL | NO |
| RI-002 | Dependency Exists | CRITICAL | CONDITIONAL |
| RI-003 | No Circular Dependencies | CRITICAL | NO |
| RI-004 | Parent Task Exists | CRITICAL | CONDITIONAL |
| RI-005 | Phase Slug Valid | WARNING | SAFE |
| RI-006 | Focus Task Exists | WARNING | SAFE |
| RI-007 | Labels Index Consistent | INFO | SAFE |
Category 3: Semantic Integrity (SI) - 20% Weight
| ID | Check Name | Severity | Auto-Fix |
|---|---|---|---|
| SI-001 | Single Active Task | WARNING | CONDITIONAL |
| SI-002 | Single Active Phase | WARNING | CONDITIONAL |
| SI-003 | Done Tasks Have completedAt | WARNING | SAFE |
| SI-004 | Blocked Tasks Have blockedBy | WARNING | NO |
| SI-005 | Active Phases Have startedAt | WARNING | SAFE |
| SI-006 | Completed Phases Have completedAt | WARNING | SAFE |
| SI-007 | Timestamp Ordering Valid | WARNING | CONDITIONAL |
| SI-008 | No Future Timestamps | WARNING | SAFE |
| SI-009 | Hierarchy Depth Valid | WARNING | NO |
| SI-010 | Sibling Count Valid | WARNING | NO |
| SI-011 | Status Transitions Valid | INFO | N/A |
| SI-012 | CurrentPhase Matches Active | WARNING | SAFE |
Category 4: Session/Operational (SO) - 5% Weight
| ID | Check Name | Severity | Auto-Fix |
|---|---|---|---|
| SO-001 | No Stale Sessions | WARNING | SAFE |
| SO-002 | Lock File Staleness | WARNING | SAFE |
| SO-003 | Focus Consistency | WARNING | SAFE |
| SO-004 | Session Note Present | INFO | NO |
| SO-005 | Last Session ID Valid | INFO | SAFE |
Category 5: Backup Health (BH) - 5% Weight
| ID | Check Name | Severity | Auto-Fix |
|---|---|---|---|
| BH-001 | Recent Backup Exists | WARNING | SAFE |
| BH-002 | Backup Directory Valid | INFO | SAFE |
| BH-003 | Migration Backups Preserved | INFO | SAFE |
| BH-004 | Backup Metadata Valid | INFO | CONDITIONAL |
| BH-005 | Backup Checksums Match | WARNING | CONDITIONAL |
| BH-006 | Safety Backups Not Expired | INFO | SAFE |
Category 6: Configuration Health (CH) - 5% Weight
| ID | Check Name | Severity | Auto-Fix |
|---|---|---|---|
| CH-001 | Config File Exists | WARNING | SAFE |
| CH-002 | Config Schema Valid | WARNING | NO |
| CH-003 | Config Version Current | INFO | CONDITIONAL |
| CH-004 | Validation Settings Sane | INFO | NO |
| CH-005 | Backup Settings Valid | INFO | SAFE |
| CH-006 | Phase Definitions Complete | INFO | SAFE |
Health Score Calculation
| Score | Grade | Status | Action |
|---|---|---|---|
| 90-100 | A | Excellent | No action needed |
| 80-89 | B | Good | Optional improvements |
| 70-79 | C | Fair | Address warnings |
| 60-69 | D | Poor | Must address issues |
| 0-59 | F | Critical | Immediate attention |
Remediation Classification
- SAFE (17 checks): Apply without confirmation - idempotent, non-destructive
- CONDITIONAL (9 checks): Requires backup + user opt-in
- MANUAL (9 checks): Cannot auto-fix, human judgment required
Health CLI Commands
4. Exit Code Taxonomy
Exit Code Ranges
| Range | Category | Description |
|---|---|---|
| 0-9 | General | Standard success/failure |
| 10-19 | Hierarchy | Parent/child, depth, sibling issues |
| 20-29 | Concurrency | Lock, session, write conflicts (existing) |
| 30-39 | Schema/Version | Version mismatch, migration |
| 50-59 | Health | Health check failures |
| 100+ | Special | Internal errors |
Schema/Version Exit Codes (30-39)
| Code | Constant | Meaning | Recoverable | Recovery Command |
|---|---|---|---|---|
| 30 | EXIT_SCHEMA_OUTDATED | Project schema older than CLI | Yes | ct migrate run |
| 31 | EXIT_SCHEMA_INCOMPATIBLE | Major version mismatch | No | Upgrade CLI or downgrade project |
| 32 | EXIT_SCHEMA_AHEAD | Project newer than CLI | Yes | Upgrade CLI |
| 33 | EXIT_SCHEMA_CORRUPT | Cannot parse version | No | Manual fix |
| 35 | EXIT_MIGRATION_IN_PROGRESS | Migration lock held | Yes | Wait/retry |
| 36 | EXIT_MIGRATION_FAILED | Migration failed | Yes | ct restore |
Health Exit Codes (50-59)
| Code | Constant | Meaning | Recoverable |
|---|---|---|---|
| 50 | EXIT_HEALTH_CRITICAL | Critical health issues | Depends on issue |
| 51 | EXIT_HEALTH_WARNING | Warning-level issues | Yes |
| 52 | EXIT_HEALTH_FIXABLE | Auto-fixable issues found | Yes (ct health --fix) |
5. LLM-Agent-First Protocols
JSON Output Structure
All commands output JSON when piped (non-TTY). Standard envelope:Error Response Structure
Health Check Response
Recommended Session Protocol
6. Git Sync Support
Project UUID for Cross-Machine Identity
Projects identified by UUID (in.cleo/project.json), not path:
Custom Git Merge Driver
Merge Strategy
Use version number + timestamp for conflict detection:- Compare
_meta.version- higher wins - Tiebreak: compare
_meta.lastModifiedAt- more recent wins - If still tied: git’s standard conflict markers, user resolves
7. Implementation Roadmap
Phase 1: Foundation (v0.24.0)
| Task | Scope | Priority |
|---|---|---|
Add _meta.version (increment) to todo.json | Small | P0 |
Add _meta.lastWriterVersion tracking | Small | P0 |
| Add exit codes 30-39 to lib/exit-codes.sh | Small | P0 |
Create ~/.cleo/registry/ structure | Small | P0 |
| Create lib/registry.sh with CRUD operations | Medium | P0 |
| Modify init.sh to register projects | Small | P0 |
Add ct registry list command | Medium | P1 |
Phase 2: Health System (v0.25.0)
| Task | Scope | Priority |
|---|---|---|
| Create lib/health.sh with 36 checks | Large | P0 |
Add ct health command with JSON output | Medium | P0 |
| Implement health score calculation | Medium | P1 |
Add ct health --fix with safety levels | Medium | P1 |
| Add health caching with TTL | Small | P2 |
Phase 3: Version Guards (v0.25.0)
| Task | Scope | Priority |
|---|---|---|
| Add fast_version_check to wrapper | Medium | P0 |
| Add validate_version_with_policy to validation.sh | Medium | P0 |
| Integrate version check in write scripts | Medium | P0 |
| Add CLEO_VERSION_CHECK env override | Small | P1 |
| Add config: migration.policy, migration.checkOnWrite | Small | P1 |
Phase 4: Git Sync (v0.26.0)
| Task | Scope | Priority |
|---|---|---|
| Add project UUID to .cleo/project.json | Small | P1 |
| Add custom git merge driver | Medium | P2 |
| Add registry reconciliation | Medium | P2 |
Phase 5: Scalability (v0.27.0)
| Task | Scope | Priority |
|---|---|---|
| Add sharded registry (50+ projects) | High | P3 |
| Add SQLite backend (500+ projects) | High | P3 |
Add ct registry gc command | Medium | P3 |
8. Files to Create/Modify
New Files
| File | Purpose |
|---|---|
lib/registry.sh | Registry CRUD operations |
lib/health.sh | Health check engine |
scripts/registry.sh | Registry command handler |
scripts/health.sh | Health command handler |
schemas/registry.schema.json | Registry JSON schema |
schemas/health.schema.json | Health output JSON schema |
templates/registry.template.json | Empty registry template |
templates/project.template.json | Project identity template |
Modified Files
| File | Changes |
|---|---|
lib/exit-codes.sh | Add exit codes 30-59 |
lib/validation.sh | Add validate_version_with_policy() |
scripts/init.sh | Add project registration, create project.json |
install.sh | Create registry directory, add registry command |
schemas/todo.schema.json | Add _meta.version, lastModifiedBy |
schemas/config.schema.json | Add migration.policy, migration.checkOnWrite |
scripts/add.sh | Add version check after lock |
scripts/update.sh | Add version check after lock |
scripts/complete.sh | Add version check after lock |
scripts/archive.sh | Add version check after lock |
| Wrapper script | Add fast_version_check() |
Appendix A: Gap Resolutions
Issues identified by Spec Challenge Agent and resolutions:| Gap | Resolution |
|---|---|
| head+grep fragility | Add jq fallback: grep ... || jq ... |
| Exit code 25 arbitrary | Use semantic range 30-39 |
| Multi-file version consistency | Add cross-file check before archive ops |
| ”Project ahead” should block | Changed to block, not warn |
| Incomplete WRITE_COMMANDS | Audit: add restore, config set |
| lastWriterVersion uses jq | Embed in atomic write jq call |
| Error recovery missing | Added rollback via ct restore |
| Plugin integration | Documented as “not supported in v1” |
Appendix B: Superseded Documents
This specification supersedes:docs/archive/specs-md/VERSION-GUARD-SPEC.md(archived) - Original proposal (contradicted by challenge agents)docs/archive/specs-md/VERSION-GUARD-FINAL-DESIGN.md(archived) - Refined but narrow (version-only focus)
Appendix C: Success Criteria
- Performance: < 5ms for fast version check, < 100ms for full health
- Safety: No data corruption on version mismatch
- UX: Clear, actionable JSON messages for LLM consumption
- Compatibility: Existing scripts/automation continue to work
- Testability: All new code has unit + integration tests
- Coverage: 36 health checks across all data integrity dimensions
Document version: 1.0.0 Generated by: Sequential thinking + 5 challenge agents synthesis
