الهندسة المعمارية

The architecture.

One Rust binary. Five subsystems. Zero cloud dependencies. Every box below maps to a real module, port, or file on disk.

System topology.

الطوبولوجيا العملية للثنائي المُشحون: سبع نقاط دخول، وتشغيل واحد، ومجموعة من المخازن المحلية. كل صندوق أدناه يمثل وحدة أو منفذًا أو ملفًا حقيقيًا على القرص.

One binary. Five subsystems. No cloud required.

تدفق البيانات Stage by stage.

يتتبع المخطط 2 طلبًا واحدًا عبر وقت التشغيل، مرحلة تلو الأخرى، بما في ذلك الدائرة القصيرة للتخزين المؤقت التي تجعل القراءات المتكررة شبه مجانية. يعمل مسار Shell بالتوازي مع نفس الحساب.

الضغط engine.

Tree-sitter parses 27 languages into ASTs. 10 read modes select the right abstraction level — from full source to aggressive entropy filtering. 95+ shell patterns compress git, cargo, npm, docker, and kubectl output into compact evidence.

Explore read modes
ctx_read — mode selection auto
Available modes
full entire file, no compression
signatures fn signatures + type defs
map structural overview
diff uncommitted changes only
task query-conditioned extract
aggressive maximum compression
entropy information-dense lines
reference symbols + doc comments
lines:N-M specific line range
Selected: signatures (420 lines → 18 lines)
27 languages · tree-sitter −95.7%

Memory, agents, security.

Content-addressed caching collapses re-reads to ~13 tokens. A knowledge graph persists decisions across sessions. The agent bus coordinates multiple agents without duplicating context. PathJail, shell allowlists, and TOCTOU checks enforce deny-by-default boundaries on every call.

Security model
lean-ctx doctor all passed
Cache 47 entries · 73% hit rate
Knowledge 342 nodes · 1,205 edges
Agent bus 3 agents registered
PathJail root: /Users/dev/project
Allowlist 14 allow, 6 deny
Redaction .env, credentials.*
TOCTOU open-handle verify active
Ledger Ed25519-signed · 0 violations
8/8 subsystems healthy deny-by-default

Engineering data sheet.

الجداول المرجعية وراء الرسومات: كل سطح بنقله ودورة حياته، والتخطيط على القرص، والطبقات ذات التعلم التكيفي، وحدود الأمان التي يفرضها وقت التشغيل.

Aنموذج العملية

جميع الواجهات هي ثنائيات متطابقة في أدوار مختلفة. لا يتطلب أي شيء اتصال سحابي؛ كل شيء مرتبط محليًا أولاً.

REF SURFACE TRANSPORT ENDPOINT LIFECYCLE الأمر
01 MCP server (stdio) JSON-RPC over stdin/stdout spawned per editor session child process of the editor lean-ctx
02 MCP server (HTTP) MCP Streamable HTTP localhost, configurable --host/--port foreground or service lean-ctx serve
03 IPC daemon Unix Domain Socket OS data dir, e.g. ~/Library/Application Support/lean-ctx/daemon.sock launchd / systemd autostart lean-ctx serve --daemon
04 Shell hook process exec, compressed stdout wraps IDE bash calls + interactive shells per command lean-ctx -c "<cmd>"
05 API proxy HTTP (LLM API pass-through) localhost:4444 (default) on demand lean-ctx proxy start
06 Web dashboard HTTP + bearer token localhost:3333 (default, --port) on demand lean-ctx dashboard
07 Terminal UI TTY (in-place redraw) live event stream / 1 s refresh interactive lean-ctx watch · gain --live

Bتخطيط التخزين — مسارات XDG المحلية

الحالة المستمرة عبارة عن ملفات عادية ضمن دليل قاعدة XDG: قابلة للتفتيش، وقابلة للتصدير، وقابلة للحذف. لا توجد قواعد بيانات مخفية تتجاوز هذه المجلدات المحلية.

المُصنَّف (ARTIFACT) FORM الغرض
config.toml TOML Single config file — integration mode, compression, providers, opt-outs (config dir)
cache/ content-addressed Session file cache; unchanged re-reads collapse to ~13-token stubs (cache dir)
bm25 index inverted index Lexical search over code chunks + provider documents (data dir)
context_graph/ property graph Imports, calls, types across files and repos — powers map mode + deep queries (data dir)
knowledge SQLite Persistent facts, decisions, rooms — recalled across sessions, CCP (data dir)
savings ledger append-only JSONL Every compression event; Ed25519-signable for audit (data dir)
litm_calibration.json JSON Learned context-position hit rates (lost-in-the-middle calibration) (cache dir)
events.jsonl event stream Live feed consumed by watch, dashboard and efficacy reports (state dir)

Cطبقات التعلم التكيفي

تضبط سبع آليات للتعلم عبر الإنترنت الضغط ليناسب استخدامك الفعلي، محليًا، من إشارات الجودة مثل الارتدادات وفشل التحرير. تعمق: التعلم التكيفي →

  • L1
    Adaptive thresholds Online-learned compression aggressiveness from quality signals (bounces, edit failures, clean runs)
  • L2
    LITM calibration Empirical placement of critical context at positions the model actually attends to
  • L3
    Stigmergic scent field Multi-agent coordination via decaying markers: claimed, done, stuck, hot, avoid
  • L4
    Delta playbook Incremental checkpoint snapshots that survive context compaction
  • L5
    Query-conditioned IB Information-Bottleneck compression fused with query relevance
  • L6
    Theta-gamma chunking Wakeup facts grouped in attention-friendly bursts
  • L7
    Semantic dedup Likelihood-scored redundancy filtering across the session

Dحدود الأمان

ضمانات صارمة يتم فرضها في وقت التشغيل. نموذج الأمان →

  • PathJail Every file access is canonicalised and confined to the workspace root
  • IDE config-dir jail Home-level IDE/agent config dirs (~/.claude, ~/.codex, ~/.codebuddy, …) are writable only when allow_ide_config_dirs is opted in; otherwise PathJail blocks them
  • Shell allowlist Deny-by-default command policy for agent-issued shell executions
  • Local-first All processing on-device; dashboard binds to localhost and requires a bearer token
  • Signed evidence Savings ledger entries are Ed25519-signable and batch-verifiable

Explore thesource.

LeanCTX is open source. Read the code, understand the design, contribute.

Support this project