v3.5.23
Added
- RAM Guardian — adaptive memory management — New
memory_guardmodule with RSS-based memory monitoring, peak tracking, and adaptive tiered eviction. Background guard task monitors memory pressure and triggers cache eviction at configurable thresholds (max_ram_percent, default 5%). Usesjemallocas global allocator on Unix for aggressive memory return (dirty_decay_ms:1000,muzzy_decay_ms:1000). Newjemalloc_purge()andforce_purge()for explicit arena cleanup. Platform-specific RSS reading viatask_info()(macOS) and/proc/self/status(Linux). New dependencies:tikv-jemallocator,tikv-jemalloc-ctl,zstd,memmap2. - zstd-compressed session cache —
CacheEntrynow stores content as zstd-compressedVec<u8>instead of rawString, reducing in-memory cache footprint by ~60–80%. NewCacheEntry::new(),content(),set_content()API.SessionCache::store()signature changed fromcontent: Stringtocontent: &str. - Memory estimation and unload for indexes —
BM25Index::memory_usage_bytes()/unload()andEmbeddingIndex::memory_usage_bytes()/unload()enable the RAM Guardian to reclaim index memory under pressure. - Dashboard memory API — New
/api/memoryendpoint exposing RSS, peak RSS, system RAM, pressure level, allocator type, and max sessions. lean-ctx doctorRAM Guardian diagnostics — Doctor output now shows current RSS, system RAM, percentage, limit, and allocator type.- Configurable savings footer suppression — New
savings_footerconfig option (auto|always|never) andLEAN_CTX_SAVINGS_FOOTERenv var. Inautomode (default), token savings footers like[42 tok saved (30%)]are shown in CLI but suppressed in MCP/agent context to prevent context pollution. Addresses user feedback about footers being added to agent context. - Explicit server shutdown —
LeanCtxServer::shutdown()clears cache, saves session, and triggersforce_purge()on MCP client disconnect. - Config schema:
max_ram_percent,savings_footer— Both new configuration keys exposed vialean-ctx config schemawith types, defaults, descriptions, and env var overrides.
Fixed
- CLI savings footer bypass —
cli/common.rs::print_savings()was formatting footers independently ofprotocol::format_savings(), ignoring thesavings_footerconfiguration. Now delegates to the central formatting function. - Daemon-delegated output footer leakage — When CLI commands (read, grep, ls) delegate to the daemon, the daemon's response could contain savings footers even when the CLI client has
LEAN_CTX_SAVINGS_FOOTER=never. Newfilter_daemon_output()function strips footer lines client-side based on the client's own footer configuration. - Shared session store cap — Reduced
MAX_CACHED_SESSIONSfrom 64 to 8 to prevent unbounded memory growth in multi-IDE setups.
Changed
CacheEntryAPI — Direct field access (entry.content) replaced with method call (entry.content()). All tools (ctx_compress,ctx_delta,ctx_share,ctx_dedup,ctx_read,ctx_preload) and tests updated.
Upgrade
lean-ctx update # recommended (auto-downloads + refreshes shell hooks)
cargo install lean-ctx # or
npm update -g lean-ctx-bin # or
brew upgrade lean-ctxNote: After upgrading via cargo/npm/brew, run
lean-ctx setupto refresh shell aliases.lean-ctx updatedoes this automatically.
Full Changelog: v3.5.23...v3.5.23