Skip to main content

Module protocol

Module protocol 

Source

Structs§

InstructionTemplate
A terse instruction code and its human-readable expansion.
ToolCallRecord
Recorded metrics for a single MCP tool invocation.

Enums§

CrpMode
Context Reduction Protocol mode controlling output verbosity.

Functions§

append_savings
Appends a savings footer to output with a newline separator, but only if the footer is non-empty.
detect_project_root
Finds the outermost project root by walking up from file_path. For monorepos with nested .git dirs (e.g. mono/backend/.git + mono/frontend/.git), returns the outermost ancestor containing .git, a workspace marker, or a known monorepo config file — so the whole monorepo is treated as one project.
detect_project_root_or_cwd
Returns the project root for file_path, falling back to cwd if none found. Checks LEAN_CTX_PROJECT_ROOT env var and config.toml project_root first. Logs a warning when the fallback is a broad directory (home, root).
encode_instructions
Encode an instruction suffix using short codes with budget hints. Response budget is dynamic based on task complexity to shape LLM output length.
encode_instructions_with_snr
Encode instructions with SNR metric for context quality awareness.
format_savings
Formats a unified token savings footer like [lean-ctx: 100→50 tok, -50%].
instruction_decoder_block
Generates the INSTRUCTION CODES block for agent system prompts.
meta_visible
Whether non-essential meta lines (cache refs, budget warnings, repetition hints) should be shown.
savings_footer_visible
Returns true if savings footers should be shown based on config + transport context.
set_mcp_context
Mark the current process as serving MCP tool calls (suppresses savings footers in auto mode).
shorten_path
Returns the file name component of a path for compact display.