iamvvekverma/fossil
GitHub: iamvvekverma/fossil
fossil 是一款死代码取证命令行工具,通过结合静态分析、git 历史挖掘和模式检测,帮助开发者精确定位死代码并安全地将其删除。
Stars: 1 | Forks: 0
发现死代码。了解其消亡原因。安全地将其删除。
`fossil` 是一款命令行取证工具,它不仅能够检测死代码,还能解释其*历史* —— 它在**何时**消亡,**什么**导致了它的消亡,是**谁**编写的,**为什么**会存在,以及是否真的**可以安全删除**。 它将静态分析、git 历史挖掘和模式检测结合到一个终端命令中,并在 3 秒内给出结果。 ## 为什么选择 fossil? 每个成熟的代码库都会积累死代码。现有的工具只能告诉你**什么**是死代码。但没有一个工具能告诉你**为什么**。 | 问题 | 其他工具 | fossil | |----------|-------------|--------| | 这个文件是否在任何地方被导入? | ✅ | ✅ | | 它是何时变成死代码的? | ❌ | ✅ — 包含确切日期的消亡提交 | | 哪个 PR 替代了它? | ❌ | ✅ — PR 编号、标题、作者 | | 最初是谁编写的? | ❌ | ✅ — 来自 git blame 的原作者 | | 是否有“暂时保留”的注释? | ❌ | ✅ — 检测并验证条件 | | 可以安全删除吗? | ❌ | ✅ — 0–100% 的置信度评分 | | 能否为我自动删除? | ❌ | ✅ — 使用 `--yolo` 创建 PR | ## 安装说明 ``` pip install fossil-code ``` ## 快速开始 ``` # 单个文件的完整取证报告 fossil explain src/billing/legacy_processor.py # 扫描整个目录 fossil scan ./src # 机器可读的 JSON 输出 fossil explain src/billing/legacy_processor.py --json # 优先删除积压 fossil clean ./src --threshold 85 # 纯文本模式(用于管道 / CI) fossil explain src/billing/legacy_processor.py --plain ``` ## 示例输出 ``` ╭─────────────────────────────────── fossil ───────────────────────────────────╮ │ │ │ FORENSIC REPORT src/billing/legacy_processor.py │ │ Status ● DEAD Language Python │ │ ╭─────────────────────────────── History ────────────────────────────────╮ │ │ │ Dead since 2023-03-14 │ │ │ │ Death commit a3f9b21 "Migrate to Stripe v3 — replace legacy │ │ │ │ SCA handler (#441)" │ │ │ │ PR #441 · Migrate to Stripe v3 — replace legacy SCA │ │ │ │ handler (#441) │ │ │ │ Original by Sarah Chen · first committed 2022-06-12 │ │ │ ╰────────────────────────────────────────────────────────────────────────╯ │ │ ╭──────────────────────────── Temporary Hold ────────────────────────────╮ │ │ │ Pattern "keeping this around until Q2 rollout completes" (line 3) │ │ │ │ Status ✓ RESOLVED — PR #489 merged April 12, 2023 │ │ │ ╰────────────────────────────────────────────────────────────────────────╯ │ │ ╭─────────────────────────── Static Analysis ────────────────────────────╮ │ │ │ Call sites 0 Dynamic imports 0 │ │ │ │ Import refs 0 Reflection None detected │ │ │ │ Test references 0 Config refs 0 │ │ │ ╰────────────────────────────────────────────────────────────────────────╯ │ │ ╭────────────────────────────── Confidence ──────────────────────────────╮ │ │ │ 91% ██████████████████░░ HIGH CONFIDENCE · LOW RISK │ │ │ ╰────────────────────────────────────────────────────────────────────────╯ │ │ Suggested rm src/billing/legacy_processor.py │ │ Auto-PR fossil explain src/billing/legacy_processor.py --yolo │ │ Analysis duration: 1840ms │ │ │ ╰──────────────────────────────────────────────────────────────────────────────╯ ``` ## 工作原理 对于分析的每个文件,`fossil` 会在 3 秒内运行五个阶段: ``` flowchart LR Static[StaticAnalysis] Git[Git History
Mining] Pattern[Pattern
Detection] Scoring[Confidence
Scoring] Render[Output
Rendering] Static --> Git --> Pattern --> Scoring --> Render subgraph Details direction LR S1(imports, calls
dynamic, reflection) -.- Static G1(death commit
PR, author) -.- Git P1(TODO: remove
DEPRECATED) -.- Pattern C1(14 signals
0-100% score) -.- Scoring end style Static fill:#0d1117,stroke:#58a6ff,stroke-width:2px,color:#c9d1d9 style Git fill:#0d1117,stroke:#3fb950,stroke-width:2px,color:#c9d1d9 style Pattern fill:#0d1117,stroke:#d2a8ff,stroke-width:2px,color:#c9d1d9 style Scoring fill:#0d1117,stroke:#ff7b72,stroke-width:2px,color:#c9d1d9 style Render fill:#0d1117,stroke:#a5d6ff,stroke-width:2px,color:#c9d1d9 style Details fill:none,stroke:none linkStyle 0,1,2,3 stroke:#8b949e,stroke-width:2px ``` ### 置信度评分 置信度评分汇总了 14 个加权信号: | 信号 | 权重 | 方向 | |--------|--------|-----------| | 零调用点(静态) | +30 | 正向 | | 无动态引用 | +20 | 正向 | | 已确定消亡提交 | +15 | 正向 | | 临时保留已解决 | +10 | 正向 | | 无反射模式 | +10 | 正向 | | 死亡文件超过 90 天 | +8 | 正向 | | 找到 PR/迁移上下文 | +7 | 正向 | | 检测到动态导入 | −30 | 负向 | | 检测到反射/getattr | −20 | 负向 | | 文件在 30 天内被修改过 | −20 | 负向 | | 未解决的“暂时保留” | −15 | 负向 | | 语言未知(回退) | −15 | 负向 | | 发现测试文件引用 | −10 | 负向 | | 消亡提交不明确 | −10 | 负向 | **风险标签:** `85–100%` 高置信度 · 低风险 · `70–84%` 中高置信度 · `55–69%` 中等置信度 · `<55%` 低置信度 · 高风险 ## 命令 ### `fossil explain
标签:Git分析, Python, Python安全, SOC Prime, 云安全监控, 开发工具, 文档结构分析, 无后门, 死代码检测, 网络安全研究, 逆向工具, 静态分析