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.
append_savings_with_info
Appends a savings footer with mode/detail context.
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).
display_path
Returns the file name component of a path for compact display. Normalize a path for display by converting Windows backslashes to forward slashes. Forward slashes are valid path separators on Windows, and unlike backslashes they are never misinterpreted as escape sequences by the JSON, markdown, or terminal layers of MCP clients — which corrupted Windows paths in tool output (e.g. C:\Users\… rendered as CUsers…). See issue #324.
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 token savings footer with box-drawing delimiters.
format_savings_with_info
Formats a savings footer with mode and optional detail context.
instruction_decoder_block
Generates the INSTRUCTION CODES block for agent system prompts. Only emits content when CRP mode is Tdd (otherwise returns empty string to avoid wasting ~80-100 tokens per MCP instructions payload).
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
shorten_path_relative
Returns a path relative to root for disambiguated display, always with forward slashes. Falls back to the basename if stripping fails.