Cognitive Context Layerとは何ですか?
Cognitive Context Layerは、AIツールとコードベースの間のインフラストラクチャです。どのファイルが読み取られるか、出力がどのように圧縮されるか、セッションをまたいでどのような知識が保持されるか、そして結果が提供前に品質基準を満たしているかを制御します。
構築図面
出荷されるバイナリのプロセストポロジー:7つのエントリポイント、1つのランタイム、1組のローカルストア。以下の各ボックスは、実際のモジュール、ポート、またはディスク上のファイルに対応します。
lean-ctx lean-ctx serve lean-ctx serve --daemon lean-ctx -c "<cmd>" lean-ctx proxy start lean-ctx dashboard lean-ctx watch · gain --live 単一の読み取りがたどる経路
Sheet 2は、ランタイムをステージごとに追跡し、繰り返し読み取りをほぼ無料にするキャッシュショートサーキットを含めて、1つのリクエストの流れを示します。シェルパスも同様の計算に基づいて並行して実行されます。
ctx_read(path, mode) · lean-ctx read - PathJail
core/pathjail.rsCanonicalises the path and rejects escapes outside the workspace root before any I/O happens.
- Session cache
hit → ~13 tokensContent-addressed lookup keyed by path + mtime/hash. Unchanged files collapse to a stub instead of re-sending content.
- AST extraction
26 languagestree-sitter parses the file into a syntax tree: signatures, imports, call edges — Lua, Luau, Kotlin and GDScript are graph-indexed too. Regex fallback for unsupported languages.
- Mode selection
10 modesauto picks the optimal of 10 read modes (full, map, signatures, diff, task, reference, aggressive, entropy, lines:N-M) from task intent and file size; structure_first biases cold medium-file code reads toward map, and a file flagged suspect on a fix task is forced to full.
- Compression
adaptive thresholdsShannon-entropy line filtering, U-curve attention placement (LITM), TF-IDF codebook and query-conditioned Information-Bottleneck fusion — an anti-inflation guard ships the file verbatim whenever framing would cost more tokens than the raw bytes.
- Token accounting
core/tokens.rsExact tiktoken counts (o200k_base; cl100k_base approximation for Claude-family models) on input and output.
- Ledger + stats
savings sign / verify-batchSavings are appended to the local ledger (Ed25519-signable), stats and the gain score update, the result streams back.
lean-ctx -c "cargo test" · IDE bash hook 両方のパスは同じ台帳で終了します:すべての圧縮イベントは正確なトークナイザ数学でカウントされ、gain、ダッシュボード、および署名された節約済み台帳にフィードされます。
エンジニアリングデータシート
図面を裏付ける参照テーブル:すべての表面とその輸送とライフサイクル、オンディスクレイアウト、適応学習層、およびランタイムが強制するセキュリティ境界です.
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ベースディレクトリ内のプレーンファイルです:検査可能、エクスポート可能、削除可能です。これらのローカルフォルダ以外に隠されたデータベースはありません。
| アーティファクト | 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適応学習レイヤー
バウンスや編集失敗などの品質シグナルから、あなたの実際の使用状況に合わせて圧縮を調整する7つのオンライン学習メカニズム。 詳細:適応学習 →
- 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
単一バイナリ。三つの入力方法。
LeanCTXは各エージェントに最適な統合モードを自動的に選択します:CLI-Redirectは、ゼロMCPオーバーヘッドでエディタールールを通じてLeanCTX CLIを駆動し、HybridはMCPキャッシュ読み取りとシェル圧縮フックを組み合わせ、Full MCPはプロトコル専用のエディターに最大限のツールアクセスを提供します。
lean-ctx -c / read / grep MCP cache + CLI shell/search 81 tools via MCP + lazy tool set いずれにせよ、LeanCTXがエディタに適したモードを自動的に選択します。 サポートされている30以上のツールを見る
常時稼働。常にあなたのもので。
小さなバックグラウンドサービスがセッションを温め続け、キャッシュヒットは即座になり、メモリは常に確保されます。セットアップ中に自動的に開始し、更新時に再起動し、それ自体でクリーンアップするため、管理するものは何もありません。
すべての機能が、単一バイナリに集約。
コードとAIの間にあるすべてを処理します。
Smart I/O
決定論的な読み取り、シェル圧縮、検索、完全なコンテキスト可視性 + トークンが99%削減
リクエスト圧縮
オプションのローカルプロキシが、モデルへのすべてのリクエスト(システムプロンプト、履歴、ツール結果)を圧縮します。これはプロンプトキャッシュに安全です。
Intelligence
意図ルーティング、モード選択、適応型パイプライン
Memory
セッション、プロジェクト知識、グラフ、ハンドオフ
Governance
ロール、予算、SLO、ワークフローゲート、ポリシー
Verification
Lean4の形式証明、クレームベースの検証、品質レベル0-4
Integrations
MCP、HTTP、SDK、29以上のIDE、クラウド、チームサーバー
Shared Sessions
エージェント間でワークスペースおよびチャネルベースのセッション共有
Context Bus
SSE経由でのコンテキスト変更のためのリアルタイムイベントストリーム
SDK & API
外部統合用のTypeScript SDKおよびREST API
すべての出力には証明が伴う
LeanCTX は、すべてのセッションについて証明アーティファクトを生成します:どのファイルが読み込まれたか、何が圧縮されたか、どのチェックが通過したか、およびトークンがどのように消費されたか。これにより、AIの作業は監査可能で、リプレイ可能で、信頼できるものになります。
LeanCTX(Lean Contextの略)は、AIエージェントのためのオープンソースのcontext engineering layerです。ローカルのRustバイナリ一つで、エージェントが何を読み取るか(10のリードモード、トークンを60〜90%削減、約13トークンのキャッシュ再読み取り)、何から学習したかを記憶するか(永続セッション、知識グラフ)、触れるものを保護するか(PathJail、シークレットのマスキング、バジェット、インジェクション検出)、そして保存するものに証明を与えるか(Ed25519署名台帳、再現可能なベンチマーク)を決定します。オプションのローカルプロキシが送信するデータ(リクエストごとのシステムプロンプト、履歴、ツール出力)を圧縮し、ワイヤー上でもプロンプトキャッシュに対応させます。この圧縮機能は——リード側もワイヤー側も——5つのサブシステムのうちの1つであり、元のデータはすべてローカルで取得可能です。MCPおよびシェルフックを通じて30以上のAIコーディングツールに対応し、Python、TypeScript、Rust SDKを備えたバージョン管理された/v1 API経由で任意のエージェントに組み込めます。ローカル利用はCIによって永続的に無料です。
詳細なストーリーを読む