인지적 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는 요청 하나가 런타임을 거쳐 단계별로 어떻게 처리되는지 추적하며, 반복적인 읽기를 거의 무료로 만드는 캐시 단락 회로까지 포함합니다. 셸 경로는 동일한 계산을 병렬로 실행합니다.
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, 대시보드 및 서명된 절감 장부에 반영됩니다.
엔지니어링 데이터 시트
도면 뒤의 참조 테이블: 모든 표면과 그 운송 및 수명 주기, 디스크 상 레이아웃, 적응형 학습 계층, 그리고 런타임이 강제하는 보안 경계.<br>
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+ IDEs, Cloud, Team Server
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 서명 원장, 재현 가능한 벤치마크). 선택적 로컬 프록시는 전송되는 내용—요청의 시스템 프롬프트, 기록 및 도구 출력—을 압축하며, 이는 와이어 상에서 prompt-cache에 안전합니다. 압축은—읽기 측과 와이어 측 모두—다섯 개 서브시스템 중 하나이며, 모든 원본 데이터는 로컬에서 검색 가능하게 유지됩니다. MCP와 셸 후크를 통해 30개 이상의 AI 코딩 도구와 작동하며; Python, TypeScript 및 Rust SDK를 갖춘 버전 관리된 /v1 API를 통해 모든 에이전트에 임베드할 수 있습니다. 로컬 사용은 CI에 의해 영구적으로 무료입니다.
전체 스토리 읽기