shannon-codebase-insight 0.4.0__tar.gz
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.
- shannon_codebase_insight-0.4.0/LICENSE +21 -0
- shannon_codebase_insight-0.4.0/PKG-INFO +209 -0
- shannon_codebase_insight-0.4.0/README.md +166 -0
- shannon_codebase_insight-0.4.0/pyproject.toml +131 -0
- shannon_codebase_insight-0.4.0/setup.cfg +4 -0
- shannon_codebase_insight-0.4.0/src/shannon_codebase_insight.egg-info/PKG-INFO +209 -0
- shannon_codebase_insight-0.4.0/src/shannon_codebase_insight.egg-info/SOURCES.txt +46 -0
- shannon_codebase_insight-0.4.0/src/shannon_codebase_insight.egg-info/dependency_links.txt +1 -0
- shannon_codebase_insight-0.4.0/src/shannon_codebase_insight.egg-info/entry_points.txt +7 -0
- shannon_codebase_insight-0.4.0/src/shannon_codebase_insight.egg-info/requires.txt +16 -0
- shannon_codebase_insight-0.4.0/src/shannon_codebase_insight.egg-info/top_level.txt +1 -0
- shannon_codebase_insight-0.4.0/src/shannon_insight/__init__.py +25 -0
- shannon_codebase_insight-0.4.0/src/shannon_insight/analyzers/__init__.py +8 -0
- shannon_codebase_insight-0.4.0/src/shannon_insight/analyzers/base.py +215 -0
- shannon_codebase_insight-0.4.0/src/shannon_insight/analyzers/go_analyzer.py +150 -0
- shannon_codebase_insight-0.4.0/src/shannon_insight/analyzers/python_analyzer.py +169 -0
- shannon_codebase_insight-0.4.0/src/shannon_insight/analyzers/typescript_analyzer.py +162 -0
- shannon_codebase_insight-0.4.0/src/shannon_insight/cache.py +214 -0
- shannon_codebase_insight-0.4.0/src/shannon_insight/cli.py +333 -0
- shannon_codebase_insight-0.4.0/src/shannon_insight/config.py +235 -0
- shannon_codebase_insight-0.4.0/src/shannon_insight/core.py +546 -0
- shannon_codebase_insight-0.4.0/src/shannon_insight/exceptions/__init__.py +31 -0
- shannon_codebase_insight-0.4.0/src/shannon_insight/exceptions/analysis.py +78 -0
- shannon_codebase_insight-0.4.0/src/shannon_insight/exceptions/base.py +18 -0
- shannon_codebase_insight-0.4.0/src/shannon_insight/exceptions/config.py +48 -0
- shannon_codebase_insight-0.4.0/src/shannon_insight/file_ops.py +218 -0
- shannon_codebase_insight-0.4.0/src/shannon_insight/logging_config.py +98 -0
- shannon_codebase_insight-0.4.0/src/shannon_insight/math/__init__.py +15 -0
- shannon_codebase_insight-0.4.0/src/shannon_insight/math/entropy.py +133 -0
- shannon_codebase_insight-0.4.0/src/shannon_insight/math/fusion.py +109 -0
- shannon_codebase_insight-0.4.0/src/shannon_insight/math/graph.py +209 -0
- shannon_codebase_insight-0.4.0/src/shannon_insight/math/robust.py +106 -0
- shannon_codebase_insight-0.4.0/src/shannon_insight/math/statistics.py +159 -0
- shannon_codebase_insight-0.4.0/src/shannon_insight/models.py +48 -0
- shannon_codebase_insight-0.4.0/src/shannon_insight/primitives/__init__.py +13 -0
- shannon_codebase_insight-0.4.0/src/shannon_insight/primitives/detector.py +318 -0
- shannon_codebase_insight-0.4.0/src/shannon_insight/primitives/extractor.py +278 -0
- shannon_codebase_insight-0.4.0/src/shannon_insight/primitives/fusion.py +373 -0
- shannon_codebase_insight-0.4.0/src/shannon_insight/primitives/recommendations.py +158 -0
- shannon_codebase_insight-0.4.0/src/shannon_insight/py.typed +2 -0
- shannon_codebase_insight-0.4.0/src/shannon_insight/security.py +284 -0
- shannon_codebase_insight-0.4.0/src/shannon_insight/utils/__init__.py +1 -0
- shannon_codebase_insight-0.4.0/tests/test_integration.py +155 -0
- shannon_codebase_insight-0.4.0/tests/test_math_entropy.py +132 -0
- shannon_codebase_insight-0.4.0/tests/test_math_fusion.py +106 -0
- shannon_codebase_insight-0.4.0/tests/test_math_graph.py +131 -0
- shannon_codebase_insight-0.4.0/tests/test_math_robust.py +98 -0
- shannon_codebase_insight-0.4.0/tests/test_math_statistics.py +144 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Naman Agarwal
|
|
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,209 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: shannon-codebase-insight
|
|
3
|
+
Version: 0.4.0
|
|
4
|
+
Summary: Multi-signal codebase quality analyzer using mathematical primitives
|
|
5
|
+
Author: Naman Agarwal
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/namanagarwal/shannon-insight
|
|
8
|
+
Project-URL: Documentation, https://github.com/namanagarwal/shannon-insight#readme
|
|
9
|
+
Project-URL: Repository, https://github.com/namanagarwal/shannon-insight
|
|
10
|
+
Project-URL: Bug Tracker, https://github.com/namanagarwal/shannon-insight/issues
|
|
11
|
+
Keywords: code-quality,static-analysis,codebase-analysis,metrics,entropy,mathematics
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: Topic :: Software Development :: Quality Assurance
|
|
15
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
22
|
+
Classifier: Environment :: Console
|
|
23
|
+
Classifier: Typing :: Typed
|
|
24
|
+
Requires-Python: >=3.9
|
|
25
|
+
Description-Content-Type: text/markdown
|
|
26
|
+
License-File: LICENSE
|
|
27
|
+
Requires-Dist: numpy>=1.22.0
|
|
28
|
+
Requires-Dist: scikit-learn>=1.0.0
|
|
29
|
+
Requires-Dist: scipy>=1.7.0
|
|
30
|
+
Requires-Dist: rich>=13.0.0
|
|
31
|
+
Requires-Dist: pydantic>=2.0.0
|
|
32
|
+
Requires-Dist: pydantic-settings>=2.0.0
|
|
33
|
+
Requires-Dist: diskcache>=5.6.0
|
|
34
|
+
Requires-Dist: typer>=0.9.0
|
|
35
|
+
Provides-Extra: dev
|
|
36
|
+
Requires-Dist: pytest>=7.0.0; extra == "dev"
|
|
37
|
+
Requires-Dist: pytest-cov>=4.0.0; extra == "dev"
|
|
38
|
+
Requires-Dist: mypy>=1.0.0; extra == "dev"
|
|
39
|
+
Requires-Dist: ruff>=0.1.0; extra == "dev"
|
|
40
|
+
Requires-Dist: build>=0.10.0; extra == "dev"
|
|
41
|
+
Requires-Dist: twine>=4.0.0; extra == "dev"
|
|
42
|
+
Dynamic: license-file
|
|
43
|
+
|
|
44
|
+
# Shannon Insight
|
|
45
|
+
|
|
46
|
+
[](https://github.com/namanagarwal/shannon-insight/actions/workflows/ci.yml)
|
|
47
|
+
[](https://pypi.org/project/shannon-insight/)
|
|
48
|
+
[](https://pypi.org/project/shannon-insight/)
|
|
49
|
+
[](LICENSE)
|
|
50
|
+
|
|
51
|
+
Multi-signal codebase quality analyzer using information-theoretic primitives. Named after Claude Shannon, father of information theory.
|
|
52
|
+
|
|
53
|
+
## Quick Start
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
pip install shannon-insight
|
|
57
|
+
shannon-insight /path/to/codebase
|
|
58
|
+
shannon-insight . --format json | jq .
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## What It Does
|
|
62
|
+
|
|
63
|
+
Shannon Insight scans your codebase and computes **5 orthogonal quality primitives** per file, then fuses them with consistency-weighted scoring to surface files that need attention:
|
|
64
|
+
|
|
65
|
+
| Primitive | What it measures | High means |
|
|
66
|
+
|-----------|-----------------|------------|
|
|
67
|
+
| **Structural Entropy** | AST node type distribution | Chaotic organization |
|
|
68
|
+
| **Network Centrality** | PageRank on dependency graph | Critical hub |
|
|
69
|
+
| **Churn Volatility** | File modification recency | Recently changed / unstable |
|
|
70
|
+
| **Semantic Coherence** | Import/export focus | Low: too many unrelated concerns |
|
|
71
|
+
| **Cognitive Load** | Functions x complexity x nesting | Overloaded file |
|
|
72
|
+
|
|
73
|
+
## Output Formats
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
# Rich terminal output (default) with summary dashboard
|
|
77
|
+
shannon-insight .
|
|
78
|
+
|
|
79
|
+
# Machine-readable JSON
|
|
80
|
+
shannon-insight . --format json
|
|
81
|
+
|
|
82
|
+
# Pipe-friendly CSV
|
|
83
|
+
shannon-insight . --format csv
|
|
84
|
+
|
|
85
|
+
# Just file paths (one per line)
|
|
86
|
+
shannon-insight . --format quiet
|
|
87
|
+
|
|
88
|
+
# Deep-dive on a specific file
|
|
89
|
+
shannon-insight . --explain complex.go
|
|
90
|
+
|
|
91
|
+
# Export to file
|
|
92
|
+
shannon-insight . --output report.json
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
## CI Integration
|
|
96
|
+
|
|
97
|
+
Use `--fail-above` to gate CI pipelines on code quality:
|
|
98
|
+
|
|
99
|
+
```bash
|
|
100
|
+
# Fail if any file scores above 2.0
|
|
101
|
+
shannon-insight . --format quiet --fail-above 2.0
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
Example GitHub Actions step:
|
|
105
|
+
|
|
106
|
+
```yaml
|
|
107
|
+
- name: Code quality gate
|
|
108
|
+
run: shannon-insight . --fail-above 2.0 --format quiet
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
## Configuration
|
|
112
|
+
|
|
113
|
+
Create `shannon-insight.toml` in your project root:
|
|
114
|
+
|
|
115
|
+
```toml
|
|
116
|
+
z_score_threshold = 1.5
|
|
117
|
+
fusion_weights = [0.2, 0.25, 0.2, 0.15, 0.2]
|
|
118
|
+
exclude_patterns = ["*_test.go", "vendor/*", "node_modules/*"]
|
|
119
|
+
max_file_size_mb = 10.0
|
|
120
|
+
enable_cache = true
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
Or use environment variables with `SHANNON_` prefix:
|
|
124
|
+
|
|
125
|
+
```bash
|
|
126
|
+
export SHANNON_Z_SCORE_THRESHOLD=2.0
|
|
127
|
+
export SHANNON_ENABLE_CACHE=false
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
## CLI Options
|
|
131
|
+
|
|
132
|
+
```
|
|
133
|
+
Options:
|
|
134
|
+
PATH Path to codebase directory [default: .]
|
|
135
|
+
-l, --language TEXT Language (auto, python, go, typescript, react, javascript)
|
|
136
|
+
-t, --top INTEGER Number of top files to display [1-1000]
|
|
137
|
+
-o, --output FILE Export JSON report to file
|
|
138
|
+
-f, --format TEXT Output format: rich, json, csv, quiet
|
|
139
|
+
-e, --explain TEXT Deep-dive on matching file(s)
|
|
140
|
+
--fail-above FLOAT CI gate: exit 1 if max score exceeds threshold
|
|
141
|
+
--threshold FLOAT Z-score threshold for anomaly detection
|
|
142
|
+
-c, --config FILE TOML configuration file
|
|
143
|
+
-v, --verbose Enable DEBUG logging
|
|
144
|
+
-q, --quiet Suppress all but ERROR logging
|
|
145
|
+
--no-cache Disable caching
|
|
146
|
+
--clear-cache Clear cache before running
|
|
147
|
+
-w, --workers INTEGER Parallel workers [1-32]
|
|
148
|
+
--version Show version and exit
|
|
149
|
+
|
|
150
|
+
Commands:
|
|
151
|
+
cache-info Show cache statistics
|
|
152
|
+
cache-clear Clear analysis cache
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
## Supported Languages
|
|
156
|
+
|
|
157
|
+
- **Python** - `.py` files
|
|
158
|
+
- **Go** - `.go` files
|
|
159
|
+
- **TypeScript/React** - `.ts`, `.tsx` files
|
|
160
|
+
- **JavaScript** - `.js`, `.jsx` files (uses TypeScript scanner)
|
|
161
|
+
|
|
162
|
+
Language is auto-detected by default. Override with `--language`.
|
|
163
|
+
|
|
164
|
+
## How It Works
|
|
165
|
+
|
|
166
|
+
```
|
|
167
|
+
CodebaseAnalyzer
|
|
168
|
+
Layer 1: Scanning - Language-specific file parsing
|
|
169
|
+
Layer 2: Extraction - Compute 5 orthogonal primitives per file
|
|
170
|
+
Layer 3: Detection - Z-score normalization + anomaly thresholding
|
|
171
|
+
Layer 4: Fusion - Consistency-weighted signal combination
|
|
172
|
+
Layer 5: Recommendations - Root cause attribution + actionable advice
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
Signal fusion uses coefficient of variation to penalize inconsistent signals:
|
|
176
|
+
|
|
177
|
+
```
|
|
178
|
+
consistency = 1 / (1 + CV)
|
|
179
|
+
final_score = consistency * |weighted_average|
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
See [docs/MATHEMATICAL_FOUNDATION.md](docs/MATHEMATICAL_FOUNDATION.md) for the full mathematical framework.
|
|
183
|
+
|
|
184
|
+
## Development
|
|
185
|
+
|
|
186
|
+
```bash
|
|
187
|
+
git clone https://github.com/namanagarwal/shannon-insight.git
|
|
188
|
+
cd shannon-insight
|
|
189
|
+
python -m venv .venv && source .venv/bin/activate
|
|
190
|
+
pip install -e ".[dev]"
|
|
191
|
+
|
|
192
|
+
make test # Run tests with coverage
|
|
193
|
+
make lint # Run ruff linter
|
|
194
|
+
make format # Format with ruff
|
|
195
|
+
make type-check # Run mypy
|
|
196
|
+
make all # Format + lint + type-check + test
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
## Contributing
|
|
200
|
+
|
|
201
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines.
|
|
202
|
+
|
|
203
|
+
## License
|
|
204
|
+
|
|
205
|
+
MIT License - see [LICENSE](LICENSE)
|
|
206
|
+
|
|
207
|
+
## Credits
|
|
208
|
+
|
|
209
|
+
Created by Naman Agarwal. Inspired by Claude Shannon's information theory, PageRank (Page & Brin), and cyclomatic complexity (McCabe).
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
# Shannon Insight
|
|
2
|
+
|
|
3
|
+
[](https://github.com/namanagarwal/shannon-insight/actions/workflows/ci.yml)
|
|
4
|
+
[](https://pypi.org/project/shannon-insight/)
|
|
5
|
+
[](https://pypi.org/project/shannon-insight/)
|
|
6
|
+
[](LICENSE)
|
|
7
|
+
|
|
8
|
+
Multi-signal codebase quality analyzer using information-theoretic primitives. Named after Claude Shannon, father of information theory.
|
|
9
|
+
|
|
10
|
+
## Quick Start
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
pip install shannon-insight
|
|
14
|
+
shannon-insight /path/to/codebase
|
|
15
|
+
shannon-insight . --format json | jq .
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## What It Does
|
|
19
|
+
|
|
20
|
+
Shannon Insight scans your codebase and computes **5 orthogonal quality primitives** per file, then fuses them with consistency-weighted scoring to surface files that need attention:
|
|
21
|
+
|
|
22
|
+
| Primitive | What it measures | High means |
|
|
23
|
+
|-----------|-----------------|------------|
|
|
24
|
+
| **Structural Entropy** | AST node type distribution | Chaotic organization |
|
|
25
|
+
| **Network Centrality** | PageRank on dependency graph | Critical hub |
|
|
26
|
+
| **Churn Volatility** | File modification recency | Recently changed / unstable |
|
|
27
|
+
| **Semantic Coherence** | Import/export focus | Low: too many unrelated concerns |
|
|
28
|
+
| **Cognitive Load** | Functions x complexity x nesting | Overloaded file |
|
|
29
|
+
|
|
30
|
+
## Output Formats
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
# Rich terminal output (default) with summary dashboard
|
|
34
|
+
shannon-insight .
|
|
35
|
+
|
|
36
|
+
# Machine-readable JSON
|
|
37
|
+
shannon-insight . --format json
|
|
38
|
+
|
|
39
|
+
# Pipe-friendly CSV
|
|
40
|
+
shannon-insight . --format csv
|
|
41
|
+
|
|
42
|
+
# Just file paths (one per line)
|
|
43
|
+
shannon-insight . --format quiet
|
|
44
|
+
|
|
45
|
+
# Deep-dive on a specific file
|
|
46
|
+
shannon-insight . --explain complex.go
|
|
47
|
+
|
|
48
|
+
# Export to file
|
|
49
|
+
shannon-insight . --output report.json
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## CI Integration
|
|
53
|
+
|
|
54
|
+
Use `--fail-above` to gate CI pipelines on code quality:
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
# Fail if any file scores above 2.0
|
|
58
|
+
shannon-insight . --format quiet --fail-above 2.0
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
Example GitHub Actions step:
|
|
62
|
+
|
|
63
|
+
```yaml
|
|
64
|
+
- name: Code quality gate
|
|
65
|
+
run: shannon-insight . --fail-above 2.0 --format quiet
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## Configuration
|
|
69
|
+
|
|
70
|
+
Create `shannon-insight.toml` in your project root:
|
|
71
|
+
|
|
72
|
+
```toml
|
|
73
|
+
z_score_threshold = 1.5
|
|
74
|
+
fusion_weights = [0.2, 0.25, 0.2, 0.15, 0.2]
|
|
75
|
+
exclude_patterns = ["*_test.go", "vendor/*", "node_modules/*"]
|
|
76
|
+
max_file_size_mb = 10.0
|
|
77
|
+
enable_cache = true
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
Or use environment variables with `SHANNON_` prefix:
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
export SHANNON_Z_SCORE_THRESHOLD=2.0
|
|
84
|
+
export SHANNON_ENABLE_CACHE=false
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
## CLI Options
|
|
88
|
+
|
|
89
|
+
```
|
|
90
|
+
Options:
|
|
91
|
+
PATH Path to codebase directory [default: .]
|
|
92
|
+
-l, --language TEXT Language (auto, python, go, typescript, react, javascript)
|
|
93
|
+
-t, --top INTEGER Number of top files to display [1-1000]
|
|
94
|
+
-o, --output FILE Export JSON report to file
|
|
95
|
+
-f, --format TEXT Output format: rich, json, csv, quiet
|
|
96
|
+
-e, --explain TEXT Deep-dive on matching file(s)
|
|
97
|
+
--fail-above FLOAT CI gate: exit 1 if max score exceeds threshold
|
|
98
|
+
--threshold FLOAT Z-score threshold for anomaly detection
|
|
99
|
+
-c, --config FILE TOML configuration file
|
|
100
|
+
-v, --verbose Enable DEBUG logging
|
|
101
|
+
-q, --quiet Suppress all but ERROR logging
|
|
102
|
+
--no-cache Disable caching
|
|
103
|
+
--clear-cache Clear cache before running
|
|
104
|
+
-w, --workers INTEGER Parallel workers [1-32]
|
|
105
|
+
--version Show version and exit
|
|
106
|
+
|
|
107
|
+
Commands:
|
|
108
|
+
cache-info Show cache statistics
|
|
109
|
+
cache-clear Clear analysis cache
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
## Supported Languages
|
|
113
|
+
|
|
114
|
+
- **Python** - `.py` files
|
|
115
|
+
- **Go** - `.go` files
|
|
116
|
+
- **TypeScript/React** - `.ts`, `.tsx` files
|
|
117
|
+
- **JavaScript** - `.js`, `.jsx` files (uses TypeScript scanner)
|
|
118
|
+
|
|
119
|
+
Language is auto-detected by default. Override with `--language`.
|
|
120
|
+
|
|
121
|
+
## How It Works
|
|
122
|
+
|
|
123
|
+
```
|
|
124
|
+
CodebaseAnalyzer
|
|
125
|
+
Layer 1: Scanning - Language-specific file parsing
|
|
126
|
+
Layer 2: Extraction - Compute 5 orthogonal primitives per file
|
|
127
|
+
Layer 3: Detection - Z-score normalization + anomaly thresholding
|
|
128
|
+
Layer 4: Fusion - Consistency-weighted signal combination
|
|
129
|
+
Layer 5: Recommendations - Root cause attribution + actionable advice
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
Signal fusion uses coefficient of variation to penalize inconsistent signals:
|
|
133
|
+
|
|
134
|
+
```
|
|
135
|
+
consistency = 1 / (1 + CV)
|
|
136
|
+
final_score = consistency * |weighted_average|
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
See [docs/MATHEMATICAL_FOUNDATION.md](docs/MATHEMATICAL_FOUNDATION.md) for the full mathematical framework.
|
|
140
|
+
|
|
141
|
+
## Development
|
|
142
|
+
|
|
143
|
+
```bash
|
|
144
|
+
git clone https://github.com/namanagarwal/shannon-insight.git
|
|
145
|
+
cd shannon-insight
|
|
146
|
+
python -m venv .venv && source .venv/bin/activate
|
|
147
|
+
pip install -e ".[dev]"
|
|
148
|
+
|
|
149
|
+
make test # Run tests with coverage
|
|
150
|
+
make lint # Run ruff linter
|
|
151
|
+
make format # Format with ruff
|
|
152
|
+
make type-check # Run mypy
|
|
153
|
+
make all # Format + lint + type-check + test
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
## Contributing
|
|
157
|
+
|
|
158
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines.
|
|
159
|
+
|
|
160
|
+
## License
|
|
161
|
+
|
|
162
|
+
MIT License - see [LICENSE](LICENSE)
|
|
163
|
+
|
|
164
|
+
## Credits
|
|
165
|
+
|
|
166
|
+
Created by Naman Agarwal. Inspired by Claude Shannon's information theory, PageRank (Page & Brin), and cyclomatic complexity (McCabe).
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=68.0", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "shannon-codebase-insight"
|
|
7
|
+
dynamic = ["version"]
|
|
8
|
+
description = "Multi-signal codebase quality analyzer using mathematical primitives"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.9"
|
|
11
|
+
license = "MIT"
|
|
12
|
+
authors = [
|
|
13
|
+
{name = "Naman Agarwal"}
|
|
14
|
+
]
|
|
15
|
+
keywords = ["code-quality", "static-analysis", "codebase-analysis", "metrics", "entropy", "mathematics"]
|
|
16
|
+
classifiers = [
|
|
17
|
+
"Development Status :: 4 - Beta",
|
|
18
|
+
"Intended Audience :: Developers",
|
|
19
|
+
"Topic :: Software Development :: Quality Assurance",
|
|
20
|
+
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
21
|
+
"Programming Language :: Python :: 3",
|
|
22
|
+
"Programming Language :: Python :: 3.9",
|
|
23
|
+
"Programming Language :: Python :: 3.10",
|
|
24
|
+
"Programming Language :: Python :: 3.11",
|
|
25
|
+
"Programming Language :: Python :: 3.12",
|
|
26
|
+
"Programming Language :: Python :: 3.13",
|
|
27
|
+
"Environment :: Console",
|
|
28
|
+
"Typing :: Typed",
|
|
29
|
+
]
|
|
30
|
+
dependencies = [
|
|
31
|
+
"numpy>=1.22.0",
|
|
32
|
+
"scikit-learn>=1.0.0",
|
|
33
|
+
"scipy>=1.7.0",
|
|
34
|
+
"rich>=13.0.0",
|
|
35
|
+
"pydantic>=2.0.0",
|
|
36
|
+
"pydantic-settings>=2.0.0",
|
|
37
|
+
"diskcache>=5.6.0",
|
|
38
|
+
"typer>=0.9.0",
|
|
39
|
+
]
|
|
40
|
+
|
|
41
|
+
[project.optional-dependencies]
|
|
42
|
+
dev = [
|
|
43
|
+
"pytest>=7.0.0",
|
|
44
|
+
"pytest-cov>=4.0.0",
|
|
45
|
+
"mypy>=1.0.0",
|
|
46
|
+
"ruff>=0.1.0",
|
|
47
|
+
"build>=0.10.0",
|
|
48
|
+
"twine>=4.0.0",
|
|
49
|
+
]
|
|
50
|
+
|
|
51
|
+
[project.scripts]
|
|
52
|
+
shannon-insight = "shannon_insight.cli:app"
|
|
53
|
+
|
|
54
|
+
[project.entry-points."shannon_insight.languages"]
|
|
55
|
+
go = "shannon_insight.analyzers.go_analyzer:GoScanner"
|
|
56
|
+
typescript = "shannon_insight.analyzers.typescript_analyzer:TypeScriptScanner"
|
|
57
|
+
python = "shannon_insight.analyzers.python_analyzer:PythonScanner"
|
|
58
|
+
|
|
59
|
+
[project.urls]
|
|
60
|
+
Homepage = "https://github.com/namanagarwal/shannon-insight"
|
|
61
|
+
Documentation = "https://github.com/namanagarwal/shannon-insight#readme"
|
|
62
|
+
Repository = "https://github.com/namanagarwal/shannon-insight"
|
|
63
|
+
"Bug Tracker" = "https://github.com/namanagarwal/shannon-insight/issues"
|
|
64
|
+
|
|
65
|
+
[tool.setuptools]
|
|
66
|
+
package-dir = {"" = "src"}
|
|
67
|
+
|
|
68
|
+
[tool.setuptools.packages.find]
|
|
69
|
+
where = ["src"]
|
|
70
|
+
|
|
71
|
+
[tool.setuptools.package-data]
|
|
72
|
+
shannon_insight = ["py.typed"]
|
|
73
|
+
|
|
74
|
+
[tool.setuptools.dynamic]
|
|
75
|
+
version = {attr = "shannon_insight.__version__"}
|
|
76
|
+
|
|
77
|
+
[tool.pytest.ini_options]
|
|
78
|
+
testpaths = ["tests"]
|
|
79
|
+
python_files = ["test_*.py"]
|
|
80
|
+
python_classes = ["Test*"]
|
|
81
|
+
python_functions = ["test_*"]
|
|
82
|
+
|
|
83
|
+
[tool.ruff]
|
|
84
|
+
target-version = "py39"
|
|
85
|
+
line-length = 100
|
|
86
|
+
|
|
87
|
+
[tool.ruff.lint]
|
|
88
|
+
select = [
|
|
89
|
+
"E", # pycodestyle errors
|
|
90
|
+
"W", # pycodestyle warnings
|
|
91
|
+
"F", # Pyflakes
|
|
92
|
+
"I", # isort
|
|
93
|
+
"B", # flake8-bugbear
|
|
94
|
+
"C4", # flake8-comprehensions
|
|
95
|
+
"UP", # pyupgrade
|
|
96
|
+
]
|
|
97
|
+
ignore = [
|
|
98
|
+
"E501", # line too long (handled by formatter)
|
|
99
|
+
"B008", # do not perform function calls in argument defaults
|
|
100
|
+
]
|
|
101
|
+
|
|
102
|
+
[tool.ruff.lint.per-file-ignores]
|
|
103
|
+
"__init__.py" = ["F401"]
|
|
104
|
+
|
|
105
|
+
[tool.ruff.lint.isort]
|
|
106
|
+
known-first-party = ["shannon_insight"]
|
|
107
|
+
|
|
108
|
+
[tool.ruff.format]
|
|
109
|
+
line-ending = "auto"
|
|
110
|
+
|
|
111
|
+
[tool.mypy]
|
|
112
|
+
python_version = "3.9"
|
|
113
|
+
warn_return_any = true
|
|
114
|
+
warn_unused_configs = true
|
|
115
|
+
disallow_untyped_defs = false
|
|
116
|
+
disallow_incomplete_defs = false
|
|
117
|
+
check_untyped_defs = true
|
|
118
|
+
disallow_untyped_decorators = false
|
|
119
|
+
no_implicit_optional = true
|
|
120
|
+
warn_redundant_casts = true
|
|
121
|
+
warn_unused_ignores = true
|
|
122
|
+
warn_no_return = true
|
|
123
|
+
warn_unreachable = true
|
|
124
|
+
strict_equality = true
|
|
125
|
+
show_error_codes = true
|
|
126
|
+
show_error_context = true
|
|
127
|
+
pretty = true
|
|
128
|
+
|
|
129
|
+
[[tool.mypy.overrides]]
|
|
130
|
+
module = ["sklearn.*", "diskcache.*", "typer.*", "rich.*"]
|
|
131
|
+
ignore_missing_imports = true
|