KISS Smart Batch Installer - FSM Implementation Analysis
🎯 Unified Implementation Plan & Refactoring Checklist
This plan integrates high-level features with specific refactoring tasks into weekly sprints. Follow this order to ensure a smooth transition to a fully FSM-centric architecture.
Week 1: Implement Frontend State Mirror & Decouple UI
The goal this week is to fix the immediate progressive loading bugs by establishing the FSM pattern on the frontend and removing all ad-hoc state flags.
Week 2: Centralize Backend State Management
The goal this week is to make the PHP StateManager the undisputed source of truth by absorbing all disparate state logic and removing legacy code.
Week 3: Implement State Broadcasting & Finalize Integration
The goal this week is to complete the event-driven architecture, making the system fully reactive and robust.
Guiding Principles & Success Criteria
CRITICAL INSTRUCTION: The refactoring is complete only when the StateManager is the single, undisputed source of state truth.
-
Success Criteria
- ✅ Zero Direct State Checks: No code directly checks plugin status without going through the FSM.
- ✅ Single State Source: Only
StateManager manages and reports the current state.
- ✅ All Changes Are Transitions: Every single state change uses the
transition() method.
- ✅ Frontend-Backend Sync: The JavaScript FSM perfectly mirrors the PHP FSM via the event stream.
- ✅ No Duplicate Logic: State determination logic exists in exactly one place:
StateManager.
-
Anti-Patterns to Avoid 🚨
- ❌ Do not add "helper" methods that bypass the FSM.
- ❌ Do not create "convenience" functions that check state directly.
- ❌ Do not keep "backup" state variables "just in case."
- ❌ Do not allow any component to determine state independently.
KISS Smart Batch Installer - FSM Implementation Analysis
🎯 Unified Implementation Plan & Refactoring Checklist
This plan integrates high-level features with specific refactoring tasks into weekly sprints. Follow this order to ensure a smooth transition to a fully FSM-centric architecture.
Week 1: Implement Frontend State Mirror & Decouple UI
The goal this week is to fix the immediate progressive loading bugs by establishing the FSM pattern on the frontend and removing all ad-hoc state flags.
Task: Create JavaScript FSM Class
RepositoryStateMachineclass in JavaScript, mirroring the backend FSM's states and transitions.Task: Remove Ad-Hoc JavaScript State Variables 🚫
src/Admin/RepositoryManager.php(JavaScript section)isLoading,processingQueue, andactiveRequestvariables entirely.repositoryFSM(e.g.,repositoryFSM.isInState('repo', 'checking')).Task: Refactor UI Updates to be FSM-Driven
updateUImethod of theRepositoryStateMachine.Task: Sync Frontend FSM with Backend
notifyBackendmethod in the JavaScript FSM.sbi_update_state) to keep the backend FSM synchronized.Week 2: Centralize Backend State Management
The goal this week is to make the PHP
StateManagerthe undisputed source of truth by absorbing all disparate state logic and removing legacy code.Task: Implement Processing State Lock Mechanism 🔐
acquireProcessingLockandreleaseProcessingLockmethods toStateManager.php.AjaxHandler.phpwith these lock functions to prevent race conditions.Task: Merge Redundant Services into StateManager 🗑️
PluginDetectionService.phpinto a privatedetectPluginState()method withinStateManager. The method should return aPluginStateenum, not a boolean.PQSIntegration.phpinto a privatecheckCacheState()method withinStateManager.Task: Deprecate and Replace Direct State Checks 🔄
is_plugin_active().StateManagermethods (e.g.,$this->state_manager->isActive($repo)). These new methods must query the FSM's state, not call the WordPress functions directly.Task: Eliminate Parallel State Tracking ⚡
src/Admin/RepositoryListTable.phpStateManager.src/API/AjaxHandler.php$this->state_manager->transition().Task: Refactor Installation Service 🔧
src/Services/PluginInstallationService.phpinstall_pluginmethod to be stateless. It should no longer return success/failure arrays. Instead, it must calltransition()to move the repository intoINSTALLING,INSTALLED_INACTIVE, orERRORstates.Week 3: Implement State Broadcasting & Finalize Integration
The goal this week is to complete the event-driven architecture, making the system fully reactive and robust.
Task: Implement State Change Broadcasting in PHP 📡
addListenerandbroadcastmethods toStateManager.php.transition()method to broadcast astate_changedevent every time a state change occurs.Task: Connect Frontend to Backend Events
EventSourceto listen forstate_changedevents from the server.Task: Finalize UI Reactivity
Task: Final Code Review and Cleanup
@deprecatedtags to all old, non-FSM state methods.Guiding Principles & Success Criteria
Success Criteria
StateManagermanages and reports the current state.transition()method.StateManager.Anti-Patterns to Avoid 🚨