Robust Hook Escaping + Auto-Context Fix
Fixed — Commands with Embedded Quotes Truncated
- JSON parser rewrite — Hook scripts and Rust handler now correctly parse JSON values containing escaped quotes (e.g.
curl -H "Authorization: Bearer token"). Previously, the naive[^"]*regex stopped at the first\"inside the value, truncating the command. Now uses([^"\\]|\\.)*pattern with proper unescape pass. Affects both bash scripts and Rustextract_json_field. - Double-escaping for rewrites — Rewrite output now applies two escaping passes: shell-escape (for the
-c "..."wrapper) then JSON-escape (for the hook protocol). Previously, only one pass was applied, causing inner quotes to break both shell and JSON parsing.
Fixed — Auto-Context Noise from Wrong Project (#62 Issue 4)
- Project root guard —
session_lifecycle_pre_hookandenrich_after_readnow require a known, non-trivialproject_rootbefore triggering auto-context. Previously, whenproject_rootwasNoneor".", the autonomy system would runctx_overviewon the MCP server's working directory (often a completely different project), injecting irrelevant "AUTO CONTEXT" blocks into responses.
Improved — Cache Hit Message Clarity (#62 Issue 3)
- Actionable stub — Cache hit responses now include guidance:
"File already in context from previous read. Use fresh=true to re-read if content needed again."Previously, the terseF1=main.rs cached 2t 4Lstub left AI agents confused about what to do next.
Housekeeping
- Redirect scripts reduced to minimal
exit 0(removed ~30 lines of deadis_binary/FILE_PATHparsing code that was never reached). - 4 new unit tests for escaped-quote JSON parsing and double-escaping.
- 1 new integration test for auto-context project_root guard.
- All 611 tests passing, zero clippy warnings.
Upgrade
cargo install lean-ctx # or
npm update -g lean-ctx-bin # or
brew upgrade lean-ctxFull Changelog: v2.21.3...v2.21.3