Phase 1: Gather Session Data
```bash
# Get the diff of changes
git diff HEAD~1 --stat
git diff HEAD~1
# Get commit message
git log -1 --pretty=format:"%s%n%n%b"
# Get list of modified files
git diff HEAD~1 --name-only
```
Phase 2: Analyze File Insights
For each modified file, extract:
- Purpose: What role does this file play?
- Changes made: What was the modification? Focus on the "why" not just "what"
- Patterns used: What coding patterns were applied?
- Gotchas: Any file-specific traps?
Good example:
```json
{
"path": "src/stores/terminal-store.ts",
"purpose": "Zustand store managing terminal session state with immer middleware",
"changes_made": "Added setAssociatedTask action to link terminals with tasks",
"patterns_used": ["Zustand action pattern", "immer state mutation"],
"gotchas": ["State changes must go through actions, not direct mutation"]
}
```
Bad example (too vague):
```json
{
"path": "src/stores/terminal-store.ts",
"purpose": "A store file",
"changes_made": "Added some code",
"patterns_used": [],
"gotchas": []
}
```
Phase 3: Extract Patterns
Only extract patterns that are reusable:
- Must apply to more than just this one case
- Include where/when to apply the pattern
- Reference a concrete example in the codebase
Good example:
```json
{
"pattern": "Use e.stopPropagation() on interactive elements inside containers with onClick handlers",
"applies_to": "Any clickable element nested inside a parent with click handling",
"example": "Terminal.tsx header - dropdown needs stopPropagation to prevent focus stealing"
}
```
Phase 4: Document Gotchas
Must be specific and actionable:
- Include what triggers the problem
- Include how to solve or prevent it
- Avoid generic advice ("be careful with X")
Good example:
```json
{
"gotcha": "Terminal header onClick steals focus from child interactive elements",
"trigger": "Adding buttons/dropdowns to Terminal header without stopPropagation",
"solution": "Call e.stopPropagation() in onClick handlers of child elements"
}
```
Phase 5: Document Approach Outcome
Capture the learning from success or failure:
- If succeeded: What made this approach work? What was key?
- If failed: Why did it fail? What would have worked instead?
- Alternatives tried: What other approaches were attempted?
This helps future sessions learn from past attempts.
Phase 6: Generate Recommendations
Specific, actionable advice for future work:
- Must be implementable by a future session
- Should be specific to this codebase, not generic
- Focus on what's next or what to watch out for
Good: "When adding more controls to Terminal header, follow the dropdown pattern in this session - use stopPropagation and position relative to header"
Bad: "Write good code" or "Test thoroughly"
Phase 7: Output Structured Insights
Create the structured insight output:
```markdown
# Session Insights: [Task Name]