This guide provides comprehensive documentation of the APC State Management System, which tracks plugin development progress across all phases.
The State Management System ensures:
- Phase Validation - Prevents skipping phases
- Progress Tracking - Know where you are at any time
- Error Recovery - Rollback capabilities
- Framework Selection - Track UI framework choice
- Multi-Agent Support - Switch AI agents without losing context
Every plugin has a status.json file with this structure:
{
"plugin_name": "PluginName",
"version": "v0.0.0",
"current_phase": "ideation",
"ui_framework": "pending",
"complexity_score": 0,
"created_at": "2026-01-01T00:00:00Z",
"last_modified": "2026-01-01T00:00:00Z",
"phase_history": [],
"validation": {
"creative_brief_exists": false,
"parameter_spec_exists": false,
"architecture_defined": false,
"ui_framework_selected": false,
"design_complete": false,
"code_complete": false,
"tests_passed": false,
"ship_ready": false
},
"framework_selection": {
"decision": "pending",
"rationale": "",
"implementation_strategy": "pending"
},
"error_recovery": {
"last_backup": null,
"rollback_available": false,
"error_log": []
}
}┌─────────────┐ ┌─────────────┐ ┌─────────────┐
│ ideation │────▶│ plan │────▶│ design │
│ (DREAM) │ │ (PLAN) │ │ (DESIGN) │
└─────────────┘ └─────────────┘ └──────┬──────┘
│
┌─────────────┐ ┌─────────────┐ │
│ ship │◀────│ code │◀──────────┘
│ (SHIP) │ │ (IMPL) │
└──────┬──────┘ └─────────────┘
│
▼
┌─────────────┐
│ complete │
└─────────────┘
The state-management.ps1 script provides these functions:
Initialize a new plugin state file.
New-PluginState -PluginName "MyPlugin" -PluginPath "plugins\MyPlugin"Creates:
status.jsonwith default values- Sets
current_phaseto "ideation" - Initializes all validation flags to
false
Retrieve the current state object.
$state = Get-PluginState -PluginPath "plugins\MyPlugin"
Write-Host "Current phase: $($state.current_phase)"
Write-Host "UI Framework: $($state.ui_framework)"Update specific fields in the state.
Update-PluginState -PluginPath "plugins\MyPlugin" -Updates @{
"current_phase" = "plan"
"validation.architecture_defined" = $true
"ui_framework" = "webview"
}Features:
- Automatic timestamp update
- Schema validation
- Nested property support (dot notation)
Validate prerequisites before proceeding.
if (-not (Test-PluginState -PluginPath "plugins\MyPlugin" `
-RequiredPhase "plan_complete" `
-RequiredFiles @(".ideas/architecture.md", ".ideas/plan.md"))) {
Write-Error "Prerequisites not met"
exit 1
}Checks:
- Phase is at or beyond required phase
- Required files exist
- Framework is selected (if applicable)
Mark a phase as complete and update state.
Complete-Phase -PluginPath "plugins\MyPlugin" -Phase "plan" -Updates @{
"validation.architecture_defined" = $true
"validation.ui_framework_selected" = $true
"framework_selection.decision" = "webview"
"complexity_score" = 3
}Actions:
- Updates
current_phaseto "[phase]_complete" - Adds entry to
phase_history - Applies all update values
- Updates
last_modifiedtimestamp
Create a backup before risky operations.
Backup-PluginState -PluginPath "plugins\MyPlugin"Creates: status.json.backup.[timestamp]
Rollback to previous state.
Restore-PluginState -PluginPath "plugins\MyPlugin"Restores: Most recent backup file
Initialize state:
New-PluginState -PluginName "MyPlugin" -PluginPath "plugins\MyPlugin"Complete phase:
Complete-Phase -PluginPath "plugins\MyPlugin" -Phase "ideation" -Updates @{
"validation.creative_brief_exists" = $true
"validation.parameter_spec_exists" = $true
}State after:
{
"current_phase": "ideation_complete",
"validation": {
"creative_brief_exists": true,
"parameter_spec_exists": true
},
"phase_history": [
{
"phase": "ideation_complete",
"completed_at": "2026-01-01T00:00:00Z",
"framework_selected": null
}
]
}Validate prerequisites:
if (-not (Test-PluginState -PluginPath "plugins\MyPlugin" `
-RequiredPhase "ideation_complete" `
-RequiredFiles @(".ideas/creative-brief.md", ".ideas/parameter-spec.md"))) {
exit 1
}Set framework selection:
# Helper function for framework selection
Set-PluginFramework -PluginPath "plugins\MyPlugin" `
-Framework "webview" `
-Rationale "Complex UI with real-time visualization requires WebView capabilities"Complete phase:
Complete-Phase -PluginPath "plugins\MyPlugin" -Phase "plan" -Updates @{
"validation.architecture_defined" = $true
"validation.ui_framework_selected" = $true
"complexity_score" = 3
"framework_selection.implementation_strategy" = "phased"
}Validate framework selection:
$state = Get-PluginState -PluginPath "plugins\MyPlugin"
if ($state.ui_framework -eq "pending") {
Write-Error "UI framework not selected. Complete planning phase first."
exit 1
}Complete phase:
Complete-Phase -PluginPath "plugins\MyPlugin" -Phase "design" -Updates @{
"validation.design_complete" = $true
}Validate prerequisites:
if (-not (Test-PluginState -PluginPath "plugins\MyPlugin" `
-RequiredPhase "design_complete" `
-RequiredFiles @(".ideas/architecture.md", ".ideas/plan.md"))) {
exit 1
}Complete phase:
Complete-Phase -PluginPath "plugins\MyPlugin" -Phase "code" -Updates @{
"validation.code_complete" = $true
"validation.tests_passed" = $true
}Validate prerequisites:
if (-not (Test-PluginState -PluginPath "plugins\MyPlugin" `
-RequiredPhase "code_complete" `
-RequiredFiles @("Source/PluginProcessor.cpp"))) {
exit 1
}Complete phase:
Complete-Phase -PluginPath "plugins\MyPlugin" -Phase "ship" -Updates @{
"validation.ship_ready" = $true
"version" = "v1.0.0"
}Centralized framework selection with validation:
Set-PluginFramework -PluginPath "plugins\MyPlugin" `
-Framework "webview" `
-Rationale "Complex UI requirements"Updates:
ui_frameworkframework_selection.decisionframework_selection.rationale
| Criteria | Visage | WebView |
|---|---|---|
| Complexity Score 1-2 | ✅ Recommended | |
| Complexity Score 3-5 | ✅ Recommended | |
| Performance Critical | ✅ Best | |
| Rich Visualization | ✅ Excellent | |
| Rapid Iteration | ✅ Fast | |
| Team Collaboration | ✅ Web Devs |
State is automatically backed up before:
- Phase completion
- Framework selection changes
- Major file operations
# Before risky operation
Backup-PluginState -PluginPath "plugins\MyPlugin"
# Try operation
try {
# Risky operation here
} catch {
# Restore on failure
Restore-PluginState -PluginPath "plugins\MyPlugin"
}# Log error to state
Add-StateError -PluginPath "plugins\MyPlugin" `
-ErrorMessage "Build failed: CMake configuration error"Updates: error_recovery.error_log array
Comprehensive prerequisite validation:
$validation = Validate-PhasePrerequisites `
-PluginPath "plugins\MyPlugin" `
-CurrentPhase "code" `
-RequiredPhase "design_complete" `
-RequiredFiles @(".ideas/architecture.md")
if (-not $validation.IsValid) {
Write-Host "Missing: $($validation.MissingFiles -join ', ')" -ForegroundColor Red
Write-Host "Current phase: $($validation.CurrentPhase)" -ForegroundColor Red
exit 1
}WebView-specific validation:
if (-not (Test-CanvasImplementation -PluginPath "plugins\MyPlugin")) {
Write-Error "Canvas implementation required for WebView"
exit 1
}ideation → ideation_complete → plan → plan_complete →
design → design_complete → code → code_complete →
ship → ship_complete → complete
ideation → design (Missing plan)
ideation → code (Missing plan, design)
plan → code (Missing design)
design → ship (Missing code)
| Error | Cause | Solution |
|---|---|---|
| "Prerequisites not met" | Previous phase incomplete | Complete prior phase |
| "Framework not selected" | Missing framework choice | Run planning phase |
| "Required files missing" | Files don't exist | Create required files |
| "Invalid phase transition" | Trying to skip phases | Follow phase order |
State enables switching between AI agents:
# Agent 1 completes ideation
/dream MyPlugin
# ... ideation complete
# Agent 2 continues with planning
/plan MyPlugin
# Reads status.json, knows ideation is complete
# Continues from correct phase# Any agent can check current state
$state = Get-PluginState -PluginPath "plugins\MyPlugin"
Write-Host "Resuming from phase: $($state.current_phase)"if (-not (Test-PluginState ...)) {
exit 1
}Backup-PluginState -PluginPath "plugins\MyPlugin"
# ... make changes# Good
Complete-Phase -PluginPath "plugins\MyPlugin" -Phase "plan" -Updates @{...}
# Bad - manual updates
Update-PluginState -PluginPath "plugins\MyPlugin" -Updates @{
"current_phase" = "plan_complete"
}try {
# Operation
} catch {
Add-StateError -PluginPath "plugins\MyPlugin" -ErrorMessage $_.Exception.Message
}$state = Get-PluginState -PluginPath "plugins\MyPlugin"
if ($state.ui_framework -eq "webview") {
# WebView-specific code
} else {
# Visage-specific code
}Check:
$state = Get-PluginState -PluginPath "plugins\MyPlugin"
$state | ConvertTo-Json -Depth 5Common causes:
- Missing required fields
- Invalid data types
- Corrupted JSON
Check:
# Current phase
$state.current_phase
# Required validation flags
$state.validation
# Missing files
Test-Path "plugins\MyPlugin\.ideas\creative-brief.md"Solution:
Set-PluginFramework -PluginPath "plugins\MyPlugin" -Framework "webview" -Rationale "..."| Function | Purpose |
|---|---|
New-PluginState |
Initialize new plugin state |
Get-PluginState |
Retrieve current state |
Update-PluginState |
Update specific fields |
Test-PluginState |
Validate prerequisites |
Complete-Phase |
Mark phase complete |
Backup-PluginState |
Create backup |
Restore-PluginState |
Rollback to backup |
Add-StateError |
Log error |
Set-PluginFramework |
Select UI framework |
Validate-PhasePrerequisites |
Comprehensive validation |
Test-CanvasImplementation |
WebView validation |
- Project Structure - Directory layout
- State Management Guide - Original guide
- Build System - Build integration
- Workflows - Phase orchestration