# Execution Lifecycle & Common Hooks ## Legend | Symbol | Meaning | | Abbrev | Meaning | |--------|---------|---|--------|---------| | ▶ | start/begin | | exec | execution | | ⏸ | pause/checkpoint | | val | validation | | ⏹ | stop/end | | ver | verification | | 🔄 | cycle/repeat | | cln | cleanup | ## Universal Execution Phases ```yaml Standard_Lifecycle: Pre_Execution: Phase: "Validation and preparation" Duration: "5-15% of total execution time" Critical: "Prevent issues before they occur" During_Execution: Phase: "Core operation execution" Duration: "70-85% of total execution time" Critical: "Monitor progress and handle errors" Post_Execution: Phase: "Cleanup and verification" Duration: "10-15% of total execution time" Critical: "Ensure completion and clean state" Phase_Transitions: Pre → During: "All validations pass" During → Post: "Core operation completes (success or controlled failure)" Post → Complete: "Cleanup verified, results confirmed" Any → Error: "Unrecoverable error triggers error handling" Any → Pause: "User interruption or checkpoint trigger" ``` ## Pre-Execution Hooks ```yaml Environment_Validation: System_Requirements: - Check required tools availability - Verify sufficient system resources - Validate network connectivity (if needed) - Confirm adequate disk space Permission_Checks: - Verify file system permissions - Check git repository access - Validate API credentials (if needed) - Confirm write access to output directories State_Validation: - Ensure clean working tree (for git operations) - Check for file locks - Verify no conflicting processes - Validate prerequisite operations completed Dependency_Verification: Tool_Availability: Required_Tools: "Tools marked as required for operation" Optional_Tools: "Tools that enhance but don't block operation" Fallback_Tools: "Alternative tools if primary unavailable" File_Dependencies: Input_Files: "Files that must exist for operation" Configuration_Files: "Config files that affect operation" Template_Files: "Templates needed for generation" Service_Dependencies: MCP_Servers: "Required MCP servers for operation" External_APIs: "External services needed" Database_Connections: "DB access if required" Risk_Assessment: Operation_Classification: Data_Loss_Risk: "Scale 1-10 based on destructiveness" Reversibility: "Can operation be undone automatically?" Scope_Impact: "How many files/systems affected?" Safety_Requirements: High_Risk: "Require explicit confirmation + backup" Medium_Risk: "Create checkpoint + warn user" Low_Risk: "Proceed with monitoring" Preparation_Actions: Backup_Creation: Critical_Files: "Files that will be modified" System_State: "Current git state, file timestamps" Configuration: "Relevant config before changes" Context_Capture: Current_State: "Working directory, git branch, file states" User_Context: "Active persona, command flags, session history" Environment: "Relevant environment variables, tool versions" ``` ## During-Execution Hooks ```yaml Progress_Monitoring: Real_Time_Tracking: Operation_Progress: "Percentage completion where measurable" Resource_Usage: "CPU, memory, disk, network utilization" Error_Frequency: "Number and types of errors encountered" Performance_Metrics: "Speed, efficiency, token usage" Checkpoint_Creation: Automatic_Triggers: - Major phase completion - Before risky operations - Regular intervals (time-based) - Resource threshold warnings Manual_Triggers: - User pause request - Error recovery points - External interruption Health_Monitoring: System_Health: - Available resources - Tool responsiveness - Network connectivity - File system status Operation_Health: - Progress rate - Error patterns - Quality indicators - User satisfaction signals Error_Handling_Integration: Error_Detection: Immediate: "Critical errors that require immediate stop" Recoverable: "Errors that can be retried or worked around" Warning: "Issues that should be logged but don't block" Recovery_Actions: Automatic_Retry: "Transient errors with exponential backoff" Fallback_Methods: "Alternative approaches when primary fails" User_Guidance: "When manual intervention needed" Adaptive_Optimization: Performance_Adjustment: Slow_Operations: "Switch to faster tools/methods" High_Resource_Usage: "Reduce scope or batch operations" Token_Efficiency: "Enable compression or caching" Strategy_Adjustment: Success_Pattern_Learning: "Adapt based on what works" Failure_Pattern_Avoidance: "Learn from what doesn't work" User_Preference_Adaptation: "Adjust to user's working style" ``` ## Post-Execution Hooks ```yaml Result_Verification: Output_Validation: Expected_Files: "Verify all expected outputs were created" File_Integrity: "Check file contents and formats" Quality_Checks: "Validate output meets requirements" System_State_Check: Git_Status: "Verify repository in expected state" File_Permissions: "Check file access rights" Process_State: "Ensure no hanging processes" Success_Confirmation: Objective_Achievement: Primary_Goals: "Did operation achieve stated objectives?" Quality_Standards: "Does output meet quality requirements?" User_Satisfaction: "Any user corrections or interruptions?" Metrics_Collection: Performance_Data: "Execution time, resource usage, efficiency" Quality_Metrics: "Error rate, retry count, success indicators" User_Experience: "Interruptions, corrections, satisfaction signals" Cleanup_Operations: Temporary_Resources: Temp_Files: "Remove temporary files created during operation" Cache_Cleanup: "Clear expired cache entries" Lock_Release: "Release any file or resource locks" System_Restoration: Working_Directory: "Restore original working directory" Environment_Variables: "Reset any temporary env vars" Process_Cleanup: "Terminate any background processes" Resource_Release: Memory_Cleanup: "Free allocated memory" Network_Connections: "Close unnecessary connections" File_Handles: "Close all opened files" Documentation_Update: Operation_Log: Execution_Record: "What was done, when, and how" Performance_Metrics: "Time, resources, efficiency data" Issues_Encountered: "Problems and how they were resolved" State_Updates: Project_State: "Update project status/progress" Configuration: "Update configs if changed" Dependencies: "Note any new dependencies added" ``` ## Lifecycle Integration Patterns ```yaml Command_Integration: Template_Usage: Pre_Execution: "@include shared/execution-lifecycle.yml#Pre_Execution" During_Execution: "@include shared/execution-lifecycle.yml#Progress_Monitoring" Post_Execution: "@include shared/execution-lifecycle.yml#Cleanup_Operations" Phase_Customization: Command_Specific: "Commands can override default hooks" Additional_Hooks: "Commands can add specific validation/cleanup" Skip_Phases: "Commands can skip irrelevant phases" Error_Recovery_Integration: Checkpoint_Strategy: Pre_Phase: "Create checkpoint before each major phase" Mid_Phase: "Create checkpoints during long operations" Recovery_Points: "Well-defined rollback points" Error_Escalation: Phase_Failure: "How to handle failure in each phase" Rollback_Strategy: "How to undo partial work" User_Notification: "What to tell user about failures" Performance_Integration: Timing_Collection: Phase_Duration: "Track time spent in each phase" Bottleneck_Identification: "Identify slow phases" Optimization_Opportunities: "Where to focus improvements" Resource_Monitoring: Peak_Usage: "Maximum resource usage during operation" Efficiency_Metrics: "Resource usage vs. output quality" Scaling_Behavior: "How resource usage scales with operation size" ``` ## Customization Framework ```yaml Hook_Customization: Override_Points: Before_Phase: "Custom actions before standard phase" Replace_Phase: "Complete replacement of standard phase" After_Phase: "Custom actions after standard phase" Conditional_Execution: Environment_Based: "Different hooks for dev/staging/prod" Operation_Based: "Different hooks for different operation types" User_Based: "Different hooks based on user preferences" Extension_Points: Additional_Validation: Custom_Checks: "Project-specific validation rules" External_Validation: "Integration with external systems" Policy_Enforcement: "Organizational policy checks" Enhanced_Monitoring: Custom_Metrics: "Project-specific performance metrics" External_Reporting: "Integration with monitoring systems" Alert_Integration: "Custom alerting rules" Specialized_Cleanup: Project_Cleanup: "Project-specific cleanup routines" External_Cleanup: "Integration with external systems" Compliance_Actions: "Regulatory compliance cleanup" ``` --- *Execution Lifecycle v1.0 - Common hooks and patterns for consistent SuperClaude operation execution*