fossil-code 0.2.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,377 @@
1
+ Metadata-Version: 2.4
2
+ Name: fossil-code
3
+ Version: 0.2.0
4
+ Summary: Dead-code forensics CLI — find dead code, understand why it died, and safely delete it.
5
+ Author: fossil contributors
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/iamvvek/fossil
8
+ Project-URL: Documentation, https://github.com/iamvvek/fossil#readme
9
+ Project-URL: Repository, https://github.com/iamvvek/fossil
10
+ Project-URL: Issues, https://github.com/iamvvek/fossil/issues
11
+ Project-URL: Changelog, https://github.com/iamvvek/fossil/blob/main/CHANGELOG.md
12
+ Keywords: dead-code,static-analysis,git,cli,forensics,code-quality,refactoring,cleanup,developer-tools
13
+ Classifier: Development Status :: 4 - Beta
14
+ Classifier: Environment :: Console
15
+ Classifier: Intended Audience :: Developers
16
+ Classifier: Operating System :: OS Independent
17
+ Classifier: Programming Language :: Python :: 3
18
+ Classifier: Programming Language :: Python :: 3.11
19
+ Classifier: Programming Language :: Python :: 3.12
20
+ Classifier: Programming Language :: Python :: 3.13
21
+ Classifier: Topic :: Software Development :: Quality Assurance
22
+ Classifier: Topic :: Software Development :: Testing
23
+ Classifier: Topic :: Software Development :: Version Control :: Git
24
+ Classifier: Typing :: Typed
25
+ Requires-Python: >=3.11
26
+ Description-Content-Type: text/markdown
27
+ License-File: LICENSE
28
+ Requires-Dist: rich>=13.0
29
+ Provides-Extra: dev
30
+ Requires-Dist: pytest>=8.0; extra == "dev"
31
+ Requires-Dist: pytest-cov>=5.0; extra == "dev"
32
+ Requires-Dist: ruff>=0.6; extra == "dev"
33
+ Provides-Extra: typer
34
+ Requires-Dist: typer>=0.12; extra == "typer"
35
+ Provides-Extra: gitpython
36
+ Requires-Dist: GitPython>=3.1; extra == "gitpython"
37
+ Provides-Extra: llm
38
+ Requires-Dist: litellm>=1.0; extra == "llm"
39
+ Provides-Extra: github
40
+ Requires-Dist: PyGithub>=2.0; extra == "github"
41
+ Provides-Extra: gitlab
42
+ Requires-Dist: python-gitlab>=4.0; extra == "gitlab"
43
+ Provides-Extra: all
44
+ Requires-Dist: typer>=0.12; extra == "all"
45
+ Requires-Dist: GitPython>=3.1; extra == "all"
46
+ Requires-Dist: litellm>=1.0; extra == "all"
47
+ Requires-Dist: PyGithub>=2.0; extra == "all"
48
+ Requires-Dist: python-gitlab>=4.0; extra == "all"
49
+ Dynamic: license-file
50
+
51
+ <p align="center">
52
+ <img src="docs/banner.svg" alt="fossil — dead code forensics" width="600">
53
+ </p>
54
+
55
+ <p align="center">
56
+ <strong>Find dead code. Understand why it died. Safely delete it.</strong>
57
+ </p>
58
+
59
+ <p align="center">
60
+ <a href="https://github.com/iamvvek/fossil/actions/workflows/ci.yml"><img src="https://github.com/iamvvek/fossil/actions/workflows/ci.yml/badge.svg" alt="CI"></a>
61
+ <a href="https://pypi.org/project/fossil-code/"><img src="https://img.shields.io/pypi/v/fossil-code?color=%2334D058&label=pypi" alt="PyPI"></a>
62
+ <a href="https://pypi.org/project/fossil-code/"><img src="https://img.shields.io/pypi/pyversions/fossil-code" alt="Python"></a>
63
+ <a href="https://github.com/iamvvek/fossil/blob/main/LICENSE"><img src="https://img.shields.io/github/license/iamvvek/fossil?color=blue" alt="License"></a>
64
+ <a href="https://github.com/iamvvek/fossil/issues"><img src="https://img.shields.io/github/issues/iamvvek/fossil" alt="Issues"></a>
65
+ </p>
66
+
67
+ ---
68
+
69
+ `fossil` is a command-line forensics tool that goes beyond detecting dead code to explaining its *history* — **when** it died, **what** killed it, **who** wrote it, **why** it existed, and whether it is genuinely **safe to delete**.
70
+
71
+ It combines static analysis, git history mining, and pattern detection into a single terminal command that answers in under 3 seconds.
72
+
73
+ ## Why fossil?
74
+
75
+ Every mature codebase accumulates dead code. Existing tools tell you **what** is dead. None of them tell you **why**.
76
+
77
+ | Question | Other Tools | fossil |
78
+ |----------|-------------|--------|
79
+ | Is this file imported anywhere? | ✅ | ✅ |
80
+ | When did it become dead? | ❌ | ✅ — exact death commit with date |
81
+ | What PR replaced it? | ❌ | ✅ — PR number, title, author |
82
+ | Who wrote it originally? | ❌ | ✅ — original author from git blame |
83
+ | Is there a "keep for now" comment? | ❌ | ✅ — detects and verifies the condition |
84
+ | Is it safe to delete? | ❌ | ✅ — 0–100% confidence score |
85
+ | Can it auto-delete for me? | ❌ | ✅ — `--yolo` creates a PR |
86
+
87
+ ## Installation
88
+
89
+ ```bash
90
+ pip install fossil-code
91
+ ```
92
+
93
+ > Requires **Python 3.11+** and **git**.
94
+
95
+ ## Quick Start
96
+
97
+ ```bash
98
+ # Full forensic report for one file
99
+ fossil explain src/billing/legacy_processor.py
100
+
101
+ # Scan an entire directory
102
+ fossil scan ./src
103
+
104
+ # Machine-readable JSON output
105
+ fossil explain src/billing/legacy_processor.py --json
106
+
107
+ # Prioritized deletion backlog
108
+ fossil clean ./src --threshold 85
109
+
110
+ # Plain text mode (for piping / CI)
111
+ fossil explain src/billing/legacy_processor.py --plain
112
+ ```
113
+
114
+ ## Example Output
115
+
116
+ ```
117
+ ╭─────────────────────────────────── fossil ───────────────────────────────────╮
118
+ │ │
119
+ │ FORENSIC REPORT src/billing/legacy_processor.py │
120
+ │ Status ● DEAD Language Python │
121
+ │ ╭─────────────────────────────── History ────────────────────────────────╮ │
122
+ │ │ Dead since 2023-03-14 │ │
123
+ │ │ Death commit a3f9b21 "Migrate to Stripe v3 — replace legacy │ │
124
+ │ │ SCA handler (#441)" │ │
125
+ │ │ PR #441 · Migrate to Stripe v3 — replace legacy SCA │ │
126
+ │ │ handler (#441) │ │
127
+ │ │ Original by Sarah Chen · first committed 2022-06-12 │ │
128
+ │ ╰────────────────────────────────────────────────────────────────────────╯ │
129
+ │ ╭──────────────────────────── Temporary Hold ────────────────────────────╮ │
130
+ │ │ Pattern "keeping this around until Q2 rollout completes" (line 3) │ │
131
+ │ │ Status ✓ RESOLVED — PR #489 merged April 12, 2023 │ │
132
+ │ ╰────────────────────────────────────────────────────────────────────────╯ │
133
+ │ ╭─────────────────────────── Static Analysis ────────────────────────────╮ │
134
+ │ │ Call sites 0 Dynamic imports 0 │ │
135
+ │ │ Import refs 0 Reflection None detected │ │
136
+ │ │ Test references 0 Config refs 0 │ │
137
+ │ ╰────────────────────────────────────────────────────────────────────────╯ │
138
+ │ ╭────────────────────────────── Confidence ──────────────────────────────╮ │
139
+ │ │ 91% ██████████████████░░ HIGH CONFIDENCE · LOW RISK │ │
140
+ │ ╰────────────────────────────────────────────────────────────────────────╯ │
141
+ │ Suggested rm src/billing/legacy_processor.py │
142
+ │ Auto-PR fossil explain src/billing/legacy_processor.py --yolo │
143
+ │ Analysis duration: 1840ms │
144
+ │ │
145
+ ╰──────────────────────────────────────────────────────────────────────────────╯
146
+ ```
147
+
148
+ ## How It Works
149
+
150
+ For every file analyzed, `fossil` runs five stages in under 3 seconds:
151
+
152
+ ```
153
+ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐
154
+ │ Static │ │ Git │ │ Pattern │ │ Confidence │ │ Output │
155
+ │ Analysis │───▶│ History │───▶│ Detection │───▶│ Scoring │───▶│ Rendering │
156
+ │ │ │ Mining │ │ │ │ │ │ │
157
+ │ • imports │ │ • death │ │ • TODO: │ │ • 14 signals │ │ • Rich panel │
158
+ │ • call sites │ │ commit │ │ remove │ │ • 0-100% │ │ • JSON │
159
+ │ • dynamic │ │ • PR number │ │ • DEPRECATED │ │ • risk label │ │ • plain text │
160
+ │ • reflection │ │ • author │ │ • keep for │ │ │ │ │
161
+ │ │ │ • blame │ │ now │ │ │ │ │
162
+ └──────────────┘ └──────────────┘ └──────────────┘ └──────────────┘ └──────────────┘
163
+ ```
164
+
165
+ ### Confidence Score
166
+
167
+ The confidence score aggregates 14 weighted signals:
168
+
169
+ | Signal | Weight | Direction |
170
+ |--------|--------|-----------|
171
+ | Zero call sites (static) | +30 | Positive |
172
+ | No dynamic references | +20 | Positive |
173
+ | Death commit identified | +15 | Positive |
174
+ | Temporary hold resolved | +10 | Positive |
175
+ | No reflection patterns | +10 | Positive |
176
+ | File age > 90 days dead | +8 | Positive |
177
+ | PR/migration context found | +7 | Positive |
178
+ | Dynamic import detected | −30 | Negative |
179
+ | Reflection/getattr detected | −20 | Negative |
180
+ | File modified < 30 days ago | −20 | Negative |
181
+ | "Keep for now" unresolved | −15 | Negative |
182
+ | Language unknown (fallback) | −15 | Negative |
183
+ | Test file references found | −10 | Negative |
184
+ | Death commit ambiguous | −10 | Negative |
185
+
186
+ **Risk labels:** `85–100%` High Confidence · Low Risk · `70–84%` Medium-High · `55–69%` Medium · `<55%` Low Confidence · High Risk
187
+
188
+ ## Commands
189
+
190
+ ### `fossil explain <file>`
191
+
192
+ Full forensic report for a single file.
193
+
194
+ ```bash
195
+ fossil explain src/billing/legacy.py # Rich panel output
196
+ fossil explain src/billing/legacy.py --json # JSON output
197
+ fossil explain src/billing/legacy.py --plain # Plain text
198
+ fossil explain src/billing/legacy.py --no-cache # Skip cache
199
+ fossil explain src/billing/legacy.py --depth 2000 # Deeper git history
200
+ ```
201
+
202
+ | Flag | Default | Description |
203
+ |------|---------|-------------|
204
+ | `--json` | false | Machine-readable JSON output |
205
+ | `--plain` | false | Plain text (no Rich formatting) |
206
+ | `--no-color` | false | Disable ANSI colors |
207
+ | `--no-cache` | false | Skip cache read/write |
208
+ | `--depth N` | 500 | Max git commits to traverse |
209
+ | `--remote` | auto | Force remote: `github`, `gitlab`, `none`, `auto` |
210
+ | `--yolo` | false | Create deletion PR if confidence ≥ 90% |
211
+ | `--force-yolo` | false | Create deletion PR regardless of confidence |
212
+ | `--narrate` | false | LLM narration (requires provider config) |
213
+
214
+ ### `fossil scan [directory]`
215
+
216
+ Scan a directory for all dead files above a confidence threshold.
217
+
218
+ ```bash
219
+ fossil scan ./src # Scan with default 70% threshold
220
+ fossil scan ./src --threshold 85 # Only high-confidence results
221
+ fossil scan ./src --language py,js # Filter by language
222
+ fossil scan ./src --exclude "**/test*" # Exclude patterns
223
+ fossil scan ./src --json # JSON for CI pipelines
224
+ ```
225
+
226
+ ### `fossil clean [directory]`
227
+
228
+ Prioritized deletion backlog — ranked by confidence.
229
+
230
+ ```bash
231
+ fossil clean ./src --threshold 80 # Show deletion candidates
232
+ fossil clean ./src --dry-run # Preview what would be done
233
+ fossil clean ./src --json # Machine-readable output
234
+ ```
235
+
236
+ ### `fossil config`
237
+
238
+ ```bash
239
+ fossil config set github_token ghp_xxxx # Store GitHub token
240
+ fossil config set llm_provider openai # Configure LLM provider
241
+ fossil config show # Show config (tokens masked)
242
+ ```
243
+
244
+ ### `fossil cache`
245
+
246
+ ```bash
247
+ fossil cache clear # Delete analysis cache
248
+ fossil cache stats # Show cache statistics
249
+ ```
250
+
251
+ ## Exit Codes
252
+
253
+ | Code | Meaning | CI Use |
254
+ |------|---------|--------|
255
+ | `0` | Dead code found, report generated | Fail CI check |
256
+ | `1` | Unexpected error | Fail CI check |
257
+ | `2` | File not found | Fail CI check |
258
+ | `3` | Not a git repository | Fail CI check |
259
+ | `4` | File is NOT dead (actively used) | Pass CI check |
260
+
261
+ ## CI Integration
262
+
263
+ ### GitHub Actions
264
+
265
+ ```yaml
266
+ - name: Check for dead code
267
+ run: |
268
+ pip install fossil-code
269
+ fossil scan . --threshold 90 --json > dead_report.json
270
+ # Exit 0 = dead code found above 90% → fail the step
271
+ # Exit 4 = no dead code above 90% → pass
272
+ ```
273
+
274
+ ### Pre-commit Hook
275
+
276
+ ```bash
277
+ #!/bin/bash
278
+ fossil scan . --threshold 90 --json --no-cache > /dev/null 2>&1
279
+ if [ $? -eq 0 ]; then
280
+ echo "⚠️ Dead code detected above 90% confidence. Run 'fossil scan .' for details."
281
+ exit 1
282
+ fi
283
+ ```
284
+
285
+ ## Configuration
286
+
287
+ ### User Config: `~/.config/fossil/config.toml`
288
+
289
+ ```toml
290
+ github_token = ""
291
+ gitlab_token = ""
292
+ llm_api_key = ""
293
+ llm_provider = "openai"
294
+ llm_model = "gpt-4o-mini"
295
+ default_depth = 500
296
+ cache_ttl_hours = 24
297
+ ```
298
+
299
+ ### Project Config: `.fossil.toml`
300
+
301
+ Commit this to your repo root so the whole team shares settings:
302
+
303
+ ```toml
304
+ [analysis]
305
+ languages = ["py", "js", "ts"]
306
+ exclude_patterns = ["**/migrations/**", "**/generated/**"]
307
+
308
+ [thresholds]
309
+ minimum_confidence = 70
310
+ yolo_minimum_confidence = 90
311
+
312
+ [pr]
313
+ base_branch = "main"
314
+ pr_labels = ["dead-code-cleanup", "automated"]
315
+ ```
316
+
317
+ ### Environment Variables
318
+
319
+ All environment variables override config file values:
320
+
321
+ | Variable | Purpose |
322
+ |----------|---------|
323
+ | `GITHUB_TOKEN` | GitHub API authentication |
324
+ | `GITLAB_TOKEN` | GitLab API authentication |
325
+ | `FOSSIL_LLM_API_KEY` | LLM provider API key |
326
+ | `FOSSIL_LLM_PROVIDER` | LLM provider (`openai` / `anthropic` / `ollama`) |
327
+ | `FOSSIL_LLM_MODEL` | LLM model name |
328
+ | `NO_COLOR` | Disable ANSI colors ([no-color.org](https://no-color.org)) |
329
+
330
+ ## Language Support
331
+
332
+ | Language | Analyzer | Capability |
333
+ |----------|----------|------------|
334
+ | **Python** | `ast` module | Deep import, call, dynamic import, reflection analysis |
335
+ | JavaScript | Text fallback | Filename/symbol reference search |
336
+ | TypeScript | Text fallback | Filename/symbol reference search |
337
+ | Java | Text fallback | Filename/symbol reference search |
338
+ | Go | Text fallback | Filename/symbol reference search |
339
+ | Other | Text fallback | Filename reference search |
340
+
341
+ > **Python** gets the deepest analysis via the `ast` module. Other languages use conservative text-based reference search as a fallback. tree-sitter integration for deeper multi-language analysis is planned.
342
+
343
+ ## Offline by Default
344
+
345
+ `fossil` works with **zero network access**. The core analysis pipeline (static analysis → git mining → pattern detection → confidence scoring) runs entirely offline.
346
+
347
+ Network is only used for three **optional** features:
348
+ - GitHub/GitLab API — PR title/body lookup, `--yolo` PR creation
349
+ - LLM API — `--narrate` natural language explanation
350
+
351
+ ## Development
352
+
353
+ ```bash
354
+ git clone https://github.com/iamvvek/fossil.git
355
+ cd fossil
356
+ python3 -m venv .venv && source .venv/bin/activate
357
+ pip install -e ".[dev]"
358
+
359
+ # Run tests (85+ tests)
360
+ pytest -v
361
+
362
+ # Lint
363
+ ruff check src/ tests/
364
+ ```
365
+
366
+ See [CONTRIBUTING.md](CONTRIBUTING.md) for the full development guide.
367
+
368
+ ## Roadmap
369
+
370
+ - [x] **Phase 1** — Python forensics with Rich output
371
+ - [x] **Phase 2** — Multi-language scan, pattern detection, parallel processing
372
+ - [ ] **Phase 3** — GitHub/GitLab API integration, `--yolo` PR creation
373
+ - [ ] **Phase 4** — LLM narration, VS Code extension
374
+
375
+ ## License
376
+
377
+ [MIT](LICENSE) — use it, fork it, ship it.
@@ -0,0 +1,20 @@
1
+ fossil/__init__.py,sha256=sF80X1-Gp2nYaH2FvqSw4_PtTLPj9auJMpMqHB9wdMU,54
2
+ fossil/__main__.py,sha256=k76xuNziiOtwOFXdN182MOgYTnsh02gPbAXZPKBRnJM,67
3
+ fossil/analyzers.py,sha256=j6LtQVgdrkLDhelALLfTuF1cIEcovN7783bOtbFYtKk,7734
4
+ fossil/cache.py,sha256=40CUZ_hnOgOWrpL2oWjctXDHrrNHG3Yw-DUUwe6aF4k,8286
5
+ fossil/cli.py,sha256=F4M544LZxwmZ02JrXoCnA12RD0sQRrlUN64hK8ylHDA,15991
6
+ fossil/config_manager.py,sha256=f3ewnQ_wQyHoZbb7xlEQgoHeEn0iYe5XMD_u4ya6evI,4335
7
+ fossil/engine.py,sha256=emOg1v3UpDOxWec9gZbCRNBvk0USuCys4YFWeJbqsls,4145
8
+ fossil/git_miner.py,sha256=GzH8n9RNEwJ3WBEoOpqifBut0wB_Hizc_QYCiSw5JAc,2608
9
+ fossil/models.py,sha256=osDNwpXBHLdz-WMPiHSk3to5MU3eXY-g_oseYlKtgmE,2342
10
+ fossil/patterns.py,sha256=XbdOeYLMfTW3FCnkeaRrQsIGbbSVYvjftPjvU4uRUb0,3207
11
+ fossil/py.typed,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
12
+ fossil/render.py,sha256=YzqhKdC-kagHT44Oko9rp3zK96OdcZVGxAsYCbMJ4Y4,15927
13
+ fossil/repo.py,sha256=yZqGhWNwYF073AJyyZaaCcMMt3A96GDHYzxxEQ5wOmk,2461
14
+ fossil/scoring.py,sha256=wZ3ei4J2OrogdjxUNKPmxW_7i6sFqRFG6XgxefTvZ5A,3744
15
+ fossil_code-0.2.0.dist-info/licenses/LICENSE,sha256=eHfGgwJp1zpBmjwovhWC2pkn0h5kUzPN8N0_u_F46uk,1076
16
+ fossil_code-0.2.0.dist-info/METADATA,sha256=eOSfvRY4nQD8XC4Ft69XL-ntZJyFPJjaNgrZlUPDj_k,16907
17
+ fossil_code-0.2.0.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
18
+ fossil_code-0.2.0.dist-info/entry_points.txt,sha256=eT9xquawhlRHCuRx8qd_K97UMBXsHO1CiMlpFSQPEGk,43
19
+ fossil_code-0.2.0.dist-info/top_level.txt,sha256=deMoGGjKs-kVwsKuQw7RHxluMyC3xz6XC2q4EMBT8Xw,7
20
+ fossil_code-0.2.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (82.0.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ fossil = fossil.cli:main
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 fossil contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1 @@
1
+ fossil