codedna-analyzer 1.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.
- codedna_analyzer-1.4.0/LICENSE +21 -0
- codedna_analyzer-1.4.0/PKG-INFO +425 -0
- codedna_analyzer-1.4.0/README.md +387 -0
- codedna_analyzer-1.4.0/codedna/__init__.py +3 -0
- codedna_analyzer-1.4.0/codedna/analyzers/__init__.py +1 -0
- codedna_analyzer-1.4.0/codedna/analyzers/ai_analyzer.py +111 -0
- codedna_analyzer-1.4.0/codedna/analyzers/architecture_detector.py +150 -0
- codedna_analyzer-1.4.0/codedna/analyzers/cache_manager.py +70 -0
- codedna_analyzer-1.4.0/codedna/analyzers/code_smell_detector.py +302 -0
- codedna_analyzer-1.4.0/codedna/analyzers/complexity_analyzer.py +329 -0
- codedna_analyzer-1.4.0/codedna/analyzers/dependency_mapper.py +171 -0
- codedna_analyzer-1.4.0/codedna/analyzers/developer_analyzer.py +148 -0
- codedna_analyzer-1.4.0/codedna/analyzers/diff_engine.py +395 -0
- codedna_analyzer-1.4.0/codedna/analyzers/dna_generator.py +308 -0
- codedna_analyzer-1.4.0/codedna/analyzers/evolution_engine.py +193 -0
- codedna_analyzer-1.4.0/codedna/analyzers/github_analyzer.py +86 -0
- codedna_analyzer-1.4.0/codedna/analyzers/language_detector.py +151 -0
- codedna_analyzer-1.4.0/codedna/analyzers/repo_cloner.py +91 -0
- codedna_analyzer-1.4.0/codedna/analyzers/security_detector.py +271 -0
- codedna_analyzer-1.4.0/codedna/analyzers/structure_analyzer.py +91 -0
- codedna_analyzer-1.4.0/codedna/ci/__init__.py +5 -0
- codedna_analyzer-1.4.0/codedna/ci/gatekeeper.py +421 -0
- codedna_analyzer-1.4.0/codedna/cli.py +839 -0
- codedna_analyzer-1.4.0/codedna/compliance/__init__.py +5 -0
- codedna_analyzer-1.4.0/codedna/compliance/sbom.py +410 -0
- codedna_analyzer-1.4.0/codedna/config.py +167 -0
- codedna_analyzer-1.4.0/codedna/mcp/__init__.py +5 -0
- codedna_analyzer-1.4.0/codedna/mcp/protocol.py +65 -0
- codedna_analyzer-1.4.0/codedna/mcp/server.py +393 -0
- codedna_analyzer-1.4.0/codedna/remediation/__init__.py +5 -0
- codedna_analyzer-1.4.0/codedna/remediation/planner.py +244 -0
- codedna_analyzer-1.4.0/codedna/visualization/__init__.py +1 -0
- codedna_analyzer-1.4.0/codedna/visualization/html_export.py +507 -0
- codedna_analyzer-1.4.0/codedna/visualization/renderer.py +373 -0
- codedna_analyzer-1.4.0/codedna_analyzer.egg-info/PKG-INFO +425 -0
- codedna_analyzer-1.4.0/codedna_analyzer.egg-info/SOURCES.txt +77 -0
- codedna_analyzer-1.4.0/codedna_analyzer.egg-info/dependency_links.txt +1 -0
- codedna_analyzer-1.4.0/codedna_analyzer.egg-info/entry_points.txt +2 -0
- codedna_analyzer-1.4.0/codedna_analyzer.egg-info/requires.txt +13 -0
- codedna_analyzer-1.4.0/codedna_analyzer.egg-info/top_level.txt +1 -0
- codedna_analyzer-1.4.0/pyproject.toml +71 -0
- codedna_analyzer-1.4.0/setup.cfg +4 -0
- codedna_analyzer-1.4.0/tests/test_ai_analyzer.py +138 -0
- codedna_analyzer-1.4.0/tests/test_analyzers.py +417 -0
- codedna_analyzer-1.4.0/tests/test_architecture_detector.py +50 -0
- codedna_analyzer-1.4.0/tests/test_cli_diff_check.py +122 -0
- codedna_analyzer-1.4.0/tests/test_cli_v12.py +126 -0
- codedna_analyzer-1.4.0/tests/test_cli_v13.py +74 -0
- codedna_analyzer-1.4.0/tests/test_cli_v14.py +69 -0
- codedna_analyzer-1.4.0/tests/test_complexity_analyzer.py +145 -0
- codedna_analyzer-1.4.0/tests/test_config.py +118 -0
- codedna_analyzer-1.4.0/tests/test_dependency_mapper_errors.py +43 -0
- codedna_analyzer-1.4.0/tests/test_dependency_mapper_normalize.py +10 -0
- codedna_analyzer-1.4.0/tests/test_dependency_mapper_path_corruption.py +46 -0
- codedna_analyzer-1.4.0/tests/test_diff_engine.py +152 -0
- codedna_analyzer-1.4.0/tests/test_diff_gate.py +114 -0
- codedna_analyzer-1.4.0/tests/test_evolution_engine.py +94 -0
- codedna_analyzer-1.4.0/tests/test_gatekeeper.py +136 -0
- codedna_analyzer-1.4.0/tests/test_git_log_formatting.py +48 -0
- codedna_analyzer-1.4.0/tests/test_git_log_tformat.py +12 -0
- codedna_analyzer-1.4.0/tests/test_git_tformat.py +40 -0
- codedna_analyzer-1.4.0/tests/test_github_analyzer_security.py +52 -0
- codedna_analyzer-1.4.0/tests/test_lazy_load.py +24 -0
- codedna_analyzer-1.4.0/tests/test_max_file_size.py +49 -0
- codedna_analyzer-1.4.0/tests/test_mcp_server.py +166 -0
- codedna_analyzer-1.4.0/tests/test_mcp_v14.py +61 -0
- codedna_analyzer-1.4.0/tests/test_minimal.py +52 -0
- codedna_analyzer-1.4.0/tests/test_perf_analyzers.py +115 -0
- codedna_analyzer-1.4.0/tests/test_perf_architecture_detector.py +43 -0
- codedna_analyzer-1.4.0/tests/test_performance.py +52 -0
- codedna_analyzer-1.4.0/tests/test_remediation_planner.py +99 -0
- codedna_analyzer-1.4.0/tests/test_repo_cloner.py +42 -0
- codedna_analyzer-1.4.0/tests/test_sbom_generator.py +153 -0
- codedna_analyzer-1.4.0/tests/test_security_enhanced.py +94 -0
- codedna_analyzer-1.4.0/tests/test_security_expanded.py +105 -0
- codedna_analyzer-1.4.0/tests/test_structure_analyzer_edge_cases.py +28 -0
- codedna_analyzer-1.4.0/tests/test_structure_analyzer_perf.py +41 -0
- codedna_analyzer-1.4.0/tests/test_tformat_regression.py +11 -0
- codedna_analyzer-1.4.0/tests/test_visualization.py +138 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 shenald-dev
|
|
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,425 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: codedna-analyzer
|
|
3
|
+
Version: 1.4.0
|
|
4
|
+
Summary: 🧬 A genetic analyzer for software — reverse-engineer any codebase into a DNA profile.
|
|
5
|
+
Author-email: Shenal Diluksha <shenald@users.noreply.github.com>
|
|
6
|
+
Maintainer-email: shenald-dev <shenald@users.noreply.github.com>
|
|
7
|
+
License: MIT
|
|
8
|
+
Project-URL: Homepage, https://github.com/shenald-dev/codedna
|
|
9
|
+
Project-URL: Documentation, https://github.com/shenald-dev/codedna#readme
|
|
10
|
+
Project-URL: Repository, https://github.com/shenald-dev/codedna
|
|
11
|
+
Project-URL: Issues, https://github.com/shenald-dev/codedna/issues
|
|
12
|
+
Project-URL: Changelog, https://github.com/shenald-dev/codedna/blob/main/CHANGELOG.md
|
|
13
|
+
Keywords: code-analysis,architecture,dependency-graph,software-intelligence,dna,cli
|
|
14
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
15
|
+
Classifier: Environment :: Console
|
|
16
|
+
Classifier: Intended Audience :: Developers
|
|
17
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
18
|
+
Classifier: Operating System :: OS Independent
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
21
|
+
Classifier: Topic :: Software Development :: Quality Assurance
|
|
22
|
+
Classifier: Topic :: Utilities
|
|
23
|
+
Requires-Python: >=3.11
|
|
24
|
+
Description-Content-Type: text/markdown
|
|
25
|
+
License-File: LICENSE
|
|
26
|
+
Requires-Dist: click>=8.0.0
|
|
27
|
+
Requires-Dist: rich>=13.0.0
|
|
28
|
+
Requires-Dist: GitPython>=3.1.0
|
|
29
|
+
Requires-Dist: networkx>=3.0
|
|
30
|
+
Provides-Extra: dev
|
|
31
|
+
Requires-Dist: pytest>=8.0.0; extra == "dev"
|
|
32
|
+
Requires-Dist: pytest-cov>=4.1.0; extra == "dev"
|
|
33
|
+
Requires-Dist: pytest-subtests; extra == "dev"
|
|
34
|
+
Requires-Dist: ruff>=0.3.0; extra == "dev"
|
|
35
|
+
Provides-Extra: ai
|
|
36
|
+
Requires-Dist: openai>=1.0.0; extra == "ai"
|
|
37
|
+
Dynamic: license-file
|
|
38
|
+
|
|
39
|
+
<div align="center">
|
|
40
|
+
<img src="assets/logo.png" alt="CodeDNA Logo" width="250" />
|
|
41
|
+
|
|
42
|
+
<br/>
|
|
43
|
+
|
|
44
|
+
<h1>🧬 CodeDNA</h1>
|
|
45
|
+
<p><b>Software Intelligence System — A Genetic Analyzer for Code</b></p>
|
|
46
|
+
<i>Reverse-engineer any codebase into a DNA profile. Track genetic drift across releases, enforce architectural quality gates in CI/CD, and visualize system evolution.</i>
|
|
47
|
+
|
|
48
|
+
<br/>
|
|
49
|
+
|
|
50
|
+
[](https://pypi.org/project/codedna-analyzer/)
|
|
51
|
+
[](https://github.com/shenald-dev/codedna/actions)
|
|
52
|
+
[](https://python.org)
|
|
53
|
+
[](https://github.com/shenald-dev/codedna/releases)
|
|
54
|
+
[](LICENSE)
|
|
55
|
+
</div>
|
|
56
|
+
|
|
57
|
+
---
|
|
58
|
+
|
|
59
|
+
## 📑 Table of Contents
|
|
60
|
+
- [✨ What is CodeDNA?](#-what-is-codedna)
|
|
61
|
+
- [🚀 Flagship Capabilities](#-flagship-capabilities)
|
|
62
|
+
- [1. ⚙️ Declarative Configuration (`codedna.toml`)](#1-️-declarative-configuration-codednatoml)
|
|
63
|
+
- [2. 🛡️ Architectural Drift Regression Gating (`gate`)](#2-️-architectural-drift-regression-gating-gate)
|
|
64
|
+
- [3. 🧬 Genetic Drift & Architecture Diff Engine (`diff`)](#3--genetic-drift--architecture-diff-engine-diff)
|
|
65
|
+
- [4. 🛡️ CI/CD Quality Gatekeeper & SARIF / PR Markdown (`check`)](#4-️-cicd-quality-gatekeeper--sarif--pr-markdown-check)
|
|
66
|
+
- [5. 🔒 Enterprise Security & Shannon Entropy Scanner](#5--enterprise-security--shannon-entropy-scanner)
|
|
67
|
+
- [6. 🎯 Interactive Executive Radar & HTML Dashboard](#6--interactive-executive-radar--html-dashboard)
|
|
68
|
+
- [7. 🔌 Model Context Protocol Gateway (`mcp`)](#7--model-context-protocol-gateway-mcp)
|
|
69
|
+
- [8. ⚙️ Cyclomatic & Cognitive Complexity Engine (`complexity`)](#8-️-cyclomatic--cognitive-complexity-engine-complexity)
|
|
70
|
+
- [9. 🔒 Executive Compliance Audit (`audit`)](#9--executive-compliance-audit-audit)
|
|
71
|
+
- [10. 📦 Software Bill of Materials Engine (`sbom`)](#10--software-bill-of-materials-engine-sbom)
|
|
72
|
+
- [11. 🔧 Intelligent Auto-Remediation Engine (`fix` / `remediate`)](#11--intelligent-auto-remediation-engine-fix--remediate)
|
|
73
|
+
- [🏗️ Analysis Pipeline](#️-analysis-pipeline)
|
|
74
|
+
- [🛠️ Quick Start Guide](#️-quick-start-guide)
|
|
75
|
+
- [💻 Comprehensive Usage](#-comprehensive-usage)
|
|
76
|
+
- [Project Scaffolding (`init`)](#project-scaffolding-init)
|
|
77
|
+
- [Analyze a Codebase](#analyze-a-codebase)
|
|
78
|
+
- [Compare Codebases / Branches (`diff`)](#compare-codebases--branches-diff)
|
|
79
|
+
- [Gating Architectural Drift in CI (`gate`)](#gating-architectural-drift-in-ci-gate)
|
|
80
|
+
- [Enforce Quality Gates in CI (`check`)](#enforce-quality-gates-in-ci-check)
|
|
81
|
+
- [GitHub Actions Integration Examples](#github-actions-integration-examples)
|
|
82
|
+
- [🧬 Example Output](#-example-output)
|
|
83
|
+
- [🤝 Contributing](#-contributing)
|
|
84
|
+
|
|
85
|
+
---
|
|
86
|
+
|
|
87
|
+
## ✨ What is CodeDNA?
|
|
88
|
+
|
|
89
|
+
**CodeDNA** reverse-engineers any codebase and generates a comprehensive "DNA profile". It acts as an automated software architect, traversing tens of thousands of lines of code to distill exactly what a system does, how it is structured, where technical debt hides, and how it is mutating over time.
|
|
90
|
+
|
|
91
|
+
| Dimension | What It Reveals |
|
|
92
|
+
| :--- | :--- |
|
|
93
|
+
| 🏗️ **Architecture Pattern** | Monolith, MVC, Layered, Microservices, Plugin, Event-Driven |
|
|
94
|
+
| 📊 **Language Distribution** | Files, lines, and percentage share per language (50+ languages supported) |
|
|
95
|
+
| 🔗 **Dependency Graph** | Module topology, coupling density, circular dependency cycle detection |
|
|
96
|
+
| 🐛 **Code Smells & Hygiene** | God classes, runaway file length, bloated functions, Spaghetti Hub coupling |
|
|
97
|
+
| 🔒 **Security Posture** | Hardcoded secrets, AI API keys (OpenAI, Anthropic, HF), command & SQL injection |
|
|
98
|
+
| 👥 **Developer Genome** | Active contributors, bus factor risk, primary architects, collaboration |
|
|
99
|
+
| 📈 **Evolution Timeline** | Commit growth velocity, churn hotspots, architecture shifts |
|
|
100
|
+
| 🧬 **Genetic Drift** | Similarity scoring and mutation delta between branches, commits, or forks |
|
|
101
|
+
|
|
102
|
+
---
|
|
103
|
+
|
|
104
|
+
## 🚀 Flagship Capabilities
|
|
105
|
+
|
|
106
|
+
### 1. ⚙️ Declarative Configuration (`codedna.toml`)
|
|
107
|
+
Configure CodeDNA directly within your repository using `codedna.toml` or `pyproject.toml [tool.codedna]`:
|
|
108
|
+
- **Path Exclusion Globs:** Cleanly ignore test suites, build outputs, and minified bundles across all analyzers.
|
|
109
|
+
- **Secret Whitelisting:** Suppress false positives for intentional test fixtures or mock keys.
|
|
110
|
+
- **Custom Smell Thresholds:** Tailor file length, function lines, and method count thresholds to your project's standards.
|
|
111
|
+
- **Gate Policies:** Specify default CI quality constraints without repeating CLI flags.
|
|
112
|
+
|
|
113
|
+
```toml
|
|
114
|
+
# codedna.toml
|
|
115
|
+
ignore_paths = ["tests/*", "docs/*", "build/*"]
|
|
116
|
+
whitelisted_secrets = ["PUBLIC_KEY", "MOCK_TOKEN"]
|
|
117
|
+
|
|
118
|
+
[gate]
|
|
119
|
+
min_health = "Fair"
|
|
120
|
+
max_critical_smells = 0
|
|
121
|
+
fail_on_secrets = true
|
|
122
|
+
fail_on_circular = false
|
|
123
|
+
max_drift = 20.0
|
|
124
|
+
|
|
125
|
+
[smells]
|
|
126
|
+
max_file_lines = 650
|
|
127
|
+
max_function_lines = 120
|
|
128
|
+
god_class_methods = 20
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
### 2. 🛡️ Architectural Drift Regression Gating (`gate`)
|
|
132
|
+
Block pull requests that introduce architectural regressions or degrade code quality:
|
|
133
|
+
- **Baseline vs. Target:** Compare incoming PR branches against `origin/main` or pre-computed baseline JSON profiles.
|
|
134
|
+
- **Zero-Regression Policies:** Fails immediately if codebase health degrades (e.g., Healthy ➔ Critical), circular dependencies are introduced, or genetic drift exceeds allowable tolerance.
|
|
135
|
+
- **Exit Codes:** Exits with `0` on clean gates, `1` on regression breach.
|
|
136
|
+
|
|
137
|
+
```bash
|
|
138
|
+
# Evaluate drift between main branch and current working tree
|
|
139
|
+
codedna gate origin/main .
|
|
140
|
+
|
|
141
|
+
# Evaluate drift between two DNA profiles with custom similarity requirements
|
|
142
|
+
codedna gate baseline_profile.json pr_profile.json --min-similarity 85.0
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
### 3. 🧬 Genetic Drift & Architecture Diff Engine (`diff`)
|
|
146
|
+
Compare two repositories, branches, or pre-generated DNA profiles to measure **architectural drift** and **genetic similarity** (0.0% to 100.0%):
|
|
147
|
+
- **Similarity Scoring:** Multi-vector composite evaluation across language distributions, structural size, architectural patterns, dependency graph density, and health ratings.
|
|
148
|
+
- **Structural Deltas:** Track added/removed modules, file volume shifts, and language composition changes.
|
|
149
|
+
- **Coupling & Cycle Shifts:** Instant alerts if circular dependencies were introduced or resolved.
|
|
150
|
+
- **Inline Gating:** Pass `--fail-on-drift` to turn `diff` into a regression gatekeeper.
|
|
151
|
+
|
|
152
|
+
```bash
|
|
153
|
+
# Compare two local repositories
|
|
154
|
+
codedna diff ./repo-main ./repo-refactor
|
|
155
|
+
|
|
156
|
+
# Compare two saved DNA profile snapshots with inline drift gating
|
|
157
|
+
codedna diff reports/profile_v1.json reports/profile_v2.json --fail-on-drift
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
### 4. 🛡️ CI/CD Quality Gatekeeper & SARIF / PR Markdown (`check`)
|
|
161
|
+
Enforce architectural rules and security standards directly in your build and PR validation pipelines:
|
|
162
|
+
- **Policy Gates:** Reject PRs that breach health ratings, introduce hardcoded secrets, or exceed smell thresholds.
|
|
163
|
+
- **Native SARIF v2.1.0:** Generates OASIS SARIF output for GitHub Code Scanning tab annotations.
|
|
164
|
+
- **PR Review Markdown:** Generates formatted markdown tables (`--format markdown`) ready to post as PR review comments.
|
|
165
|
+
|
|
166
|
+
```bash
|
|
167
|
+
# Validate local repo in CI
|
|
168
|
+
codedna check .
|
|
169
|
+
|
|
170
|
+
# Generate Markdown table for GitHub Actions PR comment
|
|
171
|
+
codedna check . --format markdown --output pr-comment.md
|
|
172
|
+
|
|
173
|
+
# Export SARIF for GitHub Code Scanning
|
|
174
|
+
codedna check . --format sarif --output codedna-results.sarif
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
### 5. 🔒 Enterprise Security & Shannon Entropy Scanner
|
|
178
|
+
Built-in zero-dependency scanning for high-risk vulnerabilities, high-entropy secrets, and cloud credentials:
|
|
179
|
+
- **Shannon Entropy Secret Hunter:** Computes mathematical information density ($H(S) = -\sum p(c) \log_2 p(c)$) to surface unformatted API keys, hex secrets, and base64 private tokens without relying on brittle prefix guessing.
|
|
180
|
+
- **AI & Cloud API Tokens:** Detects exposed keys for OpenAI (`sk-...`), Anthropic (`sk-ant-...`), Google Gemini (`AIzaSy...`), Cohere, Mistral, Perplexity, DeepSeek, Groq, Hugging Face (`hf_...`), Pinecone (`pcsk_...`), AWS, GitHub, Stripe, and Slack.
|
|
181
|
+
- **Database Connection URIs:** Flags embedded passwords in database strings (`postgres://`, `mysql://`, `mongodb://`, `redis://`).
|
|
182
|
+
- **Insecure Deserialization & Injection:** Catches dangerous `pickle.loads()`, `yaml.unsafe_load()`, `subprocess.*(shell=True)`, and SQL f-strings.
|
|
183
|
+
|
|
184
|
+
### 6. 🎯 Interactive Executive Radar & HTML Dashboard
|
|
185
|
+
The generated HTML dashboard includes:
|
|
186
|
+
- **Pure SVG Radar Chart:** Five-dimensional assessment (Health & Hygiene, Security Posture, Modularity & Coupling, Architecture Cohesion, Team Resilience) rendered with zero external CDN dependencies.
|
|
187
|
+
- **Interactive Risk Filter:** Client-side instant filtering across code smells, god classes, and security warnings.
|
|
188
|
+
- **Print / PDF Ready:** Fully styled `@media print` support for executive architecture reviews.
|
|
189
|
+
|
|
190
|
+
### 7. 🔌 Model Context Protocol Gateway (`mcp`)
|
|
191
|
+
Expose CodeDNA as an official **MCP (2024-11-05 Specification)** JSON-RPC 2.0 server over stdio for AI coding assistants:
|
|
192
|
+
- Seamlessly integrates with **Claude Desktop**, **Cursor**, **Windsurf**, and **Antigravity**.
|
|
193
|
+
- Provides 7 standard tools: `codedna_analyze`, `codedna_inspect_architecture`, `codedna_security_audit`, `codedna_complexity_metrics`, `codedna_dependency_graph`, `codedna_quality_gate`, and `codedna_drift_diff`.
|
|
194
|
+
|
|
195
|
+
```json
|
|
196
|
+
// claude_desktop_config.json
|
|
197
|
+
{
|
|
198
|
+
"mcpServers": {
|
|
199
|
+
"codedna": {
|
|
200
|
+
"command": "codedna",
|
|
201
|
+
"args": ["mcp"]
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
### 8. ⚙️ Cyclomatic & Cognitive Complexity Engine (`complexity`)
|
|
208
|
+
Comprehensive function-level structural analysis using Python AST and universal token streaming:
|
|
209
|
+
- **McCabe Cyclomatic Complexity ($CC$):** Exact decision point counting (`if`, `while`, `for`, `except`, `assert`, boolean chains, comprehensions).
|
|
210
|
+
- **Cognitive Complexity:** Standard Sonarsource nesting-penalized evaluation.
|
|
211
|
+
- **Maintainability Index ($MI$):** Standard SEI maintainability scoring on a 0–100 scale with letter grade rankings (A through F).
|
|
212
|
+
|
|
213
|
+
### 9. 🛡️ Executive Compliance Audit (`audit`)
|
|
214
|
+
Fast, terminal-native security and architectural compliance audit with colorized Rich tables and strict exit codes (`0` for pass, `1` for policy breach).
|
|
215
|
+
|
|
216
|
+
### 10. 📦 Software Bill of Materials Engine (`sbom`)
|
|
217
|
+
Generate industry-standard, audit-ready SBOM manifests conforming to federal and enterprise compliance mandates:
|
|
218
|
+
- **CycloneDX (v1.5 JSON):** Complete component graphs, Package URLs (`purl`), and dependency relationships.
|
|
219
|
+
- **SPDX (v2.3 JSON):** Open source package catalogs, licensing assertions, and document hashes.
|
|
220
|
+
- **Multi-Ecosystem Discovery:** Parses Python (`pyproject.toml`, `requirements.txt`), Node.js (`package.json`, `package-lock.json`), Rust (`Cargo.toml`, `Cargo.lock`), and Go (`go.mod`).
|
|
221
|
+
```bash
|
|
222
|
+
# Generate CycloneDX SBOM
|
|
223
|
+
codedna sbom . --format cyclonedx --output sbom-cyclonedx.json
|
|
224
|
+
|
|
225
|
+
# Generate SPDX SBOM
|
|
226
|
+
codedna sbom . --format spdx --output sbom-spdx.json
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
### 11. 🔧 Intelligent Auto-Remediation Engine (`fix` / `remediate`)
|
|
230
|
+
Close the loop from diagnostic detection to resolution with deterministic code patches:
|
|
231
|
+
- **Bare Exceptions:** Safely transforms broad `except:` to typed `except Exception:` handlers.
|
|
232
|
+
- **Secret Extraction:** Refactors hardcoded API keys and tokens into `os.getenv(...)` variables.
|
|
233
|
+
- **Wildcard Resolution:** Pins open-ended `package.json` `"*"` wildcards to safe semantic ranges (`^1.0.0`).
|
|
234
|
+
- **Unified Diffs & Dry-Runs:** Preview patches before application or export unified patch files.
|
|
235
|
+
```bash
|
|
236
|
+
# Preview auto-remediation plan
|
|
237
|
+
codedna remediate . --dry-run
|
|
238
|
+
|
|
239
|
+
# Automatically patch safe findings on disk
|
|
240
|
+
codedna fix .
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
---
|
|
244
|
+
|
|
245
|
+
## 🏗️ Analysis Pipeline
|
|
246
|
+
|
|
247
|
+
CodeDNA executes a modular 10-stage analysis pipeline:
|
|
248
|
+
|
|
249
|
+
```mermaid
|
|
250
|
+
graph TD
|
|
251
|
+
A[Repository / Git Input] --> B[Repo Cloner / Path Resolver]
|
|
252
|
+
B --> C[Language Detector]
|
|
253
|
+
C --> D[Structure Analyzer]
|
|
254
|
+
D --> E[Dependency Mapper & Mermaid Graph]
|
|
255
|
+
E --> F[Architecture Pattern Detector]
|
|
256
|
+
F --> G[Code Smell & Hygiene Detector]
|
|
257
|
+
G --> H[Security & Secret Scanner]
|
|
258
|
+
H --> I[Developer & Bus Factor Analyzer]
|
|
259
|
+
I --> J[Evolution & Git Churn Engine]
|
|
260
|
+
J --> K[DNA Profile Synthesis]
|
|
261
|
+
K --> L[Terminal Visualizer]
|
|
262
|
+
K --> M[HTML Executive Dashboard]
|
|
263
|
+
K --> N[CI Gatekeeper & SARIF]
|
|
264
|
+
K --> O[Genetic Diff Engine]
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
---
|
|
268
|
+
|
|
269
|
+
## 🛠️ Quick Start Guide
|
|
270
|
+
|
|
271
|
+
### Installation
|
|
272
|
+
```bash
|
|
273
|
+
pip install codedna-analyzer
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
Or install via `pipx` or `uv`:
|
|
277
|
+
```bash
|
|
278
|
+
pipx install codedna-analyzer
|
|
279
|
+
# or
|
|
280
|
+
uv tool install codedna-analyzer
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
Verify installation:
|
|
284
|
+
```bash
|
|
285
|
+
codedna --version
|
|
286
|
+
# codedna, version 1.4.0
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
---
|
|
290
|
+
|
|
291
|
+
## 💻 Comprehensive Usage
|
|
292
|
+
|
|
293
|
+
### Project Scaffolding (`init`)
|
|
294
|
+
Scaffold a starter configuration file in your project:
|
|
295
|
+
```bash
|
|
296
|
+
codedna init .
|
|
297
|
+
```
|
|
298
|
+
|
|
299
|
+
### Analyze a Codebase
|
|
300
|
+
```bash
|
|
301
|
+
# Analyze a public GitHub repository
|
|
302
|
+
codedna analyze https://github.com/user/project
|
|
303
|
+
|
|
304
|
+
# Analyze local directory and save all reports (HTML, JSON, Markdown)
|
|
305
|
+
codedna analyze . --output reports/
|
|
306
|
+
|
|
307
|
+
# Headless mode for automated environments
|
|
308
|
+
codedna analyze . --no-visualize --output reports/ --format json
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
### Compare Codebases / Branches (`diff`)
|
|
312
|
+
```bash
|
|
313
|
+
# Terminal comparison
|
|
314
|
+
codedna diff ./release-1.0 ./release-2.0
|
|
315
|
+
|
|
316
|
+
# Generate Markdown diff report
|
|
317
|
+
codedna diff ./branch-a ./branch-b --format markdown --output diff-report.md
|
|
318
|
+
```
|
|
319
|
+
|
|
320
|
+
### Gating Architectural Drift in CI (`gate`)
|
|
321
|
+
```bash
|
|
322
|
+
# Block PR if architecture degrades compared to baseline
|
|
323
|
+
codedna gate baseline_dna.json current_dna.json
|
|
324
|
+
|
|
325
|
+
# Fail if similarity drops below 90% or circular dependencies are added
|
|
326
|
+
codedna gate ./main-repo ./pr-repo --min-similarity 90.0
|
|
327
|
+
```
|
|
328
|
+
|
|
329
|
+
### Enforce Quality Gates in CI (`check`)
|
|
330
|
+
```bash
|
|
331
|
+
# Standard CI check
|
|
332
|
+
codedna check .
|
|
333
|
+
|
|
334
|
+
# Fail on circular dependencies or critical smells
|
|
335
|
+
codedna check . --fail-on-circular --max-critical-smells 0
|
|
336
|
+
```
|
|
337
|
+
|
|
338
|
+
### GitHub Actions Integration Examples
|
|
339
|
+
|
|
340
|
+
#### 1. GitHub Code Scanning (SARIF)
|
|
341
|
+
```yaml
|
|
342
|
+
name: Architecture & Security Gate
|
|
343
|
+
on: [pull_request]
|
|
344
|
+
|
|
345
|
+
jobs:
|
|
346
|
+
codedna-gate:
|
|
347
|
+
runs-on: ubuntu-latest
|
|
348
|
+
steps:
|
|
349
|
+
- uses: actions/checkout@v4
|
|
350
|
+
with:
|
|
351
|
+
fetch-depth: 100
|
|
352
|
+
|
|
353
|
+
- name: Set up Python
|
|
354
|
+
uses: actions/setup-python@v5
|
|
355
|
+
with:
|
|
356
|
+
python-version: '3.11'
|
|
357
|
+
|
|
358
|
+
- name: Install CodeDNA
|
|
359
|
+
run: pip install codedna
|
|
360
|
+
|
|
361
|
+
- name: Run CodeDNA Gatekeeper & SARIF Export
|
|
362
|
+
run: codedna check . --format sarif --output codedna.sarif
|
|
363
|
+
|
|
364
|
+
- name: Upload SARIF to GitHub Code Scanning
|
|
365
|
+
if: always()
|
|
366
|
+
uses: github/codeql-action/upload-sarif@v3
|
|
367
|
+
with:
|
|
368
|
+
sarif_file: codedna.sarif
|
|
369
|
+
```
|
|
370
|
+
|
|
371
|
+
#### 2. Automated PR Review Comment
|
|
372
|
+
```yaml
|
|
373
|
+
- name: Generate PR Quality Table
|
|
374
|
+
run: codedna check . --format markdown --output pr-summary.md
|
|
375
|
+
|
|
376
|
+
- name: Comment PR
|
|
377
|
+
uses: actions/github-script@v7
|
|
378
|
+
with:
|
|
379
|
+
script: |
|
|
380
|
+
const fs = require('fs');
|
|
381
|
+
const body = fs.readFileSync('pr-summary.md', 'utf8');
|
|
382
|
+
github.rest.issues.createComment({
|
|
383
|
+
issue_number: context.issue.number,
|
|
384
|
+
owner: context.repo.owner,
|
|
385
|
+
repo: context.repo.repo,
|
|
386
|
+
body: body
|
|
387
|
+
});
|
|
388
|
+
```
|
|
389
|
+
|
|
390
|
+
---
|
|
391
|
+
|
|
392
|
+
## 🧬 Example Output
|
|
393
|
+
|
|
394
|
+
### Genetic Drift & Mutation Diff
|
|
395
|
+
```
|
|
396
|
+
┌─────────────────────────── 🧬 Architecture Diff ────────────────────────────┐
|
|
397
|
+
│ │
|
|
398
|
+
│ 🧬 CodeDNA Genetic Drift & Mutation Diff │
|
|
399
|
+
│ Baseline (A): ./v1.1.0 │
|
|
400
|
+
│ Target (B): ./v1.2.0 │
|
|
401
|
+
│ │
|
|
402
|
+
│ Genetic Similarity: 96.5% ███████████████████░ │
|
|
403
|
+
│ Mutation Verdict: Quality & Hygiene Improvement │
|
|
404
|
+
└─────────────────────────────────────────────────────────────────────────────┘
|
|
405
|
+
|
|
406
|
+
📊 Architectural & Structural Drift
|
|
407
|
+
┌──────────────────┬──────────────┬──────────────┬────────────────────────────┐
|
|
408
|
+
│ Dimension │ Baseline (A) │ Target (B) │ Drift / Delta │
|
|
409
|
+
├──────────────────┼──────────────┼──────────────┼────────────────────────────┤
|
|
410
|
+
│ Architecture │ Monolith │ Monolith │ Unchanged │
|
|
411
|
+
│ Health Score │ Fair │ Healthy │ Improved (crit: 0, warn: 0)│
|
|
412
|
+
│ Files Count │ - │ - │ +6 files │
|
|
413
|
+
│ Circular Deps │ None ✅ │ None ✅ │ Clean │
|
|
414
|
+
│ Bus Factor │ - │ - │ +1 │
|
|
415
|
+
└──────────────────┴──────────────┴──────────────┴────────────────────────────┘
|
|
416
|
+
```
|
|
417
|
+
|
|
418
|
+
---
|
|
419
|
+
|
|
420
|
+
## 🤝 Contributing
|
|
421
|
+
- 🐛 **Bug reports & ideas:** Open an issue on GitHub.
|
|
422
|
+
- 🚀 **Feature additions:** PRs welcome! Ensure all tests pass with `pytest` and code matches `ruff check`.
|
|
423
|
+
|
|
424
|
+
---
|
|
425
|
+
> *Software has DNA too. Decode it with CodeDNA.*
|