# Spacedrive CLI A comprehensive command-line interface for managing Spacedrive Core with full daemon architecture, real-time monitoring, and cross-device file management. ## Features - **๐Ÿ—๏ธ Daemon Architecture**: Background daemon with client-server communication - **๐Ÿ“š Library Management**: Create, open, switch, and manage multiple libraries - **๐Ÿ“ Location Management**: Add, remove, and monitor indexed locations with real-time watching - **โš™๏ธ Job Management**: View, monitor, and control background jobs with live progress - **๐Ÿ“Š Real-time Monitoring**: Beautiful TUI for monitoring job progress and system events - **๐Ÿ” Indexing Control**: Start indexing jobs with different modes (shallow/content/deep) - **๐ŸŒ Networking Support**: Device pairing, file sharing via Spacedrop - **๐Ÿ”ง Multiple Instances**: Run isolated daemon instances for different use cases - **๐Ÿ“ Comprehensive Logging**: Built-in logging with file output for debugging - **๐Ÿ–ฅ๏ธ Cross-platform**: Works on macOS, Linux, and Windows - **๐ŸŽจ Rich UI**: Colored output, progress bars, and formatted tables ### New Modular Architecture Benefits The refactored daemon architecture provides: - **Maintainability**: Each domain (library, location, job, etc.) is isolated in its own handler module - **Extensibility**: New commands can be added by simply creating a new handler - **Type Safety**: All commands and responses are strongly typed - **Code Organization**: Clear separation between command handling, business logic, and transport - **Testability**: Individual handlers can be unit tested in isolation - **Performance**: Efficient command routing through handler registry ## Installation ```bash # Build the CLI cargo build --release --bin spacedrive # Install globally (optional) cargo install --path . --bin spacedrive ``` ## Quick Start ```bash # Start the Spacedrive daemon spacedrive start # Create a library and add a location spacedrive library create "Personal" spacedrive location add ~/Desktop --name "Desktop" # Monitor indexing progress spacedrive job monitor # Check system status spacedrive status ``` ## Usage ### Daemon Management ```bash # Start daemon in background spacedrive start # Start daemon with networking enabled spacedrive start --enable-networking # Start daemon in foreground (for debugging) spacedrive start --foreground # Stop the daemon spacedrive stop # Check daemon status spacedrive status # Advanced daemon commands spacedrive daemon status # Detailed daemon status spacedrive daemon list # List all daemon instances ``` ### Multiple Daemon Instances The CLI supports running multiple isolated daemon instances: ```bash # Run a separate daemon instance spacedrive --instance test start spacedrive --instance test library create "Test Library" # Stop specific instance spacedrive --instance test stop # List all running instances spacedrive daemon list ``` ### Basic Commands ```bash # Show help spacedrive --help # Enable verbose logging spacedrive -v # Use custom data directory spacedrive --data-dir /path/to/data ``` ### Library Management ```bash # Create a new library spacedrive library create "My Library" spacedrive library create "My Library" --path /custom/path # List all libraries spacedrive library list # Open an existing library spacedrive library open /path/to/library # Switch to a library by name or ID spacedrive library switch "My Library" spacedrive library switch 12345678-1234-1234-1234-123456789012 # Show current library spacedrive library current # Close current library spacedrive library close ``` ### Location Management ```bash # Add a location to index (automatically starts watching) spacedrive location add ~/Documents spacedrive location add ~/Pictures --name "My Photos" --mode deep # List all locations with status spacedrive location list # Remove a location (stops watching and indexing) spacedrive location remove # Rescan a location (triggers re-indexing) spacedrive location rescan spacedrive location rescan --force # Full rescan, ignore change detection ``` **Note**: Location IDs are UUIDs displayed in the list command. All location operations work with the daemon automatically. ### Enhanced Indexing The new indexing system supports different scopes and persistence modes: ```bash # Quick scan of current directory only (no subdirectories) spacedrive index quick-scan /path/to/directory --scope current # Quick scan with ephemeral mode (no database writes) spacedrive index quick-scan /path/to/directory --scope current --ephemeral # Browse external paths without adding to managed locations spacedrive index browse /media/external-drive --scope current spacedrive index browse /network/drive --scope recursive --content # Index managed locations with specific scope spacedrive index location /managed/location --scope current --mode shallow spacedrive index location --scope recursive --mode deep # Legacy full location indexing (backward compatibility) spacedrive scan /path/to/directory --mode content --watch ``` **Index Scopes:** - `current`: Index only the specified directory (single level) - `recursive`: Index the directory and all subdirectories **Index Modes:** - `shallow`: Metadata only (fastest) - `content`: Metadata + content hashing (moderate) - `deep`: Full analysis including media metadata (slowest) **Use Cases:** - **UI Navigation**: `quick-scan --scope current` for instant directory viewing - **External Browsing**: `browse --ephemeral` for exploring non-managed paths - **Location Updates**: `location --scope current` to refresh specific directories ### Job Management ```bash # List all jobs with colored status and progress spacedrive job list spacedrive job list --status running # Filter by status # Show detailed job information spacedrive job info # Monitor jobs in real-time with live progress bars spacedrive job monitor spacedrive job monitor --job-id # Monitor specific job # Control jobs (planned features) spacedrive job pause spacedrive job resume spacedrive job cancel ``` **Job Monitor Features:** - ๐Ÿ”ด Live progress bars for running jobs - ๐ŸŽจ Color-coded status (running: yellow, completed: green, failed: red) - โฑ๏ธ Real-time updates every second - ๐Ÿงน Automatic cleanup of completed jobs - โŒจ๏ธ Ctrl+C to exit gracefully ### File Operations ```bash # Copy files with progress tracking spacedrive file copy ~/source.txt ~/destination.txt spacedrive file copy ~/Photos/*.jpg ~/Backup/ --verify # Move files spacedrive file move ~/Downloads/*.pdf ~/Documents/ --preserve-timestamps # Advanced copy options spacedrive file copy ~/Project/ ~/Backup/Project/ \ --overwrite \ --verify \ --preserve-timestamps ``` ### System Commands ```bash # Show system status spacedrive status # Monitor all system activity (TUI) spacedrive monitor # View daemon logs spacedrive system logs spacedrive system logs --tail 50 ``` ### Networking & Device Management ```bash # Initialize networking (if daemon wasn't started with --enable-networking) spacedrive network init # Start/stop networking spacedrive network start spacedrive network stop # List connected devices spacedrive network devices # Device pairing spacedrive network pair --initiate # Generate pairing code spacedrive network pair --join # Join using code spacedrive network pair --status # Check pairing status # Spacedrop (file sharing) spacedrive network spacedrop /path/to/file --sender "Your Name" # Remove paired device spacedrive network revoke ``` ## Real-time Job Monitor The job monitor provides live progress tracking with beautiful visual indicators: ```bash spacedrive job monitor ``` ### Monitor Features - **๐ŸŽฏ Multi-job tracking**: Monitor all running jobs simultaneously - **๐Ÿ“Š Progress bars**: Visual progress indicators with percentage - **๐ŸŽจ Color coding**: Status-based colors (yellow=running, green=completed, red=failed) - **โšก Real-time updates**: Updates every second with latest progress - **๐Ÿงน Smart cleanup**: Completed jobs automatically marked and removed - **๐Ÿ” Job filtering**: Option to monitor specific jobs ### Sample Output ``` ๐Ÿ“ก Spacedrive Job Monitor - Press Ctrl+C to exit โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ• โ š Indexing Desktop [fdbe777d] [โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘] 25% | Status: Running โ ‚ Indexing Photos [a1b2c3d4] [โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆ] 100% | โœ… Completed โ ˆ Content Analysis [e5f6g7h8] [โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘] 15% | Status: Running ``` ## Indexing Modes - **Shallow**: Fast metadata-only indexing (file names, sizes, dates) - **Content**: Standard indexing with content hashing for deduplication - **Deep**: Comprehensive analysis including media metadata extraction ## Examples ### Complete Workflow ```bash # 1. Start the daemon spacedrive start # 2. Create a library spacedrive library create "Personal" # 3. Add locations with different index modes spacedrive location add ~/Desktop --name "Desktop" --mode content spacedrive location add ~/Documents --name "Documents" --mode content spacedrive location add ~/Pictures --name "Photos" --mode deep # 4. Monitor the indexing progress spacedrive job monitor # 5. Check the results spacedrive location list spacedrive job list ``` ### Multiple Libraries ```bash # Work with multiple libraries spacedrive library create "Work" spacedrive library create "Personal" spacedrive library list spacedrive library switch "Work" spacedrive location add ~/Work/Projects ``` ### Batch Indexing ```bash # Index multiple locations spacedrive location add ~/Documents --name "Docs" spacedrive location add ~/Pictures --name "Photos" --mode deep spacedrive location add ~/Downloads --name "Downloads" --mode shallow spacedrive job list --status running ``` ## Architecture ### Daemon-Client Model The Spacedrive CLI uses a daemon-client architecture for optimal performance: ``` โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” Unix Socket โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ CLI Client โ”‚ โ—„โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–บ โ”‚ Spacedrive โ”‚ โ”‚ (Commands) โ”‚ โ”‚ Daemon โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ โ–ผ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ Background โ”‚ โ”‚ Jobs, Watching โ”‚ โ”‚ & File System โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ ``` **Benefits:** - ๐Ÿš€ **Fast responses**: Daemon keeps state in memory - ๐Ÿ”„ **Background processing**: Jobs continue when CLI exits - ๐Ÿ“ก **Real-time updates**: File system changes processed immediately - ๐Ÿ’พ **Persistent state**: Libraries and locations survive restarts ### Modular Daemon Architecture The daemon has been refactored into a clean, modular architecture: ``` src/infrastructure/cli/daemon/ โ”œโ”€โ”€ mod.rs # Core daemon server (socket handling, lifecycle) โ”œโ”€โ”€ client.rs # DaemonClient implementation โ”œโ”€โ”€ config.rs # DaemonConfig and instance management โ”œโ”€โ”€ types/ โ”‚ โ”œโ”€โ”€ commands.rs # DaemonCommand enum and sub-commands โ”‚ โ”œโ”€โ”€ responses.rs # DaemonResponse enum and response types โ”‚ โ””โ”€โ”€ common.rs # Shared types (JobInfo, LibraryInfo, etc.) โ”œโ”€โ”€ handlers/ โ”‚ โ”œโ”€โ”€ mod.rs # Handler trait and registry โ”‚ โ”œโ”€โ”€ core.rs # Core commands (ping, shutdown, status) โ”‚ โ”œโ”€โ”€ library.rs # Library command handling โ”‚ โ”œโ”€โ”€ location.rs # Location command handling โ”‚ โ”œโ”€โ”€ job.rs # Job command handling โ”‚ โ”œโ”€โ”€ network.rs # Network command handling โ”‚ โ”œโ”€โ”€ file.rs # File command handling โ”‚ โ””โ”€โ”€ system.rs # System command handling โ””โ”€โ”€ services/ โ”œโ”€โ”€ state.rs # CLI state management service โ””โ”€โ”€ helpers.rs # Common helpers (device registration, etc.) ``` **Key Components:** 1. **Command Handlers**: Each domain (library, location, job, etc.) has its own handler that encapsulates all related command processing logic. 2. **Handler Registry**: A central registry that routes incoming commands to the appropriate handler based on command type. 3. **State Service**: Manages CLI state including current library selection and persists it across sessions. 4. **Type Safety**: All commands and responses are strongly typed, preventing errors and improving maintainability. 5. **Separation of Concerns**: Business logic is cleanly separated from transport (socket handling) and presentation concerns. ### Configuration The daemon stores data in the specified data directory: ``` spacedrive-cli-data/ โ”œโ”€โ”€ libraries/ # Library database files โ”œโ”€โ”€ daemon.sock # Unix socket for communication โ”œโ”€โ”€ daemon.pid # Process ID file โ”œโ”€โ”€ daemon.log # Daemon log file โ””โ”€โ”€ cli_state.json # CLI preferences and history ``` For multiple instances: ``` spacedrive-cli-data/ โ”œโ”€โ”€ instance-test/ โ”‚ โ”œโ”€โ”€ libraries/ โ”‚ โ””โ”€โ”€ cli_state.json โ”œโ”€โ”€ spacedrive-test.sock โ”œโ”€โ”€ spacedrive-test.pid โ””โ”€โ”€ spacedrive-test.log ``` ## Tips & Best Practices 1. **๐Ÿ”ง Start Daemon First**: Always run `spacedrive start` before other commands 2. **๐Ÿ“Š Monitor Progress**: Use `spacedrive job monitor` for real-time feedback on indexing 3. **๐Ÿ’ป Use Verbose Mode**: Add `-v` flag for detailed logging during troubleshooting 4. **๐Ÿš€ Start Simple**: Begin with shallow indexing for quick results, then upgrade to deeper modes 5. **๐Ÿ“ Organize by Purpose**: Create separate libraries for different use cases (Work, Personal, etc.) 6. **โšก Daemon Persistence**: The daemon keeps running in the background - jobs continue even if you close the terminal ## Troubleshooting ### Daemon Issues ```bash # Check if daemon is running spacedrive status # Check specific instance spacedrive --instance test status # List all daemon instances spacedrive daemon list # Restart daemon spacedrive stop spacedrive start # Run daemon in foreground for debugging spacedrive start --foreground -v # Check daemon logs spacedrive system logs --tail 100 ``` ### Communication Errors ```bash # Check daemon status spacedrive daemon # Look for socket file ls -la spacedrive-cli-data/daemon.sock # Restart daemon if socket is missing spacedrive stop && spacedrive start ``` ### Job Issues ```bash # Check job status with details spacedrive job list -v # View specific job information spacedrive job info # Monitor jobs in real-time spacedrive job monitor ``` ### Location Issues ```bash # Check location status spacedrive location list # Force rescan if files not updating spacedrive location rescan --force # Remove and re-add problematic locations spacedrive location remove spacedrive location add /path/to/location ``` ### Performance Issues ```bash # Use shallow mode for large directories spacedrive location add /large/directory --mode shallow # Check system status spacedrive status # Monitor daemon resources with verbose output spacedrive start --foreground -v ```