Identifies unused code elements and redundant components
<command_structure>
<metadata>
<instruction>You must complete all three stages in order and cannot skip any stage or the completion indicator.</instruction>
</metadata>
<preparation_stage>
<description>Before you begin any work, you must validate that you have sufficient context and resources</description>
<requirements>
<requirement_list>
<requirement>Source code or script files are provided for analysis</requirement>
<requirement>Code is readable and parseable</requirement>
<requirement>Understanding of the programming language(s) involved</requirement>
<requirement>Access to analyze imports, exports, and cross-references</requirement>
</requirement_list>
</requirements>
<critical_validation>
<condition>If ANY requirement fails, immediately stop and respond with:</condition>
<error_response>ERROR: Insufficient context - missing [specific requirement]. Please provide the source code or script files to analyze.</error_response>
<instruction>Do not proceed to execution. Only continue if you can confirm you have everything needed.</instruction>
</critical_validation>
</preparation_stage>
<execution_stage>
<success_criteria>Complete markdown report identifying unused methods, variables, classes, and types with actionable removal recommendations</success_criteria>
<error_handling>
<policy>IF any step fails:</policy>
<steps>
<step>Log error with specific analysis component that failed</step>
<step>Attempt retry once with simpler analysis approach</step>
<step>If still failing, mark that component as INCOMPLETE and continue to next analysis step</step>
</steps>
</error_handling>
<sub-agents>
<agent>Function Analysis Agent: Scan for all method and function definitions, then cross-reference usage throughout codebase</agent>
<agent>Variable Analysis Agent: Identify all variable declarations and track read/write operations</agent>
<agent>Class/Type Analysis Agent: Locate all class definitions, interfaces, and custom types, then verify instantiation and references</agent>
<agent>Usage Cross-Reference Agent: Check for dynamic references, string-based calls, reflection usage, inheritance relationships, and import/export statements</agent>
<agent>Report Generation Agent: Compile findings into structured markdown with Executive Summary, detailed unused element lists, recommendations, and Code Health Summary</agent>
</sub-agents>
<execution_steps>
<instruction>Execute these steps in exact order:</instruction>
<step_list>
<step>Initialize specialized sub-agents for parallel code analysis</step>
<step>Execute sub-agent processing in coordinated sequence</step>
<step>Synthesize sub-agent outputs into unified redundancy analysis report</step>
</step_list>
</execution_steps>
</execution_stage>
<resolution_stage>
<description>Analyze the complete execution:</description>
<validation_areas>
<area>Verify all code elements were properly analyzed for usage</area>
<area>Confirm unused elements are definitively not referenced</area>
<area>Check that dynamic references and potential external usage are noted</area>
<area>Validate that report includes actionable removal recommendations</area>
<area>Ensure Code Health Summary provides accurate cleanup impact estimates</area>
</validation_areas>
<completion_indicator>
<format>Always end with:</format>
<template>
FLOW COMPLETE: ✓ execution finished - Status: [SUCCESS/PARTIAL/FAILED] - Timestamp: [completion time]
[Summary of execution and outcomes]
</template>
</completion_indicator>
</resolution_stage>
</command_structure>