Context
The doctor command currently only prints placeholder text but doesn't implement any actual diagnostic checks described in its documentation.
Location: src/commands/doctor.rs:52
Current Behavior
When running crately doctor:
Running system diagnostics...
Diagnostics to be implemented:
- Configuration file validation
- Database connectivity check
- File system permissions
- Dependency verification
- Runtime environment checks
Doctor diagnostics complete
Expected Behavior
The doctor command should perform comprehensive health checks and report the status of each:
Running system diagnostics...
Configuration File............... ✓ Valid (~/.config/crately/config.toml)
Database Connectivity............ ✓ Connected (rocksdb://~/.local/share/crately/db)
OpenAI API Key................... ✓ Configured and valid
Cache Directory.................. ✓ Writable (~/.cache/crately)
Data Directory................... ✓ Writable (~/.local/share/crately)
Logs Directory................... ✓ Writable (~/.local/share/crately/logs)
Required Dependencies............ ✓ All available
✓ All diagnostics passed - system is healthy
Next steps:
- Run 'crately serve' to start the server
Implementation Requirements
Diagnostic Checks to Implement
-
Configuration File Validation
- Check config file exists at XDG_CONFIG_HOME/crately/config.toml
- Parse and validate config structure
- Check all required fields present
- Validate field values (e.g., port ranges, timeouts)
- Report specific issues if invalid
-
Database Connectivity Check
- Verify database path is accessible
- Test connection to embedded SurrealDB
- Check database schema is initialized
- Verify tables exist (crate, doc_chunk, embedding)
- Check database is not locked by another process
-
File System Permissions
- XDG_CONFIG_HOME/crately - readable/writable
- XDG_DATA_HOME/crately - readable/writable
- XDG_CACHE_HOME/crately - readable/writable
- XDG_DATA_HOME/crately/logs - readable/writable
- Database directory - readable/writable
-
Dependency Verification
- OpenAI API key present (env var or config)
- API key is valid (test API call if
--verbose)
- Network connectivity (if
--verbose)
- Required Rust version (cargo --version)
-
Runtime Environment Checks
- Operating system and version
- Available disk space in cache/data directories
- Memory available
- CPU architecture
Verbose Mode
When --verbose flag is used, show additional details:
Configuration File............... ✓ Valid
Location: /home/user/.config/crately/config.toml
Size: 1.2 KB
Last modified: 2025-01-15 10:30:00
Port: 3000
Model: text-embedding-3-small
Database Connectivity............ ✓ Connected
Type: RocksDB
Location: /home/user/.local/share/crately/db
Size: 45.2 MB
Tables: 3 (crate, doc_chunk, embedding)
Records: 1,234 chunks, 987 embeddings
OpenAI API Key................... ✓ Valid
Source: Environment variable OPENAI_API_KEY
Model: text-embedding-3-small (validated)
Error Reporting
When checks fail, provide actionable guidance:
Configuration File............... ✗ Invalid
Error: Missing required field 'api_endpoint'
To fix:
1. Edit ~/.config/crately/config.toml
2. Add: api_endpoint = "https://api.openai.com/v1/embeddings"
3. Or run: crately init
Database Connectivity............ ✗ Failed
Error: Database locked by another process (PID: 12345)
To fix:
1. Stop other crately instances: pkill crately
2. Or use a different database path in config
Files to Modify
src/commands/doctor.rs - Main implementation
src/actors/config.rs - May need validation helpers
src/database.rs - May need connectivity check functions
CLAUDE.md - Update documentation
Implementation Pattern
pub fn run(args: DoctorArgs) -> Result<()> {
println!("Running system diagnostics...\n");
let mut all_passed = true;
// Check 1: Configuration
all_passed &= check_configuration(&args)?;
// Check 2: Database
all_passed &= check_database(&args)?;
// Check 3: API Key
all_passed &= check_api_key(&args)?;
// Check 4: File permissions
all_passed &= check_file_permissions(&args)?;
// Check 5: Dependencies
all_passed &= check_dependencies(&args)?;
if all_passed {
println!("\n✓ All diagnostics passed - system is healthy");
} else {
println!("\n✗ Some diagnostics failed - see details above");
std::process::exit(1);
}
Ok(())
}
fn check_configuration(args: &DoctorArgs) -> Result<bool> {
print!("Configuration File............... ");
// Implementation here
println!("✓ Valid");
Ok(true)
}
Testing Requirements
Success Criteria
Related Files
src/commands/doctor.rs - Main implementation needed (lines 52-58)
src/actors/config.rs - Config validation
CLAUDE.md - Documentation to update
Dependencies
This issue should be implemented before #74 (automatic fixes), as the fix logic will depend on the diagnostic checks.
Priority
Medium - Important for troubleshooting and system health verification
Context
The
doctorcommand currently only prints placeholder text but doesn't implement any actual diagnostic checks described in its documentation.Location:
src/commands/doctor.rs:52Current Behavior
When running
crately doctor:Expected Behavior
The doctor command should perform comprehensive health checks and report the status of each:
Implementation Requirements
Diagnostic Checks to Implement
Configuration File Validation
Database Connectivity Check
File System Permissions
Dependency Verification
--verbose)--verbose)Runtime Environment Checks
Verbose Mode
When
--verboseflag is used, show additional details:Error Reporting
When checks fail, provide actionable guidance:
Files to Modify
src/commands/doctor.rs- Main implementationsrc/actors/config.rs- May need validation helperssrc/database.rs- May need connectivity check functionsCLAUDE.md- Update documentationImplementation Pattern
Testing Requirements
--verboseand--fixflags work correctlycargo nextest runcargo clippy --all-targetsSuccess Criteria
Related Files
src/commands/doctor.rs- Main implementation needed (lines 52-58)src/actors/config.rs- Config validationCLAUDE.md- Documentation to updateDependencies
This issue should be implemented before #74 (automatic fixes), as the fix logic will depend on the diagnostic checks.
Priority
Medium - Important for troubleshooting and system health verification