xiaohongshu
xiaohongshu
forensic-hotspot-finder
Use when planning refactoring priorities, investigating recurring bugs, identifying which files cause the most bugs, or determining problem areas to fix - identifies high-risk files by combining git change frequency with code complexity using research-backed formula (4-9x defect rates)
Full skill instructions
State explicitly: "Using forensic-hotspot-finder pattern"
Then follow these steps:
Hotspot analysis identifies files that are both frequently changed AND structurally complex. Research shows these files have 4-9x higher defect rates than normal code. This technique uses git history to find where bugs are most likely to occur.
Core principle: Change frequency × Complexity = Risk. Files with both characteristics are "hotspots" requiring immediate attention.
This is the research-backed formula - don't create custom variations:
Risk Score = Normalized Change Frequency × Normalized Complexity Factor
Where:
Change Frequency = (commits in time period) / (file age in days)
Complexity Factor = LOC + Indentation Depth + Function Count
Normalize BOTH factors to 0-1 scale within your codebase before multiplying.
Critical: Must have BOTH high frequency AND high complexity. High-change simple files are not hotspots.
Based on Microsoft Research and Google engineering studies:
Always cite these benchmarks when presenting hotspot findings to stakeholders.
| Purpose | Command |
|---|---|
| Change frequency | git log --since="12 months ago" --name-only --format="" | sort | uniq -c | sort -rn |
| File contributors | git log --since="12 months ago" --format="%an" -- FILE | sort | uniq -c | sort -rn |
| Commit details | git log --since="12 months ago" --follow --oneline -- FILE |
| Recent changes | git log --since="3 months ago" --stat -- FILE |
| Metric | Command | Interpretation |
|---|---|---|
| Lines of Code | wc -l FILE | >500 lines = high |
| Indentation depth | grep "^[[:space:]]" FILE | awk '{print length($0)-length(ltrim($0))}' | sort -n | tail -1 | >6 tabs/spaces = complex |
| Function count | grep -E "^(function|def|func|void|public|private)" FILE | wc -l | Context-dependent |
| Changes (12mo) | LOC | Risk Level | Action |
|---|---|---|---|
| >20 | >500 | CRITICAL | Refactor immediately |
| >15 | >300 | HIGH | Schedule for next sprint |
| >10 | >200 | MEDIUM | Monitor closely |
| <10 | any | LOW | Normal maintenance |
#!/bin/bash
# Basic hotspot finder - identifies top 10 risky files
TIME_PERIOD="12 months ago"
MIN_CHANGES=5
# Step 1: Get change frequency for all files
echo "Analyzing git history..."
git log --since="$TIME_PERIOD" --name-only --format="" | \
grep -v "^$" | \
sort | uniq -c | sort -rn | \
awk -v min="$MIN_CHANGES" '$1 >= min {print $1 "\t" $2}' > /tmp/changes.txt
# Step 2: For top 50 changed files, calculate complexity
echo "Calculating complexity scores..."
cat /tmp/changes.txt | head -50 | while read count file; do
if [ -f "$file" ]; then
loc=$(wc -l < "$file" 2>/dev/null || echo 0)
depth=$(grep "^[[:space:]]" "$file" 2>/dev/null | \
awk '{print length($0)-length($1)}' | \
sort -n | tail -1)
depth=${depth:-0}
# Risk score: changes * (LOC/100) * (depth/10)
risk=$(echo "$count * ($loc / 100) * (1 + $depth / 10)" | bc -l)
printf "%.2f\t%d\t%d\t%s\n" "$risk" "$count" "$loc" "$file"
fi
done | sort -rn > /tmp/hotspots.txt
# Step 3: Report top 10 hotspots
echo ""
echo "TOP 10 CODE HOTSPOTS"
echo "===================="
printf "%-10s %-10s %-10s %s\n" "Risk Score" "Changes" "LOC" "File"
echo "------------------------------------------------------------"
head -10 /tmp/hotspots.txt | while read risk changes loc file; do
printf "%-10.2f %-10d %-10d %s\n" "$risk" "$changes" "$loc" "$file"
done
echo ""
echo "Focus refactoring efforts on files with highest risk scores."
For more sophisticated analysis including:
Consider creating a supporting script (see pattern below) or using code analysis tools.
Problem: Inventing your own formula instead of using the research-backed approach.
# ❌ BAD: Custom formula without research backing
score = commits + (bugs × 3) + (size ÷ 100)
# ✅ GOOD: Use the normalized hotspot formula from this skill
risk = (commits / file_age) × (LOC + depth + functions)
# Then normalize both factors to 0-1 before multiplying
Fix: Use the hotspot formula from this skill. It's based on Microsoft Research showing 4-9x higher defects. Don't reinvent it.
Problem: Older files naturally have more commits, biasing results.
Fix: Always divide commit count by file age (in days or months). This is critical for accuracy.
Problem: High change + low complexity = active but healthy code (like simple config files).
Fix: Require BOTH high change AND high complexity. Check this explicitly. Simple, frequently changed files aren't hotspots.
Problem: Saying "this file is complex" without evidence.
Fix: Always cite: "Research shows hotspot files have 4-9x higher defect rates (Microsoft Research)". This makes recommendations credible.
Problem: Providing hotspot list without integration guidance.
Fix: After hotspot analysis, always suggest checking ownership (knowledge-mapping) and calculating costs (debt-quantification).
Before refactoring hotspots:
- File auth.js: 45 bugs/year, 28 changes/year
- File config.js: 32 bugs/year, 41 changes/year
- File api-handler.js: 38 bugs/year, 35 changes/year
After 2-week refactoring sprint (top 3 hotspots):
- auth.js: 12 bugs/year (-73%), 22 changes/year
- config.js: 18 bugs/year (-44%), 38 changes/year
- api-handler.js: 23 bugs/year (-39%), 31 changes/year
Overall bug reduction: 35%, Development velocity: +15%
Immediately suggest these next steps to the user:
Check ownership for single-owner hotspots (use forensic-knowledge-mapping)
Calculate business cost (use forensic-debt-quantification)
Track trends (use forensic-complexity-trends)
Find coupled files (use forensic-change-coupling)
"I've identified the top 10 hotspots using the forensic-hotspot-finder pattern.
The top 3 files with highest risk scores are:
1. manager.go (Score: 386) - 62 bug fixes, 2,471 LOC
2. Layout.tsx (Score: 371) - 61 bug fixes, 1,126 LOC
3. sessions.go (Score: 259) - 31 bug fixes, 1,799 LOC
Research shows hotspot files have 4-9x higher defect rates (Microsoft Research).
RECOMMENDED NEXT STEPS:
1. Check ownership (forensic-knowledge-mapping) - Are these single-owner risks?
2. Calculate business cost (forensic-debt-quantification) - What's the ROI?
3. Track trends (forensic-complexity-trends) - Are they getting worse?
Would you like me to proceed with any of these analyses?"
Always provide this integration guidance - it's what makes forensic analysis actionable.
For complete automation with JSON output and trend tracking, consider creating:
forensic-hotspot-finder/
├── SKILL.md (this file)
├── hotspot-analyzer.sh (complete analysis script)
└── visualize-hotspots.py (optional: generate charts)
xiaohongshu
technical spec
product ux expert
database patterns
Conduct multi-agent task orchestration and workflow coordination.
Initialize project with Conductor artifacts (product definition,
Expert in web animations, transitions, and motion design using Framer Motion and CSS
Creates Mermaid and ASCII diagrams for flowcharts, architecture, ERDs, state machines, mindmaps, and more. Use when user mentions diagram, flowchart, mermaid, ASCII diagram, text diagram, terminal diagram, visualize, C4, mindmap, architecture diagram, sequence diagram, ERD, or needs visual docume...
PostgreSQL bindings for H3 hexagonal grid system. Use when working with H3 cells in Postgres, including spatial indexing, geometry/geography integration, and raster analysis.
Context-Driven Development skill for projects using Conductor. Use this skill when you detect a `conductor/` directory in the project, when working on tasks defined in a `plan.md` file, or when the user asks about tracks, specs, or plans. Automatically applies TDD workflow, tracks task completion...
Display project status, active tracks, and next actions
Official Stakpak application containerization standard operating procedure, a step-by-step guidline to properly dockerize applications. This is a rule book curated by the Stakpak Team.
Generate, edit, and beat-sync AI video with leading models in one workspace.
The world's fastest calendar for remote work
Transform Your Design with AI Designer by ImgCreator.ai
Revolutionizing Video Production with AI-Powered Creativity
Extend an image past the frame and let AI fill the new aspect ratio.
Discover your celebrity doppelgänger with StarByFace!
ChainClarity explains 700+ crypto whitepapers in plain English, with layered summaries, comparisons, research tools, alerts, and a $4.99 Pro plan.
Opus.ai: Revolutionize Your Web Experience