CODYNEX Engine
README.md
<div align="center">
# ๐งฌ CODYNEX Engine

[](#-verify-it-yourself)
[](pyproject.toml)
[](LICENSE)
[](pyproject.toml)
[](pyproject.toml)
๐งฌ **CODYNEX Engine** โ codebase intelligence: an engine that reads your entire
project and builds a structured model of it โ architecture, dependency graph,
design decisions, bug history. **Blast-radius prediction** โ ask what breaks if
you touch `auth.py`, and get a ranked impact analysis. Apply a patch in an
isolated sandbox and see the test verdict before the change ever lands.
**Stdlib-only Python. Zero dependencies.**
</div>
## ๐ Quickstart
```bash
git clone https://github.com/Thegreatprabh/codynex-engine.git
cd DNA
pip install -e . # stdlib only โ nothing else to install
dna init ./my-project # ingest โ build the DNA
dna map # architecture: components + dependency stats
dna impact "auth.py" # blast radius: what breaks if I change this?
dna plan "change the login system" # predict a natural-language change
dna verify --patch fix.diff # sandbox: apply patch, run tests, report
dna watch # keep the DNA updated as files change
```
The DNA is saved as JSON at `~/.dna/<project>/dna.json` (dir `0700`).
Run `dna watch` during development, or re-run `dna init` after big changes.
## ๐งช How it works โ ingest โ model โ analyze โ verify
```
source code โโโบ INGEST โโโบ MODEL โโโบ ANALYZE โโโบ VERIFY
(.py files) ast parse ProjectDNA blast radius isolated
git log dep graph risk report sandbox
mining reverse decisions + pytest
graph
```
1. **Ingest** โ stdlib `ast` parses every Python file: imports (absolute
`pkg.sub` and relative `.sib` resolved to real files), functions, classes,
call edges. `git log` is mined for architectural decisions, bug history,
and churn hotspots. An **intent extractor** records what each component
is *for*: module docstring, README mentions, and the `test_*` names of
tests importing it. No git? The graph still builds โ history is skipped
gracefully.
2. **Model** โ a `ProjectDNA`: per-file components with one-line purpose
summaries, a dependency graph **and its reverse graph**, decisions,
hotspots, test coverage, and per-component intents. Persisted as JSON.
`dna watch` keeps it live: it polls mtimes and re-parses only changed
files, so the model never goes stale.
3. **Analyze** โ `dna impact` runs reverse-BFS from your target over the
dependency graph and scores every affected component. `dna plan` takes a
natural-language change request, resolves it to components with a stated
confidence, and returns the blast radius plus suggested tests. `dna risks`
reports circular imports (Tarjan SCC), god-files, dead-code candidates,
untested components. `dna decisions` lists design choices mined from
commits.
4. **Verify** โ `dna verify` copies the tree to a temp dir, applies your
unified diff (context-verified โ mismatched hunks are refused, new-file
creation rejected), and runs the project's own test suite with a timeout.
## ๐ฅ Blast-radius prediction
```console
$ dna impact "auth.py"
target: auth.py โ auth.py, session.py, api/routes.py
affected components: 3
RISK SCORE DEPTH COMPONENT
------------------------------------------
high 5 1 session.py
ยท no test coverage
ยท churn hotspot
ยท depth 1
medium 3 2 api/routes.py
ยท no test coverage
low 1 1 auth.py
ยท target itself
โโ 3 components ยท 1 high-risk โโ
```
Risk scoring is explicit, not magic: no test coverage **+2**, circular
dependency **+2**, churn hotspot **+1**, depth > 3 **+1**. Labels: 0โ1 low,
2โ3 medium, 4+ high. Every score comes with its reasons printed.
```bash
dna impact checkout --limit 30 # fuzzy match โ file, or even a function name
```
## ๐ง Change planning โ predict before you change
```console
$ dna plan "change the login system"
TARGET: auth.py (confidence: high)
request: change the login system
affected components: 3
RISK SCORE DEPTH COMPONENT
------------------------------------------
high 5 1 session.py
ยท no test coverage
ยท churn hotspot
medium 3 2 api/routes.py
ยท no test coverage
SUGGESTED TESTS:
tests/test_session.py
tests/test_routes.py
RISK SUMMARY: high=1 medium=1 low=0
HOTSPOTS IN BLAST:
session.py (12 commits)
```
`dna plan` resolves your request to components (exact path/basename โ
`high` confidence, fuzzy match โ `medium`, keyword fallback โ `low`),
reuses the blast-radius engine, and suggests the tests that cover the
affected code. Confidence is always shown โ a `low` plan tells you the
match was a guess, not a fact.
## ๐งซ Sandbox verification
```console
$ dna verify --patch fix.diff --path ./my-project
verifying patch in sandbox (project: ./my-project) ...
patched: auth.py
tests: PASS โ 42 passed, 0 failed in 1.8s
```
The patch is applied to a throwaway copy โ your working tree is never
touched. Only verify projects you trust: the sandbox runs the project's
own test suite, so it inherits your trust in that code.
## ๐๏ธ Live watcher โ DNA that stays current
```console
$ dna watch --interval 2
ingesting /home/you/my-project ...
watching 38 files in /home/you/my-project (every 2s) โ Ctrl+C to stop
update #1: ~1 changed โ DNA saved (38 files)
update #2: ~1 changed, -1 deleted โ DNA saved (37 files)
```
`dna watch` polls file mtimes (stdlib only โ no watchdog dependency) and
re-parses **only the files that changed**, then rebuilds and re-saves the
DNA. New files, deleted files, and edits are all picked up; `Ctrl+C`
exits cleanly. The DNA stops being a snapshot and becomes a living model.
## ๐ค MCP โ for AI agents
Four tools over stdio JSON-RPC. Malformed input returns `-32600`; the
server never crashes.
| Tool | Args | Returns |
|---|---|---|
| `dna_map` | โ | Components, dependency stats |
| `dna_impact` | `{target}` | Ranked blast radius with reasons |
| `dna_plan` | `{request}` | Full change prediction + suggested tests |
| `dna_decisions` | `{limit}` | Decisions mined from git history |
```json
{ "project": { "command": "<FULL PYTHON PATH>", "args": ["-m", "dna", "mcp"] } }
```
> ๐ **Full per-agent setup guide:** [docs/SETUP_ALL_AGENTS.md](docs/SETUP_ALL_AGENTS.md) โ
> Claude Code, Claude Desktop, Cursor, Codex, ChatGPT Desktop, Gemini CLI,
> Antigravity, Termux. (Golden rule: GUI apps need the **full** python path.)
## โ ๏ธ Risk report
```bash
dna risks
```
```
risk report: my-project (38 components, 112 edges)
circular imports: 1
โป api/routes.py โ db/session.py โ api/routes.py
god-files (>500 lines): 2
legacy/parser.py (812 lines)
dead-code candidates (no inbound, no tests): 3
utils/old_helpers.py
```
## ๐งฑ Honest limits โ v0.2.0
- **Python only.** Other languages are invisible to the parser.
- **Fuzzy target matching is heuristic.** Ambiguous names resolve to the
first/best match; verify with `dna map` when unsure. `dna plan` always
shows its confidence โ treat `low` as a guess.
- **Call-graph resolution is best-effort.** Dynamic imports, `exec`,
`getattr`-style dispatch, and method calls on unknown receivers are
not tracked. The dependency graph is file-level (imports), which is
robust; function-level edges are informational.
- **The sandbox runs the project's own test suite.** Only verify projects
you trust โ same trust level as running their tests locally.
- **Patch applier is minimal.** Unified diffs with new-file creation
(`/dev/null` sources) are rejected; complex renames may fail โ the
tool refuses rather than mis-applying.
- **The watcher polls.** It checks mtimes on an interval (default 2s),
so sub-second bursts of edits may batch into one update. It does not
watch git history โ commit, then re-mine decisions with `dna init`.
- **Intent is extracted, not understood.** Summaries come from docstrings,
README mentions, and test names โ useful signal, not deep comprehension.
## ๐ Verify it yourself
```bash
python -m pytest tests/ -q # 56 tests โ should all pass
```
Tests are fully mocked โ **zero network, zero real git**, under a second.
Every badge above is checkable in this repo.
## ๐๏ธ Architecture
```
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ ๐งฌ DNA CORE โ
โ ingest ยท model ยท analyze โ
โ ยท verify โ
โโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโ
โโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโ
โผ โผ โผ
โโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโ
โ INGEST โ โ MODEL โ โ ANALYZE โ
โ ast parser โ โ ProjectDNA โ โ reverse-BFS โ
โ import resolve โ โ dep + reverse โ โ risk scoring โ
โ git log miner โ โ decisions โ โ Tarjan cycles โ
โ degrades w/o โ โ hotspots โ โ god-files โ
โ git โ โ JSON @ ~/.dna โ โ dead code โ
โโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโ
โโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ VERIFY + MCP โ
โ temp-dir sandbox ยท context-verified โ
โ patch applier ยท pytest ยท 3 MCP tools โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
```
~2,000 lines of Python. No frameworks. No dependencies. The whole model
fits in one JSON file you can open and read.
## ๐ค Contributing
New analyzers are the best contribution:
1. Fork โ branch โ add your analyzer under `dna/analysis/`
2. Add a test in `tests/` (mocked โ no network, no real git)
3. `pytest tests/ -q` must stay green
4. Open a PR explaining what it detects and why it matters
## ๐ License
MIT ยฉ 2026 Prabhjot Singh. Know your codebase's genome before you edit it. ๐งฌ
TDQS
B3/5.0
Scored across 4 tools
Disambiguation5/5
Each tool targets a distinct capability: architecture summary, component impact, historical decisions, and request-level change planning. No two tools overlap in input or output scope, so an agent can easily select the right one.
Naming Consistency5/5
All four tools use the dna_ prefix followed by a single noun (map, impact, decisions, plan), forming a consistent and predictable naming convention.
Tool Count5/5
Four tools are well-suited for a focused architecture analysis engine; each covers a unique analysis dimension without redundancy.
Completeness4/5
The set covers key analysis outputs (summary, impact, decisions, plan) but lacks a tool to ingest/refresh the project or drill into specific components/decisions, leaving minor workflow gaps.
Maintenance
ActivityMaintained
ResponsivenessNo issues