GACN/codebase-forensics
GitHub: GACN/codebase-forensics
一个基于 Git 历史和文件系统分析的代码库健康度诊断工具,从五个维度生成可视化的项目体检报告。
Stars: 0 | Forks: 0
# Codebase Forensics 🔍
**代码考古诊断**——基于 [The Git Commands I Run Before Reading Any Code](https://piechowski.io/post/git-commands-before-reading-code/) 方法论,适配有 git 和无 git 的真实项目环境。
## 这是什么
一个 AI Agent 技能(Hermes Agent Skill),当你给它一个项目路径,它会自动跑 5 个维度的诊断,输出一份 Material Design 风格的 HTML 体检报告。
不用读代码,就能知道:
- 哪些文件是定时炸弹
- 谁在扛着整个项目
- 哪里反复出问题
- 项目是在增长还是衰退
- 团队是在开发还是在救火
## 5 个诊断维度
| # | 维度 | 问题 | 有 git | 无 git |
|---|------|------|--------|--------|
| 1 | 变更热点 | 哪些文件被改得最多? | `git log --name-only` | 备份文件计数 |
| 2 | 巴士因子 | 谁在写代码?一个人走了项目会停吗? | `git shortlog -sn` | 文件所有权分析 |
| 3 | 故障聚类 | 哪里反复出问题? | `git log --grep="fix"` | 备份标签解析 |
| 4 | 项目活力 | 项目在增长还是衰退? | 月度 commit 统计 | 文件修改时间分布 |
| 5 | 救火频率 | 回滚/热修复有多频繁? | revert/hotfix 计数 | 备份密集度分析 |
## 快速开始
### 作为 Hermes Agent 技能
# 安装到 Hermes
# 把 SKILL.md 放到 ~/.hermes/skills/codebase-forensics/
# 使用:对 Agent 说
"分析一下 ~/my-project 这个项目"
"看看这个代码怎么样"
"代码考古:/opt/my-app"
### 独立使用(手动跑命令)
# Step 1: 变更热点
git log --format=format: --name-only --since="1 year ago" | sort | uniq -c | sort -nr | head -20
# Step 2: 巴士因子
git shortlog -sn --all
# Step 3: 故障聚类
git log --oneline --all --grep="fix\|bug\|error\|crash\|hotfix\|revert" | awk '{print $1}' | xargs -I {} git diff-tree --no-commit-id --name-only -r {} | sort | uniq -c | sort -nr | head -20
# Step 4: 项目活力
git log --format=format: --date=short --since="2 years ago" | cut -d' ' -f1 | sort | uniq -c
# Step 5: 救火频率
echo "Reverts: $(git log --oneline --all --grep='revert' --since='1 year ago' | wc -l)"
## 输出示例
诊断报告是 Material Design 风格的 HTML 页面,包含:
- 📊 概览指标卡片
- 🔥 变更热点表格(带风险等级徽章)
- 👥 巴士因子可视化
- ⏰ 故障时间线
- 📈 项目活力柱状图
- 🚒 救火频率统计
- 🏗️ 架构全景图
- ✅ 综合诊断结论
查看完整示例:[examples/zhongmeng-audit.html](examples/zhongmeng-audit.html)
## 适用场景
- 接手一个陌生项目,不知道从哪里读起
- 评估一个项目的技术债务
- 向老板汇报项目健康状况
- 新成员入职时快速了解项目历史
- AI Agent 构建的项目的质量审计
## 灵感来源
- [The Git Commands I Run Before Reading Any Code](https://piechowski.io/post/git-commands-before-reading-code/) — Ally Piechowski
- [Your Code as a Crime Scene](https://pragprog.com/titles/atcrime2/) — Adam Tornhill
- [2005 Microsoft Research Study](https://www.microsoft.com/en-us/research/publicftware-recurrence-and-bug-fixes/) — 代码变更与缺陷密度的关系
## License
MIT
标签:Git分析, 代码分析, 凭证管理, 多模态安全, 数据管道, 网络安全研究, 软件工程