Information-theoretic context optimization for AI coding agents. Knapsack-optimal token budgeting, Shannon entropy scoring, SimHash dedup, predictive pre-fetch. MCP server.
Project description
Entroly
Information-theoretic context compression for AI coding agents.
Every AI coding tool โ Cursor, Copilot, Claude Code, Cody โ manages context with dumb heuristics: stuff tokens until the window fills, then cut. Entroly uses mathematics to compress an entire codebase into the optimal context window.
๐ The Problem
Current AI tools use Cosine Similarity (Vector Search). It's great for finding "things that look like my query," but terrible for coding because:
- Context Blindness: It finds the "top 5 files" but missed the 6th file that contains the critical interface definition.
- Boilerplate Waste: 40% of retrieved code is often imports or repetitive boilerplate, wasting expensive tokens.
- Correlation vs Causation: Vector search finds related code, not causally necessary code.
โ The Solution: Entroly
Entroly replaces "dumb search" with Information-Theoretic Compression. It treats your context window as a finite resource and uses Knapsack Optimization to pack the most "informative" (highest entropy) and "causally relevant" (dependency-linked) fragments.
pip install entroly
How It's Different
Sourcegraph Cody does search: "Find 5โ10 files that look relevant." Entroly does compression: "Show the LLM the entire codebase at variable resolution."
| Cody / Copilot | Entroly | |
|---|---|---|
| Approach | Embedding similarity search | Information-theoretic compression |
| Coverage | 5โ10 files (the rest is invisible) | 100% codebase visible via 3-level hierarchy |
| Selection | Top-K by cosine distance | Knapsack-optimal with submodular diversity |
| Dedup | None | SimHash + LSH in O(1) |
| Learning | Static | Online Wilson-score feedback + autotune |
| Security | None | Built-in SAST (55 rules, taint-aware) |
| Temperature | User-set or model default | Auto-calibrated via Fisher information |
Architecture
Hybrid Rust + Python. All math runs in Rust via PyO3 (50โ100ร faster). MCP protocol and orchestration run in Python. Pure Python fallbacks activate automatically if the Rust extension isn't available.
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ IDE (Cursor / Claude Code / Cline / Copilot) โ
โ โ
โ โโโโโ MCP mode โโโโโ โโโโโ Proxy mode โโโโโ โ
โ โ entroly MCP serverโ โ localhost:9377 โ โ
โ โ (JSON-RPC stdio) โ โ (HTTP reverse proxy)โ โ
โ โโโโโโโโโโฌโโโโโโโโโโโ โโโโโโโโโโฌโโโโโโโโโโโโ โ
โ โ โ โ
โ โโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโ โ
โ โ Entroly Engine (Python) โ โ
โ โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ โ
โ โ โ entroly-core (Rust via PyO3) โ โ โ
โ โ โ 14 modules ยท 330 KB ยท 93 tests โ โ โ
โ โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Two deployment modes:
- MCP Server โ IDE calls
remember_fragment,optimize_context, etc. via MCP protocol - Prompt Compiler Proxy โ invisible HTTP proxy at
localhost:9377, intercepts every LLM request and auto-optimizes (zero IDE changes beyond API base URL)
Engines
Rust Core (14 modules)
| Module | What | How |
|---|---|---|
| hierarchical.rs | 3-level codebase compression (ECC) | L1: skeleton map of ALL files ยท L2: dep-graph cluster expansion ยท L3: knapsack-optimal full fragments with submodular diversity |
| knapsack.rs | Optimal context subset selection | 0/1 Knapsack DP (N โค 2000) ยท greedy with Dantzig 0.5-guarantee (N > 2000) |
| entropy.rs | Information density scoring | Shannon entropy (40%) + boilerplate detection (30%) + cross-fragment n-gram redundancy (30%) |
| depgraph.rs | Dependency graph + symbol table | Auto-linking: imports (1.0) ยท type refs (0.9) ยท function calls (0.7) ยท same-module (0.5) |
| skeleton.rs | AST-lite code skeleton extraction | Preserves signatures, class/struct/trait layouts, strips bodies โ 60โ80% token reduction |
| dedup.rs | Near-duplicate detection | 64-bit SimHash fingerprints ยท Hamming threshold โค 3 ยท 4-band LSH buckets |
| lsh.rs | Semantic recall index | 12-table multi-probe LSH ยท 10-bit sampling ยท ~3 ฮผs over 100K fragments |
| sast.rs | Static Application Security Testing | 55 rules across 8 CWE categories ยท taint-flow analysis ยท severity scoring |
| health.rs | Codebase health analysis | Clone detection (Type-1/2/3) ยท dead symbol finder ยท god file detector ยท arch violation checker |
| guardrails.rs | Safety-critical file pinning | Criticality levels (Safety/Critical/Important/Normal) ยท task-aware budget multipliers |
| prism.rs | Spectral weight optimizer | Jacobi eigendecomposition on 4ร4 covariance matrix ยท anisotropic gain adaptation |
| query.rs | Query analysis + refinement | Vagueness scoring ยท keyword extraction ยท intent classification |
| fragment.rs | Core data structure | Content, metadata, scoring dimensions, skeleton, SimHash fingerprint |
| lib.rs | PyO3 bridge + orchestrator | All modules exposed to Python ยท 93 tests |
Python Layer
| Module | What |
|---|---|
| proxy.py | Invisible HTTP reverse proxy (prompt compiler mode) |
| proxy_transform.py | Request parsing ยท context formatting (flat + hierarchical) ยท EGTC ยท APA |
| proxy_config.py | Model context windows ยท all feature flags ยท autotune overlay |
| server.py | MCP server with 10+ tools ยท pure Python fallbacks |
| long_term_memory.py | Cross-session memory via hippocampus-sharp-memory integration |
| multimodal.py | Image OCR ยท diagram parsing (Mermaid/PlantUML/DOT) ยท voice transcript extraction |
| autotune.py | Autonomous hyperparameter optimization (mutate โ evaluate โ keep/discard) |
| auto_index.py | File-system crawler for automatic codebase indexing |
| adaptive_pruner.py | Online RL-based fragment pruning |
| checkpoint.py | Gzipped JSON state serialization (~100 KB per checkpoint) |
| prefetch.py | Predictive context pre-loading via import analysis + co-access patterns |
| provenance.py | Hallucination risk detection via source verification + confidence scoring |
Novel Algorithms
Entropic Context Compression (ECC)
Three-level hierarchical codebase compression. The LLM sees everything at variable resolution:
graph TD
Query["User Query"] --> L1["L1: Skeleton Map (5%)"]
Query --> L2["L2: Dependency Cluster (25%)"]
Query --> L3["L3: Full Fragments (70%)"]
L1 --> C1["Signatures of ALL 1000+ files"]
L2 --> C2["Expanded skeletons of related modules"]
L3 --> C3["Submodular diversified full code"]
C1 --> Context["Optimal Context Window"]
C2 --> Context
C3 --> Context
Novel techniques:
- Symbol-reachability slicing โ BFS through dep graph from query-relevant symbols (cf. NeurIPS 2025)
- Submodular diversity selection โ diminishing returns per module (Nemhauser 1978, 1-1/e guarantee)
- PageRank centrality โ hub files get priority in L2 expansion
- Entropy-gated budget allocation โ complex codebases get more L3 budget
EGTC v2 (Entropy-Gap Temperature Calibration)
Automatically derives the optimal LLM sampling temperature from information-theoretic properties of the selected context. Uses Fisher information scaling with 4 signals:
ฯ = clip(ฯ_base + ฮฃ signal_weights ร [vagueness, entropy_gap, sufficiency, task_type])
APA (Adaptive Prompt Augmentation)
- Calibrated token estimation โ per-language chars/token ratios (Python: 3.0, Rust: 3.5, ...)
- Task-aware preamble โ conditional hints from security findings, vagueness, and task type
- Content deduplication โ MD5 hash-based dedup saves 10โ20% in multi-turn sessions
Setup
Cursor
Add to .cursor/mcp.json:
{
"mcpServers": {
"entroly": {
"command": "entroly"
}
}
}
Claude Code
claude mcp add entroly -- entroly
Prompt Compiler Proxy (any IDE)
Change your IDE's API base URL to http://localhost:9377:
entroly --proxy
# or
ENTROLY_PROXY_PORT=9377 python -m entroly.proxy
Every LLM request is intercepted, optimized with the full pipeline (ECC + EGTC + APA + SAST), and forwarded transparently. < 10ms overhead.
Docker (cross-platform)
docker pull ghcr.io/juyterman1000/entroly:latest
docker run --rm -p 9377:9377 ghcr.io/juyterman1000/entroly:latest
Multi-arch image: linux/amd64 and linux/arm64 (Apple Silicon, AWS Graviton).
MCP Tools
| Tool | Purpose |
|---|---|
remember_fragment |
Store context with auto-dedup, entropy scoring, dep linking, criticality detection |
optimize_context |
Select optimal context subset for a token budget (knapsack + ECC) |
recall_relevant |
Sub-linear semantic recall via multi-probe LSH |
record_outcome |
Feed the Wilson-score feedback loop |
explain_context |
Per-fragment scoring breakdown with sufficiency analysis |
checkpoint_state |
Save full session state (gzipped JSON) |
resume_state |
Restore from checkpoint |
prefetch_related |
Predict and pre-load likely-needed context |
get_stats |
Session statistics and cost savings |
health_check |
Clone detection, dead symbols, god files, arch violations |
The Math
Multi-Dimensional Relevance Scoring
r(f) = (w_rec ยท recency + w_freq ยท frequency + w_sem ยท semantic + w_ent ยท entropy)
/ (w_rec + w_freq + w_sem + w_ent)
ร feedback_multiplier
- Recency: Ebbinghaus forgetting curve โ
exp(-ln(2) ร ฮt / half_life) - Frequency: Normalized access count with spaced repetition boost
- Semantic similarity: SimHash Hamming distance to query, normalized to [0, 1]
- Information density: Shannon entropy + boilerplate + redundancy
Knapsack Context Selection
Maximize: ฮฃ r(fแตข) ยท x(fแตข) for selected fragments
Subject to: ฮฃ c(fแตข) ยท x(fแตข) โค B (token budget)
- N โค 2000: Exact DP with budget quantization โ O(N ร 1000)
- N > 2000: Greedy density sort โ O(N log N), Dantzig 0.5-optimality guarantee
SAST Security Categories
| Category | CWE | Rules |
|---|---|---|
| Hardcoded Secrets | CWE-798 | API keys, passwords, tokens, private keys |
| SQL Injection | CWE-89 | f-strings, concatenation, raw queries (taint-aware) |
| Command Injection | CWE-78 | os.system, subprocess with shell=True |
| Path Traversal | CWE-22 | open() with user input, os.path.join |
| XSS | CWE-79 | innerHTML, template injection |
| SSRF | CWE-918 | requests with user-controlled URLs |
| Insecure Crypto | CWE-327 | MD5/SHA1 for auth, weak key sizes |
| Auth Flaws | CWE-287 | Hardcoded roles, missing auth checks |
Configuration
EntrolyConfig(
default_token_budget=128_000, # GPT-4 Turbo equivalent
max_fragments=10_000, # session fragment cap
weight_recency=0.30, # scoring weights (sum to 1.0)
weight_frequency=0.25,
weight_semantic_sim=0.25,
weight_entropy=0.20,
decay_half_life_turns=15, # Ebbinghaus half-life
enable_hierarchical_compression=True, # 3-level ECC
enable_temperature_calibration=True, # EGTC v2
enable_prompt_directives=True, # APA preamble
enable_security_scan=True, # SAST
)
References
- Shannon (1948) โ Information Theory
- Charikar (2002) โ SimHash
- Ebbinghaus (1885) โ Forgetting Curve
- Weiser (1981) โ Program Slicing
- Nemhauser, Wolsey & Fisher (1978) โ Submodular Maximization
- Dantzig (1957) โ Greedy Knapsack Approximation
- Wilson (1927) โ Score Confidence Intervals
- LLMLingua (EMNLP 2023) โ Perplexity-based Token Compression
- LongLLMLingua (ACL 2024) โ Query-aware Context Compression
- RepoFormer (ICML 2024 Oral) โ Selective Retrieval for Repo-Level Code
- FILM-7B (NeurIPS 2024) โ Structure-First Layout
- CodeSage (ICLR 2024) โ Code Embedding Representation Learning
- SWE-bench (ICLR 2024) / SWE-agent (NeurIPS 2024) โ Evaluation
Part of the Ebbiforge Ecosystem
Entroly integrates with hippocampus-sharp-memory for persistent cross-session memory and Ebbiforge for TF embeddings and RL weight learning. Both are optional.
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file entroly-0.3.2.tar.gz.
File metadata
- Download URL: entroly-0.3.2.tar.gz
- Upload date:
- Size: 3.5 MB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8679a4e71871de31fe34ae674923c1b528171599104b03e13927c02bffa5f6cb
|
|
| MD5 |
60757208244fd8f2dfeeee6fd5727a23
|
|
| BLAKE2b-256 |
e89cff53bc3846f4219f1b1c1c0bd8d47107c6fa9b37246563d419eb39e8bd1d
|
Provenance
The following attestation bundles were made for entroly-0.3.2.tar.gz:
Publisher:
entroly-publish.yml on juyterman1000/entroly
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
entroly-0.3.2.tar.gz -
Subject digest:
8679a4e71871de31fe34ae674923c1b528171599104b03e13927c02bffa5f6cb - Sigstore transparency entry: 1107696368
- Sigstore integration time:
-
Permalink:
juyterman1000/entroly@f21c4f0e30f6245ef3550148a5feb909963728ed -
Branch / Tag:
refs/tags/entroly-v0.3.2 - Owner: https://github.com/juyterman1000
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
entroly-publish.yml@f21c4f0e30f6245ef3550148a5feb909963728ed -
Trigger Event:
push
-
Statement type:
File details
Details for the file entroly-0.3.2-py3-none-any.whl.
File metadata
- Download URL: entroly-0.3.2-py3-none-any.whl
- Upload date:
- Size: 185.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
82854b99ac2f078a91da6680cd198fdbee68dd5613094947a1df03747afb7a37
|
|
| MD5 |
27716028297bbdd64cc5cc25b4646d41
|
|
| BLAKE2b-256 |
bed5481c138600f8f11e7c811a1d23aaa250ac1eafc0cb3adee2605d4d97f8fd
|
Provenance
The following attestation bundles were made for entroly-0.3.2-py3-none-any.whl:
Publisher:
entroly-publish.yml on juyterman1000/entroly
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
entroly-0.3.2-py3-none-any.whl -
Subject digest:
82854b99ac2f078a91da6680cd198fdbee68dd5613094947a1df03747afb7a37 - Sigstore transparency entry: 1107696373
- Sigstore integration time:
-
Permalink:
juyterman1000/entroly@f21c4f0e30f6245ef3550148a5feb909963728ed -
Branch / Tag:
refs/tags/entroly-v0.3.2 - Owner: https://github.com/juyterman1000
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
entroly-publish.yml@f21c4f0e30f6245ef3550148a5feb909963728ed -
Trigger Event:
push
-
Statement type: