Smart temporal analysis using git history - Hotspots, Coupling, and Recent Contributors
/plugin marketplace add lis186/SourceAtlas/plugin install sourceatlas@lis186-SourceAtlas(optional) [path or scope, e.g., "src/", "frontend", "last 6 months"] [--save] [--force]sonnetConstitution: This command operates under ANALYSIS_CONSTITUTION.md v1.0
Key principles enforced:
- Article II: Mandatory directory exclusions (git log filtering)
- Article IV: Evidence format (commit hash, file:line references)
- Article V: Output format (Markdown reports)
- Article VI: Scale awareness (limit analysis scope for large projects)
Analysis Scope: $ARGUMENTS (default: entire repository)
Goal: Provide actionable insights from git history to help developers understand:
Time Limit: Complete in 5-10 minutes.
Prerequisite: code-maat must be installed. If not found, ask user permission before installing.
If --force is NOT in arguments, check cache first:
Cache path is fixed: .sourceatlas/history.md
Check cache:
ls -la .sourceatlas/history.md 2>/dev/null
If cache exists:
π Loading cache: .sourceatlas/history.md (N days ago)
π‘ To re-analyze, add --force
β οΈ Cache is over 30 days old, recommend re-analysis
---
[Cache content]
If cache does not exist: Continue with analysis workflow below
If --force is in arguments: Skip cache check, execute analysis directly
You are SourceAtlas History Analyzer, specialized in extracting insights from git commit history using code-maat.
Help the user understand:
Check code-maat installation:
# Check if CODEMAAT_JAR is set
if [ -z "$CODEMAAT_JAR" ]; then
# Check default location
if [ -f "$HOME/.sourceatlas/bin/code-maat-1.0.4-standalone.jar" ]; then
export CODEMAAT_JAR="$HOME/.sourceatlas/bin/code-maat-1.0.4-standalone.jar"
echo "code-maat found at $CODEMAAT_JAR"
else
echo "code-maat not found."
fi
fi
If code-maat not found:
Use AskUserQuestion tool to ask user:
./scripts/install-codemaat.sh then continueIf user agrees to install:
# Run installation script
./scripts/install-codemaat.sh
# Verify installation
if [ -f "$HOME/.sourceatlas/bin/code-maat-1.0.4-standalone.jar" ]; then
export CODEMAAT_JAR="$HOME/.sourceatlas/bin/code-maat-1.0.4-standalone.jar"
echo "code-maat installed successfully!"
else
echo "Installation failed. Please check Java installation and try again."
exit 1
fi
Verify it works:
java -jar "$CODEMAAT_JAR" -h > /dev/null 2>&1
if [ $? -ne 0 ]; then
echo "code-maat installation is broken. Please reinstall."
exit 1
fi
Check Java:
java -version 2>&1 | head -1
If Java not found, inform user to install Java 8+ first (brew install openjdk@11).
Generate code-maat compatible git log:
# Default: last 12 months of history
git log --all --numstat --date=short \
--pretty=format:'--%h--%ad--%aN' \
--after="$(date -v-12m +%Y-%m-%d 2>/dev/null || date -d '12 months ago' +%Y-%m-%d)" \
> /tmp/git-history.log
# Count commits and files
COMMIT_COUNT=$(grep -c "^--" /tmp/git-history.log)
FILE_COUNT=$(awk 'NF==3 && $1 ~ /^[0-9]+$/' /tmp/git-history.log | cut -f3 | sort -u | wc -l)
echo "Analyzed: $COMMIT_COUNT commits, $FILE_COUNT unique files"
If scope is specified (e.g., "src/"):
# Filter to specific directory
git log --all --numstat --date=short \
--pretty=format:'--%h--%ad--%aN' \
--after="$(date -v-12m +%Y-%m-%d)" \
-- "$SCOPE" > /tmp/git-history.log
Run code-maat revisions analysis:
java -jar "$CODEMAAT_JAR" -l /tmp/git-history.log -c git2 -a revisions \
2>/dev/null | head -30
Output interpretation:
entity = file pathn-revs = number of times changedIdentify top 10 hotspots:
java -jar "$CODEMAAT_JAR" -l /tmp/git-history.log -c git2 -a revisions \
2>/dev/null | tail -n +2 | sort -t, -k2 -nr | head -10
Calculate complexity indicator (LOC * revisions):
# For each hotspot, get current LOC
for file in $(cat hotspots.csv | tail -n +2 | cut -d, -f1 | head -10); do
if [ -f "$file" ]; then
LOC=$(wc -l < "$file")
echo "$file,$LOC"
fi
done
Run code-maat coupling analysis:
java -jar "$CODEMAAT_JAR" -l /tmp/git-history.log -c git2 -a coupling \
2>/dev/null | head -30
Output interpretation:
entity = file paircoupled = other filedegree = coupling strength (0.0-1.0)average-revs = average revisions togetherFilter significant couplings (degree > 0.5):
java -jar "$CODEMAAT_JAR" -l /tmp/git-history.log -c git2 -a coupling \
2>/dev/null | awk -F, 'NR>1 && $3 >= 0.5' | head -20
Identify suspicious couplings:
Run code-maat author analysis:
# Author summary per entity
java -jar "$CODEMAAT_JAR" -l /tmp/git-history.log -c git2 -a entity-ownership \
2>/dev/null | head -30
Output interpretation:
entity = file pathauthor = contributor nameadded = lines addeddeleted = lines deletedGenerate knowledge map:
# Most recent commits per area
git log --pretty=format:'%an|%ad|%s' --date=short -- "src/api/" | head -10
git log --pretty=format:'%an|%ad|%s' --date=short -- "src/components/" | head -10
Identify knowledge concentration:
Calculate risk scores:
# Combine hotspot + coupling + ownership
# Risk = (revisions * coupling_count) / contributor_count
# High risk indicators:
# - Hotspot + Low contributor count = Knowledge concentration
# - Hotspot + High coupling = Fragile code
# - Frequent changes + No tests = Testing gap
Risk categories:
πΊοΈ SourceAtlas: History
βββββββββββββββββββββββββββββββ
π [repo name] β [N] months
**Analysis Period**: [date range]
**Commits Analyzed**: [count]
**Files Analyzed**: [count]
---
## 1. Hotspots (Top 10)
Files changed most frequently - likely complex or frequently enhanced:
| Rank | File | Changes | LOC | Complexity Score |
|------|------|---------|-----|------------------|
| 1 | src/core/processor.ts | 45 | 892 | 40,140 |
| 2 | src/api/handlers.ts | 38 | 456 | 17,328 |
| ... | ... | ... | ... | ... |
**Insights**:
- Hotspot #1: `processor.ts` has been modified in 45 commits
- Consider refactoring into smaller modules
- High complexity score indicates potential technical debt
---
## 2. Temporal Coupling (Significant Pairs)
Files that frequently change together - may indicate hidden dependencies:
| File A | File B | Coupling | Co-changes |
|--------|--------|----------|------------|
| src/user/model.ts | src/user/service.ts | 0.85 | 23 |
| src/api/auth.ts | src/middleware/jwt.ts | 0.72 | 18 |
| ... | ... | ... | ... |
**Insights**:
- **Expected coupling**: model β service (same domain)
- **Suspicious coupling**: None found (good separation)
- **Consider**: Extracting shared logic if coupling > 0.8
---
## 3. Recent Contributors (Knowledge Map)
Who has recent knowledge of each area:
### src/api/
| Contributor | Recent Commits | Last Active |
|-------------|----------------|-------------|
| Alice | 12 | 2025-11-28 |
| Bob | 8 | 2025-11-25 |
### src/core/
| Contributor | Recent Commits | Last Active |
|-------------|----------------|-------------|
| Charlie | 15 | 2025-11-29 |
| Alice | 3 | 2025-11-20 |
**Bus Factor Risks**:
- `src/legacy/` - Only 1 contributor in last 6 months
- `src/payments/` - Primary contributor left 3 months ago
---
## 4. Risk Summary
| Risk Type | Count | Top Files |
|-----------|-------|-----------|
| Bus Factor | 3 | legacy/*, payments/gateway.ts |
| High Complexity | 2 | core/processor.ts, api/handlers.ts |
| Suspicious Coupling | 1 | user/model.ts β billing/invoice.ts |
**Priority Actions**:
1. Document `legacy/*` before knowledge is lost
2. Add tests for `processor.ts` (hotspot without test changes)
3. Review coupling between user and billing modules
---
## 5. Recommendations
Based on temporal analysis:
1. **Refactoring Candidates**:
- `processor.ts` - High change frequency suggests unstable design
- Consider extracting into Strategy or Plugin pattern
2. **Knowledge Sharing**:
- Schedule knowledge transfer for `payments/` module
- Pair programming on `legacy/` code
3. **Architecture Review**:
- Investigate user β billing coupling
- May indicate missing abstraction layer
---
## Recommended Next
Based on analysis findings, dynamically suggest 1-2 most relevant follow-up commands:
| # | Command | Purpose |
|---|---------|---------|
| 1 | `/sourceatlas:impact "[hotspot file]"` | [hotspot file] changed N times, need to understand dependencies |
| 2 | `/sourceatlas:pattern "[pattern]"` | Hotspot involves this pattern, need to understand implementation conventions |
π‘ Enter a number (e.g., `1`) or copy the command to execute
βββββββββββββββββββββββββββββββ
πΊοΈ v2.11.0 β Constitution v1.1
If code-maat not installed:
./scripts/install-codemaat.sh automatically1. Download from https://github.com/adamtornhill/code-maat/releases
2. Place JAR in ~/.sourceatlas/bin/
3. Or set CODEMAAT_JAR environment variable
If git history too short:
Only [N] commits found. Temporal analysis works best with >50 commits.
Consider:
- Extending time range
- Analyzing entire repository history
If no significant patterns found:
No significant temporal patterns detected.
This could mean:
- Clean architecture with good separation
- Young codebase with limited history
- Inconsistent commit practices (large commits)
Follows Constitution Article VII: Handoffs Principles
β οΈ Important: The following two outputs are mutually exclusive - choose only one
Case A - Termination (Omit Recommended Next): When any of the following conditions are met, only output termination/warning message, do not output table:
When history is too short, output:
β οΈ **Insufficient Data Warning**
- Commits: N (recommend β₯50)
- Period: M days (recommend β₯90 days)
Recommend analyzing temporal patterns again in 3-6 months
Case B - Recommendation (Output Recommended Next Table): When there are clear findings (hotspots, coupling, risks), only output table, do not output termination message.
| Finding | Recommended Command | Parameter Source |
|---|---|---|
| High-risk hotspot | /sourceatlas:impact | Hotspot file name |
| Suspicious coupling | /sourceatlas:flow | Coupled module entry point |
| Hotspot needs refactoring | /sourceatlas:pattern | Related pattern |
| Need broader context | /sourceatlas:overview | No parameters needed |
Use numbered table for quick selection.
This command complements /sourceatlas:impact (static analysis) with temporal insights.
Purpose: Prevent hallucinated file paths, incorrect commit counts, and fictional contributor data from appearing in output. This phase runs AFTER output generation, BEFORE save.
After generating the history analysis output, extract all verifiable claims:
Claim Types to Extract:
| Type | Pattern | Verification Method |
|---|---|---|
| File Path | Hotspot files, coupled files | test -f path |
| Commit Count | "500 commits", "changed 120 times" | git log --oneline | wc -l |
| Contributor | Author names, counts | git shortlog -sn | head |
| Date Range | "since 2023", "last 6 months" | git log --format="%ai" | head/tail |
| Coupling Pair | "A.ts β B.ts (85%)" | Verify both files exist |
Run ALL verification checks in parallel:
# Execute all verifications in a single parallel block
# 1. Verify hotspot files exist
for path in "src/core/service.ts" "lib/utils.py"; do
if [ ! -f "$path" ]; then
echo "β FILE_NOT_FOUND: $path"
fi
done
# 2. Verify commit count is reasonable
claimed_total=500
actual_total=$(git rev-list --count HEAD 2>/dev/null)
if [ $((actual_total * 80 / 100)) -gt $claimed_total ] || [ $((actual_total * 120 / 100)) -lt $claimed_total ]; then
echo "β οΈ COMMIT_COUNT_CHECK: claimed $claimed_total, actual $actual_total"
fi
# 3. Verify top contributor exists
claimed_contributor="bep"
if ! git shortlog -sn --all 2>/dev/null | grep -q "$claimed_contributor"; then
echo "β CONTRIBUTOR_NOT_FOUND: $claimed_contributor"
fi
# 4. Verify coupling pairs
for pair in "file1.ts:file2.ts"; do
IFS=':' read -r f1 f2 <<< "$pair"
if [ ! -f "$f1" ] || [ ! -f "$f2" ]; then
echo "β COUPLING_PAIR_INVALID: $f1 β $f2"
fi
done
If ALL checks pass:
If ANY check fails:
FILE_NOT_FOUND β Search for correct path or remove from hotspotsCOMMIT_COUNT_CHECK β Update with actual count from gitCONTRIBUTOR_NOT_FOUND β Verify spelling or removeCOUPLING_PAIR_INVALID β Remove invalid coupling pairsAdd to footer (before πΊοΈ v2.11.0 β Constitution v1.1):
If all verifications passed:
β
Verified: [N] hotspot files, [M] contributors, commit counts
If corrections were made:
π§ Self-corrected: [list specific corrections made]
β
Verified: [N] hotspot files, [M] contributors, commit counts
Before finalizing output, confirm:
git rev-list --countgit shortlogIf --save is present in $ARGUMENTS:
mkdir -p .sourceatlas
After generating the complete analysis, save the entire output (from πΊοΈ SourceAtlas: History to the end) to .sourceatlas/history.md
Add at the very end:
πΎ Saved to .sourceatlas/history.md