mirror of
https://github.com/spacedriveapp/spacedrive.git
synced 2026-02-20 07:37:26 -05:00
3.5 KiB
3.5 KiB
CLI Daemon Actions Refactoring Design Document
Overview
This document outlines the plan to refactor CLI daemon handlers to properly use the action system for all state-mutating operations, while keeping read-only operations as direct queries.
Principles
- Actions for State Mutations: Any operation that modifies state (database, filesystem, job state) should go through the action system
- Direct Queries for Reads: Read-only operations should remain as direct database queries or service calls
- Consistency: Similar operations should follow similar patterns
- Audit Trail: Actions provide built-in audit logging for all mutations
Current State Analysis
Operations Currently Using Actions
LocationAdd- UsesLocationAddActionLocationRemove- UsesLocationRemoveActionCopy- UsesFileCopyAction
Operations That Should Use Actions
Indexing Operations
IndexLocation- Re-indexes an existing locationIndexAll- Indexes all locations in a library
Can use existing actions:
IndexLocation→ Use existingLocationIndexActionIndexAll→ Could create a newLibraryIndexAllActionor dispatch multipleLocationIndexActions
Operations That Should NOT Use Actions
These are read-only operations or ephemeral operations:
Browse- Just reads filesystem without persistingQuickScanwithephemeral: true- Temporary scan, no persistence- All List operations (
ListLibraries,ListLocations,ListJobs) - All Get operations (
GetJobInfo,GetCurrentLibrary,GetStatus) Ping- Simple health check
Operations to Remove ️
IndexPath- Redundant with location-based indexingQuickScanwithephemeral: false- Should just use location add + index
Implementation Plan
Phase 1: Update File Handler
- Remove
IndexPathcommand entirely - Implement
IndexLocationusingLocationIndexAction - Implement
IndexAllas either:- New
LibraryIndexAllAction, or - Loop dispatching multiple
LocationIndexActions <- this one is my fav
- New
- Keep
Browseas direct filesystem operation (no action) - Remove
QuickScancommand
Phase 2: Cleanup
- Remove unused imports and dead code
- Update documentation
- Add tests for new actions
Benefits
- Consistency: All state mutations go through the same system
- Auditability: Every state change is logged
- Validation: Actions validate inputs before execution
- Extensibility: Easy to add pre/post processing to actions
- Testability: Actions can be tested in isolation
Migration Strategy
- Implement one handler at a time
- Keep existing functionality working during migration
- Test each migrated handler thoroughly
- Remove old code only after new code is verified
Future Considerations
Potential New Actions
Yes lets make these!
LibraryRename- Rename a libraryLibraryExport- Export library metadataLocationRescan- Currently using direct job dispatch, could be an actionDeviceRevoke- Remove device from network (currently direct)
Read-Only Operation Patterns
We can handle this another time
Consider creating a consistent pattern for read operations:
- Standardized query builders
- Consistent error handling
- Pagination support where appropriate
Success Metrics
- All state-mutating operations use actions
- No direct database modifications in handlers
- Consistent error handling across all handlers
- Clear separation between read and write operations
- Improved testability of handlers