Version Guard System Specification
SUPERSEDED: This document has been superseded by HEALTH-REGISTRY-SPEC.md which provides a comprehensive health registry system including version guards, health monitoring, and multi-agent coordination.
Overview
This specification defines a three-layer defense system for schema integrity in cleo, ensuring data compatibility and providing clear migration paths when schema versions change.Problem Statement
Current issues:- Schemas exist in TWO locations (global
~/.cleo/schemas/+ project.cleo/schemas/) - No proactive version checking - users discover issues only via explicit
ct validate - Write commands (add/update/complete/archive) can corrupt data if schema is outdated
- Multiple documentation sources for migration (fragmented)
- No automatic migration prompting
Proposed Solution: Three-Layer Defense
Layer 1: Startup Guard (lib/startup-guard.sh)
Purpose: Fast version check on every command startup Behavior:- Single jq call to read
._meta.versionfrom.cleo/todo.json - Compare against expected version from
schemas/version-manifest.json - Return status: OK (0), WARN (1), BLOCK (2)
Layer 2: Write Guard (lib/write-guard.sh)
Purpose: Pre-write validation with inline migration option Behavior:- Called by add.sh, update.sh, complete.sh, archive.sh
- Checks: version + checksum + basic integrity
- If migration needed: prompt user (interactive) or fail with instructions (non-interactive)
Layer 3: Full Validation (validate.sh)
Purpose: Comprehensive validation with —fix capability Behavior:- Existing 11+ checks
- —fix mode for auto-repair
- Used for troubleshooting and CI/CD
Version Manifest (schemas/version-manifest.json)
Purpose: Single source of truth for schema versions Schema:- Replace hardcoded
SCHEMA_VERSION_*constants - Read from manifest at runtime:
jq -r '.current.todo' "$VERSION_MANIFEST"
Configuration Options
Add toconfig.json schema:
Behavior Matrix
| Scenario | Read Command | Write Command (interactive) | Write Command (non-interactive) |
|---|---|---|---|
| Same version | proceed | proceed | proceed |
| Minor behind | warn | prompt migrate | warn + proceed |
| Major behind | warn | block | block + error |
| Unknown version | warn | prompt migrate | warn + proceed |
| Ahead of global | warn (downgrade?) | warn + proceed | warn + proceed |
Non-Interactive Detection
Error Messages
Version Mismatch Warning (startup)
Write Guard Prompt (interactive)
Write Guard Block (major mismatch)
JSON Output (non-interactive)
Implementation Phases
Phase 1: Foundation (v0.24.0)
- Create
schemas/version-manifest.json - Create
lib/startup-guard.shwithquick_version_check() - Modify
lib/migrate.shto read from manifest - Add startup check to wrapper (warn only)
- Add config options to schema
Phase 2: Write Protection (v0.25.0)
- Create
lib/write-guard.shwithcan_write_safely() - Integrate into add.sh, update.sh, complete.sh, archive.sh
- Implement inline migration prompt
- Add non-interactive mode support
Phase 3: Polish (v0.26.0)
- Add post-install project scan to install.sh
- Consolidate migration documentation
- Add warning suppression mechanism
- Performance optimization (caching)
Performance Considerations
- Fast path optimization: If version matches, exit immediately
- Caching: Cache version check result in environment variable for session
- Lazy loading: Don’t parse full manifest unless needed
- Alternative to jq: Use
grep+sedfor ultra-fast version extraction if jq proves too slow
Testing Strategy
-
Unit tests:
- Version comparison logic
- Manifest parsing
- Error message generation
-
Integration tests:
- Startup guard with various version combinations
- Write guard with migration flow
- Non-interactive mode behavior
-
Performance tests:
- Measure startup latency with/without guard
- Test with large todo.json files (1000+ tasks)
Backward Compatibility
- Missing version field: Treat as “1.0.0” (oldest supported)
- Default config: All checks enabled, warn-only (non-blocking)
- Gradual rollout: Feature flags for new blocking behavior
