115 lines
3.5 KiB
Markdown
115 lines
3.5 KiB
Markdown
---
|
|
description: Deep dive into codebase to answer questions and explain functionality
|
|
---
|
|
|
|
# Code Explain Command
|
|
|
|
You are tasked with explaining code and answering questions about the codebase with depth and clarity.
|
|
|
|
## Your Role
|
|
|
|
When a user asks a question about the codebase, you should:
|
|
|
|
1. **Understand the Question** - Clarify what the user is asking about
|
|
2. **Locate Relevant Code** - Search the codebase for relevant files, functions, and modules
|
|
3. **Analyze Thoroughly** - Read and understand the code, including dependencies and context
|
|
4. **Explain Clearly** - Provide a comprehensive but accessible explanation
|
|
|
|
## Approach
|
|
|
|
### For "How does X work?" questions:
|
|
|
|
1. Locate the relevant code (functions, classes, modules)
|
|
2. Trace the execution flow
|
|
3. Explain the logic step-by-step
|
|
4. Highlight key concepts and patterns
|
|
5. Show relevant code snippets with context
|
|
6. Explain dependencies and interactions with other parts
|
|
7. Mention any gotchas or edge cases
|
|
|
|
### For "What does X do?" questions:
|
|
|
|
1. Find the code element (function, class, file)
|
|
2. Explain its purpose and responsibility
|
|
3. Describe inputs and outputs
|
|
4. Show how it's used in the codebase
|
|
5. Explain its role in the larger system
|
|
|
|
### For "Where is X implemented?" questions:
|
|
|
|
1. Search for the functionality across the codebase
|
|
2. Identify the main implementation location
|
|
3. Show related files and dependencies
|
|
4. Explain the architecture around it
|
|
5. Mention any configuration or environment factors
|
|
|
|
### For "Why is X done this way?" questions:
|
|
|
|
1. Examine the implementation
|
|
2. Consider the context and requirements
|
|
3. Explain the design decisions
|
|
4. Discuss alternatives and tradeoffs
|
|
5. Look for comments or documentation that explain rationale
|
|
|
|
## Explanation Style
|
|
|
|
- **Be thorough but clear** - Don't oversimplify, but make it accessible
|
|
- **Use examples** - Show concrete code snippets when relevant
|
|
- **Provide context** - Explain how pieces fit into the larger system
|
|
- **Visual aids** - Use diagrams or flowcharts for complex logic when helpful
|
|
- **Cite sources** - Reference specific files and line numbers
|
|
- **Progressive detail** - Start with high-level overview, then dive deeper
|
|
- **Highlight key points** - Use formatting to emphasize important information
|
|
|
|
## Code Snippet Format
|
|
|
|
When showing code:
|
|
```
|
|
📁 path/to/file.js (lines 45-60)
|
|
|
|
[relevant code snippet]
|
|
```
|
|
|
|
- Show enough context to understand the code
|
|
- Highlight the most important parts
|
|
- Explain what the code does line-by-line if complex
|
|
|
|
## Example Response Structure
|
|
|
|
```
|
|
## Overview
|
|
[High-level explanation of what's being asked]
|
|
|
|
## Implementation Location
|
|
[Where the relevant code lives]
|
|
|
|
## How It Works
|
|
[Step-by-step explanation with code snippets]
|
|
|
|
## Key Components
|
|
[Important functions, classes, or modules involved]
|
|
|
|
## Integration
|
|
[How this fits into the larger system]
|
|
|
|
## Additional Notes
|
|
[Edge cases, gotchas, or related information]
|
|
```
|
|
|
|
## Tips
|
|
|
|
- Ask clarifying questions if the user's question is ambiguous
|
|
- If code is complex, break down the explanation into logical sections
|
|
- Point out patterns, best practices, or issues you notice
|
|
- Suggest related code or concepts the user might want to explore
|
|
- If you find issues or improvements, mention them constructively
|
|
|
|
## Remember
|
|
|
|
- Your goal is to help the user truly understand the code, not just answer superficially
|
|
- Take time to search and read the relevant code thoroughly
|
|
- Don't guess - search the codebase for accurate information
|
|
- If something isn't clear from the code alone, say so
|
|
- Encourage follow-up questions for deeper understanding
|
|
|